OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" | 5 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
6 | 6 |
7 #include "base/sys_string_conversions.h" | 7 #include "base/sys_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 - (NSButton*)buttonView { | 135 - (NSButton*)buttonView { |
136 return static_cast<NSButton*>(self.view); | 136 return static_cast<NSButton*>(self.view); |
137 } | 137 } |
138 | 138 |
139 - (void)setImage:(NSImage*)image { | 139 - (void)setImage:(NSImage*)image { |
140 [self.buttonView setImage:[self compositeImageWithShadow:image]]; | 140 [self.buttonView setImage:[self compositeImageWithShadow:image]]; |
141 } | 141 } |
142 | 142 |
143 // Private ///////////////////////////////////////////////////////////////////// | 143 - (void)showAvatarBubble { |
144 | |
145 - (void)setOpenMenuOnClick:(BOOL)flag { | |
146 [self.buttonView setEnabled:flag]; | |
147 } | |
148 | |
149 - (IBAction)buttonClicked:(id)sender { | |
150 DCHECK_EQ(self.buttonView, sender); | |
151 if (menuController_) | 144 if (menuController_) |
152 return; | 145 return; |
153 | 146 |
| 147 NSWindowController* wc = |
| 148 [browser_->window()->GetNativeHandle() windowController]; |
| 149 if ([wc isKindOfClass:[BrowserWindowController class]]) { |
| 150 [static_cast<BrowserWindowController*>(wc) |
| 151 lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
| 152 } |
| 153 |
154 NSView* view = self.view; | 154 NSView* view = self.view; |
155 NSPoint point = NSMakePoint(NSMidX([view bounds]), | 155 NSPoint point = NSMakePoint(NSMidX([view bounds]), |
156 NSMaxY([view bounds]) - kMenuYOffsetAdjust); | 156 NSMaxY([view bounds]) - kMenuYOffsetAdjust); |
157 point = [view convertPoint:point toView:nil]; | 157 point = [view convertPoint:point toView:nil]; |
158 point = [[view window] convertBaseToScreen:point]; | 158 point = [[view window] convertBaseToScreen:point]; |
159 | 159 |
160 // |menu| will automatically release itself on close. | 160 // |menu| will automatically release itself on close. |
161 menuController_ = [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | 161 menuController_ = [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
162 anchoredAt:point]; | 162 anchoredAt:point]; |
163 [[NSNotificationCenter defaultCenter] | 163 [[NSNotificationCenter defaultCenter] |
164 addObserver:self | 164 addObserver:self |
165 selector:@selector(bubbleWillClose:) | 165 selector:@selector(bubbleWillClose:) |
166 name:NSWindowWillCloseNotification | 166 name:NSWindowWillCloseNotification |
167 object:[menuController_ window]]; | 167 object:[menuController_ window]]; |
168 [menuController_ showWindow:self]; | 168 [menuController_ showWindow:self]; |
169 } | 169 } |
170 | 170 |
| 171 // Private ///////////////////////////////////////////////////////////////////// |
| 172 |
| 173 - (void)setOpenMenuOnClick:(BOOL)flag { |
| 174 [self.buttonView setEnabled:flag]; |
| 175 } |
| 176 |
| 177 - (IBAction)buttonClicked:(id)sender { |
| 178 DCHECK_EQ(self.buttonView, sender); |
| 179 [self showAvatarBubble]; |
| 180 } |
| 181 |
171 - (void)bubbleWillClose:(NSNotification*)notif { | 182 - (void)bubbleWillClose:(NSNotification*)notif { |
| 183 NSWindowController* wc = |
| 184 [browser_->window()->GetNativeHandle() windowController]; |
| 185 if ([wc isKindOfClass:[BrowserWindowController class]]) { |
| 186 [static_cast<BrowserWindowController*>(wc) |
| 187 releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
| 188 } |
172 menuController_ = nil; | 189 menuController_ = nil; |
173 } | 190 } |
174 | 191 |
175 // This will take in an original image and redraw it with a shadow. | 192 // This will take in an original image and redraw it with a shadow. |
176 - (NSImage*)compositeImageWithShadow:(NSImage*)image { | 193 - (NSImage*)compositeImageWithShadow:(NSImage*)image { |
177 gfx::ScopedNSGraphicsContextSaveGState scopedGState; | 194 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
178 | 195 |
179 scoped_nsobject<NSImage> destination( | 196 scoped_nsobject<NSImage> destination( |
180 [[NSImage alloc] initWithSize:[image size]]); | 197 [[NSImage alloc] initWithSize:[image size]]); |
181 | 198 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 [static_cast<BrowserWindowController*>(wc) layoutSubviews]; | 254 [static_cast<BrowserWindowController*>(wc) layoutSubviews]; |
238 } | 255 } |
239 | 256 |
240 // Testing ///////////////////////////////////////////////////////////////////// | 257 // Testing ///////////////////////////////////////////////////////////////////// |
241 | 258 |
242 - (AvatarMenuBubbleController*)menuController { | 259 - (AvatarMenuBubbleController*)menuController { |
243 return menuController_; | 260 return menuController_; |
244 } | 261 } |
245 | 262 |
246 @end | 263 @end |
OLD | NEW |