diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-08-05 22:45:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-08-05 22:45:32 +0000 |
commit | a5e4f4d2969520f4563ec0d66cbe469c49ee38bc (patch) | |
tree | 8a0d6fd78eb610653f12ded770595c80f1e89a61 /catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js | |
parent | 5e1447373f2b6aaefa0e866c5907a291e7071a3d (diff) | |
parent | 5338649baa46daab43dd19d939fc1f016d400a94 (diff) | |
download | chromium-trace-a5e4f4d2969520f4563ec0d66cbe469c49ee38bc.tar.gz |
Merge changes Ie9f01eed,I3acb8a0d am: fb769a1607 am: 316160b179 am: 3fd616f492 am: 5338649baa
Original change: https://android-review.googlesource.com/c/platform/external/chromium-trace/+/1392438
Change-Id: I01f6e9f32cc3210fbc5f6f645a77b74316ecfb3b
Diffstat (limited to 'catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js')
-rw-r--r-- | catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js b/catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js new file mode 100644 index 00000000..3f8201d8 --- /dev/null +++ b/catapult/third_party/polymer/components/web-animations-js/src/shadow-handler.js @@ -0,0 +1,108 @@ +// Copyright 2014 Google Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +(function(scope) { + + function consumeShadow(string) { + var shadow = { + inset: false, + lengths: [], + color: null, + }; + function consumePart(string) { + var result = scope.consumeToken(/^inset/i, string); + if (result) { + shadow.inset = true; + return result; + } + var result = scope.consumeLengthOrPercent(string); + if (result) { + shadow.lengths.push(result[0]); + return result; + } + var result = scope.consumeColor(string); + if (result) { + shadow.color = result[0]; + return result; + } + } + var result = scope.consumeRepeated(consumePart, /^/, string); + if (result && result[0].length) { + return [shadow, result[1]]; + } + } + + function parseShadowList(string) { + var result = scope.consumeRepeated(consumeShadow, /^,/, string); + if (result && result[1] == '') { + return result[0]; + } + } + + function mergeShadow(left, right) { + while (left.lengths.length < Math.max(left.lengths.length, right.lengths.length)) + left.lengths.push({px: 0}); + while (right.lengths.length < Math.max(left.lengths.length, right.lengths.length)) + right.lengths.push({px: 0}); + + if (left.inset != right.inset || !!left.color != !!right.color) { + return; + } + var lengthReconstitution = []; + var colorReconstitution; + var matchingLeft = [[], 0]; + var matchingRight = [[], 0]; + for (var i = 0; i < left.lengths.length; i++) { + var mergedDimensions = scope.mergeDimensions(left.lengths[i], right.lengths[i], i == 2); + matchingLeft[0].push(mergedDimensions[0]); + matchingRight[0].push(mergedDimensions[1]); + lengthReconstitution.push(mergedDimensions[2]); + } + if (left.color && right.color) { + var mergedColor = scope.mergeColors(left.color, right.color); + matchingLeft[1] = mergedColor[0]; + matchingRight[1] = mergedColor[1]; + colorReconstitution = mergedColor[2]; + } + return [matchingLeft, matchingRight, function(value) { + var result = left.inset ? 'inset ' : ' '; + for (var i = 0; i < lengthReconstitution.length; i++) { + result += lengthReconstitution[i](value[0][i]) + ' '; + } + if (colorReconstitution) { + result += colorReconstitution(value[1]); + } + return result; + }]; + } + + function mergeNestedRepeatedShadow(nestedMerge, separator, left, right) { + var leftCopy = []; + var rightCopy = []; + function defaultShadow(inset) { + return {inset: inset, color: [0, 0, 0, 0], lengths: [{px: 0}, {px: 0}, {px: 0}, {px: 0}]}; + } + for (var i = 0; i < left.length || i < right.length; i++) { + var l = left[i] || defaultShadow(right[i].inset); + var r = right[i] || defaultShadow(left[i].inset); + leftCopy.push(l); + rightCopy.push(r); + } + return scope.mergeNestedRepeated(nestedMerge, separator, leftCopy, rightCopy); + } + + var mergeShadowList = mergeNestedRepeatedShadow.bind(null, mergeShadow, ', '); + scope.addPropertiesHandler(parseShadowList, mergeShadowList, ['box-shadow', 'text-shadow']); + +})(webAnimations1); |