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 "wtf/text/AtomicString.h" | |
37 #include "wtf/text/StringHash.h" | |
38 #include "wtf/text/WTFString.h" | |
39 | |
40 namespace WebCore { | |
41 | |
42 NamedFlowCollection::NamedFlowCollection(Document* document) | |
43 : DocumentLifecycleObserver(document) | |
44 { | |
45 ASSERT(RuntimeEnabledFeatures::cssRegionsEnabled()); | |
46 } | |
47 | |
48 Vector<RefPtr<NamedFlow> > NamedFlowCollection::namedFlows() | |
49 { | |
50 Vector<RefPtr<NamedFlow> > namedFlows; | |
51 | |
52 for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.en
d(); ++it) { | |
53 if ((*it)->flowState() == NamedFlow::FlowStateNull) | |
54 continue; | |
55 | |
56 namedFlows.append(RefPtr<NamedFlow>(*it)); | |
57 } | |
58 | |
59 return namedFlows; | |
60 } | |
61 | |
62 // Takes an AtomicString in argument because RenderStyle::flowThread() returns a
n AtomicString. | |
63 NamedFlow* NamedFlowCollection::flowByName(const AtomicString& flowName) | |
64 { | |
65 NamedFlowSet::iterator it = m_namedFlows.find<NamedFlowHashTranslator>(flowN
ame); | |
66 if (it == m_namedFlows.end() || (*it)->flowState() == NamedFlow::FlowStateNu
ll) | |
67 return 0; | |
68 | |
69 return *it; | |
70 } | |
71 | |
72 // Takes an AtomicString in argument because RenderStyle::flowThread() returns a
n AtomicString. | |
73 PassRefPtr<NamedFlow> NamedFlowCollection::ensureFlowWithName(const AtomicString
& flowName) | |
74 { | |
75 NamedFlowSet::iterator it = m_namedFlows.find<NamedFlowHashTranslator>(flowN
ame); | |
76 if (it != m_namedFlows.end()) { | |
77 NamedFlow* namedFlow = *it; | |
78 ASSERT(namedFlow->flowState() == NamedFlow::FlowStateNull); | |
79 | |
80 return namedFlow; | |
81 } | |
82 | |
83 RefPtr<NamedFlow> newFlow = NamedFlow::create(this, flowName); | |
84 m_namedFlows.add(newFlow.get()); | |
85 | |
86 return newFlow.release(); | |
87 } | |
88 | |
89 void NamedFlowCollection::discardNamedFlow(NamedFlow* namedFlow) | |
90 { | |
91 // The document is not valid anymore so the collection will be destroyed any
way. | |
92 if (!document()) | |
93 return; | |
94 | |
95 ASSERT(namedFlow->flowState() == NamedFlow::FlowStateNull); | |
96 ASSERT(m_namedFlows.contains(namedFlow)); | |
97 | |
98 m_namedFlows.remove(namedFlow); | |
99 } | |
100 | |
101 Document* NamedFlowCollection::document() const | |
102 { | |
103 return lifecycleContext(); | |
104 } | |
105 | |
106 PassRefPtr<DOMNamedFlowCollection> NamedFlowCollection::createCSSOMSnapshot() | |
107 { | |
108 Vector<NamedFlow*> createdFlows; | |
109 for (NamedFlowSet::iterator it = m_namedFlows.begin(); it != m_namedFlows.en
d(); ++it) | |
110 if ((*it)->flowState() == NamedFlow::FlowStateCreated) | |
111 createdFlows.append(*it); | |
112 return DOMNamedFlowCollection::create(createdFlows); | |
113 } | |
114 | |
115 // The HashFunctions object used by the HashSet to compare between NamedFlows. | |
116 // It is safe to set safeToCompareToEmptyOrDeleted because the HashSet will neve
r contain null pointers or deleted values. | |
117 struct NamedFlowCollection::NamedFlowHashFunctions { | |
118 static unsigned hash(NamedFlow* key) { return DefaultHash<AtomicString>::Has
h::hash(key->name()); } | |
119 static bool equal(NamedFlow* a, NamedFlow* b) { return a->name() == b->name(
); } | |
120 static const bool safeToCompareToEmptyOrDeleted = true; | |
121 }; | |
122 | |
123 // The HashTranslator is used to lookup a NamedFlow in the set using a name. | |
124 struct NamedFlowCollection::NamedFlowHashTranslator { | |
125 static unsigned hash(const AtomicString& key) { return DefaultHash<AtomicStr
ing>::Hash::hash(key); } | |
126 static bool equal(NamedFlow* a, const AtomicString& b) { return a->name() ==
b; } | |
127 }; | |
128 | |
129 } // namespace WebCore | |
OLD | NEW |