| 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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 if (name == sizeKeyword) | 851 if (name == sizeKeyword) |
| 852 return Size; | 852 return Size; |
| 853 if (name == alignKeyword) | 853 if (name == alignKeyword) |
| 854 return Align; | 854 return Align; |
| 855 if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && name == regionIdKeywor
d) | 855 if (RuntimeEnabledFeatures::webVTTRegionsEnabled() && name == regionIdKeywor
d) |
| 856 return RegionId; | 856 return RegionId; |
| 857 | 857 |
| 858 return None; | 858 return None; |
| 859 } | 859 } |
| 860 | 860 |
| 861 // Used for 'position' and 'size'. |
| 862 static bool scanPercentage(const String& input, unsigned* position, int& number) |
| 863 { |
| 864 ASSERT(position); |
| 865 // 1. If value contains any characters other than U+0025 PERCENT SIGN |
| 866 // characters (%) and characters in the range U+0030 DIGIT ZERO (0) to |
| 867 // U+0039 DIGIT NINE (9), then jump to the step labeled next setting. |
| 868 // 2. If value does not contain at least one character in the range U+0030 |
| 869 // DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jump to the step |
| 870 // labeled next setting. |
| 871 if (!VTTParser::collectDigitsToInt(input, position, number)) |
| 872 return false; |
| 873 if (*position >= input.length()) |
| 874 return false; |
| 875 |
| 876 // 3. If any character in value other than the last character is a U+0025 |
| 877 // PERCENT SIGN character (%), then jump to the step labeled next |
| 878 // setting. |
| 879 // 4. If the last character in value is not a U+0025 PERCENT SIGN character |
| 880 // (%), then jump to the step labeled next setting. |
| 881 if (input[(*position)++] != '%') |
| 882 return false; |
| 883 if (*position < input.length() && !VTTParser::isValidSettingDelimiter(input[
*position])) |
| 884 return false; |
| 885 |
| 886 // 5. Ignoring the trailing percent sign, interpret value as an integer, |
| 887 // and let number be that number. |
| 888 // 6. If number is not in the range 0 ≤ number ≤ 100, then jump to the step |
| 889 // labeled next setting. |
| 890 return number >= 0 && number <= 100; |
| 891 } |
| 892 |
| 861 void VTTCue::parseSettings(const String& input) | 893 void VTTCue::parseSettings(const String& input) |
| 862 { | 894 { |
| 863 unsigned position = 0; | 895 unsigned position = 0; |
| 864 | 896 |
| 865 while (position < input.length()) { | 897 while (position < input.length()) { |
| 866 | 898 |
| 867 // The WebVTT cue settings part of a WebVTT cue consists of zero or more
of the following components, in any order, | 899 // The WebVTT cue settings part of a WebVTT cue consists of zero or more
of the following components, in any order, |
| 868 // separated from each other by one or more U+0020 SPACE characters or U
+0009 CHARACTER TABULATION (tab) characters. | 900 // separated from each other by one or more U+0020 SPACE characters or U
+0009 CHARACTER TABULATION (tab) characters. |
| 869 while (position < input.length() && VTTParser::isValidSettingDelimiter(i
nput[position])) | 901 while (position < input.length() && VTTParser::isValidSettingDelimiter(i
nput[position])) |
| 870 position++; | 902 position++; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 887 // 2. Let name be the leading substring of setting up to and excluding t
he first U+003A COLON character (:) in that string. | 919 // 2. Let name be the leading substring of setting up to and excluding t
he first U+003A COLON character (:) in that string. |
| 888 name = settingName(setting.substring(0, colonOffset)); | 920 name = settingName(setting.substring(0, colonOffset)); |
| 889 | 921 |
| 890 // 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. | 922 // 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. |
| 891 position += colonOffset + 1; | 923 position += colonOffset + 1; |
| 892 if (position >= input.length()) | 924 if (position >= input.length()) |
| 893 break; | 925 break; |
| 894 | 926 |
| 895 // 4. Run the appropriate substeps that apply for the value of name, as
follows: | 927 // 4. Run the appropriate substeps that apply for the value of name, as
follows: |
| 896 switch (name) { | 928 switch (name) { |
| 897 case Vertical: | 929 case Vertical: { |
| 898 { | |
| 899 // If name is a case-sensitive match for "vertical" | 930 // If name is a case-sensitive match for "vertical" |
| 900 // 1. If value is a case-sensitive match for the string "rl", then l
et cue's text track cue writing direction | 931 // 1. If value is a case-sensitive match for the string "rl", then l
et cue's text track cue writing direction |
| 901 // be vertical growing left. | 932 // be vertical growing left. |
| 902 String writingDirection = VTTParser::collectWord(input, &position); | 933 String writingDirection = VTTParser::collectWord(input, &position); |
| 903 if (writingDirection == verticalGrowingLeftKeyword()) | 934 if (writingDirection == verticalGrowingLeftKeyword()) |
| 904 m_writingDirection = VerticalGrowingLeft; | 935 m_writingDirection = VerticalGrowingLeft; |
| 905 | 936 |
| 906 // 2. Otherwise, if value is a case-sensitive match for the string "
lr", then let cue's text track cue writing | 937 // 2. Otherwise, if value is a case-sensitive match for the string "
lr", then let cue's text track cue writing |
| 907 // direction be vertical growing right. | 938 // direction be vertical growing right. |
| 908 else if (writingDirection == verticalGrowingRightKeyword()) | 939 else if (writingDirection == verticalGrowingRightKeyword()) |
| 909 m_writingDirection = VerticalGrowingRight; | 940 m_writingDirection = VerticalGrowingRight; |
| 910 } | |
| 911 break; | 941 break; |
| 912 case Line: | 942 } |
| 913 { | 943 case Line: { |
| 914 // 1-2 - Collect chars that are either '-', '%', or a digit. | 944 // 1-2 - Collect chars that are either '-', '%', or a digit. |
| 915 // 1. If value contains any characters other than U+002D HYPHEN-MINU
S characters (-), U+0025 PERCENT SIGN | 945 // 1. If value contains any characters other than U+002D HYPHEN-MINU
S characters (-), U+0025 PERCENT SIGN |
| 916 // characters (%), and characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9), then jump | 946 // characters (%), and characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9), then jump |
| 917 // to the step labeled next setting. | 947 // to the step labeled next setting. |
| 918 StringBuilder linePositionBuilder; | 948 StringBuilder linePositionBuilder; |
| 919 while (position < input.length() && (input[position] == '-' || input
[position] == '%' || isASCIIDigit(input[position]))) | 949 while (position < input.length() && (input[position] == '-' || input
[position] == '%' || isASCIIDigit(input[position]))) |
| 920 linePositionBuilder.append(input[position++]); | 950 linePositionBuilder.append(input[position++]); |
| 921 if (position < input.length() && !VTTParser::isValidSettingDelimiter
(input[position])) | 951 if (position < input.length() && !VTTParser::isValidSettingDelimiter
(input[position])) |
| 922 break; | 952 break; |
| 923 | 953 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 951 // snap-to-lines flag be false. Otherwise, let it be true. | 981 // snap-to-lines flag be false. Otherwise, let it be true. |
| 952 if (linePosition[linePosition.length() - 1] == '%') { | 982 if (linePosition[linePosition.length() - 1] == '%') { |
| 953 if (number < 0 || number > 100) | 983 if (number < 0 || number > 100) |
| 954 break; | 984 break; |
| 955 | 985 |
| 956 // 10 - If '%' then set snap-to-lines flag to false. | 986 // 10 - If '%' then set snap-to-lines flag to false. |
| 957 m_snapToLines = false; | 987 m_snapToLines = false; |
| 958 } | 988 } |
| 959 | 989 |
| 960 m_linePosition = number; | 990 m_linePosition = number; |
| 961 } | |
| 962 break; | 991 break; |
| 963 case Position: | 992 } |
| 964 { | 993 case Position: { |
| 965 // 1. If value contains any characters other than U+0025 PERCENT SIG
N characters (%) and characters in the range | |
| 966 // U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jump to t
he step labeled next setting. | |
| 967 // 2. If value does not contain at least one character in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), | |
| 968 // then jump to the step labeled next setting. | |
| 969 int number; | 994 int number; |
| 970 if (!VTTParser::collectDigitsToInt(input, &position, number)) | 995 // Steps 1 - 6. |
| 971 break; | 996 if (!scanPercentage(input, &position, number)) |
| 972 if (position >= input.length()) | |
| 973 break; | |
| 974 | |
| 975 // 3. If any character in value other than the last character is a U
+0025 PERCENT SIGN character (%), then jump | |
| 976 // to the step labeled next setting. | |
| 977 // 4. If the last character in value is not a U+0025 PERCENT SIGN ch
aracter (%), then jump to the step labeled | |
| 978 // next setting. | |
| 979 if (input[position++] != '%') | |
| 980 break; | |
| 981 if (position < input.length() && !VTTParser::isValidSettingDelimiter
(input[position])) | |
| 982 break; | |
| 983 | |
| 984 // 5. Ignoring the trailing percent sign, interpret value as an inte
ger, and let number be that number. | |
| 985 // 6. If number is not in the range 0 ≤ number ≤ 100, then jump to t
he step labeled next setting. | |
| 986 // NOTE: toInt ignores trailing non-digit characters, such as '%'. | |
| 987 if (number < 0 || number > 100) | |
| 988 break; | 997 break; |
| 989 | 998 |
| 990 // 7. Let cue's text track cue text position be number. | 999 // 7. Let cue's text track cue text position be number. |
| 991 m_textPosition = number; | 1000 m_textPosition = number; |
| 992 } | |
| 993 break; | 1001 break; |
| 994 case Size: | 1002 } |
| 995 { | 1003 case Size: { |
| 996 // 1. If value contains any characters other than U+0025 PERCENT SIG
N characters (%) and characters in the | |
| 997 // range U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), then jum
p to the step labeled next setting. | |
| 998 // 2. If value does not contain at least one character in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT | |
| 999 // NINE (9), then jump to the step labeled next setting. | |
| 1000 int number; | 1004 int number; |
| 1001 if (!VTTParser::collectDigitsToInt(input, &position, number)) | 1005 // Steps 1 - 6. |
| 1002 break; | 1006 if (!scanPercentage(input, &position, number)) |
| 1003 if (position >= input.length()) | |
| 1004 break; | |
| 1005 | |
| 1006 // 3. If any character in value other than the last character is a U
+0025 PERCENT SIGN character (%), | |
| 1007 // then jump to the step labeled next setting. | |
| 1008 // 4. If the last character in value is not a U+0025 PERCENT SIGN ch
aracter (%), then jump to the step | |
| 1009 // labeled next setting. | |
| 1010 if (input[position++] != '%') | |
| 1011 break; | |
| 1012 if (position < input.length() && !VTTParser::isValidSettingDelimiter
(input[position])) | |
| 1013 break; | |
| 1014 | |
| 1015 // 5. Ignoring the trailing percent sign, interpret value as an inte
ger, and let number be that number. | |
| 1016 // 6. If number is not in the range 0 ≤ number ≤ 100, then jump to t
he step labeled next setting. | |
| 1017 if (number < 0 || number > 100) | |
| 1018 break; | 1007 break; |
| 1019 | 1008 |
| 1020 // 7. Let cue's text track cue size be number. | 1009 // 7. Let cue's text track cue size be number. |
| 1021 m_cueSize = number; | 1010 m_cueSize = number; |
| 1022 } | |
| 1023 break; | 1011 break; |
| 1024 case Align: | 1012 } |
| 1025 { | 1013 case Align: { |
| 1026 String cueAlignment = VTTParser::collectWord(input, &position); | 1014 String cueAlignment = VTTParser::collectWord(input, &position); |
| 1027 | 1015 |
| 1028 // 1. If value is a case-sensitive match for the string "start", the
n let cue's text track cue alignment be start alignment. | 1016 // 1. If value is a case-sensitive match for the string "start", the
n let cue's text track cue alignment be start alignment. |
| 1029 if (cueAlignment == startKeyword()) | 1017 if (cueAlignment == startKeyword()) |
| 1030 m_cueAlignment = Start; | 1018 m_cueAlignment = Start; |
| 1031 | 1019 |
| 1032 // 2. If value is a case-sensitive match for the string "middle", th
en let cue's text track cue alignment be middle alignment. | 1020 // 2. If value is a case-sensitive match for the string "middle", th
en let cue's text track cue alignment be middle alignment. |
| 1033 else if (cueAlignment == middleKeyword()) | 1021 else if (cueAlignment == middleKeyword()) |
| 1034 m_cueAlignment = Middle; | 1022 m_cueAlignment = Middle; |
| 1035 | 1023 |
| 1036 // 3. If value is a case-sensitive match for the string "end", then
let cue's text track cue alignment be end alignment. | 1024 // 3. If value is a case-sensitive match for the string "end", then
let cue's text track cue alignment be end alignment. |
| 1037 else if (cueAlignment == endKeyword()) | 1025 else if (cueAlignment == endKeyword()) |
| 1038 m_cueAlignment = End; | 1026 m_cueAlignment = End; |
| 1039 | 1027 |
| 1040 // 4. If value is a case-sensitive match for the string "left", then
let cue's text track cue alignment be left alignment. | 1028 // 4. If value is a case-sensitive match for the string "left", then
let cue's text track cue alignment be left alignment. |
| 1041 else if (cueAlignment == leftKeyword()) | 1029 else if (cueAlignment == leftKeyword()) |
| 1042 m_cueAlignment = Left; | 1030 m_cueAlignment = Left; |
| 1043 | 1031 |
| 1044 // 5. If value is a case-sensitive match for the string "right", the
n let cue's text track cue alignment be right alignment. | 1032 // 5. If value is a case-sensitive match for the string "right", the
n let cue's text track cue alignment be right alignment. |
| 1045 else if (cueAlignment == rightKeyword()) | 1033 else if (cueAlignment == rightKeyword()) |
| 1046 m_cueAlignment = Right; | 1034 m_cueAlignment = Right; |
| 1047 } | |
| 1048 break; | 1035 break; |
| 1036 } |
| 1049 case RegionId: | 1037 case RegionId: |
| 1050 m_regionId = VTTParser::collectWord(input, &position); | 1038 m_regionId = VTTParser::collectWord(input, &position); |
| 1051 break; | 1039 break; |
| 1052 case None: | 1040 case None: |
| 1053 break; | 1041 break; |
| 1054 } | 1042 } |
| 1055 | 1043 |
| 1056 NextSetting: | 1044 NextSetting: |
| 1057 position = endOfSetting; | 1045 position = endOfSetting; |
| 1058 } | 1046 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 return m_cueBackgroundBox->executionContext(); | 1089 return m_cueBackgroundBox->executionContext(); |
| 1102 } | 1090 } |
| 1103 | 1091 |
| 1104 Document& VTTCue::document() const | 1092 Document& VTTCue::document() const |
| 1105 { | 1093 { |
| 1106 ASSERT(m_cueBackgroundBox); | 1094 ASSERT(m_cueBackgroundBox); |
| 1107 return m_cueBackgroundBox->document(); | 1095 return m_cueBackgroundBox->document(); |
| 1108 } | 1096 } |
| 1109 | 1097 |
| 1110 } // namespace WebCore | 1098 } // namespace WebCore |
| OLD | NEW |