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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/dom/AssignedNodeTraversal.cpp
diff --git a/third_party/WebKit/Source/core/dom/AssignedNodeTraversal.cpp b/third_party/WebKit/Source/core/dom/AssignedNodeTraversal.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..c311d2d4cca855f10fa886863c21ccec6010690e
--- /dev/null
+++ b/third_party/WebKit/Source/core/dom/AssignedNodeTraversal.cpp
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
+ * (C) 1999 Antti Koivisto (koivisto@kde.org)
+ * (C) 2001 Dirk Mueller (mueller@kde.org)
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "core/dom/AssignedNodeTraversal.h"
+
+#include "core/dom/NodeTraversal.h"
+#include "core/html/HTMLSlotElement.h"
+
+namespace blink {
+
+HTMLSlotElement* AssignedNodeTraversal::slot(const Node& current)
+{
+ if (Node* assignedParent = AssignedNodeTraversal::assignedParent(current)) {
+ return assignedParent->assignedSlot();
+ }
+ return nullptr;
+}
+
+Node* AssignedNodeTraversal::assignedParent(const Node& current)
+{
+ Node* node = const_cast<Node*>(&current);
+ while (!node->assignedSlot()) {
+ if (node->parentNode()) {
+ node = node->parentNode();
+ } else {
+ return nullptr;
+ }
+ }
+ return node;
+}
+
+Node* AssignedNodeTraversal::next(const Node& current)
+{
+ // current.assignedSlot returns a slot only when current is assigned explicitly
+ if (HTMLSlotElement* slot = current.assignedSlot()) {
+ // return descendant of an assigned node
+ if (Node* next = NodeTraversal::next(current, &current))
+ return next;
+ const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = slot->getAssignedNodes();
+ for (size_t i = 0; i < assignedNodes.size()-1; ++i) {
+ if (current.isSameNode(assignedNodes[i].get()))
+ return assignedNodes[i+1].get();
+ }
+ return nullptr;
+ }
+ Node* assignedParent = AssignedNodeTraversal::assignedParent(current);
+ if (Node* next = NodeTraversal::next(current, assignedParent))
+ return next;
+ const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = AssignedNodeTraversal::slot(*assignedParent)->getAssignedNodes();
+ for (size_t i = 0; i < assignedNodes.size()-1; ++i) {
+ if (assignedParent->isSameNode(assignedNodes[i].get()))
+ return assignedNodes[i+1].get();
+ }
+ return nullptr;
+}
+
+Node* AssignedNodeTraversal::previous(const Node& current)
+{
+ Node* assignedParent = AssignedNodeTraversal::assignedParent(current);
+ // NodeTraversal within assignedParent
+ if (Node* previous = NodeTraversal::previous(current, assignedParent)) {
+ return previous;
+ }
+ // if null, jump to previous assigned node's descendant
+ const WillBeHeapVector<RefPtrWillBeMember<Node>> assignedNodes = AssignedNodeTraversal::slot(*assignedParent)->getAssignedNodes();
+ for (size_t i = assignedNodes.size()-1; i > 0; --i) {
+ if (assignedParent->isSameNode(assignedNodes[i].get())) {
+ if (Node* lastChild = assignedNodes[i-1]->lastChild())
+ return lastChild;
+ // if the previous assigned node has no children, return the assigned node itself
+ return assignedNodes[i-1].get();
+ }
+ }
+ return nullptr;
+}
+
+bool AssignedNodeTraversal::isInAssignedScope(const Node& current)
+{
+ if (AssignedNodeTraversal::assignedParent(current))
+ return true;
+ return false;
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698