Commit c4b85f71 authored by yamaguchi's avatar yamaguchi Committed by Commit bot

Scroll the attached view when wheel spinned on top of a scroll button.

BUG=600697
TEST=manually

Review-Url: https://codereview.chromium.org/2135163002
Cr-Commit-Position: refs/heads/master@{#404631}
parent 2d7f91d6
......@@ -51,6 +51,7 @@ ScrollBar.prototype.decorate = function() {
this.button_.addEventListener('mousedown',
this.onButtonPressed_.bind(this));
this.button_.addEventListener('wheel', this.onWheel_.bind(this));
window.addEventListener('mouseup', this.onMouseUp_.bind(this));
window.addEventListener('mousemove', this.onMouseMove_.bind(this));
};
......@@ -85,6 +86,27 @@ ScrollBar.prototype.attachToView = function(view) {
this.onRelayout_();
};
/**
* Handles scroll by a mouse wheel.
*
* @param {Event} event Mouse event.
* @private
*/
ScrollBar.prototype.onWheel_ = function(event) {
var scrollPosition = this.view_.scrollTop + event.deltaY;
// Ensure the scrollbar is in the view.
var scrollBottom =
Math.max(this.view_.scrollHeight - this.view_.clientHeight, 0);
scrollPosition = Math.max(Math.min(scrollPosition, scrollBottom), 0);
// TODO(yamaguchi): Invoke native scroll instead of setting scrollTop.
// This implementation will bypass the smooth scroll animation seen with
// native scroll.
this.scrollTop_ = scrollPosition;
this.view_.scrollTop = scrollPosition;
this.redraw_();
}
/**
* Scroll handler.
* @private
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment