Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: ui/file_manager/gallery/js/slide_mode.js

Issue 398283002: Gallery: Add the offset feature in the slide mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/viewport.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * Slide mode displays a single image and has a set of controls to navigate 8 * Slide mode displays a single image and has a set of controls to navigate
9 * between the images and to edit an image. 9 * between the images and to edit an image.
10 * 10 *
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Unique numeric key, incremented per each load attempt used to discard 42 // Unique numeric key, incremented per each load attempt used to discard
43 // old attempts. This can happen especially when changing selection fast or 43 // old attempts. This can happen especially when changing selection fast or
44 // Internet connection is slow. 44 // Internet connection is slow.
45 this.currentUniqueKey_ = 0; 45 this.currentUniqueKey_ = 0;
46 46
47 this.initListeners_(); 47 this.initListeners_();
48 this.initDom_(); 48 this.initDom_();
49 } 49 }
50 50
51 /** 51 /**
52 * SlideMode extends cr.EventTarget.
53 */
54 SlideMode.prototype.__proto__ = cr.EventTarget.prototype;
55
56 /**
57 * List of available editor modes. 52 * List of available editor modes.
58 * @type {Array.<ImageEditor.Mode>} 53 * @type {Array.<ImageEditor.Mode>}
54 * @const
59 */ 55 */
60 SlideMode.editorModes = [ 56 SlideMode.EDITOR_MODES = Object.freeze([
61 new ImageEditor.Mode.InstantAutofix(), 57 new ImageEditor.Mode.InstantAutofix(),
62 new ImageEditor.Mode.Crop(), 58 new ImageEditor.Mode.Crop(),
63 new ImageEditor.Mode.Exposure(), 59 new ImageEditor.Mode.Exposure(),
64 new ImageEditor.Mode.OneClick( 60 new ImageEditor.Mode.OneClick(
65 'rotate_left', 'GALLERY_ROTATE_LEFT', new Command.Rotate(-1)), 61 'rotate_left', 'GALLERY_ROTATE_LEFT', new Command.Rotate(-1)),
66 new ImageEditor.Mode.OneClick( 62 new ImageEditor.Mode.OneClick(
67 'rotate_right', 'GALLERY_ROTATE_RIGHT', new Command.Rotate(1)) 63 'rotate_right', 'GALLERY_ROTATE_RIGHT', new Command.Rotate(1))
68 ]; 64 ]);
65
66 /**
67 * Map of the key identifier and offset delta.
68 * @type {Object.<string, Array.<number>})
69 * @const
70 */
71 SlideMode.KEY_OFFSET_MAP = Object.freeze({
72 'Up': Object.freeze([0, 20]),
73 'Down': Object.freeze([0, -20]),
74 'Left': Object.freeze([20, 0]),
75 'Right': Object.freeze([-20, 0])
76 });
77
78 /**
79 * SlideMode extends cr.EventTarget.
80 */
81 SlideMode.prototype.__proto__ = cr.EventTarget.prototype;
69 82
70 /** 83 /**
71 * @return {string} Mode name. 84 * @return {string} Mode name.
72 */ 85 */
73 SlideMode.prototype.getName = function() { return 'slide'; }; 86 SlideMode.prototype.getName = function() { return 'slide'; };
74 87
75 /** 88 /**
76 * @return {string} Mode title. 89 * @return {string} Mode title.
77 */ 90 */
78 SlideMode.prototype.getTitle = function() { return 'GALLERY_SLIDE'; }; 91 SlideMode.prototype.getTitle = function() { return 'GALLERY_SLIDE'; };
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 this.editor_ = new ImageEditor( 222 this.editor_ = new ImageEditor(
210 this.viewport_, 223 this.viewport_,
211 this.imageView_, 224 this.imageView_,
212 this.prompt_, 225 this.prompt_,
213 { 226 {
214 root: this.container_, 227 root: this.container_,
215 image: this.imageContainer_, 228 image: this.imageContainer_,
216 toolbar: this.editBarMain_, 229 toolbar: this.editBarMain_,
217 mode: this.editBarModeWrapper_ 230 mode: this.editBarModeWrapper_
218 }, 231 },
219 SlideMode.editorModes, 232 SlideMode.EDITOR_MODES,
220 this.displayStringFunction_, 233 this.displayStringFunction_,
221 this.onToolsVisibilityChanged_.bind(this)); 234 this.onToolsVisibilityChanged_.bind(this));
222 235
223 this.editor_.getBuffer().addOverlay( 236 this.editor_.getBuffer().addOverlay(
224 new SwipeOverlay(this.advanceManually.bind(this))); 237 new SwipeOverlay(this.advanceManually.bind(this)));
225 }; 238 };
226 239
227 /** 240 /**
228 * Load items, display the selected item. 241 * Load items, display the selected item.
229 * @param {Rect} zoomFromRect Rectangle for zoom effect. 242 * @param {Rect} zoomFromRect Rectangle for zoom effect.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 this.dataModel_.removeEventListener('splice', this.onSpliceBound_); 340 this.dataModel_.removeEventListener('splice', this.onSpliceBound_);
328 this.dataModel_.removeEventListener('content', this.onContentBound_); 341 this.dataModel_.removeEventListener('content', this.onContentBound_);
329 this.ribbon_.disable(); 342 this.ribbon_.disable();
330 this.active_ = false; 343 this.active_ = false;
331 if (this.savedSelection_) 344 if (this.savedSelection_)
332 this.selectionModel_.selectedIndexes = this.savedSelection_; 345 this.selectionModel_.selectedIndexes = this.savedSelection_;
333 this.unloadImage_(zoomToRect); 346 this.unloadImage_(zoomToRect);
334 callback(); 347 callback();
335 }.bind(this); 348 }.bind(this);
336 349
337 this.viewport_.setZoomIndex(0); 350 this.viewport_.resetView();
338 if (this.getItemCount_() === 0) { 351 if (this.getItemCount_() === 0) {
339 this.showErrorBanner_(false); 352 this.showErrorBanner_(false);
340 commitDone(); 353 commitDone();
341 } else { 354 } else {
342 this.commitItem_(commitDone); 355 this.commitItem_(commitDone);
343 } 356 }
344 357
345 // Disable the slide-mode only buttons when leaving. 358 // Disable the slide-mode only buttons when leaving.
346 this.editButton_.setAttribute('disabled', ''); 359 this.editButton_.setAttribute('disabled', '');
347 this.printButton_.setAttribute('disabled', ''); 360 this.printButton_.setAttribute('disabled', '');
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 if (!this.printButton_.hasAttribute('disabled')) 852 if (!this.printButton_.hasAttribute('disabled'))
840 this.print_(); 853 this.print_();
841 break; 854 break;
842 855
843 case 'U+0045': // 'e' toggles the editor. 856 case 'U+0045': // 'e' toggles the editor.
844 if (!this.editButton_.hasAttribute('disabled')) 857 if (!this.editButton_.hasAttribute('disabled'))
845 this.toggleEditor(event); 858 this.toggleEditor(event);
846 break; 859 break;
847 860
848 case 'U+001B': // Escape 861 case 'U+001B': // Escape
849 if (!this.isEditing()) 862 if (this.isEditing()) {
863 this.toggleEditor(event);
864 } else if (this.viewport_.getZoomIndex() !== 0) {
865 this.viewport_.resetView();
866 this.imageView_.applyViewportChange();
867 } else {
850 return false; // Not handled. 868 return false; // Not handled.
851 this.toggleEditor(event); 869 }
852 break; 870 break;
853 871
854 case 'Home': 872 case 'Home':
855 this.selectFirst(); 873 this.selectFirst();
856 break; 874 break;
857 case 'End': 875 case 'End':
858 this.selectLast(); 876 this.selectLast();
859 break; 877 break;
860 case 'Up': 878 case 'Up':
861 case 'Down': 879 case 'Down':
862 case 'Left': 880 case 'Left':
863 case 'Right': 881 case 'Right':
882 if (!this.isEditing() && this.viewport_.getZoomIndex() !== 0) {
883 var delta = SlideMode.KEY_OFFSET_MAP[keyID];
884 this.viewport_.setOffset(
885 ~~(this.viewport_.getOffsetX() +
886 delta[0] * this.viewport_.getZoom()),
887 ~~(this.viewport_.getOffsetY() +
888 delta[1] * this.viewport_.getZoom()),
889 true);
890 this.imageView_.applyViewportChange();
891 } else {
892 this.advanceWithKeyboard(keyID);
893 }
894 break;
864 case 'MediaNextTrack': 895 case 'MediaNextTrack':
865 case 'MediaPreviousTrack': 896 case 'MediaPreviousTrack':
866 this.advanceWithKeyboard(keyID); 897 this.advanceWithKeyboard(keyID);
867 break; 898 break;
868 899
869 case 'Ctrl-U+00BB': // Ctrl+'=' zoom in. 900 case 'Ctrl-U+00BB': // Ctrl+'=' zoom in.
870 if (!this.isEditing()) { 901 if (!this.isEditing()) {
871 this.viewport_.setZoomIndex(this.viewport_.getZoomIndex() + 1); 902 this.viewport_.setZoomIndex(this.viewport_.getZoomIndex() + 1);
872 this.imageView_.applyViewportChange(); 903 this.imageView_.applyViewportChange();
873 } 904 }
874 break; 905 break;
875 906
876 case 'Ctrl-U+00BD': // Ctrl+'-' zoom out. 907 case 'Ctrl-U+00BD': // Ctrl+'-' zoom out.
877 if (!this.isEditing()) { 908 if (!this.isEditing()) {
878 this.viewport_.setZoomIndex(this.viewport_.getZoomIndex() - 1); 909 this.viewport_.setZoomIndex(this.viewport_.getZoomIndex() - 1);
879 this.imageView_.applyViewportChange(); 910 this.imageView_.applyViewportChange();
880 } 911 }
881 break; 912 break;
913
914 case 'Ctrl-U+0030': // Ctrl+'0' zoom reset.
915 if (!this.isEditing()) {
916 this.viewport_.resetView();
917 this.imageView_.applyViewportChange();
918 }
919 break;
882 } 920 }
883 921
884 return true; 922 return true;
885 }; 923 };
886 924
887 /** 925 /**
888 * Resize handler. 926 * Resize handler.
889 * @private 927 * @private
890 */ 928 */
891 SlideMode.prototype.onResize_ = function() { 929 SlideMode.prototype.onResize_ = function() {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 return this.container_.hasAttribute('slideshow'); 1077 return this.container_.hasAttribute('slideshow');
1040 }; 1078 };
1041 1079
1042 /** 1080 /**
1043 * Start the slideshow. 1081 * Start the slideshow.
1044 * @param {number=} opt_interval First interval in ms. 1082 * @param {number=} opt_interval First interval in ms.
1045 * @param {Event=} opt_event Event. 1083 * @param {Event=} opt_event Event.
1046 */ 1084 */
1047 SlideMode.prototype.startSlideshow = function(opt_interval, opt_event) { 1085 SlideMode.prototype.startSlideshow = function(opt_interval, opt_event) {
1048 // Reset zoom. 1086 // Reset zoom.
1049 this.viewport_.setZoomIndex(0); 1087 this.viewport_.resetView();
1050 this.imageView_.applyViewportChange(); 1088 this.imageView_.applyViewportChange();
1051 1089
1052 // Set the attribute early to prevent the toolbar from flashing when 1090 // Set the attribute early to prevent the toolbar from flashing when
1053 // the slideshow is being started from the mosaic view. 1091 // the slideshow is being started from the mosaic view.
1054 this.container_.setAttribute('slideshow', 'playing'); 1092 this.container_.setAttribute('slideshow', 'playing');
1055 1093
1056 if (this.active_) { 1094 if (this.active_) {
1057 this.stopEditing_(); 1095 this.stopEditing_();
1058 } else { 1096 } else {
1059 // We are in the Mosaic mode. Toggle the mode but remember to return. 1097 // We are in the Mosaic mode. Toggle the mode but remember to return.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 this.toggleMode_(this.toggleEditor.bind(this)); 1232 this.toggleMode_(this.toggleEditor.bind(this));
1195 return; 1233 return;
1196 } 1234 }
1197 1235
1198 this.stopSlideshow_(); 1236 this.stopSlideshow_();
1199 1237
1200 ImageUtil.setAttribute(this.container_, 'editing', !this.isEditing()); 1238 ImageUtil.setAttribute(this.container_, 'editing', !this.isEditing());
1201 1239
1202 if (this.isEditing()) { // isEditing has just been flipped to a new value. 1240 if (this.isEditing()) { // isEditing has just been flipped to a new value.
1203 // Reset zoom. 1241 // Reset zoom.
1204 this.viewport_.setZoomIndex(0); 1242 this.viewport_.resetView();
1205 this.imageView_.applyViewportChange(); 1243 this.imageView_.applyViewportChange();
1206 if (this.context_.readonlyDirName) { 1244 if (this.context_.readonlyDirName) {
1207 this.editor_.getPrompt().showAt( 1245 this.editor_.getPrompt().showAt(
1208 'top', 'GALLERY_READONLY_WARNING', 0, this.context_.readonlyDirName); 1246 'top', 'GALLERY_READONLY_WARNING', 0, this.context_.readonlyDirName);
1209 } 1247 }
1210 } else { 1248 } else {
1211 this.editor_.getPrompt().hide(); 1249 this.editor_.getPrompt().hide();
1212 this.editor_.leaveModeGently(); 1250 this.editor_.leaveModeGently();
1213 } 1251 }
1214 }; 1252 };
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 done = true; 1330 done = true;
1293 } 1331 }
1294 }.bind(this); 1332 }.bind(this);
1295 }; 1333 };
1296 1334
1297 /** 1335 /**
1298 * If the user touched the image and moved the finger more than SWIPE_THRESHOLD 1336 * If the user touched the image and moved the finger more than SWIPE_THRESHOLD
1299 * horizontally it's considered as a swipe gesture (change the current image). 1337 * horizontally it's considered as a swipe gesture (change the current image).
1300 */ 1338 */
1301 SwipeOverlay.SWIPE_THRESHOLD = 100; 1339 SwipeOverlay.SWIPE_THRESHOLD = 100;
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/viewport.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698