Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / events / TreeScopeEventContext.cpp
blobee5a34f633e112599887f8c342bfdccc938995a1
1 /*
2 * Copyright (C) 2014 Google Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "config.h"
28 #include "core/events/TreeScopeEventContext.h"
30 #include "core/dom/StaticNodeList.h"
31 #include "core/dom/shadow/ShadowRoot.h"
32 #include "core/events/EventPath.h"
33 #include "core/events/TouchEventContext.h"
35 namespace blink {
37 bool TreeScopeEventContext::isUnclosedTreeOf(const TreeScopeEventContext& other)
39 // Exclude closed nodes if necessary.
40 // If a node is in a closed shadow root, or in a tree whose ancestor has a closed shadow root,
41 // it should not be visible to nodes above the closed shadow root.
43 // (1) If |this| is an ancestor of |other| in tree-of-trees, include it.
44 if (isInclusiveAncestorOf(other))
45 return true;
47 // (2) If no closed shadow root in ancestors of this, include it.
48 if (!containingClosedShadowTree())
49 return true;
51 // (3) If |this| is descendent of |other|, exclude if any closed shadow root in between.
52 if (isDescendantOf(other))
53 return !containingClosedShadowTree()->isDescendantOf(other);
55 // (4) |this| and |other| must be in exclusive branches.
56 ASSERT(other.isExclusivePartOf(*this));
57 return false;
60 WillBeHeapVector<RefPtrWillBeMember<EventTarget>>& TreeScopeEventContext::ensureEventPath(EventPath& path)
62 if (m_eventPath)
63 return *m_eventPath;
65 m_eventPath = adoptPtrWillBeNoop(new WillBeHeapVector<RefPtrWillBeMember<EventTarget>>());
66 LocalDOMWindow* window = path.windowEventContext().window();
67 m_eventPath->reserveCapacity(path.size() + (window ? 1 : 0));
69 for (size_t i = 0; i < path.size(); ++i) {
70 if (path[i].treeScopeEventContext().isUnclosedTreeOf(*this))
71 m_eventPath->append(path[i].node());
73 if (window)
74 m_eventPath->append(window);
75 return *m_eventPath;
78 TouchEventContext* TreeScopeEventContext::ensureTouchEventContext()
80 if (!m_touchEventContext)
81 m_touchEventContext = TouchEventContext::create();
82 return m_touchEventContext.get();
85 PassRefPtrWillBeRawPtr<TreeScopeEventContext> TreeScopeEventContext::create(TreeScope& treeScope)
87 return adoptRefWillBeNoop(new TreeScopeEventContext(treeScope));
90 TreeScopeEventContext::TreeScopeEventContext(TreeScope& treeScope)
91 : m_treeScope(treeScope)
92 , m_rootNode(treeScope.rootNode())
93 , m_containingClosedShadowTree(nullptr)
94 , m_preOrder(-1)
95 , m_postOrder(-1)
99 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(TreeScopeEventContext)
101 DEFINE_TRACE(TreeScopeEventContext)
103 visitor->trace(m_treeScope);
104 visitor->trace(m_rootNode);
105 visitor->trace(m_target);
106 visitor->trace(m_relatedTarget);
107 visitor->trace(m_eventPath);
108 visitor->trace(m_touchEventContext);
109 visitor->trace(m_containingClosedShadowTree);
110 #if ENABLE(OILPAN)
111 visitor->trace(m_children);
112 #endif
115 int TreeScopeEventContext::calculateTreeOrderAndSetNearestAncestorClosedTree(int orderNumber, TreeScopeEventContext* nearestAncestorClosedTreeScopeEventContext)
117 m_preOrder = orderNumber;
118 m_containingClosedShadowTree = (rootNode().isShadowRoot() && !toShadowRoot(rootNode()).isOpen()) ? this : nearestAncestorClosedTreeScopeEventContext;
119 for (size_t i = 0; i < m_children.size(); ++i)
120 orderNumber = m_children[i]->calculateTreeOrderAndSetNearestAncestorClosedTree(orderNumber + 1, containingClosedShadowTree());
121 m_postOrder = orderNumber + 1;
123 return orderNumber + 1;
126 } // namespace blink