| 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/SizesAttributeParser.h" | 6 #include "core/css/parser/SizesAttributeParser.h" |
| 7 | 7 |
| 8 #include "core/MediaTypeNames.h" | 8 #include "core/MediaTypeNames.h" |
| 9 #include "core/css/MediaQueryEvaluator.h" | 9 #include "core/css/MediaQueryEvaluator.h" |
| 10 #include "core/css/parser/CSSTokenizer.h" | 10 #include "core/css/parser/CSSTokenizer.h" |
| 11 #include "core/css/parser/SizesCalcParser.h" | 11 #include "core/css/parser/SizesCalcParser.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 SizesAttributeParser::SizesAttributeParser(PassRefPtr<MediaValues> mediaValues,
const String& attribute) | 15 SizesAttributeParser::SizesAttributeParser(PassRefPtr<MediaValues> mediaValues,
const String& attribute, bool hasLocalFrame) |
| 16 : m_mediaValues(mediaValues) | 16 : m_mediaValues(mediaValues) |
| 17 , m_length(0) | 17 , m_length(0) |
| 18 , m_lengthWasSet(false) | 18 , m_lengthWasSet(false) |
| 19 , m_viewportDependant(false) | 19 , m_viewportDependant(false) |
| 20 , m_hasLocalFrame(hasLocalFrame) |
| 20 { | 21 { |
| 21 CSSTokenizer::tokenize(attribute, m_tokens); | 22 CSSTokenizer::tokenize(attribute, m_tokens); |
| 22 m_isValid = parse(m_tokens); | 23 m_isValid = parse(m_tokens); |
| 23 } | 24 } |
| 24 | 25 |
| 25 float SizesAttributeParser::length() | 26 float SizesAttributeParser::length() |
| 26 { | 27 { |
| 27 if (m_isValid) | 28 if (m_isValid) |
| 28 return effectiveSize(); | 29 return effectiveSize(); |
| 29 return effectiveSizeDefaultValue(); | 30 return effectiveSizeDefaultValue(); |
| 30 } | 31 } |
| 31 | 32 |
| 32 bool SizesAttributeParser::calculateLengthInPixels(CSSParserTokenIterator startT
oken, CSSParserTokenIterator endToken, float& result) | 33 bool SizesAttributeParser::calculateLengthInPixels(CSSParserTokenIterator startT
oken, CSSParserTokenIterator endToken, float& result) |
| 33 { | 34 { |
| 34 if (startToken == endToken) | 35 if (startToken == endToken) |
| 35 return false; | 36 return false; |
| 36 CSSParserTokenType type = startToken->type(); | 37 CSSParserTokenType type = startToken->type(); |
| 37 if (type == DimensionToken) { | 38 if (type == DimensionToken) { |
| 38 double length; | 39 double length; |
| 39 if (!CSSPrimitiveValue::isLength(startToken->unitType())) | 40 if (!CSSPrimitiveValue::isLength(startToken->unitType())) |
| 40 return false; | 41 return false; |
| 41 m_viewportDependant = CSSPrimitiveValue::isViewportPercentageLength(star
tToken->unitType()); | 42 m_viewportDependant = CSSPrimitiveValue::isViewportPercentageLength(star
tToken->unitType()); |
| 42 if ((m_mediaValues->computeLength(startToken->numericValue(), startToken
->unitType(), length)) && (length >= 0)) { | 43 if (!m_viewportDependant || m_hasLocalFrame) { |
| 43 result = clampTo<float>(length); | 44 if ((m_mediaValues->computeLength(startToken->numericValue(), startT
oken->unitType(), length)) && (length >= 0)) { |
| 44 return true; | 45 result = clampTo<float>(length); |
| 46 return true; |
| 47 } |
| 45 } | 48 } |
| 46 } else if (type == FunctionToken) { | 49 } else if (type == FunctionToken) { |
| 47 SizesCalcParser calcParser(startToken, endToken, m_mediaValues); | 50 SizesCalcParser calcParser(startToken, endToken, m_mediaValues); |
| 48 if (!calcParser.isValid()) | 51 if (!calcParser.isValid()) |
| 49 return false; | 52 return false; |
| 50 m_viewportDependant = calcParser.viewportDependant(); | 53 m_viewportDependant = calcParser.viewportDependant(); |
| 51 result = calcParser.result(); | 54 result = calcParser.result(); |
| 52 return true; | 55 return true; |
| 53 } else if (type == NumberToken && !startToken->numericValue()) { | 56 } else if (type == NumberToken && !startToken->numericValue()) { |
| 54 result = 0; | 57 result = 0; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 148 } |
| 146 | 149 |
| 147 unsigned SizesAttributeParser::effectiveSizeDefaultValue() | 150 unsigned SizesAttributeParser::effectiveSizeDefaultValue() |
| 148 { | 151 { |
| 149 // Returning the equivalent of "100vw" | 152 // Returning the equivalent of "100vw" |
| 150 m_viewportDependant = true; | 153 m_viewportDependant = true; |
| 151 return m_mediaValues->viewportWidth(); | 154 return m_mediaValues->viewportWidth(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 } // namespace | 157 } // namespace |
| OLD | NEW |