Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / browser / avatar_menu_bubble_controller.h
1 // Copyright (c) 2012 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_BROWSER_AVATAR_MENU_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_BROWSER_AVATAR_MENU_BUBBLE_CONTROLLER_H_
7
8 #import <Cocoa/Cocoa.h>
9
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"
14
15 class AvatarMenu;
16 class Browser;
17
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 {
21  @private
22   // The menu that contains the data from the backend.
23   scoped_ptr<AvatarMenu> menu_;
24
25   // Array of the below view controllers.
26   base::scoped_nsobject<NSMutableArray> items_;
27
28   // Is set to true if the managed user has clicked on Switch Users.
29   BOOL expanded_;
30 }
31
32 // Designated initializer. The browser is passed to the menu for profile
33 // information.
34 - (id)initWithBrowser:(Browser*)parentBrowser
35            anchoredAt:(NSPoint)point;
36
37 // Creates a new profile.
38 - (IBAction)newProfile:(id)sender;
39
40 // Switches to a given profile. |sender| is an AvatarMenuItemController.
41 - (IBAction)switchToProfile:(id)sender;
42
43 // Edits a given profile. |sender| is an AvatarMenuItemController.
44 - (IBAction)editProfile:(id)sender;
45
46 // Switches from the managed user avatar menu to the normal avatar menu which
47 // allows to switch profiles.
48 - (IBAction)switchProfile:(id)sender;
49
50 @end
51
52 ////////////////////////////////////////////////////////////////////////////////
53
54 // This view controller manages the menu item XIB.
55 @interface AvatarMenuItemController : NSViewController<NSAnimationDelegate> {
56  @private
57   // The parent menu controller; owns this.
58   __weak AvatarMenuBubbleController* controller_;
59
60   // The index of the item in the AvatarMenu.
61   size_t menuIndex_;
62
63   // Tracks whether this item is currently highlighted.
64   BOOL isHighlighted_;
65
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_;
69
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_;
79 }
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;
87
88 // Designated initializer.
89 - (id)initWithMenuIndex:(size_t)menuIndex
90           menuController:(AvatarMenuBubbleController*)controller;
91
92 // Actions that are forwarded to the |controller_|.
93 - (IBAction)switchToProfile:(id)sender;
94 - (IBAction)editProfile:(id)sender;
95
96 // Highlights the subviews appropriately for a given event type from the switch
97 // profile button.
98 - (void)highlightForEventType:(NSEventType)type;
99
100 @end
101
102 ////////////////////////////////////////////////////////////////////////////////
103
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 {
109  @private
110   // The controller that manages this.
111   __weak AvatarMenuItemController* viewController_;
112
113   // Used to highlight the background on hover.
114   ui::ScopedCrTrackingArea trackingArea_;
115 }
116 @property(assign, nonatomic) IBOutlet AvatarMenuItemController* viewController;
117 @end
118
119 ////////////////////////////////////////////////////////////////////////////////
120
121 @interface AccessibilityIgnoredImageCell : NSImageCell
122 @end
123
124 @interface AccessibilityIgnoredTextFieldCell : NSTextFieldCell
125 @end
126
127 // Testing API /////////////////////////////////////////////////////////////////
128
129 @interface AvatarMenuBubbleController (ExposedForTesting)
130 - (id)initWithMenu:(AvatarMenu*)menu
131        parentWindow:(NSWindow*)parent
132          anchoredAt:(NSPoint)point;
133 - (void)performLayout;
134 - (NSMutableArray*)items;
135 @end
136
137 @interface AvatarMenuItemController (ExposedForTesting)
138 - (void)willStartAnimation:(NSAnimation*)animation;
139 @end
140
141 #endif  // CHROME_BROWSER_UI_COCOA_BROWSER_AVATAR_MENU_BUBBLE_CONTROLLER_H_