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

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

Issue 6252003: Accept keyword by pressing space. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_edit_view_mac.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
6 6
7 #include <Carbon/Carbon.h> // kVK_Return 7 #include <Carbon/Carbon.h> // kVK_Return
8 8
9 #include "app/mac/nsimage_cache.h" 9 #include "app/mac/nsimage_cache.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 642 }
643 643
644 bool AutocompleteEditViewMac::OnAfterPossibleChange() { 644 bool AutocompleteEditViewMac::OnAfterPossibleChange() {
645 // We should only arrive here when the field is focussed. 645 // We should only arrive here when the field is focussed.
646 DCHECK(IsFirstResponder()); 646 DCHECK(IsFirstResponder());
647 647
648 const NSRange new_selection(GetSelectedRange()); 648 const NSRange new_selection(GetSelectedRange());
649 const std::wstring new_text(GetText()); 649 const std::wstring new_text(GetText());
650 const size_t length = new_text.length(); 650 const size_t length = new_text.length();
651 651
652 const bool selection_differs = !NSEqualRanges(new_selection, 652 const bool selection_differs =
653 selection_before_change_); 653 (new_selection.length || selection_before_change_.length) &&
654 !NSEqualRanges(new_selection, selection_before_change_);
654 const bool at_end_of_edit = (length == new_selection.location); 655 const bool at_end_of_edit = (length == new_selection.location);
655 const bool text_differs = (new_text != text_before_change_) || 656 const bool text_differs = (new_text != text_before_change_) ||
656 !NSEqualRanges(marked_range_before_change_, GetMarkedRange()); 657 !NSEqualRanges(marked_range_before_change_, GetMarkedRange());
657 658
658 // When the user has deleted text, we don't allow inline 659 // When the user has deleted text, we don't allow inline
659 // autocomplete. This is assumed if the text has gotten shorter AND 660 // autocomplete. This is assumed if the text has gotten shorter AND
660 // the selection has shifted towards the front of the text. During 661 // the selection has shifted towards the front of the text. During
661 // normal typing the text will almost always be shorter (as the new 662 // normal typing the text will almost always be shorter (as the new
662 // input replaces the autocomplete suggestion), but in that case the 663 // input replaces the autocomplete suggestion), but in that case the
663 // selection point will have moved towards the end of the text. 664 // selection point will have moved towards the end of the text.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 model_->OnUpOrDownKeyPressed(-model_->result().size()); 805 model_->OnUpOrDownKeyPressed(-model_->result().size());
805 return true; 806 return true;
806 } 807 }
807 808
808 if (cmd == @selector(cancelOperation:)) { 809 if (cmd == @selector(cancelOperation:)) {
809 return model_->OnEscapeKeyPressed(); 810 return model_->OnEscapeKeyPressed();
810 } 811 }
811 812
812 if (cmd == @selector(insertTab:) || 813 if (cmd == @selector(insertTab:) ||
813 cmd == @selector(insertTabIgnoringFieldEditor:)) { 814 cmd == @selector(insertTabIgnoringFieldEditor:)) {
814 if (model_->is_keyword_hint() && !model_->keyword().empty()) { 815 if (model_->is_keyword_hint() && controller_->IsKeywordHintVisible()) {
815 model_->AcceptKeyword(); 816 model_->AcceptKeyword();
816 return true; 817 return true;
817 } 818 }
818 819
819 if (suggest_text_length_ > 0) { 820 if (suggest_text_length_ > 0) {
820 controller_->OnCommitSuggestedText(GetText()); 821 controller_->OnCommitSuggestedText(GetText());
821 return true; 822 return true;
822 } 823 }
823 824
824 if (controller_->AcceptCurrentInstantPreview()) 825 if (controller_->AcceptCurrentInstantPreview())
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 // NSTextView as things you need to do if you write additional 936 // NSTextView as things you need to do if you write additional
936 // user-initiated editing functions. They cause the appropriate 937 // user-initiated editing functions. They cause the appropriate
937 // delegate methods to be called. 938 // delegate methods to be called.
938 // TODO(shess): It would be nice to separate the Cocoa-specific code 939 // TODO(shess): It would be nice to separate the Cocoa-specific code
939 // from the Chrome-specific code. 940 // from the Chrome-specific code.
940 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); 941 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]);
941 const NSRange selectedRange = GetSelectedRange(); 942 const NSRange selectedRange = GetSelectedRange();
942 if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) { 943 if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) {
943 // If this paste will be replacing all the text, record that, so 944 // If this paste will be replacing all the text, record that, so
944 // we can do different behaviors in such a case. 945 // we can do different behaviors in such a case.
945 if (IsSelectAll()) 946 model_->OnPaste(IsSelectAll());
946 model_->on_paste_replacing_all();
947 947
948 // Force a Paste operation to trigger the text_changed code in 948 // Force a Paste operation to trigger the text_changed code in
949 // OnAfterPossibleChange(), even if identical contents are pasted 949 // OnAfterPossibleChange(), even if identical contents are pasted
950 // into the text box. 950 // into the text box.
951 text_before_change_.clear(); 951 text_before_change_.clear();
952 952
953 [editor replaceCharactersInRange:selectedRange withString:s]; 953 [editor replaceCharactersInRange:selectedRange withString:s];
954 [editor didChangeText]; 954 [editor didChangeText];
955 } 955 }
956 } 956 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 } 1091 }
1092 1092
1093 return std::wstring(); 1093 return std::wstring();
1094 } 1094 }
1095 1095
1096 // static 1096 // static
1097 NSFont* AutocompleteEditViewMac::GetFieldFont() { 1097 NSFont* AutocompleteEditViewMac::GetFieldFont() {
1098 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1098 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1099 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont(); 1099 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont();
1100 } 1100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698