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

Side by Side Diff: third_party/WebKit/Source/core/css/resolver/StyleBuilderConverter.h

Issue 2346193002: Split CSSPrimitiveValue into CSSPrimitiveValue and CSSIdentifierValue (Closed)
Patch Set: Replaced ASSERTs with DCHECKS in presubmit warnings Created 4 years, 3 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * * Redistributions of source code must retain the above copyright 4 * * Redistributions of source code must retain the above copyright
5 * notice, this list of conditions and the following disclaimer. 5 * notice, this list of conditions and the following disclaimer.
6 * * Redistributions in binary form must reproduce the above 6 * * Redistributions in binary form must reproduce the above
7 * copyright notice, this list of conditions and the following disclaimer 7 * copyright notice, this list of conditions and the following disclaimer
8 * in the documentation and/or other materials provided with the 8 * in the documentation and/or other materials provided with the
9 * distribution. 9 * distribution.
10 * * Neither the name of Google Inc. nor the names of its 10 * * Neither the name of Google Inc. nor the names of its
11 * contributors may be used to endorse or promote products derived from 11 * contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission. 12 * this software without specific prior written permission.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #ifndef StyleBuilderConverter_h 27 #ifndef StyleBuilderConverter_h
28 #define StyleBuilderConverter_h 28 #define StyleBuilderConverter_h
29 29
30 #include "core/css/CSSIdentifierValue.h"
30 #include "core/css/CSSStringValue.h" 31 #include "core/css/CSSStringValue.h"
31 #include "core/css/CSSValue.h" 32 #include "core/css/CSSValue.h"
32 #include "core/css/CSSValueList.h" 33 #include "core/css/CSSValueList.h"
33 #include "core/css/resolver/StyleResolverState.h" 34 #include "core/css/resolver/StyleResolverState.h"
34 #include "core/style/QuotesData.h" 35 #include "core/style/QuotesData.h"
35 #include "core/style/ShadowList.h" 36 #include "core/style/ShadowList.h"
36 #include "core/style/StyleMotionRotation.h" 37 #include "core/style/StyleMotionRotation.h"
37 #include "core/style/StyleReflection.h" 38 #include "core/style/StyleReflection.h"
38 #include "core/style/StyleScrollSnapData.h" 39 #include "core/style/StyleScrollSnapData.h"
39 #include "core/style/TransformOrigin.h" 40 #include "core/style/TransformOrigin.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 template <typename T> 129 template <typename T>
129 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, const CSSValue& value) 130 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, const CSSValue& value)
130 { 131 {
131 return toCSSPrimitiveValue(value).computeLength<T>(state.cssToLengthConversi onData()); 132 return toCSSPrimitiveValue(value).computeLength<T>(state.cssToLengthConversi onData());
132 } 133 }
133 134
134 template <typename T> 135 template <typename T>
135 T StyleBuilderConverter::convertFlags(StyleResolverState& state, const CSSValue& value) 136 T StyleBuilderConverter::convertFlags(StyleResolverState& state, const CSSValue& value)
136 { 137 {
137 T flags = static_cast<T>(0); 138 T flags = static_cast<T>(0);
138 if (value.isPrimitiveValue() && toCSSPrimitiveValue(value).getValueID() == C SSValueNone) 139 if (value.isIdentifierValue() && toCSSIdentifierValue(value).getValueID() == CSSValueNone)
139 return flags; 140 return flags;
140 for (auto& flagValue : toCSSValueList(value)) 141 for (auto& flagValue : toCSSValueList(value))
141 flags |= toCSSPrimitiveValue(*flagValue).convertTo<T>(); 142 flags |= toCSSIdentifierValue(*flagValue).convertTo<T>();
142 return flags; 143 return flags;
143 } 144 }
144 145
145 template <typename T> 146 template <typename T>
146 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, const CSSVa lue& value) 147 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, const CSSVa lue& value)
147 { 148 {
149 if (value.isIdentifierValue()) {
150 CSSValueID valueID = toCSSIdentifierValue(value).getValueID();
151 if (valueID == CSSValueThin)
152 return 1;
153 if (valueID == CSSValueMedium)
154 return 3;
155 if (valueID == CSSValueThick)
156 return 5;
157 NOTREACHED();
158 return 0;
159 }
148 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); 160 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value);
149 CSSValueID valueID = primitiveValue.getValueID(); 161 // FIXME: We are moving to use the full page zoom implementation to handle h igh-dpi.
150 if (valueID == CSSValueThin) 162 // In that case specyfing a border-width of less than 1px would result in a border that is one device pixel thick.
151 return 1; 163 // With this change that would instead be rounded up to 2 device pixels.
152 if (valueID == CSSValueMedium) 164 // Consider clamping it to device pixels or zoom adjusted CSS pixels instead of raw CSS pixels.
153 return 3; 165 // Reference crbug.com/485650 and crbug.com/382483
154 if (valueID == CSSValueThick) 166 double result = primitiveValue.computeLength<double>(state.cssToLengthConver sionData());
155 return 5; 167 if (result > 0.0 && result < 1.0)
156 if (valueID == CSSValueInvalid) { 168 return 1.0;
157 // FIXME: We are moving to use the full page zoom implementation to hand le high-dpi. 169 return clampTo<T>(roundForImpreciseConversion<T>(result), defaultMinimumForC lamp<T>(), defaultMaximumForClamp<T>());
158 // In that case specyfing a border-width of less than 1px would result i n a border that is one device pixel thick.
159 // With this change that would instead be rounded up to 2 device pixels.
160 // Consider clamping it to device pixels or zoom adjusted CSS pixels ins tead of raw CSS pixels.
161 // Reference crbug.com/485650 and crbug.com/382483
162 double result = primitiveValue.computeLength<double>(state.cssToLengthCo nversionData());
163 if (result > 0.0 && result < 1.0)
164 return 1.0;
165 return clampTo<T>(roundForImpreciseConversion<T>(result), defaultMinimum ForClamp<T>(), defaultMaximumForClamp<T>());
166 }
167 ASSERT_NOT_REACHED();
168 return 0;
169 } 170 }
170 171
171 template <CSSValueID IdForNone> 172 template <CSSValueID IdForNone>
172 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, const CSS Value& value) 173 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, const CSS Value& value)
173 { 174 {
174 if (value.isStringValue()) 175 if (value.isStringValue())
175 return AtomicString(toCSSStringValue(value).value()); 176 return AtomicString(toCSSStringValue(value).value());
176 ASSERT(toCSSPrimitiveValue(value).getValueID() == IdForNone); 177 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), IdForNone);
177 return nullAtom; 178 return nullAtom;
178 } 179 }
179 180
180 } // namespace blink 181 } // namespace blink
181 182
182 #endif 183 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698