Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 { | 397 void OnPaint(gfx::Canvas* canvas) override { |
|
sky
2016/08/29 22:38:09
AFAICT this override isn't necessary. Am I missing
anthonyvd
2016/08/30 14:31:31
You're absolutely right, thanks!
Done.
| |
| 404 canvas->Save(); | 398 canvas->Save(); |
| 405 // Display the profile picture as a circle. | |
| 406 canvas->ClipPath(circular_mask_, true); | |
| 407 views::LabelButton::OnPaint(canvas); | 399 views::LabelButton::OnPaint(canvas); |
| 408 canvas->Restore(); | 400 canvas->Restore(); |
| 409 } | 401 } |
| 410 | 402 |
| 411 void PaintChildren(const ui::PaintContext& context) override { | 403 void PaintChildren(const ui::PaintContext& context) override { |
| 412 { | 404 { |
| 413 // Display any children (the "change photo" overlay) as a circle. | 405 // Display any children (the "change photo" overlay) as a circle. |
| 414 ui::ClipRecorder clip_recorder(context); | 406 ui::ClipRecorder clip_recorder(context); |
| 415 clip_recorder.ClipPathWithAntiAliasing(circular_mask_); | 407 gfx::Rect clip_bounds = image()->GetMirroredBounds(); |
| 408 gfx::Path clip_mask; | |
| 409 clip_mask.addCircle( | |
| 410 clip_bounds.x() + clip_bounds.width() / 2, | |
| 411 clip_bounds.y() + clip_bounds.height() / 2, | |
| 412 clip_bounds.width() / 2); | |
| 413 clip_recorder.ClipPathWithAntiAliasing(clip_mask); | |
| 416 View::PaintChildren(context); | 414 View::PaintChildren(context); |
| 417 } | 415 } |
| 418 | 416 |
| 419 ui::PaintRecorder paint_recorder( | 417 ui::PaintRecorder paint_recorder( |
| 420 context, gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize())); | 418 context, gfx::Size(GetProfileBadgeSize(), GetProfileBadgeSize())); |
| 421 gfx::Canvas* canvas = paint_recorder.canvas(); | 419 gfx::Canvas* canvas = paint_recorder.canvas(); |
| 422 if (profile_->IsSupervised()) { | 420 if (profile_->IsSupervised()) { |
| 423 gfx::Rect bounds(0, 0, GetProfileBadgeSize(), GetProfileBadgeSize()); | 421 gfx::Rect bounds(0, 0, GetProfileBadgeSize(), GetProfileBadgeSize()); |
| 424 int badge_offset = | 422 int badge_offset = |
| 425 icon_image_side() + badge_spacing() - GetProfileBadgeSize(); | 423 icon_image_side() + badge_spacing() - GetProfileBadgeSize(); |
| 426 gfx::Vector2d badge_offset_vector = gfx::Vector2d( | 424 gfx::Vector2d badge_offset_vector = gfx::Vector2d( |
| 427 badge_offset, | 425 GetMirroredXWithWidthInView(badge_offset, GetProfileBadgeSize()), |
| 428 badge_offset + (switches::IsMaterialDesignUserMenu() | 426 badge_offset + (switches::IsMaterialDesignUserMenu() |
| 429 ? views::kRelatedControlSmallVerticalSpacing | 427 ? views::kRelatedControlSmallVerticalSpacing |
| 430 : 0)); | 428 : 0)); |
| 429 | |
| 431 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector; | 430 gfx::Point center_point = bounds.CenterPoint() + badge_offset_vector; |
| 432 | 431 |
| 433 // Paint the circular background. | 432 // Paint the circular background. |
| 434 SkPaint paint; | 433 SkPaint paint; |
| 435 paint.setAntiAlias(true); | 434 paint.setAntiAlias(true); |
| 436 paint.setColor(GetNativeTheme()->GetSystemColor( | 435 paint.setColor(GetNativeTheme()->GetSystemColor( |
| 437 ui::NativeTheme::kColorId_BubbleBackground)); | 436 ui::NativeTheme::kColorId_BubbleBackground)); |
| 438 canvas->DrawCircle(center_point, GetProfileBadgeSize() / 2, paint); | 437 canvas->DrawCircle(center_point, GetProfileBadgeSize() / 2, paint); |
| 439 | 438 |
| 440 gfx::VectorIconId icon_id; | 439 gfx::VectorIconId icon_id; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 } | 495 } |
| 497 | 496 |
| 498 void OnBlur() override { | 497 void OnBlur() override { |
| 499 views::LabelButton::OnBlur(); | 498 views::LabelButton::OnBlur(); |
| 500 // Don't hide the overlay if it's being shown as a result of a mouseover. | 499 // Don't hide the overlay if it's being shown as a result of a mouseover. |
| 501 if (photo_overlay_ && state() != STATE_HOVERED) | 500 if (photo_overlay_ && state() != STATE_HOVERED) |
| 502 photo_overlay_->SetVisible(false); | 501 photo_overlay_->SetVisible(false); |
| 503 } | 502 } |
| 504 | 503 |
| 505 bool interactive_; | 504 bool interactive_; |
| 506 gfx::Path circular_mask_; | |
| 507 | 505 |
| 508 // Image that is shown when hovering over the image button. Can be NULL if | 506 // 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). | 507 // the photo isn't allowed to be edited (e.g. for guest profiles). |
| 510 views::ImageView* photo_overlay_; | 508 views::ImageView* photo_overlay_; |
| 511 | 509 |
| 512 Profile* profile_; | 510 Profile* profile_; |
| 513 | 511 |
| 514 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); | 512 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); |
| 515 }; | 513 }; |
| 516 | 514 |
| (...skipping 1794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2311 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2309 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2312 IncognitoModePrefs::DISABLED; | 2310 IncognitoModePrefs::DISABLED; |
| 2313 return incognito_available && !browser_->profile()->IsGuestSession(); | 2311 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2314 } | 2312 } |
| 2315 | 2313 |
| 2316 void ProfileChooserView::PostActionPerformed( | 2314 void ProfileChooserView::PostActionPerformed( |
| 2317 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2315 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2318 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2316 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2319 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2317 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2320 } | 2318 } |
| OLD | NEW |