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 installClass('HTMLMarqueeElement', 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; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 }, | 74 }, |
| 75 set: function(value) { | 75 set: function(value) { |
| 76 if (value) | 76 if (value) |
| 77 this.setAttribute(attributeName, ''); | 77 this.setAttribute(attributeName, ''); |
| 78 else | 78 else |
| 79 this.removeAttribute(attributeName); | 79 this.removeAttribute(attributeName); |
| 80 }, | 80 }, |
| 81 }); | 81 }); |
| 82 } | 82 } |
| 83 | 83 |
| 84 function defineInlineEventHandler(prototype, eventName) { | |
| 85 var propertyName = 'on' + eventName; | |
| 86 // FIXME: We should use symbols here instead. | |
| 87 var functionPropertyName = propertyName + 'Function_'; | |
| 88 var eventHandlerPropertyName = propertyName + 'EventHandler_'; | |
| 89 Object.defineProperty(prototype, propertyName, { | |
| 90 get: function() { | |
| 91 var func = this[functionPropertyName]; | |
| 92 return func || null; | |
| 93 }, | |
| 94 set: function(value) { | |
| 95 var oldEventHandler = this[eventHandlerPropertyName]; | |
| 96 if (oldEventHandler) | |
| 97 this.removeEventListener(eventName, oldEventHandler); | |
| 98 // Notice that we wrap |value| in an anonymous function so that the | |
| 99 // author can't call removeEventListener themselves to unregiste r the | |
| 100 // inline event handler. | |
| 101 var newEventHandler = value ? function() { value.apply(this, arg uments) } : null; | |
| 102 if (newEventHandler) | |
| 103 this.addEventListener(eventName, newEventHandler); | |
| 104 this[functionPropertyName] = value; | |
| 105 this[eventHandlerPropertyName] = newEventHandler; | |
| 106 }, | |
| 107 }); | |
| 108 } | |
| 109 | |
| 110 var HTMLMarqueeElementPrototype = Object.create(HTMLElement.prototype); | 84 var HTMLMarqueeElementPrototype = Object.create(HTMLElement.prototype); |
| 111 | 85 |
| 112 reflectAttribute(HTMLMarqueeElementPrototype, 'behavior', 'behavior'); | 86 reflectAttribute(HTMLMarqueeElementPrototype, 'behavior', 'behavior'); |
| 113 reflectAttribute(HTMLMarqueeElementPrototype, 'bgcolor', 'bgColor'); | 87 reflectAttribute(HTMLMarqueeElementPrototype, 'bgcolor', 'bgColor'); |
| 114 reflectAttribute(HTMLMarqueeElementPrototype, 'direction', 'direction'); | 88 reflectAttribute(HTMLMarqueeElementPrototype, 'direction', 'direction'); |
| 115 reflectAttribute(HTMLMarqueeElementPrototype, 'height', 'height'); | 89 reflectAttribute(HTMLMarqueeElementPrototype, 'height', 'height'); |
| 116 reflectAttribute(HTMLMarqueeElementPrototype, 'hspace', 'hspace'); | 90 reflectAttribute(HTMLMarqueeElementPrototype, 'hspace', 'hspace'); |
| 117 reflectAttribute(HTMLMarqueeElementPrototype, 'vspace', 'vspace'); | 91 reflectAttribute(HTMLMarqueeElementPrototype, 'vspace', 'vspace'); |
| 118 reflectAttribute(HTMLMarqueeElementPrototype, 'width', 'width'); | 92 reflectAttribute(HTMLMarqueeElementPrototype, 'width', 'width'); |
| 119 reflectBooleanAttribute(HTMLMarqueeElementPrototype, 'truespeed', 'trueSpeed '); | 93 reflectBooleanAttribute(HTMLMarqueeElementPrototype, 'truespeed', 'trueSpeed '); |
| 120 | 94 |
| 121 defineInlineEventHandler(HTMLMarqueeElementPrototype, 'start'); | |
| 122 defineInlineEventHandler(HTMLMarqueeElementPrototype, 'finish'); | |
| 123 defineInlineEventHandler(HTMLMarqueeElementPrototype, 'bounce'); | |
|
haraken
2014/07/15 12:57:07
I removed these event handlers, since we haven't y
| |
| 124 | |
| 125 HTMLMarqueeElementPrototype.createdCallback = function() { | 95 HTMLMarqueeElementPrototype.createdCallback = function() { |
|
haraken
2014/07/15 12:57:07
abarth@: When and how are you assuming that these
abarth-chromium
2014/07/15 17:10:07
These callbacks are all defined by http://w3c.gith
| |
| 126 var shadow = this.createShadowRoot(); | 96 var shadow = this.createShadowRoot(); |
| 127 var style = global.document.createElement('style'); | 97 var style = global.document.createElement('style'); |
| 128 style.textContent = ':host { display: inline-block; width: -webkit-fill-avai lable; overflow: hidden; text-align: initial; }' + | 98 style.textContent = ':host { display: inline-block; width: -webkit-fill-avai lable; overflow: hidden; text-align: initial; }' + |
| 129 ':host([direction="up"]), :host([direction="down"]) { height: 200px; }'; | 99 ':host([direction="up"]), :host([direction="down"]) { height: 200px; }'; |
| 130 shadow.appendChild(style); | 100 shadow.appendChild(style); |
| 131 | 101 |
| 132 var mover = global.document.createElement('div'); | 102 var mover = global.document.createElement('div'); |
| 133 shadow.appendChild(mover); | 103 shadow.appendChild(mover); |
| 134 | 104 |
| 135 mover.appendChild(global.document.createElement('content')); | 105 mover.appendChild(global.document.createElement('content')); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 loop = 1; | 327 loop = 1; |
| 358 | 328 |
| 359 if (loop <= 0) | 329 if (loop <= 0) |
| 360 return true; | 330 return true; |
| 361 return this.loopCount_ < loop; | 331 return this.loopCount_ < loop; |
| 362 }; | 332 }; |
| 363 | 333 |
| 364 HTMLMarqueeElementPrototype.continue_ = function() { | 334 HTMLMarqueeElementPrototype.continue_ = function() { |
| 365 if (!this.shouldContinue_()) { | 335 if (!this.shouldContinue_()) { |
| 366 this.player_ = null; | 336 this.player_ = null; |
| 367 this.dispatchEvent(new Event('finish', false, true)); | |
| 368 return; | 337 return; |
| 369 } | 338 } |
| 370 | 339 |
| 371 var parameters = this.getAnimationParameters_(); | 340 var parameters = this.getAnimationParameters_(); |
| 372 | 341 |
| 373 var player = this.mover_.animate([ | 342 var player = this.mover_.animate([ |
| 374 { transform: parameters.transformBegin }, | 343 { transform: parameters.transformBegin }, |
| 375 { transform: parameters.transformEnd }, | 344 { transform: parameters.transformEnd }, |
| 376 ], { | 345 ], { |
| 377 duration: parameters.distance * this.scrollDelay / this.scrollAmount , | 346 duration: parameters.distance * this.scrollDelay / this.scrollAmount , |
| 378 fill: 'forwards', | 347 fill: 'forwards', |
| 379 }); | 348 }); |
| 380 | 349 |
| 381 this.player_ = player; | 350 this.player_ = player; |
| 382 | 351 |
| 383 player.addEventListener('finish', function() { | 352 player.addEventListener('finish', function() { |
| 384 if (player != this.player_) | 353 if (player != this.player_) |
| 385 return; | 354 return; |
| 386 ++this.loopCount_; | 355 ++this.loopCount_; |
| 387 this.continue_(); | 356 this.continue_(); |
| 388 if (this.player_ && this.behavior === kBehaviorAlternate) | |
| 389 this.dispatchEvent(new Event('bounce', false, true)); | |
| 390 }.bind(this)); | 357 }.bind(this)); |
| 391 }; | 358 }; |
| 392 | 359 |
| 393 HTMLMarqueeElementPrototype.start = function() { | 360 HTMLMarqueeElementPrototype.start = function() { |
| 394 if (this.continueCallback_ || this.player_) | 361 if (this.continueCallback_ || this.player_) |
| 395 return; | 362 return; |
| 396 this.continueCallback_ = global.requestAnimationFrame(function() { | 363 this.continueCallback_ = global.requestAnimationFrame(function() { |
| 397 this.continueCallback_ = null; | 364 this.continueCallback_ = null; |
| 398 this.continue_(); | 365 this.continue_(); |
| 399 }.bind(this)); | 366 }.bind(this)); |
| 400 this.dispatchEvent(new Event('start', false, true)); | |
| 401 }; | 367 }; |
| 402 | 368 |
| 403 HTMLMarqueeElementPrototype.stop = function() { | 369 HTMLMarqueeElementPrototype.stop = function() { |
| 404 if (!this.continueCallback_ && !this.player_) | 370 if (!this.continueCallback_ && !this.player_) |
| 405 return; | 371 return; |
| 406 | 372 |
| 407 if (this.continueCallback_) { | 373 if (this.continueCallback_) { |
| 408 global.cancelAnimationFrame(this.continueCallback_); | 374 global.cancelAnimationFrame(this.continueCallback_); |
| 409 this.continueCallback_ = null; | 375 this.continueCallback_ = null; |
| 410 return; | 376 return; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 421 }; | 387 }; |
| 422 | 388 |
| 423 // FIXME: We have to inject this HTMLMarqueeElement as a custom element in o rder to make | 389 // FIXME: We have to inject this HTMLMarqueeElement as a custom element in o rder to make |
| 424 // createdCallback, attachedCallback, detachedCallback and attributeChangedC allback workable. | 390 // createdCallback, attachedCallback, detachedCallback and attributeChangedC allback workable. |
| 425 // global.document.registerElement('i-marquee', { | 391 // global.document.registerElement('i-marquee', { |
| 426 // prototype: HTMLMarqueeElementPrototype, | 392 // prototype: HTMLMarqueeElementPrototype, |
| 427 // }); | 393 // }); |
| 428 | 394 |
| 429 return HTMLMarqueeElementPrototype; | 395 return HTMLMarqueeElementPrototype; |
| 430 }); | 396 }); |
| OLD | NEW |