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

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

Issue 192008: [Mac] Implement Paste and Go/Search. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
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/l10n_util_mac.h"
9 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
10 #include "base/clipboard.h" 11 #include "base/clipboard.h"
11 #import "base/cocoa_protocols_mac.h" 12 #import "base/cocoa_protocols_mac.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
14 #include "chrome/browser/autocomplete/autocomplete_edit.h" 15 #include "chrome/browser/autocomplete/autocomplete_edit.h"
15 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 16 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
16 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h" 17 #include "chrome/browser/autocomplete/autocomplete_popup_view_mac.h"
17 #include "chrome/browser/browser_process.h" 18 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/cocoa/autocomplete_text_field.h" 19 #include "chrome/browser/cocoa/autocomplete_text_field.h"
19 #include "chrome/browser/cocoa/event_utils.h" 20 #include "chrome/browser/cocoa/event_utils.h"
20 #include "chrome/browser/tab_contents/tab_contents.h" 21 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "grit/generated_resources.h"
21 23
22 // Focus-handling between |field_| and |model_| is a bit subtle. 24 // Focus-handling between |field_| and |model_| is a bit subtle.
23 // Other platforms detect change of focus, which is inconvenient 25 // Other platforms detect change of focus, which is inconvenient
24 // without subclassing NSTextField (even with a subclass, the use of a 26 // without subclassing NSTextField (even with a subclass, the use of a
25 // field editor may complicate things). 27 // field editor may complicate things).
26 // 28 //
27 // |model_| doesn't actually do anything when it gains focus, it just 29 // |model_| doesn't actually do anything when it gains focus, it just
28 // initializes. Visible activity happens only after the user edits. 30 // initializes. Visible activity happens only after the user edits.
29 // NSTextField delegate receives messages around starting and ending 31 // NSTextField delegate receives messages around starting and ending
30 // edits, so that sufcices to catch focus changes. Since all calls 32 // edits, so that sufcices to catch focus changes. Since all calls
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // OnAfterPossibleChange(), even if identical contents are pasted into the 601 // OnAfterPossibleChange(), even if identical contents are pasted into the
600 // text box. 602 // text box.
601 text_before_change_.clear(); 603 text_before_change_.clear();
602 604
603 NSString* s = base::SysWideToNSString(text); 605 NSString* s = base::SysWideToNSString(text);
604 [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s]; 606 [[field_ currentEditor] replaceCharactersInRange:selectedRange withString:s];
605 607
606 OnAfterPossibleChange(); 608 OnAfterPossibleChange();
607 } 609 }
608 610
611 bool AutocompleteEditViewMac::CanPasteAndGo() {
612 return
613 model_->CanPasteAndGo(GetClipboardText(g_browser_process->clipboard()));
614 }
615
616 int AutocompleteEditViewMac::GetPasteActionStringId() {
617 DCHECK(CanPasteAndGo());
618
619 // Use PASTE_AND_SEARCH as the default fallback (although the DCHECK above
620 // should never trigger).
621 if (!model_->is_paste_and_search())
622 return IDS_PASTE_AND_GO;
623 else
624 return IDS_PASTE_AND_SEARCH;
625 }
626
627 void AutocompleteEditViewMac::OnPasteAndGo() {
628 if (CanPasteAndGo())
629 model_->PasteAndGo();
630 }
631
609 bool AutocompleteEditViewMac::OnTabPressed() { 632 bool AutocompleteEditViewMac::OnTabPressed() {
610 if (model_->is_keyword_hint() && !model_->keyword().empty()) { 633 if (model_->is_keyword_hint() && !model_->keyword().empty()) {
611 model_->AcceptKeyword(); 634 model_->AcceptKeyword();
612 return true; 635 return true;
613 } 636 }
614 return false; 637 return false;
615 } 638 }
616 639
617 bool AutocompleteEditViewMac::OnBackspacePressed() { 640 bool AutocompleteEditViewMac::OnBackspacePressed() {
618 // Don't intercept if not in keyword search mode. 641 // Don't intercept if not in keyword search mode.
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 852
830 // AutocompleteTextField/Editor adds a delegate method which allows us 853 // AutocompleteTextField/Editor adds a delegate method which allows us
831 // to intercept and handle -paste: calls. 854 // to intercept and handle -paste: calls.
832 - (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor { 855 - (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor {
833 edit_view_->OnPaste(); 856 edit_view_->OnPaste();
834 857
835 // Caller shouldn't also paste. 858 // Caller shouldn't also paste.
836 return NO; 859 return NO;
837 } 860 }
838 861
862 - (NSString*)control:(NSControl*)control
863 textPasteActionString:(NSText*)fieldEditor {
864 if (!edit_view_->CanPasteAndGo())
865 return nil;
866
867 return l10n_util::GetNSStringWithFixup(edit_view_->GetPasteActionStringId());
868 }
869
870 - (void)control:(NSControl*)control textDidPasteAndGo:(NSText*)fieldEditor {
871 edit_view_->OnPasteAndGo();
872 }
873
839 // Signal that we've lost focus when the window resigns key. 874 // Signal that we've lost focus when the window resigns key.
840 - (void)windowDidResignKey:(NSNotification*)notification { 875 - (void)windowDidResignKey:(NSNotification*)notification {
841 edit_view_->OnDidResignKey(); 876 edit_view_->OnDidResignKey();
842 } 877 }
843 878
844 // AutocompleteTextField adds a delegate method which allows us to 879 // AutocompleteTextField adds a delegate method which allows us to
845 // track -flagsChanged: calls. 880 // track -flagsChanged: calls.
846 // 881 //
847 // When the user types Control-Enter, the existing content has "www." 882 // When the user types Control-Enter, the existing content has "www."
848 // prepended and ".com" appended. This calls down to 883 // prepended and ".com" appended. This calls down to
849 // AutocompleteEditModel::OnControlKeyChanged() so that it can change 884 // AutocompleteEditModel::OnControlKeyChanged() so that it can change
850 // the popup to reflect this. See autocomplete_edit.cc 885 // the popup to reflect this. See autocomplete_edit.cc
851 // OnControlKeyChanged() and OnAfterPossibleChange(). 886 // OnControlKeyChanged() and OnAfterPossibleChange().
852 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { 887 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent {
853 bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; 888 bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0;
854 edit_view_->OnControlKeyChanged(controlFlag); 889 edit_view_->OnControlKeyChanged(controlFlag);
855 } 890 }
856 891
857 @end 892 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698