Changeset 48106 in webkit
- Timestamp:
- Sep 6, 2009 10:10:12 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r48101 r48106 1 2009-09-06 Erik Arvidsson <arv@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Tests for https://bugs.webkit.org/show_bug.cgi?id=27099 6 Make hidden elements not focusable. This is important becaue we should 7 not allow tabbing to a hidden element. 8 9 The patch also makes a element without href behave like generic elements 10 when it comes to focus. Added tests that asserts that this works as 11 expected. 12 13 * fast/events/click-focus-anchor-expected.txt: Added. 14 * fast/events/click-focus-anchor.html: Added. 15 * fast/events/resources/tabindex-focus-blur-all.js: 16 (test): 17 (testProgrammaticFocus): 18 * fast/events/tab-focus-anchor-expected.txt: Added. 19 * fast/events/tab-focus-anchor.html: Added. 20 * fast/events/tab-focus-hidden-expected.txt: Added. 21 * fast/events/tab-focus-hidden.html: Added. 22 * fast/events/tabindex-focus-blur-all-expected.txt: 23 1 24 2009-09-06 Martin Robinson <martin.james.robinson@gmail.com> 2 25 -
trunk/LayoutTests/fast/events/resources/tabindex-focus-blur-all.js
r32769 r48106 19 19 "TEXTAREA"]; 20 20 21 var tagNamesTransferFocused = ["LABEL"]; // lab les always transfer focus to the labeled element21 var tagNamesTransferFocused = ["LABEL"]; // labels always transfer focus to the labeled element 22 22 23 23 function printToConsole(str) … … 50 50 homeBase[0].focus(); 51 51 52 var resultSummary = focusCount+" focus / "+blurCount+" blur events dis atched, and should be 335 / 335 ";52 var resultSummary = focusCount+" focus / "+blurCount+" blur events dispatched, and should be 335 / 335 "; 53 53 resultSummary += (focusCount==blurCount) ? "<span style='color:green'>PASSED</span><br>" : "<span style='color:red'>FAILED</span><br>"; 54 54 resultSummary += "Total of "+failedTestCount+" focus test(s) failed."; … … 104 104 elemThatShouldFocus = elem; 105 105 106 if (elem.tagName == "INPUT" && elem.type == "hidden") // obviously since <input type=hidden> isn't rendered, it can't be focused 106 // Hidden elements should not be focusable. https://bugs.webkit.org/show_bug.cgi?id=27099 107 if (document.defaultView.getComputedStyle(elem).display == "none") 107 108 elemThatShouldFocus = null; 109 108 110 if (tagNamesTransferFocused.find(elem.tagName)) { 109 111 elemThatShouldFocus = null; -
trunk/LayoutTests/fast/events/tabindex-focus-blur-all-expected.txt
r32664 r48106 1 3 35 focus / 335 blur events disatched, and should be 335 / 335 PASSED1 329 focus / 329 blur events dispatched, and should be 335 / 335 PASSED 2 2 Total of 0 focus test(s) failed. PASSED -
trunk/WebCore/ChangeLog
r48105 r48106 1 2009-09-06 Erik Arvidsson <arv@chromium.org> 2 3 Reviewed by Eric Seidel. 4 5 Make hidden elements not focusable. 6 7 Clean up supportsFocus and isFocusable. 8 supportsFocus now strictly means that the node can be focused by default. 9 This is true for links, form controls and content editable elements for example. 10 isFocusable means that the user can actually focus it. 11 All (2) calls to supportsFocus have been updated to take this into account. 12 13 Make a elements without href work correctly as well. 14 15 https://bugs.webkit.org/show_bug.cgi?id=27099 16 17 Tests: fast/events/click-focus-anchor.html 18 fast/events/tab-focus-anchor.html 19 fast/events/tab-focus-hidden.html 20 21 * dom/Element.cpp: 22 (WebCore::Element::focus): 23 * dom/Node.cpp: 24 (WebCore::Node::supportsFocus): 25 (WebCore::Node::isFocusable): 26 * dom/Node.h: 27 * html/HTMLAnchorElement.cpp: 28 (WebCore::HTMLAnchorElement::supportsFocus): 29 (WebCore::HTMLAnchorElement::isMouseFocusable): 30 (WebCore::HTMLAnchorElement::isKeyboardFocusable): 31 * html/HTMLAnchorElement.h: 32 * html/HTMLAreaElement.cpp: 33 (WebCore::HTMLAreaElement::supportsFocus): 34 * html/HTMLAreaElement.h: 35 * html/HTMLElement.cpp: 36 (WebCore::HTMLElement::supportsFocus): 37 * html/HTMLElement.h: 38 * html/HTMLFieldSetElement.cpp: 39 (WebCore::HTMLFieldSetElement::supportsFocus): 40 * html/HTMLFieldSetElement.h: 41 * html/HTMLFormControlElement.cpp: 42 (WebCore::HTMLFormControlElement::supportsFocus): 43 (WebCore::HTMLFormControlElement::isFocusable): 44 * html/HTMLFrameElementBase.cpp: 45 (WebCore::HTMLFrameElementBase::supportsFocus): 46 * html/HTMLFrameElementBase.h: 47 * html/HTMLLegendElement.cpp: 48 (WebCore::HTMLLegendElement::supportsFocus): 49 * html/HTMLLegendElement.h: 50 * html/HTMLOptGroupElement.cpp: 51 (WebCore::HTMLOptGroupElement::supportsFocus): 52 (WebCore::HTMLOptGroupElement::isFocusable): 53 * html/HTMLOptGroupElement.h: 54 * html/HTMLOptionElement.cpp: 55 (WebCore::HTMLOptionElement::supportsFocus): 56 (WebCore::HTMLOptionElement::isFocusable): 57 * html/HTMLOptionElement.h: 58 * page/EventHandler.cpp: 59 (WebCore::EventHandler::dispatchMouseEvent): 60 * page/FocusController.cpp: 61 (WebCore::FocusController::advanceFocus): 62 * svg/SVGAElement.cpp: 63 (WebCore::SVGAElement::supportsFocus): 64 (WebCore::SVGAElement::isFocusable): 65 * wml/WMLAElement.cpp: 66 (WebCore::WMLAElement::supportsFocus): 67 * wml/WMLAElement.h: 68 * wml/WMLFormControlElement.cpp: 69 (WebCore::WMLFormControlElement::supportsFocus): 70 (WebCore::WMLFormControlElement::isFocusable): 71 * wml/WMLFormControlElement.h: 72 1 73 2009-09-06 Joel Stanley <joel@jms.id.au> 2 74 -
trunk/WebCore/dom/Element.cpp
r47910 r48106 1222 1222 return; 1223 1223 1224 doc->updateLayoutIgnorePendingStylesheets();1225 1226 1224 if (!supportsFocus()) 1227 1225 return; 1228 1226 1227 // If the stylesheets have already been loaded we can reliably check isFocusable. 1228 // If not, we continue and set the focused node on the focus controller below so 1229 // that it can be updated soon after attach. 1230 if (doc->haveStylesheetsLoaded()) { 1231 doc->updateLayoutIgnorePendingStylesheets(); 1232 if (!isFocusable()) 1233 return; 1234 } 1235 1229 1236 if (Page* page = doc->page()) 1230 1237 page->focusController()->setFocusedNode(this, doc->frame()); 1238 1239 // Setting the focused node above might have invalidated the layout due to scripts. 1240 doc->updateLayoutIgnorePendingStylesheets(); 1231 1241 1232 1242 if (!isFocusable()) { -
trunk/WebCore/dom/Node.cpp
r48055 r48106 830 830 return rareData()->isFocused(); 831 831 } 832 833 bool Node::supportsFocus() const 834 { 835 return hasRareData() && rareData()->tabIndexSetExplicitly(); 836 } 832 837 833 838 bool Node::isFocusable() const 834 839 { 835 return hasRareData() && rareData()->tabIndexSetExplicitly(); 840 if (!inDocument() || !supportsFocus()) 841 return false; 842 843 if (renderer()) 844 ASSERT(!renderer()->needsLayout()); 845 else 846 ASSERT(!needsStyleRecalc()); 847 848 // FIXME: Even if we are not visible, we might have a child that is visible. 849 // Hyatt wants to fix that some day with a "has visible content" flag or the like. 850 if (!renderer() || renderer()->style()->visibility() != VISIBLE) 851 return false; 852 853 return true; 836 854 } 837 855 -
trunk/WebCore/dom/Node.h
r47843 r48106 292 292 virtual short tabIndex() const; 293 293 294 / **295 * Whether this node can receive the keyboard focus.296 */297 virtual bool supportsFocus() const { return isFocusable(); }294 // Whether this kind of node can receive focus by default. Most nodes are 295 // not focusable but some elements, such as form controls and links are. 296 virtual bool supportsFocus() const; 297 // Whether the node can actually be focused. 298 298 virtual bool isFocusable() const; 299 299 virtual bool isKeyboardFocusable(KeyboardEvent*) const; -
trunk/WebCore/html/HTMLAnchorElement.cpp
r48063 r48106 61 61 if (isContentEditable()) 62 62 return HTMLElement::supportsFocus(); 63 return isFocusable() || (isLink() && document() && !document()->haveStylesheetsLoaded()); 64 } 65 66 bool HTMLAnchorElement::isFocusable() const 67 { 68 if (isContentEditable()) 69 return HTMLElement::isFocusable(); 70 71 // FIXME: Even if we are not visible, we might have a child that is visible. 72 // Dave wants to fix that some day with a "has visible content" flag or the like. 73 if (!(isLink() && renderer() && renderer()->style()->visibility() == VISIBLE)) 74 return false; 75 76 return true; 63 // If not a link we should still be able to focus the element if it has tabIndex. 64 return isLink() || HTMLElement::supportsFocus(); 77 65 } 78 66 79 67 bool HTMLAnchorElement::isMouseFocusable() const 80 68 { 81 #if PLATFORM(GTK) 69 // Anchor elements should be mouse focusable, https://bugs.webkit.org/show_bug.cgi?id=26856 70 #if !PLATFORM(GTK) 71 if (isLink()) 72 return false; 73 #endif 74 // Allow tab index etc to control focus. 82 75 return HTMLElement::isMouseFocusable(); 83 #else84 return false;85 #endif86 76 } 87 77 88 78 bool HTMLAnchorElement::isKeyboardFocusable(KeyboardEvent* event) const 89 79 { 80 if (!isLink()) 81 return HTMLElement::isKeyboardFocusable(event); 82 90 83 if (!isFocusable()) 91 84 return false; -
trunk/WebCore/html/HTMLAnchorElement.h
r47688 r48106 63 63 virtual bool isMouseFocusable() const; 64 64 virtual bool isKeyboardFocusable(KeyboardEvent*) const; 65 virtual bool isFocusable() const;66 65 virtual void defaultEventHandler(Event*); 67 66 virtual void setActive(bool active = true, bool pause = false); -
trunk/WebCore/html/HTMLAreaElement.cpp
r47688 r48106 163 163 } 164 164 165 bool HTMLAreaElement:: isFocusable() const165 bool HTMLAreaElement::supportsFocus() const 166 166 { 167 return HTMLElement::isFocusable(); 167 // Skip HTMLAnchorElements isLink() check. 168 return HTMLElement::supportsFocus(); 168 169 } 169 170 -
trunk/WebCore/html/HTMLAreaElement.h
r47688 r48106 54 54 virtual int tagPriority() const { return 0; } 55 55 virtual void parseMappedAttribute(MappedAttribute*); 56 virtual bool isFocusable() const;56 virtual bool supportsFocus() const; 57 57 virtual String target() const; 58 58 -
trunk/WebCore/html/HTMLElement.cpp
r47688 r48106 602 602 } 603 603 604 bool HTMLElement:: isFocusable() const605 { 606 return Element:: isFocusable() || (isContentEditable() && parent() && !parent()->isContentEditable());604 bool HTMLElement::supportsFocus() const 605 { 606 return Element::supportsFocus() || (isContentEditable() && parent() && !parent()->isContentEditable()); 607 607 } 608 608 -
trunk/WebCore/html/HTMLElement.h
r47688 r48106 57 57 void insertAdjacentText(const String& where, const String& text, ExceptionCode&); 58 58 59 virtual bool supportsFocus() const; 60 59 61 virtual bool isContentEditable() const; 60 62 virtual bool isContentRichlyEditable() const; … … 87 89 virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const; 88 90 virtual void parseMappedAttribute(MappedAttribute*); 89 90 virtual bool isFocusable() const;91 91 92 92 virtual bool childAllowed(Node* newChild); // Error-checking during parsing that checks the DTD -
trunk/WebCore/html/HTMLFieldSetElement.cpp
r45747 r48106 49 49 } 50 50 51 bool HTMLFieldSetElement:: isFocusable() const51 bool HTMLFieldSetElement::supportsFocus() const 52 52 { 53 return HTMLElement:: isFocusable();53 return HTMLElement::supportsFocus(); 54 54 } 55 55 -
trunk/WebCore/html/HTMLFieldSetElement.h
r43367 r48106 45 45 virtual bool checkDTD(const Node* newChild); 46 46 47 virtual bool isFocusable() const;47 virtual bool supportsFocus() const; 48 48 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 49 49 virtual const AtomicString& formControlType() const; -
trunk/WebCore/html/HTMLFormControlElement.cpp
r47655 r48106 233 233 } 234 234 235 bool HTMLFormControlElement::supportsFocus() const 236 { 237 return !disabled(); 238 } 239 235 240 bool HTMLFormControlElement::isFocusable() const 236 241 { 237 if (disabled() || !renderer() || 238 (renderer()->style() && renderer()->style()->visibility() != VISIBLE) || 242 if (!renderer() || 239 243 !renderer()->isBox() || toRenderBox(renderer())->size().isEmpty()) 240 244 return false; 241 return true; 245 // HTMLElement::isFocusable handles visibility and calls suportsFocus which 246 // will cover the disabled case. 247 return HTMLElement::isFocusable(); 242 248 } 243 249 … … 303 309 304 310 HTMLElement::dispatchBlurEvent(); 305 }306 307 bool HTMLFormControlElement::supportsFocus() const308 {309 return isFocusable() || (!disabled() && !document()->haveStylesheetsLoaded());310 311 } 311 312 -
trunk/WebCore/html/HTMLFrameElementBase.cpp
r47469 r48106 213 213 } 214 214 215 bool HTMLFrameElementBase:: isFocusable() const216 { 217 return renderer();215 bool HTMLFrameElementBase::supportsFocus() const 216 { 217 return true; 218 218 } 219 219 -
trunk/WebCore/html/HTMLFrameElementBase.h
r47688 r48106 58 58 virtual bool canLazyAttach() { return false; } 59 59 60 virtual bool isFocusable() const;60 virtual bool supportsFocus() const; 61 61 virtual void setFocus(bool); 62 62 -
trunk/WebCore/html/HTMLLegendElement.cpp
r43367 r48106 43 43 } 44 44 45 bool HTMLLegendElement:: isFocusable() const45 bool HTMLLegendElement::supportsFocus() const 46 46 { 47 return HTMLElement:: isFocusable();47 return HTMLElement::supportsFocus(); 48 48 } 49 49 -
trunk/WebCore/html/HTMLLegendElement.h
r43367 r48106 34 34 virtual ~HTMLLegendElement(); 35 35 36 virtual bool isFocusable() const;36 virtual bool supportsFocus() const; 37 37 virtual const AtomicString& formControlType() const; 38 38 virtual void accessKeyAction(bool sendToAnyElement); -
trunk/WebCore/html/HTMLOptGroupElement.cpp
r43367 r48106 45 45 } 46 46 47 bool HTMLOptGroupElement::supportsFocus() const 48 { 49 return HTMLElement::supportsFocus(); 50 } 51 47 52 bool HTMLOptGroupElement::isFocusable() const 48 53 { 49 return HTMLElement::isFocusable(); 54 // Optgroup elements do not have a renderer so we check the renderStyle instead. 55 return supportsFocus() && renderStyle() && renderStyle()->display() != NONE; 50 56 } 51 57 -
trunk/WebCore/html/HTMLOptGroupElement.h
r43367 r48106 38 38 virtual bool checkDTD(const Node*); 39 39 virtual const AtomicString& formControlType() const; 40 virtual bool supportsFocus() const; 40 41 virtual bool isFocusable() const; 41 42 virtual void parseMappedAttribute(MappedAttribute*); -
trunk/WebCore/html/HTMLOptionElement.cpp
r47313 r48106 67 67 } 68 68 69 bool HTMLOptionElement::supportsFocus() const 70 { 71 return HTMLElement::supportsFocus(); 72 } 73 69 74 bool HTMLOptionElement::isFocusable() const 70 75 { 71 return HTMLElement::isFocusable(); 76 // Option elements do not have a renderer so we check the renderStyle instead. 77 return supportsFocus() && renderStyle() && renderStyle()->display() != NONE; 72 78 } 73 79 -
trunk/WebCore/html/HTMLOptionElement.h
r44243 r48106 43 43 virtual int tagPriority() const { return 2; } 44 44 virtual bool checkDTD(const Node* newChild); 45 virtual bool supportsFocus() const; 45 46 virtual bool isFocusable() const; 46 47 virtual bool rendererIsNeeded(RenderStyle*) { return false; } -
trunk/WebCore/page/EventHandler.cpp
r47594 r48106 1680 1680 1681 1681 if (!swallowEvent && eventType == eventNames().mousedownEvent) { 1682 // The layout needs to be up to date to determine if an element is focusable. 1683 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1684 1682 1685 // Blur current focus node when a link/button is clicked; this 1683 1686 // is expected by some sites that rely on onChange handlers running … … 1685 1688 Node* node = m_nodeUnderMouse.get(); 1686 1689 RenderObject* renderer = node ? node->renderer() : 0; 1687 1690 1688 1691 // Walk up the render tree to search for a node to focus. 1689 1692 // Walking up the DOM tree wouldn't work for shadow trees, like those behind the engine-based text fields. -
trunk/WebCore/page/FocusController.cpp
r45663 r48106 147 147 currentNode = frame->selection()->start().node(); 148 148 149 document->updateLayoutIgnorePendingStylesheets(); 150 149 151 Node* node = (direction == FocusDirectionForward) 150 152 ? document->nextFocusableNode(currentNode, event) -
trunk/WebCore/svg/SVGAElement.cpp
r45947 r48106 166 166 if (isContentEditable()) 167 167 return SVGStyledTransformableElement::supportsFocus(); 168 return isFocusable() || (document() && !document()->haveStylesheetsLoaded());168 return true; 169 169 } 170 170 171 171 bool SVGAElement::isFocusable() const 172 172 { 173 if ( isContentEditable())174 return SVGStyledTransformableElement::isFocusable();173 if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty()) 174 return false; 175 175 176 // FIXME: Even if we are not visible, we might have a child that is visible. 177 // Dave wants to fix that some day with a "has visible content" flag or the like. 178 if (!renderer() || !(renderer()->style()->visibility() == VISIBLE)) 179 return false; 180 181 return !renderer()->absoluteClippedOverflowRect().isEmpty(); 176 return SVGElement::isFocusable(); 182 177 } 183 178 -
trunk/WebCore/wml/WMLAElement.cpp
r45947 r48106 74 74 bool WMLAElement::supportsFocus() const 75 75 { 76 return isFocusable() || (isLink() && document() && !document()->haveStylesheetsLoaded()); 77 } 78 79 bool WMLAElement::isFocusable() const 80 { 81 // FIXME: Even if we are not visible, we might have a child that is visible. 82 // Dave wants to fix that some day with a "has visible content" flag or the like. 83 if (!(isLink() && renderer() && renderer()->style()->visibility() == VISIBLE)) 84 return false; 85 86 return true; 76 return isLink() || WMLElement::supportsFocus(); 87 77 } 88 78 -
trunk/WebCore/wml/WMLAElement.h
r39432 r48106 37 37 38 38 virtual bool supportsFocus() const; 39 virtual bool isFocusable() const;40 39 virtual bool isMouseFocusable() const; 41 40 virtual bool isKeyboardFocusable(KeyboardEvent*) const; -
trunk/WebCore/wml/WMLFormControlElement.cpp
r44283 r48106 40 40 } 41 41 42 bool WMLFormControlElement::supportsFocus() const 43 { 44 return true; 45 } 46 42 47 bool WMLFormControlElement::isFocusable() const 43 48 { … … 47 52 if (toRenderBox(renderer())->size().isEmpty()) 48 53 return false; 49 50 if (RenderStyle* style = renderer()->style()) { 51 if (style->visibility() != VISIBLE) 52 return false; 53 } 54 55 return true; 54 55 return WMLElement::isFocusable(); 56 56 } 57 57 58 58 59 void WMLFormControlElement::attach() -
trunk/WebCore/wml/WMLFormControlElement.h
r44283 r48106 39 39 virtual void setFormControlValueMatchesRenderer(bool b = true) { m_valueMatchesRenderer = b; } 40 40 41 virtual bool supportsFocus() const; 41 42 virtual bool isFocusable() const; 42 43
Note: See TracChangeset
for help on using the changeset viewer.