[SVGSVGElement].width.baseVal.value returns 1 for 100% wide SVG

RESOLVED DUPLICATE of bug 1283539

Status

()

Core
SVG
RESOLVED DUPLICATE of bug 1283539
11 years ago
2 months ago

People

(Reporter: Swatinem, Unassigned)

Tracking

({regression, testcase})

Trunk
regression, testcase
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 6 obsolete attachments)

(Reporter)

Description

11 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a3) Gecko/20060622 BonEcho/2.0a3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1a3) Gecko/20060622 BonEcho/2.0a3

[SVGSVGElement].width.baseVal.value returns 1 for a 100% wide SVG.
This bug only occurs in a recent trunk build width gecko 1.9. It works flawlessly width a 1.8 branch build.
[SVGSVGElement].viewBox.baseVal.width returns the correct width however.

Reproducible: Always

Steps to Reproduce:
retrieve the value of [SVGSVGElement].width.baseVal.value
Actual Results:  
1

Expected Results:  
the correct width in pixels, e.g. 1158

Comment 1

11 years ago
Do you have a testcase you can attach?
(Reporter)

Comment 2

11 years ago
Created attachment 226785 [details]
testcase that prints the width of a 100% wide svg

I've just created a simple testcase. This prints out the svgDoc.width.baseVal.value and svgDoc.viewBox.baseVal.width values of a svg with width="100%".
The two values match on a branch build. A trunk build outputs 1 for svgDoc.width.baseVal.value.
Opera does not support the viewBox method at all.
This bug breaks my SVGraph examples at http://swatinemz.sourceforge.net/svgraph.xhtml

Comment 3

11 years ago
Created attachment 226795 [details]
pure svg testcase - click on red

Comment 4

11 years ago
Some results of testing - seems like little agreement:

FF 1.5:

        width.baseVal.value   = pixel width of area
        viewBox.baseVal.width = pixel width of area

FF trunk:

        width.baseVal.value   = 1
        viewBox.baseVal.width = pixel width of area

Opera 9:

        width.baseVal.value   = pixel width of area
        viewBox.baseVal.width = 0

Batik 1.6:

        width.baseVal.value   =  pixel width of area
        viewBox.baseVal.width =  <"getViewBox not implemented">

Adobe SVG Viewer 3.0:

        width.baseVal.value   = <"null or not an object">
        viewBox.baseVal.width = <"null or not an object">
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Reporter)

Comment 5

10 years ago
Todays build regressed some more. I don't know which checkin caused it but it now outputs the following:
svgDoc.width.baseVal.value = 1
svgDoc.viewBox.baseVal.width = 0
That means there is currently no way to get the actual width of a 100% wide SVG with scripting :(

Comment 6

10 years ago
Created attachment 258429 [details] [diff] [review]
make nsSVGLength2 handle a outersvg context

This doesn't reliably fix the HTML testcase attached to this bug, as the load event appears to fire before the first reflow, which sets up the outer svg dimensions.  Not sure if that is per spec or not (the random values due to an uninitialized variable before the first reflow definitely aren't, but that's trivial to fix once we decide what the appropriate behavior should be).

Comment 7

10 years ago
Created attachment 258792 [details] [diff] [review]
missed header file
Attachment #258429 - Attachment is obsolete: true
(Reporter)

Comment 8

9 years ago
Created attachment 329442 [details] [diff] [review]
mochitest for embedded testcase

I wrote a mochitest for the embedded testcase to practice writing mochitests.
Something else I noticed while playing with firebug:
>>> document.getElementById('svg').width.baseVal.newValueSpecifiedUnits(5,100) // set value to 100px
>>> document.getElementById('svg').width.baseVal.convertToSpecifiedUnits(2) // convert to percentage
>>> document.getElementById('svg').width.baseVal.value
100 // value is always in "user units" according to spec. "user units" is always equal to pixels?
>>> document.getElementById('svg').width.baseVal.valueAsString
"10000%" // this is wrong

The SVGLength implementation somehow uses a fixed conversion ratio of 100 from "user units" (pixels) to percentage. The embedded SVG actually grows when I use the convertToSpecifiedUnits method.
Attachment #329442 - Flags: review?(tor)
Ah, crap. We shipped with this broken? :-(

Thanks a lot for the mochitest Arpad! It looks good to me.
Keywords: regression, testcase
OS: Windows XP → All
Hardware: PC → All

Updated

9 years ago
Attachment #329442 - Flags: review?(tor) → review+
(Reporter)

Comment 10

9 years ago
Created attachment 329453 [details] [diff] [review]
reftest for convertToSpecifiedUnits

This is a reftest which tests the bug that the SVG is growing when using the convertToSpecifiedUnits method. I hope I've done that right, I didn't get the reftests to start :(
Attachment #329453 - Flags: review?(jwatt)
The basic problem here is our use of nsSVGElement::GetCtx which returns an nsSVGSVGElement* to the ancestor element that provides the coordinate context for the element on which it is called. Unfortunately there's no such ancestor for <svg> elements that are the root of an SVG document fragment, so GetCtx returns null. GetAxisLength then falls back to returning 1 when it doesn't get a context, so GetUnitScaleFactor returns 100 and we get 100/100 in nsSVGValue2::GetBaseValue.
Arpad: does that reftest actually fail currently? I thought this bug was only for percentage width/height on the rootmost <svg>. Besides that, it's preferable to get rid of the -ref file and just compare to pass.svg if possible. You can hopefully do that if you set the margin, border and padding on the html and body elements to none. Also, better to use convertToSpecifiedUnits(nsSVGLength.<ENUM_CONSTANT>) instead of convertToSpecifiedUnits(2). I've no idea offhand what 2 is. :-)

Updated

9 years ago
Assignee: general → jwatt
(Reporter)

Comment 13

9 years ago
I will post an updated reftest if I can get this reftest infrastructure to run correctly.

Comment 14

9 years ago
I think this would be better as a mochitest. It's the output of convertToSpecifiedUnits that you are trying to test. What gets rendered is a side effect.
(Reporter)

Comment 15

9 years ago
Created attachment 329540 [details] [diff] [review]
updated mochitest

This also tests the behavior of convertToSpecifiedUnits and friends.

Why does mozilla use SpecifiedUnits internaly and converts them to user units on every access to .value and not the other way around?

I also noticed that besides GetAxisLength also GetMMPerPixel always returns 1.
Attachment #329442 - Attachment is obsolete: true
Attachment #329453 - Attachment is obsolete: true
Attachment #329540 - Flags: review?(jwatt)
Attachment #329453 - Flags: review?(jwatt)

Comment 16

8 years ago
Patch in bug 361920 fixes this so that we're compatible with Opera.

Comment 17

8 years ago
Fixed by check in for bug 361920
Status: NEW → RESOLVED
Last Resolved: 8 years ago
Depends on: 361920
Resolution: --- → FIXED

Comment 18

8 years ago
Created attachment 363687 [details] [diff] [review]
mochitest updated to tip with invalid test removed
Assignee: jwatt → longsonr
Attachment #329540 - Attachment is obsolete: true
Attachment #329540 - Flags: review?(jwatt)

Updated

8 years ago
Attachment #258792 - Attachment is obsolete: true

Comment 19

8 years ago
checked in http://hg.mozilla.org/mozilla-central/rev/bbbe69d822c0
Flags: in-testsuite+

Updated

8 years ago
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
QA Contact: ian → general

Updated

7 years ago
Assignee: longsonr → nobody

Comment 20

3 years ago
Use getBoundingClientRect if you want to get the pixel width of an <svg> element.
Status: REOPENED → RESOLVED
Last Resolved: 8 years ago3 years ago
Depends on: 530985
No longer depends on: 361920
Resolution: --- → INVALID
Comment hidden (off-topic)

Updated

9 months ago
Resolution: INVALID → DUPLICATE
Duplicate of bug: 1283539

Updated

9 months ago
Blocks: 1283539

Updated

2 months ago
Attachment #363687 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.