OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
40 #include "core/loader/FrameLoaderClient.h" | 40 #include "core/loader/FrameLoaderClient.h" |
41 #include "core/style/StyleRareNonInheritedData.h" | 41 #include "core/style/StyleRareNonInheritedData.h" |
42 | 42 |
43 namespace blink { | 43 namespace blink { |
44 | 44 |
45 // The address of this string is important; its value is just documentation. | 45 // The address of this string is important; its value is just documentation. |
46 static const char kSupplementName[] = "CSSSelectorWatch"; | 46 static const char kSupplementName[] = "CSSSelectorWatch"; |
47 | 47 |
48 CSSSelectorWatch::CSSSelectorWatch(Document& document) | 48 CSSSelectorWatch::CSSSelectorWatch(Document& document) |
49 : m_document(document), | 49 : Supplement<Document>(document), |
50 m_callbackSelectorChangeTimer( | 50 m_callbackSelectorChangeTimer( |
51 TaskRunnerHelper::get(TaskType::UnspecedTimer, &document), | 51 TaskRunnerHelper::get(TaskType::UnspecedTimer, &document), |
52 this, | 52 this, |
53 &CSSSelectorWatch::callbackSelectorChangeTimerFired), | 53 &CSSSelectorWatch::callbackSelectorChangeTimerFired), |
54 m_timerExpirations(0) {} | 54 m_timerExpirations(0) {} |
55 | 55 |
56 CSSSelectorWatch& CSSSelectorWatch::from(Document& document) { | 56 CSSSelectorWatch& CSSSelectorWatch::from(Document& document) { |
57 CSSSelectorWatch* watch = fromIfExists(document); | 57 CSSSelectorWatch* watch = fromIfExists(document); |
58 if (!watch) { | 58 if (!watch) { |
59 watch = new CSSSelectorWatch(document); | 59 watch = new CSSSelectorWatch(document); |
60 Supplement<Document>::provideTo(document, kSupplementName, watch); | 60 Supplement<Document>::provideTo(document, kSupplementName, watch); |
61 } | 61 } |
62 return *watch; | 62 return *watch; |
63 } | 63 } |
64 | 64 |
65 CSSSelectorWatch* CSSSelectorWatch::fromIfExists(Document& document) { | 65 CSSSelectorWatch* CSSSelectorWatch::fromIfExists(Document& document) { |
66 return static_cast<CSSSelectorWatch*>( | 66 return static_cast<CSSSelectorWatch*>( |
67 Supplement<Document>::from(document, kSupplementName)); | 67 Supplement<Document>::from(document, kSupplementName)); |
68 } | 68 } |
69 | 69 |
70 void CSSSelectorWatch::callbackSelectorChangeTimerFired(TimerBase*) { | 70 void CSSSelectorWatch::callbackSelectorChangeTimerFired(TimerBase*) { |
71 // Should be ensured by updateSelectorMatches(): | 71 // Should be ensured by updateSelectorMatches(): |
72 DCHECK(!m_addedSelectors.isEmpty() || !m_removedSelectors.isEmpty()); | 72 DCHECK(!m_addedSelectors.isEmpty() || !m_removedSelectors.isEmpty()); |
73 | 73 |
74 if (m_timerExpirations < 1) { | 74 if (m_timerExpirations < 1) { |
75 m_timerExpirations++; | 75 m_timerExpirations++; |
76 m_callbackSelectorChangeTimer.startOneShot(0, BLINK_FROM_HERE); | 76 m_callbackSelectorChangeTimer.startOneShot(0, BLINK_FROM_HERE); |
77 return; | 77 return; |
78 } | 78 } |
79 if (document().frame()) { | 79 if (host()->frame()) { |
sof
2017/01/06 07:55:06
passing comment/thought - might there be a more se
| |
80 Vector<String> addedSelectors; | 80 Vector<String> addedSelectors; |
81 Vector<String> removedSelectors; | 81 Vector<String> removedSelectors; |
82 copyToVector(m_addedSelectors, addedSelectors); | 82 copyToVector(m_addedSelectors, addedSelectors); |
83 copyToVector(m_removedSelectors, removedSelectors); | 83 copyToVector(m_removedSelectors, removedSelectors); |
84 document().frame()->loader().client()->selectorMatchChanged( | 84 host()->frame()->loader().client()->selectorMatchChanged(addedSelectors, |
85 addedSelectors, removedSelectors); | 85 removedSelectors); |
86 } | 86 } |
87 m_addedSelectors.clear(); | 87 m_addedSelectors.clear(); |
88 m_removedSelectors.clear(); | 88 m_removedSelectors.clear(); |
89 m_timerExpirations = 0; | 89 m_timerExpirations = 0; |
90 } | 90 } |
91 | 91 |
92 void CSSSelectorWatch::updateSelectorMatches( | 92 void CSSSelectorWatch::updateSelectorMatches( |
93 const Vector<String>& removedSelectors, | 93 const Vector<String>& removedSelectors, |
94 const Vector<String>& addedSelectors) { | 94 const Vector<String>& addedSelectors) { |
95 bool shouldUpdateTimer = false; | 95 bool shouldUpdateTimer = false; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 if (!selectorList.isValid()) | 157 if (!selectorList.isValid()) |
158 continue; | 158 continue; |
159 | 159 |
160 // Only accept Compound Selectors, since they're cheaper to match. | 160 // Only accept Compound Selectors, since they're cheaper to match. |
161 if (!allCompound(selectorList)) | 161 if (!allCompound(selectorList)) |
162 continue; | 162 continue; |
163 | 163 |
164 m_watchedCallbackSelectors.push_back( | 164 m_watchedCallbackSelectors.push_back( |
165 StyleRule::create(std::move(selectorList), callbackPropertySet)); | 165 StyleRule::create(std::move(selectorList), callbackPropertySet)); |
166 } | 166 } |
167 document().styleEngine().watchedSelectorsChanged(); | 167 host()->styleEngine().watchedSelectorsChanged(); |
168 } | 168 } |
169 | 169 |
170 DEFINE_TRACE(CSSSelectorWatch) { | 170 DEFINE_TRACE(CSSSelectorWatch) { |
171 visitor->trace(m_watchedCallbackSelectors); | 171 visitor->trace(m_watchedCallbackSelectors); |
172 visitor->trace(m_document); | |
173 Supplement<Document>::trace(visitor); | 172 Supplement<Document>::trace(visitor); |
174 } | 173 } |
175 | 174 |
176 } // namespace blink | 175 } // namespace blink |
OLD | NEW |