OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/cocoa/apps_search_box_controller.h" | 5 #import "ui/app_list/cocoa/apps_search_box_controller.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
11 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 11 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" |
12 #include "ui/app_list/app_list_menu.h" | 12 #include "ui/app_list/app_list_menu.h" |
13 #import "ui/app_list/cocoa/current_user_menu_item_view.h" | 13 #include "ui/app_list/app_list_model.h" |
14 #include "ui/app_list/search_box_model.h" | 14 #include "ui/app_list/search_box_model.h" |
15 #include "ui/app_list/search_box_model_observer.h" | 15 #include "ui/app_list/search_box_model_observer.h" |
16 #import "ui/base/cocoa/controls/hover_image_menu_button.h" | 16 #import "ui/base/cocoa/controls/hover_image_menu_button.h" |
17 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h" | 17 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h" |
18 #import "ui/base/cocoa/menu_controller.h" | 18 #import "ui/base/cocoa/menu_controller.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image_skia_util_mac.h" | 20 #include "ui/gfx/image/image_skia_util_mac.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 appListMenu_.reset(); | 170 appListMenu_.reset(); |
171 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. | 171 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. |
172 delegate_ = delegate; | 172 delegate_ = delegate; |
173 if (!delegate_) | 173 if (!delegate_) |
174 return; | 174 return; |
175 | 175 |
176 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); | 176 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); |
177 if (![delegate_ appListDelegate]) | 177 if (![delegate_ appListDelegate]) |
178 return; | 178 return; |
179 | 179 |
180 appListMenu_.reset(new app_list::AppListMenu([delegate_ appListDelegate])); | 180 appListMenu_.reset( |
| 181 new app_list::AppListMenu([delegate_ appListDelegate], |
| 182 [delegate_ appListModel]->users())); |
181 [self rebuildMenu]; | 183 [self rebuildMenu]; |
182 } | 184 } |
183 | 185 |
184 - (NSTextField*)searchTextField { | 186 - (NSTextField*)searchTextField { |
185 return searchTextField_; | 187 return searchTextField_; |
186 } | 188 } |
187 | 189 |
188 - (NSPopUpButton*)menuControl { | 190 - (NSPopUpButton*)menuControl { |
189 return menuButton_; | 191 return menuButton_; |
190 } | 192 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 // Need to initialze super with a NULL model, otherwise it will immediately | 367 // Need to initialze super with a NULL model, otherwise it will immediately |
366 // try to populate, which can't be done until setting the parent. | 368 // try to populate, which can't be done until setting the parent. |
367 if ((self = [super initWithModel:NULL | 369 if ((self = [super initWithModel:NULL |
368 useWithPopUpButtonCell:YES])) { | 370 useWithPopUpButtonCell:YES])) { |
369 searchBoxController_ = parent; | 371 searchBoxController_ = parent; |
370 [super setModel:[parent appListMenu]->menu_model()]; | 372 [super setModel:[parent appListMenu]->menu_model()]; |
371 } | 373 } |
372 return self; | 374 return self; |
373 } | 375 } |
374 | 376 |
375 - (void)addItemToMenu:(NSMenu*)menu | |
376 atIndex:(NSInteger)index | |
377 fromModel:(ui::MenuModel*)model { | |
378 [super addItemToMenu:menu | |
379 atIndex:index | |
380 fromModel:model]; | |
381 if (model->GetCommandIdAt(index) != app_list::AppListMenu::CURRENT_USER) | |
382 return; | |
383 | |
384 base::scoped_nsobject<NSView> customItemView([[CurrentUserMenuItemView alloc] | |
385 initWithCurrentUser:[[searchBoxController_ delegate] currentUserName] | |
386 userEmail:[[searchBoxController_ delegate] currentUserEmail]]); | |
387 [[menu itemAtIndex:index] setView:customItemView]; | |
388 } | |
389 | |
390 - (NSRect)confinementRectForMenu:(NSMenu*)menu | 377 - (NSRect)confinementRectForMenu:(NSMenu*)menu |
391 onScreen:(NSScreen*)screen { | 378 onScreen:(NSScreen*)screen { |
392 NSPopUpButton* menuButton = [searchBoxController_ menuControl]; | 379 NSPopUpButton* menuButton = [searchBoxController_ menuControl]; |
393 // Ensure the menu comes up below the menu button by trimming the window frame | 380 // Ensure the menu comes up below the menu button by trimming the window frame |
394 // to a point anchored below the bottom right of the button. | 381 // to a point anchored below the bottom right of the button. |
395 NSRect anchorRect = [menuButton convertRect:[menuButton bounds] | 382 NSRect anchorRect = [menuButton convertRect:[menuButton bounds] |
396 toView:nil]; | 383 toView:nil]; |
397 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( | 384 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( |
398 NSMaxX(anchorRect) + kMenuXOffsetFromButton, | 385 NSMaxX(anchorRect) + kMenuXOffsetFromButton, |
399 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; | 386 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; |
400 NSRect confinementRect = [[menuButton window] frame]; | 387 NSRect confinementRect = [[menuButton window] frame]; |
401 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), | 388 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), |
402 anchorPoint.y - NSMinY(confinementRect)); | 389 anchorPoint.y - NSMinY(confinementRect)); |
403 return confinementRect; | 390 return confinementRect; |
404 } | 391 } |
405 | 392 |
406 @end | 393 @end |
OLD | NEW |