Skip to content
Permalink
Browse files
legend.focus() should not delegate focus
legend.focus() should not delegate focus
https://bugs.webkit.org/show_bug.cgi?id=189242

Reviewed by Ryosuke Niwa.

This patch is to align Webkit with Blink / Chromium, Gecko / Firefox and Web-Specification.

Web-Spec Discussion Issue - whatwg/html#3950

Merge - https://chromium.googlesource.com/chromium/src.git/+/2010bba41812ac1f3ea92a286c3894a14535766e

This patch removes focus delegation and accesskey from the legend element to align with Web-Specification.

* Source/WebCore/html/HTMLLegendElement.h:
(1) Remove "HTMLFormControlElement" class
(2) Remove "associatedControl", "accessKeyActions" and "focus" function
* Source/WebCore/html/HTMLLegendElement.cpp:
(HTMLLegendElement::associatedControl): Deleted
(HTMLLegendElement::focus): Ditto
(HTMLLegendElement::accessKeyAction): Ditto
* LayoutTests/fast/form/legend-access-key.html: Deleted
* LayoutTests/fast/form/legend-access-key-expected.txt: Deleted
* LayoutTests/fast/form/focus.html: Updated
* LayoutTests/fast/form/focus-expected.txt: Ditto
* LayoutTests/fast/forms/focus-selection-textarea-expected.txt: Ditto
* LayoutTests/fast/forms/focus-selection-input.html: Ditto
* LayoutTests/fast/forms/focus-selection-input-expected.txt: Ditto
* LayoutTests/fast/form/access-key-expected.txt: Ditto
* LayoutTests/imported/w3c/web-platform-tests/html/interaction/focus/processing-model/legend-expected.html: Rebaselined
* LayoutTests/platform/ios/TestExpectations: Remove 'deleted' testcase expectation
* LayoutTests/platform/win/TestExpectations: Remove 'deleted' testcase expectation

Canonical link: https://commits.webkit.org/258074@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Dec 19, 2022
1 parent 03178c5 commit 05f693e31a84e598a51d00bf3505f1e10049bbc5
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 120 deletions.
@@ -19,7 +19,6 @@ If this test passes you should see 1 - 9 and a, b and c clicked or focussed.
6 input type reset clicked
7 link focussed
7 link clicked
8 input type associated to legend focussed
9 input type associated to label around input focussed
a input type associated to label closed before input focussed
b area 1 focussed
@@ -1,10 +1,11 @@
This test checks to see if focus methods work on a couple types of elements.

If the test passes, you should see a line saying "focused 1", then 2, then 3.
If the test passes, you should see a line saying "focused 2", then 3.

legend.focus() should not delegate focus.

Legend

Label2 Label3
focused 1
focused 2
focused 3
@@ -15,10 +15,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
<input type="text"> focus selection

This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text field. These results all match Mozilla, except test 6, which selects the whole field contents to match all other cases of keyboard focus. When running manually, please follow the steps below. In the test harness, the test runs automatically.
@@ -30,10 +26,10 @@ This test checks whether the selection is restored, cleared, or set to the full
5) Click this label, only the word "SUCCESS" should be selected:
6) Hit Ctrl-Option-U (or Alt-U on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:
7) , only the word "SUCCESS" should be selected:
8) , the whole phrase "SUCCESS and SUCCESS" should be selected:
8) , only the word "SUCCESS" should be selected:


9) Hit Ctrl-Option-I (or Alt-I on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:
9) Hit Ctrl-Option-I (or Alt-I on Windows), only the word "SUCCESS" should be selected:


PASS first.selectionStart is 12
@@ -64,12 +60,12 @@ PASS seventh.selectionStart is 11
PASS seventh.selectionEnd is 18
PASS seventh.selectionStart is 11
PASS seventh.selectionEnd is 18
PASS eighth.selectionStart is 12
PASS eighth.selectionEnd is 19
PASS eighth.selectionStart is 0
PASS eighth.selectionEnd is 19
PASS ninth.selectionStart is 12
PASS ninth.selectionEnd is 19
PASS ninth.selectionStart is 0
PASS ninth.selectionEnd is 19
PASS eighth.selectionStart is 11
PASS eighth.selectionEnd is 18
PASS eighth.selectionStart is 11
PASS eighth.selectionEnd is 18
PASS ninth.selectionStart is 11
PASS ninth.selectionEnd is 18
PASS ninth.selectionStart is 11
PASS ninth.selectionEnd is 18

@@ -62,18 +62,18 @@
shouldBe("seventh.selectionStart", "11");
shouldBe("seventh.selectionEnd", "18");

shouldBe("eighth.selectionStart", "12");
shouldBe("eighth.selectionEnd", "19");
shouldBe("eighth.selectionStart", "11");
shouldBe("eighth.selectionEnd", "18");
var eighthLegend = document.getElementById("eighthLegend");
eighthLegend.focus();
shouldBe("eighth.selectionStart", "0");
shouldBe("eighth.selectionEnd", "19");
shouldBe("eighth.selectionStart", "11");
shouldBe("eighth.selectionEnd", "18");

shouldBe("ninth.selectionStart", "12");
shouldBe("ninth.selectionEnd", "19");
shouldBe("ninth.selectionStart", "11");
shouldBe("ninth.selectionEnd", "18");
eventSender.keyDown("I", accessKeyModifiers);
shouldBe("ninth.selectionStart", "0");
shouldBe("ninth.selectionEnd", "19");
shouldBe("ninth.selectionStart", "11");
shouldBe("ninth.selectionEnd", "18");

}
</script>
@@ -166,25 +166,25 @@ <h2>&lt;input type="text"&gt; focus selection</h2>

8) <input type="button" onclick="document.getElementById('eighthLegend').focus()" value="Click this button">
<fieldset>
<legend id="eighthLegend">, the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
<input type="text" id="eighth" value="SUCCESS and SUCCESS">
<legend id="eighthLegend">, only the word "SUCCESS" should be selected:</legend>
<input type="text" id="eighth" value="FAILURE or SUCCESS">
<script>
var eighth = document.getElementById("eighth");
eighth.focus();
eighth.setSelectionRange(12, 19);
eighth.setSelectionRange(11, 18);
eighth.blur();
</script>
</fieldset>
<br>


9) <fieldset>
<legend id="eighthLegend" accesskey="i">Hit Ctrl-Option-I (or Alt-I on Windows), the whole phrase "SUCCESS and SUCCESS" should be selected:</legend>
<input type="text" id="ninth" value="SUCCESS and SUCCESS">
<legend id="ninthLegend" accesskey="i">Hit Ctrl-Option-I (or Alt-I on Windows), only the word "SUCCESS" should be selected:</legend>
<input type="text" id="ninth" value="FAILURE or SUCCESS">
<script>
var ninth = document.getElementById("ninth");
ninth.focus();
ninth.setSelectionRange(12, 19);
ninth.setSelectionRange(11, 18);
ninth.blur();
</script>
</fieldset>
@@ -17,8 +17,6 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
<textarea> focus selection

This test checks whether the selection is restored, cleared, or set to the full range when using different ways to focus a text area. These results all match Mozilla. When running manually, please follow the steps below. In the test harness, the test runs automatically.
@@ -20,7 +20,8 @@
</head>
<body onload="test()">
<p>This test checks to see if focus methods work on a couple types of elements.</p>
<p>If the test passes, you should see a line saying "focused 1", then 2, then 3.</p>
<p>If the test passes, you should see a line saying "focused 2", then 3.</p>
<p>legend.focus() should not delegate focus.</p>
<hr>
<p>
<fieldset><legend id="1">Legend</legend><input onfocus="log('focused 1')" type="text"></fieldset>

This file was deleted.

This file was deleted.

@@ -1,5 +1,5 @@
legend


FAIL legend assert_unreached: input in legend was focused Reached unreachable code
PASS legend

@@ -984,7 +984,6 @@ fast/forms/input-first-letter-edit.html [ Skip ]
fast/forms/input-image-submit.html [ Skip ]
fast/forms/input-maxlength-inserting-in-middle.html [ Skip ]
fast/forms/input-search-press-escape-key.html [ Skip ]
fast/forms/legend-access-key.html [ Skip ]
fast/forms/listbox-non-contiguous-keyboard-selection.html [ Skip ]
fast/forms/listbox-onchange.html [ Skip ]
fast/forms/listbox-typeahead-cyrillic.html [ Skip ]
@@ -2453,7 +2453,6 @@ fast/dom/adopt-node-crash-2.html [ Skip ] # Debug Assertion
################ Forms Issues ####################
################################################################################
# Not putting 'focused' text
fast/forms/legend-access-key.html [ Failure ]
webkit.org/b/143739 fast/forms/listbox-visible-size.html [ Failure ]

webkit.org/b/97026 fast/forms/state-restore-broken-state.html [ Failure ]
@@ -2,8 +2,9 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2001 Dirk Mueller (mueller@kde.org)
* Copyright (C) 2004-2017 Apple Inc. All rights reserved.
* Copyright (C) 2004-2022 Apple Inc. All rights reserved.
* (C) 2006 Alexey Proskuryakov (ap@nypop.com)
* Copyright (C) 2018 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -46,40 +47,6 @@ Ref<HTMLLegendElement> HTMLLegendElement::create(const QualifiedName& tagName, D
return adoptRef(*new HTMLLegendElement(tagName, document));
}

RefPtr<HTMLFormControlElement> HTMLLegendElement::associatedControl()
{
// Check if there's a fieldset belonging to this legend.
auto enclosingFieldset = ancestorsOfType<HTMLFieldSetElement>(*this).first();
if (!enclosingFieldset)
return nullptr;

// Find first form element inside the fieldset that is not a legend element.
// FIXME: Should we consider tabindex?
return descendantsOfType<HTMLFormControlElement>(*enclosingFieldset).first();
}

void HTMLLegendElement::focus(const FocusOptions& options)
{
if (document().haveStylesheetsLoaded()) {
document().updateLayoutIgnorePendingStylesheets();
if (isFocusable()) {
Element::focus({ options.selectionRestorationMode, options.direction });
return;
}
}

// To match other browsers' behavior, never restore previous selection.
if (auto control = associatedControl())
control->focus({ SelectionRestorationMode::SelectAll, options.direction });
}

bool HTMLLegendElement::accessKeyAction(bool sendMouseEvents)
{
if (auto control = associatedControl())
return control->accessKeyAction(sendMouseEvents);
return false;
}

HTMLFormElement* HTMLLegendElement::form() const
{
// According to the specification, If the legend has a fieldset element as
@@ -2,7 +2,8 @@
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* (C) 1999 Antti Koivisto (koivisto@kde.org)
* (C) 2000 Dirk Mueller (mueller@kde.org)
* Copyright (C) 2004-2018 Apple Inc. All rights reserved.
* Copyright (C) 2004-2022 Apple Inc. All rights reserved.
* Copyright (C) 2018 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -27,8 +28,6 @@

namespace WebCore {

class HTMLFormControlElement;

class HTMLLegendElement final : public HTMLElement {
WTF_MAKE_ISO_ALLOCATED(HTMLLegendElement);
public:
@@ -38,12 +37,6 @@ class HTMLLegendElement final : public HTMLElement {

private:
HTMLLegendElement(const QualifiedName&, Document&);

// Control in the legend's field set that gets focus and access key.
RefPtr<HTMLFormControlElement> associatedControl();

bool accessKeyAction(bool sendMouseEvents) final;
void focus(const FocusOptions&) final;
};

} // namespace WebCore

0 comments on commit 05f693e

Please sign in to comment.