summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpedrosimonetti@chromium.org <pedrosimonetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 20:19:00 +0000
committerpedrosimonetti@chromium.org <pedrosimonetti@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-06 20:19:00 +0000
commit10aec59bcc5ee6aa59a5c56f8965e58c04e4edc3 (patch)
treed8471bade914d3e5e47a982fb284801fd6222dc3
parent3870363e188f0fbf455278aaa0380882fe3096f1 (diff)
downloadchromium_src-10aec59bcc5ee6aa59a5c56f8965e58c04e4edc3.zip
chromium_src-10aec59bcc5ee6aa59a5c56f8965e58c04e4edc3.tar.gz
chromium_src-10aec59bcc5ee6aa59a5c56f8965e58c04e4edc3.tar.bz2
Implements focus() method for Instant Extended API.
BUG=167173 Review URL: https://chromiumcodereview.appspot.com/12330028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186490 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/instant/instant_controller.cc10
-rw-r--r--chrome/browser/instant/instant_controller.h1
-rw-r--r--chrome/browser/instant/instant_page.cc13
-rw-r--r--chrome/browser/instant/instant_page.h5
-rw-r--r--chrome/browser/instant/instant_tab.cc4
-rw-r--r--chrome/browser/instant/instant_tab.h1
-rw-r--r--chrome/browser/ui/browser_instant_controller.cc4
-rw-r--r--chrome/browser/ui/browser_instant_controller.h5
-rw-r--r--chrome/common/render_messages.h4
-rw-r--r--chrome/renderer/resources/extensions/searchbox_api.js4
-rw-r--r--chrome/renderer/searchbox/searchbox.cc5
-rw-r--r--chrome/renderer/searchbox/searchbox.h3
-rw-r--r--chrome/renderer/searchbox/searchbox_extension.cc17
13 files changed, 71 insertions, 5 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 2be1d0d..862c8a0 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -1087,13 +1087,21 @@ void InstantController::ShowInstantOverlay(const content::WebContents* contents,
ShowOverlay(reason, height, units);
}
+void InstantController::FocusOmnibox(const content::WebContents* contents) {
+ if (!extended_enabled_)
+ return;
+
+ DCHECK(IsContentsFrom(instant_tab(), contents));
+ browser_->FocusOmnibox(true);
+}
+
void InstantController::StartCapturingKeyStrokes(
const content::WebContents* contents) {
if (!extended_enabled_)
return;
DCHECK(IsContentsFrom(instant_tab(), contents));
- browser_->FocusOmniboxInvisibly();
+ browser_->FocusOmnibox(false);
}
void InstantController::StopCapturingKeyStrokes(
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index e523153..64a9b06 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -237,6 +237,7 @@ class InstantController : public InstantPage::Delegate,
InstantShownReason reason,
int height,
InstantSizeUnits units) OVERRIDE;
+ virtual void FocusOmnibox(const content::WebContents* contents) OVERRIDE;
virtual void StartCapturingKeyStrokes(
const content::WebContents* contents) OVERRIDE;
virtual void StopCapturingKeyStrokes(content::WebContents* contents) OVERRIDE;
diff --git a/chrome/browser/instant/instant_page.cc b/chrome/browser/instant/instant_page.cc
index ba79353..43b81fa 100644
--- a/chrome/browser/instant/instant_page.cc
+++ b/chrome/browser/instant/instant_page.cc
@@ -122,6 +122,10 @@ bool InstantPage::ShouldProcessShowInstantOverlay() {
return false;
}
+bool InstantPage::ShouldProcessFocusOmnibox() {
+ return false;
+}
+
bool InstantPage::ShouldProcessStartCapturingKeyStrokes() {
return false;
}
@@ -156,6 +160,7 @@ bool InstantPage::OnMessageReceived(const IPC::Message& message) {
OnInstantSupportDetermined)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ShowInstantOverlay,
OnShowInstantOverlay)
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_FocusOmnibox, OnFocusOmnibox)
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StartCapturingKeyStrokes,
OnStartCapturingKeyStrokes);
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_StopCapturingKeyStrokes,
@@ -224,6 +229,14 @@ void InstantPage::OnShowInstantOverlay(int page_id,
}
}
+void InstantPage::OnFocusOmnibox(int page_id) {
+ if (contents()->IsActiveEntry(page_id)) {
+ OnInstantSupportDetermined(page_id, true);
+ if (ShouldProcessFocusOmnibox())
+ delegate_->FocusOmnibox(contents());
+ }
+}
+
void InstantPage::OnStartCapturingKeyStrokes(int page_id) {
if (contents()->IsActiveEntry(page_id)) {
OnInstantSupportDetermined(page_id, true);
diff --git a/chrome/browser/instant/instant_page.h b/chrome/browser/instant/instant_page.h
index 1260beb1..1ad8626 100644
--- a/chrome/browser/instant/instant_page.h
+++ b/chrome/browser/instant/instant_page.h
@@ -66,6 +66,9 @@ class InstantPage : public content::WebContentsObserver {
int height,
InstantSizeUnits units) = 0;
+ // Called when the page wants the omnibox to be focused.
+ virtual void FocusOmnibox(const content::WebContents* contents) = 0;
+
// Called when the page wants the omnibox to start capturing user key
// strokes. If this call is processed successfully, the omnibox will not
// look focused visibly but any user key strokes will go to the omnibox.
@@ -185,6 +188,7 @@ class InstantPage : public content::WebContentsObserver {
virtual bool ShouldProcessAboutToNavigateMainFrame();
virtual bool ShouldProcessSetSuggestions();
virtual bool ShouldProcessShowInstantOverlay();
+ virtual bool ShouldProcessFocusOmnibox();
virtual bool ShouldProcessStartCapturingKeyStrokes();
virtual bool ShouldProcessStopCapturingKeyStrokes();
virtual bool ShouldProcessNavigateToURL();
@@ -214,6 +218,7 @@ class InstantPage : public content::WebContentsObserver {
InstantShownReason reason,
int height,
InstantSizeUnits units);
+ void OnFocusOmnibox(int page_id);
void OnStartCapturingKeyStrokes(int page_id);
void OnStopCapturingKeyStrokes(int page_id);
void OnSearchBoxNavigate(int page_id,
diff --git a/chrome/browser/instant/instant_tab.cc b/chrome/browser/instant/instant_tab.cc
index 0a4b51a..89e0ba3 100644
--- a/chrome/browser/instant/instant_tab.cc
+++ b/chrome/browser/instant/instant_tab.cc
@@ -20,6 +20,10 @@ bool InstantTab::ShouldProcessSetSuggestions() {
return true;
}
+bool InstantTab::ShouldProcessFocusOmnibox() {
+ return true;
+}
+
bool InstantTab::ShouldProcessStartCapturingKeyStrokes() {
return true;
}
diff --git a/chrome/browser/instant/instant_tab.h b/chrome/browser/instant/instant_tab.h
index bbc675d..131e227 100644
--- a/chrome/browser/instant/instant_tab.h
+++ b/chrome/browser/instant/instant_tab.h
@@ -23,6 +23,7 @@ class InstantTab : public InstantPage {
private:
// Overridden from InstantPage:
virtual bool ShouldProcessSetSuggestions() OVERRIDE;
+ virtual bool ShouldProcessFocusOmnibox() OVERRIDE;
virtual bool ShouldProcessStartCapturingKeyStrokes() OVERRIDE;
virtual bool ShouldProcessStopCapturingKeyStrokes() OVERRIDE;
virtual bool ShouldProcessNavigateToURL() OVERRIDE;
diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc
index 0a32bba..1cf312c 100644
--- a/chrome/browser/ui/browser_instant_controller.cc
+++ b/chrome/browser/ui/browser_instant_controller.cc
@@ -178,11 +178,11 @@ void BrowserInstantController::InstantOverlayFocused() {
browser_->window()->WebContentsFocused(instant_.GetOverlayContents());
}
-void BrowserInstantController::FocusOmniboxInvisibly() {
+void BrowserInstantController::FocusOmnibox(bool caret_visibility) {
OmniboxView* omnibox_view = browser_->window()->GetLocationBar()->
GetLocationEntry();
omnibox_view->SetFocus();
- omnibox_view->model()->SetCaretVisibility(false);
+ omnibox_view->model()->SetCaretVisibility(caret_visibility);
}
content::WebContents* BrowserInstantController::GetActiveWebContents() const {
diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h
index e5d6836..21cc6d8 100644
--- a/chrome/browser/ui/browser_instant_controller.h
+++ b/chrome/browser/ui/browser_instant_controller.h
@@ -80,8 +80,9 @@ class BrowserInstantController : public content::NotificationObserver,
// to the user clicking on it.
void InstantOverlayFocused();
- // Invoked by |instant_| to give the omnibox focus invisibly.
- void FocusOmniboxInvisibly();
+ // Invoked by |instant_| to give the omnibox focus, with the option of making
+ // the caret invisible.
+ void FocusOmnibox(bool caret_visibility);
// Invoked by |instant_| to get the currently active tab, over which the
// overlay would be shown.
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 706eb47..b7f66c1 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -691,6 +691,10 @@ IPC_MESSAGE_ROUTED4(ChromeViewHostMsg_ShowInstantOverlay,
int /* height */,
InstantSizeUnits /* units */)
+// Sent by Instant to focus the omnibox.
+IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_FocusOmnibox,
+ int /* page_id */)
+
IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_StartCapturingKeyStrokes,
int /* page_id */)
diff --git a/chrome/renderer/resources/extensions/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox_api.js
index f566b8f..dcfda30 100644
--- a/chrome/renderer/resources/extensions/searchbox_api.js
+++ b/chrome/renderer/resources/extensions/searchbox_api.js
@@ -96,6 +96,7 @@ if (!chrome.embeddedSearch) {
native function SetQuery();
native function SetQueryFromAutocompleteResult();
native function ShowOverlay();
+ native function FocusOmnibox();
native function StartCapturingKeyStrokes();
native function StopCapturingKeyStrokes();
@@ -253,6 +254,9 @@ if (!chrome.embeddedSearch) {
this.markDuplicateSuggestions = function(clientSuggestions) {
return DedupeClientSuggestions(clientSuggestions);
};
+ this.focus = function() {
+ FocusOmnibox();
+ };
this.startCapturingKeyStrokes = function() {
StartCapturingKeyStrokes();
};
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 3631412..6348ae6 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -59,6 +59,11 @@ void SearchBox::ShowInstantOverlay(InstantShownReason reason,
height, units));
}
+void SearchBox::FocusOmnibox() {
+ render_view()->Send(new ChromeViewHostMsg_FocusOmnibox(
+ render_view()->GetRoutingID(), render_view()->GetPageId()));
+}
+
void SearchBox::StartCapturingKeyStrokes() {
render_view()->Send(new ChromeViewHostMsg_StartCapturingKeyStrokes(
render_view()->GetRoutingID(), render_view()->GetPageId()));
diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h
index 445d4dc..00bba89 100644
--- a/chrome/renderer/searchbox/searchbox.h
+++ b/chrome/renderer/searchbox/searchbox.h
@@ -35,6 +35,9 @@ class SearchBox : public content::RenderViewObserver,
int height,
InstantSizeUnits units);
+ // Sends ChromeViewHostMsg_FocusOmnibox to the browser.
+ void FocusOmnibox();
+
// Sends ChromeViewHostMsg_StartCapturingKeyStrokes to the browser.
void StartCapturingKeyStrokes();
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index 390f741..9a4fae9 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -314,6 +314,9 @@ class SearchBoxExtensionWrapper : public v8::Extension {
// Requests the overlay be shown with the specified contents and height.
static v8::Handle<v8::Value> ShowOverlay(const v8::Arguments& args);
+ // Sets the focus to the omnibox.
+ static v8::Handle<v8::Value> FocusOmnibox(const v8::Arguments& args);
+
// Start capturing user key strokes.
static v8::Handle<v8::Value> StartCapturingKeyStrokes(
const v8::Arguments& args);
@@ -391,6 +394,8 @@ v8::Handle<v8::FunctionTemplate> SearchBoxExtensionWrapper::GetNativeFunction(
return v8::FunctionTemplate::New(SetQueryFromAutocompleteResult);
if (name->Equals(v8::String::New("ShowOverlay")))
return v8::FunctionTemplate::New(ShowOverlay);
+ if (name->Equals(v8::String::New("FocusOmnibox")))
+ return v8::FunctionTemplate::New(FocusOmnibox);
if (name->Equals(v8::String::New("StartCapturingKeyStrokes")))
return v8::FunctionTemplate::New(StartCapturingKeyStrokes);
if (name->Equals(v8::String::New("StopCapturingKeyStrokes")))
@@ -930,6 +935,18 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::UndoAllMostVisitedDeletions(
}
// static
+v8::Handle<v8::Value> SearchBoxExtensionWrapper::FocusOmnibox(
+ const v8::Arguments& args) {
+ content::RenderView* render_view = GetRenderView();
+ if (!render_view) return v8::Undefined();
+
+ DVLOG(1) << render_view << " FocusOmnibox";
+ SearchBox::Get(render_view)->FocusOmnibox();
+
+ return v8::Undefined();
+}
+
+// static
v8::Handle<v8::Value> SearchBoxExtensionWrapper::StartCapturingKeyStrokes(
const v8::Arguments& args) {
content::RenderView* render_view = GetRenderView();