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

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: 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 void VTTRegion::parseSettingValue(RegionSetting setting, VTTScanner& input)
241 { 239 {
242 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral)); 240 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral));
243 241
242 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isASpace>();
243
244 switch (setting) { 244 switch (setting) {
245 case Id: 245 case Id: {
246 if (value.find("-->") == kNotFound) 246 String stringValue = input.extractString(valueRun);
247 m_id = value; 247 if (stringValue.find("-->") == kNotFound)
248 m_id = stringValue;
248 break; 249 break;
250 }
249 case Width: { 251 case Width: {
250 float floatWidth; 252 float floatWidth;
251 VTTScanner valueScanner(value); 253 if (VTTParser::parseFloatPercentageValue(input, floatWidth) && input.isA t(valueRun.end()))
Mike West 2014/01/22 10:24:26 Nit: `input.isAt(valueRun.end())` is awkward. You'
fs 2014/01/22 10:29:50 You mean as a local helper? Or on VTTScanner? (I t
252 if (VTTParser::parseFloatPercentageValue(valueScanner, floatWidth) && va lueScanner.isAtEnd())
253 m_width = floatWidth; 254 m_width = floatWidth;
254 else 255 else
255 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Width"); 256 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Width");
256 break; 257 break;
257 } 258 }
258 case Height: { 259 case Height: {
259 int number; 260 int number;
260 VTTScanner valueScanner(value); 261 if (input.scanDigits(number) && input.isAt(valueRun.end()))
261 if (valueScanner.scanDigits(number) && valueScanner.isAtEnd())
262 m_heightInLines = number; 262 m_heightInLines = number;
263 else 263 else
264 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Height"); 264 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Height");
265 break; 265 break;
266 } 266 }
267 case RegionAnchor: { 267 case RegionAnchor: {
268 VTTScanner valueScanner(value);
269 FloatPoint anchor; 268 FloatPoint anchor;
270 if (VTTParser::parseFloatPercentageValuePair(valueScanner, ',', anchor) && valueScanner.isAtEnd()) 269 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && inpu t.isAt(valueRun.end()))
271 m_regionAnchor = anchor; 270 m_regionAnchor = anchor;
272 else 271 else
273 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid RegionAnchor") ; 272 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid RegionAnchor") ;
274 break; 273 break;
275 } 274 }
276 case ViewportAnchor: { 275 case ViewportAnchor: {
277 VTTScanner valueScanner(value);
278 FloatPoint anchor; 276 FloatPoint anchor;
279 if (VTTParser::parseFloatPercentageValuePair(valueScanner, ',', anchor) && valueScanner.isAtEnd()) 277 if (VTTParser::parseFloatPercentageValuePair(input, ',', anchor) && inpu t.isAt(valueRun.end()))
280 m_viewportAnchor = anchor; 278 m_viewportAnchor = anchor;
281 else 279 else
282 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid ViewportAnchor "); 280 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid ViewportAnchor ");
283 break; 281 break;
284 } 282 }
285 case Scroll: 283 case Scroll:
286 if (value == scrollUpValueKeyword) 284 if (input.scanRun(valueRun, scrollUpValueKeyword))
287 m_scroll = true; 285 m_scroll = true;
288 else 286 else
289 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll"); 287 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll");
290 break; 288 break;
291 case None: 289 case None:
292 break; 290 break;
293 } 291 }
292
293 input.skipRun(valueRun);
294 } 294 }
295 295
296 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId() 296 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId()
297 { 297 {
298 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId, 298 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId,
299 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral)); 299 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral));
300 300
301 return trackRegionCueContainerPseudoId; 301 return trackRegionCueContainerPseudoId;
302 } 302 }
303 303
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 460
461 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*) 461 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*)
462 { 462 {
463 WTF_LOG(Media, "VTTRegion::scrollTimerFired"); 463 WTF_LOG(Media, "VTTRegion::scrollTimerFired");
464 464
465 stopTimer(); 465 stopTimer();
466 displayLastVTTCueBox(); 466 displayLastVTTCueBox();
467 } 467 }
468 468
469 } // namespace WebCore 469 } // 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