Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement flexible box layout for row container #12330

Merged
merged 10 commits into from Aug 3, 2016
Merged

Conversation

@stshine
Copy link
Contributor

stshine commented Jul 8, 2016

This pull requests implements basic flexible box layout for row container.
It has implemented most basic flexbox features, including grow, shrink, multi-line, *reverse properties, and alignment under justify-content, align-items, align-self, align-content.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • There are tests for these changes

r? @pcwalton


This change is Reviewable

@highfive
Copy link

highfive commented Jul 8, 2016

warning Warning warning

  • These commits modify layout code, but no tests are modified. Please consider adding a test!
@stshine
Copy link
Contributor Author

stshine commented Jul 8, 2016

There a several concerns for this pull request.

One is that previously every method involves a vtable lookup, so I add a style field and clone the style of the flow to it, but I am not very sure what the price is.
Another one is that there are occurrences of 'box-sizing' property here and there to get the proper main size. I wonder if there is a way to reduce them.

@stshine
Copy link
Contributor Author

stshine commented Jul 12, 2016

ping @pcwalton
Mind sharing some general opinion about this pull request? There are a bunch of PRs pending this.

@shinglyu
Copy link
Member

shinglyu commented Jul 15, 2016

(tracking #12453)

@shinglyu
Copy link
Member

shinglyu commented Jul 18, 2016

Review status: 0 of 1 files reviewed at latest revision, 2 unresolved discussions.


components/layout/flex.rs, line 145 [r1] (raw file):

impl FlexItem {
    pub fn new(flow: FlowRef) -> FlexItem {
        let style = flow.as_block().fragment.style.clone();

Will the style ever change after we clone it (e.g. by JavaScript)? Do we need to sync it up with the style side?


components/layout/flex.rs, line 222 [r1] (raw file):

        let ref fragment = self.flow.as_block().fragment;
        let adjustment;
        match mode {

We could just let adjustment = match mode {...}


Comments from Reviewable

@shinglyu
Copy link
Member

shinglyu commented Jul 18, 2016

Disclaimer: I don't have the right to r+ yet, just providing some feedback.

@stshine
Copy link
Contributor Author

stshine commented Jul 18, 2016

Review status: 0 of 1 files reviewed at latest revision, 3 unresolved discussions.


components/layout/flex.rs, line 145 [r1] (raw file):

Previously, shinglyu (Shing Lyu) wrote…

Will the style ever change after we clone it (e.g. by JavaScript)? Do we need to sync it up with the style side?

What cloned is just a Arc pointer to the actual `ServoComputedValues`, so It should not be a problem.

components/layout/flex.rs, line 191 [r1] (raw file):

                        (MaybeAuto::from_style(margin.inline_start, Au(0)).specified_or_zero() +
                         MaybeAuto::from_style(margin.inline_end, Au(0)).specified_or_zero())
                    }

Here when box-sizing is set to border-box, The border and padding length contained in main size is computed at intrinsic size calculating, which set percentage padding to zero. Maybe I should take percentage padding into account for inline main size.


components/layout/flex.rs, line 222 [r1] (raw file):

Previously, shinglyu (Shing Lyu) wrote…

We could just let adjustment = match mode {...}

Previously I do the border and margin computing here. Will fix it.

Comments from Reviewable

@stshine
Copy link
Contributor Author

stshine commented Jul 18, 2016

Disclaimer: I don't have the right to r+ yet, just providing some feedback.

May I ask your general opinion about this pull request? If you think this pull request is acceptable, I will make other PRs that depend on this.

/// The 'order' property of this item.
pub order: i32,
/// Whether the main size has met its constraint.
pub is_freezed: bool,

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jul 18, 2016

Contributor

nit: should this be is_frozen?

}

/// Return the outer main size of the item, including paddings and margins,
/// clamped by max and min size.

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jul 18, 2016

Contributor

Maybe this should become a method on Fragment?

This comment has been minimized.

Copy link
@stshine

stshine Jul 19, 2016

Author Contributor

All these methods exists as the result of refactoring the method of obtaining a line in flexbox. Both this and the adjustment issues remain here because I previously do margin and padding calculation in outer_main_size() . This point is quite valid, but 1. I am not sure if other components need this method, 2. This will make the style field unnecessary and make auto_margin_num() a function instead of a method. Maybe I should do this after more consideration, together with renaming the Mode enum to Direction and moving it to model.rs.

pub fn outer_main_size(&self, mode: Mode) -> Au {
let ref fragment = self.flow.as_block().fragment;
let adjustment;
match mode {

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jul 18, 2016

Contributor

nit: you can shorten this to let adjustment = match mode { ... } and then remove the adjustment =s below and the semicolons

}
}

/// Represent a child in a flex container. Most fields here are used in

This comment has been minimized.

Copy link
@pcwalton

pcwalton Jul 18, 2016

Contributor

nit: "Represent" -> "Represents"

@pcwalton
Copy link
Contributor

pcwalton commented Jul 18, 2016

Looks good, just had a few nits. Thanks!

let margin = self.style.logical_margin();
(MaybeAuto::from_style(margin.inline_start, Au(0)).specified_or_zero() +
MaybeAuto::from_style(margin.inline_end, Au(0)).specified_or_zero())
}

This comment has been minimized.

Copy link
@stshine

stshine Jul 19, 2016

Author Contributor

Here when the the box-sizing property is border-box, percentage padding included in main size is calculated to zero as a result of bubble_inline_sizes. Maybe I should recalculate them?

@stshine stshine force-pushed the stshine:flexitem branch from ee4755b to 47f55be Jul 19, 2016
@stshine
Copy link
Contributor Author

stshine commented Jul 19, 2016

Issues addressed. Thanks!

@stshine stshine mentioned this pull request Jul 19, 2016
2 of 5 tasks complete
@shinglyu
Copy link
Member

shinglyu commented Jul 20, 2016

Does any other code use these methods? If it's for future patches, maybe we should merge this right before the one that uses it.

@stshine
Copy link
Contributor Author

stshine commented Jul 20, 2016

@shinglyu told me for a big feature I should make separate commits and submit them in on PR. If so I will close other PRs, rename this PR, and push consequent commits for flexbox here.

@bors-servo
Copy link
Contributor

bors-servo commented Jul 20, 2016

The latest upstream changes (presumably #12515) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Jul 20, 2016

That sounds like a good plan.

Extend fields of `FlexItem` struct with values that are necessary to
resolve flexible lengths, and the 'order' property. Add other methods
for size computing to make the code more modular.
@bors-servo
Copy link
Contributor

bors-servo commented Aug 2, 2016

📌 Commit b2a8d74 has been approved by pcwalton

@KiChjang
Copy link
Member

KiChjang commented Aug 3, 2016

@bors-servo try- clean retry r=pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

💡 This pull request was already approved, no need to approve it again.

  • This pull request previously failed. You should add more commits to fix the bug, or use retry to trigger a build again.
@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

📌 Commit b2a8d74 has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

Testing commit b2a8d74 with merge fe47bdf...

bors-servo added a commit that referenced this pull request Aug 3, 2016
Implement flexible box layout for row container

<!-- Please describe your changes on the following line: -->

This pull requests implements basic flexible box layout for row container.
It  has implemented most basic flexbox features, including grow, shrink, multi-line, *reverse properties, and alignment under `justify-content`, `align-items`, `align-self`, `align-content`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X]  There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

r? @pcwalton

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12330)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

💔 Test failed - mac-rel-css

@highfive
Copy link

highfive commented Aug 3, 2016

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox-flex-direction-default.htm
  └   → /css-flexbox-1_dev/html/flexbox-flex-direction-default.htm a505f9f57c0b83f64a1ebf31bb8fad4649d94d07
/css-flexbox-1_dev/html/reference/flexbox-flex-direction-ref.htm 54fcc475c3f793d40ae0710e0c82021a8495aa35
Testing a505f9f57c0b83f64a1ebf31bb8fad4649d94d07 == 54fcc475c3f793d40ae0710e0c82021a8495aa35

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox-flex-direction-row-reverse.htm
  └   → /css-flexbox-1_dev/html/flexbox-flex-direction-row-reverse.htm a505f9f57c0b83f64a1ebf31bb8fad4649d94d07
/css-flexbox-1_dev/html/reference/flexbox-flex-direction-ref.htm 54fcc475c3f793d40ae0710e0c82021a8495aa35
Testing a505f9f57c0b83f64a1ebf31bb8fad4649d94d07 == 54fcc475c3f793d40ae0710e0c82021a8495aa35

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox-flex-direction-row.htm
  └   → /css-flexbox-1_dev/html/flexbox-flex-direction-row.htm a505f9f57c0b83f64a1ebf31bb8fad4649d94d07
/css-flexbox-1_dev/html/reference/flexbox-flex-direction-ref.htm 54fcc475c3f793d40ae0710e0c82021a8495aa35
Testing a505f9f57c0b83f64a1ebf31bb8fad4649d94d07 == 54fcc475c3f793d40ae0710e0c82021a8495aa35

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox-flex-wrap-wrap.htm
  └   → /css-flexbox-1_dev/html/flexbox-flex-wrap-wrap.htm a505f9f57c0b83f64a1ebf31bb8fad4649d94d07
/css-flexbox-1_dev/html/reference/flexbox-flex-direction-ref.htm 54fcc475c3f793d40ae0710e0c82021a8495aa35
Testing a505f9f57c0b83f64a1ebf31bb8fad4649d94d07 == 54fcc475c3f793d40ae0710e0c82021a8495aa35

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox-flex-wrap-wrap-reverse.htm
  └   → /css-flexbox-1_dev/html/flexbox-flex-wrap-wrap-reverse.htm a505f9f57c0b83f64a1ebf31bb8fad4649d94d07
/css-flexbox-1_dev/html/reference/flexbox-flex-direction-ref.htm 54fcc475c3f793d40ae0710e0c82021a8495aa35
Testing a505f9f57c0b83f64a1ebf31bb8fad4649d94d07 == 54fcc475c3f793d40ae0710e0c82021a8495aa35

  ▶ FAIL [expected PASS] /css-flexbox-1_dev/html/flexbox_box-clear.htm
  └   → /css-flexbox-1_dev/html/flexbox_box-clear.htm c032f9ccd110b4e972d0da4d7a9f2d0f6398a5f4
/css-flexbox-1_dev/html/reference/flexbox_box-clear-ref.htm eed758e56c9cd89490d0fdfda6531af771783e28
Testing c032f9ccd110b4e972d0da4d7a9f2d0f6398a5f4 == eed758e56c9cd89490d0fdfda6531af771783e28
@stshine
Copy link
Contributor Author

stshine commented Aug 3, 2016

Some upstream changes break the margin collapsing of references, which is sad. (Maybe also #12696 and #12676)

@stshine stshine force-pushed the stshine:flexitem branch from b2a8d74 to 60e2f44 Aug 3, 2016
@wafflespeanut
Copy link
Member

wafflespeanut commented Aug 3, 2016

@bors-servo r=pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

📌 Commit 60e2f44 has been approved by pcwalton

@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

Testing commit 60e2f44 with merge 15947f8...

bors-servo added a commit that referenced this pull request Aug 3, 2016
Implement flexible box layout for row container

<!-- Please describe your changes on the following line: -->

This pull requests implements basic flexible box layout for row container.
It  has implemented most basic flexbox features, including grow, shrink, multi-line, *reverse properties, and alignment under `justify-content`, `align-items`, `align-self`, `align-content`.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X]  There are tests for these changes

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

r? @pcwalton

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/12330)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Aug 3, 2016

@bors-servo bors-servo merged commit 60e2f44 into servo:master Aug 3, 2016
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@pcwalton
Copy link
Contributor

pcwalton commented Aug 3, 2016

🎉 Thanks for pushing this through, @stshine!

@stshine
Copy link
Contributor Author

stshine commented Aug 3, 2016

I feel satisfied and honored to be able to implement this for servo. Thank you @pcwalton again and thanks to everyone who helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

10 participants
You can’t perform that action at this time.