Chromium Code Reviews| 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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 366 int paint_count() { return paint_count_; } | 366 int paint_count() { return paint_count_; } |
| 367 | 367 |
| 368 private: | 368 private: |
| 369 int paint_count_ = 0; | 369 int paint_count_ = 0; |
| 370 int target_paint_count_ = 0; | 370 int target_paint_count_ = 0; |
| 371 base::RunLoop* run_loop_ = nullptr; | 371 base::RunLoop* run_loop_ = nullptr; |
| 372 | 372 |
| 373 DISALLOW_COPY_AND_ASSIGN(PaintCountView); | 373 DISALLOW_COPY_AND_ASSIGN(PaintCountView); |
| 374 }; | 374 }; |
| 375 | 375 |
| 376 // Test for correct child window restore when parent window is minimized | |
| 377 // and restored using makeKeyAndOrderFront. | |
|
tapted
2016/06/22 04:09:15
nit: -makeKeyAndOrderFront:.
kirr
2016/06/22 12:59:03
Done.
| |
| 378 // Child window could become occluded (because of cocoa bug?). | |
|
tapted
2016/06/22 04:09:14
You can say:
Parent-child window relationships i
kirr
2016/06/22 12:59:03
Done.
| |
| 379 TEST_F(NativeWidgetMacTest, OrderFrontAfterMiniturize) { | |
|
tapted
2016/06/22 04:09:14
Miniturize -> Miniaturize (or Minimize)
kirr
2016/06/22 12:59:04
Done.
| |
| 380 Widget* widget = new Widget; | |
|
tapted
2016/06/22 04:09:14
You should be able to avoid using InitParams with
kirr
2016/06/22 12:59:04
Done.
| |
| 381 Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW); | |
| 382 widget->Init(init_params); | |
| 383 NSWindow* ns_window = widget->GetNativeWindow(); | |
| 384 | |
| 385 Widget* child_widget = new Widget; | |
|
tapted
2016/06/22 04:09:14
Widget* child = CreateChildPlatformWidget(widget->
kirr
2016/06/22 12:59:04
Done.
| |
| 386 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | |
| 387 child_params.parent = widget->GetNativeView(); | |
| 388 child_widget->Init(child_params); | |
| 389 NSWindow* child_ns_window = child_widget->GetNativeWindow(); | |
| 390 | |
| 391 // Set parent bounds that overlap child. | |
| 392 widget->SetBounds(gfx::Rect(100, 100, 300, 300)); | |
| 393 child_widget->SetBounds(gfx::Rect(110, 110, 100, 100)); | |
|
tapted
2016/06/22 04:09:14
note with TYPE_CONTROL, I think the bounds will be
| |
| 394 | |
| 395 widget->Show(); | |
|
tapted
2016/06/22 04:09:14
show the child too?
kirr
2016/06/22 12:59:04
I think no.
Test visually works fine without it.
B
tapted
2016/06/23 12:09:26
hm - I'm pretty sure you need to show it. It's val
| |
| 396 base::RunLoop().RunUntilIdle(); | |
|
tapted
2016/06/22 04:09:14
is this needed?
kirr
2016/06/22 12:59:04
Yes, seems like it is also related to window activ
| |
| 397 | |
| 398 EXPECT_FALSE(widget->IsMinimized()); | |
| 399 | |
| 400 // Minimize parent. | |
| 401 [ns_window performMiniaturize:nil]; | |
| 402 base::RunLoop().RunUntilIdle(); | |
|
tapted
2016/06/22 04:09:14
this shouldn't be needed - miniaturize is synchron
kirr
2016/06/22 12:59:04
It's also not for the expectations below, bot for
| |
| 403 | |
| 404 EXPECT_TRUE(widget->IsMinimized()); | |
| 405 EXPECT_FALSE(widget->IsVisible()); | |
| 406 EXPECT_FALSE(child_widget->IsVisible()); | |
| 407 | |
| 408 // Restore parent window as AppController does. | |
| 409 [ns_window makeKeyAndOrderFront:nil]; | |
| 410 | |
| 411 // Wait and check that child is really visible. | |
| 412 // TODO(kirr): remove the fixed timeout. | |
| 413 base::MessageLoop::current()->PostDelayedTask( | |
|
kirr
2016/06/21 16:33:47
I've added the test to show the problem.
But I don
tapted
2016/06/22 04:09:14
Can you get a stack trace from the visibility chan
kirr
2016/06/22 12:59:04
Here is NSNotifications trace for the test (+ orde
tapted
2016/06/23 12:09:26
You can get the stack with something like base::de
| |
| 414 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | |
| 415 base::TimeDelta::FromSeconds(2)); | |
| 416 base::MessageLoop::current()->Run(); | |
| 417 | |
| 418 EXPECT_FALSE(widget->IsMinimized()); | |
| 419 EXPECT_TRUE(widget->IsVisible()); | |
| 420 EXPECT_TRUE(child_widget->IsVisible()); | |
| 421 // Check that child window is visible. | |
| 422 EXPECT_TRUE([child_ns_window occlusionState] & NSWindowOcclusionStateVisible); | |
|
tapted
2016/06/22 04:09:14
ah, occlusion states are updated from the window s
kirr
2016/06/22 12:59:04
WidgetTest::IsWindowStackedAbove(..) returns the s
tapted
2016/06/23 12:09:25
So, like you probably saw, we can't guarantee that
kirr
2016/06/23 16:20:11
Ok, I agree that we can't commit with a fixed dela
| |
| 423 widget->Close(); | |
| 424 } | |
| 425 | |
| 376 // Test minimized states triggered externally, implied visibility and restored | 426 // Test minimized states triggered externally, implied visibility and restored |
| 377 // bounds whilst minimized. | 427 // bounds whilst minimized. |
| 378 TEST_F(NativeWidgetMacTest, MiniaturizeExternally) { | 428 TEST_F(NativeWidgetMacTest, MiniaturizeExternally) { |
| 379 Widget* widget = new Widget; | 429 Widget* widget = new Widget; |
| 380 Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW); | 430 Widget::InitParams init_params(Widget::InitParams::TYPE_WINDOW); |
| 381 widget->Init(init_params); | 431 widget->Init(init_params); |
| 382 | 432 |
| 383 PaintCountView* view = new PaintCountView(); | 433 PaintCountView* view = new PaintCountView(); |
| 384 widget->GetContentsView()->AddChildView(view); | 434 widget->GetContentsView()->AddChildView(view); |
| 385 NSWindow* ns_window = widget->GetNativeWindow(); | 435 NSWindow* ns_window = widget->GetNativeWindow(); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 // -[NSWindow orderOut:] call that is triggered from -[ViewsNSWindowDelegate | 973 // -[NSWindow orderOut:] call that is triggered from -[ViewsNSWindowDelegate |
| 924 // sheetDidEnd:]. |sheet_widget| will be destroyed next, so it's still safe to | 974 // sheetDidEnd:]. |sheet_widget| will be destroyed next, so it's still safe to |
| 925 // use in the block. However, since the orderOut just happened, it's not very | 975 // use in the block. However, since the orderOut just happened, it's not very |
| 926 // interesting. | 976 // interesting. |
| 927 observer = [[NSNotificationCenter defaultCenter] | 977 observer = [[NSNotificationCenter defaultCenter] |
| 928 addObserverForName:NSWindowDidEndSheetNotification | 978 addObserverForName:NSWindowDidEndSheetNotification |
| 929 object:native_parent | 979 object:native_parent |
| 930 queue:nil | 980 queue:nil |
| 931 usingBlock:^(NSNotification* note) { | 981 usingBlock:^(NSNotification* note) { |
| 932 EXPECT_TRUE([sheet_window delegate]); | 982 EXPECT_TRUE([sheet_window delegate]); |
| 933 EXPECT_FALSE(sheet_widget->IsVisible()); | |
| 934 EXPECT_FALSE(sheet_widget->GetLayer()->IsDrawn()); | |
| 935 *did_observe_ptr = true; | 983 *did_observe_ptr = true; |
| 936 }]; | 984 }]; |
| 937 | 985 |
| 938 // Pump in order to trigger -[NSWindow endSheet:..], which will block while | 986 // Pump in order to trigger -[NSWindow endSheet:..], which will block while |
| 939 // the animation runs, then delete |sheet_widget|. | 987 // the animation runs, then delete |sheet_widget|. |
| 940 TestWidgetObserver widget_observer(sheet_widget); | 988 TestWidgetObserver widget_observer(sheet_widget); |
| 941 EXPECT_TRUE([sheet_window delegate]); | 989 EXPECT_TRUE([sheet_window delegate]); |
| 942 base::RunLoop().RunUntilIdle(); | 990 base::RunLoop().RunUntilIdle(); |
| 943 EXPECT_FALSE([sheet_window delegate]); | 991 EXPECT_FALSE([sheet_window delegate]); |
| 944 | 992 |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1585 lastDirtyRect_ = dirtyRect; | 1633 lastDirtyRect_ = dirtyRect; |
| 1586 } | 1634 } |
| 1587 | 1635 |
| 1588 @end | 1636 @end |
| 1589 | 1637 |
| 1590 @implementation FocusableTestNSView | 1638 @implementation FocusableTestNSView |
| 1591 - (BOOL)acceptsFirstResponder { | 1639 - (BOOL)acceptsFirstResponder { |
| 1592 return YES; | 1640 return YES; |
| 1593 } | 1641 } |
| 1594 @end | 1642 @end |
| OLD | NEW |