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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 // A custom image view that ignores mouse events so that the parent can receive | 130 // A custom image view that ignores mouse events so that the parent can receive |
131 // them them instead. | 131 // them them instead. |
132 class ProfileImageView : public views::ImageView { | 132 class ProfileImageView : public views::ImageView { |
133 public: | 133 public: |
134 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; | 134 virtual bool HitTest(const gfx::Point& l) const OVERRIDE; |
135 }; | 135 }; |
136 | 136 |
137 bool ProfileImageView::HitTest(const gfx::Point& l) const { | 137 bool ProfileImageView::HitTest(const gfx::Point& l) const { |
138 return false; | 138 return false; |
139 } | 139 } |
140 | 140 |
Peter Kasting
2011/12/14 22:41:56
Nit: Don't remove this.
(Besides, you didn't remo
| |
141 | |
142 // ProfileItemView ------------------------------------------------------------ | 141 // ProfileItemView ------------------------------------------------------------ |
143 | 142 |
144 // Control that shows information about a single profile. | 143 // Control that shows information about a single profile. |
145 class ProfileItemView : public views::CustomButton, | 144 class ProfileItemView : public views::CustomButton, |
146 public HighlightDelegate { | 145 public HighlightDelegate { |
147 public: | 146 public: |
148 ProfileItemView(const AvatarMenuModel::Item& item, | 147 ProfileItemView(const AvatarMenuModel::Item& item, |
149 views::ButtonListener* switch_profile_listener, | 148 views::ButtonListener* switch_profile_listener, |
150 views::LinkListener* edit_profile_listener); | 149 views::LinkListener* edit_profile_listener); |
151 | 150 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 // Moved the focus up or down by 1. | 424 // Moved the focus up or down by 1. |
426 if (accelerator.key_code() == ui::VKEY_DOWN) | 425 if (accelerator.key_code() == ui::VKEY_DOWN) |
427 focus_index = (focus_index + 1) % item_views_.size(); | 426 focus_index = (focus_index + 1) % item_views_.size(); |
428 else | 427 else |
429 focus_index = ((focus_index > 0) ? focus_index : item_views_.size()) - 1; | 428 focus_index = ((focus_index > 0) ? focus_index : item_views_.size()) - 1; |
430 item_views_[focus_index]->RequestFocus(); | 429 item_views_[focus_index]->RequestFocus(); |
431 | 430 |
432 return true; | 431 return true; |
433 } | 432 } |
434 | 433 |
435 void AvatarMenuBubbleView::ViewHierarchyChanged(bool is_add, | |
436 views::View* parent, | |
437 views::View* child) { | |
438 // Build the menu for the first time. | |
439 if (!add_profile_link_ && is_add && child == this) | |
440 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | |
441 | |
442 views::BubbleDelegateView::ViewHierarchyChanged(is_add, parent, child); | |
443 } | |
444 | |
445 void AvatarMenuBubbleView::ButtonPressed(views::Button* sender, | 434 void AvatarMenuBubbleView::ButtonPressed(views::Button* sender, |
446 const views::Event& event) { | 435 const views::Event& event) { |
447 for (size_t i = 0; i < item_views_.size(); ++i) { | 436 for (size_t i = 0; i < item_views_.size(); ++i) { |
448 ProfileItemView* item_view = static_cast<ProfileItemView*>(item_views_[i]); | 437 ProfileItemView* item_view = static_cast<ProfileItemView*>(item_views_[i]); |
449 if (sender == item_view) { | 438 if (sender == item_view) { |
450 // Clicking on the active profile shouldn't do anything. | 439 // Clicking on the active profile shouldn't do anything. |
451 if (!item_view->item().active) | 440 if (!item_view->item().active) |
452 avatar_menu_model_->SwitchToProfile(i); | 441 avatar_menu_model_->SwitchToProfile(i); |
453 break; | 442 break; |
454 } | 443 } |
(...skipping 13 matching lines...) Expand all Loading... | |
468 return; | 457 return; |
469 } | 458 } |
470 } | 459 } |
471 } | 460 } |
472 | 461 |
473 gfx::Rect AvatarMenuBubbleView::GetAnchorRect() { | 462 gfx::Rect AvatarMenuBubbleView::GetAnchorRect() { |
474 return anchor_rect_; | 463 return anchor_rect_; |
475 } | 464 } |
476 | 465 |
477 void AvatarMenuBubbleView::Init() { | 466 void AvatarMenuBubbleView::Init() { |
467 // Build the menu for the first time. | |
468 OnAvatarMenuModelChanged(avatar_menu_model_.get()); | |
478 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, 0)); | 469 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, 0)); |
479 AddAccelerator(ui::Accelerator(ui::VKEY_UP, 0)); | 470 AddAccelerator(ui::Accelerator(ui::VKEY_UP, 0)); |
480 } | 471 } |
481 | 472 |
482 void AvatarMenuBubbleView::OnAvatarMenuModelChanged( | 473 void AvatarMenuBubbleView::OnAvatarMenuModelChanged( |
483 AvatarMenuModel* avatar_menu_model) { | 474 AvatarMenuModel* avatar_menu_model) { |
484 // Unset all our child view references and call RemoveAllChildViews() which | 475 // Unset all our child view references and call RemoveAllChildViews() which |
485 // will actually delete them. | 476 // will actually delete them. |
486 add_profile_link_ = NULL; | 477 add_profile_link_ = NULL; |
487 item_views_.clear(); | 478 item_views_.clear(); |
(...skipping 15 matching lines...) Expand all Loading... | |
503 add_profile_link_ = new views::Link( | 494 add_profile_link_ = new views::Link( |
504 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); | 495 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); |
505 add_profile_link_->set_listener(this); | 496 add_profile_link_->set_listener(this); |
506 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 497 add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
507 add_profile_link_->SetBackgroundColor(color()); | 498 add_profile_link_->SetBackgroundColor(color()); |
508 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); | 499 add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); |
509 AddChildView(add_profile_link_); | 500 AddChildView(add_profile_link_); |
510 | 501 |
511 // If the bubble has already been shown then resize and reposition the bubble. | 502 // If the bubble has already been shown then resize and reposition the bubble. |
512 Layout(); | 503 Layout(); |
513 SizeToContents(); | 504 if (GetBubbleFrameView()) |
505 SizeToContents(); | |
514 } | 506 } |
OLD | NEW |