Commit 82b34604 authored by Allen Bauer's avatar Allen Bauer Committed by Chromium LUCI CQ

Use class property for ignored state in DefaultFillLayout for a given view.

Related to the work of integrating fill layout behavior into views::View.

Bug: 1159116
Change-Id: Iccf0a311536588c3ba3d141ee5c7e1f8450cd2a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613591
Auto-Submit: Allen Bauer <kylixrd@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840913}
parent 693cb0b5
...@@ -91,7 +91,7 @@ class VIEWS_EXPORT LayoutManager { ...@@ -91,7 +91,7 @@ class VIEWS_EXPORT LayoutManager {
protected: protected:
// Sets the visibility of a view without triggering ViewVisibilitySet(). // Sets the visibility of a view without triggering ViewVisibilitySet().
// During Layout(), use this method instead of View::SetVisibility(). // During Layout(), use this method instead of View::SetVisible().
void SetViewVisibility(View* view, bool visible); void SetViewVisibility(View* view, bool visible);
// Gets the child views of the specified view in paint order (reverse // Gets the child views of the specified view in paint order (reverse
......
...@@ -106,7 +106,7 @@ class VIEWS_EXPORT LayoutManagerBase : public LayoutManager { ...@@ -106,7 +106,7 @@ class VIEWS_EXPORT LayoutManagerBase : public LayoutManager {
// Returns whether the specified child view can be visible. To be able to be // Returns whether the specified child view can be visible. To be able to be
// visible, |child| must be a child of the host view, and must have been // visible, |child| must be a child of the host view, and must have been
// visible when it was added or most recently had GetVisible(true) called on // visible when it was added or most recently had SetVisible(true) called on
// it by non-layout code. // it by non-layout code.
bool CanBeVisible(const View* child) const; bool CanBeVisible(const View* child) const;
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include "ui/views/controls/scroll_view.h" #include "ui/views/controls/scroll_view.h"
#include "ui/views/drag_controller.h" #include "ui/views/drag_controller.h"
#include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_observer.h" #include "ui/views/view_observer.h"
#include "ui/views/view_tracker.h" #include "ui/views/view_tracker.h"
#include "ui/views/views_features.h" #include "ui/views/views_features.h"
...@@ -3125,14 +3126,18 @@ View::DefaultFillLayout::~DefaultFillLayout() = default; ...@@ -3125,14 +3126,18 @@ View::DefaultFillLayout::~DefaultFillLayout() = default;
void View::DefaultFillLayout::Layout(View* host) { void View::DefaultFillLayout::Layout(View* host) {
const gfx::Rect contents_bounds = host->GetContentsBounds(); const gfx::Rect contents_bounds = host->GetContentsBounds();
for (auto* child : host->children()) for (auto* child : host->children()) {
if (!child->GetProperty(kViewIgnoredByLayoutKey))
child->SetBoundsRect(contents_bounds); child->SetBoundsRect(contents_bounds);
}
} }
gfx::Size View::DefaultFillLayout::GetPreferredSize(const View* host) const { gfx::Size View::DefaultFillLayout::GetPreferredSize(const View* host) const {
gfx::Size preferred_size; gfx::Size preferred_size;
for (auto* child : host->children()) for (auto* child : host->children()) {
if (!child->GetProperty(kViewIgnoredByLayoutKey))
preferred_size.SetToMax(child->GetPreferredSize()); preferred_size.SetToMax(child->GetPreferredSize());
}
return preferred_size; return preferred_size;
} }
...@@ -3140,10 +3145,13 @@ int View::DefaultFillLayout::GetPreferredHeightForWidth(const View* host, ...@@ -3140,10 +3145,13 @@ int View::DefaultFillLayout::GetPreferredHeightForWidth(const View* host,
int width) const { int width) const {
const gfx::Insets insets = host->GetInsets(); const gfx::Insets insets = host->GetInsets();
int preferred_height = 0; int preferred_height = 0;
for (auto* child : host->children()) for (auto* child : host->children()) {
if (!child->GetProperty(kViewIgnoredByLayoutKey)) {
preferred_height = std::max( preferred_height = std::max(
preferred_height, preferred_height,
child->GetHeightForWidth(width - insets.width()) + insets.height()); child->GetHeightForWidth(width - insets.width()) + insets.height());
}
}
return preferred_height; return preferred_height;
} }
......
...@@ -41,5 +41,6 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(FlexSpecification, kFlexBehaviorKey, nullptr) ...@@ -41,5 +41,6 @@ DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(FlexSpecification, kFlexBehaviorKey, nullptr)
DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(LayoutAlignment, DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(LayoutAlignment,
kCrossAxisAlignmentKey, kCrossAxisAlignmentKey,
nullptr) nullptr)
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kViewIgnoredByLayoutKey, false)
} // namespace views } // namespace views
...@@ -58,6 +58,12 @@ VIEWS_EXPORT extern const ui::ClassProperty<FlexSpecification*>* const ...@@ -58,6 +58,12 @@ VIEWS_EXPORT extern const ui::ClassProperty<FlexSpecification*>* const
VIEWS_EXPORT extern const ui::ClassProperty<LayoutAlignment*>* const VIEWS_EXPORT extern const ui::ClassProperty<LayoutAlignment*>* const
kCrossAxisAlignmentKey; kCrossAxisAlignmentKey;
// Property indicating whether a view should be ignored by a layout. Supported
// by View::DefaultFillLayout.
// TODO(kylixrd): Revisit using for FillLayout.
VIEWS_EXPORT extern const ui::ClassProperty<bool>* const
kViewIgnoredByLayoutKey;
} // namespace views } // namespace views
// Declaring the template specialization here to make sure that the // Declaring the template specialization here to make sure that the
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include "ui/events/keycodes/keyboard_codes.h" #include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/drag_controller.h" #include "ui/views/drag_controller.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/metadata/metadata_impl_macros.h" #include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/view_targeter.h" #include "ui/views/view_targeter.h"
#include "ui/views/widget/root_view_targeter.h" #include "ui/views/widget/root_view_targeter.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -210,7 +210,7 @@ void RootView::SetContentsView(View* contents_view) { ...@@ -210,7 +210,7 @@ void RootView::SetContentsView(View* contents_view) {
<< "Can't be called until after the native widget is created!"; << "Can't be called until after the native widget is created!";
// The ContentsView must be set up _after_ the window is created so that its // The ContentsView must be set up _after_ the window is created so that its
// Widget pointer is valid. // Widget pointer is valid.
SetLayoutManager(std::make_unique<FillLayout>()); SetUseDefaultFillLayout(true);
if (!children().empty()) if (!children().empty())
RemoveAllChildViews(true); RemoveAllChildViews(true);
AddChildView(contents_view); AddChildView(contents_view);
...@@ -268,8 +268,7 @@ void RootView::AnnounceText(const base::string16& text) { ...@@ -268,8 +268,7 @@ void RootView::AnnounceText(const base::string16& text) {
DCHECK(GetContentsView()); DCHECK(GetContentsView());
if (!announce_view_) { if (!announce_view_) {
announce_view_ = AddChildView(std::make_unique<AnnounceTextView>()); announce_view_ = AddChildView(std::make_unique<AnnounceTextView>());
static_cast<FillLayout*>(GetLayoutManager()) announce_view_->SetProperty(kViewIgnoredByLayoutKey, true);
->SetChildViewIgnoredByLayout(announce_view_, true);
} }
announce_view_->Announce(text); announce_view_->Announce(text);
#endif #endif
......
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