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 @@
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;
......@@ -237,7 +234,7 @@ void ProfileItemView::Layout() {
image_view_->SetBoundsRect(icon_rect);
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();
name_size.set_width(std::min(name_size.width(), max_label_width));
gfx::Size state_size = sync_state_label_->GetPreferredSize();
......@@ -282,6 +279,11 @@ 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);
......@@ -328,14 +330,8 @@ bool ProfileItemView::IsHighlighted() {
// AvatarMenuBubbleView -------------------------------------------------------
AvatarMenuBubbleView::AvatarMenuBubbleView(
views::View* anchor_view,
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),
AvatarMenuBubbleView::AvatarMenuBubbleView(Browser* browser)
: add_profile_link_(NULL),
browser_(browser) {
avatar_menu_model_.reset(new AvatarMenuModel(
&g_browser_process->profile_manager()->GetProfileInfoCache(),
......@@ -448,13 +444,23 @@ void AvatarMenuBubbleView::LinkClicked(views::Link* source, int event_flags) {
}
}
gfx::Point AvatarMenuBubbleView::GetAnchorPoint() {
return gfx::Point(anchor_rect_.CenterPoint().x(), anchor_rect_.bottom());
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) {
}
void AvatarMenuBubbleView::Init() {
AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, 0));
AddAccelerator(ui::Accelerator(ui::VKEY_UP, 0));
bool AvatarMenuBubbleView::CloseOnEscape() {
return true;
}
bool AvatarMenuBubbleView::FadeInOnShow() {
return false;
}
void AvatarMenuBubbleView::OnAvatarMenuModelChanged(
......@@ -482,6 +488,7 @@ 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_);
......
......@@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.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/link_listener.h"
......@@ -26,15 +26,13 @@ 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::BubbleDelegateView,
class AvatarMenuBubbleView : public views::View,
public views::ButtonListener,
public views::LinkListener,
public BubbleDelegate,
public AvatarMenuModelObserver {
public:
AvatarMenuBubbleView(views::View* anchor_view,
views::BubbleBorder::ArrowLocation arrow_location,
const gfx::Rect& anchor_rect,
Browser* browser);
explicit AvatarMenuBubbleView(Browser* browser);
virtual ~AvatarMenuBubbleView();
// views::View implementation.
......@@ -50,8 +48,10 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView,
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
// BubbleDelegate implementation.
virtual gfx::Point GetAnchorPoint() OVERRIDE;
virtual void Init() OVERRIDE;
virtual void BubbleShown() OVERRIDE;
virtual void BubbleClosing(Bubble* bubble, bool closed_by_escape) OVERRIDE;
virtual bool CloseOnEscape() OVERRIDE;
virtual bool FadeInOnShow() OVERRIDE;
// AvatarMenuModelObserver implementation.
virtual void OnAvatarMenuModelChanged(
......@@ -60,7 +60,6 @@ class AvatarMenuBubbleView : public views::BubbleDelegateView,
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_;
......
......@@ -78,6 +78,7 @@ 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.
......@@ -85,6 +86,8 @@ 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())
......@@ -144,18 +147,26 @@ void AvatarMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
}
void AvatarMenuButton::ShowAvatarBubble() {
if (!has_menu_)
if (!has_menu_ || bubble_)
return;
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
gfx::Point 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,
views::BubbleBorder::TOP_LEFT, bounds, browser_);
views::BubbleDelegateView::CreateBubble(bubble);
bubble->Show();
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);
ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE);
}
void AvatarMenuButton::OnBubbleClosing() {
bubble_->RemoveObserver(this);
bubble_ = NULL;
}
......@@ -9,6 +9,7 @@
#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"
......@@ -24,7 +25,8 @@ class Browser;
// The button can optionally have a menu attached to it.
class AvatarMenuButton : public views::MenuButton,
public views::ViewMenuDelegate {
public views::ViewMenuDelegate,
public Bubble::Observer {
public:
// Creates a new button. If |has_menu| is true then clicking on the button
// will cause the profile menu to be displayed.
......@@ -45,7 +47,11 @@ 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_;
......
......@@ -2615,11 +2615,11 @@ void BrowserView::ShowAvatarBubble(TabContents* tab_contents,
views::View::ConvertPointToScreen(GetTabContentsContainerView(), &origin);
gfx::Rect bounds(origin, rect.size());
// 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();
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);
}
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