OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/avatar_menu_bubble_view.h" | 5 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 views::BubbleBorder::ArrowLocation arrow_location, | 344 views::BubbleBorder::ArrowLocation arrow_location, |
345 const gfx::Rect& anchor_rect, | 345 const gfx::Rect& anchor_rect, |
346 Browser* browser) | 346 Browser* browser) |
347 : BubbleDelegateView(anchor_view, arrow_location), | 347 : BubbleDelegateView(anchor_view, arrow_location), |
348 add_profile_link_(NULL), | 348 add_profile_link_(NULL), |
349 anchor_rect_(anchor_rect), | 349 anchor_rect_(anchor_rect), |
350 browser_(browser) { | 350 browser_(browser) { |
351 avatar_menu_model_.reset(new AvatarMenuModel( | 351 avatar_menu_model_.reset(new AvatarMenuModel( |
352 &g_browser_process->profile_manager()->GetProfileInfoCache(), | 352 &g_browser_process->profile_manager()->GetProfileInfoCache(), |
353 this, browser_)); | 353 this, browser_)); |
354 // Build the menu for the first time. | |
355 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | |
356 } | 354 } |
357 | 355 |
358 AvatarMenuBubbleView::~AvatarMenuBubbleView() { | 356 AvatarMenuBubbleView::~AvatarMenuBubbleView() { |
359 } | 357 } |
360 | 358 |
361 gfx::Size AvatarMenuBubbleView::GetPreferredSize() { | 359 gfx::Size AvatarMenuBubbleView::GetPreferredSize() { |
360 if (!add_profile_link_) | |
Peter Kasting
2011/12/13 02:25:11
Is this really necessary? Normally it's safe to a
sail
2011/12/13 02:31:40
This is currently necessary. I think it's called b
| |
361 return gfx::Size(); | |
362 | |
362 int max_width = 0; | 363 int max_width = 0; |
363 int total_height = 0; | 364 int total_height = 0; |
364 for (size_t i = 0; i < item_views_.size(); ++i) { | 365 for (size_t i = 0; i < item_views_.size(); ++i) { |
365 gfx::Size size = item_views_[i]->GetPreferredSize(); | 366 gfx::Size size = item_views_[i]->GetPreferredSize(); |
366 max_width = std::max(max_width, size.width()); | 367 max_width = std::max(max_width, size.width()); |
367 total_height += size.height() + kItemMarginY; | 368 total_height += size.height() + kItemMarginY; |
368 } | 369 } |
369 | 370 |
370 total_height += kSeparatorPaddingY * 2 + | 371 total_height += kSeparatorPaddingY * 2 + |
371 separator_->GetPreferredSize().height(); | 372 separator_->GetPreferredSize().height(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 // Moved the focus up or down by 1. | 425 // Moved the focus up or down by 1. |
425 if (accelerator.key_code() == ui::VKEY_DOWN) | 426 if (accelerator.key_code() == ui::VKEY_DOWN) |
426 focus_index = (focus_index + 1) % item_views_.size(); | 427 focus_index = (focus_index + 1) % item_views_.size(); |
427 else | 428 else |
428 focus_index = ((focus_index > 0) ? focus_index : item_views_.size()) - 1; | 429 focus_index = ((focus_index > 0) ? focus_index : item_views_.size()) - 1; |
429 item_views_[focus_index]->RequestFocus(); | 430 item_views_[focus_index]->RequestFocus(); |
430 | 431 |
431 return true; | 432 return true; |
432 } | 433 } |
433 | 434 |
435 void AvatarMenuBubbleView::ViewHierarchyChanged(bool is_add, | |
436 views::View* parent, | |
437 views::View* child) { | |
438 views::BubbleDelegateView::ViewHierarchyChanged(is_add, parent, child); | |
439 | |
440 // Build the menu for the first time. | |
Peter Kasting
2011/12/13 02:25:11
Nit: I think normally we do class-specific stuff b
sail
2011/12/13 02:31:40
Done.
| |
441 if (!add_profile_link_ && is_add && child == this) | |
442 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | |
443 } | |
444 | |
434 void AvatarMenuBubbleView::ButtonPressed(views::Button* sender, | 445 void AvatarMenuBubbleView::ButtonPressed(views::Button* sender, |
435 const views::Event& event) { | 446 const views::Event& event) { |
436 for (size_t i = 0; i < item_views_.size(); ++i) { | 447 for (size_t i = 0; i < item_views_.size(); ++i) { |
437 ProfileItemView* item_view = static_cast<ProfileItemView*>(item_views_[i]); | 448 ProfileItemView* item_view = static_cast<ProfileItemView*>(item_views_[i]); |
438 if (sender == item_view) { | 449 if (sender == item_view) { |
439 // Clicking on the active profile shouldn't do anything. | 450 // Clicking on the active profile shouldn't do anything. |
440 if (!item_view->item().active) | 451 if (!item_view->item().active) |
441 avatar_menu_model_->SwitchToProfile(i); | 452 avatar_menu_model_->SwitchToProfile(i); |
442 break; | 453 break; |
443 } | 454 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 AddChildView(separator_); | 501 AddChildView(separator_); |
491 | 502 |
492 add_profile_link_ = new views::Link( | 503 add_profile_link_ = new views::Link( |
493 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); | 504 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); |
494 add_profile_link_->set_listener(this); | 505 add_profile_link_->set_listener(this); |
495 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 506 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
496 add_profile_link_->SetBackgroundColor(color()); | 507 add_profile_link_->SetBackgroundColor(color()); |
497 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); | 508 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); |
498 AddChildView(add_profile_link_); | 509 AddChildView(add_profile_link_); |
499 | 510 |
500 PreferredSizeChanged(); | 511 // If the bubble has already been shown then resize and reposition the bubble. |
Peter Kasting
2011/12/13 02:25:11
It still seems strange to me that we need this. I
sail
2011/12/13 02:31:40
Adding Scott and msw to the review. If this requir
msw
2011/12/13 03:20:23
Doing a synchronous Layout and then calling SizeTo
sky
2011/12/13 05:18:46
We could make whatever the content view is for the
msw
2011/12/13 18:17:47
AvatarMenuBubbleView is the content view (a Bubble
| |
512 Layout(); | |
513 SizeToContents(); | |
501 } | 514 } |
OLD | NEW |