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

📄 wmlinputelement.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/** * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */#include "config.h"#if ENABLE(WML)#include "WMLInputElement.h"#include "EventNames.h"#include "FormDataList.h"#include "Frame.h"#include "HTMLNames.h"#include "KeyboardEvent.h"#include "RenderTextControlSingleLine.h"#include "TextEvent.h"#include "WMLDocument.h"#include "WMLNames.h"#include "WMLPageState.h"namespace WebCore {WMLInputElement::WMLInputElement(const QualifiedName& tagName, Document* doc)    : WMLFormControlElementWithState(tagName, doc)    , m_data(this, this)    , m_isPasswordField(false)    , m_isEmptyOk(false)    , m_numOfCharsAllowedByMask(0){}WMLInputElement::~WMLInputElement(){    if (m_isPasswordField)        document()->unregisterForDocumentActivationCallbacks(this);}static const AtomicString& formatCodes(){    DEFINE_STATIC_LOCAL(AtomicString, codes, ("AaNnXxMm"));    return codes;}bool WMLInputElement::isKeyboardFocusable(KeyboardEvent*) const{    return WMLFormControlElementWithState::isFocusable();}bool WMLInputElement::isMouseFocusable() const{    return WMLFormControlElementWithState::isFocusable();}void WMLInputElement::dispatchFocusEvent(){    InputElement::dispatchFocusEvent(m_data, document());    WMLElement::dispatchFocusEvent();}void WMLInputElement::dispatchBlurEvent(){    // Firstly check if it is allowed to leave this input field    String val = value();    if ((!m_isEmptyOk && val.isEmpty()) || !isConformedToInputMask(val)) {        updateFocusAppearance(true);        return;    }    // update the name variable of WML input elmenet    String nameVariable = name();    if (!nameVariable.isEmpty())        wmlPageStateForDocument(document())->storeVariable(nameVariable, val);     InputElement::dispatchBlurEvent(m_data, document());    WMLElement::dispatchBlurEvent();}void WMLInputElement::updateFocusAppearance(bool restorePreviousSelection){    InputElement::updateFocusAppearance(m_data, document(), restorePreviousSelection);}void WMLInputElement::aboutToUnload(){    InputElement::aboutToUnload(m_data, document());}int WMLInputElement::size() const{    return m_data.size();}const AtomicString& WMLInputElement::type() const{    // needs to be lowercase according to DOM spec    if (m_isPasswordField) {        DEFINE_STATIC_LOCAL(const AtomicString, password, ("password"));        return password;    }    DEFINE_STATIC_LOCAL(const AtomicString, text, ("text"));    return text;}const AtomicString& WMLInputElement::name() const{    return m_data.name();}String WMLInputElement::value() const{    String value = m_data.value();    if (value.isNull())        value = constrainValue(getAttribute(HTMLNames::valueAttr));    return value;}void WMLInputElement::setValue(const String& value){    InputElement::updatePlaceholderVisibility(m_data, document());    setValueMatchesRenderer(false);    m_data.setValue(constrainValue(value));    if (inDocument())        document()->updateRendering();    if (renderer())        renderer()->updateFromElement();    setChanged();    unsigned max = m_data.value().length();    if (document()->focusedNode() == this)        InputElement::updateSelectionRange(m_data, max, max);    else        cacheSelection(max, max);    InputElement::notifyFormStateChanged(m_data, document());}void WMLInputElement::setValueFromRenderer(const String& value){    InputElement::setValueFromRenderer(m_data, document(), value);}bool WMLInputElement::saveState(String& result) const{    if (m_isPasswordField)        return false;    result = value();    return true;}void WMLInputElement::restoreState(const String& state){    ASSERT(!m_isPasswordField); // should never save/restore password fields    setValue(state);}void WMLInputElement::select(){    if (RenderTextControl* r = toRenderTextControl(renderer()))        r->select();}void WMLInputElement::accessKeyAction(bool){    // should never restore previous selection here    focus(false);}void WMLInputElement::parseMappedAttribute(MappedAttribute* attr){    if (attr->name() == HTMLNames::nameAttr)        m_data.setName(parseValueForbiddingVariableReferences(attr->value()));    else if (attr->name() == HTMLNames::typeAttr) {        String type = parseValueForbiddingVariableReferences(attr->value());        m_isPasswordField = (type == "password");    } else if (attr->name() == HTMLNames::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() == HTMLNames::maxlengthAttr)        InputElement::parseMaxLengthAttribute(m_data, attr);    else if (attr->name() == HTMLNames::sizeAttr)        InputElement::parseSizeAttribute(m_data, attr);    else if (attr->name() == WMLNames::formatAttr)        m_formatMask = validateInputMask(parseValueForbiddingVariableReferences(attr->value()));    else if (attr->name() == WMLNames::emptyokAttr)        m_isEmptyOk = (attr->value() == "true");    else        WMLElement::parseMappedAttribute(attr);    // FIXME: Handle 'accesskey' attribute    // FIXME: Handle 'tabindex' attribute    // FIXME: Handle 'title' attribute}void WMLInputElement::copyNonAttributeProperties(const Element* source){    const WMLInputElement* sourceElement = static_cast<const WMLInputElement*>(source);    m_data.setValue(sourceElement->m_data.value());    WMLElement::copyNonAttributeProperties(source);}RenderObject* WMLInputElement::createRenderer(RenderArena* arena, RenderStyle*){    return new (arena) RenderTextControlSingleLine(this);}void WMLInputElement::attach(){    ASSERT(!attached());    WMLElement::attach();    // The call to updateFromElement() needs to go after the call through    // to the base class's attach() because that can sometimes do a close    // on the renderer.    if (renderer())        renderer()->updateFromElement();    // FIXME: maybe this is not a good place to do this since it is possible     // to cause unexpected several times initialise of <input> if we force the    // node to be reattached. But placing it here can ensure the run-webkit-tests    // get expected result,i.e. multiple-times initialise is expected when making    // layout test for WMLInputElement     init();}  void WMLInputElement::detach(){    WMLElement::detach();    setValueMatchesRenderer(false);}    bool WMLInputElement::appendFormData(FormDataList& encoding, bool){    if (name().isEmpty())        return false;    encoding.appendData(name(), value());    return true;}void WMLInputElement::reset(){    setValue(String());}

⌨️ 快捷键说明

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