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

Unified Diff: Source/core/css/parser/MediaQueryParser.cpp

Issue 217423005: Get Media Query parser to handle parens, brackets and braces blocks correctly (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed algorithm and more tests Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/css/parser/MediaQueryParser.h ('k') | Source/core/css/parser/MediaQueryToken.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/css/parser/MediaQueryParser.cpp
diff --git a/Source/core/css/parser/MediaQueryParser.cpp b/Source/core/css/parser/MediaQueryParser.cpp
index a4afb61bc34c592f2bb66661b740e6d19a0a0ce5..a115335275a5ac9bbc06e72be309a96c55111c5e 100644
--- a/Source/core/css/parser/MediaQueryParser.cpp
+++ b/Source/core/css/parser/MediaQueryParser.cpp
@@ -25,7 +25,7 @@ const MediaQueryParser::State MediaQueryParser::ReadFeatureColon = &MediaQueryPa
const MediaQueryParser::State MediaQueryParser::ReadFeatureValue = &MediaQueryParser::readFeatureValue;
const MediaQueryParser::State MediaQueryParser::ReadFeatureEnd = &MediaQueryParser::readFeatureEnd;
const MediaQueryParser::State MediaQueryParser::SkipUntilComma = &MediaQueryParser::skipUntilComma;
-const MediaQueryParser::State MediaQueryParser::SkipUntilParenthesis = &MediaQueryParser::skipUntilParenthesis;
+const MediaQueryParser::State MediaQueryParser::SkipUntilBlockEnd = &MediaQueryParser::skipUntilBlockEnd;
const MediaQueryParser::State MediaQueryParser::Done = &MediaQueryParser::done;
// FIXME: Replace the MediaQueryTokenizer with a generic CSSTokenizer, once there is one,
@@ -111,7 +111,7 @@ void MediaQueryParser::readFeatureColon(MediaQueryTokenType type, TokenIterator&
--token;
m_state = ReadFeatureEnd;
} else {
- m_state = SkipUntilParenthesis;
+ m_state = SkipUntilBlockEnd;
}
}
@@ -136,7 +136,7 @@ void MediaQueryParser::readFeatureEnd(MediaQueryTokenType type, TokenIterator& t
m_mediaQueryData.addParserValue(type, *token);
m_state = ReadFeatureValue;
} else {
- m_state = SkipUntilParenthesis;
+ m_state = SkipUntilBlockEnd;
}
}
@@ -149,18 +149,42 @@ void MediaQueryParser::skipUntilComma(MediaQueryTokenType type, TokenIterator& t
}
}
-void MediaQueryParser::skipUntilParenthesis(MediaQueryTokenType type, TokenIterator& token)
+void MediaQueryParser::skipUntilBlockEnd(MediaQueryTokenType type, TokenIterator& token)
{
- if (type == RightParenthesisToken)
+ if (m_blockStack.isEmpty())
m_state = SkipUntilComma;
}
void MediaQueryParser::done(MediaQueryTokenType type, TokenIterator& token) { }
+void MediaQueryParser::observeBlocks(MediaQueryTokenType type)
+{
+ if (type == LeftParenthesisToken) {
+ m_blockStack.append(ParenthesisBlock);
+ } else if (type == RightParenthesisToken) {
+ if (!m_blockStack.isEmpty() && m_blockStack.last() == ParenthesisBlock)
eseidel 2014/03/31 16:05:34 These ifs are the same for each block type. I wou
+ m_blockStack.removeLast();
+ } else if (type == LeftBracketToken) {
+ m_state = SkipUntilBlockEnd;
+ m_blockStack.append(BracketsBlock);
+ } else if (type == RightBracketToken) {
+ if (!m_blockStack.isEmpty() && m_blockStack.last() == BracketsBlock)
+ m_blockStack.removeLast();
+ } else if (type == LeftBraceToken) {
+ m_state = SkipUntilBlockEnd;
+ m_blockStack.append(BracesBlock);
+ } else if (type == RightBraceToken) {
+ if (!m_blockStack.isEmpty() && m_blockStack.last() == BracesBlock)
+ m_blockStack.removeLast();
+ }
+}
+
void MediaQueryParser::processToken(TokenIterator& token)
{
MediaQueryTokenType type = token->type();
+ observeBlocks(type);
eseidel 2014/03/31 16:05:34 Why have it be a separate function? Why not just
+
// Call the function that handles current state
if (type != WhitespaceToken && type != CommentToken)
((this)->*(m_state))(type, token);
« no previous file with comments | « Source/core/css/parser/MediaQueryParser.h ('k') | Source/core/css/parser/MediaQueryToken.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698