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 "app/gfx/text_elider.h" | 7 #include "app/gfx/text_elider.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 // everything. Popup should already be visible. | 447 // everything. Popup should already be visible. |
448 void AutocompletePopupViewMac::PaintUpdatesNow() { | 448 void AutocompletePopupViewMac::PaintUpdatesNow() { |
449 AutocompleteMatrix* matrix = [popup_ contentView]; | 449 AutocompleteMatrix* matrix = [popup_ contentView]; |
450 [matrix selectCellAtRow:model_->selected_line() column:0]; | 450 [matrix selectCellAtRow:model_->selected_line() column:0]; |
451 } | 451 } |
452 | 452 |
453 AutocompletePopupModel* AutocompletePopupViewMac::GetModel() { | 453 AutocompletePopupModel* AutocompletePopupViewMac::GetModel() { |
454 return model_.get(); | 454 return model_.get(); |
455 } | 455 } |
456 | 456 |
457 void AutocompletePopupViewMac::AcceptInput() { | 457 void AutocompletePopupViewMac::OnClick() { |
458 const NSInteger selectedRow = [[popup_ contentView] selectedRow]; | 458 const NSInteger selectedRow = [[popup_ contentView] selectedRow]; |
459 | 459 |
460 // -1 means no cells were selected. This can happen if the user | 460 // -1 means no cells were selected. This can happen if the user |
461 // clicked and then dragged their mouse off the popup before | 461 // clicked and then dragged their mouse off the popup before |
462 // releasing, so reset the selection and ignore the event. | 462 // releasing, so reset the selection and ignore the event. |
463 if (selectedRow == -1) { | 463 if (selectedRow == -1) { |
464 PaintUpdatesNow(); | 464 PaintUpdatesNow(); |
465 } else { | 465 } else { |
466 model_->SetSelectedLine(selectedRow, false); | 466 OpenURLForRow(selectedRow, false); |
467 WindowOpenDisposition disposition = | |
468 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); | |
469 edit_view_->AcceptInput(disposition, false); | |
470 } | 467 } |
471 } | 468 } |
472 | 469 |
473 void AutocompletePopupViewMac::OnMiddleClick() { | 470 void AutocompletePopupViewMac::OnMiddleClick() { |
474 const NSInteger row = [[popup_ contentView] highlightedRow]; | 471 OpenURLForRow([[popup_ contentView] highlightedRow], true); |
| 472 } |
| 473 |
| 474 void AutocompletePopupViewMac::OpenURLForRow(int row, bool force_background) { |
475 if (row == -1) { | 475 if (row == -1) { |
476 return; | 476 return; |
477 } | 477 } |
478 | 478 |
| 479 WindowOpenDisposition disposition = NEW_BACKGROUND_TAB; |
| 480 if (!force_background) { |
| 481 disposition = |
| 482 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
| 483 } |
| 484 |
479 // OpenURL() may close the popup, which will clear the result set | 485 // OpenURL() may close the popup, which will clear the result set |
480 // and, by extension, |match| and its contents. So copy the | 486 // and, by extension, |match| and its contents. So copy the |
481 // relevant strings out to make sure they stay alive until the call | 487 // relevant strings out to make sure they stay alive until the call |
482 // completes. | 488 // completes. |
483 const AutocompleteMatch& match = model_->result().match_at(row); | 489 const AutocompleteMatch& match = model_->result().match_at(row); |
484 const GURL url(match.destination_url); | 490 const GURL url(match.destination_url); |
485 std::wstring keyword; | 491 std::wstring keyword; |
486 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); | 492 const bool is_keyword_hint = model_->GetKeywordForMatch(match, &keyword); |
487 edit_view_->OpenURL(url, NEW_BACKGROUND_TAB, match.transition, GURL(), row, | 493 edit_view_->OpenURL(url, disposition, match.transition, GURL(), row, |
488 is_keyword_hint ? std::wstring() : keyword); | 494 is_keyword_hint ? std::wstring() : keyword); |
489 } | 495 } |
490 | 496 |
491 @implementation AutocompleteButtonCell | 497 @implementation AutocompleteButtonCell |
492 | 498 |
493 - init { | 499 - init { |
494 self = [super init]; | 500 self = [super init]; |
495 if (self) { | 501 if (self) { |
496 [self setImagePosition:NSImageLeft]; | 502 [self setImagePosition:NSImageLeft]; |
497 [self setBordered:NO]; | 503 [self setBordered:NO]; |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 return self; | 712 return self; |
707 } | 713 } |
708 | 714 |
709 - (void)dealloc { | 715 - (void)dealloc { |
710 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 716 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
711 [super dealloc]; | 717 [super dealloc]; |
712 } | 718 } |
713 | 719 |
714 - (void)select:(id)sender { | 720 - (void)select:(id)sender { |
715 DCHECK(popup_view_); | 721 DCHECK(popup_view_); |
716 popup_view_->AcceptInput(); | 722 popup_view_->OnClick(); |
717 } | 723 } |
718 | 724 |
719 - (void)middleSelect:(id)sender { | 725 - (void)middleSelect:(id)sender { |
720 DCHECK(popup_view_); | 726 DCHECK(popup_view_); |
721 popup_view_->OnMiddleClick(); | 727 popup_view_->OnMiddleClick(); |
722 } | 728 } |
723 | 729 |
724 @end | 730 @end |
OLD | NEW |