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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 back_button->set_request_focus_on_press(true); | 175 back_button->set_request_focus_on_press(true); |
| 176 return back_button; | 176 return back_button; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // BackgroundColorHoverButton ------------------------------------------------- | 179 // BackgroundColorHoverButton ------------------------------------------------- |
| 180 | 180 |
| 181 // A custom button that allows for setting a background color when hovered over. | 181 // A custom button that allows for setting a background color when hovered over. |
| 182 class BackgroundColorHoverButton : public views::LabelButton { | 182 class BackgroundColorHoverButton : public views::LabelButton { |
| 183 public: | 183 public: |
| 184 BackgroundColorHoverButton(views::ButtonListener* listener, | 184 BackgroundColorHoverButton(views::ButtonListener* listener, |
| 185 const base::string16& text, | 185 const base::string16& text) |
| 186 const gfx::ImageSkia& icon) | |
| 187 : views::LabelButton(listener, text) { | 186 : views::LabelButton(listener, text) { |
| 188 SetImageLabelSpacing(views::kItemLabelSpacing); | 187 SetImageLabelSpacing(views::kItemLabelSpacing); |
| 188 const int button_margin = switches::IsMaterialDesignUserMenu() | |
| 189 ? kMaterialMenuEdgeMargin | |
| 190 : views::kButtonHEdgeMarginNew; | |
| 189 SetBorder(views::Border::CreateEmptyBorder( | 191 SetBorder(views::Border::CreateEmptyBorder( |
| 190 0, views::kButtonHEdgeMarginNew, 0, views::kButtonHEdgeMarginNew)); | 192 0, button_margin, 0, button_margin)); |
| 191 SetMinSize(gfx::Size(0, | |
| 192 kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
| 193 SetImage(STATE_NORMAL, icon); | |
| 194 SetFocusForPlatform(); | 193 SetFocusForPlatform(); |
| 195 set_request_focus_on_press(true); | 194 set_request_focus_on_press(true); |
| 196 } | 195 } |
| 197 | 196 |
| 197 BackgroundColorHoverButton(views::ButtonListener* listener, | |
| 198 const base::string16& text, | |
| 199 const gfx::ImageSkia& icon) | |
| 200 : BackgroundColorHoverButton(listener, text) { | |
| 201 SetMinSize(gfx::Size(0, | |
|
sky
2016/06/30 22:00:40
Are you sure you don't want to include the size of
Jane
2016/07/01 03:22:54
Done. This line is from line 191 so I thought it's
| |
| 202 kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
| 203 SetImage(STATE_NORMAL, icon); | |
| 204 } | |
| 205 | |
| 198 ~BackgroundColorHoverButton() override {} | 206 ~BackgroundColorHoverButton() override {} |
| 199 | 207 |
| 200 private: | 208 private: |
| 201 // views::LabelButton: | 209 // views::LabelButton: |
| 202 void OnPaint(gfx::Canvas* canvas) override { | 210 void OnPaint(gfx::Canvas* canvas) override { |
| 203 if ((state() == STATE_PRESSED) || | 211 if ((state() == STATE_PRESSED) || |
| 204 (state() == STATE_HOVERED)) { | 212 (state() == STATE_HOVERED)) { |
| 205 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 213 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
| 206 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); | 214 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); |
| 207 } | 215 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 218 public: | 226 public: |
| 219 explicit SizedContainer(const gfx::Size& preferred_size) | 227 explicit SizedContainer(const gfx::Size& preferred_size) |
| 220 : preferred_size_(preferred_size) {} | 228 : preferred_size_(preferred_size) {} |
| 221 | 229 |
| 222 gfx::Size GetPreferredSize() const override { return preferred_size_; } | 230 gfx::Size GetPreferredSize() const override { return preferred_size_; } |
| 223 | 231 |
| 224 private: | 232 private: |
| 225 gfx::Size preferred_size_; | 233 gfx::Size preferred_size_; |
| 226 }; | 234 }; |
| 227 | 235 |
| 236 // NonInteractiveContainer ------------------------------------------------- | |
| 237 | |
| 238 // A simple container view that does not process events within subtree. | |
| 239 class NonInteractiveContainer : public views::View { | |
| 240 public: | |
| 241 NonInteractiveContainer() {} | |
| 242 | |
| 243 bool CanProcessEventsWithinSubtree() const override { return false; } | |
|
sky
2016/06/30 22:00:41
nit: generally sections that override functions ha
Jane
2016/07/01 03:22:54
Done.
| |
| 244 }; | |
|
sky
2016/06/30 22:00:41
Good practice is to have private: DISALLOW_... (se
Jane
2016/07/01 03:22:54
Done.
| |
| 245 | |
| 228 // A view to host the GAIA webview overlapped with a back button. This class | 246 // A view to host the GAIA webview overlapped with a back button. This class |
| 229 // is needed to reparent the back button inside a native view so that on | 247 // is needed to reparent the back button inside a native view so that on |
| 230 // windows, user input can be be properly routed to the button. | 248 // windows, user input can be be properly routed to the button. |
| 231 class HostView : public views::View { | 249 class HostView : public views::View { |
| 232 public: | 250 public: |
| 233 HostView() {} | 251 HostView() {} |
| 234 | 252 |
| 235 void Initialize(views::View* title_view, views::View* main_view); | 253 void Initialize(views::View* title_view, views::View* main_view); |
| 236 | 254 |
| 237 private: | 255 private: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 gfx::Rect bounds(title_view_->GetPreferredSize()); | 289 gfx::Rect bounds(title_view_->GetPreferredSize()); |
| 272 title_view_->SetBoundsRect(bounds); | 290 title_view_->SetBoundsRect(bounds); |
| 273 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); | 291 bounds.Offset(kTitleViewNativeWidgetOffset, kTitleViewNativeWidgetOffset); |
| 274 title_widget_->SetBounds(bounds); | 292 title_widget_->SetBounds(bounds); |
| 275 } | 293 } |
| 276 | 294 |
| 277 } // namespace | 295 } // namespace |
| 278 | 296 |
| 279 // RightAlignedIconLabelButton ------------------------------------------------- | 297 // RightAlignedIconLabelButton ------------------------------------------------- |
| 280 | 298 |
| 281 // A custom LabelButton that has a left-aligned text and right aligned icon. | 299 // A custom LabelButton that has a center-aligned text and right aligned icon. |
| 282 // For non-material-design user menu, it has centered text instead. | 300 // Only used in non-material-design user menu. |
| 283 class RightAlignedIconLabelButton : public views::LabelButton { | 301 class RightAlignedIconLabelButton : public views::LabelButton { |
| 284 public: | 302 public: |
| 285 RightAlignedIconLabelButton(views::ButtonListener* listener, | 303 RightAlignedIconLabelButton(views::ButtonListener* listener, |
| 286 const base::string16& text) | 304 const base::string16& text) |
| 287 : views::LabelButton(listener, text) { | 305 : views::LabelButton(listener, text) { |
| 288 SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 306 SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 289 label()->SetHorizontalAlignment(switches::IsMaterialDesignUserMenu() | 307 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 290 ? gfx::ALIGN_LEFT | |
| 291 : gfx::ALIGN_CENTER); | |
| 292 } | 308 } |
| 293 | 309 |
| 294 protected: | 310 protected: |
| 295 void Layout() override { | 311 void Layout() override { |
| 296 views::LabelButton::Layout(); | 312 views::LabelButton::Layout(); |
| 297 | 313 |
| 298 // Keep the text centered and the icon right-aligned by stretching the label | 314 // Keep the text centered and the icon right-aligned by stretching the label |
| 299 // to take up more of the content area and centering its contents. | 315 // to take up more of the content area and centering its contents. |
| 300 gfx::Rect content_bounds = GetContentsBounds(); | 316 gfx::Rect content_bounds = GetContentsBounds(); |
| 301 gfx::Rect label_bounds = label()->bounds(); | 317 gfx::Rect label_bounds = label()->bounds(); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 320 const size_t kProfileBadgeWhitePadding = 2; | 336 const size_t kProfileBadgeWhitePadding = 2; |
| 321 | 337 |
| 322 // A custom Image control that shows a "change" button when moused over. | 338 // A custom Image control that shows a "change" button when moused over. |
| 323 class EditableProfilePhoto : public views::LabelButton { | 339 class EditableProfilePhoto : public views::LabelButton { |
| 324 public: | 340 public: |
| 325 EditableProfilePhoto(views::ButtonListener* listener, | 341 EditableProfilePhoto(views::ButtonListener* listener, |
| 326 const gfx::Image& icon, | 342 const gfx::Image& icon, |
| 327 bool is_editing_allowed, | 343 bool is_editing_allowed, |
| 328 Profile* profile) | 344 Profile* profile) |
| 329 : views::LabelButton(listener, base::string16()), | 345 : views::LabelButton(listener, base::string16()), |
| 346 interactive_(!switches::IsMaterialDesignUserMenu()), | |
| 330 photo_overlay_(nullptr), | 347 photo_overlay_(nullptr), |
| 331 profile_(profile) { | 348 profile_(profile) { |
| 332 gfx::Image image = profiles::GetSizedAvatarIcon( | 349 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 333 icon, true, icon_image_side(), icon_image_side()); | 350 icon, true, icon_image_side(), icon_image_side()); |
| 334 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); | 351 SetImage(views::LabelButton::STATE_NORMAL, *image.ToImageSkia()); |
| 335 SetBorder(views::Border::NullBorder()); | 352 SetBorder(views::Border::NullBorder()); |
| 336 if (switches::IsMaterialDesignUserMenu()) { | 353 if (switches::IsMaterialDesignUserMenu()) { |
| 337 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), | 354 SetMinSize(gfx::Size(GetPreferredSize().width() + badge_spacing(), |
| 338 GetPreferredSize().height() + badge_spacing() + | 355 GetPreferredSize().height() + badge_spacing() + |
| 339 views::kRelatedControlSmallVerticalSpacing)); | 356 views::kRelatedControlSmallVerticalSpacing)); |
| 340 } else { | 357 } else { |
| 341 SetSize(GetPreferredSize()); | 358 SetSize(GetPreferredSize()); |
| 342 } | 359 } |
| 343 | 360 |
| 344 // Calculate the circular mask that will be used to display the photo. | 361 // Calculate the circular mask that will be used to display the photo. |
| 345 circular_mask_.addCircle( | 362 circular_mask_.addCircle( |
| 346 SkIntToScalar(icon_image_side() / 2), | 363 SkIntToScalar(icon_image_side() / 2), |
| 347 SkIntToScalar(icon_image_side() / 2) + badge_spacing(), | 364 SkIntToScalar(icon_image_side() / 2) + badge_spacing(), |
| 348 SkIntToScalar(icon_image_side() / 2)); | 365 SkIntToScalar(icon_image_side() / 2)); |
| 349 | 366 |
| 350 if (!is_editing_allowed) { | 367 if (switches::IsMaterialDesignUserMenu() || !is_editing_allowed) { |
| 351 SetEnabled(false); | 368 SetEnabled(false); |
| 352 return; | 369 return; |
| 353 } | 370 } |
| 354 | 371 |
| 355 set_notify_enter_exit_on_child(true); | 372 set_notify_enter_exit_on_child(true); |
| 356 | 373 |
| 357 // Photo overlay that appears when hovering over the button. | 374 // Photo overlay that appears when hovering over the button. |
| 358 photo_overlay_ = new views::ImageView(); | 375 photo_overlay_ = new views::ImageView(); |
| 359 | 376 |
| 360 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); | 377 const SkColor kBackgroundColor = SkColorSetARGB(65, 255, 255, 255); |
| 361 photo_overlay_->set_background( | 378 photo_overlay_->set_background( |
| 362 views::Background::CreateSolidBackground(kBackgroundColor)); | 379 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 363 photo_overlay_->SetImage( | 380 photo_overlay_->SetImage(gfx::CreateVectorIcon( |
| 364 gfx::CreateVectorIcon(gfx::VectorIconId::PHOTO_CAMERA, | 381 gfx::VectorIconId::PHOTO_CAMERA, 48u, SkColorSetRGB(0x33, 0x33, 0x33))); |
| 365 switches::IsMaterialDesignUserMenu() ? 22u : 48u, | |
| 366 SkColorSetRGB(0x33, 0x33, 0x33))); | |
| 367 | 382 |
| 368 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side())); | 383 photo_overlay_->SetSize(gfx::Size(icon_image_side(), icon_image_side())); |
| 369 photo_overlay_->SetY(badge_spacing()); | 384 photo_overlay_->SetY(badge_spacing()); |
| 370 photo_overlay_->SetVisible(false); | 385 photo_overlay_->SetVisible(false); |
| 371 AddChildView(photo_overlay_); | 386 AddChildView(photo_overlay_); |
| 372 } | 387 } |
| 373 | 388 |
| 374 void OnPaint(gfx::Canvas* canvas) override { | 389 void OnPaint(gfx::Canvas* canvas) override { |
| 375 canvas->Save(); | 390 canvas->Save(); |
| 376 // Display the profile picture as a circle. | 391 // Display the profile picture as a circle. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 return switches::IsMaterialDesignUserMenu() ? kMdImageSide | 456 return switches::IsMaterialDesignUserMenu() ? kMdImageSide |
| 442 : kLargeImageSide; | 457 : kLargeImageSide; |
| 443 } | 458 } |
| 444 | 459 |
| 445 static int badge_spacing() { | 460 static int badge_spacing() { |
| 446 // The space between the right/bottom edge of the profile badge and the | 461 // The space between the right/bottom edge of the profile badge and the |
| 447 // right/bottom edge of the profile icon. | 462 // right/bottom edge of the profile icon. |
| 448 return switches::IsMaterialDesignUserMenu() ? 4 : 0; | 463 return switches::IsMaterialDesignUserMenu() ? 4 : 0; |
| 449 } | 464 } |
| 450 | 465 |
| 466 bool CanProcessEventsWithinSubtree() const override { return interactive_; } | |
| 467 | |
| 451 private: | 468 private: |
| 452 // views::CustomButton: | 469 // views::CustomButton: |
| 453 void StateChanged() override { | 470 void StateChanged() override { |
| 454 bool show_overlay = | 471 bool show_overlay = |
| 455 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); | 472 (state() == STATE_PRESSED || state() == STATE_HOVERED || HasFocus()); |
| 456 if (photo_overlay_) | 473 if (photo_overlay_) |
| 457 photo_overlay_->SetVisible(show_overlay); | 474 photo_overlay_->SetVisible(show_overlay); |
| 458 } | 475 } |
| 459 | 476 |
| 460 void OnFocus() override { | 477 void OnFocus() override { |
| 461 views::LabelButton::OnFocus(); | 478 views::LabelButton::OnFocus(); |
| 462 if (photo_overlay_) | 479 if (photo_overlay_) |
| 463 photo_overlay_->SetVisible(true); | 480 photo_overlay_->SetVisible(true); |
| 464 } | 481 } |
| 465 | 482 |
| 466 void OnBlur() override { | 483 void OnBlur() override { |
| 467 views::LabelButton::OnBlur(); | 484 views::LabelButton::OnBlur(); |
| 468 // Don't hide the overlay if it's being shown as a result of a mouseover. | 485 // Don't hide the overlay if it's being shown as a result of a mouseover. |
| 469 if (photo_overlay_ && state() != STATE_HOVERED) | 486 if (photo_overlay_ && state() != STATE_HOVERED) |
| 470 photo_overlay_->SetVisible(false); | 487 photo_overlay_->SetVisible(false); |
| 471 } | 488 } |
| 472 | 489 |
| 490 bool interactive_; | |
| 473 gfx::Path circular_mask_; | 491 gfx::Path circular_mask_; |
| 474 | 492 |
| 475 // Image that is shown when hovering over the image button. Can be NULL if | 493 // Image that is shown when hovering over the image button. Can be NULL if |
| 476 // the photo isn't allowed to be edited (e.g. for guest profiles). | 494 // the photo isn't allowed to be edited (e.g. for guest profiles). |
| 477 views::ImageView* photo_overlay_; | 495 views::ImageView* photo_overlay_; |
| 478 | 496 |
| 479 Profile* profile_; | 497 Profile* profile_; |
| 480 | 498 |
| 481 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); | 499 DISALLOW_COPY_AND_ASSIGN(EditableProfilePhoto); |
| 482 }; | 500 }; |
| 483 | 501 |
| 484 // EditableProfileName ------------------------------------------------- | 502 // EditableProfileName ------------------------------------------------- |
| 485 | 503 |
| 486 // A custom text control that turns into a textfield for editing when clicked. | 504 // A custom text control that turns into a textfield for editing when clicked. |
| 505 // Only used in non-material-design user menu. | |
| 487 class EditableProfileName : public views::View, | 506 class EditableProfileName : public views::View, |
| 488 public views::ButtonListener { | 507 public views::ButtonListener { |
| 489 public: | 508 public: |
| 490 EditableProfileName(views::TextfieldController* controller, | 509 EditableProfileName(views::TextfieldController* controller, |
| 491 const base::string16& text, | 510 const base::string16& text, |
| 492 bool is_editing_allowed) | 511 bool is_editing_allowed) |
| 493 : button_(nullptr), profile_name_textfield_(nullptr) { | 512 : button_(nullptr), profile_name_textfield_(nullptr) { |
| 494 SetLayoutManager( | 513 SetLayoutManager( |
| 495 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 514 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 496 | 515 |
| 497 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 516 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 498 const gfx::FontList& medium_font_list = | 517 const gfx::FontList& medium_font_list = |
| 499 rb->GetFontList(ui::ResourceBundle::MediumFont); | 518 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 500 const gfx::Insets textfield_border_insets = | 519 const gfx::Insets textfield_border_insets = |
| 501 views::Textfield().border()->GetInsets(); | 520 views::Textfield().border()->GetInsets(); |
| 502 | 521 |
| 503 if (!is_editing_allowed) { | 522 if (!is_editing_allowed) { |
| 504 views::Label* name_label = new views::Label(text); | 523 views::Label* name_label = new views::Label(text); |
| 505 name_label->SetBorder( | 524 name_label->SetBorder( |
| 506 views::Border::CreateEmptyBorder(textfield_border_insets)); | 525 views::Border::CreateEmptyBorder(textfield_border_insets)); |
| 507 name_label->SetFontList(medium_font_list); | 526 name_label->SetFontList(medium_font_list); |
| 508 if (switches::IsMaterialDesignUserMenu()) | |
| 509 name_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 510 AddChildView(name_label); | 527 AddChildView(name_label); |
| 511 return; | 528 return; |
| 512 } | 529 } |
| 513 | 530 |
| 514 profile_name_textfield_ = new views::Textfield(); | 531 profile_name_textfield_ = new views::Textfield(); |
| 515 // Textfield that overlaps the button. | 532 // Textfield that overlaps the button. |
| 516 profile_name_textfield_->set_controller(controller); | 533 profile_name_textfield_->set_controller(controller); |
| 517 profile_name_textfield_->SetFontList(medium_font_list); | 534 profile_name_textfield_->SetFontList(medium_font_list); |
| 518 profile_name_textfield_->SetHorizontalAlignment( | 535 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 519 switches::IsMaterialDesignUserMenu() ? gfx::ALIGN_LEFT | |
| 520 : gfx::ALIGN_CENTER); | |
| 521 profile_name_textfield_->SetVisible(false); | 536 profile_name_textfield_->SetVisible(false); |
| 522 AddChildView(profile_name_textfield_); | 537 AddChildView(profile_name_textfield_); |
| 523 | 538 |
| 524 button_ = new RightAlignedIconLabelButton(this, text); | 539 button_ = new RightAlignedIconLabelButton(this, text); |
| 525 button_->SetFontList(medium_font_list); | 540 button_->SetFontList(medium_font_list); |
| 526 // Show an "edit" pencil icon when hovering over. In the default state, | 541 // Show an "edit" pencil icon when hovering over. In the default state, |
| 527 // we need to create an empty placeholder of the correct size, so that | 542 // we need to create an empty placeholder of the correct size, so that |
| 528 // the text doesn't jump around when the hovered icon appears. | 543 // the text doesn't jump around when the hovered icon appears. |
| 529 // TODO(estade): revisit colors and press effect. | 544 // TODO(estade): revisit colors and press effect. |
| 530 const int kIconSize = 16; | 545 const int kIconSize = 16; |
| 531 button_->SetImage(views::LabelButton::STATE_NORMAL, | 546 button_->SetImage(views::LabelButton::STATE_NORMAL, |
| 532 CreateSquarePlaceholderImage(kIconSize)); | 547 CreateSquarePlaceholderImage(kIconSize)); |
| 533 button_->SetImage(views::LabelButton::STATE_HOVERED, | 548 button_->SetImage(views::LabelButton::STATE_HOVERED, |
| 534 gfx::CreateVectorIcon( | 549 gfx::CreateVectorIcon( |
| 535 gfx::VectorIconId::MODE_EDIT, kIconSize, | 550 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 536 SkColorSetRGB(0x33, 0x33, 0x33))); | 551 SkColorSetRGB(0x33, 0x33, 0x33))); |
| 537 button_->SetImage(views::LabelButton::STATE_PRESSED, | 552 button_->SetImage(views::LabelButton::STATE_PRESSED, |
| 538 gfx::CreateVectorIcon( | 553 gfx::CreateVectorIcon( |
| 539 gfx::VectorIconId::MODE_EDIT, kIconSize, | 554 gfx::VectorIconId::MODE_EDIT, kIconSize, |
| 540 SkColorSetRGB(0x20, 0x20, 0x20))); | 555 SkColorSetRGB(0x20, 0x20, 0x20))); |
| 541 // We need to add a left padding as well as a small top/bottom padding | 556 // We need to add a left padding as well as a small top/bottom padding |
| 542 // to the text to account for the textfield's border. | 557 // to the text to account for the textfield's border. |
| 543 if (switches::IsMaterialDesignUserMenu()) { | 558 const int kIconTextLabelButtonSpacing = 5; |
| 544 button_->SetBorder(views::Border::CreateEmptyBorder( | 559 button_->SetBorder(views::Border::CreateEmptyBorder( |
| 545 textfield_border_insets + | 560 textfield_border_insets + |
| 546 gfx::Insets(0, profile_name_textfield_->GetInsets().left(), 0, 0))); | 561 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0))); |
| 547 } else { | |
| 548 const int kIconTextLabelButtonSpacing = 5; | |
| 549 button_->SetBorder(views::Border::CreateEmptyBorder( | |
| 550 textfield_border_insets + | |
| 551 gfx::Insets(0, kIconSize + kIconTextLabelButtonSpacing, 0, 0))); | |
| 552 } | |
| 553 AddChildView(button_); | 562 AddChildView(button_); |
| 554 } | 563 } |
| 555 | 564 |
| 556 views::Textfield* profile_name_textfield() { | 565 views::Textfield* profile_name_textfield() { |
| 557 return profile_name_textfield_; | 566 return profile_name_textfield_; |
| 558 } | 567 } |
| 559 | 568 |
| 560 // Hide the editable textfield to show the profile name button instead. | 569 // Hide the editable textfield to show the profile name button instead. |
| 561 void ShowReadOnlyView() { | 570 void ShowReadOnlyView() { |
| 562 button_->SetVisible(true); | 571 button_->SetVisible(true); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 749 | 758 |
| 750 void ProfileChooserView::ResetView() { | 759 void ProfileChooserView::ResetView() { |
| 751 open_other_profile_indexes_map_.clear(); | 760 open_other_profile_indexes_map_.clear(); |
| 752 delete_account_button_map_.clear(); | 761 delete_account_button_map_.clear(); |
| 753 reauth_account_button_map_.clear(); | 762 reauth_account_button_map_.clear(); |
| 754 manage_accounts_link_ = nullptr; | 763 manage_accounts_link_ = nullptr; |
| 755 signin_current_profile_button_ = nullptr; | 764 signin_current_profile_button_ = nullptr; |
| 756 auth_error_email_button_ = nullptr; | 765 auth_error_email_button_ = nullptr; |
| 757 current_profile_photo_ = nullptr; | 766 current_profile_photo_ = nullptr; |
| 758 current_profile_name_ = nullptr; | 767 current_profile_name_ = nullptr; |
| 768 current_profile_card_ = nullptr; | |
| 759 guest_profile_button_ = nullptr; | 769 guest_profile_button_ = nullptr; |
| 760 users_button_ = nullptr; | 770 users_button_ = nullptr; |
| 761 go_incognito_button_ = nullptr; | 771 go_incognito_button_ = nullptr; |
| 762 lock_button_ = nullptr; | 772 lock_button_ = nullptr; |
| 763 close_all_windows_button_ = nullptr; | 773 close_all_windows_button_ = nullptr; |
| 764 add_account_link_ = nullptr; | 774 add_account_link_ = nullptr; |
| 765 gaia_signin_cancel_button_ = nullptr; | 775 gaia_signin_cancel_button_ = nullptr; |
| 766 remove_account_button_ = nullptr; | 776 remove_account_button_ = nullptr; |
| 767 account_removal_cancel_button_ = nullptr; | 777 account_removal_cancel_button_ = nullptr; |
| 768 add_person_button_ = nullptr; | 778 add_person_button_ = nullptr; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 bool account_management_available = | 1025 bool account_management_available = |
| 1016 SigninManagerFactory::GetForProfile(browser_->profile())-> | 1026 SigninManagerFactory::GetForProfile(browser_->profile())-> |
| 1017 IsAuthenticated() && | 1027 IsAuthenticated() && |
| 1018 switches::IsEnableAccountConsistency(); | 1028 switches::IsEnableAccountConsistency(); |
| 1019 ShowViewFromMode(account_management_available ? | 1029 ShowViewFromMode(account_management_available ? |
| 1020 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : | 1030 profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : |
| 1021 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); | 1031 profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); |
| 1022 } else if (sender == current_profile_photo_) { | 1032 } else if (sender == current_profile_photo_) { |
| 1023 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | 1033 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| 1024 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); | 1034 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); |
| 1035 } else if (sender == current_profile_card_) { | |
| 1036 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | |
| 1037 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); | |
| 1038 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); | |
|
sky
2016/06/30 22:00:40
Are you intentionally calling two PostActionPerfor
Jane
2016/07/01 03:22:54
Yes, I'm intentionally calling them. My understand
sky
2016/07/01 15:50:09
As gaia_service_type_ is reset on line 2159 new th
| |
| 1039 } else if (sender == manage_accounts_button_) { | |
| 1040 // This button can either mean show/hide the account management view, | |
| 1041 // depending on which view it is displayed. | |
| 1042 ShowViewFromMode(view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT | |
| 1043 ? profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER | |
| 1044 : profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); | |
| 1025 } else if (sender == signin_current_profile_button_) { | 1045 } else if (sender == signin_current_profile_button_) { |
| 1026 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); | 1046 ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); |
| 1027 } else if (sender == add_person_button_) { | 1047 } else if (sender == add_person_button_) { |
| 1028 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 1048 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
| 1029 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); | 1049 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); |
| 1030 UserManager::Show(base::FilePath(), | 1050 UserManager::Show(base::FilePath(), |
| 1031 profiles::USER_MANAGER_NO_TUTORIAL, | 1051 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1032 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1052 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 1033 } else if (sender == disconnect_button_) { | 1053 } else if (sender == disconnect_button_) { |
| 1034 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 1054 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1514 } | 1534 } |
| 1515 | 1535 |
| 1516 return view; | 1536 return view; |
| 1517 } | 1537 } |
| 1518 | 1538 |
| 1519 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( | 1539 views::View* ProfileChooserView::CreateMaterialDesignCurrentProfileView( |
| 1520 const AvatarMenu::Item& avatar_item, | 1540 const AvatarMenu::Item& avatar_item, |
| 1521 bool is_guest) { | 1541 bool is_guest) { |
| 1522 views::View* view = new views::View(); | 1542 views::View* view = new views::View(); |
| 1523 view->SetLayoutManager( | 1543 view->SetLayoutManager( |
| 1524 new views::BoxLayout(views::BoxLayout::kVertical, kMaterialMenuEdgeMargin, | 1544 new views::BoxLayout(views::BoxLayout::kVertical, 0, |
| 1525 views::kRelatedControlVerticalSpacing, | 1545 views::kRelatedControlVerticalSpacing, 0)); |
| 1526 views::kRelatedControlVerticalSpacing)); | |
| 1527 | 1546 |
| 1528 // Profile container for the profile photo and avatar/user name. | 1547 // Container for the profile photo and avatar/user name. |
| 1529 views::View* profile_container = new views::View(); | 1548 current_profile_card_ = |
| 1549 new BackgroundColorHoverButton(this, base::string16()); | |
| 1530 | 1550 |
| 1531 // Profile picture, left-aligned. | 1551 // Profile picture, left-aligned. |
| 1532 current_profile_photo_ = new EditableProfilePhoto( | 1552 EditableProfilePhoto* current_profile_photo = new EditableProfilePhoto( |
| 1533 this, avatar_item.icon, !is_guest, browser_->profile()); | 1553 this, avatar_item.icon, !is_guest, browser_->profile()); |
| 1534 | 1554 |
| 1535 // Profile name, left-aligned to the right of profile icon. | 1555 // Profile name, left-aligned to the right of profile icon. |
| 1536 bool editing_allowed = | 1556 views::Label* current_profile_name = new views::Label( |
| 1537 !is_guest && !browser_->profile()->IsLegacySupervised(); | 1557 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())); |
| 1538 current_profile_name_ = new EditableProfileName( | 1558 current_profile_name->SetFontList( |
| 1539 this, profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()), | 1559 (&ui::ResourceBundle::GetSharedInstance()) |
|
sky
2016/06/30 22:00:40
Remove the (&...)-> and replace with ., eg ui::Res
Jane
2016/07/01 03:22:54
Done.
| |
| 1540 editing_allowed); | 1560 ->GetFontListWithDelta(1, gfx::Font::FontStyle::NORMAL, |
| 1541 views::View* profile_name_container = new views::View(); | 1561 gfx::Font::Weight::MEDIUM)); |
| 1562 current_profile_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 1563 NonInteractiveContainer* profile_name_container = | |
| 1564 new NonInteractiveContainer(); | |
| 1542 int name_container_v_spacing = views::kRelatedControlSmallVerticalSpacing; | 1565 int name_container_v_spacing = views::kRelatedControlSmallVerticalSpacing; |
| 1543 if (!avatar_item.signed_in) | 1566 if (!avatar_item.signed_in || switches::IsEnableAccountConsistency()) |
| 1544 name_container_v_spacing += views::kRelatedControlVerticalSpacing; | 1567 name_container_v_spacing += views::kRelatedControlVerticalSpacing; |
| 1545 profile_name_container->SetLayoutManager(new views::BoxLayout( | 1568 profile_name_container->SetLayoutManager(new views::BoxLayout( |
| 1546 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0)); | 1569 views::BoxLayout::kVertical, 0, name_container_v_spacing, 0)); |
| 1547 profile_name_container->AddChildView(current_profile_name_); | 1570 profile_name_container->AddChildView(current_profile_name); |
| 1548 | 1571 |
| 1549 const int between_child_spacing = | 1572 const int between_child_spacing = |
| 1550 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); | 1573 kMaterialMenuEdgeMargin - EditableProfilePhoto::badge_spacing(); |
| 1551 profile_container->SetLayoutManager(new views::BoxLayout( | 1574 current_profile_card_->SetLayoutManager(new views::BoxLayout( |
| 1552 views::BoxLayout::kHorizontal, 0, | 1575 views::BoxLayout::kHorizontal, 0, |
| 1553 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); | 1576 views::kRelatedControlSmallVerticalSpacing, between_child_spacing)); |
| 1554 profile_container->AddChildView(current_profile_photo_); | 1577 current_profile_card_->AddChildView(current_profile_photo); |
| 1555 profile_container->AddChildView(profile_name_container); | 1578 current_profile_card_->AddChildView(profile_name_container); |
| 1556 view->AddChildView(profile_container); | 1579 current_profile_card_->SetMinSize( |
| 1580 gfx::Size(0, current_profile_photo->GetPreferredSize().height() + | |
|
sky
2016/06/30 22:00:41
Similar comment about width sizing.
Jane
2016/07/01 03:22:54
Done.
| |
| 1581 2 * views::kRelatedControlSmallVerticalSpacing)); | |
| 1582 view->AddChildView(current_profile_card_); | |
| 1557 | 1583 |
| 1558 if (is_guest) | 1584 if (is_guest) { |
| 1585 current_profile_card_->SetEnabled(false); | |
| 1559 return view; | 1586 return view; |
| 1587 } | |
| 1560 | 1588 |
| 1561 // The available links depend on the type of profile that is active. | 1589 // The available links depend on the type of profile that is active. |
| 1562 if (avatar_item.signed_in) { | 1590 if (avatar_item.signed_in) { |
| 1563 if (switches::IsEnableAccountConsistency()) { | 1591 if (switches::IsEnableAccountConsistency()) { |
| 1564 base::string16 link_title = l10n_util::GetStringUTF16( | 1592 base::string16 button_text = l10n_util::GetStringUTF16( |
| 1565 IsProfileChooser(view_mode_) | 1593 IsProfileChooser(view_mode_) |
| 1566 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON | 1594 ? IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON |
| 1567 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 1595 : IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 1568 manage_accounts_link_ = CreateLink(link_title, this); | 1596 manage_accounts_button_ = |
| 1569 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1597 new BackgroundColorHoverButton(this, button_text); |
| 1570 profile_name_container->AddChildView(manage_accounts_link_); | 1598 manage_accounts_button_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1599 manage_accounts_button_->SetMinSize(gfx::Size(0, kButtonHeight)); | |
|
sky
2016/06/30 22:00:41
And here.
Jane
2016/07/01 03:22:54
Done.
| |
| 1600 view->AddChildView(manage_accounts_button_); | |
| 1571 } else { | 1601 } else { |
| 1572 views::Label* email_label = new views::Label(avatar_item.username); | 1602 views::Label* email_label = new views::Label(avatar_item.username); |
| 1573 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); | 1603 email_label->SetElideBehavior(gfx::ELIDE_EMAIL); |
| 1574 email_label->SetEnabled(false); | 1604 email_label->SetEnabled(false); |
| 1575 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1605 email_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1576 profile_name_container->AddChildView(email_label); | 1606 profile_name_container->AddChildView(email_label); |
| 1577 } | 1607 } |
| 1578 return view; | 1608 return view; |
| 1579 } | 1609 } |
| 1580 | 1610 |
| 1581 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( | 1611 SigninManagerBase* signin_manager = SigninManagerFactory::GetForProfile( |
| 1582 browser_->profile()->GetOriginalProfile()); | 1612 browser_->profile()->GetOriginalProfile()); |
| 1583 if (signin_manager->IsSigninAllowed()) { | 1613 if (signin_manager->IsSigninAllowed()) { |
| 1614 views::View* extra_links_view = new views::View(); | |
| 1615 views::BoxLayout* extra_links_layout = new views::BoxLayout( | |
| 1616 views::BoxLayout::kVertical, kMaterialMenuEdgeMargin, | |
| 1617 views::kRelatedControlVerticalSpacing, kMaterialMenuEdgeMargin); | |
| 1618 extra_links_layout->set_cross_axis_alignment( | |
| 1619 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 1620 extra_links_view->SetLayoutManager(extra_links_layout); | |
| 1584 views::Label* promo = | 1621 views::Label* promo = |
| 1585 new views::Label(l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); | 1622 new views::Label(l10n_util::GetStringUTF16(IDS_PROFILES_SIGNIN_PROMO)); |
| 1586 promo->SetMultiLine(true); | 1623 promo->SetMultiLine(true); |
| 1587 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 1624 promo->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 1588 view->AddChildView(promo); | 1625 extra_links_view->AddChildView(promo); |
| 1589 | 1626 |
| 1590 signin_current_profile_button_ = | 1627 signin_current_profile_button_ = |
| 1591 views::MdTextButton::CreateSecondaryUiBlueButton( | 1628 views::MdTextButton::CreateSecondaryUiBlueButton( |
| 1592 this, l10n_util::GetStringFUTF16( | 1629 this, l10n_util::GetStringFUTF16( |
| 1593 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 1630 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 1594 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 1631 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 1595 view->AddChildView(signin_current_profile_button_); | 1632 extra_links_view->AddChildView(signin_current_profile_button_); |
| 1596 content::RecordAction( | 1633 content::RecordAction( |
| 1597 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 1634 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| 1598 view->SetBorder(views::Border::CreateEmptyBorder( | 1635 extra_links_view->SetBorder(views::Border::CreateEmptyBorder( |
| 1599 0, 0, views::kRelatedControlVerticalSpacing, 0)); | 1636 0, 0, views::kRelatedControlSmallVerticalSpacing, 0)); |
| 1637 view->AddChildView(extra_links_view); | |
| 1600 } | 1638 } |
| 1601 | 1639 |
| 1602 return view; | 1640 return view; |
| 1603 } | 1641 } |
| 1604 | 1642 |
| 1605 views::View* ProfileChooserView::CreateGuestProfileView() { | 1643 views::View* ProfileChooserView::CreateGuestProfileView() { |
| 1606 gfx::Image guest_icon = | 1644 gfx::Image guest_icon = |
| 1607 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 1645 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 1608 profiles::GetPlaceholderAvatarIconResourceID()); | 1646 profiles::GetPlaceholderAvatarIconResourceID()); |
| 1609 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); | 1647 AvatarMenu::Item guest_avatar_item(0, base::FilePath(), guest_icon); |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2113 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2151 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2114 IncognitoModePrefs::DISABLED; | 2152 IncognitoModePrefs::DISABLED; |
| 2115 return incognito_available && !browser_->profile()->IsGuestSession(); | 2153 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2116 } | 2154 } |
| 2117 | 2155 |
| 2118 void ProfileChooserView::PostActionPerformed( | 2156 void ProfileChooserView::PostActionPerformed( |
| 2119 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2157 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2120 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2158 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2121 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2159 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2122 } | 2160 } |
| OLD | NEW |