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) |
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 { | 19 { |
20 CSSTokenizer::tokenize(attribute, m_tokens); | 20 m_isValid = parse(CSSTokenizer::Scope(attribute).tokenRange()); |
21 m_isValid = parse(m_tokens); | |
22 } | 21 } |
23 | 22 |
24 float SizesAttributeParser::length() | 23 float SizesAttributeParser::length() |
25 { | 24 { |
26 if (m_isValid) | 25 if (m_isValid) |
27 return effectiveSize(); | 26 return effectiveSize(); |
28 return effectiveSizeDefaultValue(); | 27 return effectiveSizeDefaultValue(); |
29 } | 28 } |
30 | 29 |
31 bool SizesAttributeParser::calculateLengthInPixels(CSSParserTokenRange range, fl
oat& result) | 30 bool SizesAttributeParser::calculateLengthInPixels(CSSParserTokenRange range, fl
oat& result) |
(...skipping 22 matching lines...) Expand all Loading... |
54 return false; | 53 return false; |
55 } | 54 } |
56 | 55 |
57 bool SizesAttributeParser::mediaConditionMatches(PassRefPtrWillBeRawPtr<MediaQue
rySet> mediaCondition) | 56 bool SizesAttributeParser::mediaConditionMatches(PassRefPtrWillBeRawPtr<MediaQue
rySet> mediaCondition) |
58 { | 57 { |
59 // A Media Condition cannot have a media type other then screen. | 58 // A Media Condition cannot have a media type other then screen. |
60 MediaQueryEvaluator mediaQueryEvaluator(*m_mediaValues); | 59 MediaQueryEvaluator mediaQueryEvaluator(*m_mediaValues); |
61 return mediaQueryEvaluator.eval(mediaCondition.get()); | 60 return mediaQueryEvaluator.eval(mediaCondition.get()); |
62 } | 61 } |
63 | 62 |
64 bool SizesAttributeParser::parse(Vector<CSSParserToken>& tokens) | 63 bool SizesAttributeParser::parse(CSSParserTokenRange range) |
65 { | 64 { |
66 CSSParserTokenRange range(tokens); | |
67 // Split on a comma token and parse the result tokens as (media-condition, l
ength) pairs | 65 // Split on a comma token and parse the result tokens as (media-condition, l
ength) pairs |
68 while (!range.atEnd()) { | 66 while (!range.atEnd()) { |
69 const CSSParserToken* mediaConditionStart = &range.peek(); | 67 const CSSParserToken* mediaConditionStart = &range.peek(); |
70 // The length is the last component value before the comma which isn't w
hitespace or a comment | 68 // The length is the last component value before the comma which isn't w
hitespace or a comment |
71 const CSSParserToken* lengthTokenStart = &range.peek(); | 69 const CSSParserToken* lengthTokenStart = &range.peek(); |
72 const CSSParserToken* lengthTokenEnd = &range.peek(); | 70 const CSSParserToken* lengthTokenEnd = &range.peek(); |
73 while (!range.atEnd() && range.peek().type() != CommaToken) { | 71 while (!range.atEnd() && range.peek().type() != CommaToken) { |
74 lengthTokenStart = &range.peek(); | 72 lengthTokenStart = &range.peek(); |
75 range.consumeComponentValue(); | 73 range.consumeComponentValue(); |
76 lengthTokenEnd = &range.peek(); | 74 lengthTokenEnd = &range.peek(); |
(...skipping 21 matching lines...) Expand all Loading... |
98 return effectiveSizeDefaultValue(); | 96 return effectiveSizeDefaultValue(); |
99 } | 97 } |
100 | 98 |
101 unsigned SizesAttributeParser::effectiveSizeDefaultValue() | 99 unsigned SizesAttributeParser::effectiveSizeDefaultValue() |
102 { | 100 { |
103 // Returning the equivalent of "100vw" | 101 // Returning the equivalent of "100vw" |
104 return m_mediaValues->viewportWidth(); | 102 return m_mediaValues->viewportWidth(); |
105 } | 103 } |
106 | 104 |
107 } // namespace | 105 } // namespace |
OLD | NEW |