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 <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" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
13 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 13 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
15 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" | 15 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/cocoa/autocomplete_text_field.h" | 17 #include "chrome/browser/cocoa/autocomplete_text_field.h" |
| 18 #include "chrome/browser/cocoa/event_utils.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #import "chrome/common/cocoa_utils.h" | |
20 | 20 |
21 // Focus-handling between |field_| and |model_| is a bit subtle. | 21 // Focus-handling between |field_| and |model_| is a bit subtle. |
22 // Other platforms detect change of focus, which is inconvenient | 22 // Other platforms detect change of focus, which is inconvenient |
23 // without subclassing NSTextField (even with a subclass, the use of a | 23 // without subclassing NSTextField (even with a subclass, the use of a |
24 // field editor may complicate things). | 24 // field editor may complicate things). |
25 // | 25 // |
26 // |model_| doesn't actually do anything when it gains focus, it just | 26 // |model_| doesn't actually do anything when it gains focus, it just |
27 // initializes. Visible activity happens only after the user edits. | 27 // initializes. Visible activity happens only after the user edits. |
28 // NSTextField delegate receives messages around starting and ending | 28 // NSTextField delegate receives messages around starting and ending |
29 // edits, so that sufcices to catch focus changes. Since all calls | 29 // edits, so that sufcices to catch focus changes. Since all calls |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 if (cmd == @selector(cancelOperation:)) { | 685 if (cmd == @selector(cancelOperation:)) { |
686 edit_view_->OnEscapeKeyPressed(); | 686 edit_view_->OnEscapeKeyPressed(); |
687 return YES; | 687 return YES; |
688 } | 688 } |
689 | 689 |
690 // |-noop:| is sent when the user presses Cmd+Return. Override the no-op | 690 // |-noop:| is sent when the user presses Cmd+Return. Override the no-op |
691 // behavior with the proper WindowOpenDisposition. | 691 // behavior with the proper WindowOpenDisposition. |
692 NSEvent* event = [NSApp currentEvent]; | 692 NSEvent* event = [NSApp currentEvent]; |
693 if (cmd == @selector(insertNewline:) || | 693 if (cmd == @selector(insertNewline:) || |
694 (cmd == @selector(noop:) && [event keyCode] == kVK_Return)) { | 694 (cmd == @selector(noop:) && [event keyCode] == kVK_Return)) { |
695 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( | 695 WindowOpenDisposition disposition = |
696 [event modifierFlags]); | 696 event_utils::WindowOpenDispositionFromNSEvent(event); |
697 edit_view_->AcceptInput(disposition, false); | 697 edit_view_->AcceptInput(disposition, false); |
698 return YES; | 698 return YES; |
699 } | 699 } |
700 | 700 |
701 // When the user does Control-Enter, the existing content has "www." | 701 // When the user does Control-Enter, the existing content has "www." |
702 // prepended and ".com" appended. |model_| should already have | 702 // prepended and ".com" appended. |model_| should already have |
703 // received notification when the Control key was depressed, but it | 703 // received notification when the Control key was depressed, but it |
704 // is safe to tell it twice. | 704 // is safe to tell it twice. |
705 if (cmd == @selector(insertLineBreak:)) { | 705 if (cmd == @selector(insertLineBreak:)) { |
706 edit_view_->OnControlKeyChanged(true); | 706 edit_view_->OnControlKeyChanged(true); |
707 WindowOpenDisposition disposition = event_utils::DispositionFromEventFlags( | 707 WindowOpenDisposition disposition = |
708 [[NSApp currentEvent] modifierFlags]); | 708 event_utils::WindowOpenDispositionFromNSEvent([NSApp currentEvent]); |
709 edit_view_->AcceptInput(disposition, false); | 709 edit_view_->AcceptInput(disposition, false); |
710 return YES; | 710 return YES; |
711 } | 711 } |
712 | 712 |
713 // Capture the state before the operation changes the content. | 713 // Capture the state before the operation changes the content. |
714 // TODO(shess): Determine if this is always redundent WRT the call | 714 // TODO(shess): Determine if this is always redundent WRT the call |
715 // in -controlTextDidChange:. | 715 // in -controlTextDidChange:. |
716 edit_view_->OnBeforePossibleChange(); | 716 edit_view_->OnBeforePossibleChange(); |
717 return NO; | 717 return NO; |
718 } | 718 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 // prepended and ".com" appended. This calls down to | 759 // prepended and ".com" appended. This calls down to |
760 // AutocompleteEditModel::OnControlKeyChanged() so that it can change | 760 // AutocompleteEditModel::OnControlKeyChanged() so that it can change |
761 // the popup to reflect this. See autocomplete_edit.cc | 761 // the popup to reflect this. See autocomplete_edit.cc |
762 // OnControlKeyChanged() and OnAfterPossibleChange(). | 762 // OnControlKeyChanged() and OnAfterPossibleChange(). |
763 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { | 763 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { |
764 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | 764 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |
765 edit_view_->OnControlKeyChanged(controlFlag); | 765 edit_view_->OnControlKeyChanged(controlFlag); |
766 } | 766 } |
767 | 767 |
768 @end | 768 @end |
OLD | NEW |