OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ui/views/cocoa/bridged_native_widget.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #import "ui/views/cocoa/bridged_content_view.h" |
| 9 |
| 10 namespace views { |
| 11 |
| 12 BridgedNativeWidget::BridgedNativeWidget() { |
| 13 } |
| 14 |
| 15 BridgedNativeWidget::~BridgedNativeWidget() { |
| 16 SetRootView(NULL); |
| 17 } |
| 18 |
| 19 void BridgedNativeWidget::Init(base::scoped_nsobject<NSWindow> window) { |
| 20 DCHECK(!window_); |
| 21 window_.swap(window); |
| 22 } |
| 23 |
| 24 void BridgedNativeWidget::SetRootView(views::View* view) { |
| 25 if (view == [bridged_view_ hostedView]) |
| 26 return; |
| 27 |
| 28 [bridged_view_ clearView]; |
| 29 bridged_view_.reset(); |
| 30 // Note that there can still be references to the old |bridged_view_| |
| 31 // floating around in Cocoa libraries at this point. However, references to |
| 32 // the old views::View will be gone, so any method calls will become no-ops. |
| 33 |
| 34 if (view) { |
| 35 bridged_view_.reset([[BridgedContentView alloc] initWithView:view]); |
| 36 // Objective C initializers can return nil. However, if |view| is non-NULL |
| 37 // this should be treated as an error and caught early. |
| 38 CHECK(bridged_view_); |
| 39 } |
| 40 [window_ setContentView:bridged_view_]; |
| 41 } |
| 42 |
| 43 } // namespace views |
OLD | NEW |