summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete
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/autocomplete
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/autocomplete')
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.h14
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm35
2 files changed, 49 insertions, 0 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();