Commit f1d241a5 authored by tapted's avatar tapted Committed by Commit bot

MacViews: Ensure the RootView is in place before the first call to ReorderNativeViews

This gets 3 views_unittests passing:
 - ViewTargeterTest.HitTestCallsOnView,
 - ViewTest.CanProcessEventsWithinSubtree,
 - ViewTest.GetEventHandlerForRect.

These were failing because the size of the RootView was being reset to
the Widget size when first added. This happened because NativeWidgetMac
was not ensuring the RootView was set up properly immediately after a
call to Widget::Init() for all Widget types (i.e. those without a
NonClientView).

When there _is_ a NonClientView, Widget::Init() calls SetContentsView()
which would eventually trickle down to
NativeWidgetMac::ReorderNativeViews(), which is where NativeWidgetMac
would set up the root view.

BUG=378134

Review URL: https://codereview.chromium.org/559873002

Cr-Commit-Position: refs/heads/master@{#294296}
parent e970ae47
...@@ -118,6 +118,9 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { ...@@ -118,6 +118,9 @@ void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
delegate_->OnNativeWidgetCreated(true); delegate_->OnNativeWidgetCreated(true);
bridge_->SetFocusManager(GetWidget()->GetFocusManager()); bridge_->SetFocusManager(GetWidget()->GetFocusManager());
DCHECK(GetWidget()->GetRootView());
bridge_->SetRootView(GetWidget()->GetRootView());
} }
NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() { NonClientFrameView* NativeWidgetMac::CreateNonClientFrameView() {
......
...@@ -3198,5 +3198,26 @@ TEST_F(WidgetTest, MouseEventTypesViaGenerator) { ...@@ -3198,5 +3198,26 @@ TEST_F(WidgetTest, MouseEventTypesViaGenerator) {
widget->CloseNow(); widget->CloseNow();
} }
// Tests that the root view is correctly set up for Widget types that do not
// require a non-client view, before any other views are added to the widget.
// That is, before Widget::ReorderNativeViews() is called which, if called with
// a root view not set, could cause the root view to get resized to the widget.
TEST_F(WidgetTest, NonClientWindowValidAfterInit) {
Widget* widget = CreateTopLevelFramelessPlatformWidget();
View* root_view = widget->GetRootView();
// Size the root view to exceed the widget bounds.
const gfx::Rect test_rect(0, 0, 500, 500);
root_view->SetBoundsRect(test_rect);
EXPECT_NE(test_rect.size(), widget->GetWindowBoundsInScreen().size());
EXPECT_EQ(test_rect, root_view->bounds());
widget->ReorderNativeViews();
EXPECT_EQ(test_rect, root_view->bounds());
widget->CloseNow();
}
} // namespace test } // namespace test
} // namespace views } // namespace views
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