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

Side by Side Diff: chrome/browser/resources/file_manager/js/image_editor/gallery.js

Issue 10107020: [filemanager] New visuals for file name, saved and overwrite original UI elemetns in image editor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Style. Created 8 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 * Base class that Ribbon uses to display photos. 6 * Base class that Ribbon uses to display photos.
7 */ 7 */
8 8
9 function RibbonClient() {} 9 function RibbonClient() {}
10 10
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 this.filenameEdit_.blur(); 123 this.filenameEdit_.blur();
124 if (this.isShowingVideo_()) 124 if (this.isShowingVideo_())
125 this.mediaControls_.togglePlayStateWithFeedback(); 125 this.mediaControls_.togglePlayStateWithFeedback();
126 }).bind(this)); 126 }).bind(this));
127 this.container_.appendChild(this.imageContainer_); 127 this.container_.appendChild(this.imageContainer_);
128 128
129 this.toolbar_ = doc.createElement('div'); 129 this.toolbar_ = doc.createElement('div');
130 this.toolbar_.className = 'toolbar tool dimmable'; 130 this.toolbar_.className = 'toolbar tool dimmable';
131 this.container_.appendChild(this.toolbar_); 131 this.container_.appendChild(this.toolbar_);
132 132
133 var filenameSpacer = doc.createElement('div'); 133 this.filenameSpacer_ = doc.createElement('div');
134 filenameSpacer.className = 'filename-spacer'; 134 this.filenameSpacer_.className = 'filename-spacer';
135 this.toolbar_.appendChild(filenameSpacer); 135 this.toolbar_.appendChild(this.filenameSpacer_);
136
137 var nameBox = doc.createElement('div');
138 nameBox.className = 'namebox';
139 this.filenameSpacer_.appendChild(nameBox);
136 140
137 this.filenameText_ = doc.createElement('div'); 141 this.filenameText_ = doc.createElement('div');
138 this.filenameText_.className = 'name';
139 this.filenameText_.addEventListener('click', 142 this.filenameText_.addEventListener('click',
140 this.onFilenameClick_.bind(this)); 143 this.onFilenameClick_.bind(this));
141 filenameSpacer.appendChild(this.filenameText_); 144 nameBox.appendChild(this.filenameText_);
142 145
143 this.filenameEdit_ = doc.createElement('input'); 146 this.filenameEdit_ = doc.createElement('input');
144 this.filenameEdit_.setAttribute('type', 'text'); 147 this.filenameEdit_.setAttribute('type', 'text');
145 this.filenameEdit_.addEventListener('blur', 148 this.filenameEdit_.addEventListener('blur',
146 this.onFilenameEditBlur_.bind(this)); 149 this.onFilenameEditBlur_.bind(this));
147 this.filenameEdit_.addEventListener('keydown', 150 this.filenameEdit_.addEventListener('keydown',
148 this.onFilenameEditKeydown_.bind(this)); 151 this.onFilenameEditKeydown_.bind(this));
149 filenameSpacer.appendChild(this.filenameEdit_); 152 nameBox.appendChild(this.filenameEdit_);
150 153
151 var options = doc.createElement('div'); 154 var options = doc.createElement('div');
152 options.className = 'options'; 155 options.className = 'options';
153 filenameSpacer.appendChild(options); 156 this.filenameSpacer_.appendChild(options);
154 157
155 this.savedLabel_ = doc.createElement('div'); 158 this.savedLabel_ = doc.createElement('div');
156 this.savedLabel_.className = 'saved'; 159 this.savedLabel_.className = 'saved';
157 this.savedLabel_.textContent = this.displayStringFunction_('saved'); 160 this.savedLabel_.textContent = this.displayStringFunction_('saved');
158 options.appendChild(this.savedLabel_); 161 options.appendChild(this.savedLabel_);
159 162
160 this.keepOriginal_ = doc.createElement('div'); 163 var overwriteOriginalBox = doc.createElement('div');
161 this.keepOriginal_.className = 'keep-original'; 164 overwriteOriginalBox.className = 'overwrite-original';
162 this.keepOriginal_.textContent = this.displayStringFunction_('keep_original'); 165 options.appendChild(overwriteOriginalBox);
163 this.keepOriginal_.addEventListener('click', 166
164 this.onKeepOriginalClick_.bind(this)); 167 this.overwriteOriginal_ = doc.createElement('input');
165 options.appendChild(this.keepOriginal_); 168 this.overwriteOriginal_.type = 'checkbox';
169 this.overwriteOriginal_.id = 'overwrite-checkbox';
170 this.overwriteOriginal_.className = 'common';
171 this.overwriteOriginal_.setAttribute('white', 'true');
172 overwriteOriginalBox.appendChild(this.overwriteOriginal_);
173 this.overwriteOriginal_.addEventListener('click',
174 this.onOverwriteOriginalClick_.bind(this));
175
176 var overwriteLabel = doc.createElement('label');
177 overwriteLabel.textContent =
178 this.displayStringFunction_('overwrite_original');
179 overwriteLabel.setAttribute('for', 'overwrite-checkbox');
180 overwriteOriginalBox.appendChild(overwriteLabel);
166 181
167 this.buttonSpacer_ = doc.createElement('div'); 182 this.buttonSpacer_ = doc.createElement('div');
168 this.buttonSpacer_.className = 'button-spacer'; 183 this.buttonSpacer_.className = 'button-spacer';
169 this.toolbar_.appendChild(this.buttonSpacer_); 184 this.toolbar_.appendChild(this.buttonSpacer_);
170 185
171 this.ribbonSpacer_ = doc.createElement('div'); 186 this.ribbonSpacer_ = doc.createElement('div');
172 this.ribbonSpacer_.className = 'ribbon-spacer'; 187 this.ribbonSpacer_.className = 'ribbon-spacer';
173 this.toolbar_.appendChild(this.ribbonSpacer_); 188 this.toolbar_.appendChild(this.ribbonSpacer_);
174 189
175 this.mediaSpacer_ = doc.createElement('div'); 190 this.mediaSpacer_ = doc.createElement('div');
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } else { 368 } else {
354 this.shareMode_ = null; 369 this.shareMode_ = null;
355 } 370 }
356 }.bind(this)); 371 }.bind(this));
357 }; 372 };
358 373
359 Gallery.prototype.onImageContentChanged_ = function() { 374 Gallery.prototype.onImageContentChanged_ = function() {
360 this.imageChanges_++; 375 this.imageChanges_++;
361 if (this.imageChanges_ == 0) return; 376 if (this.imageChanges_ == 0) return;
362 if (this.imageChanges_ == 1) { // First edit 377 if (this.imageChanges_ == 1) { // First edit
363 this.keepOriginal_.setAttribute('visible', 'true'); 378 this.filenameSpacer_.setAttribute('saved', 'saved');
364 this.savedLabel_.style.display = 'inline-block'; 379 this.filenameSpacer_.setAttribute('overwrite', 'overwrite');
380 this.overwriteOriginal_.checked = true;
365 ImageUtil.metrics.recordUserAction(ImageUtil.getMetricName('Edit')); 381 ImageUtil.metrics.recordUserAction(ImageUtil.getMetricName('Edit'));
366 } 382 }
367 var label = this.savedLabel_; 383 var label = this.savedLabel_;
368 setTimeout(function(){ label.setAttribute('highlighted', 'true'); }, 0); 384 setTimeout(function(){ label.setAttribute('highlighted', 'true'); }, 0);
369 setTimeout(function(){ label.removeAttribute('highlighted'); }, 300); 385 setTimeout(function(){ label.removeAttribute('highlighted'); }, 300);
370 }; 386 };
371 387
372 Gallery.prototype.onKeepOriginalClick_ = function() { 388 Gallery.prototype.onOverwriteOriginalClick_ = function(event) {
373 this.keepOriginal_.removeAttribute('visible'); 389 var overwrite = event.target.checked;
374 this.ribbon_.getSelectedItem().setCopyName(this.context_.saveDirEntry, 390 if (overwrite) {
375 this.updateFilename_.bind(this)); 391 this.ribbon_.getSelectedItem().setOriginalName(this.context_.saveDirEntry,
392 this.updateFilename_.bind(this));
393 } else {
394 this.ribbon_.getSelectedItem().setCopyName(this.context_.saveDirEntry,
395 this.updateFilename_.bind(this));
396 }
376 }; 397 };
377 398
378 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) { 399 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) {
379 if (modified) { 400 if (modified) {
380 item.save(this.context_.saveDirEntry, this.context_.metadataProvider, 401 item.save(this.context_.saveDirEntry, this.context_.metadataProvider,
381 canvas, callback); 402 canvas, callback);
382 } else { 403 } else {
383 if (callback) callback(); 404 if (callback) callback();
384 } 405 }
385 }; 406 };
(...skipping 30 matching lines...) Expand all
416 } 437 }
417 438
418 this.context_.onNameChange(fullName); 439 this.context_.onNameChange(fullName);
419 440
420 var displayName = ImageUtil.getFileNameFromFullName(fullName); 441 var displayName = ImageUtil.getFileNameFromFullName(fullName);
421 this.filenameEdit_.value = displayName; 442 this.filenameEdit_.value = displayName;
422 this.filenameText_.textContent = displayName; 443 this.filenameText_.textContent = displayName;
423 }; 444 };
424 445
425 Gallery.prototype.onFilenameClick_ = function() { 446 Gallery.prototype.onFilenameClick_ = function() {
426 ImageUtil.setAttribute(this.container_, 'renaming', true); 447 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', true);
427 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0); 448 setTimeout(this.filenameEdit_.select.bind(this.filenameEdit_), 0);
428 this.cancelFading_(); 449 this.cancelFading_();
429 }; 450 };
430 451
431 Gallery.prototype.onFilenameEditBlur_ = function() { 452 Gallery.prototype.onFilenameEditBlur_ = function() {
432 if (this.filenameEdit_.value && this.filenameEdit_.value[0] == '.') { 453 if (this.filenameEdit_.value && this.filenameEdit_.value[0] == '.') {
433 this.editor_.getPrompt().show('file_hidden_name', 5000); 454 this.editor_.getPrompt().show('file_hidden_name', 5000);
434 this.filenameEdit_.focus(); 455 this.filenameEdit_.focus();
435 return; 456 return;
436 } 457 }
437 458
438 if (this.filenameEdit_.value) { 459 if (this.filenameEdit_.value) {
439 this.renameItem_(this.ribbon_.getSelectedItem(), 460 this.renameItem_(this.ribbon_.getSelectedItem(),
440 this.filenameEdit_.value); 461 this.filenameEdit_.value);
441 } 462 }
442 463
443 ImageUtil.setAttribute(this.container_, 'renaming', false); 464 ImageUtil.setAttribute(this.filenameSpacer_, 'renaming', false);
444 this.initiateFading_(); 465 this.initiateFading_();
445 }; 466 };
446 467
447 Gallery.prototype.onFilenameEditKeydown_ = function() { 468 Gallery.prototype.onFilenameEditKeydown_ = function() {
448 switch (event.keyCode) { 469 switch (event.keyCode) {
449 case 27: // Escape 470 case 27: // Escape
450 this.updateFilename_(); 471 this.updateFilename_();
451 this.filenameEdit_.blur(); 472 this.filenameEdit_.blur();
452 break; 473 break;
453 474
(...skipping 21 matching lines...) Expand all
475 496
476 function onSuccess(entry) { 497 function onSuccess(entry) {
477 item.setUrl(entry.toURL()); 498 item.setUrl(entry.toURL());
478 self.updateFilename_(); 499 self.updateFilename_();
479 } 500 }
480 501
481 function doRename() { 502 function doRename() {
482 if (self.imageChanges_ > 0) { 503 if (self.imageChanges_ > 0) {
483 // Use this name in the next save operation. 504 // Use this name in the next save operation.
484 item.setNameForSaving(newName); 505 item.setNameForSaving(newName);
485 self.keepOriginal_.removeAttribute('visible'); 506 this.filenameSpacer_.removeAttribute('overwrite');
486 self.updateFilename_(); 507 self.updateFilename_();
487 } else { 508 } else {
488 // Rename file in place. 509 // Rename file in place.
489 dir.getFile( 510 dir.getFile(
490 ImageUtil.getFullNameFromUrl(item.getUrl()), 511 ImageUtil.getFullNameFromUrl(item.getUrl()),
491 {create: false}, 512 {create: false},
492 function(entry) { entry.moveTo(dir, newName, onSuccess, onError); }, 513 function(entry) { entry.moveTo(dir, newName, onSuccess, onError); },
493 onError); 514 onError);
494 } 515 }
495 } 516 }
496 517
497 function onVictimFound(victim) { 518 function onVictimFound(victim) {
498 self.editor_.getPrompt().show('file_exists', 3000); 519 self.editor_.getPrompt().show('file_exists', 3000);
499 self.filenameEdit_.value = name; 520 self.filenameEdit_.value = name;
500 self.onFilenameClick_(); 521 self.onFilenameClick_();
501 } 522 }
502 523
503 dir.getFile(newName, {create: false, exclusive: false}, 524 dir.getFile(newName, {create: false, exclusive: false},
504 onVictimFound, doRename); 525 onVictimFound, doRename);
505 }; 526 };
506 527
507 Gallery.prototype.isRenaming_ = function() { 528 Gallery.prototype.isRenaming_ = function() {
508 return this.container_.hasAttribute('renaming'); 529 return this.filenameSpacer_.hasAttribute('renaming');
509 }; 530 };
510 531
511 Gallery.getFileBrowserPrivate = function() { 532 Gallery.getFileBrowserPrivate = function() {
512 return chrome.fileBrowserPrivate || window.top.chrome.fileBrowserPrivate; 533 return chrome.fileBrowserPrivate || window.top.chrome.fileBrowserPrivate;
513 }; 534 };
514 535
515 Gallery.prototype.toggleFullscreen_ = function() { 536 Gallery.prototype.toggleFullscreen_ = function() {
516 Gallery.getFileBrowserPrivate().toggleFullscreen(); 537 Gallery.getFileBrowserPrivate().toggleFullscreen();
517 }; 538 };
518 539
(...skipping 17 matching lines...) Expand all
536 this.saveChanges_(this.close_.bind(this)); 557 this.saveChanges_(this.close_.bind(this));
537 }; 558 };
538 559
539 Gallery.prototype.prefetchImage = function(id, content, metadata) { 560 Gallery.prototype.prefetchImage = function(id, content, metadata) {
540 this.editor_.prefetchImage(id, content, metadata); 561 this.editor_.prefetchImage(id, content, metadata);
541 }; 562 };
542 563
543 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) { 564 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) {
544 // The first change is load, we should not count it. 565 // The first change is load, we should not count it.
545 this.imageChanges_ = -1; 566 this.imageChanges_ = -1;
546 this.savedLabel_.style.display = 'none'; 567 this.filenameSpacer_.removeAttribute('overwrite');
547 this.keepOriginal_.removeAttribute('visible'); 568 this.filenameSpacer_.removeAttribute('saved');
548 569
549 var item = this.ribbon_.getSelectedItem(); 570 var item = this.ribbon_.getSelectedItem();
550 this.updateFilename_(content); 571 this.updateFilename_(content);
551 572
552 this.showSpinner_(true); 573 this.showSpinner_(true);
553 574
554 var self = this; 575 var self = this;
555 function loadDone(loadType) { 576 function loadDone(loadType) {
556 var video = self.isShowingVideo_(); 577 var video = self.isShowingVideo_();
557 ImageUtil.setAttribute(self.container_, 'video', video); 578 ImageUtil.setAttribute(self.container_, 'video', video);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 this.editor_.getPrompt().showAt( 688 this.editor_.getPrompt().showAt(
668 'top', 'readonly_warning', 0, this.context_.readonlyDirName); 689 'top', 'readonly_warning', 0, this.context_.readonlyDirName);
669 } 690 }
670 this.cancelFading_(); 691 this.cancelFading_();
671 } else { 692 } else {
672 this.editor_.getPrompt().hide(); 693 this.editor_.getPrompt().hide();
673 if (!this.isShowingVideo_()) { 694 if (!this.isShowingVideo_()) {
674 var item = this.ribbon_.getSelectedItem(); 695 var item = this.ribbon_.getSelectedItem();
675 this.editor_.requestImage(item.updateThumbnail.bind(item)); 696 this.editor_.requestImage(item.updateThumbnail.bind(item));
676 } 697 }
677 this.savedLabel_.style.display = 'none'; 698 this.filenameSpacer_.removeAttribute('saved');
678 this.keepOriginal_.removeAttribute('visible'); 699 this.filenameSpacer_.removeAttribute('overwrite');
700 this.saveChanges_();
679 this.initiateFading_(); 701 this.initiateFading_();
680 } 702 }
681 703
682 ImageUtil.setAttribute(this.editButton_, 'pressed', this.isEditing_()); 704 ImageUtil.setAttribute(this.editButton_, 'pressed', this.isEditing_());
683 }; 705 };
684 706
685 Gallery.prototype.isSharing_ = function(event) { 707 Gallery.prototype.isSharing_ = function(event) {
686 return this.shareMode_ && this.shareMode_ == this.editor_.getMode(); 708 return this.shareMode_ && this.shareMode_ == this.editor_.getMode();
687 }; 709 };
688 710
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 tryNext(10); 1275 tryNext(10);
1254 }; 1276 };
1255 1277
1256 Ribbon.Item.prototype.setCopyName = function(dirEntry, opt_callback) { 1278 Ribbon.Item.prototype.setCopyName = function(dirEntry, opt_callback) {
1257 this.createCopyName_(dirEntry, function(name) { 1279 this.createCopyName_(dirEntry, function(name) {
1258 this.nameForSaving_ = name; 1280 this.nameForSaving_ = name;
1259 if (opt_callback) opt_callback(); 1281 if (opt_callback) opt_callback();
1260 }.bind(this)); 1282 }.bind(this));
1261 }; 1283 };
1262 1284
1285 Ribbon.Item.prototype.setOriginalName = function(dirEntry, opt_callback) {
1286 this.nameForSaving_ = null;
1287 if (opt_callback) opt_callback();
1288 };
1289
1263 Ribbon.Item.prototype.setNameForSaving = function(newName) { 1290 Ribbon.Item.prototype.setNameForSaving = function(newName) {
1264 this.nameForSaving_ = newName; 1291 this.nameForSaving_ = newName;
1265 }; 1292 };
1266 1293
1267 // The url and metadata stored in the item are not valid while the modified 1294 // The url and metadata stored in the item are not valid while the modified
1268 // image is being saved. Use the results of the latest edit instead. 1295 // image is being saved. Use the results of the latest edit instead.
1269 1296
1270 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) { 1297 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) {
1271 this.canvas_ = canvas; 1298 this.canvas_ = canvas;
1272 this.backupMetadata_ = this.metadata_; 1299 this.backupMetadata_ = this.metadata_;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 ShareMode.prototype.setUp = function() { 1441 ShareMode.prototype.setUp = function() {
1415 ImageEditor.Mode.prototype.setUp.apply(this, arguments); 1442 ImageEditor.Mode.prototype.setUp.apply(this, arguments);
1416 ImageUtil.setAttribute(this.menu_, 'hidden', false); 1443 ImageUtil.setAttribute(this.menu_, 'hidden', false);
1417 ImageUtil.setAttribute(this.button_, 'pressed', false); 1444 ImageUtil.setAttribute(this.button_, 'pressed', false);
1418 }; 1445 };
1419 1446
1420 ShareMode.prototype.cleanUpUI = function() { 1447 ShareMode.prototype.cleanUpUI = function() {
1421 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); 1448 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments);
1422 ImageUtil.setAttribute(this.menu_, 'hidden', true); 1449 ImageUtil.setAttribute(this.menu_, 'hidden', true);
1423 }; 1450 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698