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

Side by Side Diff: Source/core/css/parser/CSSToken.cpp

Issue 171383002: A thread-safe Media Query Parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Refactored and passes tests Created 6 years, 10 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
(Empty)
1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "core/css/parser/CSSToken.h"
33
34 #include "wtf/HashMap.h"
35 #include "wtf/text/StringHash.h"
36
37 namespace WebCore {
38
39 typedef HashMap<String, CSSPrimitiveValue::UnitTypes> UnitTable;
40
41 UnitTable createUnitTable()
42 {
43 UnitTable table;
44 table.set(String("em"), CSSPrimitiveValue::CSS_EMS);
45 table.set(String("ex"), CSSPrimitiveValue::CSS_EXS);
46 table.set(String("px"), CSSPrimitiveValue::CSS_PX);
47 table.set(String("cm"), CSSPrimitiveValue::CSS_CM);
48 table.set(String("mm"), CSSPrimitiveValue::CSS_MM);
49 table.set(String("in"), CSSPrimitiveValue::CSS_IN);
50 table.set(String("pt"), CSSPrimitiveValue::CSS_PT);
51 table.set(String("pc"), CSSPrimitiveValue::CSS_PC);
52 table.set(String("deg"), CSSPrimitiveValue::CSS_DEG);
53 table.set(String("rad"), CSSPrimitiveValue::CSS_RAD);
54 table.set(String("grad"), CSSPrimitiveValue::CSS_GRAD);
55 table.set(String("ms"), CSSPrimitiveValue::CSS_MS);
56 table.set(String("s"), CSSPrimitiveValue::CSS_S);
57 table.set(String("hz"), CSSPrimitiveValue::CSS_HZ);
58 table.set(String("khz"), CSSPrimitiveValue::CSS_KHZ);
59 table.set(String("dpi"), CSSPrimitiveValue::CSS_DPI);
60 table.set(String("dpcm"), CSSPrimitiveValue::CSS_DPCM);
61 table.set(String("dppx"), CSSPrimitiveValue::CSS_DPPX);
62 table.set(String("vw"), CSSPrimitiveValue::CSS_VW);
63 table.set(String("vh"), CSSPrimitiveValue::CSS_VH);
64 table.set(String("vmax"), CSSPrimitiveValue::CSS_VMIN);
65 table.set(String("vmin"), CSSPrimitiveValue::CSS_VMAX);
66 return table;
67 }
68
69 static UnitTable* getUnitTable()
70 {
71 // Allocating to avoid exit time desctructor
72 static UnitTable* unitTable = new UnitTable(createUnitTable());
73 return unitTable;
74 }
75
76 CSSToken::CSSToken(CSSTokenType type)
77 : m_type(type)
78 , m_delimiter(0)
79 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
80 {
81 }
82
83 // Just a helper used for Delim tokens.
84 CSSToken::CSSToken(CSSTokenType type, UChar c)
85 : m_type(type)
86 , m_delimiter(c)
87 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
88 {
89 ASSERT(m_type == DelimToken);
90 }
91
92 CSSToken::CSSToken(CSSTokenType type, String value)
93 : m_type(type)
94 , m_value(value)
95 , m_delimiter(0)
96 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
97 {
98 }
99
100 CSSToken::CSSToken(CSSTokenType type, String name, HashTokenType hashType)
101 : m_type(type)
102 , m_value(name)
103 , m_hashTokenType(hashType)
104 , m_delimiter(0)
105 , m_unit(CSSPrimitiveValue::CSS_UNKNOWN)
106 {
107 ASSERT(m_type == HashToken);
108 }
109
110 CSSToken::CSSToken(CSSTokenType type, double numericValue, NumericValueType nume ricValueType)
111 : m_type(type)
112 , m_delimiter(0)
113 , m_numericValueType(numericValueType)
114 , m_numericValue(numericValue)
115 , m_unit(CSSPrimitiveValue::CSS_NUMBER)
116 {
117 ASSERT(type == NumberToken);
118 }
119
120 void CSSToken::convertToDimensionWithUnit(String unit)
121 {
122 ASSERT(m_type == NumberToken);
123 m_type = DimensionToken;
124 m_unit = getUnitTable()->get(unit.lower());
125 }
126
127 void CSSToken::convertToPercentage()
128 {
129 ASSERT(m_type == NumberToken);
130 m_type = PercentageToken;
131 m_unit = CSSPrimitiveValue::CSS_PERCENTAGE;
132 }
133
134 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698