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

Side by Side Diff: third_party/WebKit/Source/core/css/parser/SizesAttributeParser.cpp

Issue 1858753003: Remove RawPtr from core/css (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
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 "core/css/parser/SizesAttributeParser.h" 5 #include "core/css/parser/SizesAttributeParser.h"
6 6
7 #include "core/MediaTypeNames.h" 7 #include "core/MediaTypeNames.h"
8 #include "core/css/MediaQueryEvaluator.h" 8 #include "core/css/MediaQueryEvaluator.h"
9 #include "core/css/parser/CSSTokenizer.h" 9 #include "core/css/parser/CSSTokenizer.h"
10 #include "core/css/parser/SizesCalcParser.h" 10 #include "core/css/parser/SizesCalcParser.h"
11 11
12 namespace blink { 12 namespace blink {
13 13
14 SizesAttributeParser::SizesAttributeParser(RawPtr<MediaValues> mediaValues, cons t String& attribute) 14 SizesAttributeParser::SizesAttributeParser(MediaValues* mediaValues, const Strin g& attribute)
15 : m_mediaValues(mediaValues) 15 : m_mediaValues(mediaValues)
16 , m_length(0) 16 , m_length(0)
17 , m_lengthWasSet(false) 17 , m_lengthWasSet(false)
18 { 18 {
19 ASSERT(m_mediaValues.get()); 19 ASSERT(m_mediaValues.get());
20 m_isValid = parse(CSSTokenizer::Scope(attribute).tokenRange()); 20 m_isValid = parse(CSSTokenizer::Scope(attribute).tokenRange());
21 } 21 }
22 22
23 float SizesAttributeParser::length() 23 float SizesAttributeParser::length()
24 { 24 {
(...skipping 21 matching lines...) Expand all
46 result = calcParser.result(); 46 result = calcParser.result();
47 return true; 47 return true;
48 } else if (type == NumberToken && !startToken.numericValue()) { 48 } else if (type == NumberToken && !startToken.numericValue()) {
49 result = 0; 49 result = 0;
50 return true; 50 return true;
51 } 51 }
52 52
53 return false; 53 return false;
54 } 54 }
55 55
56 bool SizesAttributeParser::mediaConditionMatches(RawPtr<MediaQuerySet> mediaCond ition) 56 bool SizesAttributeParser::mediaConditionMatches(MediaQuerySet* mediaCondition)
57 { 57 {
58 // A Media Condition cannot have a media type other then screen. 58 // A Media Condition cannot have a media type other then screen.
59 MediaQueryEvaluator mediaQueryEvaluator(*m_mediaValues); 59 MediaQueryEvaluator mediaQueryEvaluator(*m_mediaValues);
60 return mediaQueryEvaluator.eval(mediaCondition.get()); 60 return mediaQueryEvaluator.eval(mediaCondition);
61 } 61 }
62 62
63 bool SizesAttributeParser::parse(CSSParserTokenRange range) 63 bool SizesAttributeParser::parse(CSSParserTokenRange range)
64 { 64 {
65 // 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
66 while (!range.atEnd()) { 66 while (!range.atEnd()) {
67 const CSSParserToken* mediaConditionStart = &range.peek(); 67 const CSSParserToken* mediaConditionStart = &range.peek();
68 // 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
69 const CSSParserToken* lengthTokenStart = &range.peek(); 69 const CSSParserToken* lengthTokenStart = &range.peek();
70 const CSSParserToken* lengthTokenEnd = &range.peek(); 70 const CSSParserToken* lengthTokenEnd = &range.peek();
71 while (!range.atEnd() && range.peek().type() != CommaToken) { 71 while (!range.atEnd() && range.peek().type() != CommaToken) {
72 lengthTokenStart = &range.peek(); 72 lengthTokenStart = &range.peek();
73 range.consumeComponentValue(); 73 range.consumeComponentValue();
74 lengthTokenEnd = &range.peek(); 74 lengthTokenEnd = &range.peek();
75 range.consumeWhitespace(); 75 range.consumeWhitespace();
76 } 76 }
77 range.consume(); 77 range.consume();
78 78
79 float length; 79 float length;
80 if (!calculateLengthInPixels(range.makeSubRange(lengthTokenStart, length TokenEnd), length)) 80 if (!calculateLengthInPixels(range.makeSubRange(lengthTokenStart, length TokenEnd), length))
81 continue; 81 continue;
82 RawPtr<MediaQuerySet> mediaCondition = MediaQueryParser::parseMediaCondi tion(range.makeSubRange(mediaConditionStart, lengthTokenStart)); 82 MediaQuerySet* mediaCondition = MediaQueryParser::parseMediaCondition(ra nge.makeSubRange(mediaConditionStart, lengthTokenStart));
83 if (!mediaCondition || !mediaConditionMatches(mediaCondition)) 83 if (!mediaCondition || !mediaConditionMatches(mediaCondition))
84 continue; 84 continue;
85 m_length = length; 85 m_length = length;
86 m_lengthWasSet = true; 86 m_lengthWasSet = true;
87 return true; 87 return true;
88 } 88 }
89 return false; 89 return false;
90 } 90 }
91 91
92 float SizesAttributeParser::effectiveSize() 92 float SizesAttributeParser::effectiveSize()
93 { 93 {
94 if (m_lengthWasSet) 94 if (m_lengthWasSet)
95 return m_length; 95 return m_length;
96 return effectiveSizeDefaultValue(); 96 return effectiveSizeDefaultValue();
97 } 97 }
98 98
99 unsigned SizesAttributeParser::effectiveSizeDefaultValue() 99 unsigned SizesAttributeParser::effectiveSizeDefaultValue()
100 { 100 {
101 // Returning the equivalent of "100vw" 101 // Returning the equivalent of "100vw"
102 return m_mediaValues->viewportWidth(); 102 return m_mediaValues->viewportWidth();
103 } 103 }
104 104
105 } // namespace blink 105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698