summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsuzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 02:42:07 +0000
committersuzhe@google.com <suzhe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-18 02:42:07 +0000
commit939e54a1be5a3f2d8357a9cd9d56d97d5c8ca917 (patch)
tree3add1d80600876d3aa01d08fa8e87a22f6d10cfd
parent4757d2462ecff8976734685bea34116024668b08 (diff)
downloadchromium_src-939e54a1be5a3f2d8357a9cd9d56d97d5c8ca917.zip
chromium_src-939e54a1be5a3f2d8357a9cd9d56d97d5c8ca917.tar.gz
chromium_src-939e54a1be5a3f2d8357a9cd9d56d97d5c8ca917.tar.bz2
Accepts current instant preview with Tab key.
This CL adds a new test InstantTest.TabKey and also fixes (hopefully) InstantTest.OnSubmitEvent on Windows and InstantTest.OnCancelEvent on Mac. BUG=62940 BUG=64696 BUG=66768 TEST=See bug report. Review URL: http://codereview.chromium.org/5811002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69622 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.cc4
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_unittest.cc3
-rw-r--r--chrome/browser/autocomplete/autocomplete_edit_view_mac.mm3
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc7
-rw-r--r--chrome/browser/instant/instant_browsertest.cc194
-rw-r--r--chrome/browser/instant/instant_controller.cc9
-rw-r--r--chrome/browser/instant/instant_controller.h5
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h1
-rw-r--r--chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm4
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc30
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h1
-rw-r--r--chrome/test/ui_test_utils_linux.cc3
13 files changed, 169 insertions, 97 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc
index 37de68d..8d31941 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit.cc
@@ -36,10 +36,6 @@
///////////////////////////////////////////////////////////////////////////////
// AutocompleteEditController
-bool AutocompleteEditController::AcceptCurrentInstantPreview() {
- return false;
-}
-
AutocompleteEditController::~AutocompleteEditController() {
}
diff --git a/chrome/browser/autocomplete/autocomplete_edit.h b/chrome/browser/autocomplete/autocomplete_edit.h
index 4f0b5d8..c4d4b5a 100644
--- a/chrome/browser/autocomplete/autocomplete_edit.h
+++ b/chrome/browser/autocomplete/autocomplete_edit.h
@@ -52,7 +52,7 @@ class AutocompleteEditController {
// Accepts the currently showing instant preview, if any, and returns true.
// Returns false if there is no instant preview showing.
- virtual bool AcceptCurrentInstantPreview();
+ virtual bool AcceptCurrentInstantPreview() = 0;
// Sets the suggested search text to |suggested_text|.
virtual void OnSetSuggestedSearchText(const string16& suggested_text) = 0;
diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
index d70d07f..7dedb98 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
+++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc
@@ -68,6 +68,9 @@ class TestingAutocompleteEditController : public AutocompleteEditController {
virtual bool OnCommitSuggestedText(const std::wstring& typed_text) {
return false;
}
+ virtual bool AcceptCurrentInstantPreview() {
+ return false;
+ }
virtual void OnSetSuggestedSearchText(const string16& suggested_text) {}
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {}
virtual void OnAutocompleteAccept(const GURL& url,
diff --git a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
index 15d0f97..4bc4a5e 100644
--- a/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_edit_view_mac.mm
@@ -810,6 +810,9 @@ bool AutocompleteEditViewMac::OnDoCommandBySelector(SEL cmd) {
controller_->OnCommitSuggestedText(GetText());
return true;
}
+
+ if (controller_->AcceptCurrentInstantPreview())
+ return true;
}
// |-noop:| is sent when the user presses Cmd+Return. Override the no-op
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 5bbb0d6..c48f6313 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -464,12 +464,7 @@ bool LocationBarViewGtk::OnCommitSuggestedText(
}
bool LocationBarViewGtk::AcceptCurrentInstantPreview() {
- InstantController* instant = browser_->instant();
- if (instant && instant->IsCurrent()) {
- instant->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
- return true;
- }
- return false;
+ return InstantController::CommitIfCurrent(browser_->instant());
}
void LocationBarViewGtk::OnSetSuggestedSearchText(
diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc
index 45867c4..e8f347c 100644
--- a/chrome/browser/instant/instant_browsertest.cc
+++ b/chrome/browser/instant/instant_browsertest.cc
@@ -27,6 +27,7 @@ class InstantTest : public InProcessBrowserTest {
InstantTest()
: location_bar_(NULL),
preview_(NULL) {
+ set_show_window(true);
EnableDOMAutomation();
}
@@ -59,7 +60,7 @@ class InstantTest : public InProcessBrowserTest {
model->SetDefaultSearchProvider(template_url);
}
- virtual void FindLocationBar() {
+ void FindLocationBar() {
if (location_bar_)
return;
location_bar_ = browser()->window()->GetLocationBar();
@@ -93,26 +94,13 @@ class InstantTest : public InProcessBrowserTest {
// Wait for the preview to navigate.
WaitForPreviewToNavigate(true);
- EXPECT_TRUE(browser()->instant()->IsShowingInstant());
- EXPECT_FALSE(browser()->instant()->is_displayable());
- EXPECT_TRUE(browser()->instant()->is_active());
+ ASSERT_TRUE(browser()->instant()->IsShowingInstant());
+ ASSERT_FALSE(browser()->instant()->is_displayable());
+ ASSERT_TRUE(browser()->instant()->is_active());
// When the page loads, the initial searchBox values are set and only a
// resize will have been sent.
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- true, "window.chrome.sv", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 0, "window.onsubmitcalls", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 0, "window.oncancelcalls", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 0, "window.onchangecalls", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 1, "window.onresizecalls", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
- "a", "window.chrome.searchBox.value", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- false, "window.chrome.searchBox.verbatim", preview_));
+ ASSERT_EQ("true 0 0 0 1 a false", GetSearchStateAsString(preview_));
}
void SetLocationBarText(const std::wstring& text) {
@@ -127,43 +115,99 @@ class InstantTest : public InProcessBrowserTest {
browser(), key, false, false, false, false));
}
+ bool GetStringFromJavascript(TabContents* tab_contents,
+ const std::string& function,
+ std::string* result) {
+ std::string script = StringPrintf(
+ "window.domAutomationController.send(%s)", function.c_str());
+ return ui_test_utils::ExecuteJavaScriptAndExtractString(
+ tab_contents->render_view_host(),
+ std::wstring(), UTF8ToWide(script), result);
+ }
+
+ bool GetIntFromJavascript(TabContents* tab_contents,
+ const std::string& function,
+ int* result) {
+ std::string script = StringPrintf(
+ "window.domAutomationController.send(%s)", function.c_str());
+ return ui_test_utils::ExecuteJavaScriptAndExtractInt(
+ tab_contents->render_view_host(),
+ std::wstring(), UTF8ToWide(script), result);
+ }
+
+ bool GetBoolFromJavascript(TabContents* tab_contents,
+ const std::string& function,
+ bool* result) {
+ std::string script = StringPrintf(
+ "window.domAutomationController.send(%s)", function.c_str());
+ return ui_test_utils::ExecuteJavaScriptAndExtractBool(
+ tab_contents->render_view_host(),
+ std::wstring(), UTF8ToWide(script), result);
+ }
+
+ // Returns the state of the search box as a string. This consists of the
+ // following:
+ // window.chrome.sv window.onsubmitcalls window.oncancelcalls
+ // window.onchangecalls window.onresizecalls
+ // window.chrome.searchBox.value
+ // window.chrome.searchBox.verbatim
+ // If determining any of the values fails, the value is 'fail'.
+ std::string GetSearchStateAsString(TabContents* tab_contents) {
+ bool sv = false;
+ int onsubmitcalls = 0;
+ int oncancelcalls = 0;
+ int onchangecalls = 0;
+ int onresizecalls = 0;
+ std::string value;
+ bool verbatim = false;
+
+ if (!GetBoolFromJavascript(tab_contents, "window.chrome.sv", &sv) ||
+ !GetIntFromJavascript(tab_contents, "window.onsubmitcalls",
+ &onsubmitcalls) ||
+ !GetIntFromJavascript(tab_contents, "window.oncancelcalls",
+ &oncancelcalls) ||
+ !GetIntFromJavascript(tab_contents, "window.onchangecalls",
+ &onchangecalls) ||
+ !GetIntFromJavascript(tab_contents, "window.onresizecalls",
+ &onresizecalls) ||
+ !GetStringFromJavascript(tab_contents, "window.chrome.searchBox.value",
+ &value) ||
+ !GetBoolFromJavascript(tab_contents, "window.chrome.searchBox.verbatim",
+ &verbatim)) {
+ return "fail";
+ }
+
+ return StringPrintf("%s %d %d %d %d %s %s",
+ sv ? "true" : "false", onsubmitcalls, oncancelcalls,
+ onchangecalls, onresizecalls, value.c_str(),
+ verbatim ? "true" : "false");
+ }
+
void CheckStringValueFromJavascript(
const std::string& expected,
const std::string& function,
TabContents* tab_contents) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
std::string result;
- ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), &result));
- EXPECT_EQ(expected, result);
+ ASSERT_TRUE(GetStringFromJavascript(tab_contents, function, &result));
+ ASSERT_EQ(expected, result);
}
void CheckBoolValueFromJavascript(
bool expected,
const std::string& function,
TabContents* tab_contents) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
bool result;
- ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), &result));
- EXPECT_EQ(expected, result);
+ ASSERT_TRUE(GetBoolFromJavascript(tab_contents, function, &result));
+ ASSERT_EQ(expected, result);
}
void CheckIntValueFromJavascript(
int expected,
const std::string& function,
TabContents* tab_contents) {
- std::string script = StringPrintf(
- "window.domAutomationController.send(%s)", function.c_str());
int result;
- ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
- tab_contents->render_view_host(),
- std::wstring(), UTF8ToWide(script), &result));
- EXPECT_EQ(expected, result);
+ ASSERT_TRUE(GetIntFromJavascript(tab_contents, function, &result));
+ ASSERT_EQ(expected, result);
}
// Sends a message to the renderer and waits for the response to come back to
@@ -198,12 +242,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnChangeEvent) {
ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
// Check that the value is reflected and onchange is called.
- EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
- "abc", "window.chrome.searchBox.value", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- false, "window.chrome.searchBox.verbatim", preview_));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 1, "window.onchangecalls", preview_));
+ EXPECT_EQ("true 0 0 1 1 abc false", GetSearchStateAsString(preview_));
}
// Verify instant preview is shown correctly for a non-search query.
@@ -410,10 +449,11 @@ IN_PROC_BROWSER_TEST_F(InstantTest, HideOn403) {
}
// Verify that the onsubmit event is dispatched upon pressing enter.
-// TODO(sky): Disabled, http://crbug.com/62940.
-IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) {
+IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
ASSERT_NO_FATAL_FAILURE(SetupPreview());
@@ -422,30 +462,20 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DISABLED_OnSubmitEvent) {
// Check that the preview contents have been committed.
ASSERT_FALSE(browser()->instant()->GetPreviewContents());
+ ASSERT_FALSE(browser()->instant()->is_active());
TabContents* contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(contents);
// Check that the value is reflected and onsubmit is called.
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- true, "window.chrome.sv", contents));
- EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
- "abc", "window.chrome.searchBox.value", contents));
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- true, "window.chrome.searchBox.verbatim", contents));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 1, "window.onsubmitcalls", contents));
+ EXPECT_EQ("true 1 0 1 1 abc true", GetSearchStateAsString(preview_));
}
-#if defined(OS_MACOSX)
-// Does not pass on Mac. http://crbug.com/64696
-#define MAYBE_OnCancelEvent FAILS_OnCancelEvent
-#else
-#define MAYBE_OnCancelEvent OnCancelEvent
-#endif
// Verify that the oncancel event is dispatched upon losing focus.
-IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) {
+IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) {
ASSERT_TRUE(test_server()->Start());
ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
ASSERT_NO_FATAL_FAILURE(SetupPreview());
@@ -455,18 +485,12 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnCancelEvent) {
// Check that the preview contents have been committed.
ASSERT_FALSE(browser()->instant()->GetPreviewContents());
+ ASSERT_FALSE(browser()->instant()->is_active());
TabContents* contents = browser()->GetSelectedTabContents();
ASSERT_TRUE(contents);
// Check that the value is reflected and oncancel is called.
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- true, "window.chrome.sv", contents));
- EXPECT_NO_FATAL_FAILURE(CheckStringValueFromJavascript(
- "abc", "window.chrome.searchBox.value", contents));
- EXPECT_NO_FATAL_FAILURE(CheckBoolValueFromJavascript(
- false, "window.chrome.searchBox.verbatim", contents));
- EXPECT_NO_FATAL_FAILURE(CheckIntValueFromJavascript(
- 1, "window.oncancelcalls", contents));
+ EXPECT_EQ("true 0 1 1 1 abc false", GetSearchStateAsString(preview_));
}
// Verify that suggestion that looks like a url ('www.google.com' in this case)
@@ -496,3 +520,39 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DontShowURLSuggest) {
ASSERT_EQ(UTF16ToWide(string16()),
UTF16ToWide(instant->GetCompleteSuggestedText()));
}
+
+#if !defined(OS_MACOSX)
+// Only passes on Mac. http://crbug.com/66850
+#define MAYBE_TabKey FAILS_TabKey
+#else
+#define MAYBE_TabKey TabKey
+#endif
+IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_TabKey) {
+ ASSERT_TRUE(test_server()->Start());
+ ASSERT_NO_FATAL_FAILURE(SetupInstantProvider("search.html"));
+
+ ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ ASSERT_NO_FATAL_FAILURE(SetupLocationBar());
+ ASSERT_NO_FATAL_FAILURE(SetupPreview());
+
+ ASSERT_NO_FATAL_FAILURE(SetLocationBarText(L"abc"));
+
+ // Pressing tab to convert instant suggest into inline autocomplete.
+ ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB));
+
+ ASSERT_EQ(L"abcdef", location_bar_->location_entry()->GetText());
+
+ EXPECT_EQ("true 0 0 2 2 abcdef false", GetSearchStateAsString(preview_));
+
+ // Pressing tab again to accept the current instant preview.
+ ASSERT_NO_FATAL_FAILURE(SendKey(app::VKEY_TAB));
+
+ // Check that the preview contents have been committed.
+ ASSERT_FALSE(browser()->instant()->GetPreviewContents());
+ ASSERT_FALSE(browser()->instant()->is_active());
+ TabContents* contents = browser()->GetSelectedTabContents();
+ ASSERT_TRUE(contents);
+
+ // Check that the value is reflected and onsubmit is called.
+ EXPECT_EQ("true 1 0 2 2 abcdef true", GetSearchStateAsString(preview_));
+}
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 78e95b0..0bc6ada 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -141,6 +141,15 @@ void InstantController::Disable(Profile* profile) {
service->SetBoolean(prefs::kInstantEnabled, false);
}
+// static
+bool InstantController::CommitIfCurrent(InstantController* controller) {
+ if (controller && controller->IsCurrent()) {
+ controller->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
+ return true;
+ }
+ return false;
+}
+
void InstantController::Update(TabContentsWrapper* tab_contents,
const AutocompleteMatch& match,
const string16& user_text,
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 66ced18..28cee8e 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -91,6 +91,10 @@ class InstantController : public InstantLoaderDelegate {
// Disables instant.
static void Disable(Profile* profile);
+ // Accepts the currently showing instant preview, if any, and returns true.
+ // Returns false if there is no instant preview showing.
+ static bool CommitIfCurrent(InstantController* controller);
+
// Invoked as the user types in the omnibox with the url to navigate to. If
// the url is empty and there is a preview TabContents it is destroyed. If url
// is non-empty and the preview TabContents has not been created it is
@@ -198,7 +202,6 @@ class InstantController : public InstantLoaderDelegate {
virtual void InstantLoaderDoesntSupportInstant(InstantLoader* loader);
virtual void AddToBlacklist(InstantLoader* loader, const GURL& url);
-
private:
friend class InstantTest;
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h
index 2bf4f8c..f492aeb 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h
@@ -133,6 +133,7 @@ class LocationBarViewMac : public AutocompleteEditController,
virtual void OnAutocompleteLosingFocus(gfx::NativeView unused);
virtual void OnAutocompleteWillAccept();
virtual bool OnCommitSuggestedText(const std::wstring& typed_text);
+ virtual bool AcceptCurrentInstantPreview();
virtual void OnSetSuggestedSearchText(const string16& suggested_text);
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds);
virtual void OnAutocompleteAccept(const GURL& url,
diff --git a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
index 436963d..dc85639 100644
--- a/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
+++ b/chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.mm
@@ -254,6 +254,10 @@ bool LocationBarViewMac::OnCommitSuggestedText(const std::wstring& typed_text) {
return edit_view_->CommitSuggestText();
}
+bool LocationBarViewMac::AcceptCurrentInstantPreview() {
+ return InstantController::CommitIfCurrent(browser_->instant());
+}
+
void LocationBarViewMac::OnSetSuggestedSearchText(
const string16& suggested_text) {
SetSuggestedText(suggested_text);
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index 017574e..fc76fb0 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -797,6 +797,10 @@ bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) {
#endif
}
+bool LocationBarView::AcceptCurrentInstantPreview() {
+ return InstantController::CommitIfCurrent(delegate_->GetInstant());
+}
+
void LocationBarView::OnSetSuggestedSearchText(const string16& suggested_text) {
SetSuggestedText(suggested_text);
}
@@ -1062,38 +1066,28 @@ std::string LocationBarView::GetClassName() const {
}
bool LocationBarView::SkipDefaultKeyEventProcessing(const views::KeyEvent& e) {
- if (views::FocusManager::IsTabTraversalKeyEvent(e)) {
#if defined(OS_WIN)
+ if (views::FocusManager::IsTabTraversalKeyEvent(e)) {
if (HasValidSuggestText()) {
// Return true so that the edit sees the tab and commits the suggestion.
return true;
}
-#endif
if (keyword_hint_view_->IsVisible() && !e.IsShiftDown()) {
// Return true so the edit gets the tab event and enters keyword mode.
return true;
}
- InstantController* instant = delegate_->GetInstant();
- if (instant && instant->IsCurrent()) {
- // Tab while showing instant commits instant immediately.
- instant->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER);
- // Return true so that focus traversal isn't attempted. The edit ends
- // up doing nothing in this case.
+
+ // Tab while showing instant commits instant immediately.
+ // Return true so that focus traversal isn't attempted. The edit ends
+ // up doing nothing in this case.
+ if (AcceptCurrentInstantPreview())
return true;
- }
}
-#if defined(OS_WIN)
return location_entry_->SkipDefaultKeyEventProcessing(e);
#else
- // TODO(jcampan): We need to refactor the code of
- // AutocompleteEditViewWin::SkipDefaultKeyEventProcessing into this class so
- // it can be shared between Windows and Linux.
- // For now, we just override back-space and tab keys, as back-space is the
- // accelerator for back navigation and tab key is used by some input methods.
- if (e.GetKeyCode() == app::VKEY_BACK ||
- views::FocusManager::IsTabTraversalKeyEvent(e))
- return true;
+ // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in
+ // src/views/focus/focus_manager.cc for details.
return false;
#endif
}
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index cfda874..317bd78 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -197,6 +197,7 @@ class LocationBarView : public LocationBar,
virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus);
virtual void OnAutocompleteWillAccept();
virtual bool OnCommitSuggestedText(const std::wstring& typed_text);
+ virtual bool AcceptCurrentInstantPreview();
virtual void OnSetSuggestedSearchText(const string16& suggested_text);
virtual void OnPopupBoundsChanged(const gfx::Rect& bounds);
virtual void OnAutocompleteAccept(const GURL& url,
diff --git a/chrome/test/ui_test_utils_linux.cc b/chrome/test/ui_test_utils_linux.cc
index 5f09be7..0692f55 100644
--- a/chrome/test/ui_test_utils_linux.cc
+++ b/chrome/test/ui_test_utils_linux.cc
@@ -89,6 +89,9 @@ void HideNativeWindow(gfx::NativeWindow window) {
}
void ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+ if (gtk_window_has_toplevel_focus(GTK_WINDOW(window)))
+ return;
+
gtk_window_present(GTK_WINDOW(window));
}