apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010, Google Inc. 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 | * 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. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 | * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 17 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 20 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | */ |
| 24 | |
| 25 | #include "config.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 26 | |
| 27 | #if ENABLE(INSPECTOR) |
| 28 | |
yurys@chromium.org | 83110c8 | 2012-03-15 16:44:09 +0000 | [diff] [blame] | 29 | #include "InspectorCSSAgent.h" |
| 30 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 31 | #include "CSSComputedStyleDeclaration.h" |
apavlov@chromium.org | be789cf | 2011-05-18 13:32:07 +0000 | [diff] [blame] | 32 | #include "CSSImportRule.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 33 | #include "CSSPropertyNames.h" |
| 34 | #include "CSSPropertySourceData.h" |
| 35 | #include "CSSRule.h" |
| 36 | #include "CSSRuleList.h" |
| 37 | #include "CSSStyleRule.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 38 | #include "CSSStyleSheet.h" |
apavlov@chromium.org | 31442e8 | 2012-03-05 10:44:40 +0000 | [diff] [blame] | 39 | #include "ContentSecurityPolicy.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 40 | #include "DOMWindow.h" |
| 41 | #include "HTMLHeadElement.h" |
| 42 | #include "InspectorDOMAgent.h" |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 43 | #include "InspectorHistory.h" |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 44 | #include "InspectorState.h" |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 45 | #include "InspectorTypeBuilder.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 46 | #include "InspectorValues.h" |
yurys@chromium.org | 29626f8 | 2011-03-04 15:15:45 +0000 | [diff] [blame] | 47 | #include "InstrumentingAgents.h" |
rniwa@webkit.org | 3fc452e | 2012-08-24 21:46:24 +0000 | [diff] [blame] | 48 | #include "NamedFlowCollection.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 49 | #include "Node.h" |
pfeldman@chromium.org | 840f348 | 2011-02-11 15:23:26 +0000 | [diff] [blame] | 50 | #include "NodeList.h" |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 51 | #include "RenderRegion.h" |
antti@apple.com | f660180 | 2012-02-03 22:41:09 +0000 | [diff] [blame] | 52 | #include "StylePropertySet.h" |
pfeldman@chromium.org | a712894 | 2012-07-25 13:48:47 +0000 | [diff] [blame] | 53 | #include "StylePropertyShorthand.h" |
alexis.menard@openbossa.org | e6db2f6 | 2012-04-25 15:49:08 +0000 | [diff] [blame] | 54 | #include "StyleResolver.h" |
antti@apple.com | 8be9b56 | 2012-02-28 17:44:18 +0000 | [diff] [blame] | 55 | #include "StyleRule.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 56 | #include "StyleSheetList.h" |
commit-queue@webkit.org | 285994b | 2012-07-24 12:00:33 +0000 | [diff] [blame] | 57 | #include "WebKitNamedFlow.h" |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 58 | |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 59 | #include <wtf/CurrentTime.h> |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 60 | #include <wtf/HashSet.h> |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 61 | #include <wtf/Vector.h> |
| 62 | #include <wtf/text/CString.h> |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 63 | #include <wtf/text/StringConcatenate.h> |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 64 | |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 65 | namespace CSSAgentState { |
| 66 | static const char cssAgentEnabled[] = "cssAgentEnabled"; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 67 | static const char isSelectorProfiling[] = "isSelectorProfiling"; |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 68 | } |
| 69 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 70 | namespace WebCore { |
| 71 | |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 72 | enum ForcePseudoClassFlags { |
| 73 | PseudoNone = 0, |
| 74 | PseudoHover = 1 << 0, |
| 75 | PseudoFocus = 1 << 1, |
| 76 | PseudoActive = 1 << 2, |
| 77 | PseudoVisited = 1 << 3 |
| 78 | }; |
| 79 | |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 80 | struct RuleMatchData { |
| 81 | String selector; |
| 82 | String url; |
| 83 | unsigned lineNumber; |
| 84 | double startTime; |
| 85 | }; |
| 86 | |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 87 | struct RuleMatchingStats { |
| 88 | RuleMatchingStats() |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 89 | : lineNumber(0), totalTime(0.0), hits(0), matches(0) |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 90 | { |
| 91 | } |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 92 | RuleMatchingStats(const RuleMatchData& data, double totalTime, unsigned hits, unsigned matches) |
| 93 | : selector(data.selector), url(data.url), lineNumber(data.lineNumber), totalTime(totalTime), hits(hits), matches(matches) |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 94 | { |
| 95 | } |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 96 | |
| 97 | String selector; |
| 98 | String url; |
| 99 | unsigned lineNumber; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 100 | double totalTime; |
| 101 | unsigned hits; |
| 102 | unsigned matches; |
| 103 | }; |
| 104 | |
| 105 | class SelectorProfile { |
zoltan@webkit.org | 2eb7bec | 2012-09-14 09:12:48 +0000 | [diff] [blame] | 106 | WTF_MAKE_FAST_ALLOCATED; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 107 | public: |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 108 | SelectorProfile() |
| 109 | : m_totalMatchingTimeMs(0.0) |
| 110 | { |
| 111 | } |
| 112 | virtual ~SelectorProfile() |
| 113 | { |
| 114 | } |
| 115 | |
| 116 | double totalMatchingTimeMs() const { return m_totalMatchingTimeMs; } |
| 117 | |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 118 | String makeKey(); |
| 119 | void startSelector(const CSSStyleRule*); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 120 | void commitSelector(bool); |
| 121 | void commitSelectorTime(); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 122 | PassRefPtr<TypeBuilder::CSS::SelectorProfile> toInspectorObject() const; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 123 | |
| 124 | private: |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 125 | |
| 126 | // Key is "selector?url:line". |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 127 | typedef HashMap<String, RuleMatchingStats> RuleMatchingStatsMap; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 128 | |
| 129 | double m_totalMatchingTimeMs; |
| 130 | RuleMatchingStatsMap m_ruleMatchingStats; |
| 131 | RuleMatchData m_currentMatchData; |
| 132 | }; |
| 133 | |
| 134 | |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 135 | static unsigned computePseudoClassMask(InspectorArray* pseudoClassArray) |
| 136 | { |
abarth@webkit.org | f6d1b8c | 2012-08-29 07:38:10 +0000 | [diff] [blame] | 137 | DEFINE_STATIC_LOCAL(String, active, (ASCIILiteral("active"))); |
| 138 | DEFINE_STATIC_LOCAL(String, hover, (ASCIILiteral("hover"))); |
| 139 | DEFINE_STATIC_LOCAL(String, focus, (ASCIILiteral("focus"))); |
| 140 | DEFINE_STATIC_LOCAL(String, visited, (ASCIILiteral("visited"))); |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 141 | if (!pseudoClassArray || !pseudoClassArray->length()) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 142 | return PseudoNone; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 143 | |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 144 | unsigned result = PseudoNone; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 145 | for (size_t i = 0; i < pseudoClassArray->length(); ++i) { |
| 146 | RefPtr<InspectorValue> pseudoClassValue = pseudoClassArray->get(i); |
| 147 | String pseudoClass; |
| 148 | bool success = pseudoClassValue->asString(&pseudoClass); |
| 149 | if (!success) |
| 150 | continue; |
| 151 | if (pseudoClass == active) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 152 | result |= PseudoActive; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 153 | else if (pseudoClass == hover) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 154 | result |= PseudoHover; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 155 | else if (pseudoClass == focus) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 156 | result |= PseudoFocus; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 157 | else if (pseudoClass == visited) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 158 | result |= PseudoVisited; |
apavlov@chromium.org | 6678c9b | 2011-06-28 12:07:48 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | return result; |
| 162 | } |
| 163 | |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 164 | inline String SelectorProfile::makeKey() |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 165 | { |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 166 | return makeString(m_currentMatchData.selector, "?", m_currentMatchData.url, ":", String::number(m_currentMatchData.lineNumber)); |
| 167 | } |
| 168 | |
| 169 | inline void SelectorProfile::startSelector(const CSSStyleRule* rule) |
| 170 | { |
| 171 | m_currentMatchData.selector = rule->selectorText(); |
| 172 | CSSStyleSheet* styleSheet = rule->parentStyleSheet(); |
| 173 | String url = emptyString(); |
| 174 | if (styleSheet) { |
| 175 | url = InspectorStyleSheet::styleSheetURL(styleSheet); |
| 176 | if (url.isEmpty()) |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 177 | url = InspectorDOMAgent::documentURLString(styleSheet->ownerDocument()); |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 178 | } |
| 179 | m_currentMatchData.url = url; |
antti@apple.com | 972c082 | 2012-02-28 09:38:51 +0000 | [diff] [blame] | 180 | m_currentMatchData.lineNumber = rule->styleRule()->sourceLine(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 181 | m_currentMatchData.startTime = WTF::currentTimeMS(); |
| 182 | } |
| 183 | |
| 184 | inline void SelectorProfile::commitSelector(bool matched) |
| 185 | { |
| 186 | double matchTimeMs = WTF::currentTimeMS() - m_currentMatchData.startTime; |
| 187 | m_totalMatchingTimeMs += matchTimeMs; |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 188 | |
caio.oliveira@openbossa.org | 4c11ee0 | 2012-03-29 18:48:23 +0000 | [diff] [blame] | 189 | RuleMatchingStatsMap::AddResult result = m_ruleMatchingStats.add(makeKey(), RuleMatchingStats(m_currentMatchData, matchTimeMs, 1, matched ? 1 : 0)); |
| 190 | if (!result.isNewEntry) { |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 191 | result.iterator->value.totalTime += matchTimeMs; |
| 192 | result.iterator->value.hits += 1; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 193 | if (matched) |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 194 | result.iterator->value.matches += 1; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
| 198 | inline void SelectorProfile::commitSelectorTime() |
| 199 | { |
| 200 | double processingTimeMs = WTF::currentTimeMS() - m_currentMatchData.startTime; |
| 201 | m_totalMatchingTimeMs += processingTimeMs; |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 202 | |
| 203 | RuleMatchingStatsMap::iterator it = m_ruleMatchingStats.find(makeKey()); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 204 | if (it == m_ruleMatchingStats.end()) |
| 205 | return; |
| 206 | |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 207 | it->value.totalTime += processingTimeMs; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 208 | } |
| 209 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 210 | PassRefPtr<TypeBuilder::CSS::SelectorProfile> SelectorProfile::toInspectorObject() const |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 211 | { |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 212 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::SelectorProfileEntry> > selectorProfileData = TypeBuilder::Array<TypeBuilder::CSS::SelectorProfileEntry>::create(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 213 | for (RuleMatchingStatsMap::const_iterator it = m_ruleMatchingStats.begin(); it != m_ruleMatchingStats.end(); ++it) { |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 214 | RefPtr<TypeBuilder::CSS::SelectorProfileEntry> entry = TypeBuilder::CSS::SelectorProfileEntry::create() |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 215 | .setSelector(it->value.selector) |
| 216 | .setUrl(it->value.url) |
| 217 | .setLineNumber(it->value.lineNumber) |
| 218 | .setTime(it->value.totalTime) |
| 219 | .setHitCount(it->value.hits) |
| 220 | .setMatchCount(it->value.matches); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 221 | selectorProfileData->addItem(entry.release()); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | RefPtr<TypeBuilder::CSS::SelectorProfile> result = TypeBuilder::CSS::SelectorProfile::create() |
| 225 | .setTotalTime(totalMatchingTimeMs()) |
apavlov@chromium.org | 5ee19fd | 2012-01-11 15:14:44 +0000 | [diff] [blame] | 226 | .setData(selectorProfileData); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 227 | return result.release(); |
| 228 | } |
| 229 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 230 | class UpdateRegionLayoutTask { |
| 231 | public: |
| 232 | UpdateRegionLayoutTask(InspectorCSSAgent*); |
| 233 | void scheduleFor(WebKitNamedFlow*, int documentNodeId); |
| 234 | void unschedule(WebKitNamedFlow*); |
| 235 | void reset(); |
| 236 | void onTimer(Timer<UpdateRegionLayoutTask>*); |
| 237 | |
| 238 | private: |
| 239 | InspectorCSSAgent* m_cssAgent; |
| 240 | Timer<UpdateRegionLayoutTask> m_timer; |
| 241 | HashMap<WebKitNamedFlow*, int> m_namedFlows; |
| 242 | }; |
| 243 | |
| 244 | UpdateRegionLayoutTask::UpdateRegionLayoutTask(InspectorCSSAgent* cssAgent) |
| 245 | : m_cssAgent(cssAgent) |
| 246 | , m_timer(this, &UpdateRegionLayoutTask::onTimer) |
| 247 | { |
| 248 | } |
| 249 | |
| 250 | void UpdateRegionLayoutTask::scheduleFor(WebKitNamedFlow* namedFlow, int documentNodeId) |
| 251 | { |
| 252 | m_namedFlows.add(namedFlow, documentNodeId); |
| 253 | |
| 254 | if (!m_timer.isActive()) |
| 255 | m_timer.startOneShot(0); |
| 256 | } |
| 257 | |
| 258 | void UpdateRegionLayoutTask::unschedule(WebKitNamedFlow* namedFlow) |
| 259 | { |
| 260 | m_namedFlows.remove(namedFlow); |
| 261 | } |
| 262 | |
| 263 | void UpdateRegionLayoutTask::reset() |
| 264 | { |
| 265 | m_timer.stop(); |
| 266 | m_namedFlows.clear(); |
| 267 | } |
| 268 | |
| 269 | void UpdateRegionLayoutTask::onTimer(Timer<UpdateRegionLayoutTask>*) |
| 270 | { |
| 271 | // The timer is stopped on m_cssAgent destruction, so this method will never be called after m_cssAgent has been destroyed. |
| 272 | Vector<std::pair<WebKitNamedFlow*, int> > namedFlows; |
| 273 | |
| 274 | for (HashMap<WebKitNamedFlow*, int>::iterator it = m_namedFlows.begin(), end = m_namedFlows.end(); it != end; ++it) |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 275 | namedFlows.append(std::make_pair(it->key, it->value)); |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 276 | |
| 277 | for (unsigned i = 0, size = namedFlows.size(); i < size; ++i) { |
| 278 | WebKitNamedFlow* namedFlow = namedFlows.at(i).first; |
| 279 | int documentNodeId = namedFlows.at(i).second; |
| 280 | |
| 281 | if (m_namedFlows.contains(namedFlow)) { |
| 282 | m_cssAgent->regionLayoutUpdated(namedFlow, documentNodeId); |
| 283 | m_namedFlows.remove(namedFlow); |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | if (!m_namedFlows.isEmpty() && !m_timer.isActive()) |
| 288 | m_timer.startOneShot(0); |
| 289 | } |
| 290 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 291 | class InspectorCSSAgent::StyleSheetAction : public InspectorHistory::Action { |
| 292 | WTF_MAKE_NONCOPYABLE(StyleSheetAction); |
| 293 | public: |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 294 | StyleSheetAction(const String& name, InspectorStyleSheet* styleSheet) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 295 | : InspectorHistory::Action(name) |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 296 | , m_styleSheet(styleSheet) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 297 | { |
| 298 | } |
| 299 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 300 | protected: |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 301 | RefPtr<InspectorStyleSheet> m_styleSheet; |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | class InspectorCSSAgent::SetStyleSheetTextAction : public InspectorCSSAgent::StyleSheetAction { |
| 305 | WTF_MAKE_NONCOPYABLE(SetStyleSheetTextAction); |
| 306 | public: |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 307 | SetStyleSheetTextAction(InspectorStyleSheet* styleSheet, const String& text) |
| 308 | : InspectorCSSAgent::StyleSheetAction("SetStyleSheetText", styleSheet) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 309 | , m_text(text) |
| 310 | { |
| 311 | } |
| 312 | |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 313 | virtual bool perform(ExceptionCode& ec) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 314 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 315 | if (!m_styleSheet->getText(&m_oldText)) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 316 | return false; |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 317 | return redo(ec); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 318 | } |
| 319 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 320 | virtual bool undo(ExceptionCode&) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 321 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 322 | if (m_styleSheet->setText(m_oldText)) { |
| 323 | m_styleSheet->reparseStyleSheet(m_oldText); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 324 | return true; |
| 325 | } |
| 326 | return false; |
| 327 | } |
| 328 | |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 329 | virtual bool redo(ExceptionCode&) |
| 330 | { |
| 331 | if (m_styleSheet->setText(m_text)) { |
| 332 | m_styleSheet->reparseStyleSheet(m_text); |
| 333 | return true; |
| 334 | } |
| 335 | return false; |
| 336 | } |
| 337 | |
pfeldman@chromium.org | a1a70a4 | 2012-02-14 08:50:19 +0000 | [diff] [blame] | 338 | virtual String mergeId() |
| 339 | { |
| 340 | return String::format("SetStyleSheetText %s", m_styleSheet->id().utf8().data()); |
| 341 | } |
| 342 | |
| 343 | virtual void merge(PassOwnPtr<Action> action) |
| 344 | { |
| 345 | ASSERT(action->mergeId() == mergeId()); |
| 346 | |
| 347 | SetStyleSheetTextAction* other = static_cast<SetStyleSheetTextAction*>(action.get()); |
| 348 | m_text = other->m_text; |
| 349 | } |
| 350 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 351 | private: |
| 352 | String m_text; |
| 353 | String m_oldText; |
| 354 | }; |
| 355 | |
| 356 | class InspectorCSSAgent::SetPropertyTextAction : public InspectorCSSAgent::StyleSheetAction { |
| 357 | WTF_MAKE_NONCOPYABLE(SetPropertyTextAction); |
| 358 | public: |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 359 | SetPropertyTextAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, const String& text, bool overwrite) |
| 360 | : InspectorCSSAgent::StyleSheetAction("SetPropertyText", styleSheet) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 361 | , m_cssId(cssId) |
| 362 | , m_propertyIndex(propertyIndex) |
| 363 | , m_text(text) |
| 364 | , m_overwrite(overwrite) |
| 365 | { |
| 366 | } |
| 367 | |
| 368 | virtual String toString() |
| 369 | { |
| 370 | return mergeId() + ": " + m_oldText + " -> " + m_text; |
| 371 | } |
| 372 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 373 | virtual bool perform(ExceptionCode& ec) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 374 | { |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 375 | return redo(ec); |
| 376 | } |
| 377 | |
| 378 | virtual bool undo(ExceptionCode& ec) |
| 379 | { |
| 380 | String placeholder; |
| 381 | return m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_overwrite ? m_oldText : "", true, &placeholder, ec); |
| 382 | } |
| 383 | |
| 384 | virtual bool redo(ExceptionCode& ec) |
| 385 | { |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 386 | String oldText; |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 387 | bool result = m_styleSheet->setPropertyText(m_cssId, m_propertyIndex, m_text, m_overwrite, &oldText, ec); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 388 | m_oldText = oldText.stripWhiteSpace(); |
| 389 | // FIXME: remove this once the model handles this case. |
benjamin@webkit.org | 127cec2c | 2012-04-30 21:32:44 +0000 | [diff] [blame] | 390 | if (!m_oldText.endsWith(';')) |
abarth@webkit.org | 96a2c95 | 2012-08-31 01:25:43 +0000 | [diff] [blame] | 391 | m_oldText.append(';'); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 392 | return result; |
| 393 | } |
| 394 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 395 | virtual String mergeId() |
| 396 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 397 | return String::format("SetPropertyText %s:%u:%s", m_styleSheet->id().utf8().data(), m_propertyIndex, m_overwrite ? "true" : "false"); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | virtual void merge(PassOwnPtr<Action> action) |
| 401 | { |
| 402 | ASSERT(action->mergeId() == mergeId()); |
| 403 | |
| 404 | SetPropertyTextAction* other = static_cast<SetPropertyTextAction*>(action.get()); |
| 405 | m_text = other->m_text; |
| 406 | } |
| 407 | |
| 408 | private: |
| 409 | InspectorCSSId m_cssId; |
| 410 | unsigned m_propertyIndex; |
| 411 | String m_text; |
| 412 | String m_oldText; |
| 413 | bool m_overwrite; |
| 414 | }; |
| 415 | |
| 416 | class InspectorCSSAgent::TogglePropertyAction : public InspectorCSSAgent::StyleSheetAction { |
| 417 | WTF_MAKE_NONCOPYABLE(TogglePropertyAction); |
| 418 | public: |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 419 | TogglePropertyAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, unsigned propertyIndex, bool disable) |
| 420 | : InspectorCSSAgent::StyleSheetAction("ToggleProperty", styleSheet) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 421 | , m_cssId(cssId) |
| 422 | , m_propertyIndex(propertyIndex) |
| 423 | , m_disable(disable) |
| 424 | { |
| 425 | } |
| 426 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 427 | virtual bool perform(ExceptionCode& ec) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 428 | { |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 429 | return redo(ec); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 430 | } |
| 431 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 432 | virtual bool undo(ExceptionCode& ec) |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 433 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 434 | return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, !m_disable, ec); |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 435 | } |
| 436 | |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 437 | virtual bool redo(ExceptionCode& ec) |
| 438 | { |
| 439 | return m_styleSheet->toggleProperty(m_cssId, m_propertyIndex, m_disable, ec); |
| 440 | } |
| 441 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 442 | private: |
| 443 | InspectorCSSId m_cssId; |
| 444 | unsigned m_propertyIndex; |
| 445 | bool m_disable; |
| 446 | }; |
| 447 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 448 | class InspectorCSSAgent::SetRuleSelectorAction : public InspectorCSSAgent::StyleSheetAction { |
| 449 | WTF_MAKE_NONCOPYABLE(SetRuleSelectorAction); |
| 450 | public: |
| 451 | SetRuleSelectorAction(InspectorStyleSheet* styleSheet, const InspectorCSSId& cssId, const String& selector) |
| 452 | : InspectorCSSAgent::StyleSheetAction("SetRuleSelector", styleSheet) |
| 453 | , m_cssId(cssId) |
| 454 | , m_selector(selector) |
| 455 | { |
| 456 | } |
| 457 | |
| 458 | virtual bool perform(ExceptionCode& ec) |
| 459 | { |
| 460 | m_oldSelector = m_styleSheet->ruleSelector(m_cssId, ec); |
| 461 | if (ec) |
| 462 | return false; |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 463 | return redo(ec); |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | virtual bool undo(ExceptionCode& ec) |
| 467 | { |
| 468 | return m_styleSheet->setRuleSelector(m_cssId, m_oldSelector, ec); |
| 469 | } |
| 470 | |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 471 | virtual bool redo(ExceptionCode& ec) |
| 472 | { |
| 473 | return m_styleSheet->setRuleSelector(m_cssId, m_selector, ec); |
| 474 | } |
| 475 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 476 | private: |
| 477 | InspectorCSSId m_cssId; |
| 478 | String m_selector; |
| 479 | String m_oldSelector; |
| 480 | }; |
| 481 | |
| 482 | class InspectorCSSAgent::AddRuleAction : public InspectorCSSAgent::StyleSheetAction { |
| 483 | WTF_MAKE_NONCOPYABLE(AddRuleAction); |
| 484 | public: |
| 485 | AddRuleAction(InspectorStyleSheet* styleSheet, const String& selector) |
| 486 | : InspectorCSSAgent::StyleSheetAction("AddRule", styleSheet) |
| 487 | , m_selector(selector) |
| 488 | { |
| 489 | } |
| 490 | |
| 491 | virtual bool perform(ExceptionCode& ec) |
| 492 | { |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 493 | return redo(ec); |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | virtual bool undo(ExceptionCode& ec) |
| 497 | { |
| 498 | return m_styleSheet->deleteRule(m_newId, ec); |
| 499 | } |
| 500 | |
pfeldman@chromium.org | a9730c4 | 2012-02-15 09:12:15 +0000 | [diff] [blame] | 501 | virtual bool redo(ExceptionCode& ec) |
| 502 | { |
| 503 | CSSStyleRule* cssStyleRule = m_styleSheet->addRule(m_selector, ec); |
| 504 | if (ec) |
| 505 | return false; |
| 506 | m_newId = m_styleSheet->ruleId(cssStyleRule); |
| 507 | return true; |
| 508 | } |
| 509 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 510 | InspectorCSSId newRuleId() { return m_newId; } |
| 511 | |
| 512 | private: |
| 513 | InspectorCSSId m_newId; |
| 514 | String m_selector; |
| 515 | String m_oldSelector; |
| 516 | }; |
| 517 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 518 | // static |
andreas.kling@nokia.com | f04e49c | 2011-10-14 21:33:49 +0000 | [diff] [blame] | 519 | CSSStyleRule* InspectorCSSAgent::asCSSStyleRule(CSSRule* rule) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 520 | { |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame^] | 521 | if (rule->type() != CSSRule::STYLE_RULE) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 522 | return 0; |
| 523 | return static_cast<CSSStyleRule*>(rule); |
| 524 | } |
| 525 | |
pfeldman@chromium.org | ccc8cd93 | 2011-11-28 14:41:48 +0000 | [diff] [blame] | 526 | InspectorCSSAgent::InspectorCSSAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, InspectorDOMAgent* domAgent) |
pfeldman@chromium.org | 2f44edb | 2011-11-29 14:43:10 +0000 | [diff] [blame] | 527 | : InspectorBaseAgent<InspectorCSSAgent>("CSS", instrumentingAgents, state) |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 528 | , m_frontend(0) |
yurys@chromium.org | 29626f8 | 2011-03-04 15:15:45 +0000 | [diff] [blame] | 529 | , m_domAgent(domAgent) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 530 | , m_lastStyleSheetId(1) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 531 | { |
yurys@chromium.org | d8e367c | 2011-02-21 14:38:24 +0000 | [diff] [blame] | 532 | m_domAgent->setDOMListener(this); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | InspectorCSSAgent::~InspectorCSSAgent() |
| 536 | { |
pfeldman@chromium.org | eccfccf | 2011-12-02 08:21:57 +0000 | [diff] [blame] | 537 | ASSERT(!m_domAgent); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 538 | reset(); |
| 539 | } |
| 540 | |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 541 | void InspectorCSSAgent::setFrontend(InspectorFrontend* frontend) |
| 542 | { |
| 543 | ASSERT(!m_frontend); |
| 544 | m_frontend = frontend->css(); |
| 545 | } |
| 546 | |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 547 | void InspectorCSSAgent::clearFrontend() |
| 548 | { |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 549 | ASSERT(m_frontend); |
| 550 | m_frontend = 0; |
apavlov@chromium.org | d63acd8 | 2012-09-13 08:41:26 +0000 | [diff] [blame] | 551 | resetNonPersistentData(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 552 | String errorString; |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 553 | stopSelectorProfilerImpl(&errorString, false); |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 554 | } |
| 555 | |
pfeldman@chromium.org | eccfccf | 2011-12-02 08:21:57 +0000 | [diff] [blame] | 556 | void InspectorCSSAgent::discardAgent() |
| 557 | { |
| 558 | m_domAgent->setDOMListener(0); |
| 559 | m_domAgent = 0; |
| 560 | } |
| 561 | |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 562 | void InspectorCSSAgent::restore() |
| 563 | { |
| 564 | if (m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { |
| 565 | ErrorString error; |
| 566 | enable(&error); |
| 567 | } |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 568 | if (m_state->getBoolean(CSSAgentState::isSelectorProfiling)) { |
| 569 | String errorString; |
| 570 | startSelectorProfiler(&errorString); |
| 571 | } |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 572 | } |
| 573 | |
apavlov@chromium.org | 6dbb39d | 2010-11-10 17:12:45 +0000 | [diff] [blame] | 574 | void InspectorCSSAgent::reset() |
| 575 | { |
| 576 | m_idToInspectorStyleSheet.clear(); |
| 577 | m_cssStyleSheetToInspectorStyleSheet.clear(); |
| 578 | m_nodeToInspectorStyleSheet.clear(); |
| 579 | m_documentToInspectorStyleSheet.clear(); |
apavlov@chromium.org | d63acd8 | 2012-09-13 08:41:26 +0000 | [diff] [blame] | 580 | resetNonPersistentData(); |
| 581 | } |
| 582 | |
| 583 | void InspectorCSSAgent::resetNonPersistentData() |
| 584 | { |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 585 | m_namedFlowCollectionsRequested.clear(); |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 586 | if (m_updateRegionLayoutTask) |
| 587 | m_updateRegionLayoutTask->reset(); |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 588 | resetPseudoStates(); |
apavlov@chromium.org | 6dbb39d | 2010-11-10 17:12:45 +0000 | [diff] [blame] | 589 | } |
| 590 | |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 591 | void InspectorCSSAgent::enable(ErrorString*) |
| 592 | { |
| 593 | m_state->setBoolean(CSSAgentState::cssAgentEnabled, true); |
apavlov@chromium.org | d63acd8 | 2012-09-13 08:41:26 +0000 | [diff] [blame] | 594 | m_instrumentingAgents->setInspectorCSSAgent(this); |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | void InspectorCSSAgent::disable(ErrorString*) |
| 598 | { |
apavlov@chromium.org | d63acd8 | 2012-09-13 08:41:26 +0000 | [diff] [blame] | 599 | m_instrumentingAgents->setInspectorCSSAgent(0); |
apavlov@chromium.org | ad517d0 | 2011-12-15 09:23:19 +0000 | [diff] [blame] | 600 | m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); |
| 601 | } |
| 602 | |
| 603 | void InspectorCSSAgent::mediaQueryResultChanged() |
| 604 | { |
| 605 | if (m_frontend) |
| 606 | m_frontend->mediaQueryResultChanged(); |
| 607 | } |
| 608 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 609 | void InspectorCSSAgent::didCreateNamedFlow(Document* document, WebKitNamedFlow* namedFlow) |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 610 | { |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 611 | int documentNodeId = documentNodeWithRequestedFlowsId(document); |
| 612 | if (!documentNodeId) |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 613 | return; |
| 614 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 615 | ErrorString errorString; |
| 616 | m_frontend->namedFlowCreated(buildObjectForNamedFlow(&errorString, namedFlow, documentNodeId)); |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 617 | } |
| 618 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 619 | void InspectorCSSAgent::willRemoveNamedFlow(Document* document, WebKitNamedFlow* namedFlow) |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 620 | { |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 621 | int documentNodeId = documentNodeWithRequestedFlowsId(document); |
| 622 | if (!documentNodeId) |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 623 | return; |
| 624 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 625 | if (m_updateRegionLayoutTask) |
| 626 | m_updateRegionLayoutTask->unschedule(namedFlow); |
| 627 | |
| 628 | m_frontend->namedFlowRemoved(documentNodeId, namedFlow->name().string()); |
| 629 | } |
| 630 | |
| 631 | void InspectorCSSAgent::didUpdateRegionLayout(Document* document, WebKitNamedFlow* namedFlow) |
| 632 | { |
| 633 | int documentNodeId = documentNodeWithRequestedFlowsId(document); |
| 634 | if (!documentNodeId) |
| 635 | return; |
| 636 | |
| 637 | if (!m_updateRegionLayoutTask) |
| 638 | m_updateRegionLayoutTask = adoptPtr(new UpdateRegionLayoutTask(this)); |
| 639 | m_updateRegionLayoutTask->scheduleFor(namedFlow, documentNodeId); |
| 640 | } |
| 641 | |
| 642 | void InspectorCSSAgent::regionLayoutUpdated(WebKitNamedFlow* namedFlow, int documentNodeId) |
| 643 | { |
| 644 | if (namedFlow->flowState() == WebKitNamedFlow::FlowStateNull) |
| 645 | return; |
| 646 | |
| 647 | ErrorString errorString; |
| 648 | RefPtr<WebKitNamedFlow> protector(namedFlow); |
| 649 | |
| 650 | m_frontend->regionLayoutUpdated(buildObjectForNamedFlow(&errorString, namedFlow, documentNodeId)); |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 651 | } |
| 652 | |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 653 | bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoType pseudoType) |
| 654 | { |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 655 | if (m_nodeIdToForcedPseudoState.isEmpty()) |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 656 | return false; |
| 657 | |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 658 | int nodeId = m_domAgent->boundNodeId(element); |
| 659 | if (!nodeId) |
| 660 | return false; |
| 661 | |
| 662 | NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.find(nodeId); |
| 663 | if (it == m_nodeIdToForcedPseudoState.end()) |
| 664 | return false; |
| 665 | |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 666 | unsigned forcedPseudoState = it->value; |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 667 | switch (pseudoType) { |
| 668 | case CSSSelector::PseudoActive: |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 669 | return forcedPseudoState & PseudoActive; |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 670 | case CSSSelector::PseudoFocus: |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 671 | return forcedPseudoState & PseudoFocus; |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 672 | case CSSSelector::PseudoHover: |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 673 | return forcedPseudoState & PseudoHover; |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 674 | case CSSSelector::PseudoVisited: |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 675 | return forcedPseudoState & PseudoVisited; |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 676 | default: |
| 677 | return false; |
| 678 | } |
| 679 | } |
| 680 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 681 | void InspectorCSSAgent::getMatchedStylesForNode(ErrorString* errorString, int nodeId, const bool* includePseudo, const bool* includeInherited, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> >& matchedCSSRules, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> >& pseudoIdMatches, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> >& inheritedEntries) |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 682 | { |
| 683 | Element* element = elementForId(errorString, nodeId); |
| 684 | if (!element) |
| 685 | return; |
| 686 | |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 687 | // Matched rules. |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 688 | StyleResolver* styleResolver = element->ownerDocument()->styleResolver(); |
| 689 | RefPtr<CSSRuleList> matchedRules = styleResolver->styleRulesForElement(element, StyleResolver::AllCSSRules); |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 690 | matchedCSSRules = buildArrayForMatchedRuleList(matchedRules.get(), styleResolver, element); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 691 | |
| 692 | // Pseudo elements. |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 693 | if (!includePseudo || *includePseudo) { |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 694 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches> > pseudoElements = TypeBuilder::Array<TypeBuilder::CSS::PseudoIdMatches>::create(); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 695 | for (PseudoId pseudoId = FIRST_PUBLIC_PSEUDOID; pseudoId < AFTER_LAST_INTERNAL_PSEUDOID; pseudoId = static_cast<PseudoId>(pseudoId + 1)) { |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 696 | RefPtr<CSSRuleList> matchedRules = styleResolver->pseudoStyleRulesForElement(element, pseudoId, StyleResolver::AllCSSRules); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 697 | if (matchedRules && matchedRules->length()) { |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 698 | RefPtr<TypeBuilder::CSS::PseudoIdMatches> matches = TypeBuilder::CSS::PseudoIdMatches::create() |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 699 | .setPseudoId(static_cast<int>(pseudoId)) |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 700 | .setMatches(buildArrayForMatchedRuleList(matchedRules.get(), styleResolver, element)); |
| 701 | pseudoElements->addItem(matches.release()); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 705 | pseudoIdMatches = pseudoElements.release(); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | // Inherited styles. |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 709 | if (!includeInherited || *includeInherited) { |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 710 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry> > entries = TypeBuilder::Array<TypeBuilder::CSS::InheritedStyleEntry>::create(); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 711 | Element* parentElement = element->parentElement(); |
| 712 | while (parentElement) { |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 713 | StyleResolver* parentStyleResolver = parentElement->ownerDocument()->styleResolver(); |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 714 | RefPtr<CSSRuleList> parentMatchedRules = parentStyleResolver->styleRulesForElement(parentElement, StyleResolver::AllCSSRules); |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 715 | RefPtr<TypeBuilder::CSS::InheritedStyleEntry> entry = TypeBuilder::CSS::InheritedStyleEntry::create() |
| 716 | .setMatchedCSSRules(buildArrayForMatchedRuleList(parentMatchedRules.get(), styleResolver, parentElement)); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 717 | if (parentElement->style() && parentElement->style()->length()) { |
| 718 | InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(parentElement); |
| 719 | if (styleSheet) |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 720 | entry->setInlineStyle(styleSheet->buildObjectForStyle(styleSheet->styleForId(InspectorCSSId(styleSheet->id(), 0)))); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 721 | } |
| 722 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 723 | entries->addItem(entry.release()); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 724 | parentElement = parentElement->parentElement(); |
| 725 | } |
| 726 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 727 | inheritedEntries = entries.release(); |
apavlov@chromium.org | d35f149 | 2011-11-21 12:19:52 +0000 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 731 | void InspectorCSSAgent::getInlineStylesForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::CSS::CSSStyle>& inlineStyle, RefPtr<TypeBuilder::CSS::CSSStyle>& attributesStyle) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 732 | { |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 733 | Element* element = elementForId(errorString, nodeId); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 734 | if (!element) |
| 735 | return; |
| 736 | |
| 737 | InspectorStyleSheetForInlineStyle* styleSheet = asInspectorStyleSheet(element); |
| 738 | if (!styleSheet) |
| 739 | return; |
| 740 | |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 741 | inlineStyle = styleSheet->buildObjectForStyle(element->style()); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 742 | RefPtr<TypeBuilder::CSS::CSSStyle> attributes = buildObjectForAttributesStyle(element); |
apavlov@chromium.org | 0d4c01a | 2012-02-09 12:41:37 +0000 | [diff] [blame] | 743 | attributesStyle = attributes ? attributes.release() : 0; |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 744 | } |
| 745 | |
apavlov@chromium.org | d728ecd | 2012-08-13 09:06:15 +0000 | [diff] [blame] | 746 | void InspectorCSSAgent::getComputedStyleForNode(ErrorString* errorString, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> >& style) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 747 | { |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 748 | Element* element = elementForId(errorString, nodeId); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 749 | if (!element) |
| 750 | return; |
| 751 | |
antti@apple.com | ac019f3 | 2012-02-10 18:22:24 +0000 | [diff] [blame] | 752 | RefPtr<CSSComputedStyleDeclaration> computedStyleInfo = CSSComputedStyleDeclaration::create(element, true); |
yurys@chromium.org | 418f91f | 2010-12-24 17:51:25 +0000 | [diff] [blame] | 753 | RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), computedStyleInfo, 0); |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 754 | style = inspectorStyle->buildArrayForComputedStyle(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 755 | } |
| 756 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 757 | void InspectorCSSAgent::getAllStyleSheets(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader> >& styleInfos) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 758 | { |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 759 | styleInfos = TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>::create(); |
pfeldman@chromium.org | 840f348 | 2011-02-11 15:23:26 +0000 | [diff] [blame] | 760 | Vector<Document*> documents = m_domAgent->documents(); |
| 761 | for (Vector<Document*>::iterator it = documents.begin(); it != documents.end(); ++it) { |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 762 | StyleSheetList* list = (*it)->styleSheets(); |
| 763 | for (unsigned i = 0; i < list->length(); ++i) { |
| 764 | StyleSheet* styleSheet = list->item(i); |
apavlov@chromium.org | be789cf | 2011-05-18 13:32:07 +0000 | [diff] [blame] | 765 | if (styleSheet->isCSSStyleSheet()) |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 766 | collectStyleSheets(static_cast<CSSStyleSheet*>(styleSheet), styleInfos.get()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 771 | void InspectorCSSAgent::getStyleSheet(ErrorString* errorString, const String& styleSheetId, RefPtr<TypeBuilder::CSS::CSSStyleSheetBody>& styleSheetObject) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 772 | { |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 773 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 774 | if (!inspectorStyleSheet) |
| 775 | return; |
| 776 | |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 777 | styleSheetObject = inspectorStyleSheet->buildObjectForStyleSheet(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 778 | } |
| 779 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 780 | void InspectorCSSAgent::getStyleSheetText(ErrorString* errorString, const String& styleSheetId, String* result) |
pfeldman@chromium.org | 4ee21ff | 2010-11-24 10:11:39 +0000 | [diff] [blame] | 781 | { |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 782 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); |
pfeldman@chromium.org | 4ee21ff | 2010-11-24 10:11:39 +0000 | [diff] [blame] | 783 | if (!inspectorStyleSheet) |
| 784 | return; |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 785 | |
pfeldman@chromium.org | 9445115 | 2012-02-07 17:00:32 +0000 | [diff] [blame] | 786 | inspectorStyleSheet->getText(result); |
pfeldman@chromium.org | 4ee21ff | 2010-11-24 10:11:39 +0000 | [diff] [blame] | 787 | } |
| 788 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 789 | void InspectorCSSAgent::setStyleSheetText(ErrorString* errorString, const String& styleSheetId, const String& text) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 790 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 791 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, styleSheetId); |
| 792 | if (!inspectorStyleSheet) |
| 793 | return; |
| 794 | |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 795 | ExceptionCode ec = 0; |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 796 | m_domAgent->history()->perform(adoptPtr(new SetStyleSheetTextAction(inspectorStyleSheet, text)), ec); |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 797 | *errorString = InspectorDOMAgent::toErrorString(ec); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 798 | } |
| 799 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 800 | void InspectorCSSAgent::setPropertyText(ErrorString* errorString, const RefPtr<InspectorObject>& fullStyleId, int propertyIndex, const String& text, bool overwrite, RefPtr<TypeBuilder::CSS::CSSStyle>& result) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 801 | { |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 802 | InspectorCSSId compoundId(fullStyleId); |
| 803 | ASSERT(!compoundId.isEmpty()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 804 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 805 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 806 | if (!inspectorStyleSheet) |
| 807 | return; |
| 808 | |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 809 | ExceptionCode ec = 0; |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 810 | bool success = m_domAgent->history()->perform(adoptPtr(new SetPropertyTextAction(inspectorStyleSheet, compoundId, propertyIndex, text, overwrite)), ec); |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 811 | if (success) |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 812 | result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId)); |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 813 | *errorString = InspectorDOMAgent::toErrorString(ec); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 814 | } |
| 815 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 816 | void InspectorCSSAgent::toggleProperty(ErrorString* errorString, const RefPtr<InspectorObject>& fullStyleId, int propertyIndex, bool disable, RefPtr<TypeBuilder::CSS::CSSStyle>& result) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 817 | { |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 818 | InspectorCSSId compoundId(fullStyleId); |
| 819 | ASSERT(!compoundId.isEmpty()); |
| 820 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 821 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 822 | if (!inspectorStyleSheet) |
| 823 | return; |
| 824 | |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 825 | ExceptionCode ec = 0; |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 826 | bool success = m_domAgent->history()->perform(adoptPtr(new TogglePropertyAction(inspectorStyleSheet, compoundId, propertyIndex, disable)), ec); |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 827 | if (success) |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 828 | result = inspectorStyleSheet->buildObjectForStyle(inspectorStyleSheet->styleForId(compoundId)); |
pfeldman@chromium.org | b5db6a1 | 2012-02-10 13:15:12 +0000 | [diff] [blame] | 829 | *errorString = InspectorDOMAgent::toErrorString(ec); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 830 | } |
| 831 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 832 | void InspectorCSSAgent::setRuleSelector(ErrorString* errorString, const RefPtr<InspectorObject>& fullRuleId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 833 | { |
apavlov@chromium.org | fc8a58c | 2010-10-22 15:04:52 +0000 | [diff] [blame] | 834 | InspectorCSSId compoundId(fullRuleId); |
| 835 | ASSERT(!compoundId.isEmpty()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 836 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 837 | InspectorStyleSheet* inspectorStyleSheet = assertStyleSheetForId(errorString, compoundId.styleSheetId()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 838 | if (!inspectorStyleSheet) |
| 839 | return; |
| 840 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 841 | ExceptionCode ec = 0; |
| 842 | bool success = m_domAgent->history()->perform(adoptPtr(new SetRuleSelectorAction(inspectorStyleSheet, compoundId, selector)), ec); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 843 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 844 | if (success) |
| 845 | result = inspectorStyleSheet->buildObjectForRule(inspectorStyleSheet->ruleForId(compoundId)); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 846 | *errorString = InspectorDOMAgent::toErrorString(ec); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 847 | } |
| 848 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 849 | void InspectorCSSAgent::addRule(ErrorString* errorString, const int contextNodeId, const String& selector, RefPtr<TypeBuilder::CSS::CSSRule>& result) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 850 | { |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 851 | Node* node = m_domAgent->assertNode(errorString, contextNodeId); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 852 | if (!node) |
| 853 | return; |
| 854 | |
| 855 | InspectorStyleSheet* inspectorStyleSheet = viaInspectorStyleSheet(node->document(), true); |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 856 | if (!inspectorStyleSheet) { |
| 857 | *errorString = "No target stylesheet found"; |
apavlov@chromium.org | d41cebd | 2011-01-20 15:46:28 +0000 | [diff] [blame] | 858 | return; |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 859 | } |
apavlov@chromium.org | 6dbb39d | 2010-11-10 17:12:45 +0000 | [diff] [blame] | 860 | |
pfeldman@chromium.org | 8ef5736 | 2012-02-13 13:12:15 +0000 | [diff] [blame] | 861 | ExceptionCode ec = 0; |
| 862 | OwnPtr<AddRuleAction> action = adoptPtr(new AddRuleAction(inspectorStyleSheet, selector)); |
| 863 | AddRuleAction* rawAction = action.get(); |
| 864 | bool success = m_domAgent->history()->perform(action.release(), ec); |
| 865 | if (!success) { |
| 866 | *errorString = InspectorDOMAgent::toErrorString(ec); |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | InspectorCSSId ruleId = rawAction->newRuleId(); |
| 871 | CSSStyleRule* rule = inspectorStyleSheet->ruleForId(ruleId); |
| 872 | result = inspectorStyleSheet->buildObjectForRule(rule); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 873 | } |
| 874 | |
pfeldman@chromium.org | a712894 | 2012-07-25 13:48:47 +0000 | [diff] [blame] | 875 | void InspectorCSSAgent::getSupportedCSSProperties(ErrorString*, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo> >& cssProperties) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 876 | { |
pfeldman@chromium.org | a712894 | 2012-07-25 13:48:47 +0000 | [diff] [blame] | 877 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo> > properties = TypeBuilder::Array<TypeBuilder::CSS::CSSPropertyInfo>::create(); |
| 878 | for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) { |
| 879 | CSSPropertyID id = convertToCSSPropertyID(i); |
| 880 | RefPtr<TypeBuilder::CSS::CSSPropertyInfo> property = TypeBuilder::CSS::CSSPropertyInfo::create() |
benjamin@webkit.org | 5ab707f | 2012-08-17 21:24:15 +0000 | [diff] [blame] | 881 | .setName(getPropertyNameString(id)); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 882 | |
pfeldman@chromium.org | a712894 | 2012-07-25 13:48:47 +0000 | [diff] [blame] | 883 | const StylePropertyShorthand& shorthand = shorthandForProperty(id); |
| 884 | if (!shorthand.length()) { |
| 885 | properties->addItem(property.release()); |
| 886 | continue; |
| 887 | } |
| 888 | RefPtr<TypeBuilder::Array<String> > longhands = TypeBuilder::Array<String>::create(); |
| 889 | for (unsigned j = 0; j < shorthand.length(); ++j) { |
| 890 | CSSPropertyID longhandID = shorthand.properties()[j]; |
benjamin@webkit.org | 5ab707f | 2012-08-17 21:24:15 +0000 | [diff] [blame] | 891 | longhands->addItem(getPropertyNameString(longhandID)); |
pfeldman@chromium.org | a712894 | 2012-07-25 13:48:47 +0000 | [diff] [blame] | 892 | } |
| 893 | property->setLonghands(longhands); |
| 894 | properties->addItem(property.release()); |
| 895 | } |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 896 | cssProperties = properties.release(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 897 | } |
| 898 | |
apavlov@chromium.org | d728ecd | 2012-08-13 09:06:15 +0000 | [diff] [blame] | 899 | void InspectorCSSAgent::forcePseudoState(ErrorString* errorString, int nodeId, const RefPtr<InspectorArray>& forcedPseudoClasses) |
| 900 | { |
| 901 | Element* element = m_domAgent->assertElement(errorString, nodeId); |
| 902 | if (!element) |
| 903 | return; |
| 904 | |
| 905 | unsigned forcedPseudoState = computePseudoClassMask(forcedPseudoClasses.get()); |
| 906 | NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.find(nodeId); |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 907 | unsigned currentForcedPseudoState = it == m_nodeIdToForcedPseudoState.end() ? 0 : it->value; |
apavlov@chromium.org | d728ecd | 2012-08-13 09:06:15 +0000 | [diff] [blame] | 908 | bool needStyleRecalc = forcedPseudoState != currentForcedPseudoState; |
| 909 | if (!needStyleRecalc) |
| 910 | return; |
| 911 | |
| 912 | if (forcedPseudoState) |
| 913 | m_nodeIdToForcedPseudoState.set(nodeId, forcedPseudoState); |
| 914 | else |
| 915 | m_nodeIdToForcedPseudoState.remove(nodeId); |
| 916 | element->ownerDocument()->styleResolverChanged(RecalcStyleImmediately); |
| 917 | } |
| 918 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 919 | void InspectorCSSAgent::getNamedFlowCollection(ErrorString* errorString, int documentNodeId, RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> >& result) |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 920 | { |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 921 | Document* document = m_domAgent->assertDocument(errorString, documentNodeId); |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 922 | if (!document) |
| 923 | return; |
| 924 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 925 | m_namedFlowCollectionsRequested.add(documentNodeId); |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 926 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 927 | Vector<RefPtr<WebKitNamedFlow> > namedFlowsVector = document->namedFlows()->namedFlows(); |
| 928 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::NamedFlow> > namedFlows = TypeBuilder::Array<TypeBuilder::CSS::NamedFlow>::create(); |
commit-queue@webkit.org | 5c25fc4 | 2012-08-06 16:39:56 +0000 | [diff] [blame] | 929 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 930 | for (Vector<RefPtr<WebKitNamedFlow> >::iterator it = namedFlowsVector.begin(); it != namedFlowsVector.end(); ++it) |
| 931 | namedFlows->addItem(buildObjectForNamedFlow(errorString, it->get(), documentNodeId)); |
commit-queue@webkit.org | 6f85951 | 2012-07-20 12:34:58 +0000 | [diff] [blame] | 932 | |
| 933 | result = namedFlows.release(); |
| 934 | } |
| 935 | |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 936 | void InspectorCSSAgent::startSelectorProfiler(ErrorString*) |
| 937 | { |
| 938 | m_currentSelectorProfile = adoptPtr(new SelectorProfile()); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 939 | m_state->setBoolean(CSSAgentState::isSelectorProfiling, true); |
| 940 | } |
| 941 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 942 | void InspectorCSSAgent::stopSelectorProfiler(ErrorString* errorString, RefPtr<TypeBuilder::CSS::SelectorProfile>& result) |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 943 | { |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 944 | result = stopSelectorProfilerImpl(errorString, true); |
loislo@chromium.org | f37187e | 2011-12-21 05:51:31 +0000 | [diff] [blame] | 945 | } |
| 946 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 947 | PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorProfilerImpl(ErrorString*, bool needProfile) |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 948 | { |
| 949 | if (!m_state->getBoolean(CSSAgentState::isSelectorProfiling)) |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 950 | return 0; |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 951 | m_state->setBoolean(CSSAgentState::isSelectorProfiling, false); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 952 | RefPtr<TypeBuilder::CSS::SelectorProfile> result; |
| 953 | if (m_frontend && needProfile) |
| 954 | result = m_currentSelectorProfile->toInspectorObject(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 955 | m_currentSelectorProfile.clear(); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 956 | return result.release(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | void InspectorCSSAgent::willMatchRule(const CSSStyleRule* rule) |
| 960 | { |
apavlov@chromium.org | 1ed8ba3 | 2012-01-19 16:39:55 +0000 | [diff] [blame] | 961 | if (m_currentSelectorProfile) |
| 962 | m_currentSelectorProfile->startSelector(rule); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | void InspectorCSSAgent::didMatchRule(bool matched) |
| 966 | { |
apavlov@chromium.org | 1ed8ba3 | 2012-01-19 16:39:55 +0000 | [diff] [blame] | 967 | if (m_currentSelectorProfile) |
| 968 | m_currentSelectorProfile->commitSelector(matched); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | void InspectorCSSAgent::willProcessRule(const CSSStyleRule* rule) |
| 972 | { |
apavlov@chromium.org | 1ed8ba3 | 2012-01-19 16:39:55 +0000 | [diff] [blame] | 973 | if (m_currentSelectorProfile) |
| 974 | m_currentSelectorProfile->startSelector(rule); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | void InspectorCSSAgent::didProcessRule() |
| 978 | { |
apavlov@chromium.org | 1ed8ba3 | 2012-01-19 16:39:55 +0000 | [diff] [blame] | 979 | if (m_currentSelectorProfile) |
| 980 | m_currentSelectorProfile->commitSelectorTime(); |
apavlov@chromium.org | ba905e8 | 2011-12-19 15:14:14 +0000 | [diff] [blame] | 981 | } |
| 982 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 983 | InspectorStyleSheetForInlineStyle* InspectorCSSAgent::asInspectorStyleSheet(Element* element) |
| 984 | { |
| 985 | NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(element); |
| 986 | if (it == m_nodeToInspectorStyleSheet.end()) { |
| 987 | CSSStyleDeclaration* style = element->isStyledElement() ? element->style() : 0; |
| 988 | if (!style) |
| 989 | return 0; |
| 990 | |
| 991 | String newStyleSheetId = String::number(m_lastStyleSheetId++); |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 992 | RefPtr<InspectorStyleSheetForInlineStyle> inspectorStyleSheet = InspectorStyleSheetForInlineStyle::create(m_domAgent->pageAgent(), newStyleSheetId, element, TypeBuilder::CSS::StyleSheetOrigin::Regular, this); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 993 | m_idToInspectorStyleSheet.set(newStyleSheetId, inspectorStyleSheet); |
| 994 | m_nodeToInspectorStyleSheet.set(element, inspectorStyleSheet); |
| 995 | return inspectorStyleSheet.get(); |
| 996 | } |
| 997 | |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 998 | return it->value.get(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
pfeldman@chromium.org | 7e420b5 | 2011-03-21 07:54:32 +0000 | [diff] [blame] | 1001 | Element* InspectorCSSAgent::elementForId(ErrorString* errorString, int nodeId) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1002 | { |
| 1003 | Node* node = m_domAgent->nodeForId(nodeId); |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 1004 | if (!node) { |
caseq@chromium.org | c248569 | 2011-03-31 15:21:33 +0000 | [diff] [blame] | 1005 | *errorString = "No node with given id found"; |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 1006 | return 0; |
| 1007 | } |
| 1008 | if (node->nodeType() != Node::ELEMENT_NODE) { |
caseq@chromium.org | c248569 | 2011-03-31 15:21:33 +0000 | [diff] [blame] | 1009 | *errorString = "Not an element node"; |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 1010 | return 0; |
| 1011 | } |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1012 | return toElement(node); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
commit-queue@webkit.org | 65563d4 | 2012-09-12 12:07:24 +0000 | [diff] [blame] | 1015 | int InspectorCSSAgent::documentNodeWithRequestedFlowsId(Document* document) |
| 1016 | { |
| 1017 | int documentNodeId = m_domAgent->boundNodeId(document); |
| 1018 | if (!documentNodeId || !m_namedFlowCollectionsRequested.contains(documentNodeId)) |
| 1019 | return 0; |
| 1020 | |
| 1021 | return documentNodeId; |
| 1022 | } |
| 1023 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 1024 | void InspectorCSSAgent::collectStyleSheets(CSSStyleSheet* styleSheet, TypeBuilder::Array<TypeBuilder::CSS::CSSStyleSheetHeader>* result) |
apavlov@chromium.org | be789cf | 2011-05-18 13:32:07 +0000 | [diff] [blame] | 1025 | { |
| 1026 | InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(static_cast<CSSStyleSheet*>(styleSheet)); |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 1027 | result->addItem(inspectorStyleSheet->buildObjectForStyleSheetInfo()); |
apavlov@chromium.org | be789cf | 2011-05-18 13:32:07 +0000 | [diff] [blame] | 1028 | for (unsigned i = 0, size = styleSheet->length(); i < size; ++i) { |
andreas.kling@nokia.com | 1678e2b | 2011-10-14 18:36:31 +0000 | [diff] [blame] | 1029 | CSSRule* rule = styleSheet->item(i); |
akling@apple.com | c713db3 | 2012-11-22 03:45:40 +0000 | [diff] [blame^] | 1030 | if (rule->type() == CSSRule::IMPORT_RULE) { |
andreas.kling@nokia.com | 1678e2b | 2011-10-14 18:36:31 +0000 | [diff] [blame] | 1031 | CSSStyleSheet* importedStyleSheet = static_cast<CSSImportRule*>(rule)->styleSheet(); |
| 1032 | if (importedStyleSheet) |
| 1033 | collectStyleSheets(importedStyleSheet, result); |
apavlov@chromium.org | be789cf | 2011-05-18 13:32:07 +0000 | [diff] [blame] | 1034 | } |
| 1035 | } |
| 1036 | } |
| 1037 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1038 | InspectorStyleSheet* InspectorCSSAgent::bindStyleSheet(CSSStyleSheet* styleSheet) |
| 1039 | { |
| 1040 | RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspectorStyleSheet.get(styleSheet); |
| 1041 | if (!inspectorStyleSheet) { |
| 1042 | String id = String::number(m_lastStyleSheetId++); |
antti@apple.com | fe126eb | 2012-04-25 22:42:47 +0000 | [diff] [blame] | 1043 | Document* document = styleSheet->ownerDocument(); |
pfeldman@chromium.org | f9adb6a | 2012-05-24 14:35:50 +0000 | [diff] [blame] | 1044 | inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), id, styleSheet, detectOrigin(styleSheet, document), InspectorDOMAgent::documentURLString(document), this); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1045 | m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); |
| 1046 | m_cssStyleSheetToInspectorStyleSheet.set(styleSheet, inspectorStyleSheet); |
| 1047 | } |
| 1048 | return inspectorStyleSheet.get(); |
| 1049 | } |
| 1050 | |
| 1051 | InspectorStyleSheet* InspectorCSSAgent::viaInspectorStyleSheet(Document* document, bool createIfAbsent) |
| 1052 | { |
| 1053 | if (!document) { |
| 1054 | ASSERT(!createIfAbsent); |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_documentToInspectorStyleSheet.get(document); |
| 1059 | if (inspectorStyleSheet || !createIfAbsent) |
| 1060 | return inspectorStyleSheet.get(); |
| 1061 | |
| 1062 | ExceptionCode ec = 0; |
| 1063 | RefPtr<Element> styleElement = document->createElement("style", ec); |
| 1064 | if (!ec) |
| 1065 | styleElement->setAttribute("type", "text/css", ec); |
apavlov@chromium.org | d41cebd | 2011-01-20 15:46:28 +0000 | [diff] [blame] | 1066 | if (!ec) { |
| 1067 | ContainerNode* targetNode; |
| 1068 | // HEAD is absent in ImageDocuments, for example. |
| 1069 | if (document->head()) |
| 1070 | targetNode = document->head(); |
| 1071 | else if (document->body()) |
| 1072 | targetNode = document->body(); |
| 1073 | else |
| 1074 | return 0; |
apavlov@chromium.org | 31442e8 | 2012-03-05 10:44:40 +0000 | [diff] [blame] | 1075 | |
| 1076 | InlineStyleOverrideScope overrideScope(document); |
apavlov@chromium.org | d41cebd | 2011-01-20 15:46:28 +0000 | [diff] [blame] | 1077 | targetNode->appendChild(styleElement, ec); |
| 1078 | } |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1079 | if (ec) |
| 1080 | return 0; |
| 1081 | StyleSheetList* styleSheets = document->styleSheets(); |
| 1082 | StyleSheet* styleSheet = styleSheets->item(styleSheets->length() - 1); |
apavlov@chromium.org | 31442e8 | 2012-03-05 10:44:40 +0000 | [diff] [blame] | 1083 | if (!styleSheet || !styleSheet->isCSSStyleSheet()) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1084 | return 0; |
| 1085 | CSSStyleSheet* cssStyleSheet = static_cast<CSSStyleSheet*>(styleSheet); |
| 1086 | String id = String::number(m_lastStyleSheetId++); |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1087 | inspectorStyleSheet = InspectorStyleSheet::create(m_domAgent->pageAgent(), id, cssStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Inspector, InspectorDOMAgent::documentURLString(document), this); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1088 | m_idToInspectorStyleSheet.set(id, inspectorStyleSheet); |
| 1089 | m_cssStyleSheetToInspectorStyleSheet.set(cssStyleSheet, inspectorStyleSheet); |
| 1090 | m_documentToInspectorStyleSheet.set(document, inspectorStyleSheet); |
| 1091 | return inspectorStyleSheet.get(); |
| 1092 | } |
| 1093 | |
pfeldman@chromium.org | 8f286ef | 2011-04-15 12:39:32 +0000 | [diff] [blame] | 1094 | InspectorStyleSheet* InspectorCSSAgent::assertStyleSheetForId(ErrorString* errorString, const String& styleSheetId) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1095 | { |
| 1096 | IdToInspectorStyleSheet::iterator it = m_idToInspectorStyleSheet.find(styleSheetId); |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 1097 | if (it == m_idToInspectorStyleSheet.end()) { |
caseq@chromium.org | c248569 | 2011-03-31 15:21:33 +0000 | [diff] [blame] | 1098 | *errorString = "No style sheet with given id found"; |
pfeldman@chromium.org | e573fa3 | 2011-03-17 18:10:15 +0000 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1101 | return it->value.get(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1104 | TypeBuilder::CSS::StyleSheetOrigin::Enum InspectorCSSAgent::detectOrigin(CSSStyleSheet* pageStyleSheet, Document* ownerDocument) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1105 | { |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1106 | TypeBuilder::CSS::StyleSheetOrigin::Enum origin = TypeBuilder::CSS::StyleSheetOrigin::Regular; |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1107 | if (pageStyleSheet && !pageStyleSheet->ownerNode() && pageStyleSheet->href().isEmpty()) |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1108 | origin = TypeBuilder::CSS::StyleSheetOrigin::User_agent; |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1109 | else if (pageStyleSheet && pageStyleSheet->ownerNode() && pageStyleSheet->ownerNode()->nodeName() == "#document") |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1110 | origin = TypeBuilder::CSS::StyleSheetOrigin::User; |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1111 | else { |
| 1112 | InspectorStyleSheet* viaInspectorStyleSheetForOwner = viaInspectorStyleSheet(ownerDocument, false); |
| 1113 | if (viaInspectorStyleSheetForOwner && pageStyleSheet == viaInspectorStyleSheetForOwner->pageStyleSheet()) |
apavlov@chromium.org | 0c1c373 | 2012-05-25 16:24:48 +0000 | [diff] [blame] | 1114 | origin = TypeBuilder::CSS::StyleSheetOrigin::Inspector; |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1115 | } |
| 1116 | return origin; |
| 1117 | } |
| 1118 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 1119 | PassRefPtr<TypeBuilder::CSS::CSSRule> InspectorCSSAgent::buildObjectForRule(CSSStyleRule* rule, StyleResolver* styleResolver) |
| 1120 | { |
| 1121 | if (!rule) |
| 1122 | return 0; |
| 1123 | |
| 1124 | // CSSRules returned by StyleResolver::styleRulesForElement lack parent pointers since that infomation is not cheaply available. |
| 1125 | // Since the inspector wants to walk the parent chain, we construct the full wrappers here. |
| 1126 | // FIXME: This could be factored better. StyleResolver::styleRulesForElement should return a StyleRule vector, not a CSSRuleList. |
| 1127 | if (!rule->parentStyleSheet()) { |
| 1128 | rule = styleResolver->ensureFullCSSOMWrapperForInspector(rule->styleRule()); |
| 1129 | if (!rule) |
| 1130 | return 0; |
| 1131 | } |
| 1132 | InspectorStyleSheet* inspectorStyleSheet = bindStyleSheet(rule->parentStyleSheet()); |
| 1133 | return inspectorStyleSheet ? inspectorStyleSheet->buildObjectForRule(rule) : 0; |
| 1134 | } |
| 1135 | |
alexis.menard@openbossa.org | 31b77cb | 2012-04-24 23:51:22 +0000 | [diff] [blame] | 1136 | PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > InspectorCSSAgent::buildArrayForRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1137 | { |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 1138 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSRule> > result = TypeBuilder::Array<TypeBuilder::CSS::CSSRule>::create(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1139 | if (!ruleList) |
| 1140 | return result.release(); |
| 1141 | |
| 1142 | for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
| 1143 | CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 1144 | RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule, styleResolver); |
| 1145 | if (!ruleObject) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1146 | continue; |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 1147 | result->addItem(ruleObject); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1148 | } |
| 1149 | return result.release(); |
| 1150 | } |
| 1151 | |
apavlov@chromium.org | cecb43f | 2012-09-25 08:05:18 +0000 | [diff] [blame] | 1152 | PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > InspectorCSSAgent::buildArrayForMatchedRuleList(CSSRuleList* ruleList, StyleResolver* styleResolver, Element* element) |
| 1153 | { |
| 1154 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::RuleMatch> > result = TypeBuilder::Array<TypeBuilder::CSS::RuleMatch>::create(); |
| 1155 | if (!ruleList) |
| 1156 | return result.release(); |
| 1157 | |
| 1158 | for (unsigned i = 0, size = ruleList->length(); i < size; ++i) { |
| 1159 | CSSStyleRule* rule = asCSSStyleRule(ruleList->item(i)); |
| 1160 | RefPtr<TypeBuilder::CSS::CSSRule> ruleObject = buildObjectForRule(rule, styleResolver); |
| 1161 | if (!ruleObject) |
| 1162 | continue; |
| 1163 | RefPtr<TypeBuilder::Array<int> > matchingSelectors = TypeBuilder::Array<int>::create(); |
| 1164 | const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); |
| 1165 | long index = 0; |
| 1166 | for (CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector)) { |
| 1167 | ExceptionCode ec; |
| 1168 | bool matched = element->webkitMatchesSelector(selector->selectorText(), ec); |
| 1169 | if (matched) |
| 1170 | matchingSelectors->addItem(index); |
| 1171 | ++index; |
| 1172 | } |
| 1173 | RefPtr<TypeBuilder::CSS::RuleMatch> match = TypeBuilder::CSS::RuleMatch::create() |
| 1174 | .setRule(ruleObject) |
| 1175 | .setMatchingSelectors(matchingSelectors); |
| 1176 | result->addItem(match); |
| 1177 | } |
| 1178 | |
| 1179 | return result; |
| 1180 | } |
| 1181 | |
apavlov@chromium.org | 47bfc33 | 2012-03-26 14:04:50 +0000 | [diff] [blame] | 1182 | PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorCSSAgent::buildObjectForAttributesStyle(Element* element) |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1183 | { |
kling@webkit.org | 119bc4e | 2012-02-04 12:24:19 +0000 | [diff] [blame] | 1184 | if (!element->isStyledElement()) |
apavlov@chromium.org | 0d4c01a | 2012-02-09 12:41:37 +0000 | [diff] [blame] | 1185 | return 0; |
kling@webkit.org | 119bc4e | 2012-02-04 12:24:19 +0000 | [diff] [blame] | 1186 | |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 1187 | const StylePropertySet* attributeStyle = static_cast<StyledElement*>(element)->presentationAttributeStyle(); |
commit-queue@webkit.org | 844de9e | 2012-11-05 10:47:35 +0000 | [diff] [blame] | 1188 | if (!attributeStyle) |
apavlov@chromium.org | 0d4c01a | 2012-02-09 12:41:37 +0000 | [diff] [blame] | 1189 | return 0; |
kling@webkit.org | 119bc4e | 2012-02-04 12:24:19 +0000 | [diff] [blame] | 1190 | |
commit-queue@webkit.org | 844de9e | 2012-11-05 10:47:35 +0000 | [diff] [blame] | 1191 | RefPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(InspectorCSSId(), const_cast<StylePropertySet*>(attributeStyle)->ensureCSSStyleDeclaration(), 0); |
apavlov@chromium.org | 0d4c01a | 2012-02-09 12:41:37 +0000 | [diff] [blame] | 1192 | return inspectorStyle->buildObjectForStyle(); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
commit-queue@webkit.org | e2bb32c | 2012-08-10 09:58:35 +0000 | [diff] [blame] | 1195 | PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::Region> > InspectorCSSAgent::buildArrayForRegions(ErrorString* errorString, PassRefPtr<NodeList> regionList, int documentNodeId) |
| 1196 | { |
| 1197 | RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Region> > regions = TypeBuilder::Array<TypeBuilder::CSS::Region>::create(); |
| 1198 | |
| 1199 | for (unsigned i = 0; i < regionList->length(); ++i) { |
| 1200 | TypeBuilder::CSS::Region::RegionOverset::Enum regionOverset; |
| 1201 | |
| 1202 | switch (toElement(regionList->item(i))->renderRegion()->regionState()) { |
| 1203 | case RenderRegion::RegionFit: |
| 1204 | regionOverset = TypeBuilder::CSS::Region::RegionOverset::Fit; |
| 1205 | break; |
| 1206 | case RenderRegion::RegionEmpty: |
| 1207 | regionOverset = TypeBuilder::CSS::Region::RegionOverset::Empty; |
| 1208 | break; |
| 1209 | case RenderRegion::RegionOverset: |
| 1210 | regionOverset = TypeBuilder::CSS::Region::RegionOverset::Overset; |
| 1211 | break; |
| 1212 | case RenderRegion::RegionUndefined: |
| 1213 | continue; |
| 1214 | default: |
| 1215 | ASSERT_NOT_REACHED(); |
| 1216 | continue; |
| 1217 | } |
| 1218 | |
| 1219 | RefPtr<TypeBuilder::CSS::Region> region = TypeBuilder::CSS::Region::create() |
| 1220 | .setRegionOverset(regionOverset) |
| 1221 | // documentNodeId was previously asserted |
| 1222 | .setNodeId(m_domAgent->pushNodeToFrontend(errorString, documentNodeId, regionList->item(i))); |
| 1223 | |
| 1224 | regions->addItem(region); |
| 1225 | } |
| 1226 | |
| 1227 | return regions.release(); |
| 1228 | } |
| 1229 | |
| 1230 | PassRefPtr<TypeBuilder::CSS::NamedFlow> InspectorCSSAgent::buildObjectForNamedFlow(ErrorString* errorString, WebKitNamedFlow* webkitNamedFlow, int documentNodeId) |
| 1231 | { |
| 1232 | RefPtr<NodeList> contentList = webkitNamedFlow->getContent(); |
| 1233 | RefPtr<TypeBuilder::Array<int> > content = TypeBuilder::Array<int>::create(); |
| 1234 | |
| 1235 | for (unsigned i = 0; i < contentList->length(); ++i) { |
| 1236 | // documentNodeId was previously asserted |
| 1237 | content->addItem(m_domAgent->pushNodeToFrontend(errorString, documentNodeId, contentList->item(i))); |
| 1238 | } |
| 1239 | |
| 1240 | RefPtr<TypeBuilder::CSS::NamedFlow> namedFlow = TypeBuilder::CSS::NamedFlow::create() |
| 1241 | .setDocumentNodeId(documentNodeId) |
| 1242 | .setName(webkitNamedFlow->name().string()) |
| 1243 | .setOverset(webkitNamedFlow->overset()) |
| 1244 | .setContent(content) |
| 1245 | .setRegions(buildArrayForRegions(errorString, webkitNamedFlow->getRegions(), documentNodeId)); |
| 1246 | |
| 1247 | return namedFlow.release(); |
| 1248 | } |
| 1249 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1250 | void InspectorCSSAgent::didRemoveDocument(Document* document) |
| 1251 | { |
apavlov@chromium.org | 6dbb39d | 2010-11-10 17:12:45 +0000 | [diff] [blame] | 1252 | if (document) |
| 1253 | m_documentToInspectorStyleSheet.remove(document); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | void InspectorCSSAgent::didRemoveDOMNode(Node* node) |
| 1257 | { |
apavlov@chromium.org | 6dbb39d | 2010-11-10 17:12:45 +0000 | [diff] [blame] | 1258 | if (!node) |
| 1259 | return; |
| 1260 | |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1261 | int nodeId = m_domAgent->boundNodeId(node); |
| 1262 | if (nodeId) |
| 1263 | m_nodeIdToForcedPseudoState.remove(nodeId); |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 1264 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1265 | NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(node); |
| 1266 | if (it == m_nodeToInspectorStyleSheet.end()) |
| 1267 | return; |
| 1268 | |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1269 | m_idToInspectorStyleSheet.remove(it->value->id()); |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1270 | m_nodeToInspectorStyleSheet.remove(node); |
| 1271 | } |
| 1272 | |
apavlov@chromium.org | 93e800a | 2010-12-24 16:39:32 +0000 | [diff] [blame] | 1273 | void InspectorCSSAgent::didModifyDOMAttr(Element* element) |
| 1274 | { |
| 1275 | if (!element) |
| 1276 | return; |
| 1277 | |
| 1278 | NodeToInspectorStyleSheet::iterator it = m_nodeToInspectorStyleSheet.find(element); |
| 1279 | if (it == m_nodeToInspectorStyleSheet.end()) |
| 1280 | return; |
| 1281 | |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1282 | it->value->didModifyElementAttribute(); |
apavlov@chromium.org | 93e800a | 2010-12-24 16:39:32 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
pfeldman@chromium.org | a1a70a4 | 2012-02-14 08:50:19 +0000 | [diff] [blame] | 1285 | void InspectorCSSAgent::styleSheetChanged(InspectorStyleSheet* styleSheet) |
| 1286 | { |
| 1287 | if (m_frontend) |
| 1288 | m_frontend->styleSheetChanged(styleSheet->id()); |
| 1289 | } |
| 1290 | |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1291 | void InspectorCSSAgent::resetPseudoStates() |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 1292 | { |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1293 | HashSet<Document*> documentsToChange; |
| 1294 | for (NodeIdToForcedPseudoState::iterator it = m_nodeIdToForcedPseudoState.begin(), end = m_nodeIdToForcedPseudoState.end(); it != end; ++it) { |
benjamin@webkit.org | ee55405 | 2012-10-07 23:12:07 +0000 | [diff] [blame] | 1295 | Element* element = toElement(m_domAgent->nodeForId(it->key)); |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1296 | if (element && element->ownerDocument()) |
| 1297 | documentsToChange.add(element->ownerDocument()); |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 1298 | } |
apavlov@chromium.org | cc4fd4a | 2012-07-04 16:10:45 +0000 | [diff] [blame] | 1299 | |
| 1300 | m_nodeIdToForcedPseudoState.clear(); |
| 1301 | for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = documentsToChange.end(); it != end; ++it) |
| 1302 | (*it)->styleResolverChanged(RecalcStyleImmediately); |
pfeldman@chromium.org | efb4386 | 2011-08-16 17:15:06 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
apavlov@chromium.org | 8d79d7f | 2010-10-07 09:53:40 +0000 | [diff] [blame] | 1305 | } // namespace WebCore |
| 1306 | |
| 1307 | #endif // ENABLE(INSPECTOR) |