⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 render_form.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* * This file is part of the DOM implementation for KDE. * * Copyright (C) 1999 Lars Knoll (knoll@kde.org) *           (C) 1999 Antti Koivisto (koivisto@kde.org) *           (C) 2000 Dirk Mueller (mueller@kde.org) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB.  If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * $Id: render_form.cpp,v 1.130.2.2 2001/12/04 21:37:11 hausmann Exp $ */#include <kdebug.h>#include <kurl.h>#include <klocale.h>#include <kfiledialog.h>#include <kapp.h>#include <kcompletionbox.h>#include <kcursor.h>#include <qcombobox.h>#include "misc/helper.h"#include "dom_nodeimpl.h"#include "dom_textimpl.h"#include "dom_docimpl.h"#include "dom2_eventsimpl.h"#include "html/html_formimpl.h"#include "html/html_documentimpl.h"#include "misc/htmlhashes.h"#include "rendering/render_form.h"#include "rendering/render_style.h"#include "rendering/render_root.h"#include <assert.h>#include "khtmlview.h"#include "khtml_part.h"#include "khtml_ext.h"using namespace khtml;RenderFormElement::RenderFormElement(QScrollView *view,                                     HTMLGenericFormElementImpl *element)    : RenderWidget(view){    // init RenderObject attributes    setInline(true);   // our object is Inline    m_element = element;    m_clickCount = 0;    m_state = 0;    m_button = 0;    m_isDoubleClick = false;}RenderFormElement::~RenderFormElement(){}short RenderFormElement::baselinePosition( bool f ) const{    return RenderWidget::baselinePosition( f ) - 2 - QFontMetrics( style()->font() ).descent();}short RenderFormElement::calcReplacedWidth(bool*) const{    Length w = style()->width();    if ( w.isVariable() )        return intrinsicWidth();    else        return RenderReplaced::calcReplacedWidth();}int RenderFormElement::calcReplacedHeight() const{    Length h = style()->height();    if ( h.isVariable() )        return intrinsicHeight();    else        return RenderReplaced::calcReplacedHeight();}void RenderFormElement::layout(){    if ( layouted() ) return;    // minimum height    m_height = 0;    calcWidth();    calcHeight();    if ( m_widget ) {        m_widget->resize( m_width-borderLeft()-borderRight()-paddingLeft()-paddingRight(),                          m_height-borderLeft()-borderRight()-paddingLeft()-paddingRight());        m_widget->setEnabled(!m_element->disabled());	QColor color = style()->color();	QColor backgroundColor = style()->backgroundColor();	if ( color.isValid() || backgroundColor.isValid() ) {	    QPalette pal(m_widget->palette());	    int contrast_ = KGlobalSettings::contrast();	    int highlightVal = 100 + (2*contrast_+4)*16/10;	    int lowlightVal = 100 + (2*contrast_+4)*10;	    if (backgroundColor.isValid()) {		pal.setColor(QPalette::Active,QColorGroup::Background,backgroundColor);		pal.setColor(QPalette::Active,QColorGroup::Light,backgroundColor.light(highlightVal));		pal.setColor(QPalette::Active,QColorGroup::Dark,backgroundColor.dark(lowlightVal));		pal.setColor(QPalette::Active,QColorGroup::Mid,backgroundColor.dark(120));		pal.setColor(QPalette::Active,QColorGroup::Midlight, backgroundColor.light(110));		pal.setColor(QPalette::Active,QColorGroup::Button,backgroundColor);		pal.setColor(QPalette::Active,QColorGroup::Base,backgroundColor);		pal.setColor(QPalette::Inactive,QColorGroup::Background,backgroundColor);		pal.setColor(QPalette::Inactive,QColorGroup::Light,backgroundColor.light(highlightVal));		pal.setColor(QPalette::Inactive,QColorGroup::Dark,backgroundColor.dark(lowlightVal));		pal.setColor(QPalette::Inactive,QColorGroup::Mid,backgroundColor.dark(120));		pal.setColor(QPalette::Inactive,QColorGroup::Midlight, backgroundColor.light(110));		pal.setColor(QPalette::Inactive,QColorGroup::Button,backgroundColor);		pal.setColor(QPalette::Inactive,QColorGroup::Base,backgroundColor);		pal.setColor(QPalette::Disabled,QColorGroup::Background,backgroundColor);		pal.setColor(QPalette::Disabled,QColorGroup::Light,backgroundColor.light(highlightVal));		pal.setColor(QPalette::Disabled,QColorGroup::Dark,backgroundColor.dark(lowlightVal));		pal.setColor(QPalette::Disabled,QColorGroup::Mid,backgroundColor.dark(120));		pal.setColor(QPalette::Disabled,QColorGroup::Text,backgroundColor.dark(120));		pal.setColor(QPalette::Disabled,QColorGroup::Midlight, backgroundColor.light(110));		pal.setColor(QPalette::Disabled,QColorGroup::Button, backgroundColor);		pal.setColor(QPalette::Disabled,QColorGroup::Base,backgroundColor);	    }            if ( color.isValid() ) {		pal.setColor(QPalette::Active,QColorGroup::Foreground,color);		pal.setColor(QPalette::Active,QColorGroup::ButtonText,color);		pal.setColor(QPalette::Active,QColorGroup::Text,color);		pal.setColor(QPalette::Inactive,QColorGroup::Foreground,color);		pal.setColor(QPalette::Inactive,QColorGroup::ButtonText,color);		pal.setColor(QPalette::Inactive,QColorGroup::Text,color);		QColor disfg = color;		int h, s, v;		disfg.hsv( &h, &s, &v );		if (v > 128)		    // dark bg, light fg - need a darker disabled fg		    disfg = disfg.dark(lowlightVal);		else if (disfg != black)		    // light bg, dark fg - need a lighter disabled fg - but only if !black		    disfg = disfg.light(highlightVal);		else		    // black fg - use darkgrey disabled fg		    disfg = Qt::darkGray;		pal.setColor(QPalette::Disabled,QColorGroup::Foreground,disfg);		pal.setColor(QPalette::Disabled,QColorGroup::ButtonText, color);	    }	    m_widget->setPalette(pal);	}        else            m_widget->unsetPalette();    }    if ( !style()->width().isPercent() )        setLayouted();}bool RenderFormElement::eventFilter(QObject* /*o*/, QEvent* e){    if ( !m_element || !m_element->view || !m_element->view->part() ) return true;    ref();    m_element->ref();    switch(e->type()) {    case QEvent::FocusOut:        m_element->dispatchHTMLEvent(EventImpl::BLUR_EVENT,false,false);        if ( isEditable() ) {            KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>( m_element->view->part()->browserExtension() );            if ( ext )  ext->editableWidgetBlurred( m_widget );        }        break;    case QEvent::FocusIn:        m_element->ownerDocument()->setFocusNode(m_element);        if ( isEditable() ) {            KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>( m_element->view->part()->browserExtension() );            if ( ext )  ext->editableWidgetFocused( m_widget );        }        break;    case QEvent::MouseButtonPress:        handleMousePressed(static_cast<QMouseEvent*>(e));        break;    case QEvent::MouseButtonRelease:    {        int absX, absY;        absolutePosition(absX,absY);        QMouseEvent* _e = static_cast<QMouseEvent*>(e);        m_button = _e->button();        m_state  = _e->state();        QMouseEvent e2(e->type(),QPoint(absX,absY)+_e->pos(),_e->button(),_e->state());        m_element->dispatchMouseEvent(&e2,EventImpl::MOUSEUP_EVENT,m_clickCount);        if((m_mousePos - e2.pos()).manhattanLength() <= QApplication::startDragDistance()) {            // DOM2 Events section 1.6.2 says that a click is if the mouse was pressed            // and released in the "same screen location"            // As people usually can't click on the same pixel, we're a bit tolerant here            m_element->dispatchMouseEvent(&e2,EventImpl::CLICK_EVENT,m_clickCount);        }        if(!isRenderButton()) {            // ### DOMActivate is also dispatched for thigs like selects & textareas -            // not sure if this is correct            m_element->dispatchUIEvent(EventImpl::DOMACTIVATE_EVENT,m_isDoubleClick ? 2 : 1);            m_element->dispatchMouseEvent(&e2, m_isDoubleClick ? EventImpl::KHTML_DBLCLICK_EVENT : EventImpl::KHTML_CLICK_EVENT, m_clickCount);            m_isDoubleClick = false;        }        else            // save position for slotClicked - see below -            m_mousePos = e2.pos();    }    break;    case QEvent::MouseButtonDblClick:    {        m_isDoubleClick = true;        handleMousePressed(static_cast<QMouseEvent*>(e));    }    break;    case QEvent::MouseMove:    {        int absX, absY;        absolutePosition(absX,absY);        QMouseEvent* _e = static_cast<QMouseEvent*>(e);        QMouseEvent e2(e->type(),QPoint(absX,absY)+_e->pos(),_e->button(),_e->state());        m_element->dispatchMouseEvent(&e2);        // ### change cursor like in KHTMLView?    }    break;    default: break;    };    m_element->deref();    bool deleted = hasOneRef();    deref();    return deleted;}void RenderFormElement::slotClicked(){    if(isRenderButton()) {        QMouseEvent e2( QEvent::MouseButtonRelease, m_mousePos, m_button, m_state);        m_element->dispatchMouseEvent(&e2, m_isDoubleClick ? EventImpl::KHTML_DBLCLICK_EVENT : EventImpl::KHTML_CLICK_EVENT, m_clickCount);	m_element->dispatchUIEvent(EventImpl::DOMACTIVATE_EVENT,m_isDoubleClick ? 2 : 1);	m_isDoubleClick = false;    }}void RenderFormElement::handleMousePressed(QMouseEvent *e){    int absX, absY;    absolutePosition(absX,absY);    QMouseEvent e2(e->type(),QPoint(absX,absY)+e->pos(),e->button(),e->state());    if((m_mousePos - e2.pos()).manhattanLength() > QApplication::startDragDistance()) {        m_mousePos = e2.pos();        m_clickCount = 1;    }    else        m_clickCount++;    m_element->dispatchMouseEvent(&e2,EventImpl::MOUSEDOWN_EVENT,m_clickCount);}// -------------------------------------------------------------------------RenderButton::RenderButton(QScrollView *view,                           HTMLGenericFormElementImpl *element)    : RenderFormElement(view, element){}short RenderButton::baselinePosition( bool f ) const{    return RenderWidget::baselinePosition( f ) - 2;}// -------------------------------------------------------------------------------RenderCheckBox::RenderCheckBox(QScrollView *view,                               HTMLInputElementImpl *element)    : RenderButton(view, element){    QCheckBox* b = new QCheckBox(view->viewport());    b->setAutoMask(true);    b->setMouseTracking(true);    setQWidget(b);    b->installEventFilter(this);    connect(b,SIGNAL(stateChanged(int)),this,SLOT(slotStateChanged(int)));    connect(b, SIGNAL(clicked()), this, SLOT(slotClicked()));}void RenderCheckBox::calcMinMaxWidth(){    if ( minMaxKnown() ) return;    QSize s = static_cast<QCheckBox*>( m_widget )->style().indicatorSize();    setIntrinsicWidth( s.width() );    setIntrinsicHeight( s.height() );    RenderButton::calcMinMaxWidth();}void RenderCheckBox::layout(){    if ( layouted() ) return;    QCheckBox* cb = static_cast<QCheckBox*>( m_widget );    cb->setChecked(static_cast<HTMLInputElementImpl*>(m_element)->checked());    RenderButton::layout();}void RenderCheckBox::slotStateChanged(int state){    m_element->setAttribute(ATTR_CHECKED,state == 2 ? "" : 0);}// -------------------------------------------------------------------------------RenderRadioButton::RenderRadioButton(QScrollView *view,                                     HTMLInputElementImpl *element)    : RenderButton(view, element){    QRadioButton* b = new QRadioButton(view->viewport());    b->setAutoMask(true);    b->setMouseTracking(true);    setQWidget(b);    b->installEventFilter(this);    connect(b, SIGNAL(clicked()), this, SLOT(slotClicked()));}void RenderRadioButton::setChecked(bool checked){    static_cast<QRadioButton *>(m_widget)->setChecked(checked);}void RenderRadioButton::slotClicked(){    m_element->setAttribute(ATTR_CHECKED,"");    // emit mouseClick event etc    RenderButton::slotClicked();}void RenderRadioButton::calcMinMaxWidth(){    if ( minMaxKnown() ) return;    QSize s = static_cast<QRadioButton*>( m_widget )->style().exclusiveIndicatorSize();    setIntrinsicWidth( s.width() );    setIntrinsicHeight( s.height() );    RenderButton::calcMinMaxWidth();}void RenderRadioButton::layout(){    if ( layouted() ) return;    QRadioButton* rb = static_cast<QRadioButton*>( m_widget );    rb->setChecked(static_cast<HTMLInputElementImpl*>(m_element)->checked());    RenderButton::layout();}// -------------------------------------------------------------------------------RenderSubmitButton::RenderSubmitButton(QScrollView *view, HTMLInputElementImpl *element)    : RenderButton(view, element){    QPushButton* p = new QPushButton(view->viewport());    setQWidget(p);    p->setMouseTracking(true);    p->installEventFilter(this);    connect(p, SIGNAL(clicked()), this, SLOT(slotClicked()));}void RenderSubmitButton::calcMinMaxWidth(){    if ( minMaxKnown() ) return;    QString value = static_cast<HTMLInputElementImpl*>(m_element)->value().isEmpty() ?        defaultLabel() : static_cast<HTMLInputElementImpl*>(m_element)->value().string();    value = value.visual();    value = value.stripWhiteSpace();    QString raw;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -