Bug 32541 - Percentage height should be ignored in some cases
Summary: Percentage height should be ignored in some cases
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL: http://www.w3.org/TR/CSS2/visudet.htm...
Keywords:
: 47286 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-14 23:37 PST by Kent Tamura
Modified: 2017-07-18 08:27 PDT (History)
6 users (show)

See Also:


Attachments
Proposed patch (26.29 KB, patch)
2009-12-15 16:21 PST, Kent Tamura
no flags Details | Formatted Diff | Diff
Proposed patch (rev.2) (25.78 KB, patch)
2009-12-15 16:24 PST, Kent Tamura
no flags Details | Formatted Diff | Diff
Proposed patch (rev.3) (372.13 KB, patch)
2009-12-15 17:43 PST, Kent Tamura
bdakin: review-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kent Tamura 2009-12-14 23:37:19 PST
Open LayoutTests/fast/replaced/table-percent-height.html with Firefox, IE8, or Opera.  The page has some pairs of 75%-height element and 100%-height element.  You'll see each of pairs has identical elements with these browsers, and not with WebKit browsers.
Other browsers ignore "height:N%" in it because of the following rule of CSS 2.1:

<percentage>
    Specifies a percentage height. The percentage is calculated with respect to the height
    of the generated box's containing block. If the height of the containing block is not
    specified explicitly (i.e., it depends on content height), and this element is not absolutely
    positioned, the value computes to 'auto'. A percentage height on the root element is
    relative to the initial containing block. 

We should fix this because of browser compatibility and standard compliance.
Comment 1 Kent Tamura 2009-12-15 16:21:50 PST
Created attachment 44921 [details]
Proposed patch
Comment 2 WebKit Review Bot 2009-12-15 16:22:22 PST
style-queue ran check-webkit-style on attachment 44921 [details] without any errors.
Comment 3 Kent Tamura 2009-12-15 16:24:29 PST
Created attachment 44923 [details]
Proposed patch (rev.2)

The previous patch had a unexpected change.
Comment 4 WebKit Review Bot 2009-12-15 16:28:02 PST
style-queue ran check-webkit-style on attachment 44923 [details] without any errors.
Comment 5 Kent Tamura 2009-12-15 16:53:43 PST
Ah, I need to add -expected.png to the patch.
Comment 6 Kent Tamura 2009-12-15 17:43:39 PST
Created attachment 44927 [details]
Proposed patch (rev.3)

* Add expected PNGs
* Fix some typos
Comment 7 Beth Dakin 2010-02-02 14:57:59 PST
Comment on attachment 44927 [details]
Proposed patch (rev.3)

> +            if (cb->isTableCell() && cb->style()->height().isAuto()
> +                // Check the table for the cell too.. This is needed to pass
> +                // LayoutTests/tables/mozilla/bug/bug32205-2.html.
> +                && cb->containingBlock()->style()->height().isAuto()) {

We don't usually put comments in the middle of the condition of an if-statement like you have done here, and I don't think it's a style we want to encourage. This comment should be moved out. I also think there needs to be a better justification for checking the containing block's containing block than that it is needed to make a test pass. Are you sure this isn't just a hack for that test?

> +                // Reset to Auto.
> +                style()->setHeight(Length());

Generally, we avoid changing the RenderStyle's values like this. Instead, when this case is detected while calculating the height of the renderer, the height of the renderer should be adjusted accordingly, but you should not have to change the RenderStyle.

> +                    RenderTheme::defaultTheme()->adjustSize(style());

You should also avoid calling into the RenderTheme. Again, you want to change the render's height value, not the RenderStyle's. If you work on fixing the renderer's calculated height value, calling into the theme should not be necessary.

> +void RenderTheme::adjustSize(RenderStyle* style)
>
I don't understand how this new function is related to this bug or why it is necessary. But it certainly won't be necessary when you focus on calculating the correct height for the renderer rather than changing the RenderStyle.

Also, I we try to avoid such class-specific code (in this case, it's table-specific code) in RenderBox. If you find that calcHeight() is still the right place to patch when you work on the calculation of the renderer's height, then you should consider creating a version of calcHeight in one of the RenderTable* files to do the table-specific parts of the calculation.
Comment 8 Kent Tamura 2010-04-24 12:09:32 PDT
(In reply to comment #7)

Ok, I understand we should not modify RenderStyle values.

A difficult point to fix this bug is that only RenderTheme::adjustStyle() knows the intrinsic sizes of form controls, and adjustStyle() is called before constructing renderer nodes.  It's hard to check if we should ignore percentage heights in adjustStyle() because it's hard to obtain containingBlock in it.

A solution would be to introduce a function returning intrinsic sizes of form controls.  It will be called by adjustStyle() and renderers.
What do you think?
Comment 9 Kent Tamura 2010-10-07 22:11:21 PDT
*** Bug 47286 has been marked as a duplicate of this bug. ***