Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: third_party/WebKit/Source/core/dom/AssignedNodeTraversal.cpp

Issue 1707443003: Consider slots as a focus scope (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring related to OILPAN Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
6 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25 #include "core/dom/AssignedNodeTraversal.h"
26
27 #include "core/dom/NodeTraversal.h"
28 #include "core/html/HTMLSlotElement.h"
29
30 namespace blink {
31
32 HTMLSlotElement* AssignedNodeTraversal::slot(const Node& current)
33 {
34 if (Node* assignedParent = AssignedNodeTraversal::assignedParent(current)) {
35 return assignedParent->assignedSlot();
36 }
37 return nullptr;
38 }
39
40 Node* AssignedNodeTraversal::assignedParent(const Node& current)
41 {
42 Node* node = const_cast<Node*>(&current);
43 while (!node->assignedSlot()) {
44 if (node->parentNode()) {
45 node = node->parentNode();
46 } else {
47 return nullptr;
48 }
49 }
50 return node;
51 }
52
53 Node* AssignedNodeTraversal::next(const Node& current)
54 {
55 // current.assignedSlot returns a slot only when current is assigned explici tly
56 if (HTMLSlotElement* slot = current.assignedSlot()) {
57 // return descendant of an assigned node
58 if (Node* next = NodeTraversal::next(current, &current))
59 return next;
60 const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = slot->g etAssignedNodes();
61 for (size_t i = 0; i < assignedNodes.size()-1; ++i) {
62 if (current.isSameNode(assignedNodes[i].get()))
63 return assignedNodes[i+1].get();
64 }
65 return nullptr;
66 }
67 Node* assignedParent = AssignedNodeTraversal::assignedParent(current);
68 if (Node* next = NodeTraversal::next(current, assignedParent))
69 return next;
70 const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = AssignedNod eTraversal::slot(*assignedParent)->getAssignedNodes();
71 for (size_t i = 0; i < assignedNodes.size()-1; ++i) {
72 if (assignedParent->isSameNode(assignedNodes[i].get()))
73 return assignedNodes[i+1].get();
74 }
75 return nullptr;
76 }
77
78 Node* AssignedNodeTraversal::previous(const Node& current)
79 {
80 Node* assignedParent = AssignedNodeTraversal::assignedParent(current);
81 // NodeTraversal within assignedParent
82 if (Node* previous = NodeTraversal::previous(current, assignedParent)) {
83 return previous;
84 }
85 // if null, jump to previous assigned node's descendant
86 const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = AssignedNod eTraversal::slot(*assignedParent)->getAssignedNodes();
87 for (size_t i = assignedNodes.size()-1; i > 0; --i) {
88 if (assignedParent->isSameNode(assignedNodes[i].get())) {
89 if (Node* lastChild = assignedNodes[i-1]->lastChild())
90 return lastChild;
91 // if the previous assigned node has no children, return the assigne d node itself
92 return assignedNodes[i-1].get();
93 }
94 }
95 return nullptr;
96 }
97
98 bool AssignedNodeTraversal::isInAssignedScope(const Node& current)
99 {
100 if (AssignedNodeTraversal::assignedParent(current))
101 return true;
102 return false;
103 }
104
105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698