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

Side by Side Diff: third_party/WebKit/Source/core/css/cssom/ComputedStylePropertyMap.cpp

Issue 2312293003: [CSSTypedOM] Computed StylePropertyMap use ComputedStyle for Lengths (Closed)
Patch Set: remove unneeded braces Created 4 years, 2 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 2016 the Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/css/cssom/ComputedStylePropertyMap.h" 5 #include "core/css/cssom/ComputedStylePropertyMap.h"
6 6
7 #include "core/css/CSSComputedStyleDeclaration.h" 7 #include "core/css/CSSComputedStyleDeclaration.h"
8 #include "core/css/cssom/CSSCalcLength.h"
9 #include "core/css/cssom/CSSKeywordValue.h"
10 #include "core/css/cssom/CSSSimpleLength.h"
8 #include "core/css/cssom/StyleValueFactory.h" 11 #include "core/css/cssom/StyleValueFactory.h"
9 12
10 namespace blink { 13 namespace blink {
11 14
15 namespace {
16
17 CSSStyleValue* styleValueForLength(const Length& length)
18 {
19 if (length.isAuto()) {
20 return CSSKeywordValue::create("auto");
21 }
22 if (length.isFixed()) {
23 return CSSSimpleLength::create(length.pixels(), CSSPrimitiveValue::UnitT ype::Pixels);
24 }
25 if (length.isPercent()) {
26 return CSSSimpleLength::create(length.percent(), CSSPrimitiveValue::Unit Type::Percentage);
27 }
28 if (length.isCalculated()) {
29 return CSSCalcLength::fromLength(length);
30 }
31 NOTREACHED();
32 return nullptr;
33 }
34
35 } // namespace
36
12 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope rtyID) 37 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(CSSPropertyID prope rtyID)
13 { 38 {
14 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(propertyID); 39 Document& document = m_node->document();
15 if (!cssValue) 40 // TODO(rjwright): This style recalc is copied from
16 return CSSStyleValueVector(); 41 // CSSComputedStyleDeclaration::getPropertyValue, which also does a bunch of other stuff.
17 return StyleValueFactory::cssValueToStyleValueVector(propertyID, *cssValue); 42 // Need to look back to it and see if I need to do more here.
43 document.updateStyleAndLayoutTreeForNode(m_node);
nainar 2016/09/28 02:53:25 this should instead be like CSSComputedStyleDeclar
44 const ComputedStyle* style = m_node->ensureComputedStyle();
nainar 2016/09/28 02:53:25 This needs to be expanded to cater to the case of
45 CSSStyleValueVector styleValueVector;
46 CSSStyleValue* styleValue = nullptr;
47 switch (propertyID) {
48 case CSSPropertyLeft:
49 styleValue = styleValueForLength(style->left());
50 case CSSPropertyRight:
51 styleValue = styleValueForLength(style->right());
52 case CSSPropertyTop:
53 styleValue = styleValueForLength(style->top());
54 case CSSPropertyBottom:
55 styleValue = styleValueForLength(style->bottom());
56 case CSSPropertyHeight:
57 styleValue = styleValueForLength(style->height());
58 case CSSPropertyWidth:
59 styleValue = styleValueForLength(style->width());
60 default:
61 break;
62 }
63
64 if (styleValue) {
65 styleValueVector.append(styleValue);
66 }
67 return styleValueVector;
18 } 68 }
19 69
20 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName) 70 CSSStyleValueVector ComputedStylePropertyMap::getAllInternal(AtomicString custom PropertyName)
21 { 71 {
22 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName); 72 const CSSValue* cssValue = m_computedStyleDeclaration->getPropertyCSSValueIn ternal(customPropertyName);
23 if (!cssValue) 73 if (!cssValue)
24 return CSSStyleValueVector(); 74 return CSSStyleValueVector();
25 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue); 75 return StyleValueFactory::cssValueToStyleValueVector(CSSPropertyInvalid, *cs sValue);
26 } 76 }
27 77
28 Vector<String> ComputedStylePropertyMap::getProperties() 78 Vector<String> ComputedStylePropertyMap::getProperties()
29 { 79 {
30 Vector<String> result; 80 Vector<String> result;
31 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) { 81 for (unsigned i = 0; i < m_computedStyleDeclaration->length(); i++) {
32 result.append(m_computedStyleDeclaration->item(i)); 82 result.append(m_computedStyleDeclaration->item(i));
33 } 83 }
34 return result; 84 return result;
35 } 85 }
36 86
37 } // namespace blink 87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698