1 // Copyright 2014 Google Inc. All rights reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
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, /^\)/))
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, /^\)/))
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, /^\)/))
55 function mergeShapes(left, right) {
56 if (left[0] !== right[0])
58 if (left[0] == 'circle') {
59 return scope.mergeList(left.slice(1), right.slice(1), [
61 scope.mergeDimensions,
63 scope.mergeOffsetList,
66 if (left[0] == 'ellipse') {
67 return scope.mergeList(left.slice(1), right.slice(1), [
69 scope.mergeNonNegativeSizePair,
71 scope.mergeOffsetList,
74 if (left[0] == 'polygon' && left[1] == right[1]) {
75 return scope.mergeList(left.slice(2), right.slice(2), [
83 scope.addPropertiesHandler(parseShape, mergeShapes, ['shape-outside']);