Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "SizesAttributeParser.h" | |
| 7 | |
| 8 #include "core/css/MediaQueryEvaluator.h" | |
| 9 #include "core/css/parser/MediaQueryTokenizer.h" | |
| 10 | |
| 11 namespace WebCore { | |
| 12 | |
| 13 enum { EffectiveSizeDefaultValue = 300 }; | |
|
eseidel
2014/04/08 06:02:14
I know you were encouraged to do these as Enums be
rune
2014/04/08 10:34:42
That would have been me. I based it on how it's mo
| |
| 14 | |
| 15 int SizesAttributeParser::findEffectiveSize(const String& attribute, PassRefPtr< MediaValues> mediaValues) | |
| 16 { | |
| 17 Vector<MediaQueryToken> tokens; | |
| 18 SizesAttributeParser parser(mediaValues); | |
| 19 | |
| 20 MediaQueryTokenizer::tokenize(attribute, tokens); | |
| 21 if (!parser.parseImpl(tokens)) | |
|
eseidel
2014/04/08 06:02:14
Why parseImpl and not just parse?
| |
| 22 return EffectiveSizeDefaultValue; | |
| 23 return parser.effectiveSize(); | |
| 24 } | |
| 25 | |
| 26 int SizesAttributeParser::calculateLengthInPixels(TokenIterator startToken, Toke nIterator endToken) | |
| 27 { | |
| 28 // FIXME - make this actually do something! | |
| 29 return 0; | |
| 30 } | |
| 31 | |
| 32 static void goBackWhileWhitespaceToken(TokenIterator& token, TokenIterator start Token) | |
|
eseidel
2014/04/08 06:02:14
Other parser have used:
template<type UntilFuncti
| |
| 33 { | |
| 34 while (token != startToken && token->type() == WhitespaceToken) | |
| 35 --token; | |
| 36 } | |
| 37 | |
| 38 static void goBackUntilWhitespaceToken(TokenIterator& token, TokenIterator start Token) | |
| 39 { | |
| 40 while (token != startToken && token->type() != WhitespaceToken) | |
| 41 --token; | |
| 42 } | |
| 43 | |
| 44 bool SizesAttributeParser::mediaConditionMatches(PassRefPtr<MediaQuerySet> media Condition) | |
| 45 { | |
| 46 // FIXME: How do I handle non-screen media types here? | |
| 47 // FIXME2: Replaces "screen" with a static string | |
| 48 MediaQueryEvaluator mediaQueryEvaluator("screen", m_mediaValues); | |
|
eseidel
2014/04/08 06:02:14
IIRC you have some StaticStrings for media types,
| |
| 49 return mediaQueryEvaluator.eval(mediaCondition.get()); | |
| 50 } | |
| 51 | |
| 52 bool SizesAttributeParser::parseMediaConditionAndLength(TokenIterator startToken , TokenIterator endToken) | |
| 53 { | |
| 54 TokenIterator lengthTokenStart; | |
| 55 TokenIterator lengthTokenEnd; | |
| 56 | |
| 57 goBackWhileWhitespaceToken(endToken, startToken); | |
|
eseidel
2014/04/08 06:02:14
I see, so these would be "reverseFind" in a string
| |
| 58 lengthTokenEnd = endToken; | |
| 59 goBackUntilWhitespaceToken(endToken, startToken); | |
| 60 lengthTokenStart = endToken; | |
| 61 ++lengthTokenStart; | |
| 62 int length = calculateLengthInPixels(lengthTokenStart, lengthTokenEnd); | |
| 63 RefPtr<MediaQuerySet> mediaCondition = MediaQueryParser::parseMediaCondition (startToken, endToken); | |
| 64 if (!mediaCondition || mediaCondition->queryVector().isEmpty()) | |
| 65 m_defaultLength = length; | |
| 66 else if (mediaConditionMatches(mediaCondition)) | |
| 67 m_length = length; | |
| 68 else | |
| 69 return false; | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 bool SizesAttributeParser::parseImpl(Vector<MediaQueryToken>& tokens) | |
| 74 { | |
| 75 TokenIterator startToken = tokens.begin(); | |
| 76 TokenIterator endToken; | |
| 77 // Split on a comma token, and send the result tokens to be parsed as (media -condition, length) pairs | |
| 78 for (TokenIterator token = tokens.begin(); token != tokens.end(); ++token) { | |
| 79 if (token->type() == CommaToken) { | |
| 80 endToken = token; | |
| 81 --endToken; | |
| 82 if (parseMediaConditionAndLength(startToken, endToken)) | |
| 83 return true; | |
| 84 startToken = token; | |
| 85 ++startToken; | |
| 86 } | |
| 87 } | |
| 88 return parseMediaConditionAndLength(startToken, tokens.end()); | |
| 89 } | |
| 90 | |
| 91 int SizesAttributeParser::effectiveSize() | |
| 92 { | |
| 93 // FIXME - implement the "find effective size" algorithm! | |
| 94 return 0; | |
| 95 } | |
| 96 | |
| 97 } // namespace | |
| 98 | |
| OLD | NEW |