1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUBBLE_VIEW_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "chrome/browser/profiles/avatar_menu_observer.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/views/controls/button/button.h"
16 #include "ui/views/controls/link_listener.h"
20 class ProfileItemView
;
34 // This bubble view is displayed when the user clicks on the avatar button.
35 // It displays a list of profiles and allows users to switch between profiles.
36 class AvatarMenuBubbleView
: public views::BubbleDelegateView
,
37 public views::ButtonListener
,
38 public views::LinkListener
,
39 public AvatarMenuObserver
{
41 // Helper function to show the bubble and ensure that it doesn't reshow.
42 // Normally this bubble is shown when there's a mouse down event on a button.
43 // If the bubble is already showing when the user clicks on the button then
44 // this will cause two things to happen:
45 // - (1) the button will show a new instance of the bubble
46 // - (2) the old instance of the bubble will get a deactivate event and
48 // To prevent this reshow this function checks if an instance of the bubble
49 // is already showing and do nothing. This means that (1) will do nothing
50 // and (2) will correctly hide the old bubble instance.
51 static void ShowBubble(views::View
* anchor_view
,
52 views::BubbleBorder::Arrow arrow
,
53 views::BubbleBorder::ArrowPaintType arrow_paint_type
,
54 views::BubbleBorder::BubbleAlignment border_alignment
,
55 const gfx::Rect
& anchor_rect
,
57 static bool IsShowing();
60 virtual ~AvatarMenuBubbleView();
62 // views::View implementation.
63 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
64 virtual void Layout() OVERRIDE
;
65 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
67 // views::ButtonListener implementation.
68 virtual void ButtonPressed(views::Button
* sender
,
69 const ui::Event
& event
) OVERRIDE
;
71 // views::LinkListener implementation.
72 virtual void LinkClicked(views::Link
* source
, int event_flags
) OVERRIDE
;
74 // BubbleDelegate implementation.
75 virtual gfx::Rect
GetAnchorRect() const OVERRIDE
;
76 virtual void Init() OVERRIDE
;
77 virtual void WindowClosing() OVERRIDE
;
79 // AvatarMenuObserver implementation.
80 virtual void OnAvatarMenuChanged(
81 AvatarMenu
* avatar_menu
) OVERRIDE
;
83 // We normally close the bubble any time it becomes inactive but this can lead
84 // to flaky tests where unexpected UI events are triggering this behavior.
85 // Tests should call this with "false" for more consistent operation.
86 static void clear_close_on_deactivate_for_testing() {
87 close_on_deactivate_for_testing_
= false;
91 AvatarMenuBubbleView(views::View
* anchor_view
,
92 views::BubbleBorder::Arrow arrow
,
93 const gfx::Rect
& anchor_rect
,
96 // Sets the colors on all the |item_views_|. Called after the
97 // BubbleDelegateView is created and has loaded the colors from the
99 void SetBackgroundColors();
101 // Create the menu contents for a normal profile.
102 void InitMenuContents(AvatarMenu
* avatar_menu
);
104 // Create the managed user specific contents of the menu.
105 void InitManagedUserContents(AvatarMenu
* avatar_menu
);
107 scoped_ptr
<AvatarMenu
> avatar_menu_
;
108 gfx::Rect anchor_rect_
;
110 std::vector
<ProfileItemView
*> item_views_
;
112 // Used to separate the link entry in the avatar menu from the other entries.
113 views::Separator
* separator_
;
115 // This will be non-NULL if and only if
116 // avatar_menu_->ShouldShowAddNewProfileLink() returns true. See
117 // OnAvatarMenuChanged().
118 views::View
* buttons_view_
;
120 // This will be non-NULL if and only if |expanded_| is false and
121 // avatar_menu_->GetManagedUserInformation() returns a non-empty string.
122 // See OnAvatarMenuChanged().
123 views::Label
* managed_user_info_
;
124 views::ImageView
* icon_view_
;
125 views::Separator
* separator_switch_users_
;
126 views::Link
* switch_profile_link_
;
128 static AvatarMenuBubbleView
* avatar_bubble_
;
129 static bool close_on_deactivate_for_testing_
;
131 // Is set to true if the managed user has clicked on Switch Users.
134 DISALLOW_COPY_AND_ASSIGN(AvatarMenuBubbleView
);
137 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUBBLE_VIEW_H_