Commit 3be76f04 authored by Brian Liu Xu's avatar Brian Liu Xu Committed by Commit Bot

Dismiss tooltips from web content when web content is occluded or hidden

Hides tooltips from web content when the Chrome_RenderWidgetHostHWND is
being reparented on Windows.

Normally, mouse input messages over the Chrome_RenderWidgetHostHWND are
forwarded to the host window, where they are processed as events and
used by the tooltip controller to manage tooltip visibility.

However, when the legacy Chrome_RenderWidgetHostHWND is hidden or
occluded, it is reparented to a global hidden window, and messages are
no longer forwarded to the host window. If a WM_MOUSELEAVE message did
not arrive before this happens, the tooltip controller would not handle
it, and any open tooltips would stay open. Thus, we must explicitly
close tooltips during this reparenting step.

Bug: 724538
Change-Id: I4e4273ed451ff97c49b146e6b0499db3951baf88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2242951Reviewed-by: default avatarScott Violet <sky@chromium.org>
Auto-Submit: Brian Liu Xu <brx@microsoft.com>
Commit-Queue: Brian Liu Xu <brx@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#803984}
parent 115bb20e
...@@ -83,6 +83,10 @@ void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) { ...@@ -83,6 +83,10 @@ void LegacyRenderWidgetHostHWND::UpdateParent(HWND parent) {
direct_manipulation_helper_ = DirectManipulationHelper::CreateInstance( direct_manipulation_helper_ = DirectManipulationHelper::CreateInstance(
hwnd(), host_->GetNativeView()->GetHost()->compositor(), hwnd(), host_->GetNativeView()->GetHost()->compositor(),
GetWindowEventTarget(GetParent())); GetWindowEventTarget(GetParent()));
// Reset tooltips when parent changed; otherwise tooltips could stay open as
// the former parent wouldn't be forwarded any mouse leave messages.
host_->DisplayTooltipText(base::string16());
} }
HWND LegacyRenderWidgetHostHWND::GetParent() { HWND LegacyRenderWidgetHostHWND::GetParent() {
......
...@@ -464,6 +464,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura ...@@ -464,6 +464,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
DiscardDelegatedFrames); DiscardDelegatedFrames);
FRIEND_TEST_ALL_PREFIXES(SitePerProcessHitTestBrowserTest, FRIEND_TEST_ALL_PREFIXES(SitePerProcessHitTestBrowserTest,
ScrollOOPIFEditableElement); ScrollOOPIFEditableElement);
FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, OcclusionHidesTooltip);
class WindowObserver; class WindowObserver;
friend class WindowObserver; friend class WindowObserver;
......
...@@ -129,6 +129,8 @@ ...@@ -129,6 +129,8 @@
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
#include "ui/base/view_prop.h"
#include "ui/base/win/window_event_target.h"
#include "ui/display/win/test/scoped_screen_win.h" #include "ui/display/win/test/scoped_screen_win.h"
#endif #endif
...@@ -5297,6 +5299,109 @@ TEST_F(RenderWidgetHostViewAuraTest, ForwardMouseEvent) { ...@@ -5297,6 +5299,109 @@ TEST_F(RenderWidgetHostViewAuraTest, ForwardMouseEvent) {
view_ = nullptr; view_ = nullptr;
} }
#if defined(OS_WIN)
class MockWindowEventTarget : public ui::WindowEventTarget {
public:
MockWindowEventTarget() = default;
LRESULT HandleMouseMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandlePointerMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandleKeyboardMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandleTouchMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandleInputMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandleScrollMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
LRESULT HandleNcHitTestMessage(unsigned int message,
WPARAM w_param,
LPARAM l_param,
bool* handled) override {
return S_OK;
}
void HandleParentChanged() override {}
void ApplyPinchZoomScale(float scale) override {}
void ApplyPinchZoomBegin() override {}
void ApplyPinchZoomEnd() override {}
void ApplyPanGestureScroll(int scroll_x, int scroll_y) override {}
void ApplyPanGestureFling(int scroll_x, int scroll_y) override {}
void ApplyPanGestureScrollBegin(int scroll_x, int scroll_y) override {}
void ApplyPanGestureFlingBegin() override {}
void ApplyPanGestureFlingEnd() override {}
void ApplyPanGestureScrollEnd(bool tranisitioning_to_pinch) override {}
private:
DISALLOW_COPY_AND_ASSIGN(MockWindowEventTarget);
};
// On Windows, a native HWND (Chrome_RenderWidgetHostHWND) forwards mouse events
// to the browser window so that they can reach the tooltip controller. Since we
// reparent this HWND when the view is occluded, some mouse exits might not be
// forwarded, resulting in stuck tooltips. Test that tooltips are cleared.
TEST_F(RenderWidgetHostViewAuraTest, OcclusionHidesTooltip) {
// Give the host window an event target, which allows the view to create the
// Chrome_RenderWidgetHostHWND window.
MockWindowEventTarget event_target;
auto prop_window_target = std::make_unique<ui::ViewProp>(
parent_view_->GetHostWindowHWND(),
ui::WindowEventTarget::kWin32InputEventTarget,
static_cast<ui::WindowEventTarget*>(&event_target));
// Initialize the view.
view_->InitAsChild(nullptr);
aura::client::ParentWindowWithContext(
view_->GetNativeView(), parent_view_->GetNativeView()->GetRootWindow(),
gfx::Rect());
view_->Show();
EXPECT_TRUE(view_->UsesNativeWindowFrame());
// Simulate a tooltip.
base::string16 tooltip_text(base::ASCIIToUTF16("The tooltip!"));
view_->SetTooltipText(tooltip_text);
EXPECT_FALSE(widget_host_->is_hidden());
EXPECT_EQ(tooltip_text, view_->tooltip_);
// Simulate occlusion, which should clear the tooltip.
view_->WasOccluded();
EXPECT_TRUE(widget_host_->is_hidden());
EXPECT_EQ(base::string16(), view_->tooltip_);
}
#endif
class TouchpadRenderWidgetHostViewAuraTest class TouchpadRenderWidgetHostViewAuraTest
: public base::test::WithFeatureOverride, : public base::test::WithFeatureOverride,
public RenderWidgetHostViewAuraTest { public RenderWidgetHostViewAuraTest {
......
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