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

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: Only allow 0x0020 and 0x3000 for now. 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 } 641 }
642 642
643 bool AutocompleteEditViewMac::OnAfterPossibleChange() { 643 bool AutocompleteEditViewMac::OnAfterPossibleChange() {
644 // We should only arrive here when the field is focussed. 644 // We should only arrive here when the field is focussed.
645 DCHECK(IsFirstResponder()); 645 DCHECK(IsFirstResponder());
646 646
647 const NSRange new_selection(GetSelectedRange()); 647 const NSRange new_selection(GetSelectedRange());
648 const std::wstring new_text(GetText()); 648 const std::wstring new_text(GetText());
649 const size_t length = new_text.length(); 649 const size_t length = new_text.length();
650 650
651 const bool selection_differs = !NSEqualRanges(new_selection, 651 const bool selection_differs =
652 selection_before_change_); 652 (new_selection.length || selection_before_change_.length) &&
653 !NSEqualRanges(new_selection, selection_before_change_);
653 const bool at_end_of_edit = (length == new_selection.location); 654 const bool at_end_of_edit = (length == new_selection.location);
654 const bool text_differs = (new_text != text_before_change_) || 655 const bool text_differs = (new_text != text_before_change_) ||
655 !NSEqualRanges(marked_range_before_change_, GetMarkedRange()); 656 !NSEqualRanges(marked_range_before_change_, GetMarkedRange());
656 657
657 // When the user has deleted text, we don't allow inline 658 // When the user has deleted text, we don't allow inline
658 // autocomplete. This is assumed if the text has gotten shorter AND 659 // autocomplete. This is assumed if the text has gotten shorter AND
659 // the selection has shifted towards the front of the text. During 660 // the selection has shifted towards the front of the text. During
660 // normal typing the text will almost always be shorter (as the new 661 // normal typing the text will almost always be shorter (as the new
661 // input replaces the autocomplete suggestion), but in that case the 662 // input replaces the autocomplete suggestion), but in that case the
662 // selection point will have moved towards the end of the text. 663 // selection point will have moved towards the end of the text.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 model_->OnUpOrDownKeyPressed(-model_->result().size()); 804 model_->OnUpOrDownKeyPressed(-model_->result().size());
804 return true; 805 return true;
805 } 806 }
806 807
807 if (cmd == @selector(cancelOperation:)) { 808 if (cmd == @selector(cancelOperation:)) {
808 return model_->OnEscapeKeyPressed(); 809 return model_->OnEscapeKeyPressed();
809 } 810 }
810 811
811 if (cmd == @selector(insertTab:) || 812 if (cmd == @selector(insertTab:) ||
812 cmd == @selector(insertTabIgnoringFieldEditor:)) { 813 cmd == @selector(insertTabIgnoringFieldEditor:)) {
813 if (model_->is_keyword_hint() && !model_->keyword().empty()) { 814 if (model_->is_keyword_hint())
814 model_->AcceptKeyword(); 815 return model_->AcceptKeyword();
815 return true;
816 }
817 816
818 if (suggest_text_length_ > 0) { 817 if (suggest_text_length_ > 0) {
819 controller_->OnCommitSuggestedText(GetText()); 818 controller_->OnCommitSuggestedText(GetText());
820 return true; 819 return true;
821 } 820 }
822 821
823 if (controller_->AcceptCurrentInstantPreview()) 822 if (controller_->AcceptCurrentInstantPreview())
824 return true; 823 return true;
825 } 824 }
826 825
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 931
933 // -shouldChangeTextInRange:* and -didChangeText are documented in 932 // -shouldChangeTextInRange:* and -didChangeText are documented in
934 // NSTextView as things you need to do if you write additional 933 // NSTextView as things you need to do if you write additional
935 // user-initiated editing functions. They cause the appropriate 934 // user-initiated editing functions. They cause the appropriate
936 // delegate methods to be called. 935 // delegate methods to be called.
937 // TODO(shess): It would be nice to separate the Cocoa-specific code 936 // TODO(shess): It would be nice to separate the Cocoa-specific code
938 // from the Chrome-specific code. 937 // from the Chrome-specific code.
939 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]); 938 NSTextView* editor = static_cast<NSTextView*>([field_ currentEditor]);
940 const NSRange selectedRange = GetSelectedRange(); 939 const NSRange selectedRange = GetSelectedRange();
941 if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) { 940 if ([editor shouldChangeTextInRange:selectedRange replacementString:s]) {
942 // If this paste will be replacing all the text, record that, so 941 // Record this paste, so we can do different behavior.
943 // we can do different behaviors in such a case. 942 model_->on_paste();
944 if (IsSelectAll())
945 model_->on_paste_replacing_all();
946 943
947 // Force a Paste operation to trigger the text_changed code in 944 // Force a Paste operation to trigger the text_changed code in
948 // OnAfterPossibleChange(), even if identical contents are pasted 945 // OnAfterPossibleChange(), even if identical contents are pasted
949 // into the text box. 946 // into the text box.
950 text_before_change_.clear(); 947 text_before_change_.clear();
951 948
952 [editor replaceCharactersInRange:selectedRange withString:s]; 949 [editor replaceCharactersInRange:selectedRange withString:s];
953 [editor didChangeText]; 950 [editor didChangeText];
954 } 951 }
955 } 952 }
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 } 1087 }
1091 1088
1092 return std::wstring(); 1089 return std::wstring();
1093 } 1090 }
1094 1091
1095 // static 1092 // static
1096 NSFont* AutocompleteEditViewMac::GetFieldFont() { 1093 NSFont* AutocompleteEditViewMac::GetFieldFont() {
1097 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 1094 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
1098 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont(); 1095 return rb.GetFont(ResourceBundle::BaseFont).GetNativeFont();
1099 } 1096 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_gtk.cc ('k') | chrome/browser/autocomplete/autocomplete_edit_view_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698