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

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

Issue 137033002: Use VTTScanner for VTT region settings parsing (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') | Source/core/html/track/vtt/VTTScanner.h » ('j') | 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 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "core/html/track/vtt/VTTRegion.h" 32 #include "core/html/track/vtt/VTTRegion.h"
33 33
34 #include "bindings/v8/ExceptionMessages.h" 34 #include "bindings/v8/ExceptionMessages.h"
35 #include "bindings/v8/ExceptionState.h" 35 #include "bindings/v8/ExceptionState.h"
36 #include "core/dom/ClientRect.h" 36 #include "core/dom/ClientRect.h"
37 #include "core/dom/DOMTokenList.h" 37 #include "core/dom/DOMTokenList.h"
38 #include "core/html/HTMLDivElement.h" 38 #include "core/html/HTMLDivElement.h"
39 #include "core/html/track/vtt/VTTParser.h" 39 #include "core/html/track/vtt/VTTParser.h"
40 #include "core/html/track/vtt/VTTScanner.h"
40 #include "core/rendering/RenderInline.h" 41 #include "core/rendering/RenderInline.h"
41 #include "core/rendering/RenderObject.h" 42 #include "core/rendering/RenderObject.h"
42 #include "platform/Logging.h" 43 #include "platform/Logging.h"
43 #include "wtf/MathExtras.h" 44 #include "wtf/MathExtras.h"
44 #include "wtf/text/StringBuilder.h" 45 #include "wtf/text/StringBuilder.h"
45 46
46 namespace WebCore { 47 namespace WebCore {
47 48
48 // The following values default values are defined within the WebVTT Regions Spe c. 49 // The following values default values are defined within the WebVTT Regions Spe c.
49 // https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/region.html 50 // https://dvcs.w3.org/hg/text-tracks/raw-file/default/608toVTT/region.html
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 while (position < input.length() && VTTParser::isValidSettingDelimiter(i nput[position])) 200 while (position < input.length() && VTTParser::isValidSettingDelimiter(i nput[position]))
200 position++; 201 position++;
201 202
202 if (position >= input.length()) 203 if (position >= input.length())
203 break; 204 break;
204 205
205 parseSetting(input, &position); 206 parseSetting(input, &position);
206 } 207 }
207 } 208 }
208 209
209 VTTRegion::RegionSetting VTTRegion::getSettingFromString(const String& setting) 210 VTTRegion::RegionSetting VTTRegion::scanSettingName(VTTScanner& input)
210 { 211 {
211 DEFINE_STATIC_LOCAL(const AtomicString, idKeyword, ("id", AtomicString::Cons tructFromLiteral)); 212 if (input.scan("id"))
212 DEFINE_STATIC_LOCAL(const AtomicString, heightKeyword, ("height", AtomicStri ng::ConstructFromLiteral));
213 DEFINE_STATIC_LOCAL(const AtomicString, widthKeyword, ("width", AtomicString ::ConstructFromLiteral));
214 DEFINE_STATIC_LOCAL(const AtomicString, regionAnchorKeyword, ("regionanchor" , AtomicString::ConstructFromLiteral));
215 DEFINE_STATIC_LOCAL(const AtomicString, viewportAnchorKeyword, ("viewportanc hor", AtomicString::ConstructFromLiteral));
216 DEFINE_STATIC_LOCAL(const AtomicString, scrollKeyword, ("scroll", AtomicStri ng::ConstructFromLiteral));
217
218 if (setting == idKeyword)
219 return Id; 213 return Id;
220 if (setting == heightKeyword) 214 if (input.scan("height"))
221 return Height; 215 return Height;
222 if (setting == widthKeyword) 216 if (input.scan("width"))
223 return Width; 217 return Width;
224 if (setting == viewportAnchorKeyword) 218 if (input.scan("viewportanchor"))
225 return ViewportAnchor; 219 return ViewportAnchor;
226 if (setting == regionAnchorKeyword) 220 if (input.scan("regionanchor"))
227 return RegionAnchor; 221 return RegionAnchor;
228 if (setting == scrollKeyword) 222 if (input.scan("scroll"))
229 return Scroll; 223 return Scroll;
230 224
231 return None; 225 return None;
232 } 226 }
233 227
234 void VTTRegion::parseSettingValue(RegionSetting setting, const String& value) 228 void VTTRegion::parseSettingValue(RegionSetting setting, const String& value)
235 { 229 {
236 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral)); 230 DEFINE_STATIC_LOCAL(const AtomicString, scrollUpValueKeyword, ("up", AtomicS tring::ConstructFromLiteral));
237 231
238 switch (setting) { 232 switch (setting) {
(...skipping 30 matching lines...) Expand all
269 if (value == scrollUpValueKeyword) 263 if (value == scrollUpValueKeyword)
270 m_scroll = true; 264 m_scroll = true;
271 else 265 else
272 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll"); 266 WTF_LOG(Media, "VTTRegion::parseSettingValue, invalid Scroll");
273 break; 267 break;
274 case None: 268 case None:
275 break; 269 break;
276 } 270 }
277 } 271 }
278 272
279 void VTTRegion::parseSetting(const String& input, unsigned* position) 273 void VTTRegion::parseSetting(const String& inputString, unsigned* position)
280 { 274 {
281 String setting = VTTParser::collectWord(input, position); 275 VTTLegacyScanner input(inputString, position);
282 276
283 size_t equalOffset = setting.find('=', 1); 277 // Scan the name part.
284 if (equalOffset == kNotFound || !equalOffset || equalOffset == setting.lengt h() - 1) 278 RegionSetting name = scanSettingName(input);
279
280 // Verify that we're looking at a '='.
281 if (!input.scan('=')) {
282 input.skipUntil<VTTParser::isASpace>();
285 return; 283 return;
284 }
286 285
287 RegionSetting name = getSettingFromString(setting.substring(0, equalOffset)) ; 286 // Scan the value part.
288 String value = setting.substring(equalOffset + 1, setting.length() - 1); 287 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isASpace>();
289 288 parseSettingValue(name, input.extractString(valueRun));
290 parseSettingValue(name, value); 289 input.skipRun(valueRun);
291 } 290 }
292 291
293 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId() 292 const AtomicString& VTTRegion::textTrackCueContainerShadowPseudoId()
294 { 293 {
295 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId, 294 DEFINE_STATIC_LOCAL(const AtomicString, trackRegionCueContainerPseudoId,
296 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral)); 295 ("-webkit-media-text-track-region-container", AtomicString::ConstructFro mLiteral));
297 296
298 return trackRegionCueContainerPseudoId; 297 return trackRegionCueContainerPseudoId;
299 } 298 }
300 299
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 456
458 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*) 457 void VTTRegion::scrollTimerFired(Timer<VTTRegion>*)
459 { 458 {
460 WTF_LOG(Media, "VTTRegion::scrollTimerFired"); 459 WTF_LOG(Media, "VTTRegion::scrollTimerFired");
461 460
462 stopTimer(); 461 stopTimer();
463 displayLastVTTCueBox(); 462 displayLastVTTCueBox();
464 } 463 }
465 464
466 } // namespace WebCore 465 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/html/track/vtt/VTTRegion.h ('k') | Source/core/html/track/vtt/VTTScanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698