summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 19:35:46 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 19:35:46 +0000
commit6ecc0d5701a9e5e991d977ed2f0e33a23c8d0e16 (patch)
treea9043d89206df039db660f29baba934ed99eda35 /chrome/browser/cocoa
parent8057b04045dd5881d001d164a42e92d3daa525c3 (diff)
downloadchromium_src-6ecc0d5701a9e5e991d977ed2f0e33a23c8d0e16.zip
chromium_src-6ecc0d5701a9e5e991d977ed2f0e33a23c8d0e16.tar.gz
chromium_src-6ecc0d5701a9e5e991d977ed2f0e33a23c8d0e16.tar.bz2
[Mac] Implement Paste and Go/Search.
BUG=http://crbug.com/10937 BUG=http://crbug.com/13021 TEST=Omnibox context menu should contain paste and go/search. Review URL: http://codereview.chromium.org/192008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26603 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.h5
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field.mm15
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.h3
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.mm37
4 files changed, 59 insertions, 1 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field.h b/chrome/browser/cocoa/autocomplete_text_field.h
index 2d9e762..51afa05 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.h
+++ b/chrome/browser/cocoa/autocomplete_text_field.h
@@ -33,6 +33,11 @@
// edited. See AutocompleteTextFieldEditor implementation.
- (BOOL)control:(NSControl*)control textShouldPaste:(NSText*)fieldEditor;
+// Returns nil if paste actions are not supported.
+- (NSString*)control:(NSControl*)control
+ textPasteActionString:(NSText*)fieldEditor;
+- (void)control:(NSControl*)control textDidPasteAndGo:(NSText*)fieldEditor;
+
// Let the delegate track -flagsChanged: events.
- (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent;
diff --git a/chrome/browser/cocoa/autocomplete_text_field.mm b/chrome/browser/cocoa/autocomplete_text_field.mm
index d7942e7..9c3e593 100644
--- a/chrome/browser/cocoa/autocomplete_text_field.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field.mm
@@ -25,6 +25,21 @@
return YES;
}
+- (NSString*)textPasteActionString:(NSText*)fieldEditor {
+ id delegate = [self delegate];
+ if ([delegate respondsToSelector:@selector(control:textPasteActionString:)]) {
+ return [delegate control:self textPasteActionString:fieldEditor];
+ }
+ return nil;
+}
+
+- (void)textDidPasteAndGo:(NSText*)fieldEditor {
+ id delegate = [self delegate];
+ if ([delegate respondsToSelector:@selector(control:textDidPasteAndGo:)]) {
+ [delegate control:self textDidPasteAndGo:fieldEditor];
+ }
+}
+
- (void)flagsChanged:(NSEvent*)theEvent {
id delegate = [self delegate];
if ([delegate respondsToSelector:@selector(control:flagsChanged:)]) {
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.h b/chrome/browser/cocoa/autocomplete_text_field_editor.h
index e174296..6640f69 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.h
@@ -23,6 +23,9 @@
// (or handle it internally) by returning NO.
- (BOOL)textShouldPaste:(NSText*)fieldEditor;
+// Returns nil if paste actions are not supported.
+- (NSString*)textPasteActionString:(NSText*)fieldEditor;
+- (void)textDidPasteAndGo:(NSText*)fieldEditor;
@end
// Field editor used for the autocomplete field.
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
index 4e34692..5bcacff 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
@@ -4,8 +4,9 @@
#import "chrome/browser/cocoa/autocomplete_text_field_editor.h"
+#include "app/l10n_util_mac.h"
#include "base/string_util.h"
-#include "base/sys_string_conversions.h"
+#include "grit/generated_resources.h"
@implementation AutocompleteTextFieldEditor
@@ -45,6 +46,12 @@
}
}
+- (void)pasteAndGo:sender {
+ id delegate = [self delegate];
+ if ([delegate respondsToSelector:@selector(textDidPasteAndGo:)])
+ [delegate textDidPasteAndGo:self];
+}
+
// We have rich text, but it shouldn't be modified by the user, so
// don't update the font panel. In theory, -setUsesFontPanel: should
// accomplish this, but that gets called frequently with YES when
@@ -58,4 +65,32 @@
- (void)updateRuler {
}
+- (NSMenu*)menuForEvent:(NSEvent*)event {
+ NSMenu* menu = [[[NSMenu alloc] initWithTitle:@"TITLE"] autorelease];
+ [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_CUT)
+ action:@selector(cut:)
+ keyEquivalent:@"" atIndex:0];
+ [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_COPY)
+ action:@selector(copy:)
+ keyEquivalent:@"" atIndex:1];
+ [menu insertItemWithTitle:l10n_util::GetNSStringWithFixup(IDS_PASTE)
+ action:@selector(paste:)
+ keyEquivalent:@"" atIndex:2];
+
+ // Paste and go/search.
+ id delegate = [self delegate];
+
+ if ([delegate respondsToSelector:@selector(textPasteActionString:)]) {
+ NSString* label = [delegate textPasteActionString:self];
+ // TODO(rohitrao): If the clipboard is empty, should we show a greyed-out
+ // "Paste and Go" or nothing at all?
+ if (label) {
+ [menu insertItemWithTitle:label action:@selector(pasteAndGo:)
+ keyEquivalent:@"" atIndex:3];
+ }
+ }
+
+ return menu;
+}
+
@end