OLD | NEW |
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" |
| 11 #include "chrome/browser/cocoa/event_utils.h" |
11 #include "chrome/browser/cocoa/nsimage_cache.h" | 12 #include "chrome/browser/cocoa/nsimage_cache.h" |
12 #import "chrome/common/cocoa_utils.h" | |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // The size delta between the font used for the edit and the result | 16 // The size delta between the font used for the edit and the result |
17 // rows. | 17 // rows. |
18 const int kEditFontAdjust = -1; | 18 const int kEditFontAdjust = -1; |
19 | 19 |
20 // How much to adjust the cell sizing up from the default determined | 20 // How much to adjust the cell sizing up from the default determined |
21 // by the font. | 21 // by the font. |
22 const int kCellHeightAdjust = 7.0; | 22 const int kCellHeightAdjust = 7.0; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 [popup_ setLevel:NSNormalWindowLevel]; | 261 [popup_ setLevel:NSNormalWindowLevel]; |
262 | 262 |
263 AutocompleteMatrix* matrix = | 263 AutocompleteMatrix* matrix = |
264 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease]; | 264 [[[AutocompleteMatrix alloc] initWithFrame:NSZeroRect] autorelease]; |
265 [matrix setTarget:matrix_target_]; | 265 [matrix setTarget:matrix_target_]; |
266 [matrix setAction:@selector(select:)]; | 266 [matrix setAction:@selector(select:)]; |
267 [popup_ setContentView:matrix]; | 267 [popup_ setContentView:matrix]; |
268 | 268 |
269 // We need the popup to follow window resize. | 269 // We need the popup to follow window resize. |
270 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; | 270 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
271 [nc addObserver:matrix_target_ | 271 [nc addObserver:matrix_target_ |
272 selector:@selector(windowDidResize:) | 272 selector:@selector(windowDidResize:) |
273 name:NSWindowDidResizeNotification | 273 name:NSWindowDidResizeNotification |
274 object:[field_ window]]; | 274 object:[field_ window]]; |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 void AutocompletePopupViewMac::UpdatePopupAppearance() { | 278 void AutocompletePopupViewMac::UpdatePopupAppearance() { |
279 const AutocompleteResult& result = model_->result(); | 279 const AutocompleteResult& result = model_->result(); |
280 if (result.empty()) { | 280 if (result.empty()) { |
281 [[popup_ parentWindow] removeChildWindow:popup_]; | 281 [[popup_ parentWindow] removeChildWindow:popup_]; |
282 [popup_ orderOut:nil]; | 282 [popup_ orderOut:nil]; |
283 | 283 |
284 // Break references to matrix_target_ before releasing popup_. | 284 // Break references to matrix_target_ before releasing popup_. |
285 NSMatrix* matrix = [popup_ contentView]; | 285 NSMatrix* matrix = [popup_ contentView]; |
286 [matrix setTarget:nil]; | 286 [matrix setTarget:nil]; |
287 | 287 |
288 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; | 288 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; |
289 [nc removeObserver:matrix_target_ | 289 [nc removeObserver:matrix_target_ |
290 name:NSWindowDidResizeNotification | 290 name:NSWindowDidResizeNotification |
291 object:[field_ window]]; | 291 object:[field_ window]]; |
292 | 292 |
293 popup_.reset(nil); | 293 popup_.reset(nil); |
294 | 294 |
295 return; | 295 return; |
296 } | 296 } |
297 | 297 |
298 CreatePopupIfNeeded(); | 298 CreatePopupIfNeeded(); |
299 | 299 |
300 // The popup's font is a slightly smaller version of what |field_| | 300 // The popup's font is a slightly smaller version of what |field_| |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void AutocompletePopupViewMac::AcceptInput() { | 373 void AutocompletePopupViewMac::AcceptInput() { |
374 const NSInteger selectedRow = [[popup_ contentView] selectedRow]; | 374 const NSInteger selectedRow = [[popup_ contentView] selectedRow]; |
375 | 375 |
376 // -1 means no cells were selected. This can happen if the user | 376 // -1 means no cells were selected. This can happen if the user |
377 // clicked and then dragged their mouse off the popup before | 377 // clicked and then dragged their mouse off the popup before |
378 // releasing, so reset the selection and ignore the event. | 378 // releasing, so reset the selection and ignore the event. |
379 if (selectedRow == -1) { | 379 if (selectedRow == -1) { |
380 PaintUpdatesNow(); | 380 PaintUpdatesNow(); |
381 } else { | 381 } else { |
382 model_->SetSelectedLine(selectedRow, false); | 382 model_->SetSelectedLine(selectedRow, false); |
383 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( | 383 WindowOpenDisposition disposition = |
384 [[NSApp currentEvent] modifierFlags]); | 384 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
385 edit_view_->AcceptInput(disposition, false); | 385 edit_view_->AcceptInput(disposition, false); |
386 } | 386 } |
387 } | 387 } |
388 | 388 |
389 @implementation AutocompleteButtonCell | 389 @implementation AutocompleteButtonCell |
390 | 390 |
391 - init { | 391 - init { |
392 self = [super init]; | 392 self = [super init]; |
393 if (self) { | 393 if (self) { |
394 [self setImagePosition:NSImageLeft]; | 394 [self setImagePosition:NSImageLeft]; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 DCHECK(popup_view_); | 579 DCHECK(popup_view_); |
580 | 580 |
581 // TODO(shess): UpdatePopupAppearance() is called frequently, so it | 581 // TODO(shess): UpdatePopupAppearance() is called frequently, so it |
582 // should be really cheap, but in this case we could probably make | 582 // should be really cheap, but in this case we could probably make |
583 // things even cheaper by refactoring between the popup-placement | 583 // things even cheaper by refactoring between the popup-placement |
584 // code and the matrix-population code. | 584 // code and the matrix-population code. |
585 popup_view_->UpdatePopupAppearance(); | 585 popup_view_->UpdatePopupAppearance(); |
586 } | 586 } |
587 | 587 |
588 @end | 588 @end |
OLD | NEW |