| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ui/views/widget/native_widget_mac.h" | 5 #import "ui/views/widget/native_widget_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #import "base/mac/foundation_util.h" | 9 #import "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 host_->Attach(view_.get()); | 224 host_->Attach(view_.get()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 void Detach() { host_->Detach(); } | 227 void Detach() { host_->Detach(); } |
| 228 | 228 |
| 229 gfx::NativeView view() const { return view_.get(); } | 229 gfx::NativeView view() const { return view_.get(); } |
| 230 NativeViewHost* host() const { return host_.get(); } | 230 NativeViewHost* host() const { return host_.get(); } |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 base::scoped_nsobject<NSView> view_; | 233 base::scoped_nsobject<NSView> view_; |
| 234 scoped_ptr<NativeViewHost> host_; | 234 std::unique_ptr<NativeViewHost> host_; |
| 235 | 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(NativeHostHolder); | 236 DISALLOW_COPY_AND_ASSIGN(NativeHostHolder); |
| 237 }; | 237 }; |
| 238 | 238 |
| 239 // Test visibility states triggered externally. | 239 // Test visibility states triggered externally. |
| 240 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { | 240 TEST_F(NativeWidgetMacTest, HideAndShowExternally) { |
| 241 Widget* widget = CreateTopLevelPlatformWidget(); | 241 Widget* widget = CreateTopLevelPlatformWidget(); |
| 242 NSWindow* ns_window = widget->GetNativeWindow(); | 242 NSWindow* ns_window = widget->GetNativeWindow(); |
| 243 WidgetChangeObserver observer(widget); | 243 WidgetChangeObserver observer(widget); |
| 244 | 244 |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 Widget* parent = CreateTopLevelPlatformWidget(); | 1034 Widget* parent = CreateTopLevelPlatformWidget(); |
| 1035 parent->SetBounds(gfx::Rect(100, 100, 300, 200)); | 1035 parent->SetBounds(gfx::Rect(100, 100, 300, 200)); |
| 1036 parent->Show(); | 1036 parent->Show(); |
| 1037 ParentCloseMonitor monitor(parent); | 1037 ParentCloseMonitor monitor(parent); |
| 1038 parent->CloseNow(); | 1038 parent->CloseNow(); |
| 1039 EXPECT_TRUE(monitor.child_closed()); | 1039 EXPECT_TRUE(monitor.child_closed()); |
| 1040 } | 1040 } |
| 1041 | 1041 |
| 1042 // Test the WIDGET_OWNS_NATIVE_WIDGET flow. | 1042 // Test the WIDGET_OWNS_NATIVE_WIDGET flow. |
| 1043 { | 1043 { |
| 1044 scoped_ptr<Widget> parent(new Widget); | 1044 std::unique_ptr<Widget> parent(new Widget); |
| 1045 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); | 1045 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); |
| 1046 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 1046 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 1047 params.bounds = gfx::Rect(100, 100, 300, 200); | 1047 params.bounds = gfx::Rect(100, 100, 300, 200); |
| 1048 parent->Init(params); | 1048 parent->Init(params); |
| 1049 parent->Show(); | 1049 parent->Show(); |
| 1050 | 1050 |
| 1051 ParentCloseMonitor monitor(parent.get()); | 1051 ParentCloseMonitor monitor(parent.get()); |
| 1052 parent.reset(); | 1052 parent.reset(); |
| 1053 EXPECT_TRUE(monitor.child_closed()); | 1053 EXPECT_TRUE(monitor.child_closed()); |
| 1054 } | 1054 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1374 widget_ = CreateTopLevelPlatformWidget(); | 1374 widget_ = CreateTopLevelPlatformWidget(); |
| 1375 | 1375 |
| 1376 ASSERT_EQ(1u, [[widget_->GetNativeView() subviews] count]); | 1376 ASSERT_EQ(1u, [[widget_->GetNativeView() subviews] count]); |
| 1377 compositor_view_ = [[widget_->GetNativeView() subviews] firstObject]; | 1377 compositor_view_ = [[widget_->GetNativeView() subviews] firstObject]; |
| 1378 | 1378 |
| 1379 native_host_parent_ = new View(); | 1379 native_host_parent_ = new View(); |
| 1380 widget_->GetContentsView()->AddChildView(native_host_parent_); | 1380 widget_->GetContentsView()->AddChildView(native_host_parent_); |
| 1381 | 1381 |
| 1382 const int kNativeViewCount = 3; | 1382 const int kNativeViewCount = 3; |
| 1383 for (int i = 0; i < kNativeViewCount; ++i) { | 1383 for (int i = 0; i < kNativeViewCount; ++i) { |
| 1384 scoped_ptr<NativeHostHolder> holder(new NativeHostHolder()); | 1384 std::unique_ptr<NativeHostHolder> holder(new NativeHostHolder()); |
| 1385 native_host_parent_->AddChildView(holder->host()); | 1385 native_host_parent_->AddChildView(holder->host()); |
| 1386 holder->AttachNativeView(); | 1386 holder->AttachNativeView(); |
| 1387 hosts_.push_back(std::move(holder)); | 1387 hosts_.push_back(std::move(holder)); |
| 1388 } | 1388 } |
| 1389 EXPECT_EQ(kNativeViewCount, native_host_parent_->child_count()); | 1389 EXPECT_EQ(kNativeViewCount, native_host_parent_->child_count()); |
| 1390 EXPECT_TRUE(([[widget_->GetNativeView() subviews] isEqualToArray:@[ | 1390 EXPECT_TRUE(([[widget_->GetNativeView() subviews] isEqualToArray:@[ |
| 1391 compositor_view_, hosts_[0]->view(), hosts_[1]->view(), hosts_[2]->view() | 1391 compositor_view_, hosts_[0]->view(), hosts_[1]->view(), hosts_[2]->view() |
| 1392 ]])); | 1392 ]])); |
| 1393 } | 1393 } |
| 1394 | 1394 |
| 1395 void TearDown() override { | 1395 void TearDown() override { |
| 1396 widget_->CloseNow(); | 1396 widget_->CloseNow(); |
| 1397 WidgetTest::TearDown(); | 1397 WidgetTest::TearDown(); |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 NSView* GetContentNativeView() { return widget_->GetNativeView(); } | 1400 NSView* GetContentNativeView() { return widget_->GetNativeView(); } |
| 1401 | 1401 |
| 1402 Widget* widget_ = nullptr; | 1402 Widget* widget_ = nullptr; |
| 1403 View* native_host_parent_ = nullptr; | 1403 View* native_host_parent_ = nullptr; |
| 1404 NSView* compositor_view_ = nil; | 1404 NSView* compositor_view_ = nil; |
| 1405 std::vector<scoped_ptr<NativeHostHolder>> hosts_; | 1405 std::vector<std::unique_ptr<NativeHostHolder>> hosts_; |
| 1406 | 1406 |
| 1407 private: | 1407 private: |
| 1408 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacViewsOrderTest); | 1408 DISALLOW_COPY_AND_ASSIGN(NativeWidgetMacViewsOrderTest); |
| 1409 }; | 1409 }; |
| 1410 | 1410 |
| 1411 // Test that NativeViewHost::Attach()/Detach() method saves the NativeView | 1411 // Test that NativeViewHost::Attach()/Detach() method saves the NativeView |
| 1412 // z-order. | 1412 // z-order. |
| 1413 TEST_F(NativeWidgetMacViewsOrderTest, NativeViewAttached) { | 1413 TEST_F(NativeWidgetMacViewsOrderTest, NativeViewAttached) { |
| 1414 hosts_[1]->Detach(); | 1414 hosts_[1]->Detach(); |
| 1415 EXPECT_TRUE(([[GetContentNativeView() subviews] isEqualToArray:@[ | 1415 EXPECT_TRUE(([[GetContentNativeView() subviews] isEqualToArray:@[ |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 lastDirtyRect_ = dirtyRect; | 1499 lastDirtyRect_ = dirtyRect; |
| 1500 } | 1500 } |
| 1501 | 1501 |
| 1502 @end | 1502 @end |
| 1503 | 1503 |
| 1504 @implementation FocusableTestNSView | 1504 @implementation FocusableTestNSView |
| 1505 - (BOOL)acceptsFirstResponder { | 1505 - (BOOL)acceptsFirstResponder { |
| 1506 return YES; | 1506 return YES; |
| 1507 } | 1507 } |
| 1508 @end | 1508 @end |
| OLD | NEW |