Changeset 248784 in webkit
- Timestamp:
- Aug 16, 2019, 12:43:34 PM (7 years ago)
- Location:
- trunk/Source
- Files:
-
- 24 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/dom/Element.cpp (modified) (3 diffs)
-
WebCore/dom/Element.h (modified) (3 diffs)
-
WebCore/dom/ElementRareData.h (modified) (1 diff)
-
WebCore/html/HTMLAnchorElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLAnchorElement.h (modified) (1 diff)
-
WebCore/html/HTMLAreaElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLElement.h (modified) (1 diff)
-
WebCore/html/HTMLElement.idl (modified) (1 diff)
-
WebCore/html/HTMLFormControlElement.cpp (modified) (1 diff)
-
WebCore/html/HTMLFormControlElement.h (modified) (1 diff)
-
WebCore/mathml/MathMLElement.cpp (modified) (1 diff)
-
WebCore/mathml/MathMLElement.h (modified) (1 diff)
-
WebCore/page/FocusController.cpp (modified) (3 diffs)
-
WebCore/svg/SVGAElement.cpp (modified) (1 diff)
-
WebCore/svg/SVGAElement.h (modified) (1 diff)
-
WebCore/svg/SVGElement.cpp (modified) (1 diff)
-
WebCore/svg/SVGElement.h (modified) (1 diff)
-
WebCore/svg/SVGElement.idl (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLElement.cpp (modified) (2 diffs)
-
WebKitLegacy/mac/ChangeLog (modified) (1 diff)
-
WebKitLegacy/mac/DOM/DOMHTMLElement.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r248783 r248784 1 2019-08-16 Ryosuke Niwa <rniwa@webkit.org> 2 3 Split tabIndex computation for DOM and the rest of WebCore 4 https://bugs.webkit.org/show_bug.cgi?id=200806 5 6 Reviewed by Chris Dumez. 7 8 This patch renames Element::tabIndex to Element::tabIndexForBindings and migrates its usage in 9 WebCore outside JS bindings code to: tabIndexSetExplicitly, which now returns Optional<int>, 10 and shouldBeIgnoredInSequentialFocusNavigation which returns true whenever the old tabIndex 11 function used to return -1. 12 13 Instead of overriding Element::tabIndex, each subclass of element now overrides defaultTabIndex 14 corresponding to the concept of the default value of tabIndex IDL attribute defined at: 15 https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute 16 17 No new tests since there should be no observable behavior change. 18 19 * dom/Element.cpp: 20 (WebCore::Element::tabIndexSetExplicitly const): Now returns Optional<int> instead of bool. 21 (WebCore::Element::defaultTabIndex const): Added. Return -1 here. HTMLElement and SVGElement 22 manually override tabIndex to implement this behavior. Now MathMLElement overrides this function 23 to return 0 instead, which is arguably a bug. 24 (WebCore::Element::supportsFocus const): Convert Optional<int> to bool. 25 (WebCore::Element::tabIndexForBindings const): Renamed from tabIndex. Migrated the code in 26 HTMLElement::tabIndex and SVGElement::tabIndex here. Note all overrides of HTMLElement::tabIndex 27 and SVGElement::tabIndex below were skipping supportsFocus check and using 0 as the default value. 28 This is now accomplished by having an explicit check defaultTabIndex returning 0. MathMLElement 29 overrides defaultTabIndex so it continues to use the old logic. All this complexity should go away 30 in webkit.org/b/199606. 31 (WebCore::Element::setTabIndexForBindings): Renamed from setTabIndex. 32 (WebCore::Element::isKeyboardFocusable const): Checks shouldBeIgnoredInSequentialFocusNavigation 33 in lieu of calling Element::tabIndexForBindings. 34 * dom/Element.h: 35 (WebCore::Element::shouldBeIgnoredInSequentialFocusNavigation const): Added. Returns true if the 36 old implementation of Element::tabIndex would have returned -1 due to supportsFocus returning false. 37 * dom/ElementRareData.h: 38 (WebCore::ElementRareData::tabIndex const): Made this function return Optional<int>. Note that 39 ElementRareData continue to store a bit field and int for more efficient packing. 40 * html/HTMLAnchorElement.cpp: 41 (WebCore::HTMLAnchorElement::defaultTabIndex const): Replaced tabIndex. 42 * html/HTMLAnchorElement.h: 43 * html/HTMLAreaElement.cpp: 44 (WebCore::HTMLAreaElement::isFocusable const): 45 * html/HTMLElement.cpp: 46 (WebCore::HTMLElement::tabIndex const): Deleted. The logic is now in Element::tabIndex itself. 47 * html/HTMLElement.h: 48 * html/HTMLElement.idl: 49 * html/HTMLFormControlElement.cpp: 50 (WebCore::HTMLFormControlElement::defaultTabIndex const): Replaced tabIndex. 51 * html/HTMLFormControlElement.h: 52 * mathml/MathMLElement.cpp: 53 (WebCore::MathMLElement::defaultTabIndex const): Replaced tabIndex. This is probably a bug since 54 this would put every MathML element in the sequential navigation order regardless of whether it 55 has tabIndex set or not. 56 * mathml/MathMLElement.h: 57 * page/FocusController.cpp: 58 (WebCore::tabIndexForElement): Added. Computes the "effective" tab index FocusController uses. 59 (WebCore::shadowAdjustedTabIndex): 60 (WebCore::nextElementWithGreaterTabIndex): This code should use shadowAdjustedTabIndex instead 61 but keeping the old behavior for now. 62 * svg/SVGAElement.cpp: 63 (WebCore::SVGAElement::defaultTabIndex const): Replaced tabIndex. 64 * svg/SVGAElement.h: 65 * svg/SVGElement.cpp: 66 (WebCore::SVGElement::tabIndex const): Deleted. The logic is now in Element::tabIndex itself. 67 * svg/SVGElement.h: 68 (WebCore::SVGElement::hasTagName const): 69 * svg/SVGElement.idl: 70 1 71 2019-08-16 Ross Kirsling <ross.kirsling@sony.com> 2 72 -
trunk/Source/WebCore/dom/Element.cpp
r248669 r248784 244 244 } 245 245 246 bool Element::tabIndexSetExplicitly() const 247 { 248 return hasRareData() && elementRareData()->tabIndexSetExplicitly(); 246 Optional<int> Element::tabIndexSetExplicitly() const 247 { 248 if (!hasRareData()) 249 return WTF::nullopt; 250 return elementRareData()->tabIndex(); 251 } 252 253 int Element::defaultTabIndex() const 254 { 255 return -1; 249 256 } 250 257 251 258 bool Element::supportsFocus() const 252 259 { 253 return tabIndexSetExplicitly();260 return !!tabIndexSetExplicitly(); 254 261 } 255 262 … … 259 266 } 260 267 261 int Element::tabIndex() const 262 { 263 return hasRareData() ? elementRareData()->tabIndex() : 0; 264 } 265 266 void Element::setTabIndex(int value) 268 int Element::tabIndexForBindings() const 269 { 270 auto defaultIndex = defaultTabIndex(); 271 ASSERT(!defaultIndex || defaultIndex == -1); 272 // FIXME: supportsFocus() check shouldn't be here. 273 if (!defaultIndex || supportsFocus()) 274 return tabIndexSetExplicitly().valueOr(0); 275 return defaultIndex; 276 } 277 278 void Element::setTabIndexForBindings(int value) 267 279 { 268 280 setIntegralAttribute(tabindexAttr, value); … … 271 283 bool Element::isKeyboardFocusable(KeyboardEvent*) const 272 284 { 273 return isFocusable() && tabIndex() >= 0;285 return isFocusable() && !shouldBeIgnoredInSequentialFocusNavigation() && tabIndexSetExplicitly().valueOr(0) >= 0; 274 286 } 275 287 -
trunk/Source/WebCore/dom/Element.h
r248669 r248784 317 317 void setHasFocusWithin(bool flag); 318 318 319 bool tabIndexSetExplicitly() const; 319 Optional<int> tabIndexSetExplicitly() const; 320 bool shouldBeIgnoredInSequentialFocusNavigation() const { return defaultTabIndex() < 0 && !supportsFocus(); } 320 321 virtual bool supportsFocus() const; 321 322 virtual bool isFocusable() const; … … 325 326 virtual bool shouldUseInputMethod(); 326 327 327 virtual int tabIndex () const;328 WEBCORE_EXPORT void setTabIndex (int);328 virtual int tabIndexForBindings() const; 329 WEBCORE_EXPORT void setTabIndexForBindings(int); 329 330 virtual RefPtr<Element> focusDelegate(); 330 331 … … 715 716 ElementRareData& ensureElementRareData(); 716 717 718 virtual int defaultTabIndex() const; 719 717 720 void detachAllAttrNodesFromElement(); 718 721 void detachAttrNodeFromElementWithValue(Attr*, const AtomString& value); -
trunk/Source/WebCore/dom/ElementRareData.h
r243643 r248784 55 55 void resetStyleRelations(); 56 56 57 int tabIndex() const { return m_tabIndex; }57 Optional<int> tabIndex() const { return m_tabIndexWasSetExplicitly ? Optional<int> { m_tabIndex } : WTF::nullopt; } 58 58 void setTabIndexExplicitly(int index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; } 59 59 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; } -
trunk/Source/WebCore/html/HTMLAnchorElement.cpp
r246490 r248784 331 331 } 332 332 333 int HTMLAnchorElement::tabIndex() const 334 { 335 // Skip the supportsFocus check in HTMLElement. 336 return Element::tabIndex(); 333 int HTMLAnchorElement::defaultTabIndex() const 334 { 335 return 0; 337 336 } 338 337 -
trunk/Source/WebCore/html/HTMLAnchorElement.h
r246490 r248784 89 89 bool canStartSelection() const final; 90 90 String target() const override; 91 int tabIndex() const final;91 int defaultTabIndex() const final; 92 92 bool draggable() const final; 93 93 -
trunk/Source/WebCore/html/HTMLAreaElement.cpp
r246490 r248784 214 214 return false; 215 215 216 return supportsFocus() && Element::tabIndex() >= 0;216 return supportsFocus() && tabIndexSetExplicitly().valueOr(0) >= 0; 217 217 } 218 218 -
trunk/Source/WebCore/html/HTMLElement.cpp
r246490 r248784 715 715 } 716 716 717 int HTMLElement::tabIndex() const718 {719 if (supportsFocus())720 return Element::tabIndex();721 return -1;722 }723 724 717 bool HTMLElement::translate() const 725 718 { -
trunk/Source/WebCore/html/HTMLElement.h
r246490 r248784 44 44 45 45 WEBCORE_EXPORT String title() const final; 46 47 int tabIndex() const override;48 46 49 47 WEBCORE_EXPORT ExceptionOr<void> setInnerText(const String&); -
trunk/Source/WebCore/html/HTMLElement.idl
r239313 r248784 35 35 [CEReactions, Reflect] attribute boolean hidden; 36 36 void click(); 37 [CEReactions ] attribute long tabIndex;37 [CEReactions, ImplementedAs=tabIndexForBindings] attribute long tabIndex; 38 38 void focus(); 39 39 void blur(); -
trunk/Source/WebCore/html/HTMLFormControlElement.cpp
r248491 r248784 410 410 } 411 411 412 int HTMLFormControlElement::tabIndex() const 413 { 414 // Skip the supportsFocus check in HTMLElement. 415 return Element::tabIndex(); 412 int HTMLFormControlElement::defaultTabIndex() const 413 { 414 return 0; 416 415 } 417 416 -
trunk/Source/WebCore/html/HTMLFormControlElement.h
r246490 r248784 168 168 bool isFormControlElement() const final { return true; } 169 169 170 int tabIndex() const final;170 int defaultTabIndex() const final; 171 171 172 172 bool isValidFormControlElement() const; -
trunk/Source/WebCore/mathml/MathMLElement.cpp
r246490 r248784 222 222 } 223 223 224 int MathMLElement:: tabIndex() const225 { 226 // Skip the supportsFocus check in StyledElement.227 return Element::tabIndex();224 int MathMLElement::defaultTabIndex() const 225 { 226 // FIXME: This seems wrong. 227 return 0; 228 228 } 229 229 -
trunk/Source/WebCore/mathml/MathMLElement.h
r246490 r248784 109 109 bool isURLAttribute(const Attribute&) const final; 110 110 bool supportsFocus() const final; 111 int tabIndex() const final;111 int defaultTabIndex() const final; 112 112 }; 113 113 -
trunk/Source/WebCore/page/FocusController.cpp
r247416 r248784 326 326 } 327 327 328 // FIXME: This function should be merged into shadowAdjustedTabIndex. 329 static inline int tabIndexForElement(const Element& element) 330 { 331 return element.shouldBeIgnoredInSequentialFocusNavigation() ? -1 : element.tabIndexSetExplicitly().valueOr(0); 332 } 333 328 334 static inline int shadowAdjustedTabIndex(Element& element, KeyboardEvent* event) 329 335 { … … 332 338 return 0; // Treat a shadow host without tabindex if it has tabindex=0 even though HTMLElement::tabIndex returns -1 on such an element. 333 339 } 334 return element.tabIndex();340 return tabIndexForElement(element); 335 341 } 336 342 … … 621 627 continue; 622 628 Element& candidate = downcast<Element>(*node); 623 int candidateTabIndex = candidate.tabIndex(); 629 // FIXME: We should be calling shadowAdjustedTabIndex instead. 630 int candidateTabIndex = tabIndexForElement(candidate); 624 631 if (isFocusableElementOrScopeOwner(candidate, event) && candidateTabIndex > tabIndex && (!winner || candidateTabIndex < winningTabIndex)) { 625 632 winner = &candidate; -
trunk/Source/WebCore/svg/SVGAElement.cpp
r246490 r248784 152 152 } 153 153 154 int SVGAElement::tabIndex() const 155 { 156 // Skip the supportsFocus check in SVGElement. 157 return Element::tabIndex(); 154 int SVGAElement::defaultTabIndex() const 155 { 156 return 0; 158 157 } 159 158 -
trunk/Source/WebCore/svg/SVGAElement.h
r246490 r248784 61 61 bool isURLAttribute(const Attribute&) const final; 62 62 bool canStartSelection() const final; 63 int tabIndex() const final;63 int defaultTabIndex() const final; 64 64 65 65 bool willRespondToMouseClickEvents() final; -
trunk/Source/WebCore/svg/SVGElement.cpp
r246490 r248784 182 182 document().accessSVGExtensions().rebuildAllElementReferencesForTarget(*this); 183 183 document().accessSVGExtensions().removeAllElementReferencesForTarget(*this); 184 }185 186 int SVGElement::tabIndex() const187 {188 if (supportsFocus())189 return Element::tabIndex();190 return -1;191 184 } 192 185 -
trunk/Source/WebCore/svg/SVGElement.h
r246490 r248784 120 120 121 121 bool hasTagName(const SVGQualifiedName& name) const { return hasLocalName(name.localName()); } 122 int tabIndex() const override;123 122 124 123 void callClearTarget() { clearTarget(); } -
trunk/Source/WebCore/svg/SVGElement.idl
r216426 r248784 32 32 readonly attribute SVGAnimatedString className; 33 33 34 attribute long tabIndex;34 [CEReactions=NotNeeded, ImplementedAs=tabIndexForBindings] attribute long tabIndex; 35 35 36 36 // FIXME: Using "undefined" as default parameter value is wrong. -
trunk/Source/WebKit/ChangeLog
r248783 r248784 1 2019-08-16 Ryosuke Niwa <rniwa@webkit.org> 2 3 Split tabIndex computation for DOM and the rest of WebCore 4 https://bugs.webkit.org/show_bug.cgi?id=200806 5 6 Reviewed by Chris Dumez. 7 8 * WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLElement.cpp: 9 (webkit_dom_html_element_get_tab_index): 10 (webkit_dom_html_element_set_tab_index): 11 1 12 2019-08-16 Ross Kirsling <ross.kirsling@sony.com> 2 13 -
trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMHTMLElement.cpp
r234586 r248784 458 458 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self), 0); 459 459 WebCore::HTMLElement* item = WebKit::core(self); 460 glong result = item->tabIndex ();460 glong result = item->tabIndexForBindings(); 461 461 return result; 462 462 } … … 467 467 g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(self)); 468 468 WebCore::HTMLElement* item = WebKit::core(self); 469 item->setTabIndex (value);469 item->setTabIndexForBindings(value); 470 470 } 471 471 -
trunk/Source/WebKitLegacy/mac/ChangeLog
r248762 r248784 1 2019-08-16 Ryosuke Niwa <rniwa@webkit.org> 2 3 Split tabIndex computation for DOM and the rest of WebCore 4 https://bugs.webkit.org/show_bug.cgi?id=200806 5 6 Reviewed by Chris Dumez. 7 8 * DOM/DOMHTMLElement.mm: 9 (-[DOMHTMLElement tabIndex]): 10 (-[DOMHTMLElement setTabIndex:]): 11 1 12 2019-08-15 Yusuke Suzuki <ysuzuki@apple.com> 2 13 -
trunk/Source/WebKitLegacy/mac/DOM/DOMHTMLElement.mm
r247570 r248784 96 96 { 97 97 WebCore::JSMainThreadNullState state; 98 return IMPL->tabIndex ();98 return IMPL->tabIndexForBindings(); 99 99 } 100 100 … … 102 102 { 103 103 WebCore::JSMainThreadNullState state; 104 IMPL->setTabIndex (newTabIndex);104 IMPL->setTabIndexForBindings(newTabIndex); 105 105 } 106 106
Note:
See TracChangeset
for help on using the changeset viewer.