Chromium Code Reviews| 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" | |
| 14 #include "ui/app_list/search_box_model.h" | 13 #include "ui/app_list/search_box_model.h" |
| 15 #include "ui/app_list/search_box_model_observer.h" | 14 #include "ui/app_list/search_box_model_observer.h" |
| 16 #import "ui/base/cocoa/controls/hover_image_menu_button.h" | 15 #import "ui/base/cocoa/controls/hover_image_menu_button.h" |
| 17 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h" | 16 #import "ui/base/cocoa/controls/hover_image_menu_button_cell.h" |
| 18 #import "ui/base/cocoa/menu_controller.h" | 17 #import "ui/base/cocoa/menu_controller.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/image/image_skia_util_mac.h" | 19 #include "ui/gfx/image/image_skia_util_mac.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 appListMenu_.reset(); | 169 appListMenu_.reset(); |
| 171 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. | 170 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. |
| 172 delegate_ = delegate; | 171 delegate_ = delegate; |
| 173 if (!delegate_) | 172 if (!delegate_) |
| 174 return; | 173 return; |
| 175 | 174 |
| 176 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); | 175 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); |
| 177 if (![delegate_ appListDelegate]) | 176 if (![delegate_ appListDelegate]) |
| 178 return; | 177 return; |
| 179 | 178 |
| 180 appListMenu_.reset(new app_list::AppListMenu([delegate_ appListDelegate])); | 179 appListMenu_.reset( |
| 180 new app_list::AppListMenu([delegate_ appListDelegate], | |
| 181 [delegate_ appListModel]->users())); | |
|
tapted
2013/09/16 20:46:44
nit: since it is dereferenced here, app_list_model
calamity
2013/09/17 00:09:26
Done.
| |
| 181 [self rebuildMenu]; | 182 [self rebuildMenu]; |
| 182 } | 183 } |
| 183 | 184 |
| 184 - (NSTextField*)searchTextField { | 185 - (NSTextField*)searchTextField { |
| 185 return searchTextField_; | 186 return searchTextField_; |
| 186 } | 187 } |
| 187 | 188 |
| 188 - (NSPopUpButton*)menuControl { | 189 - (NSPopUpButton*)menuControl { |
| 189 return menuButton_; | 190 return menuButton_; |
| 190 } | 191 } |
| (...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 | 366 // 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. | 367 // try to populate, which can't be done until setting the parent. |
| 367 if ((self = [super initWithModel:NULL | 368 if ((self = [super initWithModel:NULL |
| 368 useWithPopUpButtonCell:YES])) { | 369 useWithPopUpButtonCell:YES])) { |
| 369 searchBoxController_ = parent; | 370 searchBoxController_ = parent; |
| 370 [super setModel:[parent appListMenu]->menu_model()]; | 371 [super setModel:[parent appListMenu]->menu_model()]; |
| 371 } | 372 } |
| 372 return self; | 373 return self; |
| 373 } | 374 } |
| 374 | 375 |
| 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 | 376 - (NSRect)confinementRectForMenu:(NSMenu*)menu |
| 391 onScreen:(NSScreen*)screen { | 377 onScreen:(NSScreen*)screen { |
| 392 NSPopUpButton* menuButton = [searchBoxController_ menuControl]; | 378 NSPopUpButton* menuButton = [searchBoxController_ menuControl]; |
| 393 // Ensure the menu comes up below the menu button by trimming the window frame | 379 // 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. | 380 // to a point anchored below the bottom right of the button. |
| 395 NSRect anchorRect = [menuButton convertRect:[menuButton bounds] | 381 NSRect anchorRect = [menuButton convertRect:[menuButton bounds] |
| 396 toView:nil]; | 382 toView:nil]; |
| 397 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( | 383 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( |
| 398 NSMaxX(anchorRect) + kMenuXOffsetFromButton, | 384 NSMaxX(anchorRect) + kMenuXOffsetFromButton, |
| 399 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; | 385 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; |
| 400 NSRect confinementRect = [[menuButton window] frame]; | 386 NSRect confinementRect = [[menuButton window] frame]; |
| 401 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), | 387 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), |
| 402 anchorPoint.y - NSMinY(confinementRect)); | 388 anchorPoint.y - NSMinY(confinementRect)); |
| 403 return confinementRect; | 389 return confinementRect; |
| 404 } | 390 } |
| 405 | 391 |
| 406 @end | 392 @end |
| OLD | NEW |