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 /** | 5 /** |
6 * Slide mode displays a single image and has a set of controls to navigate | 6 * Slide mode displays a single image and has a set of controls to navigate |
7 * between the images and to edit an image. | 7 * between the images and to edit an image. |
8 * | 8 * |
9 * @param {!HTMLElement} container Main container element. | 9 * @param {!HTMLElement} container Main container element. |
10 * @param {!HTMLElement} content Content container element. | 10 * @param {!HTMLElement} content Content container element. |
(...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1819 | 1819 |
1820 /** | 1820 /** |
1821 * Whether it is in a touch operation that is started from targetElement or | 1821 * Whether it is in a touch operation that is started from targetElement or |
1822 * not. | 1822 * not. |
1823 * @type {boolean} | 1823 * @type {boolean} |
1824 * @private | 1824 * @private |
1825 */ | 1825 */ |
1826 this.touchStarted_ = false; | 1826 this.touchStarted_ = false; |
1827 | 1827 |
1828 /** | 1828 /** |
1829 * Whether the element is being clicked now or not. | |
1830 * @type {boolean} | |
1831 * @private | |
1832 */ | |
1833 this.clickStarted_ = false; | |
1834 | |
1835 /** | |
1829 * The swipe action that should happen only once in an operation is already | 1836 * The swipe action that should happen only once in an operation is already |
1830 * done or not. | 1837 * done or not. |
1831 * @type {boolean} | 1838 * @type {boolean} |
1832 * @private | 1839 * @private |
1833 */ | 1840 */ |
1834 this.done_ = false; | 1841 this.done_ = false; |
1835 | 1842 |
1836 /** | 1843 /** |
1837 * Event on beginning of the current gesture. | 1844 * Event on beginning of the current gesture. |
1838 * The variable is updated when the number of touch finger changed. | 1845 * The variable is updated when the number of touch finger changed. |
(...skipping 21 matching lines...) Expand all Loading... | |
1860 * @type {number} | 1867 * @type {number} |
1861 * @private | 1868 * @private |
1862 */ | 1869 */ |
1863 this.lastZoom_ = 1.0; | 1870 this.lastZoom_ = 1.0; |
1864 | 1871 |
1865 targetElement.addEventListener('touchstart', this.onTouchStart_.bind(this)); | 1872 targetElement.addEventListener('touchstart', this.onTouchStart_.bind(this)); |
1866 var onTouchEventBound = this.onTouchEvent_.bind(this); | 1873 var onTouchEventBound = this.onTouchEvent_.bind(this); |
1867 targetElement.ownerDocument.addEventListener('touchmove', onTouchEventBound); | 1874 targetElement.ownerDocument.addEventListener('touchmove', onTouchEventBound); |
1868 targetElement.ownerDocument.addEventListener('touchend', onTouchEventBound); | 1875 targetElement.ownerDocument.addEventListener('touchend', onTouchEventBound); |
1869 | 1876 |
1877 targetElement.addEventListener('mousedown', this.onMouseDown_.bind(this)); | |
1878 targetElement.ownerDocument.addEventListener('mousemove', | |
1879 this.onMouseMove_.bind(this)); | |
1880 targetElement.ownerDocument.addEventListener('mouseup', | |
1881 this.onMouseUp_.bind(this)); | |
1870 targetElement.addEventListener('mousewheel', this.onMouseWheel_.bind(this)); | 1882 targetElement.addEventListener('mousewheel', this.onMouseWheel_.bind(this)); |
1871 } | 1883 } |
1872 | 1884 |
1873 /** | 1885 /** |
1874 * If the user touched the image and moved the finger more than SWIPE_THRESHOLD | 1886 * If the user touched the image and moved the finger more than SWIPE_THRESHOLD |
1875 * horizontally it's considered as a swipe gesture (change the current image). | 1887 * horizontally it's considered as a swipe gesture (change the current image). |
1876 * @type {number} | 1888 * @type {number} |
1877 * @const | 1889 * @const |
1878 */ | 1890 */ |
1879 TouchHandler.SWIPE_THRESHOLD = 100; | 1891 TouchHandler.SWIPE_THRESHOLD = 100; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2042 }; | 2054 }; |
2043 | 2055 |
2044 /** | 2056 /** |
2045 * Handles mouse wheel events. | 2057 * Handles mouse wheel events. |
2046 * @param {!Event} event Wheel event. | 2058 * @param {!Event} event Wheel event. |
2047 * @private | 2059 * @private |
2048 */ | 2060 */ |
2049 TouchHandler.prototype.onMouseWheel_ = function(event) { | 2061 TouchHandler.prototype.onMouseWheel_ = function(event) { |
2050 var event = assertInstanceof(event, MouseEvent); | 2062 var event = assertInstanceof(event, MouseEvent); |
2051 var viewport = this.slideMode_.getViewport(); | 2063 var viewport = this.slideMode_.getViewport(); |
2052 if (!this.enabled_ || !viewport.isZoomed()) | 2064 if (!this.enabled_) |
2053 return; | 2065 return; |
2066 | |
2054 this.stopOperation(); | 2067 this.stopOperation(); |
2068 this.lastZoom_ = viewport.getZoom(); | |
2069 var zoom = this.lastZoom_; | |
2070 if (event.wheelDeltaY > 0) { | |
2071 zoom = zoom * 1.05; | |
2072 } else { | |
2073 zoom = zoom / 1.05; | |
2074 } | |
2075 viewport.setZoom(zoom); | |
2076 this.slideMode_.imageView_.applyViewportChange(); | |
2077 }; | |
2078 | |
2079 /** | |
2080 * Handles mouse wheel events. | |
2081 * @param {!Event} event Wheel event. | |
2082 * @private | |
2083 */ | |
2084 TouchHandler.prototype.onMouseWheel_ = function(event) { | |
hirono
2016/02/06 07:27:59
nit: It looks we have two onMouseWheel_.
ryoh
2016/02/08 04:58:01
Done.
| |
2085 var event = assertInstanceof(event, MouseEvent); | |
2086 var viewport = this.slideMode_.getViewport(); | |
2087 if (!this.enabled_) | |
2088 return; | |
2089 | |
2090 this.stopOperation(); | |
2091 this.lastZoom_ = viewport.getZoom(); | |
2092 var zoom = this.lastZoom_; | |
2093 if (event.wheelDeltaY > 0) { | |
2094 zoom = zoom * 1.05; | |
2095 } else { | |
2096 zoom = zoom / 1.05; | |
2097 } | |
2098 viewport.setZoom(zoom); | |
2099 this.slideMode_.imageView_.applyViewportChange(); | |
2100 }; | |
2101 | |
2102 /** | |
2103 * Handles mouse down events. | |
2104 * @param {!Event} event Wheel event. | |
2105 * @private | |
2106 */ | |
2107 TouchHandler.prototype.onMouseDown_ = function(event) { | |
2108 var event = assertInstanceof(event, MouseEvent); | |
2109 var viewport = this.slideMode_.getViewport(); | |
2110 if (!this.enabled_) | |
2111 return; | |
2112 this.clickStarted_ = true; | |
2113 } | |
2114 | |
2115 /** | |
2116 * Handles mouse move events. | |
2117 * @param {!Event} event Wheel event. | |
2118 * @private | |
2119 */ | |
2120 TouchHandler.prototype.onMouseMove_ = function(event) { | |
2121 var event = assertInstanceof(event, MouseEvent); | |
2122 var viewport = this.slideMode_.getViewport(); | |
2123 if (!this.enabled_ || !this.clickStarted_) | |
2124 return; | |
2055 viewport.setOffset( | 2125 viewport.setOffset( |
2056 viewport.getOffsetX() + event.wheelDeltaX, | 2126 viewport.getOffsetX() + event.movementX, |
2057 viewport.getOffsetY() + event.wheelDeltaY); | 2127 viewport.getOffsetY() + event.movementY); |
2058 this.slideMode_.applyViewportChange(); | 2128 this.slideMode_.imageView_.applyViewportChange(); |
2059 }; | 2129 console.log(event); |
2130 } | |
2131 | |
2132 /** | |
2133 * Handles mouse up events. | |
2134 * @param {!Event} event Wheel event. | |
2135 * @private | |
2136 */ | |
2137 TouchHandler.prototype.onMouseUp_ = function(event) { | |
2138 this.clickStarted_ = false; | |
2139 } | |
OLD | NEW |