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)

defect
Not set
normal

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
Do you have a testcase you can attach?
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
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).
Attached patch missed header file (obsolete) — Splinter Review
Attachment #258429 - Attachment is obsolete: true
Attached patch mochitest for embedded testcase (obsolete) — Splinter Review
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
Attachment #329442 - Flags: review?(tor) → review+
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. :-)
Assignee: general → jwatt
I will post an updated reftest if I can get this reftest infrastructure to run correctly.
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.
Attached patch updated mochitest (obsolete) — Splinter Review
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)
Patch in bug 361920 fixes this so that we're compatible with Opera.
Fixed by check in for bug 361920
Status: NEW → RESOLVED
Closed: 16 years ago
Depends on: 361920
Resolution: --- → FIXED
Assignee: jwatt → longsonr
Attachment #329540 - Attachment is obsolete: true
Attachment #329540 - Flags: review?(jwatt)
Attachment #258792 - Attachment is obsolete: true
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
QA Contact: ian → general
Assignee: longsonr → nobody
Use getBoundingClientRect if you want to get the pixel width of an <svg> element.
Status: REOPENED → RESOLVED
Closed: 16 years ago10 years ago
Depends on: 530985
No longer depends on: 361920
Resolution: --- → INVALID
Resolution: INVALID → DUPLICATE
Attachment #363687 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: