OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. | |
3 * | |
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 * | |
8 * 1. Redistributions of source code must retain the above | |
9 * copyright notice, this list of conditions and the following | |
10 * disclaimer. | |
11 * 2. Redistributions in binary form must reproduce the above | |
12 * copyright notice, this list of conditions and the following | |
13 * disclaimer in the documentation and/or other materials | |
14 * provided with the distribution. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY | |
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE | |
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
21 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
25 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF | |
26 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
27 * SUCH DAMAGE. | |
28 */ | |
29 | |
30 #include "config.h" | |
31 #include "core/dom/NamedFlowCollection.h" | |
32 | |
33 #include "RuntimeEnabledFeatures.h" | |
34 #include "core/dom/DOMNamedFlowCollection.h" | |
35 #include "core/dom/Document.h" | |
36 #include "core/inspector/InspectorInstrumentation.h" | |
37 #include "wtf/text/AtomicString.h" | |
38 #include "wtf/text/StringHash.h" | |
39 #include "wtf/text/WTFString.h" | |
40 | |
41 namespace WebCore { | |
42 | |
43 NamedFlowCollection::NamedFlowCollection(Document* document) | |
44 : DocumentLifecycleObserver(document) | |
45 { | |
46 ASSERT(RuntimeEnabledFeatures::cssRegionsEnabled()); | |
47 } | |
48 | |
49 Vector<RefPtr<NamedFlow> > NamedFlowCollection::namedFlows() | |
50 { | |
51 Vector<RefPtr<NamedFlow> > namedFlows; | |
52 | |
53 for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.en
d(); ++it) { | |
54 if ((*it)->flowState() == NamedFlow::FlowStateNull) | |
55 continue; | |
56 | |
57 namedFlows.append(RefPtr<NamedFlow>(*it)); | |
58 } | |
59 | |
60 return namedFlows; | |
61 } | |
62 | |
63 // Takes an AtomicString in argument because RenderStyle::flowThread() returns a
n AtomicString. | |
64 NamedFlow* NamedFlowCollection::flowByName(const AtomicString& flowName) | |
65 { | |
66 NamedFlowSet::iterator it = m_namedFlows.find<NamedFlowHashTranslator>(flowN
ame); | |
67 if (it == m_namedFlows.end() || (*it)->flowState() == NamedFlow::FlowStateNu
ll) | |
68 return 0; | |
69 | |
70 return *it; | |
71 } | |
72 | |
73 // Takes an AtomicString in argument because RenderStyle::flowThread() returns a
n AtomicString. | |
74 PassRefPtr<NamedFlow> NamedFlowCollection::ensureFlowWithName(const AtomicString
& flowName) | |
75 { | |
76 NamedFlowSet::iterator it = m_namedFlows.find<NamedFlowHashTranslator>(flowN
ame); | |
77 if (it != m_namedFlows.end()) { | |
78 NamedFlow* namedFlow = *it; | |
79 ASSERT(namedFlow->flowState() == NamedFlow::FlowStateNull); | |
80 | |
81 return namedFlow; | |
82 } | |
83 | |
84 RefPtr<NamedFlow> newFlow = NamedFlow::create(this, flowName); | |
85 m_namedFlows.add(newFlow.get()); | |
86 | |
87 InspectorInstrumentation::didCreateNamedFlow(document(), newFlow.get()); | |
88 | |
89 return newFlow.release(); | |
90 } | |
91 | |
92 void NamedFlowCollection::discardNamedFlow(NamedFlow* namedFlow) | |
93 { | |
94 // The document is not valid anymore so the collection will be destroyed any
way. | |
95 if (!document()) | |
96 return; | |
97 | |
98 ASSERT(namedFlow->flowState() == NamedFlow::FlowStateNull); | |
99 ASSERT(m_namedFlows.contains(namedFlow)); | |
100 | |
101 InspectorInstrumentation::willRemoveNamedFlow(document(), namedFlow); | |
102 | |
103 m_namedFlows.remove(namedFlow); | |
104 } | |
105 | |
106 Document* NamedFlowCollection::document() const | |
107 { | |
108 return lifecycleContext(); | |
109 } | |
110 | |
111 PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot() | |
112 { | |
113 Vector<NamedFlow*> createdFlows; | |
114 for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.en
d(); ++it) | |
115 if ((*it)->flowState() == NamedFlow::FlowStateCreated) | |
116 createdFlows.append(*it); | |
117 return DOMNamedFlowCollection::create(createdFlows); | |
118 } | |
119 | |
120 // The HashFunctions object used by the HashSet to compare between NamedFlows. | |
121 // It is safe to set safeToCompareToEmptyOrDeleted because the HashSet will neve
r contain null pointers or deleted values. | |
122 struct NamedFlowCollection::NamedFlowHashFunctions { | |
123 static unsigned hash(NamedFlow* key) { return DefaultHash<AtomicString>::Has
h::hash(key->name()); } | |
124 static bool equal(NamedFlow* a, NamedFlow* b) { return a->name() == b->name(
); } | |
125 static const bool safeToCompareToEmptyOrDeleted = true; | |
126 }; | |
127 | |
128 // The HashTranslator is used to lookup a NamedFlow in the set using a name. | |
129 struct NamedFlowCollection::NamedFlowHashTranslator { | |
130 static unsigned hash(const AtomicString& key) { return DefaultHash<AtomicStr
ing>::Hash::hash(key); } | |
131 static bool equal(NamedFlow* a, const AtomicString& b) { return a->name() ==
b; } | |
132 }; | |
133 | |
134 } // namespace WebCore | |
OLD | NEW |