Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 cr.define('settings_test', function() { | 5 cr.define('settings_test', function() { |
| 6 var changePictureOptions = settings_test.changePictureOptions || { | 6 var changePictureOptions = settings_test.changePictureOptions || { |
| 7 /** | 7 /** |
| 8 * True if property changes should fire events for testing purposes. | 8 * True if property changes should fire events for testing purposes. |
| 9 * @type {boolean} | 9 * @type {boolean} |
| 10 */ | 10 */ |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 */ | 23 */ |
| 24 Polymer({ | 24 Polymer({ |
| 25 is: 'settings-change-picture', | 25 is: 'settings-change-picture', |
| 26 | 26 |
| 27 behaviors: [ | 27 behaviors: [ |
| 28 I18nBehavior, | 28 I18nBehavior, |
| 29 ], | 29 ], |
| 30 | 30 |
| 31 properties: { | 31 properties: { |
| 32 /** | 32 /** |
| 33 * The currently selected profile image URL. May be a data URL. | 33 * The currently selected item. This property is bound to the iron-selector |
| 34 * @private {string} | 34 * and never directly assigned. |
| 35 * @private {Element} | |
| 35 */ | 36 */ |
| 36 selectedImageUrl_: { | 37 selectedItem_: { |
| 37 type: String, | 38 type: Element, |
| 38 notify: settings_test.changePictureOptions.notifyPropertyChangesForTest, | 39 notify: settings_test.changePictureOptions.notifyPropertyChangesForTest, |
| 39 }, | 40 }, |
| 40 | 41 |
| 41 /** | 42 /** |
| 42 * True only if the user has selected the camera icon. Old photos captured | |
| 43 * from the camera are represented as the 'old' image. | |
| 44 * @private {boolean} | |
| 45 */ | |
| 46 cameraActive_: { | |
| 47 type: Boolean, | |
| 48 value: false, | |
| 49 }, | |
| 50 | |
| 51 /** | |
| 52 * This differs from its default value only if the user has just captured | 43 * This differs from its default value only if the user has just captured |
| 53 * a new photo from the camera. | 44 * a new photo from the camera. |
| 54 * @private {string} | 45 * @private {string} |
| 55 */ | 46 */ |
| 56 cameraImageUrl_: { | 47 cameraImageUrl_: { |
| 57 type: String, | 48 type: String, |
| 58 value: settings.ChangePicturePrivateApi.ButtonImages.TAKE_PHOTO, | 49 value: settings.ChangePicturePrivateApi.ButtonImages.TAKE_PHOTO, |
| 59 }, | 50 }, |
| 60 | 51 |
| 61 /** | 52 /** |
| 62 * This differs from its default value only if the user has just captured | 53 * This differs from its default value only if the user has just captured |
| 63 * a new photo from the camera. | 54 * a new photo from the camera. |
| 64 * @private {string} | 55 * @private {string} |
| 65 */ | 56 */ |
| 66 cameraImageTitle_: { | 57 cameraImageTitle_: { |
| 67 type: String, | 58 type: String, |
| 68 value: function() { return loadTimeData.getString('takePhoto'); }, | 59 value: function() { return loadTimeData.getString('takePhoto'); }, |
| 69 }, | 60 }, |
| 70 | 61 |
| 71 /** | 62 /** |
| 72 * The url of the 'old' image, which is the existing image sourced from | 63 * The url of the 'old' image, which is the existing image sourced from |
| 73 * the camera, a file, or a deprecated default image. | 64 * the camera, a file, or a deprecated default image. It defaults to an |
| 65 * empty string instead of undefined, because Polymer bindings don't behave | |
| 66 * as expected with undefined properties. | |
| 74 * @private {string} | 67 * @private {string} |
| 75 */ | 68 */ |
| 76 oldImageUrl_: String, | 69 oldImageUrl_: { |
| 70 type: String, | |
| 71 value: '', | |
| 72 }, | |
| 77 | 73 |
| 78 /** | 74 /** |
| 79 * The url of the profile image. | 75 * The url of the profile image. |
| 80 * @private {string} | 76 * @private {string} |
| 81 */ | 77 */ |
| 82 profileImageUrl_: { | 78 profileImageUrl_: { |
| 83 type: String, | 79 type: String, |
| 84 value: settings.ChangePicturePrivateApi.ButtonImages.PROFILE_PICTURE, | 80 value: settings.ChangePicturePrivateApi.ButtonImages.PROFILE_PICTURE, |
| 85 }, | 81 }, |
| 86 | 82 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 100 var nativeInterface = { | 96 var nativeInterface = { |
| 101 /** | 97 /** |
| 102 * Called from C++ to provide the default set of images. | 98 * Called from C++ to provide the default set of images. |
| 103 * @param {!Array<!settings.DefaultImage>} images | 99 * @param {!Array<!settings.DefaultImage>} images |
| 104 */ | 100 */ |
| 105 receiveDefaultImages: function(images) { | 101 receiveDefaultImages: function(images) { |
| 106 this.defaultImages_ = images; | 102 this.defaultImages_ = images; |
| 107 }.bind(this), | 103 }.bind(this), |
| 108 | 104 |
| 109 /** | 105 /** |
| 110 * Called from C++ to provide the URL of the selected image. | 106 * Called from C++ to provide the URL of the selected image. Is only |
| 107 * called with default images. | |
| 111 * @param {string} imageUrl | 108 * @param {string} imageUrl |
| 112 */ | 109 */ |
| 113 receiveSelectedImage: function(imageUrl) { | 110 receiveSelectedImage: function(imageUrl) { |
| 114 this.cameraActive_ = false; | 111 var index = this.$.selector.items.findIndex(function(image) { |
| 115 this.selectedImageUrl_ = imageUrl; | 112 return image.dataset.type == 'default' && image.src == imageUrl; |
| 113 }); | |
| 114 assert(index != -1, 'Default image not found: ' + imageUrl); | |
| 115 this.$.selector.select(index); | |
| 116 }.bind(this), | 116 }.bind(this), |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * Called from C++ to provide the URL of the 'old' image. The 'old' | 119 * Called from C++ to provide the URL of the 'old' image. The 'old' |
| 120 * image is any selected non-profile and non-default image. It can be | 120 * image is any selected non-profile and non-default image. It can be |
| 121 * from the camera, a file, or a deprecated default image. When this | 121 * from the camera, a file, or a deprecated default image. When this |
| 122 * method is called, it's implied that the old image is selected. | 122 * method is called, it's implied that the old image is selected. |
| 123 * @param {string} imageUrl | 123 * @param {string} imageUrl |
| 124 */ | 124 */ |
| 125 receiveOldImage: function(imageUrl) { | 125 receiveOldImage: function(imageUrl) { |
| 126 this.cameraActive_ = false; | |
| 127 this.oldImageUrl_ = imageUrl; | 126 this.oldImageUrl_ = imageUrl; |
| 128 this.selectedImageUrl_ = imageUrl; | 127 this.$.selector.select(this.$.selector.indexOf(this.$.oldImage)); |
| 129 }.bind(this), | 128 }.bind(this), |
| 130 | 129 |
| 131 /** | 130 /** |
| 132 * Called from C++ to provide the URL of the profile image. | 131 * Called from C++ to provide the URL of the profile image. |
| 133 * @param {string} imageUrl | 132 * @param {string} imageUrl |
| 134 * @param {boolean} selected | 133 * @param {boolean} selected |
| 135 */ | 134 */ |
| 136 receiveProfileImage: function(imageUrl, selected) { | 135 receiveProfileImage: function(imageUrl, selected) { |
| 137 this.profileImageUrl_ = imageUrl; | 136 this.profileImageUrl_ = imageUrl; |
| 138 if (selected) { | 137 if (selected) |
| 139 this.cameraActive_ = false; | 138 this.$.selector.select(this.$.selector.indexOf(this.$.profileImage)); |
| 140 this.selectedImageUrl_ = imageUrl; | |
| 141 } | |
| 142 }.bind(this), | 139 }.bind(this), |
| 143 | 140 |
| 144 /** | 141 /** |
| 145 * Called from the C++ to notify page about camera presence. | 142 * Called from the C++ to notify page about camera presence. |
| 146 * @param {boolean} cameraPresent | 143 * @param {boolean} cameraPresent |
| 147 */ | 144 */ |
| 148 receiveCameraPresence: function(cameraPresent) { | 145 receiveCameraPresence: function(cameraPresent) { |
| 149 // TODO(tommycli): Implement camera functionality. | 146 // TODO(tommycli): Implement camera functionality. |
| 150 }.bind(this), | 147 }.bind(this), |
| 151 }; | 148 }; |
| 152 | 149 |
| 153 cr.define('settings', function() { | 150 cr.define('settings', function() { |
| 154 var ChangePicturePage = nativeInterface; | 151 var ChangePicturePage = nativeInterface; |
| 155 return { | 152 return { |
| 156 ChangePicturePage: ChangePicturePage, | 153 ChangePicturePage: ChangePicturePage, |
| 157 }; | 154 }; |
| 158 }); | 155 }); |
| 159 | 156 |
| 160 settings.ChangePicturePrivateApi.initialize(); | 157 settings.ChangePicturePrivateApi.initialize(); |
| 161 }, | 158 }, |
| 162 | 159 |
| 163 /** | 160 /** |
| 164 * Handler for when the user clicks the camera image. | 161 * Handler for when the an image is activated. |
| 162 * @param {!Event} event | |
| 165 * @private | 163 * @private |
| 166 */ | 164 */ |
| 167 onCameraImageTap_: function() { | 165 onImageActivate_: function(event) { |
| 168 this.cameraActive_ = true; | 166 var selectedImage = event.detail.item; |
| 169 }, | 167 switch (selectedImage.dataset.type) { |
| 170 | 168 case 'camera': |
| 171 /** | 169 // TODO(tommycli): Implement camera functionality. |
| 172 * Handler for when the user clicks a new profile image. | 170 break; |
| 173 * @private | 171 case 'profile': |
| 174 * @param {!Event} event | 172 settings.ChangePicturePrivateApi.selectProfileImage(); |
| 175 */ | 173 break; |
| 176 onDefaultImageTap_: function(event) { | 174 case 'old': |
| 177 var element = Polymer.dom(event).rootTarget; | 175 settings.ChangePicturePrivateApi.selectOldImage(); |
| 178 | 176 break; |
| 179 var imageUrl = null; | 177 case 'default': |
| 180 if (element.nodeName == 'IMG') | 178 settings.ChangePicturePrivateApi.selectDefaultImage(selectedImage.src); |
| 181 imageUrl = element.src; | 179 break; |
| 182 else if (element.dataset && element.dataset.imageUrl) | 180 default: |
| 183 imageUrl = element.dataset.imageUrl; | 181 assertNotReached('Selected unknown image type'); |
| 184 | |
| 185 if (imageUrl != null) { | |
| 186 settings.ChangePicturePrivateApi.selectDefaultImage(imageUrl); | |
| 187 // Button toggle state is instead controlled by the selected image URL. | |
| 188 event.preventDefault(); | |
| 189 } | 182 } |
| 190 }, | 183 }, |
| 191 | 184 |
| 192 /** | 185 /** |
| 193 * Handler for when the user clicks the 'old' image. | 186 * True if there is no old image and the selection icon should be hidden. |
| 187 * @param {string} oldImageUrl | |
|
dpapad
2016/01/22 20:12:25
@return missing.
tommycli
2016/01/22 21:37:53
Done.
| |
| 194 * @private | 188 * @private |
| 195 * @param {!Event} event | |
| 196 */ | 189 */ |
| 197 onOldImageTap_: function(event) { | 190 isOldImageHidden_: function(oldImageUrl) { |
| 198 settings.ChangePicturePrivateApi.selectOldImage(); | 191 return oldImageUrl.length == 0; |
| 199 // Button toggle state is instead controlled by the selected image URL. | |
| 200 event.preventDefault(); | |
| 201 }, | 192 }, |
| 202 | 193 |
| 203 /** | 194 /** |
| 204 * Handler for when the user clicks the 'profile' image. | 195 * True if the preview image is hidden and the camera controls are shown. |
| 196 * @param {!Element} selectedItem | |
| 205 * @private | 197 * @private |
|
dpapad
2016/01/22 20:12:25
@return missing.
tommycli
2016/01/22 21:37:53
Done.
| |
| 206 * @param {!Event} event | |
| 207 */ | 198 */ |
| 208 onProfileImageTap_: function(event) { | 199 isPreviewImageHidden_: function(selectedItem) { |
| 209 settings.ChangePicturePrivateApi.selectProfileImage(); | 200 // The selected item can be undefined on initial load and between selection |
| 210 // Button toggle state is instead controlled by the selected image URL. | 201 // changes. In those cases, show the preview image. |
| 211 event.preventDefault(); | 202 return selectedItem != undefined && selectedItem.dataset.type == 'camera'; |
| 212 }, | |
| 213 | |
| 214 /** | |
| 215 * Computed binding determining which profile image button is toggled on. | |
| 216 * @private | |
| 217 * @param {string} imageUrl | |
| 218 * @param {string} selectedImageUrl | |
| 219 * @return {boolean} | |
| 220 */ | |
| 221 isActiveImage_: function(cameraActive, imageUrl, selectedImageUrl) { | |
| 222 return !cameraActive && (imageUrl == selectedImageUrl); | |
| 223 }, | 203 }, |
| 224 }); | 204 }); |
| OLD | NEW |