Commit f9e09207 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Hide WebContentsView when SadTab is shown, and show them when SadTab is

hidden.

SadTabView is a little unique in that it's a views::View which is
displayed on top of the web viewport. On macOS, this means that the
event system hit tests mouse down events to the inner WebContentsView native
view, instead of the outer BridgedContentView, which is responsible
for passing events into the views subsystem.

WebContentsView, on the other hand, is unaware of views at all, and
has no way of knowing that a sad tab is installed, and it should forward
events up to its superview for routing into the views system.

One way to get around this issue without plumbing through extra event
handling logic is to make it so events on the sad tab view hit test
to the BridgedContentView in the first place by hiding it. This change
facilitates that by propagating NativeViewHost's visibility to the
contained native view.

Bug: 896508
Change-Id: I51875903bc61eb7baef0d58e40c7ca3f6773eecc
Reviewed-on: https://chromium-review.googlesource.com/c/1334087
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609427}
parent e300850a
......@@ -206,6 +206,11 @@ gfx::NativeCursor NativeViewHost::GetCursor(const ui::MouseEvent& event) {
return native_wrapper_->GetCursor(event.x(), event.y());
}
void NativeViewHost::SetVisible(bool visible) {
native_wrapper_->SetVisible(visible);
View::SetVisible(visible);
}
////////////////////////////////////////////////////////////////////////////////
// NativeViewHost, private:
......
......@@ -98,6 +98,7 @@ class VIEWS_EXPORT NativeViewHost : public View {
void OnFocus() override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override;
void SetVisible(bool visible) override;
protected:
bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
......
......@@ -233,6 +233,13 @@ gfx::NativeCursor NativeViewHostAura::GetCursor(int x, int y) {
return gfx::kNullCursor;
}
void NativeViewHostAura::SetVisible(bool visible) {
if (!visible)
host_->native_view()->Hide();
else
host_->native_view()->Show();
}
void NativeViewHostAura::OnWindowBoundsChanged(
aura::Window* window,
const gfx::Rect& old_bounds,
......
......@@ -44,6 +44,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
gfx::NativeView GetNativeViewContainer() const override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
gfx::NativeCursor GetCursor(int x, int y) override;
void SetVisible(bool visible) override;
private:
friend class NativeViewHostAuraTest;
......
......@@ -51,6 +51,7 @@ class NativeViewHostMac : public NativeViewHostWrapper,
gfx::NativeView GetNativeViewContainer() const override;
gfx::NativeViewAccessible GetNativeViewAccessible() override;
gfx::NativeCursor GetCursor(int x, int y) override;
void SetVisible(bool visible) override;
private:
// Return the BridgedNativeWidgetHostImpl for this hosted view.
......
......@@ -261,6 +261,10 @@ gfx::NativeCursor NativeViewHostMac::GetCursor(int x, int y) {
return gfx::kNullCursor;
}
void NativeViewHostMac::SetVisible(bool visible) {
[native_view_ setHidden:!visible];
}
// static
NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
NativeViewHost* host) {
......
......@@ -90,6 +90,11 @@ class NativeViewHostWrapper {
// in the native view.
virtual gfx::NativeCursor GetCursor(int x, int y) = 0;
// Sets the visibility of the gfx::NativeView. This differs from
// {Show,Hide}Widget because it doesn't affect the placement, size,
// or clipping of the view.
virtual void SetVisible(bool visible) = 0;
// Creates a platform-specific instance of an object implementing this
// interface.
static NativeViewHostWrapper* CreateWrapper(NativeViewHost* host);
......
......@@ -129,6 +129,10 @@ void WebView::SetCrashedOverlayView(View* crashed_overlay_view) {
if (crashed_overlay_view_) {
RemoveChildView(crashed_overlay_view_);
// Show the hosted web contents view iff the crashed
// overlay is NOT showing, to ensure hit testing is
// correct on Mac. See https://crbug.com/896508
holder_->SetVisible(true);
if (!crashed_overlay_view_->owned_by_client())
delete crashed_overlay_view_;
}
......@@ -136,6 +140,7 @@ void WebView::SetCrashedOverlayView(View* crashed_overlay_view) {
crashed_overlay_view_ = crashed_overlay_view;
if (crashed_overlay_view_) {
AddChildView(crashed_overlay_view_);
holder_->SetVisible(false);
crashed_overlay_view_->SetBoundsRect(gfx::Rect(size()));
}
......
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