OLD | NEW |
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 "base/clipboard.h" | 7 #include "base/clipboard.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
10 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 10 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
(...skipping 561 matching lines...) Loading... |
572 // OnAfterPossibleChange(), even if identical contents are pasted into the | 572 // OnAfterPossibleChange(), even if identical contents are pasted into the |
573 // text box. | 573 // text box. |
574 text_before_change_.clear(); | 574 text_before_change_.clear(); |
575 | 575 |
576 NSString* s = base::SysWideToNSString(text); | 576 NSString* s = base::SysWideToNSString(text); |
577 [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s]; | 577 [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s]; |
578 | 578 |
579 OnAfterPossibleChange(); | 579 OnAfterPossibleChange(); |
580 } | 580 } |
581 | 581 |
| 582 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) { |
| 583 model_->OnControlKeyChanged(pressed); |
| 584 } |
| 585 |
582 void AutocompleteEditViewMac::AcceptInput( | 586 void AutocompleteEditViewMac::AcceptInput( |
583 WindowOpenDisposition disposition, bool for_drop) { | 587 WindowOpenDisposition disposition, bool for_drop) { |
584 model_->AcceptInput(disposition, for_drop); | 588 model_->AcceptInput(disposition, for_drop); |
585 } | 589 } |
586 | 590 |
587 void AutocompleteEditViewMac::FocusLocation() { | 591 void AutocompleteEditViewMac::FocusLocation() { |
588 [[field_ window] makeFirstResponder:field_]; | 592 [[field_ window] makeFirstResponder:field_]; |
589 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); | 593 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); |
590 } | 594 } |
591 | 595 |
(...skipping 72 matching lines...) Loading... |
664 if (cmd == @selector(cancelOperation:)) { | 668 if (cmd == @selector(cancelOperation:)) { |
665 edit_view_->OnEscapeKeyPressed(); | 669 edit_view_->OnEscapeKeyPressed(); |
666 return YES; | 670 return YES; |
667 } | 671 } |
668 | 672 |
669 if (cmd == @selector(insertNewline:)) { | 673 if (cmd == @selector(insertNewline:)) { |
670 edit_view_->AcceptInput(CURRENT_TAB, false); | 674 edit_view_->AcceptInput(CURRENT_TAB, false); |
671 return YES; | 675 return YES; |
672 } | 676 } |
673 | 677 |
| 678 // When the user does Control-Enter, the existing content has "www." |
| 679 // prepended and ".com" appended. |model_| should already have |
| 680 // received notification when the Control key was depressed, but it |
| 681 // is safe to tell it twice. |
| 682 if (cmd == @selector(insertLineBreak:)) { |
| 683 edit_view_->OnControlKeyChanged(true); |
| 684 edit_view_->AcceptInput(CURRENT_TAB, false); |
| 685 return YES; |
| 686 } |
| 687 |
674 // Capture the state before the operation changes the content. | 688 // Capture the state before the operation changes the content. |
675 // TODO(shess): Determine if this is always redundent WRT the call | 689 // TODO(shess): Determine if this is always redundent WRT the call |
676 // in -controlTextDidChange:. | 690 // in -controlTextDidChange:. |
677 edit_view_->OnBeforePossibleChange(); | 691 edit_view_->OnBeforePossibleChange(); |
678 return NO; | 692 return NO; |
679 } | 693 } |
680 | 694 |
681 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification { | 695 - (void)controlTextDidBeginEditing:(NSNotification*)aNotification { |
682 edit_view_->OnWillBeginEditing(); | 696 edit_view_->OnWillBeginEditing(); |
683 } | 697 } |
684 | 698 |
685 - (void)controlTextDidChange:(NSNotification*)aNotification { | 699 - (void)controlTextDidChange:(NSNotification*)aNotification { |
686 // Figure out what changed and notify the model_. | 700 // Figure out what changed and notify the model_. |
687 edit_view_->OnAfterPossibleChange(); | 701 edit_view_->OnAfterPossibleChange(); |
688 | 702 |
689 // Then capture the new state. | 703 // Then capture the new state. |
690 edit_view_->OnBeforePossibleChange(); | 704 edit_view_->OnBeforePossibleChange(); |
691 } | 705 } |
692 | 706 |
693 - (BOOL)control:(NSControl*)control textShouldEndEditing:(NSText*)fieldEditor { | 707 - (BOOL)control:(NSControl*)control textShouldEndEditing:(NSText*)fieldEditor { |
694 edit_view_->OnDidEndEditing(); | 708 edit_view_->OnDidEndEditing(); |
695 | 709 |
696 return YES; | 710 return YES; |
697 | 711 |
698 // TODO(shess): Figure out where the selection belongs. On GTK, | 712 // TODO(shess): Figure out where the selection belongs. On GTK, |
699 // it's set to the start of the text. | 713 // it's set to the start of the text. |
700 } | 714 } |
701 | 715 |
| 716 // AutocompleteTextField/Editor adds a delegate method which allows us |
| 717 // to intercept and handle -paste: calls. |
702 - (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor { | 718 - (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor { |
703 edit_view_->OnPaste(); | 719 edit_view_->OnPaste(); |
704 | 720 |
705 // Caller shouldn't also paste. | 721 // Caller shouldn't also paste. |
706 return NO; | 722 return NO; |
707 } | 723 } |
708 | 724 |
709 // Signal that we've lost focus when the window resigns key. | 725 // Signal that we've lost focus when the window resigns key. |
710 - (void)windowDidResignKey:(NSNotification*)notification { | 726 - (void)windowDidResignKey:(NSNotification*)notification { |
711 edit_view_->OnDidResignKey(); | 727 edit_view_->OnDidResignKey(); |
712 } | 728 } |
713 | 729 |
| 730 // AutocompleteTextField adds a delegate method which allows us to |
| 731 // track -flagsChanged: calls. |
| 732 // |
| 733 // When the user types Control-Enter, the existing content has "www." |
| 734 // prepended and ".com" appended. This calls down to |
| 735 // AutocompleteEditModel::OnControlKeyChanged() so that it can change |
| 736 // the popup to reflect this. See autocomplete_edit.cc |
| 737 // OnControlKeyChanged() and OnAfterPossibleChange(). |
| 738 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { |
| 739 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |
| 740 edit_view_->OnControlKeyChanged(controlFlag); |
| 741 } |
| 742 |
714 @end | 743 @end |
OLD | NEW |