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 ~AvatarMenuBubbleView() override
;
62 // views::View implementation.
63 gfx::Size
GetPreferredSize() const override
;
64 void Layout() override
;
65 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
67 // views::ButtonListener implementation.
68 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
70 // views::LinkListener implementation.
71 void LinkClicked(views::Link
* source
, int event_flags
) override
;
73 // BubbleDelegate implementation.
74 gfx::Rect
GetAnchorRect() const override
;
76 void WindowClosing() override
;
78 // AvatarMenuObserver implementation.
79 void OnAvatarMenuChanged(AvatarMenu
* avatar_menu
) override
;
81 // We normally close the bubble any time it becomes inactive but this can lead
82 // to flaky tests where unexpected UI events are triggering this behavior.
83 // Tests should call this with "false" for more consistent operation.
84 static void clear_close_on_deactivate_for_testing() {
85 close_on_deactivate_for_testing_
= false;
89 AvatarMenuBubbleView(views::View
* anchor_view
,
90 views::BubbleBorder::Arrow arrow
,
91 const gfx::Rect
& anchor_rect
,
94 // Sets the colors on all the |item_views_|. Called after the
95 // BubbleDelegateView is created and has loaded the colors from the
97 void SetBackgroundColors();
99 // Create the menu contents for a normal profile.
100 void InitMenuContents(AvatarMenu
* avatar_menu
);
102 // Create the supervised user specific contents of the menu.
103 void InitSupervisedUserContents(AvatarMenu
* avatar_menu
);
105 scoped_ptr
<AvatarMenu
> avatar_menu_
;
106 gfx::Rect anchor_rect_
;
108 std::vector
<ProfileItemView
*> item_views_
;
110 // Used to separate the link entry in the avatar menu from the other entries.
111 views::Separator
* separator_
;
113 // This will be non-NULL if and only if
114 // avatar_menu_->ShouldShowAddNewProfileLink() returns true. See
115 // OnAvatarMenuChanged().
116 views::View
* buttons_view_
;
118 // This will be non-NULL if and only if |expanded_| is false and
119 // avatar_menu_->GetSupervisedUserInformation() returns a non-empty string.
120 // See OnAvatarMenuChanged().
121 views::Label
* supervised_user_info_
;
122 views::ImageView
* icon_view_
;
123 views::Separator
* separator_switch_users_
;
124 views::Link
* switch_profile_link_
;
126 static AvatarMenuBubbleView
* avatar_bubble_
;
127 static bool close_on_deactivate_for_testing_
;
129 // Is set to true if the supervised user has clicked on Switch Users.
132 DISALLOW_COPY_AND_ASSIGN(AvatarMenuBubbleView
);
135 #endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_MENU_BUBBLE_VIEW_H_