Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 19 matching lines...) Expand all Loading... | |
| 30 this.closeCallback_ = closeCallback; | 30 this.closeCallback_ = closeCallback; |
| 31 this.metadataProvider_ = metadataProvider; | 31 this.metadataProvider_ = metadataProvider; |
| 32 | 32 |
| 33 this.displayStringFunction_ = function(id) { | 33 this.displayStringFunction_ = function(id) { |
| 34 return displayStringFunction('GALLERY_' + id.toUpperCase()); | 34 return displayStringFunction('GALLERY_' + id.toUpperCase()); |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 this.onFadeTimeoutBound_ = this.onFadeTimeout_.bind(this); | 37 this.onFadeTimeoutBound_ = this.onFadeTimeout_.bind(this); |
| 38 this.fadeTimeoutId_ = null; | 38 this.fadeTimeoutId_ = null; |
| 39 this.mouseOverTool_ = false; | 39 this.mouseOverTool_ = false; |
| 40 this.imageChanges_ = 0; | |
| 40 | 41 |
| 41 this.initDom_(shareActions); | 42 this.initDom_(shareActions); |
| 42 } | 43 } |
| 43 | 44 |
| 44 Gallery.prototype = { __proto__: RibbonClient.prototype }; | 45 Gallery.prototype = { __proto__: RibbonClient.prototype }; |
| 45 | 46 |
| 46 Gallery.open = function(parentDirEntry, items, selectedItem, | 47 Gallery.open = function(parentDirEntry, items, selectedItem, |
| 47 closeCallback, metadataProvider, shareActions, displayStringFunction) { | 48 closeCallback, metadataProvider, shareActions, displayStringFunction) { |
| 48 var container = document.querySelector('.gallery'); | 49 var container = document.querySelector('.gallery'); |
| 49 container.innerHTML = ''; | 50 container.innerHTML = ''; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 this.container_.appendChild(this.closeButton_); | 90 this.container_.appendChild(this.closeButton_); |
| 90 | 91 |
| 91 this.imageContainer_ = doc.createElement('div'); | 92 this.imageContainer_ = doc.createElement('div'); |
| 92 this.imageContainer_.className = 'image-container'; | 93 this.imageContainer_.className = 'image-container'; |
| 93 this.container_.appendChild(this.imageContainer_); | 94 this.container_.appendChild(this.imageContainer_); |
| 94 | 95 |
| 95 this.toolbar_ = doc.createElement('div'); | 96 this.toolbar_ = doc.createElement('div'); |
| 96 this.toolbar_.className = 'toolbar tool dimmable'; | 97 this.toolbar_.className = 'toolbar tool dimmable'; |
| 97 this.container_.appendChild(this.toolbar_); | 98 this.container_.appendChild(this.toolbar_); |
| 98 | 99 |
| 100 var filenameSpacer = doc.createElement('div'); | |
| 101 filenameSpacer.className = 'filename-spacer'; | |
| 102 this.toolbar_.appendChild(filenameSpacer); | |
| 103 | |
| 104 this.filenameEdit_ = doc.createElement('input'); | |
| 105 this.filenameEdit_.setAttribute('type', 'text'); | |
| 106 this.filenameEdit_.addEventListener('blur', | |
| 107 this.updateFilename_.bind(this)); | |
| 108 this.filenameEdit_.addEventListener('keydown', | |
| 109 this.onFilenameEditKeydown_.bind(this)); | |
| 110 filenameSpacer.appendChild(this.filenameEdit_); | |
| 111 | |
| 99 this.ribbonSpacer_ = doc.createElement('div'); | 112 this.ribbonSpacer_ = doc.createElement('div'); |
| 100 this.ribbonSpacer_.className = 'ribbon-spacer'; | 113 this.ribbonSpacer_.className = 'ribbon-spacer'; |
| 101 this.toolbar_.appendChild(this.ribbonSpacer_); | 114 this.toolbar_.appendChild(this.ribbonSpacer_); |
| 102 | 115 |
| 103 this.arrowBox_ = this.document_.createElement('div'); | 116 this.arrowBox_ = this.document_.createElement('div'); |
| 104 this.arrowBox_.className = 'arrow-box'; | 117 this.arrowBox_.className = 'arrow-box'; |
| 105 this.container_.appendChild(this.arrowBox_); | 118 this.container_.appendChild(this.arrowBox_); |
| 106 | 119 |
| 107 this.arrowLeft_ = this.document_.createElement('div'); | 120 this.arrowLeft_ = this.document_.createElement('div'); |
| 108 this.arrowLeft_.className = 'arrow left tool dimmable'; | 121 this.arrowLeft_.className = 'arrow left tool dimmable'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 | 159 |
| 147 this.editor_ = new ImageEditor( | 160 this.editor_ = new ImageEditor( |
| 148 this.container_, | 161 this.container_, |
| 149 this.imageContainer_, | 162 this.imageContainer_, |
| 150 this.editBarMain_, | 163 this.editBarMain_, |
| 151 this.editBarModeWrapper_, | 164 this.editBarModeWrapper_, |
| 152 Gallery.editorModes, | 165 Gallery.editorModes, |
| 153 this.displayStringFunction_); | 166 this.displayStringFunction_); |
| 154 | 167 |
| 155 this.imageView_ = this.editor_.getImageView(); | 168 this.imageView_ = this.editor_.getImageView(); |
| 169 this.imageView_.addContentCallback(this.onImageContentChanged_.bind(this)); | |
| 156 | 170 |
| 157 this.editor_.trackWindow(doc.defaultView); | 171 this.editor_.trackWindow(doc.defaultView); |
| 158 | 172 |
| 159 if (shareActions.length > 0) { | 173 if (shareActions.length > 0) { |
| 160 this.shareMode_ = new ShareMode( | 174 this.shareMode_ = new ShareMode( |
| 161 this.container_, this.toolbar_, shareActions, | 175 this.container_, this.toolbar_, shareActions, |
| 162 this.onShare_.bind(this), this.onActionExecute_.bind(this), | 176 this.onShare_.bind(this), this.onActionExecute_.bind(this), |
| 163 this.displayStringFunction_); | 177 this.displayStringFunction_); |
| 164 | 178 |
| 165 } else { | 179 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 function initRibbon() { | 219 function initRibbon() { |
| 206 self.ribbon_.load(urls, selectedIndex); | 220 self.ribbon_.load(urls, selectedIndex); |
| 207 // Flash the ribbon briefly to let the user know it is there. | 221 // Flash the ribbon briefly to let the user know it is there. |
| 208 self.cancelFading_(); | 222 self.cancelFading_(); |
| 209 self.initiateFading_(Gallery.FIRST_FADE_TIMEOUT); | 223 self.initiateFading_(Gallery.FIRST_FADE_TIMEOUT); |
| 210 } | 224 } |
| 211 | 225 |
| 212 var selectedURL = urls[selectedIndex]; | 226 var selectedURL = urls[selectedIndex]; |
| 213 // Initialize the ribbon only after the selected image is fully loaded. | 227 // Initialize the ribbon only after the selected image is fully loaded. |
| 214 this.metadataProvider_.fetch(selectedURL, function (metadata) { | 228 this.metadataProvider_.fetch(selectedURL, function (metadata) { |
| 229 // The first change is load, we should not count it. | |
| 230 self.imageChanges_ = -1; | |
| 231 self.filenameEdit_.value = ImageUtil.getFileNameFromUrl(selectedURL); | |
|
Vladislav Kaznacheev
2011/12/01 10:34:09
Did you forget to add image_util.js?
dgozman
2011/12/01 11:34:05
Whoops. Added.
| |
| 215 self.editor_.openSession( | 232 self.editor_.openSession( |
| 216 selectedIndex, selectedURL, metadata, 0, initRibbon); | 233 selectedIndex, selectedURL, metadata, 0, initRibbon); |
| 217 }); | 234 }); |
| 218 }; | 235 }; |
| 219 | 236 |
| 237 Gallery.prototype.onImageContentChanged_ = function() { | |
| 238 this.imageChanges_++; | |
| 239 if (this.imageChanges_ == 1) | |
| 240 this.ribbon_.getSelectedItem().setCopyName(); | |
| 241 this.updateFilename_(); | |
| 242 }; | |
| 243 | |
| 220 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) { | 244 Gallery.prototype.saveItem_ = function(item, callback, canvas, modified) { |
| 221 if (modified) { | 245 if (modified) { |
| 222 item.save( | 246 item.save( |
| 223 this.parentDirEntry_, this.metadataProvider_, canvas, callback); | 247 this.parentDirEntry_, this.metadataProvider_, canvas, callback); |
| 224 } else { | 248 } else { |
| 225 if (callback) callback(); | 249 if (callback) callback(); |
| 226 } | 250 } |
| 227 }; | 251 }; |
| 228 | 252 |
| 229 Gallery.prototype.saveChanges_ = function(opt_callback) { | 253 Gallery.prototype.saveChanges_ = function(opt_callback) { |
| 254 this.imageChanges_ = 0; | |
| 230 this.editor_.requestImage( | 255 this.editor_.requestImage( |
| 231 this.saveItem_.bind(this, this.ribbon_.getSelectedItem(), opt_callback)); | 256 this.saveItem_.bind(this, this.ribbon_.getSelectedItem(), opt_callback)); |
| 232 }; | 257 }; |
| 233 | 258 |
| 234 Gallery.prototype.onActionExecute_ = function(action) { | 259 Gallery.prototype.onActionExecute_ = function(action) { |
| 235 var url = this.ribbon_.getSelectedItem().getUrl(); | 260 var url = this.ribbon_.getSelectedItem().getUrl(); |
| 236 // saveChanges_ makes the editor leave the mode and close the sharing menu. | 261 // saveChanges_ makes the editor leave the mode and close the sharing menu. |
| 237 this.saveChanges_(action.execute.bind(action, [url])); | 262 this.saveChanges_(action.execute.bind(action, [url])); |
| 238 }; | 263 }; |
| 239 | 264 |
| 265 Gallery.prototype.updateFilename_ = function() { | |
| 266 var item = this.ribbon_.getSelectedItem(); | |
| 267 if (!item) | |
| 268 return; | |
| 269 | |
| 270 var fullName = item.getCopyName() || | |
| 271 ImageUtil.getFullNameFromUrl(item.getUrl()); | |
| 272 this.filenameEdit_.value = ImageUtil.getFileNameFromFullName(fullName); | |
| 273 }; | |
| 274 | |
| 275 Gallery.prototype.onFilenameEditKeydown_ = function() { | |
| 276 switch (event.keyCode) { | |
| 277 case 27: // Escape | |
| 278 this.filenameEdit_.blur(); | |
| 279 break; | |
| 280 | |
| 281 case 13: // Enter | |
| 282 if (this.filenameEdit_.value) { | |
| 283 this.renameItem_(this.ribbon_.getSelectedItem(), | |
| 284 this.filenameEdit_.value); | |
| 285 this.filenameEdit_.blur(); | |
| 286 } | |
| 287 break; | |
| 288 } | |
| 289 event.stopPropagation(); | |
| 290 }; | |
| 291 | |
| 292 Gallery.prototype.renameItem_ = function(item, name) { | |
| 293 if (this.imageChanges_ > 0) { | |
| 294 // We are editing the file. | |
| 295 item.setCopyName(ImageUtil.replaceFileNameInFullName( | |
| 296 item.getCopyName(), name)); | |
| 297 return; | |
|
Vladislav Kaznacheev
2011/12/01 10:34:09
I think we should check for existing file name, we
dgozman
2011/12/01 11:34:05
Done.
| |
| 298 } | |
| 299 | |
| 300 var dir = this.parentDirEntry_; | |
| 301 var self = this; | |
| 302 var newName = ImageUtil.replaceFileNameInFullName( | |
| 303 ImageUtil.getFullNameFromUrl(item.getUrl()), name); | |
| 304 | |
| 305 function onError() { | |
| 306 console.log('Rename error: "' + | |
| 307 ImageUtil.getFullNameFromUrl(item.getUrl()) + '" to "' + name + '"'); | |
| 308 } | |
| 309 | |
| 310 function onSuccess(entry) { | |
| 311 item.setUrl(entry.toURL()); | |
| 312 self.updateFilename_(); | |
| 313 } | |
| 314 | |
| 315 function doRename() { | |
| 316 dir.getFile( | |
| 317 ImageUtil.getFullNameFromUrl(item.getUrl()), | |
| 318 {create: false}, | |
| 319 function(entry) { entry.moveTo(dir, newName, onSuccess, onError); }, | |
| 320 onError); | |
| 321 } | |
| 322 | |
| 323 function onVictimFound(victim) { | |
| 324 self.editor_.getPrompt().show('file_exists', 3000); | |
| 325 } | |
| 326 | |
| 327 dir.getFile(newName, {create: false, exclusive: false}, | |
| 328 onVictimFound, doRename); | |
| 329 }; | |
| 330 | |
| 240 Gallery.prototype.onClose_ = function() { | 331 Gallery.prototype.onClose_ = function() { |
| 241 // TODO: handle write errors gracefully (suggest retry or saving elsewhere). | 332 // TODO: handle write errors gracefully (suggest retry or saving elsewhere). |
| 242 this.saveChanges_(this.closeCallback_); | 333 this.saveChanges_(this.closeCallback_); |
| 243 }; | 334 }; |
| 244 | 335 |
| 245 Gallery.prototype.prefetchImage = function(id, content, metadata) { | 336 Gallery.prototype.prefetchImage = function(id, content, metadata) { |
| 246 this.editor_.prefetchImage(id, content, metadata); | 337 this.editor_.prefetchImage(id, content, metadata); |
| 247 }; | 338 }; |
| 248 | 339 |
| 249 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) { | 340 Gallery.prototype.openImage = function(id, content, metadata, slide, callback) { |
| 341 // The first change is load, we should not count it. | |
| 342 this.imageChanges_ = -1; | |
| 343 this.updateFilename_(); | |
| 250 this.editor_.openSession(id, content, metadata, slide, callback); | 344 this.editor_.openSession(id, content, metadata, slide, callback); |
| 251 }; | 345 }; |
| 252 | 346 |
| 253 Gallery.prototype.closeImage = function(item) { | 347 Gallery.prototype.closeImage = function(item) { |
| 254 this.editor_.closeSession(this.saveItem_.bind(this, item, null)); | 348 this.editor_.closeSession(this.saveItem_.bind(this, item, null)); |
| 255 }; | 349 }; |
| 256 | 350 |
| 257 Gallery.prototype.isEditing_ = function() { | 351 Gallery.prototype.isEditing_ = function() { |
| 258 return this.container_.hasAttribute('editing'); | 352 return this.container_.hasAttribute('editing'); |
| 259 }; | 353 }; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 * @param {MetadataProvider} metadataProvider | 471 * @param {MetadataProvider} metadataProvider |
| 378 * @param {HTMLElement} arrowLeft | 472 * @param {HTMLElement} arrowLeft |
| 379 * @param {HTMLElement} arrowRight | 473 * @param {HTMLElement} arrowRight |
| 380 */ | 474 */ |
| 381 function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) { | 475 function Ribbon(container, client, metadataProvider, arrowLeft, arrowRight) { |
| 382 this.container_ = container; | 476 this.container_ = container; |
| 383 this.document_ = container.ownerDocument; | 477 this.document_ = container.ownerDocument; |
| 384 this.client_ = client; | 478 this.client_ = client; |
| 385 this.metadataProvider_ = metadataProvider; | 479 this.metadataProvider_ = metadataProvider; |
| 386 | 480 |
| 481 this.items_ = []; | |
| 482 this.selectedIndex_ = -1; | |
| 483 | |
| 387 this.arrowLeft_ = arrowLeft; | 484 this.arrowLeft_ = arrowLeft; |
| 388 this.arrowLeft_. | 485 this.arrowLeft_. |
| 389 addEventListener('click', this.selectNext.bind(this, -1, null)); | 486 addEventListener('click', this.selectNext.bind(this, -1, null)); |
| 390 | 487 |
| 391 this.arrowRight_ = arrowRight; | 488 this.arrowRight_ = arrowRight; |
| 392 this.arrowRight_. | 489 this.arrowRight_. |
| 393 addEventListener('click', this.selectNext.bind(this, 1, null)); | 490 addEventListener('click', this.selectNext.bind(this, 1, null)); |
| 394 | 491 |
| 395 this.fadeLeft_ = this.document_.createElement('div'); | 492 this.fadeLeft_ = this.document_.createElement('div'); |
| 396 this.fadeLeft_.className = 'fade left'; | 493 this.fadeLeft_.className = 'fade left'; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 671 | 768 |
| 672 var img = document.createElement('img'); | 769 var img = document.createElement('img'); |
| 673 wrapper.appendChild(img); | 770 wrapper.appendChild(img); |
| 674 | 771 |
| 675 this.boxes_.push(box); | 772 this.boxes_.push(box); |
| 676 this.wrappers_.push(wrapper); | 773 this.wrappers_.push(wrapper); |
| 677 this.imgs_.push(img); | 774 this.imgs_.push(img); |
| 678 } | 775 } |
| 679 | 776 |
| 680 this.original_ = true; | 777 this.original_ = true; |
| 778 this.copyName_ = null; | |
| 681 }; | 779 }; |
| 682 | 780 |
| 683 Ribbon.Item.prototype.getIndex = function () { return this.index_ }; | 781 Ribbon.Item.prototype.getIndex = function () { return this.index_ }; |
| 684 | 782 |
| 685 Ribbon.Item.prototype.getBox = function (index) { return this.boxes_[index] }; | 783 Ribbon.Item.prototype.getBox = function (index) { return this.boxes_[index] }; |
| 686 | 784 |
| 687 Ribbon.Item.prototype.isOriginal = function () { return this.original_ }; | 785 Ribbon.Item.prototype.isOriginal = function () { return this.original_ }; |
| 688 | 786 |
| 689 Ribbon.Item.prototype.getUrl = function () { return this.url_ }; | 787 Ribbon.Item.prototype.getUrl = function () { return this.url_ }; |
| 788 Ribbon.Item.prototype.setUrl = function (url) { this.url_ = url }; | |
| 789 | |
| 790 Ribbon.Item.prototype.getCopyName = function () { return this.copyName_ }; | |
| 690 | 791 |
| 691 Ribbon.Item.prototype.isSelected = function() { | 792 Ribbon.Item.prototype.isSelected = function() { |
| 692 return this.boxes_[0].hasAttribute('selected'); | 793 return this.boxes_[0].hasAttribute('selected'); |
| 693 }; | 794 }; |
| 694 | 795 |
| 695 Ribbon.Item.prototype.select = function(on) { | 796 Ribbon.Item.prototype.select = function(on) { |
| 696 for (var i = 0; i < 2; i++) { | 797 for (var i = 0; i < 2; i++) { |
| 697 ImageUtil.setAttribute(this.boxes_[i], 'selected', on); | 798 ImageUtil.setAttribute(this.boxes_[i], 'selected', on); |
| 698 } | 799 } |
| 699 }; | 800 }; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 718 | 819 |
| 719 if (!dirEntry) { // Happens only in gallery_demo.js | 820 if (!dirEntry) { // Happens only in gallery_demo.js |
| 720 self.onSaveSuccess( | 821 self.onSaveSuccess( |
| 721 window.webkitURL.createObjectURL( | 822 window.webkitURL.createObjectURL( |
| 722 ImageEncoder.getBlob(canvas, metadataEncoder))); | 823 ImageEncoder.getBlob(canvas, metadataEncoder))); |
| 723 if (opt_callback) opt_callback(); | 824 if (opt_callback) opt_callback(); |
| 724 return; | 825 return; |
| 725 } | 826 } |
| 726 | 827 |
| 727 var newFile = this.isOriginal(); | 828 var newFile = this.isOriginal(); |
| 728 var name = this.getCopyName(); | 829 var name = this.copyName_; |
| 830 this.original_ = false; | |
| 831 this.copyName_ = ''; | |
| 729 | 832 |
| 730 function onSuccess(url) { | 833 function onSuccess(url) { |
| 731 console.log('Saved from gallery', name); | 834 console.log('Saved from gallery', name); |
| 732 // Force the metadata provider to reread the metadata from the file. | 835 // Force the metadata provider to reread the metadata from the file. |
| 733 metadataProvider.reset(url); | 836 metadataProvider.reset(url); |
| 734 self.onSaveSuccess(url); | 837 self.onSaveSuccess(url); |
| 735 if (opt_callback) opt_callback(); | 838 if (opt_callback) opt_callback(); |
| 736 } | 839 } |
| 737 | 840 |
| 738 function onError(error) { | 841 function onError(error) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 754 } else { | 857 } else { |
| 755 fileWriter.onwriteend = writeContent; | 858 fileWriter.onwriteend = writeContent; |
| 756 fileWriter.truncate(0); | 859 fileWriter.truncate(0); |
| 757 } | 860 } |
| 758 }, | 861 }, |
| 759 onError); | 862 onError); |
| 760 }, onError); | 863 }, onError); |
| 761 }; | 864 }; |
| 762 | 865 |
| 763 // TODO: Localize? | 866 // TODO: Localize? |
| 764 Ribbon.Item.COPY_SIGNATURE = '_Edited_'; | 867 Ribbon.Item.COPY_SIGNATURE = 'Copy of '; |
| 765 | 868 |
| 766 Ribbon.Item.prototype.getCopyName = function () { | 869 Ribbon.Item.prototype.createCopyName_ = function () { |
| 767 // When saving a modified image we never overwrite the original file (the one | 870 // When saving a modified image we never overwrite the original file (the one |
| 768 // that existed prior to opening the Gallery. Instead we save to a file named | 871 // that existed prior to opening the Gallery. Instead we save to a file named |
| 769 // <original-name>_Edited_<date-stamp>.<original extension>. | 872 // <original-name>_Edited_<date-stamp>.<original extension>. |
| 770 | 873 |
| 771 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); | 874 var name = this.url_.substr(this.url_.lastIndexOf('/') + 1); |
| 772 | 875 |
| 773 // If the item represents a file created during the current Gallery session | 876 // If the item represents a file created during the current Gallery session |
| 774 // we reuse it for subsequent saves instead of creating multiple copies. | 877 // we reuse it for subsequent saves instead of creating multiple copies. |
| 775 if (!this.original_) | 878 if (!this.original_) |
| 776 return name; | 879 return name; |
| 777 | 880 |
| 778 this.original_ = false; | |
| 779 | |
| 780 var ext = ''; | 881 var ext = ''; |
| 781 var index = name.lastIndexOf('.'); | 882 var index = name.lastIndexOf('.'); |
| 782 if (index != -1) { | 883 if (index != -1) { |
| 783 ext = name.substr(index); | 884 ext = name.substr(index); |
| 784 name = name.substr(0, index); | 885 name = name.substr(0, index); |
| 785 } | 886 } |
| 786 var signaturePos = name.indexOf(Ribbon.Item.COPY_SIGNATURE); | 887 |
| 787 if (signaturePos >= 0) { | 888 if (name.indexOf(Ribbon.Item.COPY_SIGNATURE) == 0) { |
| 788 // The file is likely to be a copy created during a previous session. | 889 // The file is likely to be a copy created during a previous session. |
| 789 // Replace the signature instead of appending a new one. | 890 // Replace the signature instead of appending a new one. |
| 790 name = name.substr(0, signaturePos); | 891 name = name.substr(Ribbon.Item.COPY_SIGNATURE.length); |
|
Vladislav Kaznacheev
2011/12/01 10:34:09
This would not work nicely. If you do not want to
dgozman
2011/12/01 11:34:05
Done.
| |
| 791 } | 892 } |
| 792 | 893 |
| 793 var mimeType = this.metadata_.mimeType.toLowerCase(); | 894 var mimeType = this.metadata_.mimeType.toLowerCase(); |
| 794 if (mimeType != 'image/jpeg') { | 895 if (mimeType != 'image/jpeg') { |
| 795 // Chrome can natively encode only two formats: JPEG and PNG. | 896 // Chrome can natively encode only two formats: JPEG and PNG. |
| 796 // All non-JPEG images are saved in PNG, hence forcing the file extension. | 897 // All non-JPEG images are saved in PNG, hence forcing the file extension. |
| 797 if (mimeType == 'image/png') { | 898 if (mimeType == 'image/png') { |
| 798 ext = '.png'; | 899 ext = '.png'; |
| 799 } else { | 900 } else { |
| 800 // All non-JPEG images get 'image/png' mimeType (see | 901 // All non-JPEG images get 'image/png' mimeType (see |
| 801 // ImageEncoder.MetadataEncoder constructor). | 902 // ImageEncoder.MetadataEncoder constructor). |
| 802 // This code can be reached only if someone has added a metadata parser | 903 // This code can be reached only if someone has added a metadata parser |
| 803 // for a format other than JPEG or PNG. The message below is to remind | 904 // for a format other than JPEG or PNG. The message below is to remind |
| 804 // that one must also come up with the way to encode the image data. | 905 // that one must also come up with the way to encode the image data. |
| 805 console.error('Image encoding for ' + mimeType + ' is not supported'); | 906 console.error('Image encoding for ' + mimeType + ' is not supported'); |
| 806 } | 907 } |
| 807 } | 908 } |
| 808 | 909 |
| 809 function twoDigits(n) { return (n < 10 ? '0' : '' ) + n } | 910 return Ribbon.Item.COPY_SIGNATURE + name + ext; |
| 911 }; | |
| 810 | 912 |
| 811 var now = new Date(); | 913 Ribbon.Item.prototype.setCopyName = function(opt_name) { |
| 812 | 914 if (opt_name) { |
| 813 // Datestamp the copy with YYYYMMDD_HHMMSS (similar to what many cameras do) | 915 this.copyName_ = opt_name; |
| 814 return name + | 916 } else { |
| 815 Ribbon.Item.COPY_SIGNATURE + | 917 this.copyName_ = this.createCopyName_(); |
| 816 now.getFullYear() + | 918 } |
| 817 twoDigits(now.getMonth() + 1) + | |
| 818 twoDigits(now.getDate()) + | |
| 819 '_' + | |
| 820 twoDigits(now.getHours()) + | |
| 821 twoDigits(now.getMinutes()) + | |
| 822 twoDigits(now.getSeconds()) + | |
| 823 ext; | |
| 824 }; | 919 }; |
| 825 | 920 |
| 826 // The url and metadata stored in the item are not valid while the modified | 921 // The url and metadata stored in the item are not valid while the modified |
| 827 // image is being saved. Use the results of the latest edit instead. | 922 // image is being saved. Use the results of the latest edit instead. |
| 828 | 923 |
| 829 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) { | 924 Ribbon.Item.prototype.overrideContent = function(canvas, metadata) { |
| 830 this.canvas_ = canvas; | 925 this.canvas_ = canvas; |
| 831 this.backupMetadata_ = this.metadata_; | 926 this.backupMetadata_ = this.metadata_; |
| 832 this.setMetadata(metadata); | 927 this.setMetadata(metadata); |
| 833 }; | 928 }; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 976 ShareMode.prototype.setUp = function() { | 1071 ShareMode.prototype.setUp = function() { |
| 977 ImageEditor.Mode.prototype.setUp.apply(this, arguments); | 1072 ImageEditor.Mode.prototype.setUp.apply(this, arguments); |
| 978 ImageUtil.setAttribute(this.menu_, 'hidden', false); | 1073 ImageUtil.setAttribute(this.menu_, 'hidden', false); |
| 979 ImageUtil.setAttribute(this.button_, 'pressed', false); | 1074 ImageUtil.setAttribute(this.button_, 'pressed', false); |
| 980 }; | 1075 }; |
| 981 | 1076 |
| 982 ShareMode.prototype.cleanUpUI = function() { | 1077 ShareMode.prototype.cleanUpUI = function() { |
| 983 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 1078 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
| 984 ImageUtil.setAttribute(this.menu_, 'hidden', true); | 1079 ImageUtil.setAttribute(this.menu_, 'hidden', true); |
| 985 }; | 1080 }; |
| OLD | NEW |