OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/inspector/LayoutEditor.h" | 6 #include "core/inspector/LayoutEditor.h" |
7 | 7 |
8 #include "core/css/CSSComputedStyleDeclaration.h" | 8 #include "core/css/CSSComputedStyleDeclaration.h" |
9 #include "core/css/CSSImportRule.h" | 9 #include "core/css/CSSImportRule.h" |
10 #include "core/css/CSSMediaRule.h" | 10 #include "core/css/CSSMediaRule.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 break; | 286 break; |
287 } | 287 } |
288 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; | 288 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; |
289 } | 289 } |
290 | 290 |
291 void LayoutEditor::overlayPropertyChanged(float cssDelta) | 291 void LayoutEditor::overlayPropertyChanged(float cssDelta) |
292 { | 292 { |
293 if (m_changingProperty && m_factor) { | 293 if (m_changingProperty && m_factor) { |
294 String errorString; | 294 String errorString; |
295 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); | 295 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); |
296 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType)); | 296 m_cssAgent->setCSSPropertyValueInRule(&errorString, m_element.get(), m_c urrentRuleIndex == -1 ? nullptr : m_matchedRules[m_currentRuleIndex].get(), m_ch angingProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveV alue::unitTypeToString(m_valueUnitType)); |
dgozman
2015/09/02 22:26:17
I don't like nullptr as an indicator of inline sty
sergeyv
2015/09/03 00:52:28
Done.
| |
297 if (!errorString) | 297 if (!errorString) |
298 m_isDirty = true; | 298 m_isDirty = true; |
299 } | 299 } |
300 } | 300 } |
301 | 301 |
302 void LayoutEditor::overlayEndedPropertyChange() | 302 void LayoutEditor::overlayEndedPropertyChange() |
303 { | 303 { |
304 m_changingProperty = CSSPropertyInvalid; | 304 m_changingProperty = CSSPropertyInvalid; |
305 m_propertyInitialValue = 0; | 305 m_propertyInitialValue = 0; |
306 m_factor = 0; | 306 m_factor = 0; |
(...skipping 13 matching lines...) Expand all Loading... | |
320 m_matchedRules.clear(); | 320 m_matchedRules.clear(); |
321 m_cachedSelectorsInfo.clear(); | 321 m_cachedSelectorsInfo.clear(); |
322 m_currentRuleIndex = -1; | 322 m_currentRuleIndex = -1; |
323 } | 323 } |
324 | 324 |
325 void LayoutEditor::initializeCSSRules() | 325 void LayoutEditor::initializeCSSRules() |
326 { | 326 { |
327 if (!m_element) | 327 if (!m_element) |
328 return; | 328 return; |
329 | 329 |
330 Document* ownerDocument = m_element->ownerDocument(); | 330 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = m_cssAgent->matchedRulesList( m_element.get()); |
331 // A non-active document has no styles. | |
332 if (!ownerDocument->isActive()) | |
333 return; | |
334 | |
335 // Matched rules. | |
336 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver(); | |
337 PseudoId elementPseudoId = m_element->pseudoId(); | |
338 m_element->updateDistribution(); | |
339 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(m_element.get(), elementPseudoId, StyleResolver::AllCSSRules); | |
340 if (!matchedRules) | 331 if (!matchedRules) |
341 return; | 332 return; |
342 | 333 |
343 HashSet<CSSStyleRule*> uniqRulesSet; | 334 HashSet<CSSStyleRule*> uniqRulesSet; |
344 Vector<CSSStyleRule*> uniqRules; | 335 Vector<CSSStyleRule*> uniqRules; |
345 for (unsigned i = matchedRules->length(); i > 0; --i) { | 336 for (unsigned i = matchedRules->length(); i > 0; --i) { |
346 CSSRule* rule = matchedRules->item(i); | 337 CSSRule* rule = matchedRules->item(i); |
347 if (!rule || rule->type() != CSSRule::STYLE_RULE || !rule->parentStyleSh eet()) | 338 if (!rule || rule->type() != CSSRule::STYLE_RULE || !rule->parentStyleSh eet()) |
348 continue; | 339 continue; |
349 | 340 |
350 CSSStyleRule* styleRule = toCSSStyleRule(rule); | 341 CSSStyleRule* styleRule = toCSSStyleRule(rule); |
351 | 342 |
352 if (uniqRulesSet.contains(styleRule)) | 343 if (uniqRulesSet.contains(styleRule)) |
353 continue; | 344 continue; |
354 uniqRulesSet.add(styleRule); | 345 uniqRulesSet.add(styleRule); |
355 uniqRules.append(styleRule); | 346 uniqRules.append(styleRule); |
356 } | 347 } |
357 Vector<std::pair<unsigned, CSSStyleRule*>> selectors; | 348 Vector<std::pair<unsigned, CSSStyleRule*>> selectors; |
358 for (unsigned i = 0; i < uniqRules.size(); ++i) { | 349 for (unsigned i = 0; i < uniqRules.size(); ++i) { |
359 TrackExceptionState exceptionState; | 350 TrackExceptionState exceptionState; |
360 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySel ectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState); | 351 RefPtrWillBeRawPtr<StaticElementList> elements = m_element->ownerDocumen t()->querySelectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState ); |
361 unsigned length = exceptionState.hadException() ? 0: elements->length(); | 352 unsigned length = exceptionState.hadException() ? 0: elements->length(); |
362 selectors.append(std::make_pair(length, uniqRules[i])); | 353 selectors.append(std::make_pair(length, uniqRules[i])); |
363 } | 354 } |
364 | 355 |
365 std::sort(selectors.begin(), selectors.end(), &comparePairs); | 356 std::sort(selectors.begin(), selectors.end(), &comparePairs); |
366 for (size_t i = 0; i < selectors.size(); ++i) | 357 for (size_t i = 0; i < selectors.size(); ++i) |
367 m_matchedRules.append(selectors[i].second); | 358 m_matchedRules.append(selectors[i].second); |
368 }; | 359 }; |
369 | 360 |
370 void LayoutEditor::nextSelector() | 361 void LayoutEditor::nextSelector() |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 if (parentRule) | 465 if (parentRule) |
475 break; | 466 break; |
476 styleSheet = styleSheet->parentStyleSheet(); | 467 styleSheet = styleSheet->parentStyleSheet(); |
477 } | 468 } |
478 } | 469 } |
479 } | 470 } |
480 return result.release(); | 471 return result.release(); |
481 } | 472 } |
482 | 473 |
483 } // namespace blink | 474 } // namespace blink |
OLD | NEW |