| Index: ui/views/controls/native/native_view_host_mac.mm
|
| diff --git a/ui/views/controls/native/native_view_host_mac.mm b/ui/views/controls/native/native_view_host_mac.mm
|
| index da057fa743ad67bb948d225aa0dd65458dc98ea4..0f74c57924a8607d786f2ac4e652f452a19cd20a 100644
|
| --- a/ui/views/controls/native/native_view_host_mac.mm
|
| +++ b/ui/views/controls/native/native_view_host_mac.mm
|
| @@ -5,19 +5,18 @@
|
| #include "ui/views/controls/native/native_view_host_mac.h"
|
|
|
| #import <Cocoa/Cocoa.h>
|
| +#import <objc/runtime.h>
|
|
|
| -#include "base/logging.h"
|
| -#include "base/mac/foundation_util.h"
|
| -#import "ui/views/cocoa/bridged_content_view.h"
|
| #include "ui/views/controls/native/native_view_host.h"
|
| #include "ui/views/widget/widget.h"
|
| +#include "ui/views/widget/widget_mac_utils.h"
|
|
|
| namespace views {
|
| namespace {
|
|
|
| // Reparents |native_view| to be a child of the native content view of
|
| -// |new_parent|.
|
| -void ReparentNSView(NSView* native_view, Widget* new_parent) {
|
| +// |host| widget.
|
| +void ReparentNSView(NSView* native_view, NativeViewHost* host) {
|
| DCHECK(native_view);
|
| // Mac's NativeViewHost has no support for hosting its own child widgets.
|
| // This check is probably overly restrictive, since the Widget containing the
|
| @@ -30,16 +29,11 @@ void ReparentNSView(NSView* native_view, Widget* new_parent) {
|
| CHECK_GE(1u, child_widgets.size()); // 1 (itself) or 0 if detached.
|
| }
|
|
|
| - if (!new_parent) {
|
| + if (!host) {
|
| [native_view removeFromSuperview];
|
| return;
|
| }
|
| -
|
| - BridgedContentView* new_superview =
|
| - base::mac::ObjCCastStrict<BridgedContentView>(
|
| - new_parent->GetNativeView());
|
| - DCHECK(new_superview);
|
| - [new_superview addSubview:native_view];
|
| + AttachNSViewRelatedToHost(native_view, host);
|
| }
|
|
|
| } // namespace
|
| @@ -57,7 +51,10 @@ void NativeViewHostMac::AttachNativeView() {
|
| DCHECK(host_->native_view());
|
| DCHECK(!native_view_);
|
| native_view_.reset([host_->native_view() retain]);
|
| - ReparentNSView(host_->native_view(), host_->GetWidget());
|
| + ReparentNSView(host_->native_view(), host_);
|
| + objc_setAssociatedObject(native_view_.get(), &kAssociatedViewHostKey,
|
| + [NSValue valueWithPointer:host_],
|
| + OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
| }
|
|
|
| void NativeViewHostMac::NativeViewDetaching(bool destroyed) {
|
| @@ -70,7 +67,9 @@ void NativeViewHostMac::NativeViewDetaching(bool destroyed) {
|
| // NativeViewHost::Detach().
|
| DCHECK(!native_view_ || native_view_ == host_->native_view());
|
| [host_->native_view() setHidden:YES];
|
| - ReparentNSView(host_->native_view(), NULL);
|
| + ReparentNSView(host_->native_view(), nullptr);
|
| + objc_setAssociatedObject(native_view_.get(), &kAssociatedViewHostKey, nil,
|
| + OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
| native_view_.reset();
|
| }
|
|
|
|
|