Commit a4dcec15 authored by msw@chromium.org's avatar msw@chromium.org

Revert 111018 - 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.

Review URL: http://codereview.chromium.org/8500004

TBR=msw@chromium.org
Review URL: http://codereview.chromium.org/8621004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@111024 0039d316-1c4b-4281-b951-d872f2087c98
parent 2f12d421
...@@ -29,9 +29,6 @@ ...@@ -29,9 +29,6 @@
namespace { namespace {
// TODO(msw): Get color from theme/window color.
const SkColor kColor = SK_ColorWHITE;
const int kItemHeight = 44; const int kItemHeight = 44;
const int kItemMarginY = 4; const int kItemMarginY = 4;
const int kIconWidth = 38; const int kIconWidth = 38;
...@@ -237,7 +234,7 @@ void ProfileItemView::Layout() { ...@@ -237,7 +234,7 @@ void ProfileItemView::Layout() {
image_view_->SetBoundsRect(icon_rect); image_view_->SetBoundsRect(icon_rect);
int label_x = icon_rect.right() + kIconMarginX; int label_x = icon_rect.right() + kIconMarginX;
int max_label_width = std::max(width() - label_x, 0); int max_label_width = width() - label_x;
gfx::Size name_size = name_label_->GetPreferredSize(); gfx::Size name_size = name_label_->GetPreferredSize();
name_size.set_width(std::min(name_size.width(), max_label_width)); name_size.set_width(std::min(name_size.width(), max_label_width));
gfx::Size state_size = sync_state_label_->GetPreferredSize(); gfx::Size state_size = sync_state_label_->GetPreferredSize();
...@@ -282,6 +279,11 @@ void ProfileItemView::OnBlur() { ...@@ -282,6 +279,11 @@ void ProfileItemView::OnBlur() {
void ProfileItemView::OnHighlightStateChanged() { void ProfileItemView::OnHighlightStateChanged() {
set_background(IsHighlighted() ? views::Background::CreateSolidBackground( set_background(IsHighlighted() ? views::Background::CreateSolidBackground(
SkColorSetRGB(0xe3, 0xed, 0xf6)) : NULL); 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; bool show_edit = IsHighlighted() && item_.active;
sync_state_label_->SetVisible(!show_edit); sync_state_label_->SetVisible(!show_edit);
...@@ -328,14 +330,8 @@ bool ProfileItemView::IsHighlighted() { ...@@ -328,14 +330,8 @@ bool ProfileItemView::IsHighlighted() {
// AvatarMenuBubbleView ------------------------------------------------------- // AvatarMenuBubbleView -------------------------------------------------------
AvatarMenuBubbleView::AvatarMenuBubbleView( AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser)
views::View* anchor_view, : add_profile_link_(NULL),
views::BubbleBorder::ArrowLocation arrow_location,
const gfx::Rect& anchor_rect,
Browser* browser)
: BubbleDelegateView(anchor_view, arrow_location, kColor),
anchor_rect_(anchor_rect),
add_profile_link_(NULL),
browser_(browser) { browser_(browser) {
avatar_menu_model_.reset(new AvatarMenuModel( avatar_menu_model_.reset(new AvatarMenuModel(
&g_browser_process->profile_manager()->GetProfileInfoCache(), &g_browser_process->profile_manager()->GetProfileInfoCache(),
...@@ -448,13 +444,23 @@ void AvatarMenuBubbleView::LinkClicked(views::Link* source, int event_flags) { ...@@ -448,13 +444,23 @@ void AvatarMenuBubbleView::LinkClicked(views::Link* source, int event_flags) {
} }
} }
gfx::Point AvatarMenuBubbleView::GetAnchorPoint() { void AvatarMenuBubbleView::BubbleShown() {
return gfx::Point(anchor_rect_.CenterPoint().x(), anchor_rect_.bottom()); 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) {
} }
void AvatarMenuBubbleView::Init() { bool AvatarMenuBubbleView::CloseOnEscape() {
AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, 0)); return true;
AddAccelerator(ui::Accelerator(ui::VKEY_UP, 0)); }
bool AvatarMenuBubbleView::FadeInOnShow() {
return false;
} }
void AvatarMenuBubbleView::OnAvatarMenuModelChanged( void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
...@@ -482,6 +488,7 @@ void AvatarMenuBubbleView::OnAvatarMenuModelChanged( ...@@ -482,6 +488,7 @@ void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK));
add_profile_link_->set_listener(this); add_profile_link_->set_listener(this);
add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); add_profile_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
add_profile_link_->SetBackgroundColor(Bubble::kBackgroundColor);
add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6)); add_profile_link_->SetEnabledColor(SkColorSetRGB(0xe3, 0xed, 0xf6));
AddChildView(add_profile_link_); AddChildView(add_profile_link_);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/browser/profiles/avatar_menu_model_observer.h" #include "chrome/browser/profiles/avatar_menu_model_observer.h"
#include "ui/views/bubble/bubble_delegate.h" #include "chrome/browser/ui/views/bubble/bubble.h"
#include "views/controls/button/button.h" #include "views/controls/button/button.h"
#include "views/controls/link_listener.h" #include "views/controls/link_listener.h"
...@@ -26,15 +26,13 @@ class Separator; ...@@ -26,15 +26,13 @@ class Separator;
// This bubble view is displayed when the user clicks on the avatar button. // 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. // It displays a list of profiles and allows users to switch between profiles.
class AvatarMenuBubbleView : public views::BubbleDelegateView, class AvatarMenuBubbleView : public views::View,
public views::ButtonListener, public views::ButtonListener,
public views::LinkListener, public views::LinkListener,
public BubbleDelegate,
public AvatarMenuModelObserver { public AvatarMenuModelObserver {
public: public:
AvatarMenuBubbleView(views::View* anchor_view, explicit AvatarMenuBubbleView(Browser* browser);
views::BubbleBorder::ArrowLocation arrow_location,
const gfx::Rect& anchor_rect,
Browser* browser);
virtual ~AvatarMenuBubbleView(); virtual ~AvatarMenuBubbleView();
// views::View implementation. // views::View implementation.
...@@ -50,8 +48,10 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView, ...@@ -50,8 +48,10 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView,
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
// BubbleDelegate implementation. // BubbleDelegate implementation.
virtual gfx::Point GetAnchorPoint() OVERRIDE; virtual void BubbleShown() OVERRIDE;
virtual void Init() OVERRIDE; virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
virtual bool CloseOnEscape() OVERRIDE;
virtual bool FadeInOnShow() OVERRIDE;
// AvatarMenuModelObserver implementation. // AvatarMenuModelObserver implementation.
virtual void OnAvatarMenuModelChanged( virtual void OnAvatarMenuModelChanged(
...@@ -60,7 +60,6 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView, ...@@ -60,7 +60,6 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView,
private: private:
views::Link* add_profile_link_; views::Link* add_profile_link_;
scoped_ptr<AvatarMenuModel> avatar_menu_model_; scoped_ptr<AvatarMenuModel> avatar_menu_model_;
gfx::Rect anchor_rect_;
Browser* browser_; Browser* browser_;
std::vector<views::CustomButton*> item_views_; std::vector<views::CustomButton*> item_views_;
views::Separator* separator_; views::Separator* separator_;
......
...@@ -78,6 +78,7 @@ void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) { ...@@ -78,6 +78,7 @@ void DrawTaskBarDecoration(const Browser* browser, const SkBitmap* bitmap) {
AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
: MenuButton(NULL, string16(), this, false), : MenuButton(NULL, string16(), this, false),
browser_(browser), browser_(browser),
bubble_(NULL),
has_menu_(has_menu), has_menu_(has_menu),
set_taskbar_decoration_(false) { set_taskbar_decoration_(false) {
// In RTL mode, the avatar icon should be looking the opposite direction. // In RTL mode, the avatar icon should be looking the opposite direction.
...@@ -85,6 +86,8 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu) ...@@ -85,6 +86,8 @@ AvatarMenuButton::AvatarMenuButton(Browser* browser, bool has_menu)
} }
AvatarMenuButton::~AvatarMenuButton() { AvatarMenuButton::~AvatarMenuButton() {
if (bubble_)
OnBubbleClosing();
// During destruction of the browser frame, we might not have a window // During destruction of the browser frame, we might not have a window
// so the taskbar button will be removed by windows anyway. // so the taskbar button will be removed by windows anyway.
if (browser_->IsAttemptingToCloseBrowser()) if (browser_->IsAttemptingToCloseBrowser())
...@@ -144,18 +147,26 @@ void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { ...@@ -144,18 +147,26 @@ void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
} }
void AvatarMenuButton::ShowAvatarBubble() { void AvatarMenuButton::ShowAvatarBubble() {
if (!has_menu_) if (!has_menu_ || bubble_)
return; return;
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
gfx::Point origin; gfx::Point origin;
views::View::ConvertPointToScreen(this, &origin); views::View::ConvertPointToScreen(this, &origin);
gfx::Rect bounds(origin, size()); gfx::Rect bounds(0, 0, width(), height());
bounds.set_origin(origin);
AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_);
views::BubbleBorder::TOP_LEFT, bounds, browser_); // Bubble::Show() takes ownership of the view.
views::BubbleDelegateView::CreateBubble(bubble); bubble_ = Bubble::Show(browser_view->GetWidget(), bounds,
bubble->Show(); views::BubbleBorder::TOP_LEFT,
views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, bubble_view, bubble_view);
bubble_->AddObserver(this);
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
} }
void AvatarMenuButton::OnBubbleClosing() {
bubble_->RemoveObserver(this);
bubble_ = NULL;
}
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "chrome/browser/ui/views/bubble/bubble.h"
#include "ui/base/models/simple_menu_model.h" #include "ui/base/models/simple_menu_model.h"
#include "views/controls/button/menu_button.h" #include "views/controls/button/menu_button.h"
#include "views/controls/menu/view_menu_delegate.h" #include "views/controls/menu/view_menu_delegate.h"
...@@ -24,7 +25,8 @@ class Browser; ...@@ -24,7 +25,8 @@ class Browser;
// The button can optionally have a menu attached to it. // The button can optionally have a menu attached to it.
class AvatarMenuButton : public views::MenuButton, class AvatarMenuButton : public views::MenuButton,
public views::ViewMenuDelegate { public views::ViewMenuDelegate,
public Bubble::Observer {
public: public:
// Creates a new button. If |has_menu| is true then clicking on the button // Creates a new button. If |has_menu| is true then clicking on the button
// will cause the profile menu to be displayed. // will cause the profile menu to be displayed.
...@@ -45,7 +47,11 @@ class AvatarMenuButton : public views::MenuButton, ...@@ -45,7 +47,11 @@ class AvatarMenuButton : public views::MenuButton,
// views::ViewMenuDelegate // views::ViewMenuDelegate
virtual void RunMenu(views::View* source, const gfx::Point& pt) OVERRIDE; virtual void RunMenu(views::View* source, const gfx::Point& pt) OVERRIDE;
// Bubble::Observer implementation.
virtual void OnBubbleClosing();
Browser* browser_; Browser* browser_;
Bubble* bubble_;
bool has_menu_; bool has_menu_;
bool set_taskbar_decoration_; bool set_taskbar_decoration_;
scoped_ptr<ui::MenuModel> menu_model_; scoped_ptr<ui::MenuModel> menu_model_;
......
...@@ -2615,11 +2615,11 @@ void BrowserView::ShowAvatarBubble(TabContents* tab_contents, ...@@ -2615,11 +2615,11 @@ void BrowserView::ShowAvatarBubble(TabContents* tab_contents,
views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin); views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin);
gfx::Rect bounds(origin, rect.size()); gfx::Rect bounds(origin, rect.size());
// TODO(msw): Set and support views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE. AvatarMenuBubbleView* bubble_view = new AvatarMenuBubbleView(browser_.get());
AvatarMenuBubbleView* bubble = new AvatarMenuBubbleView(this, // Bubble::Show() takes ownership of the view.
views::BubbleBorder::TOP_RIGHT, bounds, browser_.get()); Bubble::Show(this->GetWidget(), bounds, views::BubbleBorder::TOP_RIGHT,
views::BubbleDelegateView::CreateBubble(bubble); views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE,
bubble->Show(); bubble_view, bubble_view);
} }
void BrowserView::ShowAvatarBubbleFromAvatarButton() { void BrowserView::ShowAvatarBubbleFromAvatarButton() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment