Commit 37470a6d authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Focus tab contents after drag-and-drop.

It is desirable (see https://crbug.com/1031119) to focus tab contents
when a navigation is triggered by dropping a link or a file onto the
browser window.

Before this CL, tab contents would be focused any time the OpenURL code
path is used, but not in BeginNavigation code path.  This meant that
dropping a local file (e.g. navigating to a file: URL) would result
in focusing the tab contents (possibly moving the focus away from the
omnibox), but other navigations (e.g. navigating to a https: URL)
would not affect focus.

After this CL any "drop" focuses the WebContents.

Bug: 1042271
Change-Id: Ib1db79faec6e32846747d1cde9a78450dc354b42
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003079Reviewed-by: default avatarCharlie Reis <creis@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734245}
parent 3d05e15b
......@@ -21,8 +21,10 @@
#include "base/threading/sequenced_task_runner_handle.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
......@@ -815,8 +817,9 @@ IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DropTextFromOutside) {
#define MAYBE_DropValidUrlFromOutside DropValidUrlFromOutside
#endif
// Scenario: drag URL from outside the browser and drop to the right frame.
// Mostly focuses on covering the navigation path (the dragover and/or drop DOM
// events are already covered via the DropTextFromOutside test above).
// Mostly focuses on covering 1) the navigation path, 2) focus behavior. This
// test explicitly does not cover the dragover and/or drop DOM events - they are
// already covered via the DropTextFromOutside test above.
IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DropValidUrlFromOutside) {
std::string frame_site = use_cross_site_subframe() ? "b.com" : "a.com";
ASSERT_TRUE(NavigateToTestPage("a.com"));
......@@ -826,6 +829,11 @@ IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DropValidUrlFromOutside) {
content::NavigationController& controller = web_contents->GetController();
int initial_history_count = controller.GetEntryCount();
// Focus the omnibox.
chrome::FocusLocationBar(browser());
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
// Drag a normal URL from outside the browser into/over the right frame.
GURL dragged_url = embedded_test_server()->GetURL("d.com", "/title2.html");
ASSERT_TRUE(SimulateDragEnterToRightFrame(dragged_url));
......@@ -839,6 +847,10 @@ IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DropValidUrlFromOutside) {
nav_observer.Wait();
EXPECT_EQ(dragged_url, web_contents->GetMainFrame()->GetLastCommittedURL());
EXPECT_EQ(initial_history_count + 1, controller.GetEntryCount());
// Verify that the focus moved from the omnibox to the tab contents.
EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER));
}
#if defined(OS_WIN) || defined(OS_LINUX) || defined(THREAD_SANITIZER)
......
......@@ -480,6 +480,7 @@ void WebContentsViewAndroid::OnDragExited() {
void WebContentsViewAndroid::OnPerformDrop(DropData* drop_data,
const gfx::PointF& location,
const gfx::PointF& screen_location) {
web_contents_->Focus();
web_contents_->GetRenderViewHost()->GetWidget()->FilterDropData(drop_data);
web_contents_->GetRenderViewHost()->GetWidget()->DragTargetDrop(
*drop_data, location, screen_location, 0);
......
......@@ -1535,6 +1535,8 @@ void WebContentsViewAura::CompleteDrop(RenderWidgetHostImpl* target_rwh,
const gfx::PointF& client_pt,
const gfx::PointF& screen_pt,
int key_modifiers) {
web_contents_->Focus();
target_rwh->DragTargetDrop(drop_data, client_pt, screen_pt, key_modifiers);
if (drag_dest_delegate_)
drag_dest_delegate_->OnDrop();
......
......@@ -313,6 +313,7 @@ content::GlobalRoutingID GetRenderViewHostID(content::RenderViewHost* rvh) {
_currentRVH = NULL;
_webContents->Focus();
targetRWH->DragTargetDrop(*_dropDataFiltered, transformedPt,
info->location_in_screen, GetModifierFlags());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment