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

Side by Side Diff: chrome/browser/resources/settings/people_page/change_picture.js

Issue 1575543003: Settings People Revamp: Implement parts of ChromeOS Change Picture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactor Created 4 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview
7 * 'settings-change-picture' is the settings subpage containing controls to
8 * edit a ChromeOS user's picture.
9 *
10 * @group Chrome Settings Elements
11 * @element settings-change-picture
12 */
13 Polymer({
14 is: 'settings-change-picture',
15
16 behaviors: [
17 I18nBehavior,
18 ],
19
20 properties: {
21 /**
22 * The currently selected profile image URL. May be a data URL.
23 * @private {string}
24 */
25 selectedImageUrl_: String,
26
27 /**
28 * The url of the 'old' image, which is the existing image sourced from
29 * the camera, a file, or a deprecated default image.
30 * @private {string}
31 */
32 oldImageUrl_: String,
33
34 /**
35 * The url of the profile image.
36 * @private {string}
37 */
38 profileImageUrl_: {
39 type: String,
40 value: settings.ChangePicturePrivateApi.ButtonImages.PROFILE_PICTURE,
41 },
42
43 /**
44 * The default user images. Populated by ChangePicturePrivateApi.
45 * @private {!Array<!settings.DefaultImage>}
46 */
47 defaultImages_: {
48 type: Array,
49 value: function() { return []; },
50 },
51 },
52
53 /** @override */
54 attached: function() {
55 // This is the interface called by the C++ handler.
56 var nativeInterface = {
57 /**
58 * Called from C++ to provide the default set of images.
59 * @param {!Array<!settings.DefaultImage>} images
60 */
61 receiveDefaultImages: function(images) {
62 this.defaultImages_ = images;
63 }.bind(this),
64
65 /**
66 * Called from C++ to provide the URL of the selected image.
67 * @param {string} imageUrl
68 */
69 receiveSelectedImage: function(imageUrl) {
70 this.selectedImageUrl_ = imageUrl;
71 }.bind(this),
72
73 /**
74 * Called from C++ to provide the URL of the 'old' image. The 'old'
75 * image is any selected non-profile and non-default image. It can be
76 * from the camera, a file, or a deprecated default image. When this
77 * method is called, it's implied that the old image is selected.
78 * @param {string} imageUrl
79 */
80 receiveOldImage: function(imageUrl) {
81 this.oldImageUrl_ = imageUrl;
82 this.selectedImageUrl_ = imageUrl;
83 }.bind(this),
84
85 /**
86 * Called from C++ to provide the URL of the profile image.
87 * @param {string} imageUrl
88 * @param {boolean} selected
89 */
90 receiveProfileImage: function(imageUrl, selected) {
91 this.profileImageUrl_ = imageUrl;
92 if (selected)
93 this.selectedImageUrl_ = imageUrl;
94 }.bind(this),
95
96 /**
97 * Called from the C++ to notify page about camera presence.
98 * @param {boolean} cameraPresent
99 */
100 receiveCameraPresence: function(cameraPresent) {
101 // TODO(tommycli): Implement camera functionality.
102 }.bind(this),
103 };
104
105 cr.define('settings', function() {
106 var ChangePicturePage = nativeInterface;
dpapad 2016/01/13 19:00:07 Nit: Does the compiler complain if you do directly
tommycli 2016/01/13 19:35:17 Exactly. That's what I had initially, but I get #
107 return {
108 ChangePicturePage: ChangePicturePage,
109 };
110 });
111
112 settings.ChangePicturePrivateApi.initialize();
113 },
114
115 /**
116 * Handler for when the user clicks a new profile image.
117 * @private
118 * @param {!Event} event
119 */
120 onDefaultImageTap_: function(event) {
121 var element = Polymer.dom(event).rootTarget;
122
123 var imageUrl = null;
124 if (element.nodeName == 'IMG')
125 imageUrl = element.src;
126 else if (element.dataset && element.dataset.imageUrl)
127 imageUrl = element.dataset.imageUrl;
128
129 if (imageUrl != null) {
130 settings.ChangePicturePrivateApi.selectDefaultImage(imageUrl);
131 // Button toggle state is instead controlled by the selected image URL.
132 event.preventDefault();
133 }
134 },
135
136 /**
137 * Handler for when the user clicks the 'old' image.
138 * @private
139 * @param {!Event} event
140 */
141 onOldImageTap_: function(event) {
142 settings.ChangePicturePrivateApi.selectOldImage();
143 // Button toggle state is instead controlled by the selected image URL.
144 event.preventDefault();
145 },
146
147 /**
148 * Handler for when the user clicks the 'profile' image.
149 * @private
150 * @param {!Event} event
151 */
152 onProfileImageTap_: function(event) {
153 settings.ChangePicturePrivateApi.selectProfileImage();
154 // Button toggle state is instead controlled by the selected image URL.
155 event.preventDefault();
156 },
157
158 /**
159 * Computed binding determining which profile image button is toggled on.
160 * @private
161 * @param {string} imageUrl
162 * @param {string} selectedImageUrl
163 * @return {boolean}
164 */
165 isActiveImage_: function(imageUrl, selectedImageUrl) {
166 return imageUrl == selectedImageUrl;
167 },
168 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698