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

📄 html_formimpl.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    switch (m_type) {        case HIDDEN:        case TEXT:#if APPLE_CHANGES        case SEARCH:        case RANGE:#endif        case PASSWORD:            // always successful            encoding += fixUpfromUnicode(codec, value().string());            return true;        case CHECKBOX:            if( checked() ) {                encoding += fixUpfromUnicode(codec, value().string());                return true;            }            break;        case RADIO:            if( checked() ) {                encoding += fixUpfromUnicode(codec, value().string());                return true;            }            break;        case BUTTON:        case RESET:            // those buttons are never successful            return false;        case IMAGE:            if(m_activeSubmit)            {                QString astr(nme.isEmpty() ? QString::fromLatin1("x") : nme + ".x");                encoding += fixUpfromUnicode(codec, astr);                astr.setNum(clickX());                encoding += fixUpfromUnicode(codec, astr);                astr = nme.isEmpty() ? QString::fromLatin1("y") : nme + ".y";                encoding += fixUpfromUnicode(codec, astr);                astr.setNum(clickY());                encoding += fixUpfromUnicode(codec, astr);                return true;            }            break;        case SUBMIT:            if (m_activeSubmit)            {                QString enc_str = value().string();                if (enc_str.isEmpty())                    enc_str = static_cast<RenderSubmitButton*>(m_render)->defaultLabel();                if (!enc_str.isEmpty()) {                    encoding += fixUpfromUnicode(codec, enc_str);                    return true;                }            }            break;        case FILE:        {            // can't submit file on GET            // don't submit if display: none or display: hidden            if(!multipart || !renderer() || renderer()->style()->visibility() != khtml::VISIBLE)                return false;                        QString local;            QCString dummy("");                        // if no filename at all is entered, return successful, however empty            // null would be more logical but netscape posts an empty file. argh.            if(value().isEmpty()) {                encoding += dummy;                return true;            }            KURL fileurl("file:///");            fileurl.setPath(value().string());            KIO::UDSEntry filestat;                        if (!KIO::NetAccess::stat(fileurl, filestat)) {#if APPLE_CHANGES                LOG(KwiqLog, "Error fetching file for submission %s", fileurl.url().latin1() );                // FIXME: Figure out how to report this error.#else                KMessageBox::sorry(0L, i18n("Error fetching file for submission:\n%1").arg(KIO::NetAccess::lastErrorString()));#endif                return false;            }            KFileItem fileitem(filestat, fileurl, true, false);            if(fileitem.isDir()) {                encoding += dummy;                return false;            }            if ( KIO::NetAccess::download(fileurl, local) )            {                                QFile file(local);                if (file.open(IO_ReadOnly))                {                    QCString filearray(file.size()+1);                    int readbytes = file.readBlock( filearray.data(), file.size());                    if ( readbytes >= 0 )                        filearray[readbytes] = '\0';                    file.close();                    encoding += filearray;                    KIO::NetAccess::removeTempFile( local );                    return true;                }                return false;            }            else {#if APPLE_CHANGES                                LOG(KwiqLog, "Error fetching file for submission %s", fileurl.url().latin1() );                // FIXME: Figure out how to report this error.#else                KMessageBox::sorry(0L, i18n("Error fetching file for submission:\n%1").arg(KIO::NetAccess::lastErrorString()));#endif                return false;            }            break;        }        case ISINDEX:            encoding += fixUpfromUnicode(codec, value().string());            return true;    }    return false;}void HTMLInputElementImpl::reset(){    setValue(DOMString());    setChecked(m_defaultChecked);    m_useDefaultChecked = true;}void HTMLInputElementImpl::setChecked(bool _checked){    if (checked() == _checked) return;    if (m_form && m_type == RADIO && _checked && !name().isEmpty())        m_form->radioClicked(this);    m_useDefaultChecked = false;    m_checked = _checked;    setChanged();}DOMString HTMLInputElementImpl::value() const{    if (m_type == CHECKBOX || m_type == RADIO) {        DOMString val = getAttribute(ATTR_VALUE);        // If no attribute exists, then just use "on" or "" based off the checked() state        // of the control.        if (val.isNull()) {            if (checked())                return DOMString("on");            else                return DOMString("");        }        return val;    }    // It's important *not* to fall back to the value attribute for file inputs,    // because that would allow a malicious web page to upload files by setting the    // value attribute in markup.    if (m_value.isNull() && m_type != FILE)        return getAttribute(ATTR_VALUE);    return m_value;}void HTMLInputElementImpl::setValue(DOMString val){    if (m_type == FILE) return;    m_value = val;    setChanged();}void HTMLInputElementImpl::blur(){    if(getDocument()->focusNode() == this)	getDocument()->setFocusNode(0);}void HTMLInputElementImpl::focus(){    getDocument()->setFocusNode(this);}void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt){    if (evt->isMouseEvent() &&        ( evt->id() == EventImpl::KHTML_CLICK_EVENT || evt->id() == EventImpl::KHTML_DBLCLICK_EVENT ) &&        m_type == IMAGE        && m_render) {        // record the mouse position for when we get the DOMActivate event        MouseEventImpl *me = static_cast<MouseEventImpl*>(evt);        int offsetX, offsetY;        m_render->absolutePosition(offsetX,offsetY);        xPos = me->clientX()-offsetX;        yPos = me->clientY()-offsetY;	me->setDefaultHandled();    }    // DOMActivate events cause the input to be "activated" - in the case of image and submit inputs, this means    // actually submitting the form. For reset inputs, the form is reset. These events are sent when the user clicks    // on the element, or presses enter while it is the active element. Javacsript code wishing to activate the element    // must dispatch a DOMActivate event - a click event will not do the job.    if ((evt->id() == EventImpl::DOMACTIVATE_EVENT) &&        (m_type == IMAGE || m_type == SUBMIT || m_type == RESET)){        if (!m_form || !m_render)            return;        if (m_type == RESET) {            m_form->reset();        }        else {            m_activeSubmit = true;            if (!m_form->prepareSubmit()) {                xPos = 0;                yPos = 0;            }            m_activeSubmit = false;        }    }#if APPLE_CHANGES    // Use key press event here since sending simulated mouse events    // on key down blocks the proper sending of the key press event.    if (evt->id() == EventImpl::KEYPRESS_EVENT && evt->isKeyboardEvent()) {        DOMString key = static_cast<KeyboardEventImpl *>(evt)->keyIdentifier();        switch (m_type) {            case BUTTON:            case CHECKBOX:            case FILE:            case IMAGE:            case RADIO:            case RESET:            case SUBMIT:                // Simulate mouse click for enter or spacebar for these types of elements.                // The AppKit already does this for spacebar for some, but not all, of them.                if (key == "U+000020" || key == "Enter") {                    click();                    evt->setDefaultHandled();                }                break;            case HIDDEN:            case ISINDEX:            case PASSWORD:            case RANGE:            case SEARCH:            case TEXT:                // Simulate mouse click on the default form button for enter for these types of elements.                if (key == "Enter" && m_form) {                    m_form->submitClick();                    evt->setDefaultHandled();                }                break;        }    }#endif    HTMLGenericFormElementImpl::defaultEventHandler(evt);}bool HTMLInputElementImpl::isEditable(){    return ((m_type == TEXT) || (m_type == PASSWORD) ||            (m_type == SEARCH) || (m_type == ISINDEX) || (m_type == FILE));}bool HTMLInputElementImpl::isURLAttribute(AttributeImpl *attr) const{    return (attr->id() == ATTR_SRC);}// -------------------------------------------------------------------------HTMLLabelElementImpl::HTMLLabelElementImpl(DocumentPtr *doc)    : HTMLElementImpl(doc){}HTMLLabelElementImpl::~HTMLLabelElementImpl(){}bool HTMLLabelElementImpl::isFocusable() const{    return false;}NodeImpl::Id HTMLLabelElementImpl::id() const{    return ID_LABEL;}void HTMLLabelElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr){    switch(attr->id())    {    case ATTR_ONFOCUS:        setHTMLEventListener(EventImpl::FOCUS_EVENT,            getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_ONBLUR:        setHTMLEventListener(EventImpl::BLUR_EVENT,            getDocument()->createHTMLEventListener(attr->value().string()));        break;    default:        HTMLElementImpl::parseHTMLAttribute(attr);    }}ElementImpl *HTMLLabelElementImpl::formElement(){    DOMString formElementId = getAttribute(ATTR_FOR);    if (formElementId.isNull() || formElementId.isEmpty())        return 0;    return getDocument()->getElementById(formElementId);}// -------------------------------------------------------------------------HTMLLegendElementImpl::HTMLLegendElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f): HTMLGenericFormElementImpl(doc, f){}HTMLLegendElementImpl::~HTMLLegendElementImpl(){}bool HTMLLegendElementImpl::isFocusable() const{    return false;}NodeImpl::Id HTMLLegendElementImpl::id() const{    return ID_LEGEND;}RenderObject* HTMLLegendElementImpl::createRenderer(RenderArena* arena, RenderStyle* style){    return new (arena) RenderLegend(this);}DOMString HTMLLegendElementImpl::type() const{    return "legend";}// -------------------------------------------------------------------------HTMLSelectElementImpl::HTMLSelectElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f)    : HTMLGenericFormElementImpl(doc, f), m_options(0){    m_multiple = false;    m_recalcListItems = false;    // 0 means invalid (i.e. not set)    m_size = 0;    m_minwidth = 0;}HTMLSelectElementImpl::~HTMLSelectElementImpl(){    if (getDocument()) getDocument()->deregisterMaintainsState(this);    if (m_options) {        m_options->detach();        m_options->deref();    }}NodeImpl::Id HTMLSelectElementImpl::id() const{    return ID_SELECT;}void HTMLSelectElementImpl::recalcStyle( StyleChange ch ){    if (hasChangedChild() && m_render) {        static_cast<khtml::RenderSelect*>(m_render)->setOptionsChanged(true);    }    HTMLGenericFormElementImpl::recalcStyle( ch );}DOMString HTMLSelectElementImpl::type() const{    return (m_multiple ? "select-multiple" : "select-one");}long HTMLSelectElementImpl::selectedIndex() const{    // return the number of the first option selected    uint o = 0;    QMemArray<HTMLGenericFormElementImpl*> items = listItems();    for (unsigned int i = 0; i < items.size(); i++) {        if (items[i]->id() == ID_OPTION) {            if (static_cast<HTMLOptionElementImpl*>(items[i])->selected())                return o;            o++;        }    }    Q_ASSERT(m_multiple);    return -1;}void HTMLSelectElementImpl::setSelectedIndex( long  index ){    // deselect all other options and select only the new one    QMemArray<HTMLGenericFormElementImpl*> items = listItems();    int listIndex;    for (listIndex = 0; listIndex < int(items.size()); listIndex++) {        if (items[listIndex]->id() == ID_OPTION)            static_cast<HTMLOptionElementImp

⌨️ 快捷键说明

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