Commit 1dd87306 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

RemoteMacViews: Remove NativeWidgetMac refs from BridgedNativeWidgetImpl

Pass the "is widget top level" parameter at BridgedNativeWidgetImpl init
rather than querying it from the NativeWidgetMac.

Remove the NativeWidgetMac member and accessor from
BridgedNativeWidgetImpl.

Move NativeWidgetMac::GetBridge[Host]ImplForNativeWindow to
BridgedNativeWidget[Host]Impl::GetFromNativeWindow (since there's no
reason to require going through NativeWidgetMac).

Change-Id: I1ed0753acc21dc45e8ed8fbe893b83e30c6abe34
Reviewed-on: https://chromium-review.googlesource.com/1217516
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590463}
parent d1ade8c4
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/views/cocoa/bridged_native_widget.h" #include "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/widget/native_widget_mac.h"
@implementation FullscreenToolbarControllerViews @implementation FullscreenToolbarControllerViews
...@@ -28,7 +27,7 @@ ...@@ -28,7 +27,7 @@
- (BOOL)isFullscreenTransitionInProgress { - (BOOL)isFullscreenTransitionInProgress {
views::BridgedNativeWidgetImpl* bridge_widget = views::BridgedNativeWidgetImpl* bridge_widget =
views::NativeWidgetMac::GetBridgeImplForNativeWindow([self window]); views::BridgedNativeWidgetImpl::GetFromNativeWindow([self window]);
return bridge_widget->in_fullscreen_transition(); return bridge_widget->in_fullscreen_transition();
} }
...@@ -36,7 +35,7 @@ ...@@ -36,7 +35,7 @@
NSWindow* ns_window = browserView_->GetNativeWindow(); NSWindow* ns_window = browserView_->GetNativeWindow();
if (!ns_view_) { if (!ns_view_) {
ns_view_.reset( ns_view_.reset(
[views::NativeWidgetMac::GetBridgeImplForNativeWindow(ns_window) [views::BridgedNativeWidgetImpl::GetFromNativeWindow(ns_window)
->ns_view() retain]); ->ns_view() retain]);
} }
return ns_window; return ns_window;
......
...@@ -44,7 +44,6 @@ class BridgedNativeWidgetHostHelper; ...@@ -44,7 +44,6 @@ class BridgedNativeWidgetHostHelper;
class CocoaMouseCapture; class CocoaMouseCapture;
class CocoaWindowMoveLoop; class CocoaWindowMoveLoop;
class DragDropClientMac; class DragDropClientMac;
class NativeWidgetMac;
class View; class View;
using views_bridge_mac::mojom::BridgedNativeWidgetHost; using views_bridge_mac::mojom::BridgedNativeWidgetHost;
...@@ -64,14 +63,17 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl ...@@ -64,14 +63,17 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl
static gfx::Size GetWindowSizeForClientSize(NSWindow* window, static gfx::Size GetWindowSizeForClientSize(NSWindow* window,
const gfx::Size& size); const gfx::Size& size);
// Retrieves the bridge associated with the given NSWindow. Returns null if
// the supplied handle has no associated Widget.
static BridgedNativeWidgetImpl* GetFromNativeWindow(NSWindow* window);
// Retrieve a BridgedNativeWidgetImpl* from its id. // Retrieve a BridgedNativeWidgetImpl* from its id.
static BridgedNativeWidgetImpl* GetFromId(uint64_t bridged_native_widget_id); static BridgedNativeWidgetImpl* GetFromId(uint64_t bridged_native_widget_id);
// Creates one side of the bridge. |host| and |parent| must not be NULL. // Creates one side of the bridge. |host| and |parent| must not be NULL.
BridgedNativeWidgetImpl(uint64_t bridged_native_widget_id, BridgedNativeWidgetImpl(uint64_t bridged_native_widget_id,
BridgedNativeWidgetHost* host, BridgedNativeWidgetHost* host,
BridgedNativeWidgetHostHelper* host_helper, BridgedNativeWidgetHostHelper* host_helper);
NativeWidgetMac* parent);
~BridgedNativeWidgetImpl() override; ~BridgedNativeWidgetImpl() override;
// Initialize the NSWindow by taking ownership of the specified object. // Initialize the NSWindow by taking ownership of the specified object.
...@@ -151,7 +153,6 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl ...@@ -151,7 +153,6 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl
// Sort child NSViews according to their ranking in |rank|. // Sort child NSViews according to their ranking in |rank|.
void SortSubviews(std::map<NSView*, int> rank); void SortSubviews(std::map<NSView*, int> rank);
NativeWidgetMac* native_widget_mac() { return native_widget_mac_; }
BridgedContentView* ns_view() { return bridged_view_; } BridgedContentView* ns_view() { return bridged_view_; }
BridgedNativeWidgetHost* host() { return host_; } BridgedNativeWidgetHost* host() { return host_; }
BridgedNativeWidgetHostHelper* host_helper() { return host_helper_; } BridgedNativeWidgetHostHelper* host_helper() { return host_helper_; }
...@@ -283,7 +284,6 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl ...@@ -283,7 +284,6 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl
const uint64_t id_; const uint64_t id_;
BridgedNativeWidgetHost* const host_; // Weak. Owns this. BridgedNativeWidgetHost* const host_; // Weak. Owns this.
BridgedNativeWidgetHostHelper* const host_helper_; // Weak, owned by |host_|. BridgedNativeWidgetHostHelper* const host_helper_; // Weak, owned by |host_|.
NativeWidgetMac* const native_widget_mac_; // Weak. Owns |host_|.
base::scoped_nsobject<NativeWidgetMacNSWindow> window_; base::scoped_nsobject<NativeWidgetMacNSWindow> window_;
base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_;
base::scoped_nsobject<BridgedContentView> bridged_view_; base::scoped_nsobject<BridgedContentView> bridged_view_;
...@@ -293,6 +293,7 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl ...@@ -293,6 +293,7 @@ class VIEWS_EXPORT BridgedNativeWidgetImpl
std::unique_ptr<DragDropClientMac> drag_drop_client_; std::unique_ptr<DragDropClientMac> drag_drop_client_;
ui::ModalType modal_type_ = ui::MODAL_TYPE_NONE; ui::ModalType modal_type_ = ui::MODAL_TYPE_NONE;
bool is_translucent_window_ = false; bool is_translucent_window_ = false;
bool widget_is_top_level_ = false;
BridgedNativeWidgetOwner* parent_ = nullptr; // Weak. If non-null, owns this. BridgedNativeWidgetOwner* parent_ = nullptr; // Weak. If non-null, owns this.
std::vector<BridgedNativeWidgetImpl*> child_windows_; std::vector<BridgedNativeWidgetImpl*> child_windows_;
......
...@@ -34,8 +34,6 @@ ...@@ -34,8 +34,6 @@
#import "ui/views/cocoa/native_widget_mac_nswindow.h" #import "ui/views/cocoa/native_widget_mac_nswindow.h"
#import "ui/views/cocoa/views_nswindow_delegate.h" #import "ui/views/cocoa/views_nswindow_delegate.h"
#import "ui/views/cocoa/widget_owner_nswindow_adapter.h" #import "ui/views/cocoa/widget_owner_nswindow_adapter.h"
#include "ui/views/widget/native_widget_mac.h"
#include "ui/views/widget/widget.h"
#include "ui/views_bridge_mac/mojo/bridged_native_widget_host.mojom.h" #include "ui/views_bridge_mac/mojo/bridged_native_widget_host.mojom.h"
using views_bridge_mac::mojom::WindowVisibilityState; using views_bridge_mac::mojom::WindowVisibilityState;
...@@ -232,6 +230,16 @@ gfx::Size BridgedNativeWidgetImpl::GetWindowSizeForClientSize( ...@@ -232,6 +230,16 @@ gfx::Size BridgedNativeWidgetImpl::GetWindowSizeForClientSize(
return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)); return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect));
} }
// static
BridgedNativeWidgetImpl* BridgedNativeWidgetImpl::GetFromNativeWindow(
gfx::NativeWindow window) {
if (NativeWidgetMacNSWindow* widget_window =
base::mac::ObjCCast<NativeWidgetMacNSWindow>(window)) {
return GetFromId([widget_window bridgedNativeWidgetId]);
}
return nullptr; // Not created by NativeWidgetMac.
}
// static // static
BridgedNativeWidgetImpl* BridgedNativeWidgetImpl::GetFromId( BridgedNativeWidgetImpl* BridgedNativeWidgetImpl::GetFromId(
uint64_t bridged_native_widget_id) { uint64_t bridged_native_widget_id) {
...@@ -244,15 +252,10 @@ BridgedNativeWidgetImpl* BridgedNativeWidgetImpl::GetFromId( ...@@ -244,15 +252,10 @@ BridgedNativeWidgetImpl* BridgedNativeWidgetImpl::GetFromId(
BridgedNativeWidgetImpl::BridgedNativeWidgetImpl( BridgedNativeWidgetImpl::BridgedNativeWidgetImpl(
uint64_t bridged_native_widget_id, uint64_t bridged_native_widget_id,
BridgedNativeWidgetHost* host, BridgedNativeWidgetHost* host,
BridgedNativeWidgetHostHelper* host_helper, BridgedNativeWidgetHostHelper* host_helper)
NativeWidgetMac* parent) : id_(bridged_native_widget_id), host_(host), host_helper_(host_helper) {
: id_(bridged_native_widget_id),
host_(host),
host_helper_(host_helper),
native_widget_mac_(parent) {
DCHECK(GetIdToWidgetImplMap().find(id_) == GetIdToWidgetImplMap().end()); DCHECK(GetIdToWidgetImplMap().find(id_) == GetIdToWidgetImplMap().end());
GetIdToWidgetImplMap().insert(std::make_pair(id_, this)); GetIdToWidgetImplMap().insert(std::make_pair(id_, this));
DCHECK(parent);
} }
BridgedNativeWidgetImpl::~BridgedNativeWidgetImpl() { BridgedNativeWidgetImpl::~BridgedNativeWidgetImpl() {
...@@ -287,7 +290,7 @@ void BridgedNativeWidgetImpl::SetWindow( ...@@ -287,7 +290,7 @@ void BridgedNativeWidgetImpl::SetWindow(
void BridgedNativeWidgetImpl::SetParent(NSView* new_parent) { void BridgedNativeWidgetImpl::SetParent(NSView* new_parent) {
BridgedNativeWidgetImpl* bridged_native_widget_parent = BridgedNativeWidgetImpl* bridged_native_widget_parent =
NativeWidgetMac::GetBridgeImplForNativeWindow([new_parent window]); BridgedNativeWidgetImpl::GetFromNativeWindow([new_parent window]);
// Remove from the old parent. // Remove from the old parent.
if (parent_) { if (parent_) {
parent_->RemoveChildWindow(this); parent_->RemoveChildWindow(this);
...@@ -323,6 +326,7 @@ void BridgedNativeWidgetImpl::InitWindow( ...@@ -323,6 +326,7 @@ void BridgedNativeWidgetImpl::InitWindow(
views_bridge_mac::mojom::BridgedNativeWidgetInitParamsPtr params) { views_bridge_mac::mojom::BridgedNativeWidgetInitParamsPtr params) {
modal_type_ = params->modal_type; modal_type_ = params->modal_type;
is_translucent_window_ = params->is_translucent; is_translucent_window_ = params->is_translucent;
widget_is_top_level_ = params->widget_is_top_level;
// Register for application hide notifications so that visibility can be // Register for application hide notifications so that visibility can be
// properly tracked. This is not done in the delegate so that the lifetime is // properly tracked. This is not done in the delegate so that the lifetime is
...@@ -902,7 +906,7 @@ void BridgedNativeWidgetImpl::ReparentNativeView(NSView* native_view, ...@@ -902,7 +906,7 @@ void BridgedNativeWidgetImpl::ReparentNativeView(NSView* native_view,
DCHECK(window_ && ![window_ isSheet]); DCHECK(window_ && ![window_ isSheet]);
BridgedNativeWidgetImpl* parent_bridge = BridgedNativeWidgetImpl* parent_bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow([new_parent window]); BridgedNativeWidgetImpl::GetFromNativeWindow([new_parent window]);
if (native_view == bridged_view_.get() && parent_bridge != parent_) { if (native_view == bridged_view_.get() && parent_bridge != parent_) {
SetParent(new_parent); SetParent(new_parent);
...@@ -913,8 +917,7 @@ void BridgedNativeWidgetImpl::ReparentNativeView(NSView* native_view, ...@@ -913,8 +917,7 @@ void BridgedNativeWidgetImpl::ReparentNativeView(NSView* native_view,
[[new_parent window] addChildWindow:window_ ordered:NSWindowAbove]; [[new_parent window] addChildWindow:window_ ordered:NSWindowAbove];
} }
if (!native_widget_mac_->GetWidget()->is_top_level() || if (!widget_is_top_level_ || native_view != bridged_view_.get()) {
native_view != bridged_view_.get()) {
// Make native_view be a child of new_parent by adding it as a subview. // Make native_view be a child of new_parent by adding it as a subview.
// The window_ must remain visible because it controls the bounds and // The window_ must remain visible because it controls the bounds and
// visibility of the ui::Layer. So just hide it by setting alpha value to // visibility of the ui::Layer. So just hide it by setting alpha value to
......
...@@ -46,6 +46,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -46,6 +46,11 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
public ui::LayerOwner, public ui::LayerOwner,
public ui::AcceleratedWidgetMacNSView { public ui::AcceleratedWidgetMacNSView {
public: public:
// Retrieves the bridge host associated with the given NSWindow. Returns null
// if the supplied handle has no associated Widget.
static BridgedNativeWidgetHostImpl* GetFromNativeWindow(
gfx::NativeWindow window);
// Unique integer id handles are used to bridge between the // Unique integer id handles are used to bridge between the
// BridgedNativeWidgetHostImpl in one process and the BridgedNativeWidgetHost // BridgedNativeWidgetHostImpl in one process and the BridgedNativeWidgetHost
// potentially in another. // potentially in another.
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/views/cocoa/bridged_native_widget_host_impl.h" #include "ui/views/cocoa/bridged_native_widget_host_impl.h"
#include "base/mac/foundation_util.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h" #include "ui/base/ime/input_method_factory.h"
...@@ -12,6 +13,7 @@ ...@@ -12,6 +13,7 @@
#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/views/cocoa/bridged_native_widget.h" #include "ui/views/cocoa/bridged_native_widget.h"
#include "ui/views/cocoa/native_widget_mac_nswindow.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"
#include "ui/views/controls/menu/menu_controller.h" #include "ui/views/controls/menu/menu_controller.h"
...@@ -51,6 +53,16 @@ uint64_t g_last_bridged_native_widget_id = 0; ...@@ -51,6 +53,16 @@ uint64_t g_last_bridged_native_widget_id = 0;
} // namespace } // namespace
// static
BridgedNativeWidgetHostImpl* BridgedNativeWidgetHostImpl::GetFromNativeWindow(
gfx::NativeWindow window) {
if (NativeWidgetMacNSWindow* widget_window =
base::mac::ObjCCast<NativeWidgetMacNSWindow>(window)) {
return GetFromId([widget_window bridgedNativeWidgetId]);
}
return nullptr; // Not created by NativeWidgetMac.
}
// static // static
BridgedNativeWidgetHostImpl* BridgedNativeWidgetHostImpl::GetFromId( BridgedNativeWidgetHostImpl* BridgedNativeWidgetHostImpl::GetFromId(
uint64_t bridged_native_widget_id) { uint64_t bridged_native_widget_id) {
...@@ -64,10 +76,11 @@ BridgedNativeWidgetHostImpl::BridgedNativeWidgetHostImpl( ...@@ -64,10 +76,11 @@ BridgedNativeWidgetHostImpl::BridgedNativeWidgetHostImpl(
NativeWidgetMac* parent) NativeWidgetMac* parent)
: id_(++g_last_bridged_native_widget_id), : id_(++g_last_bridged_native_widget_id),
native_widget_mac_(parent), native_widget_mac_(parent),
bridge_impl_(new BridgedNativeWidgetImpl(id_, this, this, parent)) { bridge_impl_(new BridgedNativeWidgetImpl(id_, this, this)) {
DCHECK(GetIdToWidgetHostImplMap().find(id_) == DCHECK(GetIdToWidgetHostImplMap().find(id_) ==
GetIdToWidgetHostImplMap().end()); GetIdToWidgetHostImplMap().end());
GetIdToWidgetHostImplMap().insert(std::make_pair(id_, this)); GetIdToWidgetHostImplMap().insert(std::make_pair(id_, this));
GetIdToWidgetHostImplMap().insert(std::make_pair(id_, this));
DCHECK(parent); DCHECK(parent);
} }
...@@ -108,6 +121,8 @@ void BridgedNativeWidgetHostImpl::InitWindow(const Widget::InitParams& params) { ...@@ -108,6 +121,8 @@ void BridgedNativeWidgetHostImpl::InitWindow(const Widget::InitParams& params) {
native_widget_mac_->GetWidget()->widget_delegate()->GetModalType(); native_widget_mac_->GetWidget()->widget_delegate()->GetModalType();
bridge_params->is_translucent = bridge_params->is_translucent =
params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW; params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW;
bridge_params->widget_is_top_level =
native_widget_mac_->GetWidget()->is_top_level();
// OSX likes to put shadows on most things. However, frameless windows (with // OSX likes to put shadows on most things. However, frameless windows (with
// styleMask = NSBorderlessWindowMask) default to no shadow. So change that. // styleMask = NSBorderlessWindowMask) default to no shadow. So change that.
......
...@@ -186,9 +186,9 @@ class DragDropClientMacTest : public WidgetTest { ...@@ -186,9 +186,9 @@ class DragDropClientMacTest : public WidgetTest {
gfx::Rect bounds(0, 0, 100, 100); gfx::Rect bounds(0, 0, 100, 100);
widget_->SetBounds(bounds); widget_->SetBounds(bounds);
bridge_ = NativeWidgetMac::GetBridgeImplForNativeWindow( bridge_ = BridgedNativeWidgetImpl::GetFromNativeWindow(
widget_->GetNativeWindow()); widget_->GetNativeWindow());
bridge_host_ = NativeWidgetMac::GetBridgeHostImplForNativeWindow( bridge_host_ = BridgedNativeWidgetHostImpl::GetFromNativeWindow(
widget_->GetNativeWindow()); widget_->GetNativeWindow());
widget_->Show(); widget_->Show();
......
...@@ -94,7 +94,7 @@ void NativeViewHostMac::AttachNativeView() { ...@@ -94,7 +94,7 @@ void NativeViewHostMac::AttachNativeView() {
EnsureNativeViewHasNoChildWidgets(native_view_); EnsureNativeViewHasNoChildWidgets(native_view_);
BridgedNativeWidgetHostImpl* bridge_host = BridgedNativeWidgetHostImpl* bridge_host =
NativeWidgetMac::GetBridgeHostImplForNativeWindow( BridgedNativeWidgetHostImpl::GetFromNativeWindow(
host_->GetWidget()->GetNativeWindow()); host_->GetWidget()->GetNativeWindow());
DCHECK(bridge_host); DCHECK(bridge_host);
bridge_host->SetAssociationForView(host_, native_view_); bridge_host->SetAssociationForView(host_, native_view_);
...@@ -127,7 +127,7 @@ void NativeViewHostMac::NativeViewDetaching(bool destroyed) { ...@@ -127,7 +127,7 @@ void NativeViewHostMac::NativeViewDetaching(bool destroyed) {
EnsureNativeViewHasNoChildWidgets(host_->native_view()); EnsureNativeViewHasNoChildWidgets(host_->native_view());
BridgedNativeWidgetHostImpl* bridge_host = BridgedNativeWidgetHostImpl* bridge_host =
NativeWidgetMac::GetBridgeHostImplForNativeWindow( BridgedNativeWidgetHostImpl::GetFromNativeWindow(
host_->GetWidget()->GetNativeWindow()); host_->GetWidget()->GetNativeWindow());
// BridgedNativeWidgetImpl can be null when Widget is closing. // BridgedNativeWidgetImpl can be null when Widget is closing.
if (bridge_host) if (bridge_host)
......
...@@ -82,10 +82,8 @@ ui::EventSink* WidgetTest::GetEventSink(Widget* widget) { ...@@ -82,10 +82,8 @@ ui::EventSink* WidgetTest::GetEventSink(Widget* widget) {
// static // static
ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget( ui::internal::InputMethodDelegate* WidgetTest::GetInputMethodDelegateForWidget(
Widget* widget) { Widget* widget) {
return NativeWidgetMac::GetBridgeImplForNativeWindow( return BridgedNativeWidgetHostImpl::GetFromNativeWindow(
widget->GetNativeWindow()) widget->GetNativeWindow());
->native_widget_mac()
->bridge_host_for_testing();
} }
// static // static
......
...@@ -36,13 +36,6 @@ class VIEWS_EXPORT NativeWidgetMac : public internal::NativeWidgetPrivate { ...@@ -36,13 +36,6 @@ class VIEWS_EXPORT NativeWidgetMac : public internal::NativeWidgetPrivate {
explicit NativeWidgetMac(internal::NativeWidgetDelegate* delegate); explicit NativeWidgetMac(internal::NativeWidgetDelegate* delegate);
~NativeWidgetMac() override; ~NativeWidgetMac() override;
// Retrieves the bridge associated with the given NSWindow. Returns null if
// the supplied handle has no associated Widget.
static BridgedNativeWidgetHostImpl* GetBridgeHostImplForNativeWindow(
gfx::NativeWindow window);
static BridgedNativeWidgetImpl* GetBridgeImplForNativeWindow(
gfx::NativeWindow window);
// Informs |delegate_| that the native widget is about to be destroyed. // Informs |delegate_| that the native widget is about to be destroyed.
// BridgedNativeWidgetImpl::OnWindowWillClose() invokes this early when the // BridgedNativeWidgetImpl::OnWindowWillClose() invokes this early when the
// NSWindowDelegate informs the bridge that the window is being closed (later, // NSWindowDelegate informs the bridge that the window is being closed (later,
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -81,28 +80,6 @@ NativeWidgetMac::~NativeWidgetMac() { ...@@ -81,28 +80,6 @@ NativeWidgetMac::~NativeWidgetMac() {
CloseNow(); CloseNow();
} }
// static
BridgedNativeWidgetImpl* NativeWidgetMac::GetBridgeImplForNativeWindow(
gfx::NativeWindow window) {
if (NativeWidgetMacNSWindow* widget_window =
base::mac::ObjCCast<NativeWidgetMacNSWindow>(window)) {
return BridgedNativeWidgetImpl::GetFromId(
[widget_window bridgedNativeWidgetId]);
}
return nullptr; // Not created by NativeWidgetMac.
}
// static
BridgedNativeWidgetHostImpl* NativeWidgetMac::GetBridgeHostImplForNativeWindow(
gfx::NativeWindow window) {
if (NativeWidgetMacNSWindow* widget_window =
base::mac::ObjCCast<NativeWidgetMacNSWindow>(window)) {
return BridgedNativeWidgetHostImpl::GetFromId(
[widget_window bridgedNativeWidgetId]);
}
return nullptr; // Not created by NativeWidgetMac.
}
void NativeWidgetMac::WindowDestroying() { void NativeWidgetMac::WindowDestroying() {
OnWindowDestroying(GetNativeWindow()); OnWindowDestroying(GetNativeWindow());
delegate_->OnNativeWidgetDestroying(); delegate_->OnNativeWidgetDestroying();
...@@ -694,7 +671,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView( ...@@ -694,7 +671,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeView(
NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
gfx::NativeWindow window) { gfx::NativeWindow window) {
if (BridgedNativeWidgetHostImpl* bridge_host_impl = if (BridgedNativeWidgetHostImpl* bridge_host_impl =
NativeWidgetMac::GetBridgeHostImplForNativeWindow(window)) { BridgedNativeWidgetHostImpl::GetFromNativeWindow(window)) {
return bridge_host_impl->native_widget_mac(); return bridge_host_impl->native_widget_mac();
} }
return nullptr; // Not created by NativeWidgetMac. return nullptr; // Not created by NativeWidgetMac.
...@@ -704,7 +681,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow( ...@@ -704,7 +681,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetNativeWidgetForNativeWindow(
NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
gfx::NativeView native_view) { gfx::NativeView native_view) {
BridgedNativeWidgetHostImpl* bridge_host = BridgedNativeWidgetHostImpl* bridge_host =
NativeWidgetMac::GetBridgeHostImplForNativeWindow([native_view window]); BridgedNativeWidgetHostImpl::GetFromNativeWindow([native_view window]);
if (!bridge_host) if (!bridge_host)
return nullptr; return nullptr;
...@@ -721,7 +698,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget( ...@@ -721,7 +698,7 @@ NativeWidgetPrivate* NativeWidgetPrivate::GetTopLevelNativeWidget(
void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
Widget::Widgets* children) { Widget::Widgets* children) {
BridgedNativeWidgetHostImpl* bridge_host = BridgedNativeWidgetHostImpl* bridge_host =
NativeWidgetMac::GetBridgeHostImplForNativeWindow([native_view window]); BridgedNativeWidgetHostImpl::GetFromNativeWindow([native_view window]);
if (!bridge_host) { if (!bridge_host) {
// The NSWindow is not itself a views::Widget, but it may have children that // The NSWindow is not itself a views::Widget, but it may have children that
// are. Support returning Widgets that are parented to the NSWindow, except: // are. Support returning Widgets that are parented to the NSWindow, except:
...@@ -770,7 +747,7 @@ void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view, ...@@ -770,7 +747,7 @@ void NativeWidgetPrivate::GetAllChildWidgets(gfx::NativeView native_view,
void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view, void NativeWidgetPrivate::GetAllOwnedWidgets(gfx::NativeView native_view,
Widget::Widgets* owned) { Widget::Widgets* owned) {
BridgedNativeWidgetImpl* bridge = BridgedNativeWidgetImpl* bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow([native_view window]); BridgedNativeWidgetImpl::GetFromNativeWindow([native_view window]);
if (!bridge) { if (!bridge) {
GetAllChildWidgets(native_view, owned); GetAllChildWidgets(native_view, owned);
return; return;
...@@ -791,9 +768,9 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view, ...@@ -791,9 +768,9 @@ void NativeWidgetPrivate::ReparentNativeView(gfx::NativeView native_view,
} }
BridgedNativeWidgetImpl* bridge = BridgedNativeWidgetImpl* bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow([native_view window]); BridgedNativeWidgetImpl::GetFromNativeWindow([native_view window]);
BridgedNativeWidgetImpl* parent_bridge = BridgedNativeWidgetImpl* parent_bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow([new_parent window]); BridgedNativeWidgetImpl::GetFromNativeWindow([new_parent window]);
DCHECK(bridge); DCHECK(bridge);
if (Widget::GetWidgetForNativeView(native_view)->is_top_level() && if (Widget::GetWidgetForNativeView(native_view)->is_top_level() &&
bridge->parent() == parent_bridge) bridge->parent() == parent_bridge)
......
...@@ -97,7 +97,7 @@ namespace test { ...@@ -97,7 +97,7 @@ namespace test {
class BridgedNativeWidgetTestApi { class BridgedNativeWidgetTestApi {
public: public:
explicit BridgedNativeWidgetTestApi(NSWindow* window) { explicit BridgedNativeWidgetTestApi(NSWindow* window) {
bridge_ = NativeWidgetMac::GetBridgeImplForNativeWindow(window); bridge_ = BridgedNativeWidgetImpl::GetFromNativeWindow(window);
} }
// Simulate a frame swap from the compositor. // Simulate a frame swap from the compositor.
...@@ -758,7 +758,7 @@ TEST_F(NativeWidgetMacTest, NonWidgetParent) { ...@@ -758,7 +758,7 @@ TEST_F(NativeWidgetMacTest, NonWidgetParent) {
// To verify the parent, we need to use NativeWidgetMac APIs. // To verify the parent, we need to use NativeWidgetMac APIs.
BridgedNativeWidgetImpl* bridged_native_widget = BridgedNativeWidgetImpl* bridged_native_widget =
NativeWidgetMac::GetBridgeImplForNativeWindow(child->GetNativeWindow()); BridgedNativeWidgetImpl::GetFromNativeWindow(child->GetNativeWindow());
EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow()); EXPECT_EQ(native_parent, bridged_native_widget->parent()->GetNSWindow());
const gfx::Rect child_bounds(50, 50, 200, 100); const gfx::Rect child_bounds(50, 50, 200, 100);
...@@ -1547,7 +1547,7 @@ TEST_F(NativeWidgetMacTest, NoopReparentNativeView) { ...@@ -1547,7 +1547,7 @@ TEST_F(NativeWidgetMacTest, NoopReparentNativeView) {
Widget* dialog = views::DialogDelegate::CreateDialogWidget( Widget* dialog = views::DialogDelegate::CreateDialogWidget(
new DialogDelegateView, nullptr, [parent contentView]); new DialogDelegateView, nullptr, [parent contentView]);
BridgedNativeWidgetImpl* bridge = BridgedNativeWidgetImpl* bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow(dialog->GetNativeWindow()); BridgedNativeWidgetImpl::GetFromNativeWindow(dialog->GetNativeWindow());
EXPECT_EQ(bridge->parent()->GetNSWindow(), parent); EXPECT_EQ(bridge->parent()->GetNSWindow(), parent);
Widget::ReparentNativeView(dialog->GetNativeView(), [parent contentView]); Widget::ReparentNativeView(dialog->GetNativeView(), [parent contentView]);
...@@ -1560,7 +1560,7 @@ TEST_F(NativeWidgetMacTest, NoopReparentNativeView) { ...@@ -1560,7 +1560,7 @@ TEST_F(NativeWidgetMacTest, NoopReparentNativeView) {
dialog = views::DialogDelegate::CreateDialogWidget( dialog = views::DialogDelegate::CreateDialogWidget(
new DialogDelegateView, nullptr, [parent contentView]); new DialogDelegateView, nullptr, [parent contentView]);
bridge = bridge =
NativeWidgetMac::GetBridgeImplForNativeWindow(dialog->GetNativeWindow()); BridgedNativeWidgetImpl::GetFromNativeWindow(dialog->GetNativeWindow());
EXPECT_EQ(bridge->parent()->GetNSWindow(), parent); EXPECT_EQ(bridge->parent()->GetNSWindow(), parent);
Widget::ReparentNativeView(dialog->GetNativeView(), [parent contentView]); Widget::ReparentNativeView(dialog->GetNativeView(), [parent contentView]);
...@@ -2107,7 +2107,7 @@ class NativeWidgetMacFullKeyboardAccessTest : public NativeWidgetMacTest { ...@@ -2107,7 +2107,7 @@ class NativeWidgetMacFullKeyboardAccessTest : public NativeWidgetMacTest {
NativeWidgetMacTest::SetUp(); NativeWidgetMacTest::SetUp();
widget_ = CreateTopLevelPlatformWidget(); widget_ = CreateTopLevelPlatformWidget();
bridge_ = NativeWidgetMac::GetBridgeImplForNativeWindow( bridge_ = BridgedNativeWidgetImpl::GetFromNativeWindow(
widget_->GetNativeWindow()); widget_->GetNativeWindow());
fake_full_keyboard_access_ = fake_full_keyboard_access_ =
ui::test::ScopedFakeFullKeyboardAccess::GetInstance(); ui::test::ScopedFakeFullKeyboardAccess::GetInstance();
......
...@@ -24,6 +24,8 @@ struct BridgedNativeWidgetInitParams { ...@@ -24,6 +24,8 @@ struct BridgedNativeWidgetInitParams {
ui.mojom.ModalType modal_type; ui.mojom.ModalType modal_type;
// If true, the underlying window potentially be seen through. // If true, the underlying window potentially be seen through.
bool is_translucent; bool is_translucent;
// True if the widget is considered top level widget.
bool widget_is_top_level;
// If true, then the NSWindow is set to have a shadow using // If true, then the NSWindow is set to have a shadow using
// -[NSWindow setHasShadow:YES]. // -[NSWindow setHasShadow:YES].
bool has_window_server_shadow; bool has_window_server_shadow;
......
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