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

Side by Side Diff: third_party/WebKit/Source/core/style/ComputedStyle.cpp

Issue 2366313006: CSS Properties and Values API: Support non-inherited custom properties (Closed)
Patch Set: use de morgan's law 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 /* 1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 22 matching lines...) Expand all
33 #include "core/style/AppliedTextDecoration.h" 33 #include "core/style/AppliedTextDecoration.h"
34 #include "core/style/BorderEdge.h" 34 #include "core/style/BorderEdge.h"
35 #include "core/style/ComputedStyleConstants.h" 35 #include "core/style/ComputedStyleConstants.h"
36 #include "core/style/ContentData.h" 36 #include "core/style/ContentData.h"
37 #include "core/style/CursorData.h" 37 #include "core/style/CursorData.h"
38 #include "core/style/DataEquivalency.h" 38 #include "core/style/DataEquivalency.h"
39 #include "core/style/QuotesData.h" 39 #include "core/style/QuotesData.h"
40 #include "core/style/ShadowList.h" 40 #include "core/style/ShadowList.h"
41 #include "core/style/StyleImage.h" 41 #include "core/style/StyleImage.h"
42 #include "core/style/StyleInheritedData.h" 42 #include "core/style/StyleInheritedData.h"
43 #include "core/style/StyleVariableData.h" 43 #include "core/style/StyleInheritedVariables.h"
44 #include "core/style/StyleNonInheritedVariables.h"
44 #include "platform/LengthFunctions.h" 45 #include "platform/LengthFunctions.h"
45 #include "platform/RuntimeEnabledFeatures.h" 46 #include "platform/RuntimeEnabledFeatures.h"
46 #include "platform/fonts/Font.h" 47 #include "platform/fonts/Font.h"
47 #include "platform/fonts/FontSelector.h" 48 #include "platform/fonts/FontSelector.h"
48 #include "platform/geometry/FloatRoundedRect.h" 49 #include "platform/geometry/FloatRoundedRect.h"
49 #include "platform/graphics/GraphicsContext.h" 50 #include "platform/graphics/GraphicsContext.h"
50 #include "platform/transforms/RotateTransformOperation.h" 51 #include "platform/transforms/RotateTransformOperation.h"
51 #include "platform/transforms/ScaleTransformOperation.h" 52 #include "platform/transforms/ScaleTransformOperation.h"
52 #include "platform/transforms/TranslateTransformOperation.h" 53 #include "platform/transforms/TranslateTransformOperation.h"
53 #include "wtf/MathExtras.h" 54 #include "wtf/MathExtras.h"
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 if (!value->nativeInvalidationProperties() || !value->customInvalidationProp erties()) 875 if (!value->nativeInvalidationProperties() || !value->customInvalidationProp erties())
875 return true; 876 return true;
876 877
877 for (CSSPropertyID propertyID : *value->nativeInvalidationProperties()) { 878 for (CSSPropertyID propertyID : *value->nativeInvalidationProperties()) {
878 // TODO(ikilpatrick): remove isInterpolableProperty check once 879 // TODO(ikilpatrick): remove isInterpolableProperty check once
879 // CSSPropertyEquality::propertiesEqual correctly handles all properties . 880 // CSSPropertyEquality::propertiesEqual correctly handles all properties .
880 if (!CSSPropertyMetadata::isInterpolableProperty(propertyID) || !CSSProp ertyEquality::propertiesEqual(propertyID, *this, other)) 881 if (!CSSPropertyMetadata::isInterpolableProperty(propertyID) || !CSSProp ertyEquality::propertiesEqual(propertyID, *this, other))
881 return true; 882 return true;
882 } 883 }
883 884
884 if (variables() || other.variables()) { 885 if (inheritedVariables() || other.inheritedVariables()) {
885 for (const AtomicString& property : *value->customInvalidationProperties ()) { 886 for (const AtomicString& property : *value->customInvalidationProperties ()) {
886 CSSVariableData* thisVar = variables() ? variables()->getVariable(pr operty) : nullptr; 887 CSSVariableData* thisVar = inheritedVariables() ? inheritedVariables ()->getVariable(property) : nullptr;
887 CSSVariableData* otherVar = other.variables() ? other.variables()->g etVariable(property) : nullptr; 888 CSSVariableData* otherVar = other.inheritedVariables() ? other.inher itedVariables()->getVariable(property) : nullptr;
888 889
889 if (!dataEquivalent(thisVar, otherVar)) 890 if (!dataEquivalent(thisVar, otherVar))
890 return true; 891 return true;
891 } 892 }
892 } 893 }
893 894
894 return false; 895 return false;
895 } 896 }
896 897
897 void ComputedStyle::updatePropertySpecificDifferences(const ComputedStyle& other , StyleDifference& diff) const 898 void ComputedStyle::updatePropertySpecificDifferences(const ComputedStyle& other , StyleDifference& diff) const
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 return empty; 1434 return empty;
1434 } 1435 }
1435 if (m_inheritedData.m_textUnderline) { 1436 if (m_inheritedData.m_textUnderline) {
1436 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, Applie dTextDecoration(TextDecorationUnderline))); 1437 DEFINE_STATIC_LOCAL(Vector<AppliedTextDecoration>, underline, (1, Applie dTextDecoration(TextDecorationUnderline)));
1437 return underline; 1438 return underline;
1438 } 1439 }
1439 1440
1440 return m_rareInheritedData->appliedTextDecorations->vector(); 1441 return m_rareInheritedData->appliedTextDecorations->vector();
1441 } 1442 }
1442 1443
1443 StyleVariableData* ComputedStyle::variables() const 1444 StyleInheritedVariables* ComputedStyle::inheritedVariables() const
1444 { 1445 {
1445 return m_rareInheritedData->variables.get(); 1446 return m_rareInheritedData->variables.get();
1446 } 1447 }
1447 1448
1448 void ComputedStyle::setVariable(const AtomicString& name, PassRefPtr<CSSVariable Data> value) 1449 StyleNonInheritedVariables* ComputedStyle::nonInheritedVariables() const
1449 { 1450 {
1450 RefPtr<StyleVariableData>& variables = m_rareInheritedData.access()->variabl es; 1451 return m_rareNonInheritedData->m_variables.get();
1452 }
1453
1454 StyleInheritedVariables& ComputedStyle::mutableInheritedVariables()
1455 {
1456 RefPtr<StyleInheritedVariables>& variables = m_rareInheritedData.access()->v ariables;
1451 if (!variables) 1457 if (!variables)
1452 variables = StyleVariableData::create(); 1458 variables = StyleInheritedVariables::create();
1453 else if (!variables->hasOneRef()) 1459 else if (!variables->hasOneRef())
1454 variables = variables->copy(); 1460 variables = variables->copy();
1455 variables->setVariable(name, std::move(value)); 1461 return *variables;
1456 } 1462 }
1457 1463
1458 void ComputedStyle::setRegisteredInheritedProperty(const AtomicString& name, con st CSSValue* parsedValue) 1464 StyleNonInheritedVariables& ComputedStyle::mutableNonInheritedVariables()
1459 { 1465 {
1460 RefPtr<StyleVariableData>& variables = m_rareInheritedData.access()->variabl es; 1466 std::unique_ptr<StyleNonInheritedVariables>& variables = m_rareNonInheritedD ata.access()->m_variables;
1461 // The CSSVariableData needs to be set before calling this function 1467 if (!variables)
1462 DCHECK(variables); 1468 variables = StyleNonInheritedVariables::create();
1463 DCHECK(!!parsedValue == !!variables->getVariable(name)); 1469 return *variables;
1464 DCHECK(!(variables->getVariable(name) && variables->getVariable(name)->needs VariableResolution()));
1465
1466 if (!variables->hasOneRef())
1467 variables = variables->copy();
1468 variables->setRegisteredInheritedProperty(name, parsedValue);
1469 } 1470 }
1470 1471
1471 void ComputedStyle::removeVariable(const AtomicString& name) 1472 void ComputedStyle::setUnresolvedInheritedVariable(const AtomicString& name, Pas sRefPtr<CSSVariableData> value)
1472 { 1473 {
1473 RefPtr<StyleVariableData>& variables = m_rareInheritedData.access()->variabl es; 1474 DCHECK(value && value->needsVariableResolution());
1474 if (!variables) 1475 mutableInheritedVariables().setVariable(name, std::move(value));
1475 return; 1476 }
1476 if (!variables->hasOneRef()) 1477
1477 variables = variables->copy(); 1478 void ComputedStyle::setUnresolvedNonInheritedVariable(const AtomicString& name, PassRefPtr<CSSVariableData> value)
1478 variables->removeVariable(name); 1479 {
1480 DCHECK(value && value->needsVariableResolution());
1481 mutableNonInheritedVariables().setVariable(name, std::move(value));
1482 }
1483
1484 void ComputedStyle::setResolvedUnregisteredVariable(const AtomicString& name, Pa ssRefPtr<CSSVariableData> value)
1485 {
1486 DCHECK(value && !value->needsVariableResolution());
1487 mutableInheritedVariables().setVariable(name, std::move(value));
1488 }
1489
1490 void ComputedStyle::setResolvedInheritedVariable(const AtomicString& name, PassR efPtr<CSSVariableData> value, const CSSValue* parsedValue)
1491 {
1492 DCHECK(!!value == !!parsedValue);
1493 DCHECK(!(value && value->needsVariableResolution()));
1494
1495 StyleInheritedVariables& variables = mutableInheritedVariables();
1496 variables.setVariable(name, std::move(value));
1497 variables.setRegisteredVariable(name, parsedValue);
1498 }
1499
1500 void ComputedStyle::setResolvedNonInheritedVariable(const AtomicString& name, Pa ssRefPtr<CSSVariableData> value, const CSSValue* parsedValue)
1501 {
1502 DCHECK(!!value == !!parsedValue);
1503 DCHECK(!(value && value->needsVariableResolution()));
1504
1505 StyleNonInheritedVariables& variables = mutableNonInheritedVariables();
1506 variables.setVariable(name, std::move(value));
1507 variables.setRegisteredVariable(name, parsedValue);
1508 }
1509
1510 void ComputedStyle::removeInheritedVariable(const AtomicString& name)
1511 {
1512 mutableInheritedVariables().removeVariable(name);
1513 }
1514
1515 void ComputedStyle::removeNonInheritedVariable(const AtomicString& name)
1516 {
1517 mutableNonInheritedVariables().removeVariable(name);
1479 } 1518 }
1480 1519
1481 float ComputedStyle::wordSpacing() const { return getFontDescription().wordSpaci ng(); } 1520 float ComputedStyle::wordSpacing() const { return getFontDescription().wordSpaci ng(); }
1482 float ComputedStyle::letterSpacing() const { return getFontDescription().letterS pacing(); } 1521 float ComputedStyle::letterSpacing() const { return getFontDescription().letterS pacing(); }
1483 1522
1484 bool ComputedStyle::setFontDescription(const FontDescription& v) 1523 bool ComputedStyle::setFontDescription(const FontDescription& v)
1485 { 1524 {
1486 if (m_styleInheritedData->font.getFontDescription() != v) { 1525 if (m_styleInheritedData->font.getFontDescription() != v) {
1487 m_styleInheritedData.access()->font = Font(v); 1526 m_styleInheritedData.access()->font = Font(v);
1488 return true; 1527 return true;
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 if (value < 0) 2092 if (value < 0)
2054 fvalue -= 0.5f; 2093 fvalue -= 0.5f;
2055 else 2094 else
2056 fvalue += 0.5f; 2095 fvalue += 0.5f;
2057 } 2096 }
2058 2097
2059 return roundForImpreciseConversion<int>(fvalue / zoomFactor); 2098 return roundForImpreciseConversion<int>(fvalue / zoomFactor);
2060 } 2099 }
2061 2100
2062 } // namespace blink 2101 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.h ('k') | third_party/WebKit/Source/core/style/StyleInheritedVariables.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698