Commit 6f5f5a4d authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

View::SetVisible() notifies layout manager.

Explicit calls to View::SetVisible() outside of LayoutManager::Layout()
will cause the view's parent's layout manager (if there is one) to be
notified. This way, we can treat someone calling SetVisible() as a state
change for the layout manager, perpendicular to any changes the layout
manager itself makes to the visibility of child views (for example, if
it decides to hide them because there is not enough space to display
them).

Also, reordering child views invalidates layout. It should always have.

Bug: 898632
Change-Id: I47382e5efe348b63a7dda7b6e493f55ac5bd74fb
Reviewed-on: https://chromium-review.googlesource.com/c/1368274Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614832}
parent 0c63af8a
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
#include "base/auto_reset.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
...@@ -39,4 +40,12 @@ void LayoutManager::ViewAdded(View* host, View* view) { ...@@ -39,4 +40,12 @@ void LayoutManager::ViewAdded(View* host, View* view) {
void LayoutManager::ViewRemoved(View* host, View* view) { void LayoutManager::ViewRemoved(View* host, View* view) {
} }
void LayoutManager::ViewVisibilitySet(View* host, View* view, bool visible) {}
void LayoutManager::SetViewVisibility(View* view, bool visible) {
DCHECK_EQ(view->parent()->GetLayoutManager(), this);
base::AutoReset<View*> setter(&view_setting_visibility_on_, view);
view->SetVisible(visible);
}
} // namespace views } // namespace views
...@@ -71,6 +71,20 @@ class VIEWS_EXPORT LayoutManager { ...@@ -71,6 +71,20 @@ class VIEWS_EXPORT LayoutManager {
// been installed on. This function allows the LayoutManager to cleanup any // been installed on. This function allows the LayoutManager to cleanup any
// state it has kept specific to a View. // state it has kept specific to a View.
virtual void ViewRemoved(View* host, View* view); virtual void ViewRemoved(View* host, View* view);
// Called when View::SetVisible() is called by external code. Classes derived
// from LayoutManager can call SetViewVisibility() below to avoid triggering
// this event.
virtual void ViewVisibilitySet(View* host, View* view, bool visible);
protected:
// Sets the visibility of a view without triggering ViewVisibilitySet().
// During Layout(), use this method instead of View::SetVisibility().
void SetViewVisibility(View* view, bool visible);
private:
friend class views::View;
View* view_setting_visibility_on_ = nullptr;
}; };
} // namespace views } // namespace views
......
...@@ -266,6 +266,7 @@ void View::ReorderChildView(View* view, int index) { ...@@ -266,6 +266,7 @@ void View::ReorderChildView(View* view, int index) {
observer.OnChildViewReordered(this, view); observer.OnChildViewReordered(this, view);
ReorderLayers(); ReorderLayers();
InvalidateLayout();
} }
void View::RemoveChildView(View* view) { void View::RemoveChildView(View* view) {
...@@ -439,6 +440,12 @@ int View::GetHeightForWidth(int w) const { ...@@ -439,6 +440,12 @@ int View::GetHeightForWidth(int w) const {
} }
void View::SetVisible(bool visible) { void View::SetVisible(bool visible) {
if (parent_) {
LayoutManager* const layout_manager = parent_->GetLayoutManager();
if (layout_manager && layout_manager->view_setting_visibility_on_ != this)
layout_manager->ViewVisibilitySet(parent_, this, visible);
}
if (visible != visible_) { if (visible != visible_) {
// If the View is currently visible, schedule paint to refresh parent. // If the View is currently visible, schedule paint to refresh parent.
// TODO(beng): not sure we should be doing this if we have a layer. // TODO(beng): not sure we should be doing this if we have a layer.
......
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