OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 else if (input.scan("align")) | 961 else if (input.scan("align")) |
962 parsedSetting = Align; | 962 parsedSetting = Align; |
963 else if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && input.scan("regio
n")) | 963 else if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && input.scan("regio
n")) |
964 parsedSetting = RegionId; | 964 parsedSetting = RegionId; |
965 // Verify that a ':' follows. | 965 // Verify that a ':' follows. |
966 if (parsedSetting != None && input.scan(':')) | 966 if (parsedSetting != None && input.scan(':')) |
967 return parsedSetting; | 967 return parsedSetting; |
968 return None; | 968 return None; |
969 } | 969 } |
970 | 970 |
971 // Used for 'position' and 'size'. | 971 static bool scanPercentage(VTTScanner& input, float& number) |
972 static bool scanPercentage(VTTScanner& input, const VTTScanner::Run& valueRun, i
nt& number) | |
973 { | 972 { |
974 // 1. If value contains any characters other than U+0025 PERCENT SIGN | 973 // http://dev.w3.org/html5/webvtt/#dfn-parse-a-percentage-string |
975 // characters (%) and characters in the range U+0030 DIGIT ZERO (0) to | |
976 // U+0039 DIGIT NINE (9), then jump to the step labeled next setting. | |
977 // 2. If value does not contain at least one character in the range U+0030 | |
978 // DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jump to the step | |
979 // labeled next setting. | |
980 if (!input.scanDigits(number)) | |
981 return false; | |
982 | 974 |
983 // 3. If any character in value other than the last character is a U+0025 | 975 // 1. Let input be the string being parsed. |
984 // PERCENT SIGN character (%), then jump to the step labeled next | 976 // 2. If input contains any characters other than U+0025 PERCENT SIGN |
985 // setting. | 977 // characters (%), U+002E DOT characters (.) and ASCII digits, then |
986 // 4. If the last character in value is not a U+0025 PERCENT SIGN character | 978 // fail. |
987 // (%), then jump to the step labeled next setting. | 979 // 3. If input does not contain at least one ASCII digit, then fail. |
988 if (!input.scan('%') || !input.isAt(valueRun.end())) | 980 // 4. If input contains more than one U+002E DOT character (.), then fail. |
989 return false; | 981 // 5. If any character in input other than the last character is a U+0025 |
990 | 982 // PERCENT SIGN character (%), then fail. |
991 // 5. Ignoring the trailing percent sign, interpret value as an integer, | 983 // 6. If the last character in input is not a U+0025 PERCENT SIGN character |
992 // and let number be that number. | 984 // (%), then fail. |
993 // 6. If number is not in the range 0 ≤ number ≤ 100, then jump to the step | 985 // 7. Ignoring the trailing percent sign, interpret input as a real |
994 // labeled next setting. | 986 // number. Let that number be the percentage. |
995 return number >= 0 && number <= 100; | 987 // 8. If percentage is outside the range 0..100, then fail. |
| 988 // 9. Return percentage. |
| 989 return input.scanPercentage(number) && !isInvalidPercentage(number); |
996 } | 990 } |
997 | 991 |
998 void VTTCue::parseSettings(const String& inputString) | 992 void VTTCue::parseSettings(const String& inputString) |
999 { | 993 { |
1000 VTTScanner input(inputString); | 994 VTTScanner input(inputString); |
1001 | 995 |
1002 while (!input.isAtEnd()) { | 996 while (!input.isAtEnd()) { |
1003 | 997 |
1004 // The WebVTT cue settings part of a WebVTT cue consists of zero or more
of the following components, in any order, | 998 // The WebVTT cue settings part of a WebVTT cue consists of zero or more
of the following components, in any order, |
1005 // separated from each other by one or more U+0020 SPACE characters or U
+0009 CHARACTER TABULATION (tab) characters. | 999 // separated from each other by one or more U+0020 SPACE characters or U
+0009 CHARACTER TABULATION (tab) characters. |
(...skipping 11 matching lines...) Expand all Loading... |
1017 // 2. Let name be the leading substring of setting up to and excludin
g the first U+003A COLON character (:) in that string. | 1011 // 2. Let name be the leading substring of setting up to and excludin
g the first U+003A COLON character (:) in that string. |
1018 CueSetting name = settingName(input); | 1012 CueSetting name = settingName(input); |
1019 | 1013 |
1020 // 3. Let value be the trailing substring of setting starting from the c
haracter immediately after the first U+003A COLON character (:) in that string. | 1014 // 3. Let value be the trailing substring of setting starting from the c
haracter immediately after the first U+003A COLON character (:) in that string. |
1021 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isValidSettingD
elimiter>(); | 1015 VTTScanner::Run valueRun = input.collectUntil<VTTParser::isValidSettingD
elimiter>(); |
1022 | 1016 |
1023 // 4. Run the appropriate substeps that apply for the value of name, as
follows: | 1017 // 4. Run the appropriate substeps that apply for the value of name, as
follows: |
1024 switch (name) { | 1018 switch (name) { |
1025 case Vertical: { | 1019 case Vertical: { |
1026 // If name is a case-sensitive match for "vertical" | 1020 // If name is a case-sensitive match for "vertical" |
1027 // 1. If value is a case-sensitive match for the string "rl", then l
et cue's text track cue writing direction | 1021 // 1. If value is a case-sensitive match for the string "rl", then |
1028 // be vertical growing left. | 1022 // let cue's text track cue writing direction be vertical |
| 1023 // growing left. |
1029 if (input.scanRun(valueRun, verticalGrowingLeftKeyword())) | 1024 if (input.scanRun(valueRun, verticalGrowingLeftKeyword())) |
1030 m_writingDirection = VerticalGrowingLeft; | 1025 m_writingDirection = VerticalGrowingLeft; |
1031 | 1026 |
1032 // 2. Otherwise, if value is a case-sensitive match for the string "
lr", then let cue's text track cue writing | 1027 // 2. Otherwise, if value is a case-sensitive match for the string |
1033 // direction be vertical growing right. | 1028 // "lr", then let cue's text track cue writing direction be |
| 1029 // vertical growing right. |
1034 else if (input.scanRun(valueRun, verticalGrowingRightKeyword())) | 1030 else if (input.scanRun(valueRun, verticalGrowingRightKeyword())) |
1035 m_writingDirection = VerticalGrowingRight; | 1031 m_writingDirection = VerticalGrowingRight; |
1036 break; | 1032 break; |
1037 } | 1033 } |
1038 case Line: { | 1034 case Line: { |
1039 // 1-2 - Collect chars that are either '-', '%', or a digit. | 1035 // If name is a case-sensitive match for "line" |
1040 // 1. If value contains any characters other than U+002D HYPHEN-MINU
S characters (-), U+0025 PERCENT SIGN | 1036 // Steps 1 - 2 skipped. |
1041 // characters (%), and characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9), then jump | 1037 float number; |
1042 // to the step labeled next setting. | 1038 // 3. If linepos does not contain at least one ASCII digit, then |
1043 bool isNegative = input.scan('-'); | 1039 // jump to the step labeled next setting. |
1044 int linePosition; | 1040 // 4. If the last character in linepos is a U+0025 PERCENT SIGN char
acter (%) |
1045 unsigned numDigits = input.scanDigits(linePosition); | 1041 // |
1046 bool isPercentage = input.scan('%'); | 1042 // If parse a percentage string from linepos doesn't fail, let |
1047 | 1043 // number be the returned percentage, otherwise jump to the step |
| 1044 // labeled next setting. |
| 1045 bool isPercentage = scanPercentage(input, number); |
| 1046 if (!isPercentage) { |
| 1047 // Otherwise |
| 1048 // |
| 1049 // 1. If linepos contains any characters other than U+002D |
| 1050 // HYPHEN-MINUS characters (-) and ASCII digits, then jump to |
| 1051 // the step labeled next setting. |
| 1052 // 2. If any character in linepos other than the first character
is |
| 1053 // a U+002D HYPHEN-MINUS character (-), then jump to the step |
| 1054 // labeled next setting. |
| 1055 bool isNegative = input.scan('-'); |
| 1056 int intLinePosition; |
| 1057 if (!input.scanDigits(intLinePosition)) |
| 1058 break; |
| 1059 // 3. Interpret linepos as a (potentially signed) integer, and l
et |
| 1060 // number be that number. |
| 1061 number = isNegative ? -intLinePosition : intLinePosition; |
| 1062 } |
1048 if (!input.isAt(valueRun.end())) | 1063 if (!input.isAt(valueRun.end())) |
1049 break; | 1064 break; |
1050 | 1065 // 5. Let cue's text track cue line position be number. |
1051 // 2. If value does not contain at least one character in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT | 1066 m_linePosition = number; |
1052 // NINE (9), then jump to the step labeled next setting. | 1067 // 6. If the last character in linepos is a U+0025 PERCENT SIGN |
1053 // 3. If any character in value other than the first character is a
U+002D HYPHEN-MINUS character (-), then | 1068 // character (%), then let cue's text track cue snap-to-lines |
1054 // jump to the step labeled next setting. | 1069 // flag be false. Otherwise, let it be true. |
1055 // 4. If any character in value other than the last character is a U
+0025 PERCENT SIGN character (%), then | 1070 m_snapToLines = !isPercentage; |
1056 // jump to the step labeled next setting. | 1071 // Steps 7 - 9 skipped. |
1057 | |
1058 // 5. If the first character in value is a U+002D HYPHEN-MINUS chara
cter (-) and the last character in value is a | |
1059 // U+0025 PERCENT SIGN character (%), then jump to the step label
ed next setting. | |
1060 if (!numDigits || (isPercentage && isNegative)) | |
1061 break; | |
1062 | |
1063 // 6. Ignoring the trailing percent sign, if any, interpret value as
a (potentially signed) integer, and | |
1064 // let number be that number. | |
1065 // 7. If the last character in value is a U+0025 PERCENT SIGN charac
ter (%), but number is not in the range | |
1066 // 0 ≤ number ≤ 100, then jump to the step labeled next setting. | |
1067 // 8. Let cue's text track cue line position be number. | |
1068 // 9. If the last character in value is a U+0025 PERCENT SIGN charac
ter (%), then let cue's text track cue | |
1069 // snap-to-lines flag be false. Otherwise, let it be true. | |
1070 if (isPercentage) { | |
1071 if (linePosition < 0 || linePosition > 100) | |
1072 break; | |
1073 // 10 - If '%' then set snap-to-lines flag to false. | |
1074 m_snapToLines = false; | |
1075 } else { | |
1076 if (isNegative) | |
1077 linePosition = -linePosition; | |
1078 m_snapToLines = true; | |
1079 } | |
1080 m_linePosition = linePosition; | |
1081 break; | 1072 break; |
1082 } | 1073 } |
1083 case Position: { | 1074 case Position: { |
1084 int number; | 1075 // If name is a case-sensitive match for "position". |
1085 // Steps 1 - 6. | 1076 float number; |
1086 if (!scanPercentage(input, valueRun, number)) | 1077 // Steps 1 - 2 skipped. |
| 1078 // 3. If parse a percentage string from colpos doesn't fail, let |
| 1079 // number be the returned percentage, otherwise jump to the step |
| 1080 // labeled next setting (text track cue text position's value |
| 1081 // remains the special value auto). |
| 1082 if (!scanPercentage(input, number)) |
1087 break; | 1083 break; |
1088 | 1084 if (!input.isAt(valueRun.end())) |
1089 // 7. Let cue's text track cue text position be number. | 1085 break; |
| 1086 // 4. Let cue's text track cue text position be number. |
1090 m_textPosition = number; | 1087 m_textPosition = number; |
| 1088 // Steps 5 - 7 skipped. |
1091 break; | 1089 break; |
1092 } | 1090 } |
1093 case Size: { | 1091 case Size: { |
1094 int number; | 1092 // If name is a case-sensitive match for "size" |
1095 // Steps 1 - 6. | 1093 float number; |
1096 if (!scanPercentage(input, valueRun, number)) | 1094 // 1. If parse a percentage string from value doesn't fail, let |
| 1095 // number be the returned percentage, otherwise jump to the step |
| 1096 // labeled next setting. |
| 1097 if (!scanPercentage(input, number)) |
1097 break; | 1098 break; |
1098 | 1099 if (!input.isAt(valueRun.end())) |
1099 // 7. Let cue's text track cue size be number. | 1100 break; |
| 1101 // 2. Let cue's text track cue size be number. |
1100 m_cueSize = number; | 1102 m_cueSize = number; |
1101 break; | 1103 break; |
1102 } | 1104 } |
1103 case Align: { | 1105 case Align: { |
1104 // 1. If value is a case-sensitive match for the string "start", the
n let cue's text track cue alignment be start alignment. | 1106 // If name is a case-sensitive match for "align" |
| 1107 // 1. If value is a case-sensitive match for the string "start", |
| 1108 // then let cue's text track cue alignment be start alignment. |
1105 if (input.scanRun(valueRun, startKeyword())) | 1109 if (input.scanRun(valueRun, startKeyword())) |
1106 m_cueAlignment = Start; | 1110 m_cueAlignment = Start; |
1107 | 1111 |
1108 // 2. If value is a case-sensitive match for the string "middle", th
en let cue's text track cue alignment be middle alignment. | 1112 // 2. If value is a case-sensitive match for the string "middle", |
| 1113 // then let cue's text track cue alignment be middle alignment. |
1109 else if (input.scanRun(valueRun, middleKeyword())) | 1114 else if (input.scanRun(valueRun, middleKeyword())) |
1110 m_cueAlignment = Middle; | 1115 m_cueAlignment = Middle; |
1111 | 1116 |
1112 // 3. If value is a case-sensitive match for the string "end", then
let cue's text track cue alignment be end alignment. | 1117 // 3. If value is a case-sensitive match for the string "end", then |
| 1118 // let cue's text track cue alignment be end alignment. |
1113 else if (input.scanRun(valueRun, endKeyword())) | 1119 else if (input.scanRun(valueRun, endKeyword())) |
1114 m_cueAlignment = End; | 1120 m_cueAlignment = End; |
1115 | 1121 |
1116 // 4. If value is a case-sensitive match for the string "left", then
let cue's text track cue alignment be left alignment. | 1122 // 4. If value is a case-sensitive match for the string "left", |
| 1123 // then let cue's text track cue alignment be left alignment. |
1117 else if (input.scanRun(valueRun, leftKeyword())) | 1124 else if (input.scanRun(valueRun, leftKeyword())) |
1118 m_cueAlignment = Left; | 1125 m_cueAlignment = Left; |
1119 | 1126 |
1120 // 5. If value is a case-sensitive match for the string "right", the
n let cue's text track cue alignment be right alignment. | 1127 // 5. If value is a case-sensitive match for the string "right", |
| 1128 // then let cue's text track cue alignment be right alignment. |
1121 else if (input.scanRun(valueRun, rightKeyword())) | 1129 else if (input.scanRun(valueRun, rightKeyword())) |
1122 m_cueAlignment = Right; | 1130 m_cueAlignment = Right; |
1123 break; | 1131 break; |
1124 } | 1132 } |
1125 case RegionId: | 1133 case RegionId: |
1126 m_regionId = input.extractString(valueRun); | 1134 m_regionId = input.extractString(valueRun); |
1127 break; | 1135 break; |
1128 case None: | 1136 case None: |
1129 break; | 1137 break; |
1130 } | 1138 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1186 | 1194 |
1187 void VTTCue::trace(Visitor* visitor) | 1195 void VTTCue::trace(Visitor* visitor) |
1188 { | 1196 { |
1189 visitor->trace(m_vttNodeTree); | 1197 visitor->trace(m_vttNodeTree); |
1190 visitor->trace(m_cueBackgroundBox); | 1198 visitor->trace(m_cueBackgroundBox); |
1191 visitor->trace(m_displayTree); | 1199 visitor->trace(m_displayTree); |
1192 TextTrackCue::trace(visitor); | 1200 TextTrackCue::trace(visitor); |
1193 } | 1201 } |
1194 | 1202 |
1195 } // namespace blink | 1203 } // namespace blink |
OLD | NEW |