OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/cocoa/omnibox/omnibox_view_mac.h" | 5 #include "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> // kVK_Return | 7 #include <Carbon/Carbon.h> // kVK_Return |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 cmd != @selector(insertTabIgnoringFieldEditor:)) { | 698 cmd != @selector(insertTabIgnoringFieldEditor:)) { |
699 // Reset the suggest text for any change other than key right or tab. | 699 // Reset the suggest text for any change other than key right or tab. |
700 // TODO(rohitrao): This is here to prevent complications when editing text. | 700 // TODO(rohitrao): This is here to prevent complications when editing text. |
701 // See if this can be removed. | 701 // See if this can be removed. |
702 SetInstantSuggestion(string16()); | 702 SetInstantSuggestion(string16()); |
703 } | 703 } |
704 | 704 |
705 if (cmd == @selector(deleteForward:)) | 705 if (cmd == @selector(deleteForward:)) |
706 delete_was_pressed_ = true; | 706 delete_was_pressed_ = true; |
707 | 707 |
708 // Don't intercept up/down-arrow or backtab if the popup isn't open. | 708 if (cmd == @selector(moveDown:)) { |
| 709 model()->OnUpOrDownKeyPressed(1); |
| 710 return true; |
| 711 } |
| 712 |
| 713 if (cmd == @selector(moveUp:)) { |
| 714 model()->OnUpOrDownKeyPressed(-1); |
| 715 return true; |
| 716 } |
| 717 |
709 if (model()->popup_model()->IsOpen()) { | 718 if (model()->popup_model()->IsOpen()) { |
710 if (cmd == @selector(moveDown:)) { | 719 // If instant extended is enabled then allow users to press tab to select |
711 model()->OnUpOrDownKeyPressed(1); | 720 // results from the omnibox popup. |
712 return true; | |
713 } | |
714 | |
715 if (cmd == @selector(moveUp:)) { | |
716 model()->OnUpOrDownKeyPressed(-1); | |
717 return true; | |
718 } | |
719 | |
720 // If instant extended is then allow users to press tab to select results | |
721 // from the omnibox popup. | |
722 BOOL enableTabAutocomplete = | 721 BOOL enableTabAutocomplete = |
723 chrome::search::IsInstantExtendedAPIEnabled(model()->profile()); | 722 chrome::search::IsInstantExtendedAPIEnabled(model()->profile()); |
724 | 723 |
725 if (cmd == @selector(insertBacktab:)) { | 724 if (cmd == @selector(insertBacktab:)) { |
726 if (model()->popup_model()->selected_line_state() == | 725 if (model()->popup_model()->selected_line_state() == |
727 OmniboxPopupModel::KEYWORD) { | 726 OmniboxPopupModel::KEYWORD) { |
728 model()->ClearKeyword(GetText()); | 727 model()->ClearKeyword(GetText()); |
729 return true; | 728 return true; |
730 } else if (enableTabAutocomplete) { | 729 } else if (enableTabAutocomplete) { |
731 model()->OnUpOrDownKeyPressed(-1); | 730 model()->OnUpOrDownKeyPressed(-1); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 NSUInteger OmniboxViewMac::GetTextLength() const { | 1038 NSUInteger OmniboxViewMac::GetTextLength() const { |
1040 return ([field_ currentEditor] ? | 1039 return ([field_ currentEditor] ? |
1041 [[[field_ currentEditor] string] length] : | 1040 [[[field_ currentEditor] string] length] : |
1042 [[field_ stringValue] length]) - suggest_text_length_; | 1041 [[field_ stringValue] length]) - suggest_text_length_; |
1043 } | 1042 } |
1044 | 1043 |
1045 bool OmniboxViewMac::IsCaretAtEnd() const { | 1044 bool OmniboxViewMac::IsCaretAtEnd() const { |
1046 const NSRange selection = GetSelectedRange(); | 1045 const NSRange selection = GetSelectedRange(); |
1047 return selection.length == 0 && selection.location == GetTextLength(); | 1046 return selection.length == 0 && selection.location == GetTextLength(); |
1048 } | 1047 } |
OLD | NEW |