Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_popup_view_mac.mm

Issue 165332: Mac: Make autocomplete popup track autocomplete field resizes. (Closed)
Patch Set: Oops, was unregistering for the wrong notification. Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
6 6
7 #include "base/sys_string_conversions.h" 7 #include "base/sys_string_conversions.h"
8 #include "chrome/browser/autocomplete/autocomplete_edit.h" 8 #include "chrome/browser/autocomplete/autocomplete_edit.h"
9 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h" 9 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 10 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // directly. 183 // directly.
184 184
185 @interface AutocompleteMatrixTarget : NSObject { 185 @interface AutocompleteMatrixTarget : NSObject {
186 @private 186 @private
187 AutocompletePopupViewMac* popup_view_; // weak, owns us. 187 AutocompletePopupViewMac* popup_view_; // weak, owns us.
188 } 188 }
189 - initWithPopupView:(AutocompletePopupViewMac*)view; 189 - initWithPopupView:(AutocompletePopupViewMac*)view;
190 190
191 // Tell popup model via popup_view_ about the selected row. 191 // Tell popup model via popup_view_ about the selected row.
192 - (void)select:sender; 192 - (void)select:sender;
193
194 // Resize the popup when the field's window resizes.
195 - (void)windowDidResize:(NSNotification*)notification;
196
193 @end 197 @end
194 198
195 AutocompletePopupViewMac::AutocompletePopupViewMac( 199 AutocompletePopupViewMac::AutocompletePopupViewMac(
196 AutocompleteEditViewMac* edit_view, 200 AutocompleteEditViewMac* edit_view,
197 AutocompleteEditModel* edit_model, 201 AutocompleteEditModel* edit_model,
198 Profile* profile, 202 Profile* profile,
199 NSTextField* field) 203 NSTextField* field)
200 : model_(new AutocompletePopupModel(this, edit_model, profile)), 204 : model_(new AutocompletePopupModel(this, edit_model, profile)),
201 edit_view_(edit_view), 205 edit_view_(edit_view),
202 field_(field), 206 field_(field),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 [popup_ setMovableByWindowBackground:NO]; 238 [popup_ setMovableByWindowBackground:NO];
235 [popup_ setOpaque:YES]; 239 [popup_ setOpaque:YES];
236 [popup_ setHasShadow:YES]; 240 [popup_ setHasShadow:YES];
237 [popup_ setLevel:NSNormalWindowLevel]; 241 [popup_ setLevel:NSNormalWindowLevel];
238 242
239 AutocompleteMatrix* matrix = 243 AutocompleteMatrix* matrix =
240 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease]; 244 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease];
241 [matrix setTarget:matrix_target_]; 245 [matrix setTarget:matrix_target_];
242 [matrix setAction:@selector(select:)]; 246 [matrix setAction:@selector(select:)];
243 [popup_ setContentView:matrix]; 247 [popup_ setContentView:matrix];
248
249 // We need the popup to follow window resize.
250 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
251 [nc addObserver:matrix_target_
252 selector:@selector(windowDidResize:)
253 name:NSWindowDidResizeNotification
254 object:[field_ window]];
244 } 255 }
245 } 256 }
246 257
247 void AutocompletePopupViewMac::UpdatePopupAppearance() { 258 void AutocompletePopupViewMac::UpdatePopupAppearance() {
248 const AutocompleteResult& result = model_->result(); 259 const AutocompleteResult& result = model_->result();
249 if (result.empty()) { 260 if (result.empty()) {
250 [[popup_ parentWindow] removeChildWindow:popup_]; 261 [[popup_ parentWindow] removeChildWindow:popup_];
251 [popup_ orderOut:nil]; 262 [popup_ orderOut:nil];
252 263
253 // Break references to matrix_target_ before releasing popup_. 264 // Break references to matrix_target_ before releasing popup_.
254 NSMatrix* matrix = [popup_ contentView]; 265 NSMatrix* matrix = [popup_ contentView];
255 [matrix setTarget:nil]; 266 [matrix setTarget:nil];
256 267
268 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
269 [nc removeObserver:matrix_target_
270 name:NSWindowDidResizeNotification
271 object:[field_ window]];
272
257 popup_.reset(nil); 273 popup_.reset(nil);
258 274
259 return; 275 return;
260 } 276 }
261 277
262 CreatePopupIfNeeded(); 278 CreatePopupIfNeeded();
263 279
264 // Load the results into the popup's matrix. 280 // Load the results into the popup's matrix.
265 AutocompleteMatrix* matrix = [popup_ contentView]; 281 AutocompleteMatrix* matrix = [popup_ contentView];
266 const size_t rows = model_->result().size(); 282 const size_t rows = model_->result().size();
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 popup_view_ = view; 464 popup_view_ = view;
449 } 465 }
450 return self; 466 return self;
451 } 467 }
452 468
453 - (void)select:sender { 469 - (void)select:sender {
454 DCHECK(popup_view_); 470 DCHECK(popup_view_);
455 popup_view_->AcceptInput(); 471 popup_view_->AcceptInput();
456 } 472 }
457 473
474 - (void)windowDidResize:(NSNotification*)notification {
475 DCHECK(popup_view_);
476
477 // TODO(shess): UpdatePopupAppearance() is called frequently, so it
478 // should be really cheap, but in this case we could probably make
479 // things even cheaper by refactoring between the popup-placement
480 // code and the matrix-population code.
481 popup_view_->UpdatePopupAppearance();
482 }
483
458 @end 484 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698