Changeset 143911 in webkit


Ignore:
Timestamp:
Feb 25, 2013 5:20:09 AM (11 years ago)
Author:
keishi@webkit.org
Message:

Add a scrollbar class for the new calendar picker
https://bugs.webkit.org/show_bug.cgi?id=110589

Reviewed by Kent Tamura.

Adding a scrollbar to be used in the new calendar picker (Bug 109439).

No new tests. Code is not used yet.

  • Resources/pagepopups/calendarPicker.js:

(ScrubbyScrollBar):
(ScrubbyScrollBar.prototype.height):
(ScrubbyScrollBar.prototype.setHeight):
(ScrubbyScrollBar.prototype.setThumbHeight): Sets the height of the scroll bar thumb.
(ScrubbyScrollBar.prototype._setThumbPositionFromEvent): Sets the thumb position from a mouse event.
(ScrubbyScrollBar.prototype.onMouseDown):
(ScrubbyScrollBar.prototype.onWindowMouseMove):
(ScrubbyScrollBar.prototype.onWindowMouseUp):
(ScrubbyScrollBar.prototype.onThumbStyleTopAnimationStep): Animates the thumb back to the center position.
(ScrubbyScrollBar.prototype.onScrollTimer): Fires repeatedly while the thumb is being dragged.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r143904 r143911  
     12013-02-25  Keishi Hattori  <keishi@webkit.org>
     2
     3        Add a scrollbar class for the new calendar picker
     4        https://bugs.webkit.org/show_bug.cgi?id=110589
     5
     6        Reviewed by Kent Tamura.
     7
     8        Adding a scrollbar to be used in the new calendar picker (Bug 109439).
     9
     10        No new tests. Code is not used yet.
     11
     12        * Resources/pagepopups/calendarPicker.js:
     13        (ScrubbyScrollBar):
     14        (ScrubbyScrollBar.prototype.height):
     15        (ScrubbyScrollBar.prototype.setHeight):
     16        (ScrubbyScrollBar.prototype.setThumbHeight): Sets the height of the scroll bar thumb.
     17        (ScrubbyScrollBar.prototype._setThumbPositionFromEvent): Sets the thumb position from a mouse event.
     18        (ScrubbyScrollBar.prototype.onMouseDown):
     19        (ScrubbyScrollBar.prototype.onWindowMouseMove):
     20        (ScrubbyScrollBar.prototype.onWindowMouseUp):
     21        (ScrubbyScrollBar.prototype.onThumbStyleTopAnimationStep): Animates the thumb back to the center position.
     22        (ScrubbyScrollBar.prototype.onScrollTimer): Fires repeatedly while the thumb is being dragged.
     23
    1242013-02-25  Ilya Tikhonovsky  <loislo@chromium.org>
    225
  • trunk/Source/WebCore/Resources/pagepopups/calendarPicker.js

    r143901 r143911  
    17191719ListView.prototype.scrollToRow = function(row, animate) {
    17201720    this.scrollView.scrollTo(this.scrollOffsetForRow(row), animate);
     1721};
     1722
     1723/**
     1724 * @constructor
     1725 * @extends View
     1726 * @param {!ScrollView} scrollView
     1727 */
     1728function ScrubbyScrollBar(scrollView) {
     1729    View.call(this, createElement("div", ScrubbyScrollBar.ClassNameScrubbyScrollBar));
     1730
     1731    /**
     1732     * @type {!Element}
     1733     * @const
     1734     */
     1735    this.thumb = createElement("div", ScrubbyScrollBar.ClassNameScrubbyScrollThumb);
     1736    this.element.appendChild(this.thumb);
     1737
     1738    /**
     1739     * @type {!ScrollView}
     1740     * @const
     1741     */
     1742    this.scrollView = scrollView;
     1743
     1744    /**
     1745     * @type {!number}
     1746     * @protected
     1747     */
     1748    this._height = 0;
     1749    /**
     1750     * @type {!number}
     1751     * @protected
     1752     */
     1753    this._thumbHeight = 0;
     1754    /**
     1755     * @type {!number}
     1756     * @protected
     1757     */
     1758    this._thumbPosition = 0;
     1759
     1760    this.setHeight(0);
     1761    this.setThumbHeight(ScrubbyScrollBar.ThumbHeight);
     1762
     1763    /**
     1764     * @type {?Animator}
     1765     * @protected
     1766     */
     1767    this._thumbStyleTopAnimator = null;
     1768
     1769    /**
     1770     * @type {?number}
     1771     * @protected
     1772     */
     1773    this._timer = null;
     1774   
     1775    this.element.addEventListener("mousedown", this.onMouseDown, false);
     1776}
     1777
     1778ScrubbyScrollBar.prototype = Object.create(View.prototype);
     1779
     1780ScrubbyScrollBar.ScrollInterval = 16;
     1781ScrubbyScrollBar.ThumbMargin = 2;
     1782ScrubbyScrollBar.ThumbHeight = 30;
     1783ScrubbyScrollBar.ClassNameScrubbyScrollBar = "scrubby-scroll-bar";
     1784ScrubbyScrollBar.ClassNameScrubbyScrollThumb = "scrubby-scroll-thumb";
     1785
     1786/**
     1787 * @return {!number} Height of the view in pixels.
     1788 */
     1789ScrubbyScrollBar.prototype.height = function() {
     1790    return this._height;
     1791};
     1792
     1793/**
     1794 * @param {!number} height Height of the view in pixels.
     1795 */
     1796ScrubbyScrollBar.prototype.setHeight = function(height) {
     1797    if (this._height === height)
     1798        return;
     1799    this._height = height;
     1800    this.element.style.height = this._height + "px";
     1801    this.thumb.style.top = ((this._height - this._thumbHeight) / 2) + "px";
     1802    this._thumbPosition = 0;
     1803};
     1804
     1805/**
     1806 * @param {!number} height Height of the scroll bar thumb in pixels.
     1807 */
     1808ScrubbyScrollBar.prototype.setThumbHeight = function(height) {
     1809    if (this._thumbHeight === height)
     1810        return;
     1811    this._thumbHeight = height;
     1812    this.thumb.style.height = this._thumbHeight + "px";
     1813    this.thumb.style.top = ((this._height - this._thumbHeight) / 2) + "px";
     1814    this._thumbPosition = 0;
     1815};
     1816
     1817/**
     1818 * @param {?Event} event
     1819 */
     1820ScrubbyScrollBar.prototype._setThumbPositionFromEvent = function(event) {
     1821    var thumbMin = ScrubbyScrollBar.ThumbMargin;
     1822    var thumbMax = this._height - this._thumbHeight - ScrubbyScrollBar.ThumbMargin * 2;
     1823    var y = event.clientY - this.element.getBoundingClientRect().top - this.element.clientTop + this.element.scrollTop;
     1824    var thumbPosition = y - this._thumbHeight / 2;
     1825    thumbPosition = Math.max(thumbPosition, thumbMin);
     1826    thumbPosition = Math.min(thumbPosition, thumbMax);
     1827    this.thumb.style.top = thumbPosition + "px";
     1828    this._thumbPosition = 1.0 - (thumbPosition - thumbMin) / (thumbMax - thumbMin) * 2;
     1829};
     1830
     1831/**
     1832 * @param {?Event} event
     1833 */
     1834ScrubbyScrollBar.prototype.onMouseDown = function(event) {
     1835    this._setThumbPositionFromEvent(event);
     1836
     1837    window.addEventListener("mousemove", this.onWindowMouseMove, false);
     1838    window.addEventListener("mouseup", this.onWindowMouseUp, false);
     1839    if (this._thumbStyleTopAnimator)
     1840        this._thumbStyleTopAnimator.stop();
     1841    this._timer = setInterval(this.onScrollTimer, ScrubbyScrollBar.ScrollInterval);
     1842};
     1843
     1844/**
     1845 * @param {?Event} event
     1846 */
     1847ScrubbyScrollBar.prototype.onWindowMouseMove = function(event) {
     1848    this._setThumbPositionFromEvent(event);
     1849};
     1850
     1851/**
     1852 * @param {?Event} event
     1853 */
     1854ScrubbyScrollBar.prototype.onWindowMouseUp = function(event) {
     1855    this._thumbStyleTopAnimator = new Animator();
     1856    this._thumbStyleTopAnimator.step = this.onThumbStyleTopAnimationStep;
     1857    this._thumbStyleTopAnimator.setFrom(this.thumb.offsetTop);
     1858    this._thumbStyleTopAnimator.setTo((this._height - this._thumbHeight) / 2);
     1859    this._thumbStyleTopAnimator.timingFunction = AnimationTimingFunction.EaseInOut;
     1860    this._thumbStyleTopAnimator.duration = 100;
     1861    this._thumbStyleTopAnimator.start();
     1862   
     1863    window.removeEventListener("mousemove", this.onWindowMouseMove, false);
     1864    window.removeEventListener("mouseup", this.onWindowMouseUp, false);
     1865    clearInterval(this._timer);
     1866};
     1867
     1868/**
     1869 * @param {!Animator} animator
     1870 */
     1871ScrubbyScrollBar.prototype.onThumbStyleTopAnimationStep = function(animator) {
     1872    this.thumb.style.top = animator.currentValue + "px";
     1873};
     1874
     1875ScrubbyScrollBar.prototype.onScrollTimer = function() {
     1876    var scrollAmount = Math.pow(this._thumbPosition, 2) * 10;
     1877    if (this._thumbPosition > 0)
     1878        scrollAmount = -scrollAmount;
     1879    this.scrollView.scrollBy(scrollAmount, false);
    17211880};
    17221881
Note: See TracChangeset for help on using the changeset viewer.