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

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

Issue 369423002: Have srcset respond to viewport changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Oilpan comments Created 6 years, 5 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/css/parser/SizesCalcParser.h" 6 #include "core/css/parser/SizesCalcParser.h"
7 7
8 #include "core/css/MediaValues.h" 8 #include "core/css/MediaValues.h"
9 #include "core/css/parser/MediaQueryToken.h" 9 #include "core/css/parser/MediaQueryToken.h"
10 10
11 namespace WebCore { 11 namespace WebCore {
12 12
13 bool SizesCalcParser::parse(MediaQueryTokenIterator start, MediaQueryTokenIterat or end, PassRefPtr<MediaValues> mediaValues, unsigned& result) 13 bool SizesCalcParser::parse(MediaQueryTokenIterator start, MediaQueryTokenIterat or end, PassRefPtr<MediaValues> mediaValues, unsigned& result, bool& viewportDep endant)
14 { 14 {
15 SizesCalcParser parser(mediaValues); 15 SizesCalcParser parser(mediaValues);
16 if (!parser.calcToReversePolishNotation(start, end)) 16 if (!parser.calcToReversePolishNotation(start, end))
17 return false; 17 return false;
18 viewportDependant = parser.viewportDependant();
esprehn 2014/07/14 08:39:49 ditto, make a real API.
18 return parser.calculate(result); 19 return parser.calculate(result);
19 } 20 }
20 21
21 static bool operatorPriority(UChar cc, bool& highPriority) 22 static bool operatorPriority(UChar cc, bool& highPriority)
22 { 23 {
23 if (cc == '+' || cc == '-') 24 if (cc == '+' || cc == '-')
24 highPriority = false; 25 highPriority = false;
25 else if (cc == '*' || cc == '/') 26 else if (cc == '*' || cc == '/')
26 highPriority = true; 27 highPriority = true;
27 else 28 else
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // http://en.wikipedia.org/wiki/Shunting-yard_algorithm 87 // http://en.wikipedia.org/wiki/Shunting-yard_algorithm
87 88
88 Vector<MediaQueryToken> stack; 89 Vector<MediaQueryToken> stack;
89 for (MediaQueryTokenIterator it = start; it != end; ++it) { 90 for (MediaQueryTokenIterator it = start; it != end; ++it) {
90 MediaQueryTokenType type = it->type(); 91 MediaQueryTokenType type = it->type();
91 switch (type) { 92 switch (type) {
92 case NumberToken: 93 case NumberToken:
93 appendNumber(*it); 94 appendNumber(*it);
94 break; 95 break;
95 case DimensionToken: 96 case DimensionToken:
97 if (CSSPrimitiveValue::isViewportPercentageLength(it->unitType()))
esprehn 2014/07/14 08:39:49 Does this happen repeatedly? Should you be doing m
98 m_viewportDependant = true;
96 if (!CSSPrimitiveValue::isLength(it->unitType()) || !appendLength(*i t)) 99 if (!CSSPrimitiveValue::isLength(it->unitType()) || !appendLength(*i t))
97 return false; 100 return false;
98 break; 101 break;
99 case DelimiterToken: 102 case DelimiterToken:
100 if (!handleOperator(stack, *it)) 103 if (!handleOperator(stack, *it))
101 return false; 104 return false;
102 break; 105 break;
103 case FunctionToken: 106 case FunctionToken:
104 if (it->value() != "calc") 107 if (it->value() != "calc")
105 return false; 108 return false;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 208 }
206 } 209 }
207 if (stack.size() == 1 && stack.last().isLength) { 210 if (stack.size() == 1 && stack.last().isLength) {
208 result = clampTo<unsigned>(stack.last().value); 211 result = clampTo<unsigned>(stack.last().value);
209 return true; 212 return true;
210 } 213 }
211 return false; 214 return false;
212 } 215 }
213 216
214 } // namespace WebCore 217 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698