summaryrefslogtreecommitdiffstats
path: root/chrome
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
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')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm35
-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
6 files changed, 108 insertions, 1 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
index df7891b..8d038ec 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.h
@@ -14,6 +14,7 @@
#include "chrome/browser/autocomplete/autocomplete_edit_view.h"
#include "chrome/browser/toolbar_model.h"
#include "chrome/common/page_transition_types.h"
+#include "grit/generated_resources.h"
#include "webkit/glue/window_open_disposition.h"
class AutocompleteEditController;
@@ -113,6 +114,19 @@ class AutocompleteEditViewMac : public AutocompleteEditView {
// Called when the user attempts to paste into |field_|.
void OnPaste();
+ // Returns true if the current clipboard text supports paste and go (or paste
+ // and search).
+ bool CanPasteAndGo();
+
+ // Returns the appropriate "Paste and Go" or "Paste and Search" context menu
+ // string, depending on what is currently in the clipboard. Must not be
+ // called unless CanPasteAndGo() returns true.
+ int GetPasteActionStringId();
+
+ // Called when the user initiates a "paste and go" or "paste and search" into
+ // |field_|.
+ void OnPasteAndGo();
+
// Checks if a keyword search is possible and forwards to |model_|
// if so. Returns true if the tab should be eaten.
bool OnTabPressed();
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index ff81db3..b3af808 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -6,6 +6,7 @@
#include <Carbon/Carbon.h> // kVK_Return
#include "app/gfx/font.h"
+#include "app/l10n_util_mac.h"
#include "app/resource_bundle.h"
#include "base/clipboard.h"
#import "base/cocoa_protocols_mac.h"
@@ -18,6 +19,7 @@
#include "chrome/browser/cocoa/autocomplete_text_field.h"
#include "chrome/browser/cocoa/event_utils.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "grit/generated_resources.h"
// Focus-handling between |field_| and |model_| is a bit subtle.
// Other platforms detect change of focus, which is inconvenient
@@ -606,6 +608,27 @@ void AutocompleteEditViewMac::OnPaste() {
OnAfterPossibleChange();
}
+bool AutocompleteEditViewMac::CanPasteAndGo() {
+ return
+ model_->CanPasteAndGo(GetClipboardText(g_browser_process->clipboard()));
+}
+
+int AutocompleteEditViewMac::GetPasteActionStringId() {
+ DCHECK(CanPasteAndGo());
+
+ // Use PASTE_AND_SEARCH as the default fallback (although the DCHECK above
+ // should never trigger).
+ if (!model_->is_paste_and_search())
+ return IDS_PASTE_AND_GO;
+ else
+ return IDS_PASTE_AND_SEARCH;
+}
+
+void AutocompleteEditViewMac::OnPasteAndGo() {
+ if (CanPasteAndGo())
+ model_->PasteAndGo();
+}
+
bool AutocompleteEditViewMac::OnTabPressed() {
if (model_->is_keyword_hint() && !model_->keyword().empty()) {
model_->AcceptKeyword();
@@ -836,6 +859,18 @@ std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
return NO;
}
+- (NSString*)control:(NSControl*)control
+ textPasteActionString:(NSText*)fieldEditor {
+ if (!edit_view_->CanPasteAndGo())
+ return nil;
+
+ return l10n_util::GetNSStringWithFixup(edit_view_->GetPasteActionStringId());
+}
+
+- (void)control:(NSControl*)control textDidPasteAndGo:(NSText*)fieldEditor {
+ edit_view_->OnPasteAndGo();
+}
+
// Signal that we've lost focus when the window resigns key.
- (void)windowDidResignKey:(NSNotification*)notification {
edit_view_->OnDidResignKey();
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