Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 (function(global) { | 7 installClass('HTMLMarqueeElement', function(global) { |
| 8 | 8 |
| 9 var kDefaultScrollAmount = 6; | 9 var kDefaultScrollAmount = 6; |
| 10 var kDefaultScrollDelayMS = 85; | 10 var kDefaultScrollDelayMS = 85; |
| 11 var kMinimumScrollDelayMS = 60; | 11 var kMinimumScrollDelayMS = 60; |
| 12 | 12 |
| 13 var kDefaultLoopLimit = -1; | 13 var kDefaultLoopLimit = -1; |
| 14 | 14 |
| 15 var kBehaviorScroll = 'scroll'; | 15 var kBehaviorScroll = 'scroll'; |
| 16 var kBehaviorSlide = 'slide'; | 16 var kBehaviorSlide = 'slide'; |
| 17 var kBehaviorAlternate = 'alternate'; | 17 var kBehaviorAlternate = 'alternate'; |
| 18 | 18 |
| 19 var kDirectionLeft = 'left'; | 19 var kDirectionLeft = 'left'; |
| 20 var kDirectionRight = 'right'; | 20 var kDirectionRight = 'right'; |
| 21 var kDirectionUp = 'up'; | 21 var kDirectionUp = 'up'; |
| 22 var kDirectionDown = 'down'; | 22 var kDirectionDown = 'down'; |
| 23 | 23 |
| 24 var kPresentationalAttributes = [ | 24 var kPresentationalAttributes = [ |
| 25 'bgcolor', | 25 'bgcolor', |
| 26 'height', | 26 'height', |
| 27 'hspace', | 27 'hspace', |
| 28 'vspace', | 28 'vspace', |
| 29 'width', | 29 'width', |
| 30 ]; | 30 ]; |
| 31 | 31 |
| 32 var pixelLengthRegexp = /^\s*([\d.]+)\s*$/; | 32 var pixelLengthRegexp = /^\s*([\d.]+)\s*$/; |
| 33 var percentageLengthRegexp = /^\s*([\d.]+)\s*%\s*$/; | 33 var percentageLengthRegexp = /^\s*([\d.]+)\s*%\s*$/; |
| 34 | 34 |
| 35 function convertHTMLLengthToCSSLength(value) | 35 function convertHTMLLengthToCSSLength(value) { |
| 36 { | |
| 37 var pixelMatch = value.match(pixelLengthRegexp); | 36 var pixelMatch = value.match(pixelLengthRegexp); |
| 38 if (pixelMatch) | 37 if (pixelMatch) |
| 39 return pixelMatch[1] + 'px'; | 38 return pixelMatch[1] + 'px'; |
| 40 var percentageMatch = value.match(percentageLengthRegexp); | 39 var percentageMatch = value.match(percentageLengthRegexp); |
| 41 if (percentageMatch) | 40 if (percentageMatch) |
| 42 return percentageMatch[1] + '%'; | 41 return percentageMatch[1] + '%'; |
| 43 return null; | 42 return null; |
| 44 } | 43 } |
| 45 | 44 |
| 46 function reflectAttribute(prototype, attributeName, propertyName) | 45 // FIXME: Consider moving these utility functions to PrivateScriptUtils.js. |
| 47 { | 46 function reflectAttribute(prototype, attributeName, propertyName) { |
| 48 Object.defineProperty(prototype, propertyName, { | 47 Object.defineProperty(prototype, propertyName, { |
| 49 get: function() { | 48 get: function() { |
| 50 return this.getAttribute(attributeName) || ''; | 49 return this.getAttribute(attributeName) || ''; |
| 51 }, | 50 }, |
| 52 set: function(value) { | 51 set: function(value) { |
| 53 this.setAttribute(attributeName, value); | 52 this.setAttribute(attributeName, value); |
| 54 }, | 53 }, |
| 54 configurable: true, | |
| 55 enumerable: true, | |
| 55 }); | 56 }); |
| 56 } | 57 } |
| 57 | 58 |
| 58 function reflectBooleanAttribute(prototype, attributeName, propertyName) | 59 function reflectBooleanAttribute(prototype, attributeName, propertyName) { |
| 59 { | |
| 60 Object.defineProperty(prototype, propertyName, { | 60 Object.defineProperty(prototype, propertyName, { |
| 61 get: function() { | 61 get: function() { |
| 62 return this.hasAttribute(attributeName); | 62 return this.hasAttribute(attributeName); |
| 63 }, | 63 }, |
| 64 set: function(value) { | 64 set: function(value) { |
| 65 this.setAttribute(attributeName, value ? '' : null); | 65 if (Boolean(value) === false) |
|
abarth-chromium
2014/07/14 06:04:35
Does this call valueOf? Are we supposed to call v
abarth-chromium
2014/07/14 06:04:35
Does this call valueOf? Are we supposed to call v
haraken
2014/07/14 09:59:12
Done.
| |
| 66 this.removeAttribute(attributeName); | |
| 67 else | |
| 68 this.setAttribute(attributeName, value ? '' : null); | |
| 66 }, | 69 }, |
| 67 }); | 70 }); |
| 68 } | 71 } |
| 69 | 72 |
| 70 function defineInlineEventHandler(prototype, eventName) | 73 function defineInlineEventHandler(prototype, eventName) { |
| 71 { | |
| 72 var propertyName = 'on' + eventName; | 74 var propertyName = 'on' + eventName; |
| 73 // FIXME: We should use symbols here instead. | 75 // FIXME: We should use symbols here instead. |
| 74 var functionPropertyName = propertyName + 'Function_'; | 76 var functionPropertyName = propertyName + 'Function_'; |
| 75 var eventHandlerPropertyName = propertyName + 'EventHandler_'; | 77 var eventHandlerPropertyName = propertyName + 'EventHandler_'; |
| 76 Object.defineProperty(prototype, propertyName, { | 78 Object.defineProperty(prototype, propertyName, { |
| 77 get: function() { | 79 get: function() { |
| 78 var func = this[functionPropertyName]; | 80 var func = this[functionPropertyName]; |
| 79 return func || null; | 81 return func || null; |
| 80 }, | 82 }, |
| 81 set: function(value) { | 83 set: function(value) { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 // FIXME: Rather than canceling the animation, we really should just | 392 // FIXME: Rather than canceling the animation, we really should just |
| 391 // pause the animation, but the pause function is still flagged as | 393 // pause the animation, but the pause function is still flagged as |
| 392 // experimental. | 394 // experimental. |
| 393 if (this.player_) { | 395 if (this.player_) { |
| 394 var player = this.player_; | 396 var player = this.player_; |
| 395 this.player_ = null; | 397 this.player_ = null; |
| 396 player.cancel(); | 398 player.cancel(); |
| 397 } | 399 } |
| 398 }; | 400 }; |
| 399 | 401 |
| 400 global.document.registerElement('i-marquee', { | 402 // FIXME: We have to inject this HTMLMarqueeElement as a custom element in o rder to make |
| 401 prototype: HTMLMarqueeElementPrototype, | 403 // createdCallback, attachedCallback, detachedCallback and attributeChangedC allback workable. |
| 402 }); | 404 // global.document.registerElement('i-marquee', { |
| 405 // prototype: HTMLMarqueeElementPrototype, | |
| 406 // }); | |
| 403 | 407 |
| 404 })(this); | 408 return HTMLMarqueeElementPrototype; |
| 409 }); | |
| OLD | NEW |