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

Unified Diff: Source/core/css/parser/MediaQueryToken.cpp

Issue 171383002: A thread-safe Media Query Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Another comment fixed Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/css/parser/MediaQueryToken.cpp
diff --git a/Source/core/css/parser/MediaQueryToken.cpp b/Source/core/css/parser/MediaQueryToken.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..ec06226dfab8d11ebc3128ec5676b3dcd77ddbe9
--- /dev/null
+++ b/Source/core/css/parser/MediaQueryToken.cpp
@@ -0,0 +1,97 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/css/parser/MediaQueryToken.h"
+
+#include "wtf/HashMap.h"
+#include "wtf/text/StringHash.h"
+
+namespace WebCore {
+
+typedef HashMap<String, CSSPrimitiveValue::UnitTypes> UnitTable;
+
+UnitTable createUnitTable()
+{
+ UnitTable table;
+ table.set(String("em"), CSSPrimitiveValue::CSS_EMS);
eseidel 2014/03/11 20:14:19 Should this funtion be on CSSPrimtiveValue? If we
Yoav Weiss 2014/03/12 20:39:00 Maybe the best way to do that is through some CSSU
eseidel 2014/03/13 00:49:36 OK. Just file a bug and table that for a later CL
+ table.set(String("ex"), CSSPrimitiveValue::CSS_EXS);
+ table.set(String("px"), CSSPrimitiveValue::CSS_PX);
+ table.set(String("cm"), CSSPrimitiveValue::CSS_CM);
+ table.set(String("mm"), CSSPrimitiveValue::CSS_MM);
+ table.set(String("in"), CSSPrimitiveValue::CSS_IN);
+ table.set(String("pt"), CSSPrimitiveValue::CSS_PT);
+ table.set(String("pc"), CSSPrimitiveValue::CSS_PC);
+ table.set(String("deg"), CSSPrimitiveValue::CSS_DEG);
+ table.set(String("rad"), CSSPrimitiveValue::CSS_RAD);
+ table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD);
+ table.set(String("ms"), CSSPrimitiveValue::CSS_MS);
+ table.set(String("s"), CSSPrimitiveValue::CSS_S);
+ table.set(String("hz"), CSSPrimitiveValue::CSS_HZ);
+ table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ);
+ table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI);
+ table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM);
+ table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX);
+ table.set(String("vw"), CSSPrimitiveValue::CSS_VW);
+ table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
+ table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN);
+ table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX);
+ return table;
+}
+
+static UnitTable& getUnitTable()
+{
+ DEFINE_STATIC_LOCAL(UnitTable, unitTable, (createUnitTable()));
+ return unitTable;
+}
+
+MediaQueryToken::MediaQueryToken(MediaQueryTokenType type)
+ : m_type(type)
+ , m_delimiter(0)
+ , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
+{
+}
+
+// Just a helper used for Delimiter tokens.
+MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, UChar c)
+ : m_type(type)
+ , m_delimiter(c)
+ , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
+{
+ ASSERT(m_type == DelimiterToken);
+}
+
+MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, String value)
+ : m_type(type)
+ , m_value(value)
+ , m_delimiter(0)
+ , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
+{
+}
+
+MediaQueryToken::MediaQueryToken(MediaQueryTokenType type, double numericValue, NumericValueType numericValueType)
+ : m_type(type)
+ , m_delimiter(0)
+ , m_numericValueType(numericValueType)
+ , m_numericValue(numericValue)
+ , m_unit(CSSPrimitiveValue::CSS_NUMBER)
+{
+ ASSERT(type == NumberToken);
+}
+
+void MediaQueryToken::convertToDimensionWithUnit(String unit)
+{
+ ASSERT(m_type == NumberToken);
+ m_type = DimensionToken;
+ m_unit = getUnitTable().get(unit.lower());
+}
+
+void MediaQueryToken::convertToPercentage()
+{
+ ASSERT(m_type == NumberToken);
+ m_type = PercentageToken;
+ m_unit = CSSPrimitiveValue::CSS_PERCENTAGE;
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698