Skip to content

Commit

Permalink
Updated TestChildModalParent to use AddedToWidget()
Browse files Browse the repository at this point in the history
Removed the use of ViewHierarchyChanged() to update native view
properties when added to a view hierarchy. Changed to use
AddedToWidget() instead.

Currently the logic in ViewHierarchyChanged() requires the view
be in a Widget hierarchy. This should not be assumed in
ViewHierarchyChanged(). Instead, having the logic in AddedToWidget()
helps to make the assumptions more clear.

Bug: 1083822
Change-Id: Ia393fd0141a863212e5c9e30e364fbc4d2b2d7d1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2206215
Reviewed-by: Robert Flack <[email protected]>
Commit-Queue: Thomas Lukaszewicz <[email protected]>
Cr-Commit-Position: refs/heads/master@{#771036}
  • Loading branch information
Thomas Lukaszewicz authored and Commit Bot committed May 21, 2020
1 parent 333915d commit 2e418fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions ash/wm/test_child_modal_parent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ void TestChildModalParent::Layout() {
host_->SetBounds(x(), running_y, width(), height() - running_y);
}

void TestChildModalParent::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
if (details.is_add && details.child == this) {
host_->Attach(modal_parent_->GetNativeView());
GetWidget()->GetNativeView()->SetName("Parent");
}
void TestChildModalParent::AddedToWidget() {
// The function requires a Widget be present.
DCHECK(GetWidget());
host_->Attach(modal_parent_->GetNativeView());
GetWidget()->GetNativeView()->SetName("Parent");
}

void TestChildModalParent::ButtonPressed(views::Button* sender,
Expand Down
3 changes: 1 addition & 2 deletions ash/wm/test_child_modal_parent.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class TestChildModalParent : public views::WidgetDelegateView,
private:
// Overridden from views::View:
void Layout() override;
void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override;
void AddedToWidget() override;

// Overridden from ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
Expand Down

0 comments on commit 2e418fe

Please sign in to comment.