Commit 739f7f62 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Fix context menus

This fix has two parts.

First, call -[NSView addSubview:] in views::NativeViewHostMac, instead
of calling it in views::BridgedNativeWidgetHostImpl. This will set up
the browser-side NSView hierarchy, even when the browser-side NSViews
are not visible (because the app-side NSViews are).

Second, in BridgedNativeWidgetHostImpl::OnWindowGeometryChanged, update
the geometry of the browser-side doppelganger NSWindow to match the
geometry of the app-side true NSWindow. This ensures that the context
menu appears in the right place.

Both of these fixes are band-aids on the larger issue that we should
change the gfx::NativeView and gfx::NativeWindow types to be a wrapper
interface that will clearly delineate the where the native types
are actually manipulated, and where the native types are just plumbed
through.

Bug: 859152
Change-Id: I8428166dd889f45888432220be70de340574c385
Reviewed-on: https://chromium-review.googlesource.com/c/1263592Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597174}
parent 25ad0fbc
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ui/compositor/recyclable_compositor_mac.h" #include "ui/compositor/recyclable_compositor_mac.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/geometry/dip_util.h"
#include "ui/gfx/mac/coordinate_conversion.h"
#include "ui/native_theme/native_theme_mac.h" #include "ui/native_theme/native_theme_mac.h"
#include "ui/views/cocoa/tooltip_manager_mac.h" #include "ui/views/cocoa/tooltip_manager_mac.h"
#include "ui/views/controls/menu/menu_config.h" #include "ui/views/controls/menu/menu_config.h"
...@@ -398,13 +399,6 @@ void* BridgedNativeWidgetHostImpl::GetNativeWindowProperty( ...@@ -398,13 +399,6 @@ void* BridgedNativeWidgetHostImpl::GetNativeWindowProperty(
void BridgedNativeWidgetHostImpl::SetAssociationForView(const View* view, void BridgedNativeWidgetHostImpl::SetAssociationForView(const View* view,
NSView* native_view) { NSView* native_view) {
// TODO(ccameron): For the case of out-of-process NSWindows, it will be
// necessary to:
// - migrate |native_view| to the new process (for web contents).
// - use a dummy parent window if |native_view| is perforce in this process.
if (bridge_impl_)
[bridge_impl_->ns_view() addSubview:native_view];
DCHECK_EQ(0u, associated_views_.count(view)); DCHECK_EQ(0u, associated_views_.count(view));
associated_views_[view] = native_view; associated_views_[view] = native_view;
native_widget_mac_->GetWidget()->ReorderNativeViews(); native_widget_mac_->GetWidget()->ReorderNativeViews();
...@@ -639,6 +633,16 @@ bool BridgedNativeWidgetHostImpl::GetIsFocusedViewTextual(bool* is_textual) { ...@@ -639,6 +633,16 @@ bool BridgedNativeWidgetHostImpl::GetIsFocusedViewTextual(bool* is_textual) {
void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged( void BridgedNativeWidgetHostImpl::OnWindowGeometryChanged(
const gfx::Rect& new_window_bounds_in_screen, const gfx::Rect& new_window_bounds_in_screen,
const gfx::Rect& new_content_bounds_in_screen) { const gfx::Rect& new_content_bounds_in_screen) {
// If we are accessing the BridgedNativeWidget through mojo, then
// |local_window_| is not the true window that was just resized. Update
// the frame of |local_window_| to keep it in sync for any native calls
// that may use it (e.g, for context menu positioning).
if (bridge_ptr_) {
[local_window_ setFrame:gfx::ScreenRectToNSRect(new_window_bounds_in_screen)
display:NO
animate:NO];
}
bool window_has_moved = bool window_has_moved =
new_window_bounds_in_screen.origin() != window_bounds_in_screen_.origin(); new_window_bounds_in_screen.origin() != window_bounds_in_screen_.origin();
bool content_has_resized = bool content_has_resized =
......
...@@ -116,6 +116,7 @@ void NativeViewHostMac::AttachNativeView() { ...@@ -116,6 +116,7 @@ void NativeViewHostMac::AttachNativeView() {
auto* bridge_host = GetBridgedNativeWidgetHost(); auto* bridge_host = GetBridgedNativeWidgetHost();
DCHECK(bridge_host); DCHECK(bridge_host);
[bridge_host->native_widget_mac()->GetNativeView() addSubview:native_view_];
bridge_host->SetAssociationForView(host_, native_view_); bridge_host->SetAssociationForView(host_, native_view_);
if ([native_view_ conformsToProtocol:@protocol(ViewsHostable)]) { if ([native_view_ conformsToProtocol:@protocol(ViewsHostable)]) {
......
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