Commit 4d89104f authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Add basic machinery to communicate available space to child views.

GetAvailableSize() is now present on View and LayoutManager.

Followup CLs will implement and add support for all LayoutManagerBase
layouts including having AnimatingLayoutManager use this information to
correctly plan animations.

Bug: 995448
Change-Id: Iaf50c9816af1b830e348f5019f30309147cd2c29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1958589
Commit-Queue: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723510}
parent 72dcbd10
......@@ -33,6 +33,11 @@ int LayoutManager::GetPreferredHeightForWidth(const View* host,
return GetPreferredSize(host).height();
}
SizeBounds LayoutManager::GetAvailableSize(const View* host,
const View* view) const {
return SizeBounds();
}
void LayoutManager::ViewAdded(View* host, View* view) {
}
......
......@@ -7,6 +7,7 @@
#include <vector>
#include "ui/views/layout/layout_types.h"
#include "ui/views/views_export.h"
namespace gfx {
......@@ -65,6 +66,10 @@ class VIEWS_EXPORT LayoutManager {
// The default implementation returns GetPreferredSize().height().
virtual int GetPreferredHeightForWidth(const View* host, int width) const;
// Returns the maximum space available in the layout for the specified child
// view. Default is unbounded.
virtual SizeBounds GetAvailableSize(const View* host, const View* view) const;
// Called when a View is added as a child of the View the LayoutManager has
// been installed on.
virtual void ViewAdded(View* host, View* view);
......
......@@ -425,6 +425,12 @@ int View::GetHeightForWidth(int w) const {
return GetPreferredSize().height();
}
SizeBounds View::GetAvailableSize(const View* child) const {
if (layout_manager_)
return layout_manager_->GetAvailableSize(this, child);
return SizeBounds();
}
bool View::GetVisible() const {
return visible_;
}
......
......@@ -43,6 +43,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/paint_info.h"
......@@ -539,6 +540,13 @@ class VIEWS_EXPORT View : public ui::LayerDelegate,
// GetPreferredSize().height().
virtual int GetHeightForWidth(int w) const;
// Returns a bound on the available space for a child view, for example, in
// case the child view wants to play an animation that would cause it to
// become larger. Default is not to bound the available size; it is the
// responsibility of specific view/layout manager implementations to determine
// if and when a bound applies.
virtual SizeBounds GetAvailableSize(const View* child) const;
// The |Visible| property. See comment above for instructions on declaring and
// implementing a property.
//
......
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