Commit a0a331e3 authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Move proposed layout into its own file.

This prevents us from having to put our layout interpolation code in
LayoutManagerBase where it really doesn't belong.

Bug: 898632
Change-Id: I837b14ff05eee9f5ea9b2659955d787bde23958e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1815665Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698696}
parent 8495c9bf
......@@ -83,8 +83,7 @@ InterpolatingLayoutManager::GetInterpolation(
return result;
}
views::LayoutManagerBase::ProposedLayout
InterpolatingLayoutManager::CalculateProposedLayout(
views::ProposedLayout InterpolatingLayoutManager::CalculateProposedLayout(
const views::SizeBounds& size_bounds) const {
// For interpolating layout we will never call this method except for fully-
// specified sizes.
......@@ -93,14 +92,17 @@ InterpolatingLayoutManager::CalculateProposedLayout(
const gfx::Size size(*size_bounds.width(), *size_bounds.height());
const LayoutInterpolation interpolation = GetInterpolation(size_bounds);
const ProposedLayout first = interpolation.first->GetProposedLayout(size);
const views::ProposedLayout first =
interpolation.first->GetProposedLayout(size);
if (!interpolation.second)
return first;
// If the target size falls in an interpolation range, get the other layout.
const ProposedLayout second = interpolation.second->GetProposedLayout(size);
return Interpolate(interpolation.percent_second, first, second);
const views::ProposedLayout second =
interpolation.second->GetProposedLayout(size);
return views::ProposedLayoutBetween(interpolation.percent_second, first,
second);
}
void InterpolatingLayoutManager::SetDefaultLayout(
......
......@@ -80,7 +80,7 @@ class InterpolatingLayoutManager : public views::LayoutManagerBase {
int width) const override;
protected:
ProposedLayout CalculateProposedLayout(
views::ProposedLayout CalculateProposedLayout(
const views::SizeBounds& size_bounds) const override;
private:
......
......@@ -46,8 +46,8 @@ class TestLayout : public LayoutManagerBase {
mutable int num_layouts_generated_ = 0;
};
void CompareProposedLayouts(const LayoutManagerBase::ProposedLayout& left,
const LayoutManagerBase::ProposedLayout& right) {
void CompareProposedLayouts(const ProposedLayout& left,
const ProposedLayout& right) {
EXPECT_EQ(left.host_size, right.host_size);
EXPECT_EQ(left.child_layouts.size(), right.child_layouts.size());
for (auto left_it = left.child_layouts.begin(),
......@@ -284,9 +284,9 @@ TEST_F(InterpolatingLayoutManagerTest, GetProposedLayout) {
constexpr gfx::Size kLargeSize{11, 10};
constexpr gfx::Size kOneThirdSize{7, 10};
constexpr gfx::Size kOneHalfSize{8, 10};
const LayoutManagerBase::ProposedLayout expected_default =
const ProposedLayout expected_default =
first_layout->GetProposedLayout(kSmallSize);
const LayoutManagerBase::ProposedLayout expected_other =
const ProposedLayout expected_other =
second_layout->GetProposedLayout(kLargeSize);
CompareProposedLayouts(expected_default,
......@@ -294,8 +294,7 @@ TEST_F(InterpolatingLayoutManagerTest, GetProposedLayout) {
CompareProposedLayouts(expected_other,
layout_manager()->GetProposedLayout(kLargeSize));
LayoutManagerBase::ProposedLayout actual =
layout_manager()->GetProposedLayout(kOneThirdSize);
ProposedLayout actual = layout_manager()->GetProposedLayout(kOneThirdSize);
EXPECT_EQ(gfx::Tween::SizeValueBetween(0.3333, expected_default.host_size,
expected_other.host_size),
actual.host_size);
......
......@@ -210,6 +210,7 @@ jumbo_component("views") {
"layout/layout_provider.h",
"layout/layout_types.h",
"layout/normalized_geometry.h",
"layout/proposed_layout.h",
"masked_targeter_delegate.h",
"metadata/metadata_cache.h",
"metadata/metadata_header_macros.h",
......@@ -419,6 +420,7 @@ jumbo_component("views") {
"layout/layout_provider.cc",
"layout/layout_types.cc",
"layout/normalized_geometry.cc",
"layout/proposed_layout.cc",
"masked_targeter_delegate.cc",
"metadata/metadata_cache.cc",
"metadata/metadata_types.cc",
......
......@@ -19,12 +19,6 @@
namespace views {
using layout::Denormalize;
using layout::Normalize;
using layout::NormalizedInsets;
using layout::NormalizedRect;
using layout::NormalizedSize;
// Holds data about a view that is fading in or out as part of an animation.
struct AnimatingLayoutManager::LayoutFadeInfo {
// Whether the view is fading in or out.
......@@ -381,8 +375,7 @@ void AnimatingLayoutManager::EnableAnimationForTesting() {
DCHECK(animation_delegate_->ready_to_animate());
}
LayoutManagerBase::ProposedLayout
AnimatingLayoutManager::CalculateProposedLayout(
ProposedLayout AnimatingLayoutManager::CalculateProposedLayout(
const SizeBounds& size_bounds) const {
// This class directly overrides Layout() so GetProposedLayout() and
// CalculateProposedLayout() are not called.
......@@ -482,7 +475,8 @@ void AnimatingLayoutManager::RunDelayedActions() {
void AnimatingLayoutManager::UpdateCurrentLayout(double percent) {
// This drops out any child view elements that don't exist in the target
// layout. We'll add them back in later.
current_layout_ = Interpolate(percent, starting_layout_, target_layout_);
current_layout_ =
ProposedLayoutBetween(percent, starting_layout_, target_layout_);
if (default_fade_mode_ == FadeInOutMode::kHide || fade_infos_.empty())
return;
......@@ -676,7 +670,7 @@ void AnimatingLayoutManager::CalculateFadeInfos() {
}
}
LayoutManagerBase::ChildLayout AnimatingLayoutManager::CalculateScaleFade(
ChildLayout AnimatingLayoutManager::CalculateScaleFade(
const LayoutFadeInfo& fade_info,
base::Optional<size_t> prev_index,
base::Optional<size_t> next_index,
......@@ -726,7 +720,7 @@ LayoutManagerBase::ChildLayout AnimatingLayoutManager::CalculateScaleFade(
return child_layout;
}
LayoutManagerBase::ChildLayout AnimatingLayoutManager::CalculateSlideFade(
ChildLayout AnimatingLayoutManager::CalculateSlideFade(
const LayoutFadeInfo& fade_info,
base::Optional<size_t> prev_index,
base::Optional<size_t> next_index,
......
......@@ -20,8 +20,6 @@
namespace views {
using ProposedLayout = LayoutManagerBase::ProposedLayout;
namespace {
// View that allows directly setting minimum size.
......@@ -204,8 +202,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, layout1(), layout2());
ProposedLayout expected = ProposedLayoutBetween(0.25, layout1(), layout2());
EXPECT_TRUE(layout()->is_animating());
EXPECT_EQ(expected.host_size, view()->size());
EnsureLayout(expected);
......@@ -213,7 +210,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance again.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.5, layout1(), layout2());
expected = ProposedLayoutBetween(0.5, layout1(), layout2());
EXPECT_TRUE(layout()->is_animating());
EXPECT_EQ(expected.host_size, view()->size());
EnsureLayout(expected);
......@@ -325,15 +322,14 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->Layout();
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, layout1(), layout2());
ProposedLayout expected = ProposedLayoutBetween(0.25, layout1(), layout2());
EXPECT_TRUE(layout()->is_animating());
EnsureLayout(expected);
// Advance again.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->Layout();
expected = LayoutManagerBase::Interpolate(0.5, layout1(), layout2());
expected = ProposedLayoutBetween(0.5, layout1(), layout2());
EXPECT_TRUE(layout()->is_animating());
EnsureLayout(expected);
......@@ -378,7 +374,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, initial_layout, final_layout);
ProposedLayoutBetween(0.25, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[1].child_view, child(1));
expected.child_layouts[1].visible = true;
expected.child_layouts[1].bounds = {
......@@ -394,7 +390,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.5, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[1].child_view, child(1));
expected.child_layouts[1].visible = true;
expected.child_layouts[1].bounds = {
......@@ -410,7 +406,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.75, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.75, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// zero in size so it will disappear.
EXPECT_TRUE(layout()->is_animating());
......@@ -458,7 +454,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, initial_layout, final_layout);
ProposedLayoutBetween(0.25, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[1].child_view, child(1));
expected.child_layouts[1].visible = true;
expected.child_layouts[1].bounds = {
......@@ -474,7 +470,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.5, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// its minimum size so it will disappear.
EXPECT_TRUE(layout()->is_animating());
......@@ -522,7 +518,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, initial_layout, final_layout);
ProposedLayoutBetween(0.25, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[0].child_view, child(0));
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = {
......@@ -536,7 +532,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.5, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// its minimum size so it will disappear.
EXPECT_TRUE(layout()->is_animating());
......@@ -585,7 +581,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
ProposedLayoutBetween(0.5, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// its minimum size so it will not be visible.
EXPECT_TRUE(layout()->is_animating());
......@@ -595,7 +591,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.75, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.75, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[2].child_view, child(2));
expected.child_layouts[2].visible = true;
expected.child_layouts[2].bounds = {
......@@ -649,7 +645,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, initial_layout, final_layout);
ProposedLayoutBetween(0.25, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[2].child_view, child(2));
expected.child_layouts[2].visible = true;
expected.child_layouts[2].bounds = {
......@@ -665,7 +661,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->SetSize(view()->GetPreferredSize());
expected = LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.5, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// its minimum size so it will disappear.
EXPECT_TRUE(layout()->is_animating());
......@@ -713,7 +709,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->Layout();
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.25, initial_layout, final_layout);
ProposedLayoutBetween(0.25, initial_layout, final_layout);
DCHECK_EQ(expected.child_layouts[2].child_view, child(2));
expected.child_layouts[2].visible = true;
expected.child_layouts[2].bounds = {
......@@ -728,7 +724,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest,
// Advance the animation.
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->Layout();
expected = LayoutManagerBase::Interpolate(0.5, initial_layout, final_layout);
expected = ProposedLayoutBetween(0.5, initial_layout, final_layout);
// At this point the layout is still animating but the middle view is below
// its minimum size so it will disappear.
EXPECT_TRUE(layout()->is_animating());
......@@ -1030,7 +1026,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeOutOnVisibilitySet) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
ProposedLayoutBetween(0.5, expected_start, expected_end);
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = expected_start.child_layouts[0].bounds;
expected.child_layouts[0].bounds.set_width(
......@@ -1087,7 +1083,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeInOnVisibilitySet) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
ProposedLayoutBetween(0.5, expected_start, expected_end);
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = expected_end.child_layouts[0].bounds;
expected.child_layouts[0].bounds.set_width(
......@@ -1147,8 +1143,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeInOnAdded) {
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, after_add, expected_end);
ProposedLayout expected = ProposedLayoutBetween(0.5, after_add, expected_end);
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = expected_end.child_layouts[0].bounds;
expected.child_layouts[0].bounds.set_width(
......@@ -1205,7 +1200,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeIn) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
ProposedLayoutBetween(0.5, expected_start, expected_end);
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = expected_end.child_layouts[0].bounds;
expected.child_layouts[0].bounds.set_width(
......@@ -1261,7 +1256,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeOut) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
ProposedLayoutBetween(0.5, expected_start, expected_end);
expected.child_layouts[0].visible = true;
expected.child_layouts[0].bounds = expected_start.child_layouts[0].bounds;
expected.child_layouts[0].bounds.set_width(
......@@ -1323,7 +1318,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeOut_NoCrashOnRemove) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, after_remove, expected_end);
ProposedLayoutBetween(0.5, after_remove, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
......@@ -1375,7 +1370,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_FadeOut_IgnoreChildView) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
ProposedLayoutBetween(0.5, expected_start, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
......@@ -1421,13 +1416,13 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_SlideAfterViewHidden) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.0, expected_start, expected_end);
ProposedLayoutBetween(0.0, expected_start, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
expected = LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
expected = ProposedLayoutBetween(0.5, expected_start, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
......@@ -1473,13 +1468,13 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_SlideAfterViewRemoved) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.0, expected_start, expected_end);
ProposedLayoutBetween(0.0, expected_start, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
expected = LayoutManagerBase::Interpolate(0.5, expected_start, expected_end);
expected = ProposedLayoutBetween(0.5, expected_start, expected_end);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
......@@ -1530,7 +1525,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_RedirectAnimation) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.5, expected_start, expected_end1);
ProposedLayoutBetween(0.5, expected_start, expected_end1);
EnsureLayout(expected);
child(2)->SetVisible(false);
......@@ -1538,7 +1533,7 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_RedirectAnimation) {
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
expected = LayoutManagerBase::Interpolate(0.5, expected, expected_end2);
expected = ProposedLayoutBetween(0.5, expected, expected_end2);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(250));
......@@ -1589,19 +1584,19 @@ TEST_F(AnimatingLayoutManagerSteppingTest, FlexLayout_ResetAnimation) {
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
ProposedLayout expected =
LayoutManagerBase::Interpolate(0.9, expected_start, expected_end1);
ProposedLayoutBetween(0.9, expected_start, expected_end1);
EnsureLayout(expected);
child(2)->SetVisible(false);
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
expected = LayoutManagerBase::Interpolate(0.0, expected, expected_end2);
expected = ProposedLayoutBetween(0.0, expected, expected_end2);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
view()->Layout();
EXPECT_TRUE(layout()->is_animating());
expected = LayoutManagerBase::Interpolate(0.5, expected, expected_end2);
expected = ProposedLayoutBetween(0.5, expected, expected_end2);
EnsureLayout(expected);
animation_api()->IncrementTime(base::TimeDelta::FromMilliseconds(500));
......
......@@ -28,15 +28,6 @@
namespace views {
using layout::NormalizedInsets;
using layout::NormalizedPoint;
using layout::NormalizedRect;
using layout::NormalizedSize;
using layout::NormalizedSizeBounds;
using layout::Denormalize;
using layout::Normalize;
namespace {
// Layout information for a specific child view in a proposed layout.
......@@ -334,7 +325,7 @@ FlexLayout& FlexLayout::SetBetweenChildSpacing(int between_child_spacing) {
return *this;
}
LayoutManagerBase::ProposedLayout FlexLayout::CalculateProposedLayout(
ProposedLayout FlexLayout::CalculateProposedLayout(
const SizeBounds& size_bounds) const {
FlexLayoutData data;
......@@ -386,7 +377,7 @@ LayoutManagerBase::ProposedLayout FlexLayout::CalculateProposedLayout(
}
void FlexLayout::InitializeChildData(
const layout::NormalizedSizeBounds& bounds,
const NormalizedSizeBounds& bounds,
FlexLayoutData* data,
FlexOrderToViewIndexMap* flex_order_to_index) const {
// Step through the children, creating placeholder layout view elements
......
......@@ -22,11 +22,8 @@
namespace views {
class View;
namespace layout {
class NormalizedSizeBounds;
}
class View;
// Provides CSS-like layout for a one-dimensional (vertical or horizontal)
// arrangement of child views. Independent alignment can be specified for the
......@@ -165,7 +162,7 @@ class VIEWS_EXPORT FlexLayout : public LayoutManagerBase {
base::Optional<int> GetAvailableCrossAxisSize(
const FlexLayoutData& layout,
size_t child_index,
const layout::NormalizedSizeBounds& bounds) const;
const NormalizedSizeBounds& bounds) const;
// Calculates the preferred spacing between two child views, or between a
// view edge and the first or last visible child views.
......@@ -175,7 +172,7 @@ class VIEWS_EXPORT FlexLayout : public LayoutManagerBase {
// Calculates the position of each child view and the size of the overall
// layout based on tentative visibilities and sizes for each child.
void UpdateLayoutFromChildren(const layout::NormalizedSizeBounds& bounds,
void UpdateLayoutFromChildren(const NormalizedSizeBounds& bounds,
FlexLayoutData* data,
ChildViewSpacing* child_spacing) const;
......@@ -190,7 +187,7 @@ class VIEWS_EXPORT FlexLayout : public LayoutManagerBase {
// Typically, this method will be called once with |expandable_views| set and
// then again with it null to allocate the remaining space.
void AllocateFlexSpace(
const layout::NormalizedSizeBounds& bounds,
const NormalizedSizeBounds& bounds,
const FlexOrderToViewIndexMap& order_to_index,
FlexLayoutData* data,
ChildViewSpacing* child_spacing,
......@@ -199,7 +196,7 @@ class VIEWS_EXPORT FlexLayout : public LayoutManagerBase {
// Fills out the child entries for |data| and generates some initial size
// and visibility data, and stores off information about which views can
// expand in |flex_order_to_index|.
void InitializeChildData(const layout::NormalizedSizeBounds& bounds,
void InitializeChildData(const NormalizedSizeBounds& bounds,
FlexLayoutData* data,
FlexOrderToViewIndexMap* flex_order_to_index) const;
......
......@@ -8,39 +8,10 @@
#include "base/auto_reset.h"
#include "base/logging.h"
#include "ui/gfx/animation/tween.h"
#include "ui/views/view.h"
namespace views {
bool LayoutManagerBase::ChildLayout::operator==(
const ChildLayout& other) const {
// Note: if the view is not visible, the bounds do not matter as they will not
// be set.
return child_view == other.child_view && visible == other.visible &&
(!visible || bounds == other.bounds);
}
LayoutManagerBase::ProposedLayout::ProposedLayout() = default;
LayoutManagerBase::ProposedLayout::ProposedLayout(const ProposedLayout& other) =
default;
LayoutManagerBase::ProposedLayout::ProposedLayout(ProposedLayout&& other) =
default;
LayoutManagerBase::ProposedLayout::ProposedLayout(
const gfx::Size& size,
const std::initializer_list<ChildLayout>& children)
: host_size(size), child_layouts(children) {}
LayoutManagerBase::ProposedLayout::~ProposedLayout() = default;
LayoutManagerBase::ProposedLayout& LayoutManagerBase::ProposedLayout::operator=(
const ProposedLayout& other) = default;
LayoutManagerBase::ProposedLayout& LayoutManagerBase::ProposedLayout::operator=(
ProposedLayout&& other) = default;
bool LayoutManagerBase::ProposedLayout::operator==(
const ProposedLayout& other) const {
return host_size == other.host_size && child_layouts == other.child_layouts;
}
LayoutManagerBase::~LayoutManagerBase() = default;
gfx::Size LayoutManagerBase::GetPreferredSize(const View* host) const {
......@@ -74,50 +45,13 @@ void LayoutManagerBase::Layout(View* host) {
ApplyLayout(GetProposedLayout(size));
}
// static
views::LayoutManagerBase::ProposedLayout LayoutManagerBase::Interpolate(
double value,
const ProposedLayout& start,
const ProposedLayout& target) {
if (value >= 1.0)
return target;
ProposedLayout layout;
// Interpolate the host size.
layout.host_size =
gfx::Tween::SizeValueBetween(value, start.host_size, target.host_size);
// The views may not be listed in the same order and some views might be
// omitted from either the |start| or |target| layout.
std::map<const views::View*, size_t> start_view_to_index;
for (size_t i = 0; i < start.child_layouts.size(); ++i)
start_view_to_index.emplace(start.child_layouts[i].child_view, i);
for (const ChildLayout& target_child : target.child_layouts) {
// Try to match the view from the target with the view from the start.
const auto start_match = start_view_to_index.find(target_child.child_view);
if (start_match == start_view_to_index.end()) {
// If there is no match, make the view present but invisible.
layout.child_layouts.push_back({target_child.child_view, false});
} else {
// Tween the two layouts.
const ChildLayout& start_child = start.child_layouts[start_match->second];
layout.child_layouts.push_back(
{target_child.child_view, start_child.visible && target_child.visible,
gfx::Tween::RectValueBetween(value, start_child.bounds,
target_child.bounds)});
}
}
return layout;
}
std::vector<View*> LayoutManagerBase::GetChildViewsInPaintOrder(
const View* host) const {
DCHECK_EQ(host_view_, host);
return LayoutManager::GetChildViewsInPaintOrder(host);
}
LayoutManagerBase::ProposedLayout LayoutManagerBase::GetProposedLayout(
ProposedLayout LayoutManagerBase::GetProposedLayout(
const gfx::Size& host_size) const {
if (cached_layout_size_ != host_size) {
cached_layout_size_ = host_size;
......
......@@ -17,6 +17,7 @@
#include "ui/gfx/geometry/size.h"
#include "ui/views/layout/layout_manager.h"
#include "ui/views/layout/layout_types.h"
#include "ui/views/layout/proposed_layout.h"
#include "ui/views/views_export.h"
namespace views {
......@@ -28,43 +29,6 @@ class View;
// CalculateProposedLayout(). Used in interpolating and animating layouts.
class VIEWS_EXPORT LayoutManagerBase : public LayoutManager {
public:
// Represents layout information for a child view within a host being laid
// out.
struct VIEWS_EXPORT ChildLayout {
bool operator==(const ChildLayout& other) const;
bool operator!=(const ChildLayout& other) const {
return !(*this == other);
}
View* child_view = nullptr;
bool visible = false;
gfx::Rect bounds;
};
// Contains a full layout specification for the children of the host view.
struct VIEWS_EXPORT ProposedLayout {
ProposedLayout();
~ProposedLayout();
ProposedLayout(const ProposedLayout& other);
ProposedLayout(ProposedLayout&& other);
ProposedLayout(const gfx::Size& size,
const std::initializer_list<ChildLayout>& children);
ProposedLayout& operator=(const ProposedLayout& other);
ProposedLayout& operator=(ProposedLayout&& other);
bool operator==(const ProposedLayout& other) const;
bool operator!=(const ProposedLayout& other) const {
return !(*this == other);
}
// The size of the host view given the size bounds for this layout. If both
// dimensions of the size bounds are specified, this will be the same size.
gfx::Size host_size;
// Contains an entry for each child view included in the layout.
std::vector<ChildLayout> child_layouts;
};
~LayoutManagerBase() override;
View* host_view() { return host_view_; }
......@@ -87,13 +51,6 @@ class VIEWS_EXPORT LayoutManagerBase : public LayoutManager {
int GetPreferredHeightForWidth(const View* host, int width) const override;
void Layout(View* host) override;
// Returns a layout that's linearly interpolated between |start| and |target|
// by |value|, which should be between 0 and 1. See
// gfx::Tween::LinearIntValueBetween() for the exact math involved.
static ProposedLayout Interpolate(double value,
const ProposedLayout& start,
const ProposedLayout& target);
protected:
LayoutManagerBase();
......
......@@ -13,8 +13,6 @@
namespace views {
// Test LayoutManagerBase-specific functionality:
namespace {
constexpr int kChildViewPadding = 5;
......@@ -340,7 +338,7 @@ TEST_F(LayoutManagerBaseManagerTest, ApplyLayout) {
// doesn't change.
const gfx::Size old_size = host_view()->size();
LayoutManagerBase::ProposedLayout layout;
ProposedLayout layout;
// This should be ignored.
layout.host_size = {123, 456};
......@@ -366,7 +364,7 @@ TEST_F(LayoutManagerBaseManagerTest, ApplyLayout_SkipsOmittedViews) {
AddChildView(gfx::Size());
AddChildView(gfx::Size());
LayoutManagerBase::ProposedLayout layout;
ProposedLayout layout;
// Set the child visibility and bounds.
constexpr gfx::Rect kChild1Bounds(3, 4, 10, 15);
constexpr gfx::Rect kChild2Bounds(1, 2, 3, 4);
......@@ -597,7 +595,6 @@ TEST(LayoutManagerBase_ProposedLayoutTest, Equality) {
View* ptr0 = nullptr;
View* ptr1 = ptr0 + 1;
View* ptr2 = ptr0 + 2;
using ProposedLayout = LayoutManagerBase::ProposedLayout;
ProposedLayout a;
ProposedLayout b;
EXPECT_TRUE(a == b);
......
......@@ -11,16 +11,6 @@
namespace views {
namespace {
std::string OptionalToString(const base::Optional<int>& opt) {
if (!opt.has_value())
return "_";
return base::StringPrintf("%d", opt.value());
}
} // namespace
// SizeBounds ------------------------------------------------------------------
SizeBounds::SizeBounds() = default;
......@@ -55,8 +45,17 @@ bool SizeBounds::operator<(const SizeBounds& other) const {
}
std::string SizeBounds::ToString() const {
return base::StringPrintf("%s x %s", OptionalToString(width()).c_str(),
OptionalToString(height()).c_str());
std::ostringstream oss;
if (width().has_value())
oss << *width();
else
oss << "_";
oss << " x ";
if (height().has_value())
oss << *height();
else
oss << "_";
return oss.str();
}
} // namespace views
......@@ -16,17 +16,6 @@
#include "ui/views/layout/flex_layout_types.h"
namespace views {
namespace layout {
namespace {
std::string OptionalToString(const base::Optional<int>& opt) {
if (!opt.has_value())
return "_";
return base::StringPrintf("%d", opt.value());
}
} // namespace
// NormalizedPoint -------------------------------------------------------------
......@@ -160,8 +149,17 @@ bool NormalizedSizeBounds::operator<(const NormalizedSizeBounds& other) const {
}
std::string NormalizedSizeBounds::ToString() const {
return base::StringPrintf("%s x %s", OptionalToString(main()).c_str(),
OptionalToString(cross()).c_str());
std::ostringstream oss;
if (main().has_value())
oss << *main();
else
oss << "_";
oss << " x ";
if (cross().has_value())
oss << *cross();
else
oss << "_";
return oss.str();
}
// NormalizedRect --------------------------------------------------------------
......@@ -379,5 +377,4 @@ gfx::Rect Denormalize(LayoutOrientation orientation,
Denormalize(orientation, bounds.size()));
}
} // namespace layout
} // namespace views
......@@ -22,13 +22,6 @@ namespace views {
class SizeBounds;
// NOTE: Types in this file are intended for use by layout managers, preferably
// only in ui/views/layout. They are marked as VIEWS_EXPORT for use in unit
// tests as well as experimental layout managers currently not in the Views
// library.
namespace layout {
// Represents a point in layout space - that is, a point on the main and cross
// axes of the layout (regardless of whether it is vertically or horizontally
// oriented.
......@@ -285,7 +278,6 @@ NormalizedRect VIEWS_EXPORT Normalize(LayoutOrientation orientation,
gfx::Rect VIEWS_EXPORT Denormalize(LayoutOrientation orientation,
const NormalizedRect& rect);
} // namespace layout
} // namespace views
#endif // UI_VIEWS_LAYOUT_NORMALIZED_GEOMETRY_H_
......@@ -7,7 +7,6 @@
#include "testing/gtest/include/gtest/gtest.h"
namespace views {
namespace layout {
TEST(NormalizedRectTest, Inset_NormalizedInsets) {
NormalizedRect rect(1, 2, 10, 11);
......@@ -46,5 +45,4 @@ TEST(NormalizedRectTest, Inset_Negative) {
EXPECT_EQ(17, rect.size_cross());
}
} // namespace layout
} // namespace views
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/layout/proposed_layout.h"
#include <map>
#include "ui/gfx/animation/tween.h"
namespace views {
bool ChildLayout::operator==(const ChildLayout& other) const {
// Note: if the view is not visible, the bounds do not matter as they will not
// be set.
return child_view == other.child_view && visible == other.visible &&
(!visible || bounds == other.bounds);
}
ProposedLayout::ProposedLayout() = default;
ProposedLayout::ProposedLayout(const ProposedLayout& other) = default;
ProposedLayout::ProposedLayout(ProposedLayout&& other) = default;
ProposedLayout::ProposedLayout(
const gfx::Size& size,
const std::initializer_list<ChildLayout>& children)
: host_size(size), child_layouts(children) {}
ProposedLayout::~ProposedLayout() = default;
ProposedLayout& ProposedLayout::operator=(const ProposedLayout& other) =
default;
ProposedLayout& ProposedLayout::operator=(ProposedLayout&& other) = default;
bool ProposedLayout::operator==(const ProposedLayout& other) const {
return host_size == other.host_size && child_layouts == other.child_layouts;
}
ProposedLayout ProposedLayoutBetween(double value,
const ProposedLayout& start,
const ProposedLayout& target) {
if (value >= 1.0)
return target;
ProposedLayout layout;
// Interpolate the host size.
layout.host_size =
gfx::Tween::SizeValueBetween(value, start.host_size, target.host_size);
// The views may not be listed in the same order and some views might be
// omitted from either the |start| or |target| layout.
std::map<const views::View*, size_t> start_view_to_index;
for (size_t i = 0; i < start.child_layouts.size(); ++i)
start_view_to_index.emplace(start.child_layouts[i].child_view, i);
for (const ChildLayout& target_child : target.child_layouts) {
// Try to match the view from the target with the view from the start.
const auto start_match = start_view_to_index.find(target_child.child_view);
if (start_match == start_view_to_index.end()) {
// If there is no match, make the view present but invisible.
layout.child_layouts.push_back({target_child.child_view, false});
} else {
// Tween the two layouts.
const ChildLayout& start_child = start.child_layouts[start_match->second];
layout.child_layouts.push_back(
{target_child.child_view, start_child.visible && target_child.visible,
gfx::Tween::RectValueBetween(value, start_child.bounds,
target_child.bounds)});
}
}
return layout;
}
} // namespace views
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_LAYOUT_PROPOSED_LAYOUT_H_
#define UI_VIEWS_LAYOUT_PROPOSED_LAYOUT_H_
#include "ui/gfx/geometry/rect.h"
#include "ui/views/views_export.h"
namespace views {
class View;
// Represents layout information for a child view within a host being laid
// out.
struct VIEWS_EXPORT ChildLayout {
bool operator==(const ChildLayout& other) const;
bool operator!=(const ChildLayout& other) const { return !(*this == other); }
View* child_view = nullptr;
bool visible = false;
gfx::Rect bounds;
};
// Contains a full layout specification for the children of the host view.
struct VIEWS_EXPORT ProposedLayout {
ProposedLayout();
~ProposedLayout();
ProposedLayout(const ProposedLayout& other);
ProposedLayout(ProposedLayout&& other);
ProposedLayout(const gfx::Size& size,
const std::initializer_list<ChildLayout>& children);
ProposedLayout& operator=(const ProposedLayout& other);
ProposedLayout& operator=(ProposedLayout&& other);
bool operator==(const ProposedLayout& other) const;
bool operator!=(const ProposedLayout& other) const {
return !(*this == other);
}
// The size of the host view given the size bounds for this layout. If both
// dimensions of the size bounds are specified, this will be the same size.
gfx::Size host_size;
// Contains an entry for each child view included in the layout.
std::vector<ChildLayout> child_layouts;
};
// Returns a layout that's linearly interpolated between |start| and |target|
// by |value|, which should be between 0 and 1. See
// gfx::Tween::LinearIntValueBetween() for the exact math involved.
VIEWS_EXPORT ProposedLayout ProposedLayoutBetween(double value,
const ProposedLayout& start,
const ProposedLayout& target);
} // namespace views
#endif // UI_VIEWS_LAYOUT_PROPOSED_LAYOUT_H_
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