Changeset 150707 in webkit
- Timestamp:
- May 25, 2013 9:33:35 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r150702 r150707 1 2013-05-25 Andreas Kling <akling@apple.com> 2 3 Move Node::tabIndex() to Element. 4 <http://webkit.org/b/116772> 5 6 Reviewed by Ryosuke Niwa. 7 8 Since only Elements are keyboard-focusable, it doesn't make sense for Node to have a tabIndex(). 9 10 * dom/Element.h: 11 * dom/Node.cpp: 12 * dom/Node.h: 13 14 A Node can't have a tab index, so move tabIndex() to Element. 15 16 * page/FocusController.h: 17 * page/FocusController.cpp: 18 (WebCore::adjustedTabIndex): 19 (WebCore::FocusController::findElementWithExactTabIndex): 20 (WebCore::nextElementWithGreaterTabIndex): 21 (WebCore::previousElementWithLowerTabIndex): 22 (WebCore::FocusController::nextFocusableNode): 23 (WebCore::FocusController::previousFocusableNode): 24 25 Make this code deal in Element* when doing tab index stuff. FocusController needs 26 more Node->Element cleanup, but let's do that separately. 27 28 * html/HTMLAnchorElement.h: 29 * html/HTMLElement.h: 30 * html/HTMLFormControlElement.h: 31 32 Sprinkle OVERRIDE. 33 1 34 2013-05-25 Andreas Kling <akling@apple.com> 2 35 -
trunk/Source/WebCore/dom/Element.h
r150697 r150707 436 436 virtual bool isMouseFocusable() const; 437 437 438 virtual short tabIndex() const; 438 439 virtual Element* focusDelegate(); 439 440 … … 655 656 void setTabIndexExplicitly(short); 656 657 virtual bool supportsFocus() const OVERRIDE; 657 virtual short tabIndex() const OVERRIDE;658 658 659 659 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType); -
trunk/Source/WebCore/dom/Node.cpp
r150697 r150707 500 500 } 501 501 502 short Node::tabIndex() const503 {504 return 0;505 }506 507 502 String Node::nodeValue() const 508 503 { -
trunk/Source/WebCore/dom/Node.h
r150697 r150707 400 400 virtual void setActive(bool flag = true, bool pause = false); 401 401 402 virtual short tabIndex() const;403 404 402 // Whether this kind of node can receive focus by default. Most nodes are 405 403 // not focusable but some elements, such as form controls and links, are. -
trunk/Source/WebCore/html/HTMLAnchorElement.h
r150692 r150707 118 118 virtual bool canStartSelection() const; 119 119 virtual String target() const; 120 virtual short tabIndex() const ;120 virtual short tabIndex() const OVERRIDE FINAL; 121 121 virtual bool draggable() const; 122 122 -
trunk/Source/WebCore/html/HTMLElement.h
r149960 r150707 51 51 virtual String title() const OVERRIDE FINAL; 52 52 53 virtual short tabIndex() const ;53 virtual short tabIndex() const OVERRIDE; 54 54 void setTabIndex(int); 55 55 -
trunk/Source/WebCore/html/HTMLFormControlElement.h
r150692 r150707 137 137 virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE { return true; } 138 138 139 virtual short tabIndex() const ;139 virtual short tabIndex() const OVERRIDE FINAL; 140 140 141 141 virtual HTMLFormElement* virtualForm() const; -
trunk/Source/WebCore/page/FocusController.cpp
r150687 r150707 150 150 { 151 151 ASSERT(node); 152 return isNonFocusableShadowHost(node, event) ? 0 : node->tabIndex(); 152 if (!node->isElementNode()) 153 return 0; 154 return isNonFocusableShadowHost(node, event) ? 0 : toElement(node)->tabIndex(); 153 155 } 154 156 … … 416 418 } 417 419 418 Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)420 Element* FocusController::findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction) 419 421 { 420 422 // Search is inclusive of start 421 423 using namespace NodeRenderingTraversal; 422 424 for (Node* node = start; node; node = direction == FocusDirectionForward ? nextInScope(node) : previousInScope(node)) { 423 if (shouldVisit(node, event) && adjustedTabIndex(node, event) == tabIndex) 424 return node; 425 if (!node->isElementNode()) 426 continue; 427 Element* element = toElement(node); 428 if (shouldVisit(element, event) && adjustedTabIndex(element, event) == tabIndex) 429 return element; 425 430 } 426 431 return 0; 427 432 } 428 433 429 static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event)434 static Element* nextElementWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event) 430 435 { 431 436 // Search is inclusive of start 432 437 int winningTabIndex = std::numeric_limits<short>::max() + 1; 433 Node* winner = 0;438 Element* winner = 0; 434 439 for (Node* node = start; node; node = NodeRenderingTraversal::nextInScope(node)) { 435 if (shouldVisit(node, event) && node->tabIndex() > tabIndex && node->tabIndex() < winningTabIndex) { 436 winner = node; 437 winningTabIndex = node->tabIndex(); 440 if (!node->isElementNode()) 441 continue; 442 Element* element = toElement(node); 443 if (shouldVisit(element, event) && element->tabIndex() > tabIndex && element->tabIndex() < winningTabIndex) { 444 winner = element; 445 winningTabIndex = element->tabIndex(); 438 446 } 439 447 } … … 442 450 } 443 451 444 static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event)452 static Element* previousElementWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event) 445 453 { 446 454 // Search is inclusive of start 447 455 int winningTabIndex = 0; 448 Node* winner = 0;456 Element* winner = 0; 449 457 for (Node* node = start; node; node = NodeRenderingTraversal::previousInScope(node)) { 450 int currentTabIndex = adjustedTabIndex(node, event); 451 if ((shouldVisit(node, event) || isNonFocusableShadowHost(node, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) { 452 winner = node; 458 if (!node->isElementNode()) 459 continue; 460 Element* element = toElement(node); 461 int currentTabIndex = adjustedTabIndex(element, event); 462 if ((shouldVisit(element, event) || isNonFocusableShadowHost(element, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) { 463 winner = element; 453 464 winningTabIndex = currentTabIndex; 454 465 } … … 472 483 473 484 // First try to find a node with the same tabindex as start that comes after start in the scope. 474 if ( Node* winner = findNodeWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward))485 if (Element* winner = findElementWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward)) 475 486 return winner; 476 487 … … 480 491 } 481 492 482 // Look for the first nodein the scope that:493 // Look for the first Element in the scope that: 483 494 // 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and 484 495 // 2) comes first in the scope, if there's a tie. 485 if ( Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event))496 if (Element* winner = nextElementWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event)) 486 497 return winner; 487 498 488 499 // There are no nodes with a tabindex greater than start's tabindex, 489 500 // so find the first node with a tabindex of 0. 490 return find NodeWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward);501 return findElementWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward); 491 502 } 492 503 … … 520 531 } 521 532 522 if ( Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward))533 if (Element* winner = findElementWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward)) 523 534 return winner; 524 535 … … 527 538 // 2) comes last in the scope, if there's a tie. 528 539 startingTabIndex = (start && startingTabIndex) ? startingTabIndex : std::numeric_limits<short>::max(); 529 return previous NodeWithLowerTabIndex(last, startingTabIndex, event);540 return previousElementWithLowerTabIndex(last, startingTabIndex, event); 530 541 } 531 542 -
trunk/Source/WebCore/page/FocusController.h
r141738 r150707 106 106 Node* previousFocusableNode(FocusNavigationScope, Node* start, KeyboardEvent*); 107 107 108 Node* findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection);108 Element* findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection); 109 109 110 110 bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*);
Note: See TracChangeset
for help on using the changeset viewer.