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

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

Issue 180009: [Mac] Handle backspacing out of keyword search. (Closed)
Patch Set: Consistent initializer per Rohit. Created 11 years, 3 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
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_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 #include "app/gfx/font.h" 8 #include "app/gfx/font.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/clipboard.h" 10 #include "base/clipboard.h"
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 } 623 }
624 624
625 bool AutocompleteEditViewMac::OnTabPressed() { 625 bool AutocompleteEditViewMac::OnTabPressed() {
626 if (model_->is_keyword_hint() && !model_->keyword().empty()) { 626 if (model_->is_keyword_hint() && !model_->keyword().empty()) {
627 model_->AcceptKeyword(); 627 model_->AcceptKeyword();
628 return true; 628 return true;
629 } 629 }
630 return false; 630 return false;
631 } 631 }
632 632
633 bool AutocompleteEditViewMac::OnBackspacePressed() {
634 // Don't intercept if not in keyword search mode.
635 if (model_->is_keyword_hint() || model_->keyword().empty()) {
636 return false;
637 }
638
639 // Don't intercept if there is a selection, or the cursor isn't at
640 // the leftmost position.
641 const NSRange selection = GetSelectedRange();
642 if (selection.length > 0 || selection.location > 0) {
643 return false;
644 }
645
646 // We're showing a keyword and the user pressed backspace at the
647 // beginning of the text. Delete the selected keyword.
648 model_->ClearKeyword(GetText());
649 return true;
650 }
651
633 bool AutocompleteEditViewMac::IsPopupOpen() const { 652 bool AutocompleteEditViewMac::IsPopupOpen() const {
634 return popup_view_->IsOpen(); 653 return popup_view_->IsOpen();
635 } 654 }
636 655
637 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) { 656 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) {
638 model_->OnControlKeyChanged(pressed); 657 model_->OnControlKeyChanged(pressed);
639 } 658 }
640 659
641 void AutocompleteEditViewMac::AcceptInput( 660 void AutocompleteEditViewMac::AcceptInput(
642 WindowOpenDisposition disposition, bool for_drop) { 661 WindowOpenDisposition disposition, bool for_drop) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 // received notification when the Control key was depressed, but it 769 // received notification when the Control key was depressed, but it
751 // is safe to tell it twice. 770 // is safe to tell it twice.
752 if (cmd == @selector(insertLineBreak:)) { 771 if (cmd == @selector(insertLineBreak:)) {
753 edit_view_->OnControlKeyChanged(true); 772 edit_view_->OnControlKeyChanged(true);
754 WindowOpenDisposition disposition = 773 WindowOpenDisposition disposition =
755 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); 774 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]);
756 edit_view_->AcceptInput(disposition, false); 775 edit_view_->AcceptInput(disposition, false);
757 return YES; 776 return YES;
758 } 777 }
759 778
779 if (cmd == @selector(deleteBackward:)) {
780 if (edit_view_->OnBackspacePressed()) {
781 return YES;
782 }
783 }
784
760 // Capture the state before the operation changes the content. 785 // Capture the state before the operation changes the content.
761 // TODO(shess): Determine if this is always redundent WRT the call 786 // TODO(shess): Determine if this is always redundent WRT the call
762 // in -controlTextDidChange:. 787 // in -controlTextDidChange:.
763 edit_view_->OnBeforePossibleChange(); 788 edit_view_->OnBeforePossibleChange();
764 return NO; 789 return NO;
765 } 790 }
766 791
767 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification { 792 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification {
768 edit_view_->OnWillBeginEditing(); 793 edit_view_->OnWillBeginEditing();
769 } 794 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 // prepended and ".com" appended. This calls down to 831 // prepended and ".com" appended. This calls down to
807 // AutocompleteEditModel::OnControlKeyChanged() so that it can change 832 // AutocompleteEditModel::OnControlKeyChanged() so that it can change
808 // the popup to reflect this. See autocomplete_edit.cc 833 // the popup to reflect this. See autocomplete_edit.cc
809 // OnControlKeyChanged() and OnAfterPossibleChange(). 834 // OnControlKeyChanged() and OnAfterPossibleChange().
810 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { 835 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent {
811 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; 836 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0;
812 edit_view_->OnControlKeyChanged(controlFlag); 837 edit_view_->OnControlKeyChanged(controlFlag);
813 } 838 }
814 839
815 @end 840 @end
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698