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

Side by Side Diff: Source/core/events/TreeScopeEventContext.h

Issue 182683002: Lazy evaluation of event.path by numbering TreeScopes in DFS order for later O(1) queries (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Implement lazy evaluation Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All Rights Reserved. 2 * Copyright (C) 2014 Google Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 19 matching lines...) Expand all
30 #include "core/dom/Node.h" 30 #include "core/dom/Node.h"
31 #include "core/dom/NodeList.h" 31 #include "core/dom/NodeList.h"
32 #include "core/dom/TreeScope.h" 32 #include "core/dom/TreeScope.h"
33 #include "core/events/EventTarget.h" 33 #include "core/events/EventTarget.h"
34 #include "wtf/PassRefPtr.h" 34 #include "wtf/PassRefPtr.h"
35 #include "wtf/RefPtr.h" 35 #include "wtf/RefPtr.h"
36 #include "wtf/Vector.h" 36 #include "wtf/Vector.h"
37 37
38 namespace WebCore { 38 namespace WebCore {
39 39
40 class EventPath;
40 class EventTarget; 41 class EventTarget;
41 class Node; 42 class Node;
42 class TouchEventContext; 43 class TouchEventContext;
43 class TreeScope; 44 class TreeScope;
44 45
45 class TreeScopeEventContext : public RefCounted<TreeScopeEventContext> { 46 class TreeScopeEventContext : public RefCounted<TreeScopeEventContext> {
46 public: 47 public:
47 static PassRefPtr<TreeScopeEventContext> create(TreeScope&); 48 static PassRefPtr<TreeScopeEventContext> create(TreeScope&);
48 ~TreeScopeEventContext(); 49 ~TreeScopeEventContext();
49 50
50 TreeScope& treeScope() const { return m_treeScope; } 51 TreeScope& treeScope() const { return m_treeScope; }
51 52
52 EventTarget* target() const { return m_target.get(); } 53 EventTarget* target() const { return m_target.get(); }
53 void setTarget(PassRefPtr<EventTarget>); 54 void setTarget(PassRefPtr<EventTarget>);
54 55
55 EventTarget* relatedTarget() const { return m_relatedTarget.get(); } 56 EventTarget* relatedTarget() const { return m_relatedTarget.get(); }
56 void setRelatedTarget(PassRefPtr<EventTarget>); 57 void setRelatedTarget(PassRefPtr<EventTarget>);
57 58
58 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge t(); } 59 TouchEventContext* touchEventContext() const { return m_touchEventContext.ge t(); }
59 TouchEventContext* ensureTouchEventContext(); 60 TouchEventContext* ensureTouchEventContext();
60 61
61 PassRefPtr<NodeList> eventPath() const { return m_eventPath; } 62 PassRefPtr<NodeList> ensureEventPath(EventPath&);
62 void adoptEventPath(Vector<RefPtr<Node> >&); 63
64 bool isInclusiveAncestorOf(const TreeScopeEventContext&);
65 void addChild(TreeScopeEventContext& child) { m_children.append(&child); }
66
67 // Number each TreeScope for ancestor-descendant relationship check in Q(1).
68 // Preprocessing takes O(N).
69 int numberByDepthFirstSearch(int number);
dglazkov 2014/03/10 16:34:53 "number" is awkward here. What's the right term f
hayato 2014/03/11 05:54:04 Let me use more explicit name, pre-order number an
63 70
64 private: 71 private:
65 TreeScopeEventContext(TreeScope&); 72 TreeScopeEventContext(TreeScope&);
66 73
67 #ifndef NDEBUG 74 #ifndef NDEBUG
68 bool isUnreachableNode(EventTarget&); 75 bool isUnreachableNode(EventTarget&);
69 #endif 76 #endif
70 77
71 TreeScope& m_treeScope; 78 TreeScope& m_treeScope;
72 RefPtr<EventTarget> m_target; 79 RefPtr<EventTarget> m_target;
73 RefPtr<EventTarget> m_relatedTarget; 80 RefPtr<EventTarget> m_relatedTarget;
74 RefPtr<NodeList> m_eventPath; 81 RefPtr<NodeList> m_eventPath;
75 RefPtrWillBePersistent<TouchEventContext> m_touchEventContext; 82 RefPtrWillBePersistent<TouchEventContext> m_touchEventContext;
83
84 Vector<TreeScopeEventContext*> m_children;
85 int m_preVisit;
86 int m_postVisit;
76 }; 87 };
77 88
78 #ifndef NDEBUG 89 #ifndef NDEBUG
79 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target) 90 inline bool TreeScopeEventContext::isUnreachableNode(EventTarget& target)
80 { 91 {
81 // FIXME: Checks also for SVG elements. 92 // FIXME: Checks also for SVG elements.
82 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode ()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(m_treeSco pe); 93 return target.toNode() && !target.toNode()->isSVGElement() && !target.toNode ()->treeScope().isInclusiveOlderSiblingShadowRootOrAncestorTreeScopeOf(m_treeSco pe);
83 } 94 }
84 #endif 95 #endif
85 96
86 inline void TreeScopeEventContext::setTarget(PassRefPtr<EventTarget> target) 97 inline void TreeScopeEventContext::setTarget(PassRefPtr<EventTarget> target)
87 { 98 {
88 ASSERT(target); 99 ASSERT(target);
89 ASSERT(!isUnreachableNode(*target)); 100 ASSERT(!isUnreachableNode(*target));
90 m_target = target; 101 m_target = target;
91 } 102 }
92 103
93 inline void TreeScopeEventContext::setRelatedTarget(PassRefPtr<EventTarget> rela tedTarget) 104 inline void TreeScopeEventContext::setRelatedTarget(PassRefPtr<EventTarget> rela tedTarget)
94 { 105 {
95 ASSERT(relatedTarget); 106 ASSERT(relatedTarget);
96 ASSERT(!isUnreachableNode(*relatedTarget)); 107 ASSERT(!isUnreachableNode(*relatedTarget));
97 m_relatedTarget = relatedTarget; 108 m_relatedTarget = relatedTarget;
98 } 109 }
99 110
111 inline bool TreeScopeEventContext::isInclusiveAncestorOf(const TreeScopeEventCon text& other)
112 {
113 ASSERT(m_preVisit != -1 && m_postVisit != -1 && other.m_preVisit != -1 && ot her.m_postVisit != -1);
114 return m_preVisit <= other.m_preVisit && other.m_postVisit <= m_postVisit;
115 }
116
100 } 117 }
101 118
102 #endif // TreeScopeEventContext_h 119 #endif // TreeScopeEventContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698