Log Message
Move Node::tabIndex() to Element. <http://webkit.org/b/116772> Reviewed by Ryosuke Niwa.
Since only Elements are keyboard-focusable, it doesn't make sense for Node to have a tabIndex().
* dom/Element.h:
* dom/Node.cpp:
* dom/Node.h:
A Node can't have a tab index, so move tabIndex() to Element.
* page/FocusController.h:
* page/FocusController.cpp:
(WebCore::adjustedTabIndex):
(WebCore::FocusController::findElementWithExactTabIndex):
(WebCore::nextElementWithGreaterTabIndex):
(WebCore::previousElementWithLowerTabIndex):
(WebCore::FocusController::nextFocusableNode):
(WebCore::FocusController::previousFocusableNode):
Make this code deal in Element* when doing tab index stuff. FocusController needs
more Node->Element cleanup, but let's do that separately.
* html/HTMLAnchorElement.h:
* html/HTMLElement.h:
* html/HTMLFormControlElement.h:
Sprinkle OVERRIDE.
Modified Paths
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/dom/Element.h
- trunk/Source/WebCore/dom/Node.cpp
- trunk/Source/WebCore/dom/Node.h
- trunk/Source/WebCore/html/HTMLAnchorElement.h
- trunk/Source/WebCore/html/HTMLElement.h
- trunk/Source/WebCore/html/HTMLFormControlElement.h
- trunk/Source/WebCore/page/FocusController.cpp
- trunk/Source/WebCore/page/FocusController.h
Diff
Modified: trunk/Source/WebCore/ChangeLog (150706 => 150707)
--- trunk/Source/WebCore/ChangeLog 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/ChangeLog 2013-05-26 04:33:35 UTC (rev 150707)
@@ -1,5 +1,38 @@
2013-05-25 Andreas Kling <[email protected]>
+ Move Node::tabIndex() to Element.
+ <http://webkit.org/b/116772>
+
+ Reviewed by Ryosuke Niwa.
+
+ Since only Elements are keyboard-focusable, it doesn't make sense for Node to have a tabIndex().
+
+ * dom/Element.h:
+ * dom/Node.cpp:
+ * dom/Node.h:
+
+ A Node can't have a tab index, so move tabIndex() to Element.
+
+ * page/FocusController.h:
+ * page/FocusController.cpp:
+ (WebCore::adjustedTabIndex):
+ (WebCore::FocusController::findElementWithExactTabIndex):
+ (WebCore::nextElementWithGreaterTabIndex):
+ (WebCore::previousElementWithLowerTabIndex):
+ (WebCore::FocusController::nextFocusableNode):
+ (WebCore::FocusController::previousFocusableNode):
+
+ Make this code deal in Element* when doing tab index stuff. FocusController needs
+ more Node->Element cleanup, but let's do that separately.
+
+ * html/HTMLAnchorElement.h:
+ * html/HTMLElement.h:
+ * html/HTMLFormControlElement.h:
+
+ Sprinkle OVERRIDE.
+
+2013-05-25 Andreas Kling <[email protected]>
+
Don't instantiate ChildNodeLists just to get a child count.
<http://webkit.org/b/116776>
Modified: trunk/Source/WebCore/dom/Element.h (150706 => 150707)
--- trunk/Source/WebCore/dom/Element.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/dom/Element.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -435,6 +435,7 @@
virtual bool isKeyboardFocusable(KeyboardEvent*) const;
virtual bool isMouseFocusable() const;
+ virtual short tabIndex() const;
virtual Element* focusDelegate();
RenderStyle* computedStyle(PseudoId = NOPSEUDO);
@@ -654,7 +655,6 @@
void clearTabIndexExplicitlyIfNeeded();
void setTabIndexExplicitly(short);
virtual bool supportsFocus() const OVERRIDE;
- virtual short tabIndex() const OVERRIDE;
PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
HTMLCollection* cachedHTMLCollection(CollectionType);
Modified: trunk/Source/WebCore/dom/Node.cpp (150706 => 150707)
--- trunk/Source/WebCore/dom/Node.cpp 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/dom/Node.cpp 2013-05-26 04:33:35 UTC (rev 150707)
@@ -499,11 +499,6 @@
return 0;
}
-short Node::tabIndex() const
-{
- return 0;
-}
-
String Node::nodeValue() const
{
return String();
Modified: trunk/Source/WebCore/dom/Node.h (150706 => 150707)
--- trunk/Source/WebCore/dom/Node.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/dom/Node.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -399,8 +399,6 @@
virtual void setActive(bool flag = true, bool pause = false);
- virtual short tabIndex() const;
-
// Whether this kind of node can receive focus by default. Most nodes are
// not focusable but some elements, such as form controls and links, are.
virtual bool supportsFocus() const;
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.h (150706 => 150707)
--- trunk/Source/WebCore/html/HTMLAnchorElement.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -117,7 +117,7 @@
virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
virtual bool canStartSelection() const;
virtual String target() const;
- virtual short tabIndex() const;
+ virtual short tabIndex() const OVERRIDE FINAL;
virtual bool draggable() const;
void sendPings(const KURL& destinationURL);
Modified: trunk/Source/WebCore/html/HTMLElement.h (150706 => 150707)
--- trunk/Source/WebCore/html/HTMLElement.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/html/HTMLElement.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -50,7 +50,7 @@
virtual String title() const OVERRIDE FINAL;
- virtual short tabIndex() const;
+ virtual short tabIndex() const OVERRIDE;
void setTabIndex(int);
String innerHTML() const;
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (150706 => 150707)
--- trunk/Source/WebCore/html/HTMLFormControlElement.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -136,7 +136,7 @@
virtual bool isFormControlElement() const { return true; }
virtual bool alwaysCreateUserAgentShadowRoot() const OVERRIDE { return true; }
- virtual short tabIndex() const;
+ virtual short tabIndex() const OVERRIDE FINAL;
virtual HTMLFormElement* virtualForm() const;
virtual bool isDefaultButtonForForm() const;
Modified: trunk/Source/WebCore/page/FocusController.cpp (150706 => 150707)
--- trunk/Source/WebCore/page/FocusController.cpp 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/page/FocusController.cpp 2013-05-26 04:33:35 UTC (rev 150707)
@@ -149,7 +149,9 @@
static inline int adjustedTabIndex(Node* node, KeyboardEvent* event)
{
ASSERT(node);
- return isNonFocusableShadowHost(node, event) ? 0 : node->tabIndex();
+ if (!node->isElementNode())
+ return 0;
+ return isNonFocusableShadowHost(node, event) ? 0 : toElement(node)->tabIndex();
}
static inline bool shouldVisit(Node* node, KeyboardEvent* event)
@@ -415,41 +417,50 @@
: previousFocusableNode(scope, node, event);
}
-Node* FocusController::findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
+Element* FocusController::findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent* event, FocusDirection direction)
{
// Search is inclusive of start
using namespace NodeRenderingTraversal;
for (Node* node = start; node; node = direction == FocusDirectionForward ? nextInScope(node) : previousInScope(node)) {
- if (shouldVisit(node, event) && adjustedTabIndex(node, event) == tabIndex)
- return node;
+ if (!node->isElementNode())
+ continue;
+ Element* element = toElement(node);
+ if (shouldVisit(element, event) && adjustedTabIndex(element, event) == tabIndex)
+ return element;
}
return 0;
}
-static Node* nextNodeWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
+static Element* nextElementWithGreaterTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
{
// Search is inclusive of start
int winningTabIndex = std::numeric_limits<short>::max() + 1;
- Node* winner = 0;
+ Element* winner = 0;
for (Node* node = start; node; node = NodeRenderingTraversal::nextInScope(node)) {
- if (shouldVisit(node, event) && node->tabIndex() > tabIndex && node->tabIndex() < winningTabIndex) {
- winner = node;
- winningTabIndex = node->tabIndex();
+ if (!node->isElementNode())
+ continue;
+ Element* element = toElement(node);
+ if (shouldVisit(element, event) && element->tabIndex() > tabIndex && element->tabIndex() < winningTabIndex) {
+ winner = element;
+ winningTabIndex = element->tabIndex();
}
}
return winner;
}
-static Node* previousNodeWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
+static Element* previousElementWithLowerTabIndex(Node* start, int tabIndex, KeyboardEvent* event)
{
// Search is inclusive of start
int winningTabIndex = 0;
- Node* winner = 0;
+ Element* winner = 0;
for (Node* node = start; node; node = NodeRenderingTraversal::previousInScope(node)) {
- int currentTabIndex = adjustedTabIndex(node, event);
- if ((shouldVisit(node, event) || isNonFocusableShadowHost(node, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
- winner = node;
+ if (!node->isElementNode())
+ continue;
+ Element* element = toElement(node);
+ int currentTabIndex = adjustedTabIndex(element, event);
+ if ((shouldVisit(element, event) || isNonFocusableShadowHost(element, event)) && currentTabIndex < tabIndex && currentTabIndex > winningTabIndex) {
+ winner = element;
winningTabIndex = currentTabIndex;
}
}
@@ -471,7 +482,7 @@
}
// First try to find a node with the same tabindex as start that comes after start in the scope.
- if (Node* winner = findNodeWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward))
+ if (Element* winner = findElementWithExactTabIndex(nextInScope(start), tabIndex, event, FocusDirectionForward))
return winner;
if (!tabIndex)
@@ -479,15 +490,15 @@
return 0;
}
- // Look for the first node in the scope that:
+ // Look for the first Element in the scope that:
// 1) has the lowest tabindex that is higher than start's tabindex (or 0, if start is null), and
// 2) comes first in the scope, if there's a tie.
- if (Node* winner = nextNodeWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event))
+ if (Element* winner = nextElementWithGreaterTabIndex(scope.rootNode(), start ? adjustedTabIndex(start, event) : 0, event))
return winner;
// There are no nodes with a tabindex greater than start's tabindex,
// so find the first node with a tabindex of 0.
- return findNodeWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward);
+ return findElementWithExactTabIndex(scope.rootNode(), 0, event, FocusDirectionForward);
}
Node* FocusController::previousFocusableNode(FocusNavigationScope scope, Node* start, KeyboardEvent* event)
@@ -519,14 +530,14 @@
}
}
- if (Node* winner = findNodeWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward))
+ if (Element* winner = findElementWithExactTabIndex(startingNode, startingTabIndex, event, FocusDirectionBackward))
return winner;
// There are no nodes before start with the same tabindex as start, so look for a node that:
// 1) has the highest non-zero tabindex (that is less than start's tabindex), and
// 2) comes last in the scope, if there's a tie.
startingTabIndex = (start && startingTabIndex) ? startingTabIndex : std::numeric_limits<short>::max();
- return previousNodeWithLowerTabIndex(last, startingTabIndex, event);
+ return previousElementWithLowerTabIndex(last, startingTabIndex, event);
}
static bool relinquishesEditingFocus(Node *node)
Modified: trunk/Source/WebCore/page/FocusController.h (150706 => 150707)
--- trunk/Source/WebCore/page/FocusController.h 2013-05-26 04:31:13 UTC (rev 150706)
+++ trunk/Source/WebCore/page/FocusController.h 2013-05-26 04:33:35 UTC (rev 150707)
@@ -105,7 +105,7 @@
Node* nextFocusableNode(FocusNavigationScope, Node* start, KeyboardEvent*);
Node* previousFocusableNode(FocusNavigationScope, Node* start, KeyboardEvent*);
- Node* findNodeWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection);
+ Element* findElementWithExactTabIndex(Node* start, int tabIndex, KeyboardEvent*, FocusDirection);
bool advanceFocusDirectionallyInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*);
void findFocusCandidateInContainer(Node* container, const LayoutRect& startingRect, FocusDirection, KeyboardEvent*, FocusCandidate& closest);
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
