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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 866 if (!this.original_) | 866 if (!this.original_) |
| 867 return name; | 867 return name; |
| 868 | 868 |
| 869 var ext = ''; | 869 var ext = ''; |
| 870 var index = name.lastIndexOf('.'); | 870 var index = name.lastIndexOf('.'); |
| 871 if (index != -1) { | 871 if (index != -1) { |
| 872 ext = name.substr(index); | 872 ext = name.substr(index); |
| 873 name = name.substr(0, index); | 873 name = name.substr(0, index); |
| 874 } | 874 } |
| 875 | 875 |
| 876 if (name.indexOf(Ribbon.Item.COPY_SIGNATURE) == 0) { | 876 var regExpCopyN = |
| 877 // TODO(dgozman): add a number to form 'Copy (X) of File.jpg'. | 877 new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+) \\((\\d+)\\)$'); |
|
dgozman
2011/12/07 06:02:09
You can extract regExp constants and place them ne
Vladislav Kaznacheev
2011/12/07 13:11:14
Done.
| |
| 878 name = name.substr(Ribbon.Item.COPY_SIGNATURE.length); | 878 var match = regExpCopyN.exec(name); |
| 879 if (match && match[1] && match[2]) { | |
| 880 var copyNumber = parseInt(match[2], 10) + 1; | |
| 881 name = match[1] + ' (' + copyNumber + ')'; | |
| 882 } else { | |
| 883 var regExpCopy0 = | |
| 884 new RegExp('^' + Ribbon.Item.COPY_SIGNATURE + '(.+)$'); | |
| 885 match = regExpCopy0.exec(name); | |
| 886 if (match && match[1]) { | |
| 887 name = match[1] + ' (1)'; | |
| 888 } | |
| 879 } | 889 } |
| 880 | 890 |
| 881 var mimeType = this.metadata_.mimeType.toLowerCase(); | 891 var mimeType = this.metadata_.mimeType.toLowerCase(); |
| 882 if (mimeType != 'image/jpeg') { | 892 if (mimeType != 'image/jpeg') { |
| 883 // Chrome can natively encode only two formats: JPEG and PNG. | 893 // Chrome can natively encode only two formats: JPEG and PNG. |
| 884 // All non-JPEG images are saved in PNG, hence forcing the file extension. | 894 // All non-JPEG images are saved in PNG, hence forcing the file extension. |
| 885 if (mimeType == 'image/png') { | 895 ext = '.png'; |
| 886 ext = '.png'; | |
| 887 } else { | |
| 888 // All non-JPEG images get 'image/png' mimeType (see | |
| 889 // ImageEncoder.MetadataEncoder constructor). | |
| 890 // This code can be reached only if someone has added a metadata parser | |
| 891 // for a format other than JPEG or PNG. The message below is to remind | |
| 892 // that one must also come up with the way to encode the image data. | |
| 893 console.error('Image encoding for ' + mimeType + ' is not supported'); | |
| 894 } | |
| 895 } | 896 } |
| 896 | 897 |
| 897 return Ribbon.Item.COPY_SIGNATURE + name + ext; | 898 return Ribbon.Item.COPY_SIGNATURE + name + ext; |
| 898 }; | 899 }; |
| 899 | 900 |
| 900 Ribbon.Item.prototype.setCopyName = function(opt_name) { | 901 Ribbon.Item.prototype.setCopyName = function(opt_name) { |
| 901 if (opt_name) { | 902 if (opt_name) { |
| 902 this.copyName_ = opt_name; | 903 this.copyName_ = opt_name; |
| 903 } else { | 904 } else { |
| 904 this.copyName_ = this.createCopyName_(); | 905 this.copyName_ = this.createCopyName_(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 ShareMode.prototype.setUp = function() { | 1062 ShareMode.prototype.setUp = function() { |
| 1062 ImageEditor.Mode.prototype.setUp.apply(this, arguments); | 1063 ImageEditor.Mode.prototype.setUp.apply(this, arguments); |
| 1063 ImageUtil.setAttribute(this.menu_, 'hidden', false); | 1064 ImageUtil.setAttribute(this.menu_, 'hidden', false); |
| 1064 ImageUtil.setAttribute(this.button_, 'pressed', false); | 1065 ImageUtil.setAttribute(this.button_, 'pressed', false); |
| 1065 }; | 1066 }; |
| 1066 | 1067 |
| 1067 ShareMode.prototype.cleanUpUI = function() { | 1068 ShareMode.prototype.cleanUpUI = function() { |
| 1068 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 1069 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
| 1069 ImageUtil.setAttribute(this.menu_, 'hidden', true); | 1070 ImageUtil.setAttribute(this.menu_, 'hidden', true); |
| 1070 }; | 1071 }; |
| OLD | NEW |