Commit f2061c44 authored by Manuel Rego Casasnovas's avatar Manuel Rego Casasnovas Committed by Commit Bot

[css-grid] Remove unneeded code in FreeSpaceForStretchAutoTracksStep()

This is a follow up after r510461. In that patch we added a TODO in
IndefiniteSizeStrategy::FreeSpaceForStretchAutoTracksStep().
This was related to how preferred widths were computed,
that could be missing the min-width information.

However after r511451 removing some wrong code
in LayoutGrid::UpdateBlockLayout(), that was trying to compute
the preferred widths, we can avoid doing any special calculation
for the columns case, as that's already managed
by LayoutBlock::ComputePreferredLogicalWidths().

Basically GridTrackSizing provides a min and max logical widths
that ignore min-width. But that's not an issue as LayoutGrid only
overrides ComputeIntrinsicLogicalWidths(),
then ComputePreferredLogicalWidths() will use that information
together with the min-size and properly compute the preferred widths.

For this reason in FreeSpaceForStretchAutoTracksStep() we don't need
any special computation for columns, the same that happens
in RecomputeUsedFlexFractionIfNeeded().

Added two unit tests to verify that the preferred widths are right
in both cases (auto and flexible tracks with min-width).

Bug=773625

Change-Id: I69efeb064fa03685c3e77bca33d294df3e1db79d
Reviewed-on: https://chromium-review.googlesource.com/741505Reviewed-by: default avatarJavier Fernandez <jfernandez@igalia.com>
Commit-Queue: Manuel Rego Casasnovas <rego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#512692}
parent 4605f2dd
...@@ -4206,6 +4206,40 @@ TEST_P(WebViewTest, PreferredSizeWithGrid) { ...@@ -4206,6 +4206,40 @@ TEST_P(WebViewTest, PreferredSizeWithGrid) {
EXPECT_EQ(100, size.height); EXPECT_EQ(100, size.height);
} }
TEST_P(WebViewTest, PreferredSizeWithGridMinWidth) {
WebViewImpl* web_view = web_view_helper_.Initialize();
WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
R"HTML(<!DOCTYPE html>
<body style="margin: 0px;">
<div style="display: inline-grid; min-width: 200px;">
<div>item</div>
</div>
</body>
)HTML",
base_url);
WebSize size = web_view->ContentsPreferredMinimumSize();
EXPECT_EQ(200, size.width);
}
TEST_P(WebViewTest, PreferredSizeWithGridMinWidthFlexibleTracks) {
WebViewImpl* web_view = web_view_helper_.Initialize();
WebURL base_url = URLTestHelpers::ToKURL("http://example.com/");
FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(),
R"HTML(<!DOCTYPE html>
<body style="margin: 0px;">
<div style="display: inline-grid; min-width: 200px; grid-template-columns: 1fr;">
<div>item</div>
</div>
</body>
)HTML",
base_url);
WebSize size = web_view->ContentsPreferredMinimumSize();
EXPECT_EQ(200, size.width);
}
class UnhandledTapWebViewClient : public FrameTestHelpers::TestWebViewClient { class UnhandledTapWebViewClient : public FrameTestHelpers::TestWebViewClient {
public: public:
void ShowUnhandledTapUIIfNeeded(const WebTappedInfo& tapped_info) override { void ShowUnhandledTapUIIfNeeded(const WebTappedInfo& tapped_info) override {
......
...@@ -544,25 +544,11 @@ bool IndefiniteSizeStrategy::RecomputeUsedFlexFractionIfNeeded( ...@@ -544,25 +544,11 @@ bool IndefiniteSizeStrategy::RecomputeUsedFlexFractionIfNeeded(
LayoutUnit IndefiniteSizeStrategy::FreeSpaceForStretchAutoTracksStep() const { LayoutUnit IndefiniteSizeStrategy::FreeSpaceForStretchAutoTracksStep() const {
DCHECK(!algorithm_.FreeSpace(Direction())); DCHECK(!algorithm_.FreeSpace(Direction()));
LayoutUnit min_size; if (Direction() == kForColumns)
return LayoutUnit();
if (Direction() == kForColumns) {
// TODO(rego): Review intrinsic sizes in follow-up patches. For flexible LayoutUnit min_size = GetLayoutGrid()->ComputeContentLogicalHeight(
// tracks we will need to do something similar if we want to have accurate kMinSize, GetLayoutGrid()->StyleRef().LogicalMinHeight(), LayoutUnit(-1));
// intrinsic sizes. Even in ComputeGridContainerIntrinsicSizes() we should
// consider this.
Length min_width = GetLayoutGrid()->StyleRef().LogicalMinWidth();
if (min_width.IsFixed() && min_width.Value() > 0) {
min_size = GetLayoutGrid()->AdjustContentBoxLogicalWidthForBoxSizing(
LayoutUnit(min_width.Value()));
} else {
return LayoutUnit();
}
} else {
min_size = GetLayoutGrid()->ComputeContentLogicalHeight(
kMinSize, GetLayoutGrid()->StyleRef().LogicalMinHeight(),
LayoutUnit(-1));
}
return min_size - ComputeTrackBasedSize(); return min_size - ComputeTrackBasedSize();
} }
......
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