Updated Test Driver with video decoding capabilities so that when a video sample...
[chromium-blink-merge.git] / third_party / web-animations-js / sources / src / shape-handler.js
blob6bbf79fe488377885cf9b88b16aa7a8a72b34afe
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 //   You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 //   See the License for the specific language governing permissions and
13 // limitations under the License.
15 (function(scope) {
17   var consumeLengthOrPercent = scope.consumeParenthesised.bind(null, scope.parseLengthOrPercent);
18   var consumeLengthOrPercentPair = scope.consumeRepeated.bind(undefined, consumeLengthOrPercent, /^/);
20   var mergeSizePair = scope.mergeNestedRepeated.bind(undefined, scope.mergeDimensions, ' ');
21   var mergeSizePairList = scope.mergeNestedRepeated.bind(undefined, mergeSizePair, ',');
23   function parseShape(input) {
24     var circle = scope.consumeToken(/^circle/, input);
25     if (circle && circle[0]) {
26       return ['circle'].concat(scope.consumeList([
27         scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
28         consumeLengthOrPercent,
29         scope.ignore(scope.consumeToken.bind(undefined, /^at/)),
30         scope.consumePosition,
31         scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
32       ], circle[1]));
33     }
34     var ellipse = scope.consumeToken(/^ellipse/, input);
35     if (ellipse && ellipse[0]) {
36       return ['ellipse'].concat(scope.consumeList([
37         scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
38         consumeLengthOrPercentPair,
39         scope.ignore(scope.consumeToken.bind(undefined, /^at/)),
40         scope.consumePosition,
41         scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
42       ], ellipse[1]));
43     }
44     var polygon = scope.consumeToken(/^polygon/, input);
45     if (polygon && polygon[0]) {
46       return ['polygon'].concat(scope.consumeList([
47         scope.ignore(scope.consumeToken.bind(undefined, /^\(/)),
48         scope.optional(scope.consumeToken.bind(undefined, /^nonzero\s*,|^evenodd\s*,/), 'nonzero,'),
49         scope.consumeSizePairList,
50         scope.ignore(scope.consumeToken.bind(undefined, /^\)/))
51       ], polygon[1]));
52     }
53   }
55   function mergeShapes(left, right) {
56     if (left[0] !== right[0])
57       return;
58     if (left[0] == 'circle') {
59       return scope.mergeList(left.slice(1), right.slice(1), [
60         'circle(',
61         scope.mergeDimensions,
62         ' at ',
63         scope.mergeOffsetList,
64         ')']);
65     }
66     if (left[0] == 'ellipse') {
67       return scope.mergeList(left.slice(1), right.slice(1), [
68         'ellipse(',
69         scope.mergeNonNegativeSizePair,
70         ' at ',
71         scope.mergeOffsetList,
72         ')']);
73     }
74     if (left[0] == 'polygon' && left[1] == right[1]) {
75       return scope.mergeList(left.slice(2), right.slice(2), [
76         'polygon(',
77         left[1],
78         mergeSizePairList,
79         ')']);
80     }
81   }
83   scope.addPropertiesHandler(parseShape, mergeShapes, ['shape-outside']);
85 })(webAnimations1);