diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-24 16:36:50 +0100 |
commit | ad0d549d4cc13433f77c1ac8f0ab379c83d93f28 (patch) | |
tree | b34b0daceb7c8e7fdde4b4ec43650ab7caadb0a9 /Source/WebCore/html/HTMLInputElement.cpp | |
parent | 03e12282df9aa1e1fb05a8b90f1cfc2e08764cec (diff) | |
download | qtwebkit-ad0d549d4cc13433f77c1ac8f0ab379c83d93f28.tar.gz |
Imported WebKit commit bb52bf3c0119e8a128cd93afe5572413a8617de9 (http://svn.webkit.org/repository/webkit/trunk@108790)
Diffstat (limited to 'Source/WebCore/html/HTMLInputElement.cpp')
-rw-r--r-- | Source/WebCore/html/HTMLInputElement.cpp | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/Source/WebCore/html/HTMLInputElement.cpp b/Source/WebCore/html/HTMLInputElement.cpp index 960040fdd..422ac8513 100644 --- a/Source/WebCore/html/HTMLInputElement.cpp +++ b/Source/WebCore/html/HTMLInputElement.cpp @@ -51,6 +51,7 @@ #include "RenderTextControlSingleLine.h" #include "RenderTheme.h" #include "SearchInputType.h" +#include "ShadowRoot.h" #include "ScriptEventListener.h" #include "WheelEvent.h" #include <wtf/MathExtras.h> @@ -108,6 +109,9 @@ PassRefPtr<HTMLInputElement> HTMLInputElement::create(const QualifiedName& tagNa void HTMLInputElement::createShadowSubtree() { + ASSERT(!hasShadowRoot()); + ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot, ASSERT_NO_EXCEPTION); + m_inputType->createShadowSubtree(); } @@ -349,7 +353,7 @@ bool HTMLInputElement::getAllowedValueStepWithDecimalPlaces(AnyStepHandling anyS return true; } -void HTMLInputElement::applyStep(double count, AnyStepHandling anyStepHandling, bool sendChangeEvent, ExceptionCode& ec) +void HTMLInputElement::applyStep(double count, AnyStepHandling anyStepHandling, TextFieldEventBehavior eventBehavior, ExceptionCode& ec) { double step; unsigned stepDecimalPlaces, currentDecimalPlaces; @@ -389,7 +393,7 @@ void HTMLInputElement::applyStep(double count, AnyStepHandling anyStepHandling, if (newValue > m_inputType->maximum()) newValue = m_inputType->maximum(); - setValueAsNumber(newValue, ec, sendChangeEvent); + setValueAsNumber(newValue, ec, eventBehavior); if (AXObjectCache::accessibilityEnabled()) document()->axObjectCache()->postNotification(renderer(), AXObjectCache::AXValueChanged, true); @@ -416,14 +420,12 @@ double HTMLInputElement::alignValueForStep(double newValue, double step, unsigne void HTMLInputElement::stepUp(int n, ExceptionCode& ec) { - bool sendChangeEvent = false; - applyStep(n, RejectAny, sendChangeEvent, ec); + applyStep(n, RejectAny, DispatchNoEvent, ec); } void HTMLInputElement::stepDown(int n, ExceptionCode& ec) { - bool sendChangeEvent = false; - applyStep(-n, RejectAny, sendChangeEvent, ec); + applyStep(-n, RejectAny, DispatchNoEvent, ec); } bool HTMLInputElement::isKeyboardFocusable(KeyboardEvent* event) const @@ -545,7 +547,7 @@ void HTMLInputElement::updateType() registerForSuspensionCallbackIfNeeded(); if (didRespectHeightAndWidth != m_inputType->shouldRespectHeightAndWidthAttributes()) { - ASSERT(attributeMap()); + ASSERT(attributeData()); if (Attribute* height = getAttributeItem(heightAttr)) attributeChanged(height); if (Attribute* width = getAttributeItem(widthAttr)) @@ -658,6 +660,36 @@ void HTMLInputElement::accessKeyAction(bool sendMouseEvents) m_inputType->accessKeyAction(sendMouseEvents); } +bool HTMLInputElement::isPresentationAttribute(Attribute* attr) const +{ + if (attr->name() == vspaceAttr || attr->name() == hspaceAttr || attr->name() == alignAttr || attr->name() == widthAttr || attr->name() == heightAttr || (attr->name() == borderAttr && isImageButton())) + return true; + return HTMLTextFormControlElement::isPresentationAttribute(attr); +} + +void HTMLInputElement::collectStyleForAttribute(Attribute* attr, StylePropertySet* style) +{ + if (attr->name() == vspaceAttr) { + addHTMLLengthToStyle(style, CSSPropertyMarginTop, attr->value()); + addHTMLLengthToStyle(style, CSSPropertyMarginBottom, attr->value()); + } else if (attr->name() == hspaceAttr) { + addHTMLLengthToStyle(style, CSSPropertyMarginLeft, attr->value()); + addHTMLLengthToStyle(style, CSSPropertyMarginRight, attr->value()); + } else if (attr->name() == alignAttr) { + if (m_inputType->shouldRespectAlignAttribute()) + applyAlignmentAttributeToStyle(attr, style); + } else if (attr->name() == widthAttr) { + if (m_inputType->shouldRespectHeightAndWidthAttributes()) + addHTMLLengthToStyle(style, CSSPropertyWidth, attr->value()); + } else if (attr->name() == heightAttr) { + if (m_inputType->shouldRespectHeightAndWidthAttributes()) + addHTMLLengthToStyle(style, CSSPropertyHeight, attr->value()); + } else if (attr->name() == borderAttr && isImageButton()) + applyBorderAttributeToStyle(attr, style); + else + return HTMLTextFormControlElement::collectStyleForAttribute(attr, style); +} + void HTMLInputElement::parseAttribute(Attribute* attr) { if (attr->name() == nameAttr) { @@ -713,29 +745,6 @@ void HTMLInputElement::parseAttribute(Attribute* attr) m_inputType->srcAttributeChanged(); else if (attr->name() == usemapAttr || attr->name() == accesskeyAttr) { // FIXME: ignore for the moment - } else if (attr->name() == vspaceAttr) { - addCSSLength(CSSPropertyMarginTop, attr->value()); - addCSSLength(CSSPropertyMarginBottom, attr->value()); - } else if (attr->name() == hspaceAttr) { - addCSSLength(CSSPropertyMarginLeft, attr->value()); - addCSSLength(CSSPropertyMarginRight, attr->value()); - } else if (attr->name() == alignAttr) { - if (m_inputType->shouldRespectAlignAttribute()) - addHTMLAlignment(attr); - else - removeHTMLAlignment(); - } else if (attr->name() == widthAttr) { - if (m_inputType->shouldRespectHeightAndWidthAttributes()) - addCSSLength(CSSPropertyWidth, attr->value()); - else - removeCSSProperty(CSSPropertyWidth); - } else if (attr->name() == heightAttr) { - if (m_inputType->shouldRespectHeightAndWidthAttributes()) - addCSSLength(CSSPropertyHeight, attr->value()); - else - removeCSSProperty(CSSPropertyHeight); - } else if (attr->name() == borderAttr && isImageButton()) { - applyBorderAttribute(attr); } else if (attr->name() == onsearchAttr) { // Search field and slider attributes all just cause updateFromElement to be called through style recalcing. setAttributeEventListener(eventNames().searchEvent, createAttributeEventListener(this, attr)); @@ -900,7 +909,7 @@ bool HTMLInputElement::isTextType() const return m_inputType->isTextType(); } -void HTMLInputElement::setChecked(bool nowChecked, bool sendChangeEvent) +void HTMLInputElement::setChecked(bool nowChecked, TextFieldEventBehavior eventBehavior) { if (checked() == nowChecked) return; @@ -925,7 +934,7 @@ void HTMLInputElement::setChecked(bool nowChecked, bool sendChangeEvent) // unchecked to match other browsers. DOM is not a useful standard for this // because it says only to fire change events at "lose focus" time, which is // definitely wrong in practice for these types of elements. - if (sendChangeEvent && inDocument() && m_inputType->shouldSendChangeEventAfterCheckedChanged()) { + if (eventBehavior != DispatchNoEvent && inDocument() && m_inputType->shouldSendChangeEventAfterCheckedChanged()) { setTextAsOfLastFormControlChangeEvent(String()); dispatchFormControlChangeEvent(); } @@ -999,7 +1008,7 @@ String HTMLInputElement::valueWithDefault() const void HTMLInputElement::setValueForUser(const String& value) { // Call setValue and make it send a change event. - setValue(value, true); + setValue(value, DispatchChangeEvent); } const String& HTMLInputElement::suggestedValue() const @@ -1017,7 +1026,7 @@ void HTMLInputElement::setSuggestedValue(const String& value) updateInnerTextValue(); } -void HTMLInputElement::setValue(const String& value, bool sendChangeEvent) +void HTMLInputElement::setValue(const String& value, TextFieldEventBehavior eventBehavior) { if (!m_inputType->canSetValue(value)) return; @@ -1029,25 +1038,18 @@ void HTMLInputElement::setValue(const String& value, bool sendChangeEvent) setLastChangeWasNotUserEdit(); setFormControlValueMatchesRenderer(false); m_suggestedValue = String(); // Prevent TextFieldInputType::setValue from using the suggested value. - m_inputType->setValue(sanitizedValue, valueChanged, sendChangeEvent); + m_inputType->setValue(sanitizedValue, valueChanged, eventBehavior); if (!valueChanged) return; - if (sendChangeEvent) - m_inputType->dispatchChangeEventInResponseToSetValue(); - - // FIXME: Why do we do this when !sendChangeEvent? - if (isTextField() && (!focused() || !sendChangeEvent)) - setTextAsOfLastFormControlChangeEvent(value); - notifyFormStateChanged(); } -void HTMLInputElement::setValueInternal(const String& sanitizedValue, bool sendChangeEvent) +void HTMLInputElement::setValueInternal(const String& sanitizedValue, TextFieldEventBehavior eventBehavior) { m_valueIfDirty = sanitizedValue; - m_wasModifiedByUser = sendChangeEvent; + m_wasModifiedByUser = eventBehavior != DispatchNoEvent; setNeedsValidityCheck(); } @@ -1066,13 +1068,13 @@ double HTMLInputElement::valueAsNumber() const return m_inputType->valueAsNumber(); } -void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, bool sendChangeEvent) +void HTMLInputElement::setValueAsNumber(double newValue, ExceptionCode& ec, TextFieldEventBehavior eventBehavior) { if (!isfinite(newValue)) { ec = NOT_SUPPORTED_ERR; return; } - m_inputType->setValueAsNumber(newValue, sendChangeEvent, ec); + m_inputType->setValueAsNumber(newValue, eventBehavior, ec); } String HTMLInputElement::placeholder() const @@ -1626,7 +1628,6 @@ void HTMLInputElement::stepUpFromRenderer(int n) const double nan = numeric_limits<double>::quiet_NaN(); String currentStringValue = value(); double current = m_inputType->parseToDouble(currentStringValue, nan); - const bool sendChangeEvent = true; if (!isfinite(current)) { ExceptionCode ec; current = m_inputType->defaultValueForStepUp(); @@ -1635,10 +1636,10 @@ void HTMLInputElement::stepUpFromRenderer(int n) current = m_inputType->minimum() - nextDiff; if (current > m_inputType->maximum() - nextDiff) current = m_inputType->maximum() - nextDiff; - setValueAsNumber(current, ec, sendChangeEvent); + setValueAsNumber(current, ec, DispatchInputAndChangeEvent); } if ((sign > 0 && current < m_inputType->minimum()) || (sign < 0 && current > m_inputType->maximum())) - setValue(m_inputType->serialize(sign > 0 ? m_inputType->minimum() : m_inputType->maximum()), sendChangeEvent); + setValue(m_inputType->serialize(sign > 0 ? m_inputType->minimum() : m_inputType->maximum()), DispatchInputAndChangeEvent); else { ExceptionCode ec; if (stepMismatch(value())) { @@ -1658,14 +1659,14 @@ void HTMLInputElement::stepUpFromRenderer(int n) if (newValue > m_inputType->maximum()) newValue = m_inputType->maximum(); - setValueAsNumber(newValue, ec, n == 1 || n == -1); + setValueAsNumber(newValue, ec, n == 1 || n == -1 ? DispatchInputAndChangeEvent : DispatchNoEvent); current = newValue; if (n > 1) - applyStep(n - 1, AnyIsDefaultStep, sendChangeEvent, ec); + applyStep(n - 1, AnyIsDefaultStep, DispatchInputAndChangeEvent, ec); else if (n < -1) - applyStep(n + 1, AnyIsDefaultStep, sendChangeEvent, ec); + applyStep(n + 1, AnyIsDefaultStep, DispatchInputAndChangeEvent, ec); } else - applyStep(n, AnyIsDefaultStep, sendChangeEvent, ec); + applyStep(n, AnyIsDefaultStep, DispatchInputAndChangeEvent, ec); } } |