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

Side by Side Diff: Source/core/css/CSSComputedStyleDeclaration.cpp

Issue 1164573002: CSSValue Immediates: Change CSSValue to an object instead of a pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Some small fixes to (hopefully) fix some broken tests Created 5 years, 6 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 /* 1 /*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org> 2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 4 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2011 Sencha, Inc. All rights reserved. 6 * Copyright (C) 2011 Sencha, Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 ASSERT_ARG(keywordSize, keywordSize); 397 ASSERT_ARG(keywordSize, keywordSize);
398 ASSERT_ARG(keywordSize, keywordSize <= 8); 398 ASSERT_ARG(keywordSize, keywordSize <= 8);
399 return static_cast<CSSValueID>(CSSValueXxSmall + keywordSize - 1); 399 return static_cast<CSSValueID>(CSSValueXxSmall + keywordSize - 1);
400 } 400 }
401 401
402 inline static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> zoomAdjustedPixelValue(d ouble value, const ComputedStyle& style) 402 inline static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> zoomAdjustedPixelValue(d ouble value, const ComputedStyle& style)
403 { 403 {
404 return cssValuePool().createValue(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::CSS_PX); 404 return cssValuePool().createValue(adjustFloatForAbsoluteZoom(value, style), CSSPrimitiveValue::CSS_PX);
405 } 405 }
406 406
407 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getFontSizeCSSValu ePreferringKeyword() const 407 NullableCSSValue CSSComputedStyleDeclaration::getFontSizeCSSValuePreferringKeywo rd() const
408 { 408 {
409 if (!m_node) 409 if (!m_node)
410 return nullptr; 410 return nullptr;
411 411
412 m_node->document().updateLayoutIgnorePendingStylesheets(); 412 m_node->document().updateLayoutIgnorePendingStylesheets();
413 413
414 const ComputedStyle* style = m_node->ensureComputedStyle(m_pseudoElementSpec ifier); 414 const ComputedStyle* style = m_node->ensureComputedStyle(m_pseudoElementSpec ifier);
415 if (!style) 415 if (!style)
416 return nullptr; 416 return nullptr;
417 417
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 { 514 {
515 if (!m_node) 515 if (!m_node)
516 return 0; 516 return 0;
517 if (m_node->isElementNode()) { 517 if (m_node->isElementNode()) {
518 if (PseudoElement* element = toElement(m_node)->pseudoElement(m_pseudoEl ementSpecifier)) 518 if (PseudoElement* element = toElement(m_node)->pseudoElement(m_pseudoEl ementSpecifier))
519 return element; 519 return element;
520 } 520 }
521 return m_node.get(); 521 return m_node.get();
522 } 522 }
523 523
524 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu e(CSSPropertyID propertyID) const 524 NullableCSSValue CSSComputedStyleDeclaration::getPropertyCSSValue(CSSPropertyID propertyID) const
525 { 525 {
526 Node* styledNode = this->styledNode(); 526 Node* styledNode = this->styledNode();
527 if (!styledNode) 527 if (!styledNode)
528 return nullptr; 528 return nullptr;
529 LayoutObject* layoutObject = styledNode->layoutObject(); 529 LayoutObject* layoutObject = styledNode->layoutObject();
530 const ComputedStyle* style; 530 const ComputedStyle* style;
531 531
532 Document& document = styledNode->document(); 532 Document& document = styledNode->document();
533 533
534 // A timing update may be required if a compositor animation is running. 534 // A timing update may be required if a compositor animation is running.
(...skipping 15 matching lines...) Expand all
550 if (forceFullLayout) { 550 if (forceFullLayout) {
551 document.updateLayoutIgnorePendingStylesheets(); 551 document.updateLayoutIgnorePendingStylesheets();
552 styledNode = this->styledNode(); 552 styledNode = this->styledNode();
553 style = computeComputedStyle(); 553 style = computeComputedStyle();
554 layoutObject = styledNode->layoutObject(); 554 layoutObject = styledNode->layoutObject();
555 } 555 }
556 556
557 if (!style) 557 if (!style)
558 return nullptr; 558 return nullptr;
559 559
560 RefPtrWillBeRawPtr<CSSValue> value = ComputedStyleCSSValueMapping::get(prope rtyID, *style, layoutObject, styledNode, m_allowVisitedStyle); 560 NullableCSSValue value = ComputedStyleCSSValueMapping::get(propertyID, *styl e, layoutObject, styledNode, m_allowVisitedStyle);
561 if (value) 561 if (value)
562 return value; 562 return *value;
563 563
564 logUnimplementedPropertyID(propertyID); 564 logUnimplementedPropertyID(propertyID);
565 return nullptr; 565 return nullptr;
566 } 566 }
567 567
568 String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) c onst 568 String CSSComputedStyleDeclaration::getPropertyValue(CSSPropertyID propertyID) c onst
569 { 569 {
570 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 570 NullableCSSValue value = getPropertyCSSValue(propertyID);
571 if (value) 571 if (value)
572 return value->cssText(); 572 return value->cssText();
573 return ""; 573 return "";
574 } 574 }
575 575
576 576
577 unsigned CSSComputedStyleDeclaration::length() const 577 unsigned CSSComputedStyleDeclaration::length() const
578 { 578 {
579 if (!m_node || !m_node->inActiveDocument()) 579 if (!m_node || !m_node->inActiveDocument())
580 return 0; 580 return 0;
581 return computableProperties().size(); 581 return computableProperties().size();
582 } 582 }
583 583
584 String CSSComputedStyleDeclaration::item(unsigned i) const 584 String CSSComputedStyleDeclaration::item(unsigned i) const
585 { 585 {
586 if (i >= length()) 586 if (i >= length())
587 return ""; 587 return "";
588 588
589 return getPropertyNameString(computableProperties()[i]); 589 return getPropertyNameString(computableProperties()[i]);
590 } 590 }
591 591
592 bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c onst CSSValue* propertyValue) const 592 bool CSSComputedStyleDeclaration::cssPropertyMatches(CSSPropertyID propertyID, c onst CSSValue propertyValue) const
593 { 593 {
594 if (propertyID == CSSPropertyFontSize && propertyValue->isPrimitiveValue() & & m_node) { 594 if (propertyID == CSSPropertyFontSize && propertyValue.isPrimitiveValue() && m_node) {
595 m_node->document().updateLayoutIgnorePendingStylesheets(); 595 m_node->document().updateLayoutIgnorePendingStylesheets();
596 const ComputedStyle* style = m_node->ensureComputedStyle(m_pseudoElement Specifier); 596 const ComputedStyle* style = m_node->ensureComputedStyle(m_pseudoElement Specifier);
597 if (style && style->fontDescription().keywordSize()) { 597 if (style && style->fontDescription().keywordSize()) {
598 CSSValueID sizeValue = cssIdentifierForFontSizeKeyword(style->fontDe scription().keywordSize()); 598 CSSValueID sizeValue = cssIdentifierForFontSizeKeyword(style->fontDe scription().keywordSize());
599 const CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(proper tyValue); 599 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(proper tyValue);
600 if (primitiveValue->isValueID() && primitiveValue->getValueID() == s izeValue) 600 if (primitiveValue.isValueID() && primitiveValue.getValueID() == siz eValue)
601 return true; 601 return true;
602 } 602 }
603 } 603 }
604 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(propertyID); 604 NullableCSSValue value = getPropertyCSSValue(propertyID);
605 return value && propertyValue && value->equals(*propertyValue); 605 return value && value->equals(propertyValue);
606 } 606 }
607 607
608 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::cop yProperties() const 608 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::cop yProperties() const
609 { 609 {
610 return copyPropertiesInSet(computableProperties()); 610 return copyPropertiesInSet(computableProperties());
611 } 611 }
612 612
613 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::cop yPropertiesInSet(const Vector<CSSPropertyID>& properties) const 613 PassRefPtrWillBeRawPtr<MutableStylePropertySet> CSSComputedStyleDeclaration::cop yPropertiesInSet(const Vector<CSSPropertyID>& properties) const
614 { 614 {
615 WillBeHeapVector<CSSProperty, 256> list; 615 WillBeHeapVector<CSSProperty, 256> list;
616 list.reserveInitialCapacity(properties.size()); 616 list.reserveInitialCapacity(properties.size());
617 for (unsigned i = 0; i < properties.size(); ++i) { 617 for (unsigned i = 0; i < properties.size(); ++i) {
618 RefPtrWillBeRawPtr<CSSValue> value = getPropertyCSSValue(properties[i]); 618 NullableCSSValue value = getPropertyCSSValue(properties[i]);
619 if (value) 619 if (value)
620 list.append(CSSProperty(properties[i], value.release(), false)); 620 list.append(CSSProperty(properties[i], *value, false));
621 } 621 }
622 return MutableStylePropertySet::create(list.data(), list.size()); 622 return MutableStylePropertySet::create(list.data(), list.size());
623 } 623 }
624 624
625 CSSRule* CSSComputedStyleDeclaration::parentRule() const 625 CSSRule* CSSComputedStyleDeclaration::parentRule() const
626 { 626 {
627 return 0; 627 return 0;
628 } 628 }
629 629
630 String CSSComputedStyleDeclaration::getPropertyValue(const String& propertyName) 630 String CSSComputedStyleDeclaration::getPropertyValue(const String& propertyName)
(...skipping 25 matching lines...) Expand all
656 { 656 {
657 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + name + "' property is read-only."); 657 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + name + "' property is read-only.");
658 } 658 }
659 659
660 String CSSComputedStyleDeclaration::removeProperty(const String& name, Exception State& exceptionState) 660 String CSSComputedStyleDeclaration::removeProperty(const String& name, Exception State& exceptionState)
661 { 661 {
662 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + name + "' property is read-only."); 662 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + name + "' property is read-only.");
663 return String(); 663 return String();
664 } 664 }
665 665
666 PassRefPtrWillBeRawPtr<CSSValue> CSSComputedStyleDeclaration::getPropertyCSSValu eInternal(CSSPropertyID propertyID) 666 NullableCSSValue CSSComputedStyleDeclaration::getPropertyCSSValueInternal(CSSPro pertyID propertyID)
667 { 667 {
668 return getPropertyCSSValue(propertyID); 668 return getPropertyCSSValue(propertyID);
669 } 669 }
670 670
671 String CSSComputedStyleDeclaration::getPropertyValueInternal(CSSPropertyID prope rtyID) 671 String CSSComputedStyleDeclaration::getPropertyValueInternal(CSSPropertyID prope rtyID)
672 { 672 {
673 return getPropertyValue(propertyID); 673 return getPropertyValue(propertyID);
674 } 674 }
675 675
676 void CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID id, const St ring&, bool, ExceptionState& exceptionState) 676 void CSSComputedStyleDeclaration::setPropertyInternal(CSSPropertyID id, const St ring&, bool, ExceptionState& exceptionState)
677 { 677 {
678 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + getPropertyNameString(id) + "' property is r ead-only."); 678 exceptionState.throwDOMException(NoModificationAllowedError, "These styles a re computed, and therefore the '" + getPropertyNameString(id) + "' property is r ead-only.");
679 } 679 }
680 680
681 DEFINE_TRACE(CSSComputedStyleDeclaration) 681 DEFINE_TRACE(CSSComputedStyleDeclaration)
682 { 682 {
683 visitor->trace(m_node); 683 visitor->trace(m_node);
684 CSSStyleDeclaration::trace(visitor); 684 CSSStyleDeclaration::trace(visitor);
685 } 685 }
686 686
687 } // namespace blink 687 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698