Label of an <option> element should not be displayed in quirks mode
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Mar 2017 22:24:19 +0000 (22:24 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Mar 2017 22:24:19 +0000 (22:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169296
<rdar://problem/30900751>

Reviewed by Simon Fraser.

Source/WebCore:

Label of an <option> element should not be displayed in quirks mode, to
match Chrome and Firefox. However, we should still display the label in
strict mode, as per the HTML specification:
- https://html.spec.whatwg.org/multipage/rendering.html#the-select-element-2

Chrome renders the label in strict mode, same as us. Firefox does not:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1345242

Tests: fast/dom/HTMLOptionElement/option-label-quirksmode.html
       fast/dom/HTMLOptionElement/option-label-quirksmode2.html
       fast/dom/HTMLOptionElement/option-label-strictmode.html

* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::displayLabel):
(WebCore::HTMLOptionElement::textIndentedToRespectGroupLabel):
* html/HTMLOptionElement.h:

LayoutTests:

Add layout test coverage.

* fast/dom/HTMLOptionElement/option-label-quirksmode-expected.html: Added.
* fast/dom/HTMLOptionElement/option-label-quirksmode.html: Added.
* fast/dom/HTMLOptionElement/option-label-quirksmode2-expected.html: Added.
* fast/dom/HTMLOptionElement/option-label-quirksmode2.html: Added.
* fast/dom/HTMLOptionElement/option-label-strictmode-expected.html: Added.
* fast/dom/HTMLOptionElement/option-label-strictmode.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@213542 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLOptionElement.cpp
Source/WebCore/html/HTMLOptionElement.h

index 522931b..333e1b7 100644 (file)
@@ -1,3 +1,20 @@
+2017-03-07  Chris Dumez  <cdumez@apple.com>
+
+        Label of an <option> element should not be displayed in quirks mode
+        https://bugs.webkit.org/show_bug.cgi?id=169296
+        <rdar://problem/30900751>
+
+        Reviewed by Simon Fraser.
+
+        Add layout test coverage.
+
+        * fast/dom/HTMLOptionElement/option-label-quirksmode-expected.html: Added.
+        * fast/dom/HTMLOptionElement/option-label-quirksmode.html: Added.
+        * fast/dom/HTMLOptionElement/option-label-quirksmode2-expected.html: Added.
+        * fast/dom/HTMLOptionElement/option-label-quirksmode2.html: Added.
+        * fast/dom/HTMLOptionElement/option-label-strictmode-expected.html: Added.
+        * fast/dom/HTMLOptionElement/option-label-strictmode.html: Added.
+
 2017-03-07  Ryan Haddad  <ryanhaddad@apple.com>
 
         Mark media/modern-media-controls/seek-backward-support/seek-backward-support.html as flaky.
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode-expected.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode-expected.html
new file mode 100644 (file)
index 0000000..f32e881
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<p>Tests that the option's label is not displayed in quirks mode.</p>
+<select>
+    <option value="X"></option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode.html
new file mode 100644 (file)
index 0000000..c2af549
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<p>Tests that the option's label is not displayed in quirks mode.</p>
+<select>
+    <option value="X" label="X"></option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2-expected.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2-expected.html
new file mode 100644 (file)
index 0000000..d0b5d9e
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<p>Tests that the option's label is not displayed in quirks mode.</p>
+<select>
+    <option value="X">X</option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-quirksmode2.html
new file mode 100644 (file)
index 0000000..355cc93
--- /dev/null
@@ -0,0 +1,9 @@
+<html>
+<body>
+<p>Tests that the option's label is not displayed in quirks mode.</p>
+<select>
+    <option value="X" label="Y">X</option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode-expected.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode-expected.html
new file mode 100644 (file)
index 0000000..c6a260f
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests that the option's label is displayed in strict mode.</p>
+<select>
+    <option value="X">Y</option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode.html b/LayoutTests/fast/dom/HTMLOptionElement/option-label-strictmode.html
new file mode 100644 (file)
index 0000000..be94278
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<body>
+<p>Tests that the option's label is displayed in strict mode.</p>
+<select>
+    <option value="X" label="Y">X</option>
+    <option value="-" >-</option>
+</select>
+</body>
+</html>
index 4b23d06..44dc165 100644 (file)
@@ -1,3 +1,28 @@
+2017-03-07  Chris Dumez  <cdumez@apple.com>
+
+        Label of an <option> element should not be displayed in quirks mode
+        https://bugs.webkit.org/show_bug.cgi?id=169296
+        <rdar://problem/30900751>
+
+        Reviewed by Simon Fraser.
+
+        Label of an <option> element should not be displayed in quirks mode, to
+        match Chrome and Firefox. However, we should still display the label in
+        strict mode, as per the HTML specification:
+        - https://html.spec.whatwg.org/multipage/rendering.html#the-select-element-2
+
+        Chrome renders the label in strict mode, same as us. Firefox does not:
+        - https://bugzilla.mozilla.org/show_bug.cgi?id=1345242
+
+        Tests: fast/dom/HTMLOptionElement/option-label-quirksmode.html
+               fast/dom/HTMLOptionElement/option-label-quirksmode2.html
+               fast/dom/HTMLOptionElement/option-label-strictmode.html
+
+        * html/HTMLOptionElement.cpp:
+        (WebCore::HTMLOptionElement::displayLabel):
+        (WebCore::HTMLOptionElement::textIndentedToRespectGroupLabel):
+        * html/HTMLOptionElement.h:
+
 2017-03-07  Dean Jackson  <dino@apple.com>
 
         Add GPUDevice implementation and WebGPULayer
index 8fbe51e..8dffd56 100644 (file)
@@ -276,6 +276,14 @@ String HTMLOptionElement::label() const
     return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSpace(isHTMLSpace);
 }
 
+// Same as label() but ignores the label content attribute in quirks mode for compatibility with other browsers.
+String HTMLOptionElement::displayLabel() const
+{
+    if (document().inQuirksMode())
+        return collectOptionInnerText().stripWhiteSpace(isHTMLSpace).simplifyWhiteSpace(isHTMLSpace);
+    return label();
+}
+
 void HTMLOptionElement::setLabel(const String& label)
 {
     setAttributeWithoutSynchronization(labelAttr, label);
@@ -295,8 +303,8 @@ String HTMLOptionElement::textIndentedToRespectGroupLabel() const
 {
     ContainerNode* parent = parentNode();
     if (is<HTMLOptGroupElement>(parent))
-        return "    " + label();
-    return label();
+        return "    " + displayLabel();
+    return displayLabel();
 }
 
 bool HTMLOptionElement::isDisabledFormControl() const
index 24e9054..5b7ee5b 100644 (file)
@@ -54,6 +54,7 @@ public:
     HTMLSelectElement* ownerSelectElement() const;
 
     WEBCORE_EXPORT String label() const;
+    String displayLabel() const;
     WEBCORE_EXPORT void setLabel(const String&);
 
     bool ownElementDisabled() const { return m_disabled; }