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

Side by Side Diff: Source/core/html/track/vtt/VTTRegion.cpp

Issue 144893002: Pass a VTTScanner to VTTRegion::parseSettingValue (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: parsedEntireRun helper. Created 6 years, 11 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
« no previous file with comments | « Source/core/html/track/vtt/VTTRegion.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 // Scan the name part. 206 // Scan the name part.
207 RegionSetting name = scanSettingName(input); 207 RegionSetting name = scanSettingName(input);
208 208
209 // Verify that we're looking at a '='. 209 // Verify that we're looking at a '='.
210 if (name == None || !input.scan('=')) { 210 if (name == None || !input.scan('=')) {
211 input.skipUntil<VTTParser::isASpace>(); 211 input.skipUntil<VTTParser::isASpace>();
212 continue; 212 continue;
213 } 213 }
214 214
215 // Scan the value part. 215 // Scan the value part.
216 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isASpace>(); 216 parseSettingValue(name, input);
217 parseSettingValue(name, input.extractString(valueRun));
218 input.skipRun(valueRun);
219 } 217 }
220 } 218 }
221 219
222 VTTRegion::RegionSetting VTTRegion::scanSettingName(VTTScanner& input) 220 VTTRegion::RegionSetting VTTRegion::scanSettingName(VTTScanner& input)
223 { 221 {
224 if (input.scan("id")) 222 if (input.scan("id"))
225 return Id; 223 return Id;
226 if (input.scan("height")) 224 if (input.scan("height"))
227 return Height; 225 return Height;
228 if (input.scan("width")) 226 if (input.scan("width"))
229 return Width; 227 return Width;
230 if (input.scan("viewportanchor")) 228 if (input.scan("viewportanchor"))
231 return ViewportAnchor; 229 return ViewportAnchor;
232 if (input.scan("regionanchor")) 230 if (input.scan("regionanchor"))
233 return RegionAnchor; 231 return RegionAnchor;
234 if (input.scan("scroll")) 232 if (input.scan("scroll"))
235 return Scroll; 233 return Scroll;
236 234
237 return None; 235 return None;
238 } 236 }
239 237
240 void VTTRegion::parseSettingValue(RegionSetting setting, const String& value) 238 static inline bool parsedEntireRun(const VTTScanner& input, const VTTScanner::Ru n& run)
239 {
240 return input.isAt(run.end());
241 }
242
243 void VTTRegion::parseSettingValue(RegionSetting setting, VTTScanner& input)
241 { 244 {
242 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral)); 245 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral));
243 246
247 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isASpace>();
248
244 switch (setting) { 249 switch (setting) {
245 case Id: 250 case Id: {
246 if (value.find("-->") == kNotFound) 251 String stringValue = input.extractString(valueRun);
247 m_id = value; 252 if (stringValue.find("-->") == kNotFound)
253 m_id = stringValue;
248 break; 254 break;
255 }
249 case Width: { 256 case Width: {
250 float floatWidth; 257 float floatWidth;
251 VTTScanner valueScanner(value); 258 if (VTTParser::parseFloatPercentageValue(input, floatWidth) && parsedEnt ireRun(input, valueRun))
252 if (VTTParser::parseFloatPercentageValue(valueScanner, floatWidth) && va lueScanner.isAtEnd())
253 m_width = floatWidth; 259 m_width = floatWidth;
254 else 260 else
255 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Width"); 261 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Width");
256 break; 262 break;
257 } 263 }
258 case Height: { 264 case Height: {
259 int number; 265 int number;
260 VTTScanner valueScanner(value); 266 if (input.scanDigits(number) && parsedEntireRun(input, valueRun))
261 if (valueScanner.scanDigits(number) && valueScanner.isAtEnd())
262 m_heightInLines = number; 267 m_heightInLines = number;
263 else 268 else
264 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Height"); 269 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Height");
265 break; 270 break;
266 } 271 }
267 case RegionAnchor: { 272 case RegionAnchor: {
268 VTTScanner valueScanner(value);
269 FloatPoint anchor; 273 FloatPoint anchor;
270 if (VTTParser::parseFloatPercentageValuePair(valueScanner, ',', anchor) && valueScanner.isAtEnd()) 274 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && pars edEntireRun(input, valueRun))
271 m_regionAnchor = anchor; 275 m_regionAnchor = anchor;
272 else 276 else
273 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid RegionAnchor") ; 277 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid RegionAnchor") ;
274 break; 278 break;
275 } 279 }
276 case ViewportAnchor: { 280 case ViewportAnchor: {
277 VTTScanner valueScanner(value);
278 FloatPoint anchor; 281 FloatPoint anchor;
279 if (VTTParser::parseFloatPercentageValuePair(valueScanner, ',', anchor) && valueScanner.isAtEnd()) 282 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && pars edEntireRun(input, valueRun))
280 m_viewportAnchor = anchor; 283 m_viewportAnchor = anchor;
281 else 284 else
282 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid ViewportAnchor "); 285 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid ViewportAnchor ");
283 break; 286 break;
284 } 287 }
285 case Scroll: 288 case Scroll:
286 if (value == scrollUpValueKeyword) 289 if (input.scanRun(valueRun, scrollUpValueKeyword))
287 m_scroll = true; 290 m_scroll = true;
288 else 291 else
289 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll"); 292 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll");
290 break; 293 break;
291 case None: 294 case None:
292 break; 295 break;
293 } 296 }
297
298 input.skipRun(valueRun);
294 } 299 }
295 300
296 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId() 301 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId()
297 { 302 {
298 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId, 303 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId,
299 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral)); 304 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral));
300 305
301 return trackRegionCueContainerPseudoId; 306 return trackRegionCueContainerPseudoId;
302 } 307 }
303 308
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 465
461 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*) 466 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*)
462 { 467 {
463 WTF_LOG(Media, "VTTRegion::scrollTimerFired"); 468 WTF_LOG(Media, "VTTRegion::scrollTimerFired");
464 469
465 stopTimer(); 470 stopTimer();
466 displayLastVTTCueBox(); 471 displayLastVTTCueBox();
467 } 472 }
468 473
469 } // namespace WebCore 474 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTRegion.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698