xul images should support ratio scaling

RESOLVED FIXED in mozilla8



XP Toolkit/Widgets: XUL
7 years ago
6 years ago


(Reporter: Neil Deakin (mostly unavailable until September), Assigned: Neil Deakin (mostly unavailable until September))


(Blocks: 1 bug, {dev-doc-complete})

Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags



(Whiteboard: [qa-])


(1 attachment, 2 obsolete attachments)

Created attachment 463557 [details] [diff] [review]
patch, partially tested, automated tests to come

Such that:

<image src="image.png" maxwidth="400" maxheight="300"/>

can specify maximum sizes and the image will shrink down with the same ratio in both directions.
Created attachment 517458 [details] [diff] [review]
patch with reftests
Assignee: nobody → enndeakin
Attachment #463557 - Attachment is obsolete: true
Attachment #517458 - Flags: review?
Attachment #517458 - Flags: review? → review?(dbaron)
Blocks: 596002
Comment on attachment 517458 [details] [diff] [review]
patch with reftests

Sorry for taking so long to get to this (though for a while I was
postponing it because your bugzilla name said you were on vacation).

'width' and 'height' should not be inputs to
nsLayoutUtils::ComputeAutoSizeWithIntrinsicDimensions; they should
just be local variables inside of it.  (Or, alternatively, they
could be out params and the function could return void, but it's
probably better returning nsSize as you have it.)

In nsLayoutUtils.h, ComputeAutoSizeWithIntrinsicDimensions should
give a better explanation of tentWidth and tentHeight:  it should
describe them as the result of applying the rules for handling
intrinsic sizes and ratios.

The way you use this in nsImageBoxFrame seems to me to all be off by
border+padding.  In particular, the code in nsLayoutUtils that
you're using intends to deal with content-box sizes, but you're
giving it border-box sizes for the min and max sizes (and for the
ignored first two parameters), though you're giving it content box
sizes for the important last 2 parameters.  I *think* that's going
to yield the wrong results.  Then the code in nsLayoutUtils returns
a content box size, but you're returning it directly from
GetPrefSize which is supposed to return a border-box size.

The hand-written code in nsImageBoxFrame seems likewise incorrect in
the presence of border and/or padding.

I didn't look closely at your tests, but I think you need a bunch
with border and padding; you don't seem to have any.
Attachment #517458 - Flags: review?(dbaron) → review-
Created attachment 537208 [details] [diff] [review]
patch with proper border/padding handling

This patch subtracts off and adds on the border/padding as needed.
Attachment #517458 - Attachment is obsolete: true
Attachment #537208 - Flags: review?(dbaron)
Comment on attachment 537208 [details] [diff] [review]
patch with proper border/padding handling

I recommend also having tests with asymmetric padding and border, e.g.,
with padding: 1px 2px 4px 8px.

+    if (size.width != NS_INTRINSICSIZE)
+      size.width += borderPadding.LeftRight();
+    if (size.height != NS_INTRINSICSIZE)
+      size.height += borderPadding.TopBottom();

It shouldn't be possible for these to be NS_INTRINSICSIZE, unless
I'm missing something (which I think would also mean things are
pretty broken).

+      nscoord height = size.height;
+      if (height != NS_INTRINSICSIZE)
+        height -= borderPadding.TopBottom();

Same here.

+      nscoord width = size.width;
+      if (width != NS_INTRINSICSIZE)
+        width -= borderPadding.LeftRight();

And here.

Instead of these tests, could you assert that |size| doesn't have
NS_INTRINSICSIZE components both after AddCSSPrefSize and after

r=dbaron with that

Sorry for the delay getting to this.
Attachment #537208 - Flags: review?(dbaron) → review+
Last Resolved: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
Flags: in-testsuite+


6 years ago
Depends on: 677087


6 years ago
Depends on: 677091
Keywords: dev-doc-needed
Depends on: 677161


6 years ago
Depends on: 677886
tracking-firefox8: --- → +
(tracking-8+ since we might need to back this out on aurora if bug 677091 and related issues don't get fixed)
This patch added tests to the reftest directory layout/xul/base/reftest/ (originally added in bug 442228) which was not listed in the toplevel manifest, so they were never run in our automated testing.  I just did that:
Do we know yet whether this will make Firefox 7? I see there's some concern about possibly backing it out.
The regression problems were fixed so it should be staying in.
Can anyone tell me how can this be verified?
Whiteboard: [qa?]
This bug changes the following behaviour. Given an example such as:

<image src="image.png" maxwidth="200"/>

where image.png is a large image such as a photo, the old behaviour was to shrink the width down to the maximum allowed of 200 but keep the height the same. The new behaviour aligns more with the html img tag and shrinks both the width and height down proportionally.

An automated test also verifies the behaviour.
Given this is covered by automation, I don't think there is much QA can do to verify this is fixed. Simona, if you feel like you have time, you can code an example like in comment 11 (test it in a previous build and the current build to compare).
Whiteboard: [qa?] → [qa-]
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.