Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: Source/core/inspector/LayoutEditor.cpp

Issue 1310923003: Devtools [LayoutEditor]: Patch values in the selected rule (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@medias
Patch Set: Address comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 appendAnchorFor(anchors.get(), "margin", "margin-right", marginHandles.p2(), orthogonals.p2()); 258 appendAnchorFor(anchors.get(), "margin", "margin-right", marginHandles.p2(), orthogonals.p2());
259 appendAnchorFor(anchors.get(), "margin", "margin-bottom", marginHandles.p3() , orthogonals.p3()); 259 appendAnchorFor(anchors.get(), "margin", "margin-bottom", marginHandles.p3() , orthogonals.p3());
260 appendAnchorFor(anchors.get(), "margin", "margin-left", marginHandles.p4(), orthogonals.p4()); 260 appendAnchorFor(anchors.get(), "margin", "margin-left", marginHandles.p4(), orthogonals.p4());
261 261
262 object->setArray("anchors", anchors.release()); 262 object->setArray("anchors", anchors.release());
263 return object.release(); 263 return object.release();
264 } 264 }
265 265
266 RefPtrWillBeRawPtr<CSSPrimitiveValue> LayoutEditor::getPropertyCSSValue(CSSPrope rtyID property) const 266 RefPtrWillBeRawPtr<CSSPrimitiveValue> LayoutEditor::getPropertyCSSValue(CSSPrope rtyID property) const
267 { 267 {
268 RefPtrWillBeRawPtr<CSSStyleDeclaration> style = m_cssAgent->findEffectiveDec laration(m_element.get(), property); 268 RefPtrWillBeRawPtr<CSSRuleList> ruleList = m_cssAgent->matchedRulesList(m_el ement.get());
269 RefPtrWillBeRawPtr<CSSStyleDeclaration> style = m_cssAgent->findEffectiveDec laration(property, ruleList.get(), m_element->style());
269 if (!style) 270 if (!style)
270 return nullptr; 271 return nullptr;
271 272
272 RefPtrWillBeRawPtr<CSSValue> cssValue = style->getPropertyCSSValueInternal(p roperty); 273 RefPtrWillBeRawPtr<CSSValue> cssValue = style->getPropertyCSSValueInternal(p roperty);
273 if (!cssValue || !cssValue->isPrimitiveValue()) 274 if (!cssValue || !cssValue->isPrimitiveValue())
274 return nullptr; 275 return nullptr;
275 276
276 return toCSSPrimitiveValue(cssValue.get()); 277 return toCSSPrimitiveValue(cssValue.get());
277 } 278 }
278 279
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 default: 326 default:
326 ASSERT_NOT_REACHED(); 327 ASSERT_NOT_REACHED();
327 break; 328 break;
328 } 329 }
329 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0; 330 m_propertyInitialValue = cssValue ? cssValue->getFloatValue() : 0;
330 } 331 }
331 332
332 void LayoutEditor::overlayPropertyChanged(float cssDelta) 333 void LayoutEditor::overlayPropertyChanged(float cssDelta)
333 { 334 {
334 if (m_changingProperty && m_factor) { 335 if (m_changingProperty && m_factor) {
335 String errorString;
336 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue); 336 float newValue = toValidValue(m_changingProperty, cssDelta / m_factor + m_propertyInitialValue);
337 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), m_changin gProperty, truncateZeroes(String::format("%.2f", newValue)) + CSSPrimitiveValue: :unitTypeToString(m_valueUnitType)); 337 m_isDirty |= setCSSPropertyValueInCurrentRule(truncateZeroes(String::for mat("%.2f", newValue)) + CSSPrimitiveValue::unitTypeToString(m_valueUnitType));
338 if (!errorString)
339 m_isDirty = true;
340 } 338 }
341 } 339 }
342 340
343 void LayoutEditor::overlayEndedPropertyChange() 341 void LayoutEditor::overlayEndedPropertyChange()
344 { 342 {
345 m_changingProperty = CSSPropertyInvalid; 343 m_changingProperty = CSSPropertyInvalid;
346 m_propertyInitialValue = 0; 344 m_propertyInitialValue = 0;
347 m_factor = 0; 345 m_factor = 0;
348 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown; 346 m_valueUnitType = CSSPrimitiveValue::UnitType::Unknown;
349 } 347 }
(...skipping 11 matching lines...) Expand all
361 m_matchedRules.clear(); 359 m_matchedRules.clear();
362 m_cachedSelectorsInfo.clear(); 360 m_cachedSelectorsInfo.clear();
363 m_currentRuleIndex = -1; 361 m_currentRuleIndex = -1;
364 } 362 }
365 363
366 void LayoutEditor::initializeCSSRules() 364 void LayoutEditor::initializeCSSRules()
367 { 365 {
368 if (!m_element) 366 if (!m_element)
369 return; 367 return;
370 368
371 Document* ownerDocument = m_element->ownerDocument(); 369 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = m_cssAgent->matchedRulesList( m_element.get());
372 // A non-active document has no styles.
373 if (!ownerDocument->isActive())
374 return;
375
376 // Matched rules.
377 StyleResolver& styleResolver = ownerDocument->ensureStyleResolver();
378 PseudoId elementPseudoId = m_element->pseudoId();
379 m_element->updateDistribution();
380 RefPtrWillBeRawPtr<CSSRuleList> matchedRules = styleResolver.pseudoCSSRulesF orElement(m_element.get(), elementPseudoId, StyleResolver::AllCSSRules);
381 if (!matchedRules) 370 if (!matchedRules)
382 return; 371 return;
383 372
384 HashSet<CSSStyleRule*> uniqRulesSet; 373 HashSet<CSSStyleRule*> uniqRulesSet;
385 Vector<CSSStyleRule*> uniqRules; 374 Vector<CSSStyleRule*> uniqRules;
386 for (unsigned i = matchedRules->length(); i > 0; --i) { 375 for (unsigned i = matchedRules->length(); i > 0; --i) {
387 CSSRule* rule = matchedRules->item(i); 376 CSSRule* rule = matchedRules->item(i);
388 if (!rule || rule->type() != CSSRule::STYLE_RULE || !rule->parentStyleSh eet()) 377 if (!rule || rule->type() != CSSRule::STYLE_RULE || !rule->parentStyleSh eet())
389 continue; 378 continue;
390 379
391 CSSStyleRule* styleRule = toCSSStyleRule(rule); 380 CSSStyleRule* styleRule = toCSSStyleRule(rule);
392 381
393 if (uniqRulesSet.contains(styleRule)) 382 if (uniqRulesSet.contains(styleRule))
394 continue; 383 continue;
395 uniqRulesSet.add(styleRule); 384 uniqRulesSet.add(styleRule);
396 uniqRules.append(styleRule); 385 uniqRules.append(styleRule);
397 } 386 }
398 Vector<std::pair<unsigned, CSSStyleRule*>> selectors; 387 Vector<std::pair<unsigned, CSSStyleRule*>> selectors;
399 for (unsigned i = 0; i < uniqRules.size(); ++i) { 388 for (unsigned i = 0; i < uniqRules.size(); ++i) {
400 TrackExceptionState exceptionState; 389 TrackExceptionState exceptionState;
401 RefPtrWillBeRawPtr<StaticElementList> elements = ownerDocument->querySel ectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState); 390 RefPtrWillBeRawPtr<StaticElementList> elements = m_element->ownerDocumen t()->querySelectorAll(AtomicString(uniqRules[i]->selectorText()), exceptionState );
402 unsigned length = exceptionState.hadException() ? 0: elements->length(); 391 unsigned length = exceptionState.hadException() ? 0: elements->length();
403 selectors.append(std::make_pair(length, uniqRules[i])); 392 selectors.append(std::make_pair(length, uniqRules[i]));
404 } 393 }
405 394
406 std::sort(selectors.begin(), selectors.end(), &comparePairs); 395 std::sort(selectors.begin(), selectors.end(), &comparePairs);
407 for (size_t i = 0; i < selectors.size(); ++i) 396 for (size_t i = 0; i < selectors.size(); ++i)
408 m_matchedRules.append(selectors[i].second); 397 m_matchedRules.append(selectors[i].second);
409 }; 398 };
410 399
411 void LayoutEditor::nextSelector() 400 void LayoutEditor::nextSelector()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 464
476 InspectorHighlight highlight(element, config, false); 465 InspectorHighlight highlight(element, config, false);
477 highlights->pushObject(highlight.asJSONObject()); 466 highlights->pushObject(highlight.asJSONObject());
478 } 467 }
479 468
480 object->setArray("nodes", highlights.release()); 469 object->setArray("nodes", highlights.release());
481 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString()); 470 m_cachedSelectorsInfo.add(m_currentRuleIndex, object->toJSONString());
482 return m_cachedSelectorsInfo.get(m_currentRuleIndex); 471 return m_cachedSelectorsInfo.get(m_currentRuleIndex);
483 } 472 }
484 473
474 bool LayoutEditor::setCSSPropertyValueInCurrentRule(const String& value)
475 {
476 if (!m_element)
477 return false;
478
479 CSSStyleRule* rule = m_currentRuleIndex == -1 ? nullptr : m_matchedRules[m_c urrentRuleIndex].get();
dgozman 2015/09/03 20:42:14 RefPtrWil....<CSSStyleRule>
sergeyv 2015/09/03 22:43:27 Done.
480 RefPtrWillBeRawPtr<CSSRuleList> ruleList = m_cssAgent->matchedRulesList(m_el ement.get());
481 RefPtrWillBeRawPtr<CSSStyleDeclaration> effectiveDeclaration = m_cssAgent->f indEffectiveDeclaration(m_changingProperty, ruleList.get(), m_element->style());
482
483 CSSStyleRule* effectiveRule = nullptr;
484 if (effectiveDeclaration && effectiveDeclaration->parentRule() && effectiveD eclaration->parentRule()->type() == CSSRule::STYLE_RULE)
485 effectiveRule = toCSSStyleRule(effectiveDeclaration->parentRule());
486
487 String longhand = getPropertyNameString(m_changingProperty);
488 bool forceImportant = effectiveDeclaration && effectiveDeclaration->getPrope rtyPriority(longhand) == "important";
489
490 if (effectiveDeclaration && rule) {
491 int effectiveRuleIndex = -1;
492 int ruleIndex = -1;
493 for (unsigned i = 0, size = ruleList ? ruleList->length() : 0; i < size; ++i) {
494 CSSRule* currentRule = ruleList->item(size - i - 1);
495 if (currentRule == effectiveRule)
496 effectiveRuleIndex = i;
497 if (currentRule == rule)
498 ruleIndex = i;
499 }
500 forceImportant |= effectiveRuleIndex < ruleIndex;
501 }
502 String errorString;
503 m_cssAgent->setCSSPropertyValue(&errorString, m_element.get(), rule ? rule-> style() : m_element->style(), m_changingProperty, value, forceImportant);
504 return errorString.isEmpty();
505 }
506
485 } // namespace blink 507 } // namespace blink
OLDNEW
« Source/core/inspector/InspectorCSSAgent.cpp ('K') | « Source/core/inspector/LayoutEditor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698