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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 290333012: [Win] Draw the circular avatar programmatically rather than with a frame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing virtual keyword Created 6 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 20 matching lines...) Expand all
31 #include "components/signin/core/common/profile_management_switches.h" 31 #include "components/signin/core/common/profile_management_switches.h"
32 #include "grit/chromium_strings.h" 32 #include "grit/chromium_strings.h"
33 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
34 #include "grit/theme_resources.h" 34 #include "grit/theme_resources.h"
35 #include "third_party/skia/include/core/SkColor.h" 35 #include "third_party/skia/include/core/SkColor.h"
36 #include "ui/base/l10n/l10n_util.h" 36 #include "ui/base/l10n/l10n_util.h"
37 #include "ui/base/resource/resource_bundle.h" 37 #include "ui/base/resource/resource_bundle.h"
38 #include "ui/gfx/canvas.h" 38 #include "ui/gfx/canvas.h"
39 #include "ui/gfx/image/image.h" 39 #include "ui/gfx/image/image.h"
40 #include "ui/gfx/image/image_skia.h" 40 #include "ui/gfx/image/image_skia.h"
41 #include "ui/gfx/path.h"
42 #include "ui/gfx/skia_util.h"
41 #include "ui/gfx/text_elider.h" 43 #include "ui/gfx/text_elider.h"
42 #include "ui/native_theme/native_theme.h" 44 #include "ui/native_theme/native_theme.h"
43 #include "ui/views/controls/button/blue_button.h" 45 #include "ui/views/controls/button/blue_button.h"
44 #include "ui/views/controls/button/image_button.h" 46 #include "ui/views/controls/button/image_button.h"
45 #include "ui/views/controls/button/label_button.h" 47 #include "ui/views/controls/button/label_button.h"
46 #include "ui/views/controls/button/menu_button.h" 48 #include "ui/views/controls/button/menu_button.h"
47 #include "ui/views/controls/label.h" 49 #include "ui/views/controls/label.h"
48 #include "ui/views/controls/link.h" 50 #include "ui/views/controls/link.h"
49 #include "ui/views/controls/separator.h" 51 #include "ui/views/controls/separator.h"
50 #include "ui/views/controls/styled_label.h" 52 #include "ui/views/controls/styled_label.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 const gfx::Image& icon, 152 const gfx::Image& icon,
151 bool is_editing_allowed, 153 bool is_editing_allowed,
152 const gfx::Rect& bounds) 154 const gfx::Rect& bounds)
153 : views::ImageView(), 155 : views::ImageView(),
154 change_photo_button_(NULL) { 156 change_photo_button_(NULL) {
155 gfx::Image image = profiles::GetSizedAvatarIcon( 157 gfx::Image image = profiles::GetSizedAvatarIcon(
156 icon, true, kLargeImageSide, kLargeImageSide); 158 icon, true, kLargeImageSide, kLargeImageSide);
157 SetImage(image.ToImageSkia()); 159 SetImage(image.ToImageSkia());
158 SetBoundsRect(bounds); 160 SetBoundsRect(bounds);
159 161
160 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 162 // Calculate the circular mask that will be used to display the photo.
161 views::ImageView* frame_overlay = new views::ImageView(); 163 gfx::Point center = bounds.CenterPoint();
162 frame_overlay->SetImage(rb->GetImageNamed( 164 circular_mask_.addCircle(SkIntToScalar(center.x()),
163 IDR_ICON_PROFILES_AVATAR_PHOTO_FRAME).ToImageSkia()); 165 SkIntToScalar(center.y()),
164 frame_overlay->SetVerticalAlignment(views::ImageView::CENTER); 166 SkIntToScalar(bounds.width() / 2));
165 frame_overlay->SetBoundsRect(bounds);
166 AddChildView(frame_overlay);
167 167
168 if (!is_editing_allowed) 168 if (!is_editing_allowed)
169 return; 169 return;
170 170
171 set_notify_enter_exit_on_child(true); 171 set_notify_enter_exit_on_child(true);
172 172
173 // Button overlay that appears when hovering over the image. 173 // Button overlay that appears when hovering over the image.
174 change_photo_button_ = new views::LabelButton(listener, base::string16()); 174 change_photo_button_ = new views::LabelButton(listener, base::string16());
175 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 175 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
176 change_photo_button_->SetBorder(views::Border::NullBorder()); 176 change_photo_button_->SetBorder(views::Border::NullBorder());
177 177
178 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); 178 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
179 change_photo_button_->set_background( 179 change_photo_button_->set_background(
180 views::Background::CreateSolidBackground(kBackgroundColor)); 180 views::Background::CreateSolidBackground(kBackgroundColor));
181 change_photo_button_->SetImage(views::LabelButton::STATE_NORMAL, 181 change_photo_button_->SetImage(views::LabelButton::STATE_NORMAL,
182 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_CAMERA)); 182 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
183 IDR_ICON_PROFILES_EDIT_CAMERA));
183 184
184 change_photo_button_->SetBoundsRect(bounds); 185 change_photo_button_->SetBoundsRect(bounds);
185 change_photo_button_->SetVisible(false); 186 change_photo_button_->SetVisible(false);
186 AddChildView(change_photo_button_); 187 AddChildView(change_photo_button_);
187 } 188 }
188 189
190 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
191 // Display the profile picture as a circle.
192 canvas->ClipPath(circular_mask_, true);
193 views::ImageView::OnPaint(canvas);
194 }
195
196 virtual void PaintChildren(gfx::Canvas* canvas,
197 const views::CullSet& cull_set) OVERRIDE {
198 // Display any children (the "change photo" overlay) as a circle.
199 canvas->ClipPath(circular_mask_, true);
200 View::PaintChildren(canvas, cull_set);
201 }
202
189 views::LabelButton* change_photo_button() { return change_photo_button_; } 203 views::LabelButton* change_photo_button() { return change_photo_button_; }
190 204
191 private: 205 private:
192 // views::View: 206 // views::View:
193 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { 207 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
194 if (change_photo_button_) 208 if (change_photo_button_)
195 change_photo_button_->SetVisible(true); 209 change_photo_button_->SetVisible(true);
196 } 210 }
197 211
198 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE { 212 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
199 if (change_photo_button_) 213 if (change_photo_button_)
200 change_photo_button_->SetVisible(false); 214 change_photo_button_->SetVisible(false);
201 } 215 }
202 216
217 gfx::Path circular_mask_;
218
203 // Button that is shown when hovering over the image view. Can be NULL if 219 // Button that is shown when hovering over the image view. Can be NULL if
204 // the photo isn't allowed to be edited (e.g. for guest profiles). 220 // the photo isn't allowed to be edited (e.g. for guest profiles).
205 views::LabelButton* change_photo_button_; 221 views::LabelButton* change_photo_button_;
206 222
207 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); 223 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto);
208 }; 224 };
209 225
210 226
211 // EditableProfileName ------------------------------------------------- 227 // EditableProfileName -------------------------------------------------
212 228
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 layout->StartRowWithPadding( 1318 layout->StartRowWithPadding(
1303 1, 0, 0, views::kUnrelatedControlVerticalSpacing); 1319 1, 0, 0, views::kUnrelatedControlVerticalSpacing);
1304 layout->AddView(end_preview_and_relaunch_button_); 1320 layout->AddView(end_preview_and_relaunch_button_);
1305 1321
1306 TitleCard* title_card = new TitleCard( 1322 TitleCard* title_card = new TitleCard(
1307 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_); 1323 IDS_PROFILES_END_PREVIEW, this, &end_preview_cancel_button_);
1308 return TitleCard::AddPaddedTitleCard( 1324 return TitleCard::AddPaddedTitleCard(
1309 view, title_card, kFixedAccountRemovalViewWidth); 1325 view, title_card, kFixedAccountRemovalViewWidth);
1310 } 1326 }
1311 1327
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_dialog_views.cc ('k') | ui/app_list/views/app_list_background.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698