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_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_
8 #import <Cocoa/Cocoa.h>
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #import "chrome/browser/ui/cocoa/base_bubble_controller.h"
13 #import "ui/base/cocoa/tracking_area.h"
18 // This window controller manages the bubble that displays a "menu" of profiles.
19 // It is brought open by clicking on the avatar icon in the window frame.
20 @interface AvatarMenuBubbleController
: BaseBubbleController
{
22 // The menu that contains the data from the backend.
23 scoped_ptr
<AvatarMenu
> menu_
;
25 // Array of the below view controllers.
26 base::scoped_nsobject
<NSMutableArray
> items_
;
28 // Is set to true if the supervised user has clicked on Switch Users.
32 // Designated initializer. The browser is passed to the menu for profile
34 - (id
)initWithBrowser
:(Browser
*)parentBrowser
35 anchoredAt
:(NSPoint
)point
;
37 // Creates a new profile.
38 - (IBAction
)newProfile
:(id
)sender
;
40 // Switches to a given profile. |sender| is an AvatarMenuItemController.
41 - (IBAction
)switchToProfile
:(id
)sender
;
43 // Edits a given profile. |sender| is an AvatarMenuItemController.
44 - (IBAction
)editProfile
:(id
)sender
;
46 // Switches from the supervised user avatar menu to the normal avatar menu which
47 // allows to switch profiles.
48 - (IBAction
)switchProfile
:(id
)sender
;
52 ////////////////////////////////////////////////////////////////////////////////
54 // This view controller manages the menu item XIB.
55 @interface AvatarMenuItemController
: NSViewController
<NSAnimationDelegate
> {
57 // The parent menu controller; owns this.
58 __weak AvatarMenuBubbleController
* controller_
;
60 // The index of the item in the AvatarMenu.
63 // Tracks whether this item is currently highlighted.
66 // The animation showing the edit link, which is run after the user has
67 // dwelled over the item for a short delay.
68 base::scoped_nsobject
<NSAnimation
> linkAnimation_
;
70 // Instance variables that back the outlets.
71 __weak NSImageView
* iconView_
;
72 __weak NSImageView
* activeView_
;
73 __weak NSTextField
* nameField_
;
74 // These two views sit on top of each other, and only one is visible at a
75 // time. The editButton_ is visible when the mouse is over the item and the
76 // emailField_ is visible otherwise.
77 __weak NSTextField
* emailField_
;
78 __weak NSButton
* editButton_
;
80 @
property(readonly
, nonatomic
) size_t menuIndex
;
81 @
property(assign
, nonatomic
) BOOL isHighlighted
;
82 @
property(assign
, nonatomic
) IBOutlet NSImageView
* iconView
;
83 @
property(assign
, nonatomic
) IBOutlet NSImageView
* activeView
;
84 @
property(assign
, nonatomic
) IBOutlet NSTextField
* nameField
;
85 @
property(assign
, nonatomic
) IBOutlet NSTextField
* emailField
;
86 @
property(assign
, nonatomic
) IBOutlet NSButton
* editButton
;
88 // Designated initializer.
89 - (id
)initWithMenuIndex
:(size_t)menuIndex
90 menuController
:(AvatarMenuBubbleController
*)controller
;
92 // Actions that are forwarded to the |controller_|.
93 - (IBAction
)switchToProfile
:(id
)sender
;
94 - (IBAction
)editProfile
:(id
)sender
;
96 // Highlights the subviews appropriately for a given event type from the switch
98 - (void)highlightForEventType
:(NSEventType
)type
;
102 ////////////////////////////////////////////////////////////////////////////////
104 // Simple button cell to get tracking and mouse events forwarded back to the
105 // view controller for changing highlight style of the item subviews. This is
106 // an invisible button that underlays most of the menu item and is responsible
107 // for performing the switch profile action.
108 @interface AvatarMenuItemView
: NSView
{
110 // The controller that manages this.
111 __weak AvatarMenuItemController
* viewController_
;
113 // Used to highlight the background on hover.
114 ui::ScopedCrTrackingArea trackingArea_
;
116 @
property(assign
, nonatomic
) IBOutlet AvatarMenuItemController
* viewController
;
119 ////////////////////////////////////////////////////////////////////////////////
121 @interface AccessibilityIgnoredImageCell
: NSImageCell
124 @interface AccessibilityIgnoredTextFieldCell
: NSTextFieldCell
127 // Testing API /////////////////////////////////////////////////////////////////
129 @interface
AvatarMenuBubbleController (ExposedForTesting
)
130 - (id
)initWithMenu
:(AvatarMenu
*)menu
131 parentWindow
:(NSWindow
*)parent
132 anchoredAt
:(NSPoint
)point
;
133 - (void)performLayout
;
134 - (NSMutableArray
*)items
;
137 @interface
AvatarMenuItemController (ExposedForTesting
)
138 - (void)willStartAnimation
:(NSAnimation
*)animation
;
141 #endif // CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_