| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * Abstract parent of classes that manage updating the browser | 8 * Abstract parent of classes that manage updating the browser |
| 9 * with zoom changes and/or updating the viewer's zoom when | 9 * with zoom changes and/or updating the viewer's zoom when |
| 10 * the browser zoom changes. | 10 * the browser zoom changes. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 * @param {number} a The first number. | 79 * @param {number} a The first number. |
| 80 * @param {number} b The second number. | 80 * @param {number} b The second number. |
| 81 */ | 81 */ |
| 82 floatingPointEquals(a, b) { | 82 floatingPointEquals(a, b) { |
| 83 let MIN_ZOOM_DELTA = 0.01; | 83 let MIN_ZOOM_DELTA = 0.01; |
| 84 // If the zoom level is close enough to the current zoom level, don't | 84 // If the zoom level is close enough to the current zoom level, don't |
| 85 // change it. This avoids us getting into an infinite loop of zoom changes | 85 // change it. This avoids us getting into an infinite loop of zoom changes |
| 86 // due to floating point error. | 86 // due to floating point error. |
| 87 return Math.abs(a - b) <= MIN_ZOOM_DELTA; | 87 return Math.abs(a - b) <= MIN_ZOOM_DELTA; |
| 88 } | 88 } |
| 89 }; | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * InactiveZoomManager has no control over the browser's zoom | 92 * InactiveZoomManager has no control over the browser's zoom |
| 93 * and does not respond to browser zoom changes. | 93 * and does not respond to browser zoom changes. |
| 94 */ | 94 */ |
| 95 class InactiveZoomManager extends ZoomManager {}; | 95 class InactiveZoomManager extends ZoomManager {} |
| 96 | 96 |
| 97 /** | 97 /** |
| 98 * ActiveZoomManager controls the browser's zoom. | 98 * ActiveZoomManager controls the browser's zoom. |
| 99 */ | 99 */ |
| 100 class ActiveZoomManager extends ZoomManager { | 100 class ActiveZoomManager extends ZoomManager { |
| 101 /** | 101 /** |
| 102 * Constructs a ActiveZoomManager. | 102 * Constructs a ActiveZoomManager. |
| 103 * @param {!Viewport} viewport A Viewport for which to manage zoom. | 103 * @param {!Viewport} viewport A Viewport for which to manage zoom. |
| 104 * @param {Function} setBrowserZoomFunction A function that sets the browser | 104 * @param {Function} setBrowserZoomFunction A function that sets the browser |
| 105 * zoom to the provided value. | 105 * zoom to the provided value. |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 * Given a zoom level, return the internal zoom level needed to | 173 * Given a zoom level, return the internal zoom level needed to |
| 174 * produce that zoom level. | 174 * produce that zoom level. |
| 175 * @param {number} totalZoom the total zoom level. | 175 * @param {number} totalZoom the total zoom level. |
| 176 * @return {number} the zoom level internal to the viewer. | 176 * @return {number} the zoom level internal to the viewer. |
| 177 */ | 177 */ |
| 178 internalZoomComponent(totalZoom) { | 178 internalZoomComponent(totalZoom) { |
| 179 // The internal zoom and browser zoom are changed together, so the | 179 // The internal zoom and browser zoom are changed together, so the |
| 180 // internal zoom is the total zoom. | 180 // internal zoom is the total zoom. |
| 181 return totalZoom; | 181 return totalZoom; |
| 182 } | 182 } |
| 183 }; | 183 } |
| 184 | 184 |
| 185 /** | 185 /** |
| 186 * This EmbeddedZoomManager responds to changes in the browser zoom, | 186 * This EmbeddedZoomManager responds to changes in the browser zoom, |
| 187 * but does not control the browser zoom. | 187 * but does not control the browser zoom. |
| 188 */ | 188 */ |
| 189 class EmbeddedZoomManager extends ZoomManager { | 189 class EmbeddedZoomManager extends ZoomManager { |
| 190 /** | 190 /** |
| 191 * Invoked when a browser-initiated zoom-level change occurs. | 191 * Invoked when a browser-initiated zoom-level change occurs. |
| 192 * @param {number} newZoom the new browser zoom level. | 192 * @param {number} newZoom the new browser zoom level. |
| 193 */ | 193 */ |
| 194 onBrowserZoomChange(newZoom) { | 194 onBrowserZoomChange(newZoom) { |
| 195 let oldZoom = this.browserZoom_; | 195 let oldZoom = this.browserZoom_; |
| 196 this.browserZoom_ = newZoom; | 196 this.browserZoom_ = newZoom; |
| 197 this.viewport_.updateZoomFromBrowserChange(oldZoom); | 197 this.viewport_.updateZoomFromBrowserChange(oldZoom); |
| 198 } | 198 } |
| 199 }; | 199 } |
| OLD | NEW |