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

📄 htmlinputelement.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        case FILE:        case HIDDEN:        case IMAGE:        case ISINDEX:        case RANGE:        case RESET:        case SEARCH:        case SUBMIT:        case TEXT:            setValue(state);            break;        case CHECKBOX:        case RADIO:            setChecked(state == "on");            break;        case PASSWORD:            break;    }}bool HTMLInputElement::canStartSelection() const{    if (!isTextField())        return false;    return HTMLFormControlElementWithState::canStartSelection();}bool HTMLInputElement::canHaveSelection() const{    return isTextField();}int HTMLInputElement::selectionStart() const{    if (!isTextField())        return 0;    if (document()->focusedNode() != this && m_data.cachedSelectionStart() != -1)        return m_data.cachedSelectionStart();    if (!renderer())        return 0;    return toRenderTextControl(renderer())->selectionStart();}int HTMLInputElement::selectionEnd() const{    if (!isTextField())        return 0;    if (document()->focusedNode() != this && m_data.cachedSelectionEnd() != -1)        return m_data.cachedSelectionEnd();    if (!renderer())        return 0;    return toRenderTextControl(renderer())->selectionEnd();}void HTMLInputElement::setSelectionStart(int start){    if (!isTextField())        return;    if (!renderer())        return;    toRenderTextControl(renderer())->setSelectionStart(start);}void HTMLInputElement::setSelectionEnd(int end){    if (!isTextField())        return;    if (!renderer())        return;    toRenderTextControl(renderer())->setSelectionEnd(end);}void HTMLInputElement::select(){    if (!isTextField())        return;    if (!renderer())        return;    toRenderTextControl(renderer())->select();}void HTMLInputElement::setSelectionRange(int start, int end){    InputElement::updateSelectionRange(m_data, start, end);}void HTMLInputElement::accessKeyAction(bool sendToAnyElement){    switch (inputType()) {        case BUTTON:        case CHECKBOX:        case FILE:        case IMAGE:        case RADIO:        case RANGE:        case RESET:        case SUBMIT:            focus(false);            // send the mouse button events iff the caller specified sendToAnyElement            dispatchSimulatedClick(0, sendToAnyElement);            break;        case HIDDEN:            // a no-op for this type            break;        case ISINDEX:        case PASSWORD:        case SEARCH:        case TEXT:            // should never restore previous selection here            focus(false);            break;    }}bool HTMLInputElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const{    if (((attrName == heightAttr || attrName == widthAttr) && respectHeightAndWidthAttrs()) ||        attrName == vspaceAttr ||        attrName == hspaceAttr) {        result = eUniversal;        return false;    }     if (attrName == alignAttr) {        if (inputType() == IMAGE) {            // Share with <img> since the alignment behavior is the same.            result = eReplaced;            return false;        }    }    return HTMLElement::mapToEntry(attrName, result);}void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr){    if (attr->name() == nameAttr) {        checkedRadioButtons(this).removeButton(this);        m_data.setName(attr->value());        checkedRadioButtons(this).addButton(this);    } else if (attr->name() == autocompleteAttr) {        if (equalIgnoringCase(attr->value(), "off")) {            m_autocomplete = Off;            registerForActivationCallbackIfNeeded();        } else {            if (m_autocomplete == Off)                unregisterForActivationCallbackIfNeeded();            if (attr->isEmpty())                m_autocomplete = Uninitialized;            else                m_autocomplete = On;        }    } else if (attr->name() == typeAttr) {        setInputType(attr->value());    } else if (attr->name() == valueAttr) {        // We only need to setChanged if the form is looking at the default value right now.        if (m_data.value().isNull())            setChanged();        setValueMatchesRenderer(false);    } else if (attr->name() == checkedAttr) {        m_defaultChecked = !attr->isNull();        if (m_useDefaultChecked) {            setChecked(m_defaultChecked);            m_useDefaultChecked = true;        }    } else if (attr->name() == maxlengthAttr)        InputElement::parseMaxLengthAttribute(m_data, attr);    else if (attr->name() == sizeAttr)        InputElement::parseSizeAttribute(m_data, attr);    else if (attr->name() == altAttr) {        if (renderer() && inputType() == IMAGE)            toRenderImage(renderer())->updateAltText();    } else if (attr->name() == srcAttr) {        if (renderer() && inputType() == IMAGE) {            if (!m_imageLoader)                m_imageLoader.set(new HTMLImageLoader(this));            m_imageLoader->updateFromElementIgnoringPreviousError();        }    } else if (attr->name() == usemapAttr ||               attr->name() == accesskeyAttr) {        // FIXME: ignore for the moment    } else if (attr->name() == vspaceAttr) {        addCSSLength(attr, CSSPropertyMarginTop, attr->value());        addCSSLength(attr, CSSPropertyMarginBottom, attr->value());    } else if (attr->name() == hspaceAttr) {        addCSSLength(attr, CSSPropertyMarginLeft, attr->value());        addCSSLength(attr, CSSPropertyMarginRight, attr->value());    } else if (attr->name() == alignAttr) {        if (inputType() == IMAGE)            addHTMLAlignment(attr);    } else if (attr->name() == widthAttr) {        if (respectHeightAndWidthAttrs())            addCSSLength(attr, CSSPropertyWidth, attr->value());    } else if (attr->name() == heightAttr) {        if (respectHeightAndWidthAttrs())            addCSSLength(attr, CSSPropertyHeight, attr->value());    } else if (attr->name() == onfocusAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().focusEvent, attr);    } else if (attr->name() == onblurAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().blurEvent, attr);    } else if (attr->name() == onselectAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().selectEvent, attr);    } else if (attr->name() == onchangeAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().changeEvent, attr);    } else if (attr->name() == oninputAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().inputEvent, attr);    }    // Search field and slider attributes all just cause updateFromElement to be called through style    // recalcing.    else if (attr->name() == onsearchAttr) {        setInlineEventListenerForTypeAndAttribute(eventNames().searchEvent, attr);    } else if (attr->name() == resultsAttr) {        int oldResults = m_maxResults;        m_maxResults = !attr->isNull() ? min(attr->value().toInt(), maxSavedResults) : -1;        // FIXME: Detaching just for maxResults change is not ideal.  We should figure out the right        // time to relayout for this change.        if (m_maxResults != oldResults && (m_maxResults <= 0 || oldResults <= 0) && attached()) {            detach();            attach();        }        setChanged();    } else if (attr->name() == placeholderAttr) {        if (isTextField())            InputElement::updatePlaceholderVisibility(m_data, document(), true);    } else if (attr->name() == autosaveAttr ||             attr->name() == incrementalAttr ||             attr->name() == minAttr ||             attr->name() == maxAttr ||             attr->name() == multipleAttr ||             attr->name() == precisionAttr)        setChanged();    else        HTMLFormControlElementWithState::parseMappedAttribute(attr);}bool HTMLInputElement::rendererIsNeeded(RenderStyle *style){    switch (inputType()) {        case BUTTON:        case CHECKBOX:        case FILE:        case IMAGE:        case ISINDEX:        case PASSWORD:        case RADIO:        case RANGE:        case RESET:        case SEARCH:        case SUBMIT:        case TEXT:            return HTMLFormControlElementWithState::rendererIsNeeded(style);        case HIDDEN:            return false;    }    ASSERT(false);    return false;}RenderObject *HTMLInputElement::createRenderer(RenderArena *arena, RenderStyle *style){    switch (inputType()) {        case BUTTON:        case RESET:        case SUBMIT:            return new (arena) RenderButton(this);        case CHECKBOX:        case RADIO:            return RenderObject::createObject(this, style);        case FILE:            return new (arena) RenderFileUploadControl(this);        case HIDDEN:            break;        case IMAGE:            return new (arena) RenderImage(this);        case RANGE:            return new (arena) RenderSlider(this);        case ISINDEX:        case PASSWORD:        case SEARCH:        case TEXT:            return new (arena) RenderTextControlSingleLine(this);    }    ASSERT(false);    return 0;}void HTMLInputElement::attach(){    if (!m_inited) {        if (!m_haveType)            setInputType(getAttribute(typeAttr));        m_inited = true;    }    HTMLFormControlElementWithState::attach();    if (inputType() == IMAGE) {        if (!m_imageLoader)            m_imageLoader.set(new HTMLImageLoader(this));        m_imageLoader->updateFromElement();        if (renderer()) {            RenderImage* imageObj = toRenderImage(renderer());            imageObj->setCachedImage(m_imageLoader->image());                         // If we have no image at all because we have no src attribute, set            // image height and width for the alt text instead.            if (!m_imageLoader->image() && !imageObj->cachedImage())                imageObj->setImageSizeForAltText();        }    }}void HTMLInputElement::detach(){    HTMLFormControlElementWithState::detach();    setValueMatchesRenderer(false);}String HTMLInputElement::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 HTMLImageElement::altText()    String alt = getAttribute(altAttr);    // fall back to title attribute    if (alt.isNull())        alt = getAttribute(titleAttr);    if (alt.isNull())        alt = getAttribute(valueAttr);    if (alt.isEmpty())        alt = inputElementAltText();    return alt;}bool HTMLInputElement::isSuccessfulSubmitButton() const{    // HTML spec says that buttons must have names to be considered successful.    // However, other browsers do not impose this constraint. So we do likewise.    return !disabled() && (inputType() == IMAGE || inputType() == SUBMIT);}bool HTMLInputElement::isActivatedSubmit() const{    return m_activeSubmit;}void HTMLInputElement::setActivatedSubmit(bool flag){    m_activeSubmit = flag;}bool HTMLInputElement::appendFormData(FormDataList& encoding, bool multipart){    // image generates its own names, but for other types there is no form data unless there's a name    if (name().isEmpty() && inputType() != IMAGE)        return false;    switch (inputType()) {        case HIDDEN:        case ISINDEX:        case PASSWORD:        case RANGE:        case SEARCH:        case TEXT:            // always successful            encoding.appendData(name(), value());            return true;        case CHECKBOX:        case RADIO:            if (checked()) {                encoding.appendData(name(), value());                return true;            }            break;        case BUTTON:        case RESET:            // these types of buttons are never successful            return false;        case IMAGE:            if (m_activeSubmit) {                encoding.appendData(name().isEmpty() ? "x" : (name() + ".x"), m_xPos);                encoding.appendData(name().isEmpty() ? "y" : (name() + ".y"), m_yPos);                if (!name().isEmpty() && !value().isEmpty())                    encoding.appendData(name(), value());                return true;            }            break;        case SUBMIT:            if (m_activeSubmit) {

⌨️ 快捷键说明

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