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

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

Issue 1192983003: CSS Custom Properties (Variables) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Post-merge Created 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2012 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "core/css/CSSPrimitiveValue.h" 22 #include "core/css/CSSPrimitiveValue.h"
23 23
24 #include "core/css/CSSBasicShapes.h" 24 #include "core/css/CSSBasicShapes.h"
25 #include "core/css/CSSCalculationValue.h" 25 #include "core/css/CSSCalculationValue.h"
26 #include "core/css/CSSHelper.h" 26 #include "core/css/CSSHelper.h"
27 #include "core/css/CSSMarkup.h" 27 #include "core/css/CSSMarkup.h"
28 #include "core/css/CSSToLengthConversionData.h" 28 #include "core/css/CSSToLengthConversionData.h"
29 #include "core/css/CSSVariableData.h"
29 #include "core/css/StyleSheetContents.h" 30 #include "core/css/StyleSheetContents.h"
30 #include "core/dom/Node.h" 31 #include "core/dom/Node.h"
31 #include "core/style/ComputedStyle.h" 32 #include "core/style/ComputedStyle.h"
32 #include "platform/LayoutUnit.h" 33 #include "platform/LayoutUnit.h"
33 #include "platform/fonts/FontMetrics.h" 34 #include "platform/fonts/FontMetrics.h"
34 #include "wtf/StdLibExtras.h" 35 #include "wtf/StdLibExtras.h"
35 #include "wtf/ThreadSpecific.h" 36 #include "wtf/ThreadSpecific.h"
36 #include "wtf/Threading.h" 37 #include "wtf/Threading.h"
37 #include "wtf/text/StringBuffer.h" 38 #include "wtf/text/StringBuffer.h"
38 #include "wtf/text/StringBuilder.h" 39 #include "wtf/text/StringBuilder.h"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 m_value.calc = c.leakRef(); 334 m_value.calc = c.leakRef();
334 } 335 }
335 336
336 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSBasicShape> shape) 337 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSBasicShape> shape)
337 { 338 {
338 init(UnitType::Shape); 339 init(UnitType::Shape);
339 m_hasCachedCSSText = false; 340 m_hasCachedCSSText = false;
340 m_value.shape = shape.leakRef(); 341 m_value.shape = shape.leakRef();
341 } 342 }
342 343
344 void CSSPrimitiveValue::init(PassRefPtrWillBeRawPtr<CSSVariableData> variableDat a)
345 {
346 init(UnitType::VariableReference);
347 m_hasCachedCSSText = false;
348 m_value.variableData = variableData.leakRef();
349 }
350
343 CSSPrimitiveValue::~CSSPrimitiveValue() 351 CSSPrimitiveValue::~CSSPrimitiveValue()
344 { 352 {
345 cleanup(); 353 cleanup();
346 } 354 }
347 355
348 void CSSPrimitiveValue::cleanup() 356 void CSSPrimitiveValue::cleanup()
349 { 357 {
350 switch (type()) { 358 switch (type()) {
351 case UnitType::CustomIdentifier: 359 case UnitType::CustomIdentifier:
352 case UnitType::String: 360 case UnitType::String:
(...skipping 10 matching lines...) Expand all
363 case UnitType::CalcPercentageWithNumber: 371 case UnitType::CalcPercentageWithNumber:
364 case UnitType::CalcPercentageWithLength: 372 case UnitType::CalcPercentageWithLength:
365 ASSERT_NOT_REACHED(); 373 ASSERT_NOT_REACHED();
366 break; 374 break;
367 case UnitType::Shape: 375 case UnitType::Shape:
368 // We must not call deref() when oilpan is enabled because m_value.shape is traced. 376 // We must not call deref() when oilpan is enabled because m_value.shape is traced.
369 #if !ENABLE(OILPAN) 377 #if !ENABLE(OILPAN)
370 m_value.shape->deref(); 378 m_value.shape->deref();
371 #endif 379 #endif
372 break; 380 break;
381 case UnitType::VariableReference:
382 #if !ENABLE(OILPAN)
383 m_value.variableData->deref();
384 #endif
385 break;
373 case UnitType::Number: 386 case UnitType::Number:
374 case UnitType::Integer: 387 case UnitType::Integer:
375 case UnitType::Percentage: 388 case UnitType::Percentage:
376 case UnitType::Ems: 389 case UnitType::Ems:
377 case UnitType::QuirkyEms: 390 case UnitType::QuirkyEms:
378 case UnitType::Exs: 391 case UnitType::Exs:
379 case UnitType::Rems: 392 case UnitType::Rems:
380 case UnitType::Chs: 393 case UnitType::Chs:
381 case UnitType::Pixels: 394 case UnitType::Pixels:
382 case UnitType::Centimeters: 395 case UnitType::Centimeters:
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 case UnitType::CustomIdentifier: 858 case UnitType::CustomIdentifier:
846 case UnitType::String: 859 case UnitType::String:
847 case UnitType::URI: 860 case UnitType::URI:
848 case UnitType::ValueID: 861 case UnitType::ValueID:
849 case UnitType::PropertyID: 862 case UnitType::PropertyID:
850 case UnitType::RGBColor: 863 case UnitType::RGBColor:
851 case UnitType::Calc: 864 case UnitType::Calc:
852 case UnitType::Shape: 865 case UnitType::Shape:
853 case UnitType::CalcPercentageWithNumber: 866 case UnitType::CalcPercentageWithNumber:
854 case UnitType::CalcPercentageWithLength: 867 case UnitType::CalcPercentageWithLength:
868 case UnitType::VariableReference:
855 break; 869 break;
856 }; 870 };
857 ASSERT_NOT_REACHED(); 871 ASSERT_NOT_REACHED();
858 return ""; 872 return "";
859 } 873 }
860 874
861 String CSSPrimitiveValue::customCSSText() const 875 String CSSPrimitiveValue::customCSSText() const
862 { 876 {
863 if (m_hasCachedCSSText) { 877 if (m_hasCachedCSSText) {
864 ASSERT(cssTextCache().contains(this)); 878 ASSERT(cssTextCache().contains(this));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 case UnitType::RGBColor: { 937 case UnitType::RGBColor: {
924 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue(); 938 text = Color(m_value.rgbcolor).serializedAsCSSComponentValue();
925 break; 939 break;
926 } 940 }
927 case UnitType::Calc: 941 case UnitType::Calc:
928 text = m_value.calc->customCSSText(); 942 text = m_value.calc->customCSSText();
929 break; 943 break;
930 case UnitType::Shape: 944 case UnitType::Shape:
931 text = m_value.shape->cssText(); 945 text = m_value.shape->cssText();
932 break; 946 break;
947 case UnitType::VariableReference: {
948 CSSParserTokenRange range = m_value.variableData->tokenRange();
949 text = range.serialize();
950 break;
951 }
933 case UnitType::CalcPercentageWithNumber: 952 case UnitType::CalcPercentageWithNumber:
934 case UnitType::CalcPercentageWithLength: 953 case UnitType::CalcPercentageWithLength:
935 ASSERT_NOT_REACHED(); 954 ASSERT_NOT_REACHED();
936 break; 955 break;
937 } 956 }
938 957
939 ASSERT(!cssTextCache().contains(this)); 958 ASSERT(!cssTextCache().contains(this));
940 cssTextCache().set(this, text); 959 cssTextCache().set(this, text);
941 m_hasCachedCSSText = true; 960 m_hasCachedCSSText = true;
942 return text; 961 return text;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 case UnitType::CustomIdentifier: 1004 case UnitType::CustomIdentifier:
986 case UnitType::String: 1005 case UnitType::String:
987 case UnitType::URI: 1006 case UnitType::URI:
988 return equal(m_value.string, other.m_value.string); 1007 return equal(m_value.string, other.m_value.string);
989 case UnitType::RGBColor: 1008 case UnitType::RGBColor:
990 return m_value.rgbcolor == other.m_value.rgbcolor; 1009 return m_value.rgbcolor == other.m_value.rgbcolor;
991 case UnitType::Calc: 1010 case UnitType::Calc:
992 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc); 1011 return m_value.calc && other.m_value.calc && m_value.calc->equals(*other .m_value.calc);
993 case UnitType::Shape: 1012 case UnitType::Shape:
994 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape); 1013 return m_value.shape && other.m_value.shape && m_value.shape->equals(*ot her.m_value.shape);
1014 case UnitType::VariableReference:
1015 return m_value.variableData == other.m_value.variableData;
995 case UnitType::Integer: 1016 case UnitType::Integer:
996 case UnitType::Chs: 1017 case UnitType::Chs:
997 case UnitType::CalcPercentageWithNumber: 1018 case UnitType::CalcPercentageWithNumber:
998 case UnitType::CalcPercentageWithLength: 1019 case UnitType::CalcPercentageWithLength:
999 case UnitType::QuirkyEms: 1020 case UnitType::QuirkyEms:
1000 return false; 1021 return false;
1001 } 1022 }
1002 return false; 1023 return false;
1003 } 1024 }
1004 1025
1005 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue) 1026 DEFINE_TRACE_AFTER_DISPATCH(CSSPrimitiveValue)
1006 { 1027 {
1007 #if ENABLE(OILPAN) 1028 #if ENABLE(OILPAN)
1008 switch (type()) { 1029 switch (type()) {
1009 case UnitType::Calc: 1030 case UnitType::Calc:
1010 visitor->trace(m_value.calc); 1031 visitor->trace(m_value.calc);
1011 break; 1032 break;
1012 case UnitType::Shape: 1033 case UnitType::Shape:
1013 visitor->trace(m_value.shape); 1034 visitor->trace(m_value.shape);
1014 break; 1035 break;
1015 default: 1036 default:
1016 break; 1037 break;
1017 } 1038 }
1018 #endif 1039 #endif
1019 CSSValue::traceAfterDispatch(visitor); 1040 CSSValue::traceAfterDispatch(visitor);
1020 } 1041 }
1021 1042
1022 } // namespace blink 1043 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698