(currentZoom, steps)
| 208 | } |
| 209 | |
| 210 | function nextZoomLevel(currentZoom, steps) { |
| 211 | // Chrome's default zoom levels. |
| 212 | const chromeLevels = [0.25, 0.33, 0.5, 0.75, 0.8, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5]; |
| 213 | // Firefox's default zoom levels. |
| 214 | const firefoxLevels = [0.3, 0.5, 0.67, 0.8, 0.9, 1, 1.1, 1.2, 1.33, 1.5, 1.7, 2, 2.4, 3, 4, 5]; |
| 215 | |
| 216 | let zoomLevels = chromeLevels; // Chrome by default |
| 217 | if (bgUtils.isFirefox()) { |
| 218 | zoomLevels = firefoxLevels; |
| 219 | } |
| 220 | |
| 221 | if (steps === 0) { // Nothing |
| 222 | return currentZoom; |
| 223 | } else if (steps > 0) { // In |
| 224 | // Chrome sometimes returns values with floating point errors. |
| 225 | // Example: Chrome gives 0.32999999999999996 instead of 0.33. |
| 226 | currentZoom += 0.0000001; // This is needed to solve floating point bugs in Chrome. |
| 227 | const nextIndex = zoomLevels.findIndex((level) => level > currentZoom); |
| 228 | const floorIndex = nextIndex == -1 ? zoomLevels.length : nextIndex - 1; |
| 229 | return zoomLevels[Math.min(zoomLevels.length - 1, floorIndex + steps)]; |
| 230 | } else if (steps < 0) { // Out |
| 231 | currentZoom -= 0.0000001; // This is needed to solve floating point bugs in Chrome. |
| 232 | let ceilIndex = zoomLevels.findIndex((level) => level >= currentZoom); |
| 233 | ceilIndex = ceilIndex == -1 ? zoomLevels.length : ceilIndex; |
| 234 | return zoomLevels[Math.max(0, ceilIndex + steps)]; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // These are commands which are bound to keystrokes which must be handled by the background page. |
| 239 | // They are mapped in commands.js. |
no outgoing calls
no test coverage detected