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

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

Issue 2285413002: [User Menu] Flipped the profile badge to be on the LHS for RTL layouts (Closed)
Patch Set: Cleanup unnecessary overload. Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); 365 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia());
366 SetBorder(views::Border::NullBorder()); 366 SetBorder(views::Border::NullBorder());
367 if (switches::IsMaterialDesignUserMenu()) { 367 if (switches::IsMaterialDesignUserMenu()) {
368 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), 368 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(),
369 GetPreferredSize().height() + badge_spacing() + 369 GetPreferredSize().height() + badge_spacing() +
370 views::kRelatedControlSmallVerticalSpacing)); 370 views::kRelatedControlSmallVerticalSpacing));
371 } else { 371 } else {
372 SetSize(GetPreferredSize()); 372 SetSize(GetPreferredSize());
373 } 373 }
374 374
375 // Calculate the circular mask that will be used to display the photo.
376 circular_mask_.addCircle(
377 SkIntToScalar(icon_image_side() / 2),
378 SkIntToScalar(icon_image_side() / 2) + badge_spacing(),
379 SkIntToScalar(icon_image_side() / 2));
380
381 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { 375 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) {
382 SetEnabled(false); 376 SetEnabled(false);
383 return; 377 return;
384 } 378 }
385 379
386 set_notify_enter_exit_on_child(true); 380 set_notify_enter_exit_on_child(true);
387 381
388 // Photo overlay that appears when hovering over the button. 382 // Photo overlay that appears when hovering over the button.
389 photo_overlay_ = new views::ImageView(); 383 photo_overlay_ = new views::ImageView();
390 384
391 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); 385 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255);
392 photo_overlay_->set_background( 386 photo_overlay_->set_background(
393 views::Background::CreateSolidBackground(kBackgroundColor)); 387 views::Background::CreateSolidBackground(kBackgroundColor));
394 photo_overlay_->SetImage(gfx::CreateVectorIcon( 388 photo_overlay_->SetImage(gfx::CreateVectorIcon(
395 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); 389 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33)));
396 390
397 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side())); 391 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side()));
398 photo_overlay_->SetY(badge_spacing()); 392 photo_overlay_->SetY(badge_spacing());
399 photo_overlay_->SetVisible(false); 393 photo_overlay_->SetVisible(false);
400 AddChildView(photo_overlay_); 394 AddChildView(photo_overlay_);
401 } 395 }
402 396
403 void OnPaint(gfx::Canvas* canvas) override {
404 canvas->Save();
405 // Display the profile picture as a circle.
406 canvas->ClipPath(circular_mask_, true);
407 views::LabelButton::OnPaint(canvas);
408 canvas->Restore();
409 }
410
411 void PaintChildren(const ui::PaintContext& context) override { 397 void PaintChildren(const ui::PaintContext& context) override {
412 { 398 {
413 // Display any children (the "change photo" overlay) as a circle. 399 // Display any children (the "change photo" overlay) as a circle.
414 ui::ClipRecorder clip_recorder(context); 400 ui::ClipRecorder clip_recorder(context);
415 clip_recorder.ClipPathWithAntiAliasing(circular_mask_); 401 gfx::Rect clip_bounds = image()->GetMirroredBounds();
402 gfx::Path clip_mask;
403 clip_mask.addCircle(
404 clip_bounds.x() + clip_bounds.width() / 2,
405 clip_bounds.y() + clip_bounds.height() / 2,
406 clip_bounds.width() / 2);
407 clip_recorder.ClipPathWithAntiAliasing(clip_mask);
416 View::PaintChildren(context); 408 View::PaintChildren(context);
417 } 409 }
418 410
419 ui::PaintRecorder paint_recorder( 411 ui::PaintRecorder paint_recorder(
420 context, gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize())); 412 context, gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize()));
421 gfx::Canvas* canvas = paint_recorder.canvas(); 413 gfx::Canvas* canvas = paint_recorder.canvas();
422 if (profile_->IsSupervised()) { 414 if (profile_->IsSupervised()) {
423 gfx::Rect bounds(0, 0, GetProfileBadgeSize(), GetProfileBadgeSize()); 415 gfx::Rect bounds(0, 0, GetProfileBadgeSize(), GetProfileBadgeSize());
424 int badge_offset = 416 int badge_offset =
425 icon_image_side() + badge_spacing() - GetProfileBadgeSize(); 417 icon_image_side() + badge_spacing() - GetProfileBadgeSize();
426 gfx::Vector2d badge_offset_vector = gfx::Vector2d( 418 gfx::Vector2d badge_offset_vector = gfx::Vector2d(
427 badge_offset, 419 GetMirroredXWithWidthInView(badge_offset, GetProfileBadgeSize()),
428 badge_offset + (switches::IsMaterialDesignUserMenu() 420 badge_offset + (switches::IsMaterialDesignUserMenu()
429 ? views::kRelatedControlSmallVerticalSpacing 421 ? views::kRelatedControlSmallVerticalSpacing
430 : 0)); 422 : 0));
423
431 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector; 424 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector;
432 425
433 // Paint the circular background. 426 // Paint the circular background.
434 SkPaint paint; 427 SkPaint paint;
435 paint.setAntiAlias(true); 428 paint.setAntiAlias(true);
436 paint.setColor(GetNativeTheme()->GetSystemColor( 429 paint.setColor(GetNativeTheme()->GetSystemColor(
437 ui::NativeTheme::kColorId_BubbleBackground)); 430 ui::NativeTheme::kColorId_BubbleBackground));
438 canvas->DrawCircle(center_point, GetProfileBadgeSize() / 2, paint); 431 canvas->DrawCircle(center_point, GetProfileBadgeSize() / 2, paint);
439 432
440 gfx::VectorIconId icon_id; 433 gfx::VectorIconId icon_id;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 } 489 }
497 490
498 void OnBlur() override { 491 void OnBlur() override {
499 views::LabelButton::OnBlur(); 492 views::LabelButton::OnBlur();
500 // Don't hide the overlay if it's being shown as a result of a mouseover. 493 // Don't hide the overlay if it's being shown as a result of a mouseover.
501 if (photo_overlay_ && state() != STATE_HOVERED) 494 if (photo_overlay_ && state() != STATE_HOVERED)
502 photo_overlay_->SetVisible(false); 495 photo_overlay_->SetVisible(false);
503 } 496 }
504 497
505 bool interactive_; 498 bool interactive_;
506 gfx::Path circular_mask_;
507 499
508 // Image that is shown when hovering over the image button. Can be NULL if 500 // Image that is shown when hovering over the image button. Can be NULL if
509 // the photo isn't allowed to be edited (e.g. for guest profiles). 501 // the photo isn't allowed to be edited (e.g. for guest profiles).
510 views::ImageView* photo_overlay_; 502 views::ImageView* photo_overlay_;
511 503
512 Profile* profile_; 504 Profile* profile_;
513 505
514 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); 506 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto);
515 }; 507 };
516 508
(...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2303 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2312 IncognitoModePrefs::DISABLED; 2304 IncognitoModePrefs::DISABLED;
2313 return incognito_available && !browser_->profile()->IsGuestSession(); 2305 return incognito_available && !browser_->profile()->IsGuestSession();
2314 } 2306 }
2315 2307
2316 void ProfileChooserView::PostActionPerformed( 2308 void ProfileChooserView::PostActionPerformed(
2317 ProfileMetrics::ProfileDesktopMenu action_performed) { 2309 ProfileMetrics::ProfileDesktopMenu action_performed) {
2318 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 2310 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
2319 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 2311 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
2320 } 2312 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698