| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_AVATAR_MENU_BUBBLE_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_VIEWS_AVATAR_MENU_BUBBLE_VIEW_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 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" | |
| 17 | |
| 18 class AvatarMenu; | |
| 19 class Browser; | |
| 20 class ProfileItemView; | |
| 21 | |
| 22 namespace content { | |
| 23 class WebContents; | |
| 24 } | |
| 25 | |
| 26 namespace views { | |
| 27 class CustomButton; | |
| 28 class ImageView; | |
| 29 class Label; | |
| 30 class Link; | |
| 31 class Separator; | |
| 32 } | |
| 33 | |
| 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 { | |
| 40 public: | |
| 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 | |
| 47 // close | |
| 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::BubbleAlignment border_alignment, | |
| 54 const gfx::Rect& anchor_rect, | |
| 55 Browser* browser); | |
| 56 static bool IsShowing(); | |
| 57 static void Hide(); | |
| 58 | |
| 59 virtual ~AvatarMenuBubbleView(); | |
| 60 | |
| 61 // views::View implementation. | |
| 62 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 63 virtual void Layout() OVERRIDE; | |
| 64 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 65 | |
| 66 // views::ButtonListener implementation. | |
| 67 virtual void ButtonPressed(views::Button* sender, | |
| 68 const ui::Event& event) OVERRIDE; | |
| 69 | |
| 70 // views::LinkListener implementation. | |
| 71 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | |
| 72 | |
| 73 // BubbleDelegate implementation. | |
| 74 virtual gfx::Rect GetAnchorRect() OVERRIDE; | |
| 75 virtual void Init() OVERRIDE; | |
| 76 virtual void WindowClosing() OVERRIDE; | |
| 77 | |
| 78 // AvatarMenuObserver implementation. | |
| 79 virtual void OnAvatarMenuChanged( | |
| 80 AvatarMenu* avatar_menu) OVERRIDE; | |
| 81 | |
| 82 // We normally close the bubble any time it becomes inactive but this can lead | |
| 83 // to flaky tests where unexpected UI events are triggering this behavior. | |
| 84 // Tests should call this with "false" for more consistent operation. | |
| 85 static void clear_close_on_deactivate_for_testing() { | |
| 86 close_on_deactivate_for_testing_ = false; | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 AvatarMenuBubbleView(views::View* anchor_view, | |
| 91 views::BubbleBorder::Arrow arrow, | |
| 92 const gfx::Rect& anchor_rect, | |
| 93 Browser* browser); | |
| 94 | |
| 95 // Sets the colors on all the |item_views_|. Called after the | |
| 96 // BubbleDelegateView is created and has loaded the colors from the | |
| 97 // NativeTheme. | |
| 98 void SetBackgroundColors(); | |
| 99 | |
| 100 // Create the menu contents for a normal profile. | |
| 101 void InitMenuContents(AvatarMenu* avatar_menu); | |
| 102 | |
| 103 // Create the managed user specific contents of the menu. | |
| 104 void InitManagedUserContents(AvatarMenu* avatar_menu); | |
| 105 | |
| 106 scoped_ptr<AvatarMenu> avatar_menu_; | |
| 107 gfx::Rect anchor_rect_; | |
| 108 Browser* browser_; | |
| 109 std::vector<ProfileItemView*> item_views_; | |
| 110 | |
| 111 // Used to separate the link entry in the avatar menu from the other entries. | |
| 112 views::Separator* separator_; | |
| 113 | |
| 114 // This will be non-NULL if and only if | |
| 115 // avatar_menu_->ShouldShowAddNewProfileLink() returns true. See | |
| 116 // OnAvatarMenuChanged(). | |
| 117 views::View* buttons_view_; | |
| 118 | |
| 119 // This will be non-NULL if and only if |expanded_| is false and | |
| 120 // avatar_menu_->GetManagedUserInformation() returns a non-empty string. | |
| 121 // See OnAvatarMenuChanged(). | |
| 122 views::Label* managed_user_info_; | |
| 123 views::ImageView* icon_view_; | |
| 124 views::Separator* separator_switch_users_; | |
| 125 views::Link* switch_profile_link_; | |
| 126 | |
| 127 static AvatarMenuBubbleView* avatar_bubble_; | |
| 128 static bool close_on_deactivate_for_testing_; | |
| 129 | |
| 130 // Is set to true if the managed user has clicked on Switch Users. | |
| 131 bool expanded_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(AvatarMenuBubbleView); | |
| 134 }; | |
| 135 | |
| 136 #endif // CHROME_BROWSER_UI_VIEWS_AVATAR_MENU_BUBBLE_VIEW_H_ | |
| OLD | NEW |