Closed
Bug 342513
Opened 19 years ago
Closed 10 years ago
[SVGSVGElement].width.baseVal.value returns 1 for 100% wide SVG
Categories
(Core :: SVG, defect)
Core
SVG
Tracking
()
RESOLVED
DUPLICATE
of bug 1283539
People
(Reporter: Swatinem, Unassigned)
References
Details
(Keywords: regression, testcase)
Attachments
(2 files, 6 obsolete files)
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
Reporter | ||
Comment 2•19 years ago
|
||
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
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•18 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 :(
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).
Attachment #258429 -
Attachment is obsolete: true
Reporter | ||
Comment 8•16 years ago
|
||
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)
Comment 9•16 years ago
|
||
Ah, crap. We shipped with this broken? :-(
Thanks a lot for the mochitest Arpad! It looks good to me.
Updated•16 years ago
|
Attachment #329442 -
Flags: review?(tor) → review+
Reporter | ||
Comment 10•16 years ago
|
||
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)
Comment 11•16 years ago
|
||
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.
Comment 12•16 years ago
|
||
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•16 years ago
|
Assignee: general → jwatt
Reporter | ||
Comment 13•16 years ago
|
||
I will post an updated reftest if I can get this reftest infrastructure to run correctly.
Comment 14•16 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•16 years ago
|
||
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•16 years ago
|
||
Patch in bug 361920 fixes this so that we're compatible with Opera.
Comment 17•16 years ago
|
||
Fixed by check in for bug 361920
Comment 18•16 years ago
|
||
Assignee: jwatt → longsonr
Attachment #329540 -
Attachment is obsolete: true
Attachment #329540 -
Flags: review?(jwatt)
Updated•16 years ago
|
Attachment #258792 -
Attachment is obsolete: true
Comment 19•16 years ago
|
||
Flags: in-testsuite+
Updated•16 years ago
|
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Updated•15 years ago
|
QA Contact: ian → general
Updated•15 years ago
|
Assignee: longsonr → nobody
Comment 20•10 years ago
|
||
Use getBoundingClientRect if you want to get the pixel width of an <svg> element.
Comment hidden (off-topic) |
Updated•8 years ago
|
Resolution: INVALID → DUPLICATE
Updated•8 years ago
|
Attachment #363687 -
Attachment is obsolete: true
You need to log in
before you can comment on or make changes to this bug.
Description
•