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" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 - (void)clearSearch { | 153 - (void)clearSearch { |
154 [searchTextField_ setStringValue:@""]; | 154 [searchTextField_ setStringValue:@""]; |
155 [self controlTextDidChange:nil]; | 155 [self controlTextDidChange:nil]; |
156 } | 156 } |
157 | 157 |
158 - (void)rebuildMenu { | 158 - (void)rebuildMenu { |
159 if (![delegate_ appListDelegate]) | 159 if (![delegate_ appListDelegate]) |
160 return; | 160 return; |
161 | 161 |
| 162 [menuController_ setModel:NULL]; |
| 163 appListMenu_.reset( |
| 164 new app_list::AppListMenu([delegate_ appListDelegate], |
| 165 [delegate_ appListModel]->users())); |
162 menuController_.reset([[AppListMenuController alloc] | 166 menuController_.reset([[AppListMenuController alloc] |
163 initWithSearchBoxController:self]); | 167 initWithSearchBoxController:self]); |
164 [menuButton_ setMenu:[menuController_ menu]]; // Menu will populate here. | 168 [menuButton_ setMenu:[menuController_ menu]]; // Menu will populate here. |
165 } | 169 } |
166 | 170 |
167 - (void)setDelegate:(id<AppsSearchBoxDelegate>)delegate { | 171 - (void)setDelegate:(id<AppsSearchBoxDelegate>)delegate { |
168 [[menuButton_ menu] removeAllItems]; | 172 [[menuButton_ menu] removeAllItems]; |
169 menuController_.reset(); | 173 menuController_.reset(); |
170 appListMenu_.reset(); | 174 appListMenu_.reset(); |
171 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. | 175 bridge_.reset(); // Ensure observers are cleared before updating |delegate_|. |
172 delegate_ = delegate; | 176 delegate_ = delegate; |
173 if (!delegate_) | 177 if (!delegate_) |
174 return; | 178 return; |
175 | 179 |
176 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); | 180 bridge_.reset(new app_list::SearchBoxModelObserverBridge(self)); |
177 if (![delegate_ appListDelegate]) | |
178 return; | |
179 | |
180 appListMenu_.reset( | |
181 new app_list::AppListMenu([delegate_ appListDelegate], | |
182 [delegate_ appListModel]->users())); | |
183 [self rebuildMenu]; | 181 [self rebuildMenu]; |
184 } | 182 } |
185 | 183 |
186 - (NSTextField*)searchTextField { | 184 - (NSTextField*)searchTextField { |
187 return searchTextField_; | 185 return searchTextField_; |
188 } | 186 } |
189 | 187 |
190 - (NSPopUpButton*)menuControl { | 188 - (NSPopUpButton*)menuControl { |
191 return menuButton_; | 189 return menuButton_; |
192 } | 190 } |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( | 382 NSPoint anchorPoint = [[menuButton window] convertBaseToScreen:NSMakePoint( |
385 NSMaxX(anchorRect) + kMenuXOffsetFromButton, | 383 NSMaxX(anchorRect) + kMenuXOffsetFromButton, |
386 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; | 384 NSMinY(anchorRect) - kMenuYOffsetFromButton)]; |
387 NSRect confinementRect = [[menuButton window] frame]; | 385 NSRect confinementRect = [[menuButton window] frame]; |
388 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), | 386 confinementRect.size = NSMakeSize(anchorPoint.x - NSMinX(confinementRect), |
389 anchorPoint.y - NSMinY(confinementRect)); | 387 anchorPoint.y - NSMinY(confinementRect)); |
390 return confinementRect; | 388 return confinementRect; |
391 } | 389 } |
392 | 390 |
393 @end | 391 @end |
OLD | NEW |