| 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 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 var pos = advance(this.savedSelection_.indexOf(this.getSelectedIndex()), | 917 var pos = advance(this.savedSelection_.indexOf(this.getSelectedIndex()), |
| 918 this.savedSelection_.length); | 918 this.savedSelection_.length); |
| 919 return this.savedSelection_[pos]; | 919 return this.savedSelection_[pos]; |
| 920 } else { | 920 } else { |
| 921 return advance(this.getSelectedIndex(), this.getItemCount_()); | 921 return advance(this.getSelectedIndex(), this.getItemCount_()); |
| 922 } | 922 } |
| 923 }; | 923 }; |
| 924 | 924 |
| 925 /** | 925 /** |
| 926 * Advance the selection based on the pressed key ID. | 926 * Advance the selection based on the pressed key ID. |
| 927 * @param {string} keyID Key identifier. | 927 * @param {string} keyID Key of the KeyboardEvent. |
| 928 */ | 928 */ |
| 929 SlideMode.prototype.advanceWithKeyboard = function(keyID) { | 929 SlideMode.prototype.advanceWithKeyboard = function(keyID) { |
| 930 var prev = (keyID === 'Up' || | 930 var prev = (keyID === 'ArrowUp' || |
| 931 keyID === 'Left' || | 931 keyID === 'ArrowLeft' || |
| 932 keyID === 'MediaPreviousTrack'); | 932 keyID === 'MediaTrackPrevious'); |
| 933 this.advanceManually(prev ? -1 : 1); | 933 this.advanceManually(prev ? -1 : 1); |
| 934 }; | 934 }; |
| 935 | 935 |
| 936 /** | 936 /** |
| 937 * Advance the selection as a result of a user action (as opposed to an | 937 * Advance the selection as a result of a user action (as opposed to an |
| 938 * automatic change in the slideshow mode). | 938 * automatic change in the slideshow mode). |
| 939 * @param {number} direction -1 for left, 1 for right. | 939 * @param {number} direction -1 for left, 1 for right. |
| 940 */ | 940 */ |
| 941 SlideMode.prototype.advanceManually = function(direction) { | 941 SlideMode.prototype.advanceManually = function(direction) { |
| 942 if (this.isSlideshowPlaying_()) | 942 if (this.isSlideshowPlaying_()) |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 } | 1135 } |
| 1136 }; | 1136 }; |
| 1137 | 1137 |
| 1138 /** | 1138 /** |
| 1139 * Keydown handler. | 1139 * Keydown handler. |
| 1140 * | 1140 * |
| 1141 * @param {!Event} event Event. | 1141 * @param {!Event} event Event. |
| 1142 * @return {boolean} True if handled. | 1142 * @return {boolean} True if handled. |
| 1143 */ | 1143 */ |
| 1144 SlideMode.prototype.onKeyDown = function(event) { | 1144 SlideMode.prototype.onKeyDown = function(event) { |
| 1145 var keyID = util.getKeyModifiers(event) + event.keyIdentifier; | 1145 var keyID = util.getKeyModifiers(event) + event.key; |
| 1146 | 1146 |
| 1147 if (this.isSlideshowOn_()) { | 1147 if (this.isSlideshowOn_()) { |
| 1148 switch (keyID) { | 1148 switch (keyID) { |
| 1149 case 'U+001B': // Escape | 1149 case 'Escape': |
| 1150 case 'MediaStop': | 1150 case 'MediaStop': |
| 1151 this.stopSlideshow_(event); | 1151 this.stopSlideshow_(event); |
| 1152 break; | 1152 break; |
| 1153 | 1153 |
| 1154 case 'U+0020': // Space pauses/resumes the slideshow. | 1154 case ' ': // Space pauses/resumes the slideshow. |
| 1155 case 'MediaPlayPause': | 1155 case 'MediaPlayPause': |
| 1156 this.toggleSlideshowPause_(); | 1156 this.toggleSlideshowPause_(); |
| 1157 break; | 1157 break; |
| 1158 | 1158 |
| 1159 case 'Up': | 1159 case 'ArrowUp': |
| 1160 case 'Down': | 1160 case 'ArrowDown': |
| 1161 case 'Left': | 1161 case 'ArrowLeft': |
| 1162 case 'Right': | 1162 case 'ArrowRight': |
| 1163 case 'MediaNextTrack': | 1163 case 'MediaTrackNex': |
| 1164 case 'MediaPreviousTrack': | 1164 case 'MediaTrackPrevious': |
| 1165 this.advanceWithKeyboard(keyID); | 1165 this.advanceWithKeyboard(keyID); |
| 1166 break; | 1166 break; |
| 1167 } | 1167 } |
| 1168 return true; // Consume all keystrokes in the slideshow mode. | 1168 return true; // Consume all keystrokes in the slideshow mode. |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 // Handles shortcut keys common for both modes (editing and not-editing). | 1171 // Handles shortcut keys common for both modes (editing and not-editing). |
| 1172 switch (keyID) { | 1172 switch (keyID) { |
| 1173 case 'Ctrl-U+0050': // Ctrl+'p' prints the current image. | 1173 case 'Ctrl-p': // Ctrl+'p' prints the current image. |
| 1174 if (!this.printButton_.disabled) | 1174 if (!this.printButton_.disabled) |
| 1175 this.print_(); | 1175 this.print_(); |
| 1176 return true; | 1176 return true; |
| 1177 | 1177 |
| 1178 case 'U+0045': // 'e' toggles the editor. | 1178 case 'e': // 'e' toggles the editor. |
| 1179 if (!this.editButton_.disabled) | 1179 if (!this.editButton_.disabled) |
| 1180 this.toggleEditor(event); | 1180 this.toggleEditor(event); |
| 1181 return true; | 1181 return true; |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 // Handles shortcurt keys for editing mode. | 1184 // Handles shortcurt keys for editing mode. |
| 1185 if (this.isEditing()) { | 1185 if (this.isEditing()) { |
| 1186 if (this.editor_.onKeyDown(event)) | 1186 if (this.editor_.onKeyDown(event)) |
| 1187 return true; | 1187 return true; |
| 1188 | 1188 |
| 1189 if (keyID === 'U+001B') { // Escape | 1189 if (keyID === 'Escape') { // Escape |
| 1190 this.toggleEditor(event); | 1190 this.toggleEditor(event); |
| 1191 return true; | 1191 return true; |
| 1192 } | 1192 } |
| 1193 | 1193 |
| 1194 return false; | 1194 return false; |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 // Handles shortcut keys for not-editing mode. | 1197 // Handles shortcut keys for not-editing mode. |
| 1198 switch (keyID) { | 1198 switch (keyID) { |
| 1199 case 'U+001B': // Escape | 1199 case 'Escape': |
| 1200 if (this.viewport_.isZoomed()) { | 1200 if (this.viewport_.isZoomed()) { |
| 1201 this.viewport_.resetView(); | 1201 this.viewport_.resetView(); |
| 1202 this.touchHandlers_.stopOperation(); | 1202 this.touchHandlers_.stopOperation(); |
| 1203 this.imageView_.applyViewportChange(); | 1203 this.imageView_.applyViewportChange(); |
| 1204 return true; | 1204 return true; |
| 1205 } | 1205 } |
| 1206 break; | 1206 break; |
| 1207 | 1207 |
| 1208 case 'Home': | 1208 case 'Home': |
| 1209 this.selectFirst(); | 1209 this.selectFirst(); |
| 1210 return true; | 1210 return true; |
| 1211 | 1211 |
| 1212 case 'End': | 1212 case 'End': |
| 1213 this.selectLast(); | 1213 this.selectLast(); |
| 1214 return true; | 1214 return true; |
| 1215 | 1215 |
| 1216 case 'Up': | 1216 case 'ArrowUp': |
| 1217 case 'Down': | 1217 case 'ArrowDown': |
| 1218 case 'Left': | 1218 case 'ArrowLeft': |
| 1219 case 'Right': | 1219 case 'ArrowRight': |
| 1220 if (this.viewport_.isZoomed()) { | 1220 if (this.viewport_.isZoomed()) { |
| 1221 var delta = SlideMode.KEY_OFFSET_MAP[keyID]; | 1221 var delta = SlideMode.KEY_OFFSET_MAP[keyID]; |
| 1222 this.viewport_.setOffset( | 1222 this.viewport_.setOffset( |
| 1223 ~~(this.viewport_.getOffsetX() + | 1223 ~~(this.viewport_.getOffsetX() + |
| 1224 delta[0] * this.viewport_.getZoom()), | 1224 delta[0] * this.viewport_.getZoom()), |
| 1225 ~~(this.viewport_.getOffsetY() + | 1225 ~~(this.viewport_.getOffsetY() + |
| 1226 delta[1] * this.viewport_.getZoom())); | 1226 delta[1] * this.viewport_.getZoom())); |
| 1227 this.touchHandlers_.stopOperation(); | 1227 this.touchHandlers_.stopOperation(); |
| 1228 this.imageView_.applyViewportChange(); | 1228 this.imageView_.applyViewportChange(); |
| 1229 } else { | 1229 } else { |
| 1230 this.advanceWithKeyboard(keyID); | 1230 this.advanceWithKeyboard(keyID); |
| 1231 } | 1231 } |
| 1232 return true; | 1232 return true; |
| 1233 | 1233 |
| 1234 case 'MediaNextTrack': | 1234 case 'MediaTrackNext': |
| 1235 case 'MediaPreviousTrack': | 1235 case 'MediaTrackPrevious': |
| 1236 this.advanceWithKeyboard(keyID); | 1236 this.advanceWithKeyboard(keyID); |
| 1237 return true; | 1237 return true; |
| 1238 | 1238 |
| 1239 case 'Ctrl-U+00BB': // Ctrl+'=' zoom in. | 1239 case 'Ctrl-=': // Ctrl+'=' zoom in. |
| 1240 this.viewport_.zoomIn(); | 1240 this.viewport_.zoomIn(); |
| 1241 this.touchHandlers_.stopOperation(); | 1241 this.touchHandlers_.stopOperation(); |
| 1242 this.imageView_.applyViewportChange(); | 1242 this.imageView_.applyViewportChange(); |
| 1243 return true; | 1243 return true; |
| 1244 | 1244 |
| 1245 case 'Ctrl-U+00BD': // Ctrl+'-' zoom out. | 1245 case 'Ctrl--': // Ctrl+'-' zoom out. |
| 1246 this.viewport_.zoomOut(); | 1246 this.viewport_.zoomOut(); |
| 1247 this.touchHandlers_.stopOperation(); | 1247 this.touchHandlers_.stopOperation(); |
| 1248 this.imageView_.applyViewportChange(); | 1248 this.imageView_.applyViewportChange(); |
| 1249 return true; | 1249 return true; |
| 1250 | 1250 |
| 1251 case 'Ctrl-U+0030': // Ctrl+'0' zoom reset. | 1251 case 'Ctrl-0': // Ctrl+'0' zoom reset. |
| 1252 this.viewport_.setZoom(1.0); | 1252 this.viewport_.setZoom(1.0); |
| 1253 this.touchHandlers_.stopOperation(); | 1253 this.touchHandlers_.stopOperation(); |
| 1254 this.imageView_.applyViewportChange(); | 1254 this.imageView_.applyViewportChange(); |
| 1255 return true; | 1255 return true; |
| 1256 } | 1256 } |
| 1257 | 1257 |
| 1258 return false; | 1258 return false; |
| 1259 }; | 1259 }; |
| 1260 | 1260 |
| 1261 /** | 1261 /** |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 /** | 2133 /** |
| 2134 * Handles mouse up events. | 2134 * Handles mouse up events. |
| 2135 * @param {!Event} event Wheel event. | 2135 * @param {!Event} event Wheel event. |
| 2136 * @private | 2136 * @private |
| 2137 */ | 2137 */ |
| 2138 TouchHandler.prototype.onMouseUp_ = function(event) { | 2138 TouchHandler.prototype.onMouseUp_ = function(event) { |
| 2139 if (event.button !== 0) | 2139 if (event.button !== 0) |
| 2140 return; | 2140 return; |
| 2141 this.clickStarted_ = false; | 2141 this.clickStarted_ = false; |
| 2142 }; | 2142 }; |
| OLD | NEW |