| OLD | NEW |
| 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 blink { | 11 namespace blink { |
| 12 | 12 |
| 13 SizesCalcParser::SizesCalcParser(MediaQueryTokenIterator start, MediaQueryTokenI
terator end, PassRefPtr<MediaValues> mediaValues) | 13 SizesCalcParser::SizesCalcParser(MediaQueryTokenIterator start, MediaQueryTokenI
terator end, PassRefPtr<MediaValues> mediaValues) |
| 14 : m_mediaValues(mediaValues) | 14 : m_mediaValues(mediaValues) |
| 15 , m_viewportDependant(false) | 15 , m_viewportDependant(false) |
| 16 , m_result(0) | 16 , m_result(0) |
| 17 { | 17 { |
| 18 m_isValid = calcToReversePolishNotation(start, end) && calculate(); | 18 m_isValid = calcToReversePolishNotation(start, end) && calculate(); |
| 19 } | 19 } |
| 20 | 20 |
| 21 unsigned SizesCalcParser::result() const | 21 float SizesCalcParser::result() const |
| 22 { | 22 { |
| 23 ASSERT(m_isValid); | 23 ASSERT(m_isValid); |
| 24 return m_result; | 24 return m_result; |
| 25 } | 25 } |
| 26 | 26 |
| 27 static bool operatorPriority(UChar cc, bool& highPriority) | 27 static bool operatorPriority(UChar cc, bool& highPriority) |
| 28 { | 28 { |
| 29 if (cc == '+' || cc == '-') | 29 if (cc == '+' || cc == '-') |
| 30 highPriority = false; | 30 highPriority = false; |
| 31 else if (cc == '*' || cc == '/') | 31 else if (cc == '*' || cc == '/') |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 Vector<SizesCalcValue> stack; | 205 Vector<SizesCalcValue> stack; |
| 206 for (Vector<SizesCalcValue>::iterator it = m_valueList.begin(); it != m_valu
eList.end(); ++it) { | 206 for (Vector<SizesCalcValue>::iterator it = m_valueList.begin(); it != m_valu
eList.end(); ++it) { |
| 207 if (it->operation == 0) { | 207 if (it->operation == 0) { |
| 208 stack.append(*it); | 208 stack.append(*it); |
| 209 } else { | 209 } else { |
| 210 if (!operateOnStack(stack, it->operation)) | 210 if (!operateOnStack(stack, it->operation)) |
| 211 return false; | 211 return false; |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 if (stack.size() == 1 && stack.last().isLength) { | 214 if (stack.size() == 1 && stack.last().isLength) { |
| 215 m_result = clampTo<unsigned>(stack.last().value); | 215 m_result = std::max(clampTo<float>(stack.last().value), (float)0.0); |
| 216 return true; | 216 return true; |
| 217 } | 217 } |
| 218 return false; | 218 return false; |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace blink | 221 } // namespace blink |
| OLD | NEW |