Title: [111659] trunk
Revision
111659
Author
[email protected]
Date
2012-03-22 01:04:11 -0700 (Thu, 22 Mar 2012)

Log Message

[Forms] The option element should not be form associated element.
https://bugs.webkit.org/show_bug.cgi?id=79764

Patch by Yoshifumi Inoue <[email protected]> on 2012-03-22
Reviewed by Kent Tamura.

Source/WebCore:

This patch changes base class of HTMLOptionELement to HTMLElement
from HTMLFormControlElement for saving memory space and iteration
time of extra "option" elements in HTMLFormElement::m_formAssociatedElements
and matching the HTML5 specification for ease of maintenance.

This patch changes behavior of handling of CSS pseudo classes "invalid"
and "valid". The "option" elements no longer use these CSS pseudo classes
as HTML5 specification. This bug was filed in https://bugs.webkit.org/show_bug.cgi?id=80088

Changes of TextIterator is lead by usage of isFormControlElement. This
changes will be replaced with more meaningful predicate as part of
https://bugs.webkit.org/show_bug.cgi?id=80381

No new tests but updated select-live-pseudo-selectors.html test.

* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::canShareStyleWithElement): Added checking of the "option" element and returns false as HTMLFormControlElement.
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOneSelector): Removed isFormControlElement for PseudoDisabled and PseudoChecked.
* html/HTMLKeygenElement.cpp:
(WebCore::HTMLKeygenElement::HTMLKeygenElement): Removed form parameter of call site of HTMLOptionElement::create.
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::HTMLOptionElement): Removed form parameter which no longer needed. Changed base class in initialization list. Added m_disabled initialization.
(WebCore::HTMLOptionElement::create): Removed form parameter which no longer needed.
(WebCore::HTMLOptionElement::attach): Changeid base class.
(WebCore::HTMLOptionElement::detach): Changed base class.
(WebCore::HTMLOptionElement::parseAttribute): Changed base class. Added "disabled" attribute handling.
(WebCore::HTMLOptionElement::childrenChanged): Changed base class.
(WebCore::HTMLOptionElement::insertedIntoTree): Changed base class.
* html/HTMLOptionElement.h:
(HTMLOptionElement): Added new member variable m_disabled which was in HTMLFormControlElement.
(WebCore::HTMLOptionElement::ownElementDisabled): Changed for using m_disabled.
* html/HTMLTagNames.in: Removed constructorNeedsFormElement for the "option" element, which was used for passing form parameter to create function.

LayoutTests:

This patch fixes a bug in select-live-pseudo-selectors.js, adds
assertions to improve coverage, and updates test expectation for
behavior changes (makes the "option" element uses CSS pseudo class
":valid".)

* fast/forms/resources/select-live-pseudo-selectors.js:
(mouseDownOnSelect): Copied from listbox-selection.html for replacing broken simulateClick which used position and size of the "option" element, but these values are zero. Note: five files use mouseDownOnSelect. We'll share this function in future tracked by https://bugs.webkit.org/show_bug.cgi?id=81496.
(backgroundOf): Added String parameter support for ease of writing test case.
* fast/forms/select-live-pseudo-selectors-expected.txt: Added check fo background color of the "selection" element. Changed expected color of the "option" element because the "option" element doesn't support CSS pseudo class ":valid". This also covers bug 80088.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111658 => 111659)


--- trunk/LayoutTests/ChangeLog	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/LayoutTests/ChangeLog	2012-03-22 08:04:11 UTC (rev 111659)
@@ -1,3 +1,20 @@
+2012-03-22  Yoshifumi Inoue  <[email protected]>
+
+        [Forms] The option element should not be form associated element.
+        https://bugs.webkit.org/show_bug.cgi?id=79764
+
+        Reviewed by Kent Tamura.
+
+        This patch fixes a bug in select-live-pseudo-selectors.js, adds
+        assertions to improve coverage, and updates test expectation for
+        behavior changes (makes the "option" element uses CSS pseudo class
+        ":valid".)
+
+        * fast/forms/resources/select-live-pseudo-selectors.js:
+        (mouseDownOnSelect): Copied from listbox-selection.html for replacing broken simulateClick which used position and size of the "option" element, but these values are zero. Note: five files use mouseDownOnSelect. We'll share this function in future tracked by https://bugs.webkit.org/show_bug.cgi?id=81496.
+        (backgroundOf): Added String parameter support for ease of writing test case.
+        * fast/forms/select-live-pseudo-selectors-expected.txt: Added check fo background color of the "selection" element. Changed expected color of the "option" element because the "option" element doesn't support CSS pseudo class ":valid". This also covers bug 80088.
+
 2012-03-22  Keishi Hattori  <[email protected]>
 
         [chromium] Unreviewed gardening.

Modified: trunk/LayoutTests/fast/forms/resources/select-live-pseudo-selectors.js (111658 => 111659)


--- trunk/LayoutTests/fast/forms/resources/select-live-pseudo-selectors.js	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/LayoutTests/fast/forms/resources/select-live-pseudo-selectors.js	2012-03-22 08:04:11 UTC (rev 111659)
@@ -6,17 +6,18 @@
 var nonForm = document.createElement('div');
 document.body.appendChild(nonForm);
 
-function simulateClick(element) {
-    var rect = element.getBoundingClientRect();
-    var x = rect.left + rect.width / 2;
-    var y = rect.top + rect.height / 2;
+function mouseDownOnSelect(selId, index, modifier) {
+    var sl = document.getElementById(selId);
+    var itemHeight = Math.floor(sl.offsetHeight / sl.size);
+    var border = 1;
+    var y = border + index * itemHeight;
 
-    if (!window.eventSender) {
-        return;
+    sl.focus();
+    if (window.eventSender) {
+        eventSender.mouseMoveTo(sl.offsetLeft + border, sl.offsetTop + y - window.pageYOffset);
+        eventSender.mouseDown(0, [modifier]);
+        eventSender.mouseUp(0, [modifier]);
     }
-    eventSender.mouseMoveTo(x, y);
-    eventSender.mouseDown();
-    eventSender.mouseUp();
 }
 
 function makeInvalid() {
@@ -50,6 +51,8 @@
 }
 
 function backgroundOf(el) {
+    if (typeof(el) == 'string')
+        el = document.getElementById(el);
     return document.defaultView.getComputedStyle(el, null).getPropertyValue('background-color');
 }
 
@@ -58,6 +61,7 @@
 var normalColor = 'rgb(255, 255, 255)';
 var disabledColor = 'rgb(0, 0, 0)';
 var readOnlyColor = 'rgb(0, 255, 0)'
+var transparentColor = 'rgba(0, 0, 0, 0)';
 var validColor = 'rgb(0, 0, 255)';
 
 // --------------------------------
@@ -102,7 +106,7 @@
 // --------------------------------
 
 debug('Change the values of select elements without explicit initializing values by clicking:');
-form.innerHTML = '<select id="select-multiple" multiple required>' +
+form.innerHTML = '<select id="select-multiple" multiple required size="4">' +
 '  <option id="multiple-empty">empty</option>' +
 '  <option id="multiple-another">another</option>' +
 '</select>' +
@@ -110,14 +114,12 @@
 '  <option id="size4-empty">empty</option>' +
 '  <option id="size4-another">another</option>' +
 '</select>';
-var selectMultiple = document.getElementById("multiple-empty");
-selectMultiple.focus();
-simulateClick(selectMultiple);
-var selectSize4 = document.getElementById("size4-empty");
-selectSize4.focus();
-simulateClick(selectSize4);
-shouldBe('backgroundOf(selectMultiple)', 'validColor');
-shouldBe('backgroundOf(selectSize4)', 'validColor');
+mouseDownOnSelect('select-multiple', 0);
+mouseDownOnSelect('select-size4', 0);
+shouldBe('backgroundOf("select-multiple")', 'validColor');
+shouldBe('backgroundOf("multiple-empty")', 'transparentColor');
+shouldBe('backgroundOf("select-size4")', 'validColor');
+shouldBe('backgroundOf("size4-empty")', 'transparentColor');
 
 debug('Change the value with a placeholder label option:');
 el = makeInvalid();

Modified: trunk/LayoutTests/fast/forms/select-live-pseudo-selectors-expected.txt (111658 => 111659)


--- trunk/LayoutTests/fast/forms/select-live-pseudo-selectors-expected.txt	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/LayoutTests/fast/forms/select-live-pseudo-selectors-expected.txt	2012-03-22 08:04:11 UTC (rev 111659)
@@ -15,8 +15,10 @@
 PASS backgroundOf(el) is invalidColor
 PASS backgroundOf(el) is invalidColor
 Change the values of select elements without explicit initializing values by clicking:
-PASS backgroundOf(selectMultiple) is validColor
-PASS backgroundOf(selectSize4) is validColor
+PASS backgroundOf("select-multiple") is validColor
+PASS backgroundOf("multiple-empty") is transparentColor
+PASS backgroundOf("select-size4") is validColor
+PASS backgroundOf("size4-empty") is transparentColor
 Change the value with a placeholder label option:
 PASS backgroundOf(el) is validColor
 PASS backgroundOf(el) is invalidColor

Modified: trunk/Source/WebCore/ChangeLog (111658 => 111659)


--- trunk/Source/WebCore/ChangeLog	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/ChangeLog	2012-03-22 08:04:11 UTC (rev 111659)
@@ -1,3 +1,44 @@
+2012-03-22  Yoshifumi Inoue  <[email protected]>
+
+        [Forms] The option element should not be form associated element.
+        https://bugs.webkit.org/show_bug.cgi?id=79764
+
+        Reviewed by Kent Tamura.
+
+        This patch changes base class of HTMLOptionELement to HTMLElement
+        from HTMLFormControlElement for saving memory space and iteration
+        time of extra "option" elements in HTMLFormElement::m_formAssociatedElements
+        and matching the HTML5 specification for ease of maintenance.
+
+        This patch changes behavior of handling of CSS pseudo classes "invalid"
+        and "valid". The "option" elements no longer use these CSS pseudo classes
+        as HTML5 specification. This bug was filed in https://bugs.webkit.org/show_bug.cgi?id=80088
+
+        Changes of TextIterator is lead by usage of isFormControlElement. This
+        changes will be replaced with more meaningful predicate as part of
+        https://bugs.webkit.org/show_bug.cgi?id=80381
+
+        No new tests but updated select-live-pseudo-selectors.html test.
+
+        * css/CSSStyleSelector.cpp:
+        (WebCore::CSSStyleSelector::canShareStyleWithElement): Added checking of the "option" element and returns false as HTMLFormControlElement.
+        * css/SelectorChecker.cpp:
+        (WebCore::SelectorChecker::checkOneSelector): Removed isFormControlElement for PseudoDisabled and PseudoChecked.
+        * html/HTMLKeygenElement.cpp:
+        (WebCore::HTMLKeygenElement::HTMLKeygenElement): Removed form parameter of call site of HTMLOptionElement::create.
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::HTMLOptionElement): Removed form parameter which no longer needed. Changed base class in initialization list. Added m_disabled initialization.
+        (WebCore::HTMLOptionElement::create): Removed form parameter which no longer needed.
+        (WebCore::HTMLOptionElement::attach): Changeid base class.
+        (WebCore::HTMLOptionElement::detach): Changed base class.
+        (WebCore::HTMLOptionElement::parseAttribute): Changed base class. Added "disabled" attribute handling.
+        (WebCore::HTMLOptionElement::childrenChanged): Changed base class.
+        (WebCore::HTMLOptionElement::insertedIntoTree): Changed base class.
+        * html/HTMLOptionElement.h:
+        (HTMLOptionElement): Added new member variable m_disabled which was in HTMLFormControlElement.
+        (WebCore::HTMLOptionElement::ownElementDisabled): Changed for using m_disabled.
+        * html/HTMLTagNames.in: Removed constructorNeedsFormElement for the "option" element, which was used for passing form parameter to create function.
+
 2012-03-21  Pavel Podivilov  <[email protected]>
 
         Web Inspector: rename ClosureCompilerSourceMapping to SourceMapParser and move it to CompilerScriptMapping.js.

Modified: trunk/Source/WebCore/css/CSSStyleSelector.cpp (111658 => 111659)


--- trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/css/CSSStyleSelector.cpp	2012-03-22 08:04:11 UTC (rev 111659)
@@ -65,6 +65,7 @@
 #include "HTMLElement.h"
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
+#include "HTMLOptionElement.h"
 #include "HTMLProgressElement.h"
 #include "HTMLStyleElement.h"
 #include "HTMLTextAreaElement.h"
@@ -1354,6 +1355,9 @@
     }
 #endif
 
+    if (element->hasTagName(optionTag))
+        return false;
+
     bool isControl = element->isFormControlElement();
 
     if (isControl != m_element->isFormControlElement())

Modified: trunk/Source/WebCore/css/SelectorChecker.cpp (111658 => 111659)


--- trunk/Source/WebCore/css/SelectorChecker.cpp	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/css/SelectorChecker.cpp	2012-03-22 08:04:11 UTC (rev 111659)
@@ -1052,7 +1052,7 @@
         case CSSSelector::PseudoDefault:
             return element && element->isDefaultButtonForForm();
         case CSSSelector::PseudoDisabled:
-            if (element && element->isFormControlElement())
+            if (element && (element->isFormControlElement() || element->hasTagName(optionTag)))
                 return !element->isEnabledFormControl();
             break;
         case CSSSelector::PseudoReadOnly:
@@ -1079,7 +1079,7 @@
             return (element->willValidate() && !element->isValidFormControlElement()) || element->hasUnacceptableValue();
         case CSSSelector::PseudoChecked:
             {
-                if (!element || !element->isFormControlElement())
+                if (!element)
                     break;
                 // Even though WinIE allows checked and indeterminate to co-exist, the CSS selector spec says that
                 // you can't be both checked and indeterminate. We will behave like WinIE behind the scenes and just

Modified: trunk/Source/WebCore/html/HTMLKeygenElement.cpp (111658 => 111659)


--- trunk/Source/WebCore/html/HTMLKeygenElement.cpp	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/html/HTMLKeygenElement.cpp	2012-03-22 08:04:11 UTC (rev 111659)
@@ -81,7 +81,7 @@
     RefPtr<HTMLSelectElement> select = KeygenSelectElement::create(document);
     ExceptionCode ec = 0;
     for (size_t i = 0; i < keys.size(); ++i) {
-        RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document, this->form());
+        RefPtr<HTMLOptionElement> option = HTMLOptionElement::create(document);
         select->appendChild(option, ec);
         option->appendChild(Text::create(document, keys[i]), ec);
     }

Modified: trunk/Source/WebCore/html/HTMLOptionElement.cpp (111658 => 111659)


--- trunk/Source/WebCore/html/HTMLOptionElement.cpp	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/html/HTMLOptionElement.cpp	2012-03-22 08:04:11 UTC (rev 111659)
@@ -37,6 +37,7 @@
 #include "NodeRenderStyle.h"
 #include "NodeRenderingContext.h"
 #include "RenderMenuList.h"
+#include "RenderTheme.h"
 #include "ScriptElement.h"
 #include "Text.h"
 #include <wtf/StdLibExtras.h>
@@ -47,21 +48,22 @@
 
 using namespace HTMLNames;
 
-HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
-    : HTMLFormControlElement(tagName, document, form)
+HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* document)
+    : HTMLElement(tagName, document)
+    , m_disabled(false)
     , m_isSelected(false)
 {
     ASSERT(hasTagName(optionTag));
 }
 
-PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(Document* document, HTMLFormElement* form)
+PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(Document* document)
 {
-    return adoptRef(new HTMLOptionElement(optionTag, document, form));
+    return adoptRef(new HTMLOptionElement(optionTag, document));
 }
 
-PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
+PassRefPtr<HTMLOptionElement> HTMLOptionElement::create(const QualifiedName& tagName, Document* document)
 {
-    return adoptRef(new HTMLOptionElement(tagName, document, form));
+    return adoptRef(new HTMLOptionElement(tagName, document));
 }
 
 PassRefPtr<HTMLOptionElement> HTMLOptionElement::createForJSConstructor(Document* document, const String& data, const String& value,
@@ -89,13 +91,13 @@
 {
     if (parentNode()->renderStyle())
         setRenderStyle(styleForRenderer());
-    HTMLFormControlElement::attach();
+    HTMLElement::attach();
 }
 
 void HTMLOptionElement::detach()
 {
     m_style.clear();
-    HTMLFormControlElement::detach();
+    HTMLElement::detach();
 }
 
 bool HTMLOptionElement::supportsFocus() const
@@ -109,12 +111,6 @@
     return supportsFocus() && renderStyle() && renderStyle()->display() != NONE;
 }
 
-const AtomicString& HTMLOptionElement::formControlType() const
-{
-    DEFINE_STATIC_LOCAL(const AtomicString, option, ("option"));
-    return option;
-}
-
 String HTMLOptionElement::text() const
 {
     Document* document = this->document();
@@ -191,7 +187,15 @@
 
 void HTMLOptionElement::parseAttribute(Attribute* attr)
 {
-    if (attr->name() == selectedAttr) {
+    if (attr->name() == disabledAttr) {
+        bool oldDisabled = m_disabled;
+        m_disabled = !attr->isNull();
+        if (oldDisabled != m_disabled) {
+            setNeedsStyleRecalc();
+            if (renderer() && renderer()->style()->hasAppearance())
+                renderer()->theme()->stateChanged(renderer(), EnabledState);
+        }
+    } else if (attr->name() == selectedAttr) {
         // FIXME: This doesn't match what the HTML specification says.
         // The specification implies that removing the selected attribute or
         // changing the value of a selected attribute that is already present
@@ -200,7 +204,7 @@
         // case; we'd need to do the other work from the setSelected function.
         m_isSelected = !attr->isNull();
     } else
-        HTMLFormControlElement::parseAttribute(attr);
+        HTMLElement::parseAttribute(attr);
 }
 
 String HTMLOptionElement::value() const
@@ -247,7 +251,7 @@
 {
     if (HTMLSelectElement* select = ownerSelectElement())
         select->optionElementChildrenChanged();
-    HTMLFormControlElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
+    HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
 }
 
 HTMLSelectElement* HTMLOptionElement::ownerSelectElement() const
@@ -315,7 +319,7 @@
         select->scrollToSelection();
     }
 
-    HTMLFormControlElement::insertedIntoTree(deep);
+    HTMLElement::insertedIntoTree(deep);
 }
 
 String HTMLOptionElement::collectOptionInnerText() const

Modified: trunk/Source/WebCore/html/HTMLOptionElement.h (111658 => 111659)


--- trunk/Source/WebCore/html/HTMLOptionElement.h	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/html/HTMLOptionElement.h	2012-03-22 08:04:11 UTC (rev 111659)
@@ -25,16 +25,16 @@
 #ifndef HTMLOptionElement_h
 #define HTMLOptionElement_h
 
-#include "HTMLFormControlElement.h"
+#include "HTMLElement.h"
 
 namespace WebCore {
 
 class HTMLSelectElement;
 
-class HTMLOptionElement : public HTMLFormControlElement {
+class HTMLOptionElement : public HTMLElement {
 public:
-    static PassRefPtr<HTMLOptionElement> create(Document*, HTMLFormElement*);
-    static PassRefPtr<HTMLOptionElement> create(const QualifiedName&, Document*, HTMLFormElement*);
+    static PassRefPtr<HTMLOptionElement> create(Document*);
+    static PassRefPtr<HTMLOptionElement> create(const QualifiedName&, Document*);
     static PassRefPtr<HTMLOptionElement> createForJSConstructor(Document*, const String& data, const String& value,
        bool defaultSelected, bool selected, ExceptionCode&);
 
@@ -54,7 +54,8 @@
     String label() const;
     void setLabel(const String&);
 
-    bool ownElementDisabled() const { return HTMLFormControlElement::disabled(); }
+    virtual bool isEnabledFormControl() const OVERRIDE { return !disabled(); }
+    bool ownElementDisabled() const { return m_disabled; }
 
     virtual bool disabled() const;
 
@@ -63,7 +64,7 @@
     void setSelectedState(bool);
 
 private:
-    HTMLOptionElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
+    HTMLOptionElement(const QualifiedName&, Document*);
 
     virtual bool supportsFocus() const;
     virtual bool isFocusable() const;
@@ -72,8 +73,6 @@
     virtual void detach();
     virtual void setRenderStyle(PassRefPtr<RenderStyle>);
 
-    virtual const AtomicString& formControlType() const;
-
     virtual void parseAttribute(Attribute*) OVERRIDE;
 
     virtual void insertedIntoTree(bool);
@@ -87,6 +86,7 @@
 
     String m_value;
     String m_label;
+    bool m_disabled;
     bool m_isSelected;
     RefPtr<RenderStyle> m_style;
 };

Modified: trunk/Source/WebCore/html/HTMLTagNames.in (111658 => 111659)


--- trunk/Source/WebCore/html/HTMLTagNames.in	2012-03-22 07:51:06 UTC (rev 111658)
+++ trunk/Source/WebCore/html/HTMLTagNames.in	2012-03-22 08:04:11 UTC (rev 111659)
@@ -92,7 +92,7 @@
 object constructorNeedsFormElement, constructorNeedsCreatedByParser
 ol interfaceName=HTMLOListElement
 optgroup interfaceName=HTMLOptGroupElement
-option constructorNeedsFormElement
+option
 output constructorNeedsFormElement
 shadow interfaceName=HTMLShadowElement, conditional=SHADOW_DOM, runtimeConditional=shadowDOM
 p interfaceName=HTMLParagraphElement
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to