OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 /** | 7 /** |
8 * Creates a new scroll bar element. | 8 * Creates a new scroll bar element. |
9 * @extends {HTMLDivElement} | 9 * @extends {HTMLDivElement} |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 var ScrollBar = cr.ui.define('div'); | 12 var ScrollBar = cr.ui.define('div'); |
13 | 13 |
14 /** | 14 /** |
15 * Mode of the scrollbar. As for now, only vertical scrollbars are supported. | 15 * Mode of the scrollbar. As for now, only vertical scrollbars are supported. |
16 * @type {number} | 16 * @enum {number} |
17 */ | 17 */ |
18 ScrollBar.Mode = { | 18 ScrollBar.Mode = { |
19 VERTICAL: 0, | 19 VERTICAL: 0, |
20 HORIZONTAL: 1 | 20 HORIZONTAL: 1 |
21 }; | 21 }; |
22 | 22 |
23 ScrollBar.prototype = { | 23 ScrollBar.prototype = { |
24 set mode(value) { | 24 set mode(value) { |
25 this.mode_ = value; | 25 this.mode_ = value; |
26 if (this.mode_ == ScrollBar.Mode.VERTICAL) { | 26 if (this.mode_ == ScrollBar.Mode.VERTICAL) { |
(...skipping 26 matching lines...) Expand all Loading... | |
53 | 53 |
54 this.button_.addEventListener('mousedown', | 54 this.button_.addEventListener('mousedown', |
55 this.onButtonPressed_.bind(this)); | 55 this.onButtonPressed_.bind(this)); |
56 window.addEventListener('mouseup', this.onMouseUp_.bind(this)); | 56 window.addEventListener('mouseup', this.onMouseUp_.bind(this)); |
57 window.addEventListener('mousemove', this.onMouseMove_.bind(this)); | 57 window.addEventListener('mousemove', this.onMouseMove_.bind(this)); |
58 }; | 58 }; |
59 | 59 |
60 /** | 60 /** |
61 * Initialize a scrollbar. | 61 * Initialize a scrollbar. |
62 * | 62 * |
63 * @param {Element} parent Parent element, must have a relative or absolute | 63 * @param {Element} parent Parent node, must have a relative or absolute |
hirono
2014/10/16 07:24:47
nit: Parent node -> Parent element
fukino
2014/10/16 07:43:43
Done.
| |
64 * positioning. | 64 * positioning. |
65 * @param {Element=} opt_scrollableArea Element with scrollable contents. | 65 * @param {Element=} opt_scrollableArea Element with scrollable contents. |
66 * If not passed, then call attachToView manually when the scrollable | 66 * If not passed, then call attachToView manually when the scrollable |
67 * element becomes available. | 67 * element becomes available. |
68 */ | 68 */ |
69 ScrollBar.prototype.initialize = function(parent, opt_scrollableArea) { | 69 ScrollBar.prototype.initialize = function(parent, opt_scrollableArea) { |
70 parent.appendChild(this); | 70 parent.appendChild(this); |
71 if (opt_scrollableArea) | 71 if (opt_scrollableArea) |
72 this.attachToView(opt_scrollableArea); | 72 this.attachToView(opt_scrollableArea); |
73 }; | 73 }; |
74 | 74 |
75 /** | 75 /** |
76 * Attaches the scrollbar to a scrollable element and attaches handlers. | 76 * Attaches the scrollbar to a scrollable element and attaches handlers. |
77 * @param {Element} view Scrollable element. | 77 * @param {Element} view Scrollable element. |
78 */ | 78 */ |
79 ScrollBar.prototype.attachToView = function(view) { | 79 ScrollBar.prototype.attachToView = function(view) { |
80 this.view_ = view; | 80 this.view_ = view; |
81 this.view_.addEventListener('scroll', this.onScroll_.bind(this)); | 81 this.view_.addEventListener('scroll', this.onScroll_.bind(this)); |
82 this.view_.addEventListener('relayout', this.onRelayout_.bind(this)); | 82 this.view_.addEventListener('relayout', this.onRelayout_.bind(this)); |
83 this.domObserver_ = new MutationObserver(this.onDomChanged_.bind(this)); | 83 this.domObserver_ = new MutationObserver(this.onDomChanged_.bind(this)); |
84 this.domObserver_.observe(this.view_, {subtree: true, attributes: true}); | 84 this.domObserver_.observe( |
85 this.view_, | |
86 /** @type {MutationObserverInit} */ ({subtree: true, attributes: true})); | |
85 this.onRelayout_(); | 87 this.onRelayout_(); |
86 }; | 88 }; |
87 | 89 |
88 /** | 90 /** |
89 * Scroll handler. | 91 * Scroll handler. |
90 * @private | 92 * @private |
91 */ | 93 */ |
92 ScrollBar.prototype.onScroll_ = function() { | 94 ScrollBar.prototype.onScroll_ = function() { |
93 this.scrollTop_ = this.view_.scrollTop; | 95 this.scrollTop_ = this.view_.scrollTop; |
94 this.redraw_(); | 96 this.redraw_(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 return this.scrollHeight_ - this.bottomMarginForPanel_; | 299 return this.scrollHeight_ - this.bottomMarginForPanel_; |
298 }; | 300 }; |
299 | 301 |
300 /** | 302 /** |
301 * Sets the bottom margin height of the view for the transparent preview panel. | 303 * Sets the bottom margin height of the view for the transparent preview panel. |
302 * @param {number} margin Margin to be set in px. | 304 * @param {number} margin Margin to be set in px. |
303 */ | 305 */ |
304 MainPanelScrollBar.prototype.setBottomMarginForPanel = function(margin) { | 306 MainPanelScrollBar.prototype.setBottomMarginForPanel = function(margin) { |
305 this.bottomMarginForPanel_ = margin; | 307 this.bottomMarginForPanel_ = margin; |
306 }; | 308 }; |
OLD | NEW |