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

📄 html_formimpl.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
DOMString HTMLInputElementImpl::type() const{    // needs to be lowercase according to DOM spec    switch (m_type) {    case TEXT: return "text";    case PASSWORD: return "password";    case CHECKBOX: return "checkbox";    case RADIO: return "radio";    case SUBMIT: return "submit";    case RESET: return "reset";    case FILE: return "file";    case HIDDEN: return "hidden";    case IMAGE: return "image";    case BUTTON: return "button";#if APPLE_CHANGES    case SEARCH: return "search";    case RANGE: return "range";#endif    default: return "";    }}QString HTMLInputElementImpl::state( ){    assert(m_type != PASSWORD);		// should never save/restore password fields    QString state = HTMLGenericFormElementImpl::state();    switch (m_type) {    case CHECKBOX:    case RADIO:        return state + (checked() ? "on" : "off");    default:        return state + value().string()+'.'; // Make sure the string is not empty!    }}void HTMLInputElementImpl::restoreState(QStringList &states){    assert(m_type != PASSWORD);		// should never save/restore password fields        QString state = HTMLGenericFormElementImpl::findMatchingState(states);    if (state.isNull()) return;    switch (m_type) {    case CHECKBOX:    case RADIO:        setChecked((state == "on"));        break;    default:        setValue(DOMString(state.left(state.length()-1)));        break;    }}void HTMLInputElementImpl::select(  ){    if(!m_render) return;    if (m_type == TEXT || m_type == PASSWORD)        static_cast<RenderLineEdit*>(m_render)->select();    else if (m_type == FILE)        static_cast<RenderFileButton*>(m_render)->select();}void HTMLInputElementImpl::click(){    switch (inputType()) {        case HIDDEN:            // a no-op for this type            break;        case CHECKBOX:        case RADIO:        case SUBMIT:        case RESET:        case BUTTON: #if APPLE_CHANGES        {            QWidget *widget;            if (renderer() && (widget = static_cast<RenderWidget *>(renderer())->widget())) {                // using this method gives us nice Cocoa user interface feedback                static_cast<QButton *>(widget)->click();                break;            }        }#endif            HTMLGenericFormElementImpl::click();            break;        case FILE:#if APPLE_CHANGES            if (renderer()) {                static_cast<RenderFileButton *>(renderer())->click();                break;            }#endif            HTMLGenericFormElementImpl::click();            break;        case IMAGE:        case ISINDEX:        case PASSWORD:#if APPLE_CHANGES        case SEARCH:        case RANGE:#endif        case TEXT:            HTMLGenericFormElementImpl::click();            break;    }}void HTMLInputElementImpl::accessKeyAction(){    switch (inputType()) {        case HIDDEN:            // a no-op for this type            break;        case TEXT:        case PASSWORD:#if APPLE_CHANGES        case SEARCH:#endif        case ISINDEX:            focus();            break;        case CHECKBOX:        case RADIO:        case SUBMIT:        case RESET:        case IMAGE:        case BUTTON:        case FILE:#if APPLE_CHANGES        case RANGE:#endif            // focus and click            focus();            click();            break;    }}bool HTMLInputElementImpl::mapToEntry(NodeImpl::Id attr, MappedAttributeEntry& result) const{    switch (attr) {        case ATTR_WIDTH:        case ATTR_HEIGHT:        case ATTR_VSPACE:        case ATTR_HSPACE:            result = eUniversal;            return false;        case ATTR_ALIGN:            result = eReplaced; // Share with <img> since the alignment behavior is the same.            return false;        default:            break;    }        return HTMLElementImpl::mapToEntry(attr, result);}void HTMLInputElementImpl::parseHTMLAttribute(HTMLAttributeImpl *attr){    switch(attr->id())    {    case ATTR_AUTOCOMPLETE:        m_autocomplete = strcasecmp( attr->value(), "off" );        break;    case ATTR_TYPE:        setType(attr->value());        if (m_type != IMAGE && m_imageLoader) {            delete m_imageLoader;            m_imageLoader = 0;        }        break;    case ATTR_VALUE:        if (m_value.isNull()) // We only need to setChanged if the form is looking            setChanged();     // at the default value right now.        break;    case ATTR_CHECKED:        m_defaultChecked = !attr->isNull();        if (m_useDefaultChecked) {            setChecked(m_defaultChecked);            m_useDefaultChecked = true;        }        break;    case ATTR_MAXLENGTH:        m_maxLen = !attr->isNull() ? attr->value().toInt() : -1;        setChanged();        break;    case ATTR_SIZE:        m_size = !attr->isNull() ? attr->value().toInt() : 20;        break;    case ATTR_ALT:        if (m_render && m_type == IMAGE)            static_cast<RenderImage*>(m_render)->updateAltText();        break;    case ATTR_SRC:        if (m_render && m_type == IMAGE) {            if (!m_imageLoader)                m_imageLoader = new HTMLImageLoader(this);            m_imageLoader->updateFromElement();        }        break;    case ATTR_USEMAP:    case ATTR_ACCESSKEY:        // ### ignore for the moment        break;    case ATTR_VSPACE:        addCSSLength(attr, CSS_PROP_MARGIN_TOP, attr->value());        addCSSLength(attr, CSS_PROP_MARGIN_BOTTOM, attr->value());        break;    case ATTR_HSPACE:        addCSSLength(attr, CSS_PROP_MARGIN_LEFT, attr->value());        addCSSLength(attr, CSS_PROP_MARGIN_RIGHT, attr->value());        break;            case ATTR_ALIGN:        addHTMLAlignment(attr);        break;    case ATTR_WIDTH:        addCSSLength(attr, CSS_PROP_WIDTH, attr->value() );        break;    case ATTR_HEIGHT:        addCSSLength(attr, CSS_PROP_HEIGHT, attr->value() );        break;    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;    case ATTR_ONSELECT:        setHTMLEventListener(EventImpl::SELECT_EVENT,            getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_ONCHANGE:        setHTMLEventListener(EventImpl::CHANGE_EVENT,            getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_ONINPUT:        setHTMLEventListener(EventImpl::INPUT_EVENT,                             getDocument()->createHTMLEventListener(attr->value().string()));        break;#if APPLE_CHANGES    // Search field and slider attributes all just cause updateFromElement to be called through style    // recalcing.    case ATTR_ONSEARCH:        setHTMLEventListener(EventImpl::SEARCH_EVENT,                             getDocument()->createHTMLEventListener(attr->value().string()));        break;    case ATTR_RESULTS:        m_maxResults = !attr->isNull() ? attr->value().toInt() : 0;        /* Fall through */    case ATTR_AUTOSAVE:    case ATTR_INCREMENTAL:    case ATTR_PLACEHOLDER:    case ATTR_MIN:    case ATTR_MAX:    case ATTR_PRECISION:        setChanged();        break;#endif    default:        HTMLGenericFormElementImpl::parseHTMLAttribute(attr);    }}bool HTMLInputElementImpl::rendererIsNeeded(RenderStyle *style){    switch(m_type)    {    case TEXT:    case PASSWORD:#if APPLE_CHANGES    case SEARCH:    case RANGE:#endif    case ISINDEX:    case CHECKBOX:    case RADIO:    case SUBMIT:    case IMAGE:    case RESET:    case FILE:    case BUTTON:   return HTMLGenericFormElementImpl::rendererIsNeeded(style);    case HIDDEN:   return false;    }    assert(false);    return false;}RenderObject *HTMLInputElementImpl::createRenderer(RenderArena *arena, RenderStyle *style){    switch(m_type)    {    case TEXT:    case PASSWORD:#if APPLE_CHANGES    case SEARCH:#endif    case ISINDEX:  return new (arena) RenderLineEdit(this);    case CHECKBOX: return new (arena) RenderCheckBox(this);    case RADIO:    {RenderObject *o = new (arena) RenderRadioButton(this); if (m_form) m_form->updateRadioGroups(); return o;}    case SUBMIT:   return new (arena) RenderSubmitButton(this);    case IMAGE:    return new (arena) RenderImageButton(this);    case RESET:    return new (arena) RenderResetButton(this);    case FILE:     return new (arena) RenderFileButton(this);    case BUTTON:   return new (arena) RenderPushButton(this);#if KWIQ    case RANGE:    break;#elif APPLE_CHANGES    case RANGE:    return new (arena) RenderSlider(this);#endif    case HIDDEN:   break;    }    assert(false);    return 0;}void HTMLInputElementImpl::attach(){    if (!m_inited) {        if (!m_haveType)            setType(getAttribute(ATTR_TYPE));        // FIXME: This needs to be dynamic, doesn't it, since someone could set this        // after attachment?        DOMString val = getAttribute(ATTR_VALUE);        if ((uint) m_type <= ISINDEX && !val.isEmpty()) {            // remove newline stuff..            QString nvalue;            for (unsigned int i = 0; i < val.length(); ++i)                if (val[i] >= ' ')                    nvalue += val[i];            if (val.length() != nvalue.length())                setAttribute(ATTR_VALUE, nvalue);        }        m_defaultChecked = (!getAttribute(ATTR_CHECKED).isNull());                m_inited = true;    }    // Disallow the width attribute on inputs other than HIDDEN and IMAGE.    // Dumb Web sites will try to set the width as an attribute on form controls that aren't    // images or hidden.    if (hasMappedAttributes() && m_type != HIDDEN && m_type != IMAGE && !getAttribute(ATTR_WIDTH).isEmpty()) {        int excCode;        removeAttribute(ATTR_WIDTH, excCode);    }    HTMLGenericFormElementImpl::attach();    if (m_type == IMAGE) {        if (!m_imageLoader)            m_imageLoader = new HTMLImageLoader(this);        m_imageLoader->updateFromElement();        if (renderer()) {            RenderImage* imageObj = static_cast<RenderImage*>(renderer());            imageObj->setImage(m_imageLoader->image());            }    }#ifdef KWIQ    if (renderer()){	if (inputType() == HTMLInputElementImpl::RADIO)	    if (m_form) m_form->updateRadioGroups();    }#endif#if APPLE_CHANGES    // note we don't deal with calling passwordFieldRemoved() on detach, because the timing    // was such that it cleared our state too early    if (m_type == PASSWORD)        getDocument()->passwordFieldAdded();#endif}DOMString HTMLInputElementImpl::altText() const{    // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen    // also heavily discussed by Hixie on bugzilla    // note this is intentionally different to HTMLImageElementImpl::altText()    DOMString alt = getAttribute( ATTR_ALT );    // fall back to title attribute    if ( alt.isNull() )        alt = getAttribute( ATTR_TITLE );    if ( alt.isNull() )        alt = getAttribute( ATTR_VALUE );    if ( alt.isEmpty() )#if APPLE_CHANGES        alt = inputElementAltText();#else        alt = i18n( "Submit" );#endif    return alt;}bool HTMLInputElementImpl::isSuccessfulSubmitButton() const{    // HTML spec says that buttons must have names    // to be considered successful. However, other browsers    // do not impose this constraint. Therefore, we behave    // differently and can use different buttons than the     // author intended.     // Was: (m_type == SUBMIT && !name().isEmpty())    return !m_disabled && (m_type == IMAGE || m_type == SUBMIT);}bool HTMLInputElementImpl::isActivatedSubmit() const{    return m_activeSubmit;}void HTMLInputElementImpl::setActivatedSubmit(bool flag){    m_activeSubmit = flag;}bool HTMLInputElementImpl::encoding(const QTextCodec* codec, khtml::encodingList& encoding, bool multipart){    QString nme = name().string();    // image generates its own name's    if (nme.isEmpty() && m_type != IMAGE) return false;    // IMAGE needs special handling later    if(m_type != IMAGE) encoding += fixUpfromUnicode(codec, nme);

⌨️ 快捷键说明

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