OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_ | |
7 | |
8 #import <Cocoa/Cocoa.h> | |
9 #include <stddef.h> | |
10 | |
11 #include <memory> | |
12 | |
13 #include "base/mac/objc_property_releaser.h" | |
14 #include "base/mac/scoped_nsobject.h" | |
15 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | |
16 #import "ui/base/cocoa/tracking_area.h" | |
17 | |
18 class AvatarMenu; | |
19 class Browser; | |
20 | |
21 // This window controller manages the bubble that displays a "menu" of profiles. | |
22 // It is brought open by clicking on the avatar icon in the window frame. | |
23 @interface AvatarMenuBubbleController : BaseBubbleController { | |
24 @private | |
25 // The menu that contains the data from the backend. | |
26 std::unique_ptr<AvatarMenu> menu_; | |
27 | |
28 // Array of the below view controllers. | |
29 base::scoped_nsobject<NSMutableArray> items_; | |
30 | |
31 // Is set to true if the supervised user has clicked on Switch Users. | |
32 BOOL expanded_; | |
33 } | |
34 | |
35 // Designated initializer. The browser is passed to the menu for profile | |
36 // information. | |
37 - (id)initWithBrowser:(Browser*)parentBrowser | |
38 anchoredAt:(NSPoint)point; | |
39 | |
40 // Creates a new profile. | |
41 - (IBAction)newProfile:(id)sender; | |
42 | |
43 // Switches to a given profile. |sender| is an AvatarMenuItemController. | |
44 - (IBAction)switchToProfile:(id)sender; | |
45 | |
46 // Edits a given profile. |sender| is an AvatarMenuItemController. | |
47 - (IBAction)editProfile:(id)sender; | |
48 | |
49 // Switches from the supervised user avatar menu to the normal avatar menu which | |
50 // allows to switch profiles. | |
51 - (IBAction)switchProfile:(id)sender; | |
52 | |
53 @end | |
54 | |
55 //////////////////////////////////////////////////////////////////////////////// | |
56 | |
57 // This view controller manages the menu item XIB. | |
58 @interface AvatarMenuItemController : NSViewController<NSAnimationDelegate> { | |
59 @private | |
60 // The parent menu controller; owns this. | |
61 AvatarMenuBubbleController* controller_; // weak | |
62 | |
63 // The index of the item in the AvatarMenu. | |
64 size_t menuIndex_; | |
65 | |
66 // Tracks whether this item is currently highlighted. | |
67 BOOL isHighlighted_; | |
68 | |
69 // The animation showing the edit link, which is run after the user has | |
70 // dwelled over the item for a short delay. | |
71 base::scoped_nsobject<NSAnimation> linkAnimation_; | |
72 | |
73 // Instance variables that back the outlets. | |
74 NSImageView* iconView_; | |
75 NSImageView* activeView_; | |
76 NSTextField* nameField_; | |
77 // These two views sit on top of each other, and only one is visible at a | |
78 // time. The editButton_ is visible when the mouse is over the item and the | |
79 // emailField_ is visible otherwise. | |
80 NSTextField* emailField_; | |
81 NSButton* editButton_; | |
82 | |
83 base::mac::ObjCPropertyReleaser propertyReleaser_; | |
84 } | |
85 @property(readonly, nonatomic) size_t menuIndex; | |
86 @property(assign, nonatomic) BOOL isHighlighted; | |
87 @property(retain, nonatomic) IBOutlet NSImageView* iconView; | |
88 @property(retain, nonatomic) IBOutlet NSImageView* activeView; | |
89 @property(retain, nonatomic) IBOutlet NSTextField* nameField; | |
90 @property(retain, nonatomic) IBOutlet NSTextField* emailField; | |
91 @property(retain, nonatomic) IBOutlet NSButton* editButton; | |
92 | |
93 // Designated initializer. | |
94 - (id)initWithMenuIndex:(size_t)menuIndex | |
95 menuController:(AvatarMenuBubbleController*)controller; | |
96 | |
97 // Actions that are forwarded to the |controller_|. | |
98 - (IBAction)switchToProfile:(id)sender; | |
99 - (IBAction)editProfile:(id)sender; | |
100 | |
101 // Highlights the subviews appropriately for a given event type from the switch | |
102 // profile button. | |
103 - (void)highlightForEventType:(NSEventType)type; | |
104 | |
105 @end | |
106 | |
107 //////////////////////////////////////////////////////////////////////////////// | |
108 | |
109 // Simple button cell to get tracking and mouse events forwarded back to the | |
110 // view controller for changing highlight style of the item subviews. This is | |
111 // an invisible button that underlays most of the menu item and is responsible | |
112 // for performing the switch profile action. | |
113 @interface AvatarMenuItemView : NSView { | |
114 @private | |
115 // The controller that manages this. | |
116 // weak to not form a reference cycle with the controller. | |
117 __unsafe_unretained AvatarMenuItemController* viewController_; | |
118 | |
119 // Used to highlight the background on hover. | |
120 ui::ScopedCrTrackingArea trackingArea_; | |
121 } | |
122 @property(assign, nonatomic) IBOutlet AvatarMenuItemController* viewController; | |
123 @end | |
124 | |
125 //////////////////////////////////////////////////////////////////////////////// | |
126 | |
127 @interface AccessibilityIgnoredImageCell : NSImageCell | |
128 @end | |
129 | |
130 @interface AccessibilityIgnoredTextFieldCell : NSTextFieldCell | |
131 @end | |
132 | |
133 // Testing API ///////////////////////////////////////////////////////////////// | |
134 | |
135 @interface AvatarMenuBubbleController (ExposedForTesting) | |
136 - (id)initWithMenu:(AvatarMenu*)menu | |
137 parentWindow:(NSWindow*)parent | |
138 anchoredAt:(NSPoint)point; | |
139 - (void)performLayout; | |
140 - (NSMutableArray*)items; | |
141 @end | |
142 | |
143 @interface AvatarMenuItemController (ExposedForTesting) | |
144 - (void)willStartAnimation:(NSAnimation*)animation; | |
145 @end | |
146 | |
147 #endif // CHROME_BROWSER_UI_COCOA_PROFILES_AVATAR_MENU_BUBBLE_CONTROLLER_H_ | |
OLD | NEW |