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

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

Issue 6685002: Wires up ability for page to specify instant auto complete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test and stray char Created 9 years, 9 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 "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 suggest_text_length_ = 0; 597 suggest_text_length_ = 0;
598 SetWindowTextAndCaretPos(display_text, display_text.size()); 598 SetWindowTextAndCaretPos(display_text, display_text.size());
599 model_->OnChanged(); 599 model_->OnChanged();
600 [field_ clearUndoChain]; 600 [field_ clearUndoChain];
601 } 601 }
602 602
603 void AutocompleteEditViewMac::OnStartingIME() { 603 void AutocompleteEditViewMac::OnStartingIME() {
604 // Reset the suggest text just before starting an IME composition session, 604 // Reset the suggest text just before starting an IME composition session,
605 // otherwise the IME composition may be interrupted when the suggest text 605 // otherwise the IME composition may be interrupted when the suggest text
606 // gets reset by the IME composition change. 606 // gets reset by the IME composition change.
607 SetInstantSuggestion(string16()); 607 SetInstantSuggestion(string16(), false);
608 } 608 }
609 609
610 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( 610 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged(
611 const string16& display_text, size_t user_text_length) { 611 const string16& display_text, size_t user_text_length) {
612 // TODO(shess): Make sure that this actually works. The round trip 612 // TODO(shess): Make sure that this actually works. The round trip
613 // to native form and back may mean that it's the same but not the 613 // to native form and back may mean that it's the same but not the
614 // same. 614 // same.
615 if (display_text == GetText()) 615 if (display_text == GetText())
616 return false; 616 return false;
617 617
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 696
697 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const { 697 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const {
698 return field_; 698 return field_;
699 } 699 }
700 700
701 CommandUpdater* AutocompleteEditViewMac::GetCommandUpdater() { 701 CommandUpdater* AutocompleteEditViewMac::GetCommandUpdater() {
702 return command_updater_; 702 return command_updater_;
703 } 703 }
704 704
705 void AutocompleteEditViewMac::SetInstantSuggestion( 705 void AutocompleteEditViewMac::SetInstantSuggestion(
706 const string16& suggest_text) { 706 const string16& suggest_text,
707 bool animate_to_complete) {
707 NSString* text = GetNonSuggestTextSubstring(); 708 NSString* text = GetNonSuggestTextSubstring();
708 bool needs_update = (suggest_text_length_ > 0); 709 bool needs_update = (suggest_text_length_ > 0);
709 710
710 // Append the new suggest text. 711 // Append the new suggest text.
711 suggest_text_length_ = suggest_text.length(); 712 suggest_text_length_ = suggest_text.length();
712 if (suggest_text_length_ > 0) { 713 if (suggest_text_length_ > 0) {
713 text = [text stringByAppendingString:base::SysUTF16ToNSString( 714 text = [text stringByAppendingString:base::SysUTF16ToNSString(
714 suggest_text)]; 715 suggest_text)];
715 needs_update = true; 716 needs_update = true;
716 } 717 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) { 763 bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) {
763 // We should only arrive here when the field is focussed. 764 // We should only arrive here when the field is focussed.
764 DCHECK(IsFirstResponder()); 765 DCHECK(IsFirstResponder());
765 766
766 if (cmd != @selector(moveRight:) && 767 if (cmd != @selector(moveRight:) &&
767 cmd != @selector(insertTab:) && 768 cmd != @selector(insertTab:) &&
768 cmd != @selector(insertTabIgnoringFieldEditor:)) { 769 cmd != @selector(insertTabIgnoringFieldEditor:)) {
769 // Reset the suggest text for any change other than key right or tab. 770 // Reset the suggest text for any change other than key right or tab.
770 // TODO(rohitrao): This is here to prevent complications when editing text. 771 // TODO(rohitrao): This is here to prevent complications when editing text.
771 // See if this can be removed. 772 // See if this can be removed.
772 SetInstantSuggestion(string16()); 773 SetInstantSuggestion(string16(), false);
773 } 774 }
774 775
775 if (cmd == @selector(deleteForward:)) 776 if (cmd == @selector(deleteForward:))
776 delete_was_pressed_ = true; 777 delete_was_pressed_ = true;
777 778
778 // Don't intercept up/down-arrow if the popup isn't open. 779 // Don't intercept up/down-arrow if the popup isn't open.
779 if (popup_view_->IsOpen()) { 780 if (popup_view_->IsOpen()) {
780 if (cmd == @selector(moveDown:)) { 781 if (cmd == @selector(moveDown:)) {
781 model_->OnUpOrDownKeyPressed(1); 782 model_->OnUpOrDownKeyPressed(1);
782 return true; 783 return true;
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 1110
1110 void AutocompleteEditViewMac::PlaceCaretAt(NSUInteger pos) { 1111 void AutocompleteEditViewMac::PlaceCaretAt(NSUInteger pos) {
1111 DCHECK(pos <= GetTextLength()); 1112 DCHECK(pos <= GetTextLength());
1112 SetSelectedRange(NSMakeRange(pos, pos)); 1113 SetSelectedRange(NSMakeRange(pos, pos));
1113 } 1114 }
1114 1115
1115 bool AutocompleteEditViewMac::IsCaretAtEnd() const { 1116 bool AutocompleteEditViewMac::IsCaretAtEnd() const {
1116 const NSRange selection = GetSelectedRange(); 1117 const NSRange selection = GetSelectedRange();
1117 return selection.length == 0 && selection.location == GetTextLength(); 1118 return selection.length == 0 && selection.location == GetTextLength();
1118 } 1119 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698