summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 05:43:46 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-22 05:43:46 +0000
commitb217450b5c2863b81b7b7e14d4da2f39fa5b3fb0 (patch)
treeff1753dc6f5a7ddd9be1afded2aedd40b76a25bb
parent0157282494c1096cef55f04d7b8936c7db022679 (diff)
downloadchromium_src-b217450b5c2863b81b7b7e14d4da2f39fa5b3fb0.zip
chromium_src-b217450b5c2863b81b7b7e14d4da2f39fa5b3fb0.tar.gz
chromium_src-b217450b5c2863b81b7b7e14d4da2f39fa5b3fb0.tar.bz2
Rebase AvatarMenuBubbleView on the new views bubble.
Added an std::max to prevent negative width calculation. TODO(sail/msw): BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE. I filed crbug.com/105014 for the placement regression on NTP. BUG=98323 TEST=The avatar menu bubble works as before. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=111018 Review URL: http://codereview.chromium.org/8500004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111102 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/avatar_menu_bubble_view.cc41
-rw-r--r--chrome/browser/ui/views/avatar_menu_bubble_view.h17
-rw-r--r--chrome/browser/ui/views/avatar_menu_button.cc24
-rw-r--r--chrome/browser/ui/views/avatar_menu_button.h8
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc10
5 files changed, 38 insertions, 62 deletions
diff --git a/chrome/browser/ui/views/avatar_menu_bubble_view.cc b/chrome/browser/ui/views/avatar_menu_bubble_view.cc
index 4ce0104..a4e34ea 100644
--- a/chrome/browser/ui/views/avatar_menu_bubble_view.cc
+++ b/chrome/browser/ui/views/avatar_menu_bubble_view.cc
@@ -29,6 +29,9 @@
namespace {
+// TODO(msw): Get color from theme/window color.
+const SkColor kColor = SK_ColorWHITE;
+
const int kItemHeight = 44;
const int kItemMarginY = 4;
const int kIconWidth = 38;
@@ -234,7 +237,7 @@ void ProfileItemView::Layout() {
image_view_->SetBoundsRect(icon_rect);
int label_x = icon_rect.right() + kIconMarginX;
- int max_label_width = width() - label_x;
+ int max_label_width = std::max(width() - label_x, 0);
gfx::Size name_size = name_label_->GetPreferredSize();
name_size.set_width(std::min(name_size.width(), max_label_width));
gfx::Size state_size = sync_state_label_->GetPreferredSize();
@@ -279,11 +282,6 @@ void ProfileItemView::OnBlur() {
void ProfileItemView::OnHighlightStateChanged() {
set_background(IsHighlighted() ? views::Background::CreateSolidBackground(
SkColorSetRGB(0xe3, 0xed, 0xf6)) : NULL);
- SkColor background_color = background() ?
- background()->get_color() : Bubble::kBackgroundColor;
- name_label_->SetBackgroundColor(background_color);
- sync_state_label_->SetBackgroundColor(background_color);
- edit_link_->SetBackgroundColor(background_color);
bool show_edit = IsHighlighted() && item_.active;
sync_state_label_->SetVisible(!show_edit);
@@ -330,8 +328,14 @@ bool ProfileItemView::IsHighlighted() {
// AvatarMenuBubbleView -------------------------------------------------------
-AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser)
- : add_profile_link_(NULL),
+AvatarMenuBubbleView::AvatarMenuBubbleView(
+ views::View* anchor_view,
+ views::BubbleBorder::ArrowLocation arrow_location,
+ const gfx::Rect& anchor_rect,
+ Browser* browser)
+ : BubbleDelegateView(anchor_view, arrow_location, kColor),
+ add_profile_link_(NULL),
+ anchor_rect_(anchor_rect),
browser_(browser) {
avatar_menu_model_.reset(new AvatarMenuModel(
&g_browser_process->profile_manager()->GetProfileInfoCache(),
@@ -444,23 +448,13 @@ void AvatarMenuBubbleView::LinkClicked(views::Link* source, int event_flags) {
}
}
-void AvatarMenuBubbleView::BubbleShown() {
- GetFocusManager()->RegisterAccelerator(
- ui::Accelerator(ui::VKEY_DOWN, false, false, false), this);
- GetFocusManager()->RegisterAccelerator(
- ui::Accelerator(ui::VKEY_UP, false, false, false), this);
-}
-
-void AvatarMenuBubbleView::BubbleClosing(Bubble* bubble,
- bool closed_by_escape) {
+gfx::Point AvatarMenuBubbleView::GetAnchorPoint() {
+ return gfx::Point(anchor_rect_.CenterPoint().x(), anchor_rect_.bottom());
}
-bool AvatarMenuBubbleView::CloseOnEscape() {
- return true;
-}
-
-bool AvatarMenuBubbleView::FadeInOnShow() {
- return false;
+void AvatarMenuBubbleView::Init() {
+ AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, 0));
+ AddAccelerator(ui::Accelerator(ui::VKEY_UP, 0));
}
void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
@@ -488,7 +482,6 @@ void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK));
add_profile_link_->set_listener(this);
add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- add_profile_link_->SetBackgroundColor(Bubble::kBackgroundColor);
add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6));
AddChildView(add_profile_link_);
diff --git a/chrome/browser/ui/views/avatar_menu_bubble_view.h b/chrome/browser/ui/views/avatar_menu_bubble_view.h
index c606a3a..894b1f3 100644
--- a/chrome/browser/ui/views/avatar_menu_bubble_view.h
+++ b/chrome/browser/ui/views/avatar_menu_bubble_view.h
@@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/profiles/avatar_menu_model_observer.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
+#include "ui/views/bubble/bubble_delegate.h"
#include "views/controls/button/button.h"
#include "views/controls/link_listener.h"
@@ -26,13 +26,15 @@ class Separator;
// This bubble view is displayed when the user clicks on the avatar button.
// It displays a list of profiles and allows users to switch between profiles.
-class AvatarMenuBubbleView : public views::View,
+class AvatarMenuBubbleView : public views::BubbleDelegateView,
public views::ButtonListener,
public views::LinkListener,
- public BubbleDelegate,
public AvatarMenuModelObserver {
public:
- explicit AvatarMenuBubbleView(Browser* browser);
+ AvatarMenuBubbleView(views::View* anchor_view,
+ views::BubbleBorder::ArrowLocation arrow_location,
+ const gfx::Rect& anchor_rect,
+ Browser* browser);
virtual ~AvatarMenuBubbleView();
// views::View implementation.
@@ -48,10 +50,8 @@ class AvatarMenuBubbleView : public views::View,
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
// BubbleDelegate implementation.
- virtual void BubbleShown() OVERRIDE;
- virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
- virtual bool CloseOnEscape() OVERRIDE;
- virtual bool FadeInOnShow() OVERRIDE;
+ virtual gfx::Point GetAnchorPoint() OVERRIDE;
+ virtual void Init() OVERRIDE;
// AvatarMenuModelObserver implementation.
virtual void OnAvatarMenuModelChanged(
@@ -60,6 +60,7 @@ class AvatarMenuBubbleView : public views::View,
private:
views::Link* add_profile_link_;
scoped_ptr<AvatarMenuModel> avatar_menu_model_;
+ gfx::Rect anchor_rect_;
Browser* browser_;
std::vector<views::CustomButton*> item_views_;
views::Separator* separator_;
diff --git a/chrome/browser/ui/views/avatar_menu_button.cc b/chrome/browser/ui/views/avatar_menu_button.cc
index ba7738b..cbbae44d 100644
--- a/chrome/browser/ui/views/avatar_menu_button.cc
+++ b/chrome/browser/ui/views/avatar_menu_button.cc
@@ -78,7 +78,6 @@ void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) {
AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
: MenuButton(NULL, string16(), this, false),
browser_(browser),
- bubble_(NULL),
has_menu_(has_menu),
set_taskbar_decoration_(false) {
// In RTL mode, the avatar icon should be looking the opposite direction.
@@ -86,8 +85,6 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
}
AvatarMenuButton::~AvatarMenuButton() {
- if (bubble_)
- OnBubbleClosing();
// During destruction of the browser frame, we might not have a window
// so the taskbar button will be removed by windows anyway.
if (browser_->IsAttemptingToCloseBrowser())
@@ -147,26 +144,17 @@ void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
}
void AvatarMenuButton::ShowAvatarBubble() {
- if (!has_menu_ || bubble_)
+ if (!has_menu_)
return;
- BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
gfx::Point origin;
views::View::ConvertPointToScreen(this, &origin);
- gfx::Rect bounds(0, 0, width(), height());
- bounds.set_origin(origin);
+ gfx::Rect bounds(origin, size());
- AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_);
- // Bubble::Show() takes ownership of the view.
- bubble_ = Bubble::Show(browser_view->GetWidget(), bounds,
- views::BubbleBorder::TOP_LEFT,
- views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bubble_view, bubble_view);
- bubble_->AddObserver(this);
+ AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this,
+ views::BubbleBorder::TOP_LEFT, bounds, browser_);
+ views::BubbleDelegateView::CreateBubble(bubble);
+ bubble->Show();
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
}
-
-void AvatarMenuButton::OnBubbleClosing() {
- bubble_->RemoveObserver(this);
- bubble_ = NULL;
-}
diff --git a/chrome/browser/ui/views/avatar_menu_button.h b/chrome/browser/ui/views/avatar_menu_button.h
index 71609b6..4072517 100644
--- a/chrome/browser/ui/views/avatar_menu_button.h
+++ b/chrome/browser/ui/views/avatar_menu_button.h
@@ -9,7 +9,6 @@
#include <string>
#include "base/compiler_specific.h"
-#include "chrome/browser/ui/views/bubble/bubble.h"
#include "ui/base/models/simple_menu_model.h"
#include "views/controls/button/menu_button.h"
#include "views/controls/menu/view_menu_delegate.h"
@@ -25,8 +24,7 @@ class Browser;
// The button can optionally have a menu attached to it.
class AvatarMenuButton : public views::MenuButton,
- public views::ViewMenuDelegate,
- public Bubble::Observer {
+ public views::ViewMenuDelegate {
public:
// Creates a new button. If |has_menu| is true then clicking on the button
// will cause the profile menu to be displayed.
@@ -47,11 +45,7 @@ class AvatarMenuButton : public views::MenuButton,
// views::ViewMenuDelegate
virtual void RunMenu(views::View* source, const gfx::Point& pt) OVERRIDE;
- // Bubble::Observer implementation.
- virtual void OnBubbleClosing();
-
Browser* browser_;
- Bubble* bubble_;
bool has_menu_;
bool set_taskbar_decoration_;
scoped_ptr<ui::MenuModel> menu_model_;
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index d82d478..004d6db 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -2627,11 +2627,11 @@ void BrowserView::ShowAvatarBubble(TabContents* tab_contents,
views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin);
gfx::Rect bounds(origin, rect.size());
- AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_.get());
- // Bubble::Show() takes ownership of the view.
- Bubble::Show(this->GetWidget(), bounds, views::BubbleBorder::TOP_RIGHT,
- views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE,
- bubble_view, bubble_view);
+ // TODO(msw): Set and support views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE.
+ AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this,
+ views::BubbleBorder::TOP_RIGHT, bounds, browser_.get());
+ views::BubbleDelegateView::CreateBubble(bubble);
+ bubble->Show();
}
void BrowserView::ShowAvatarBubbleFromAvatarButton() {