Closed Bug 1867106 Opened 10 months ago Closed 2 months ago

CSSOM doesn't seem to have @page `size` descriptor wired up to be modified or inspected from script

Categories

(Core :: DOM: CSS Object Model, defect)

defect

Tracking

()

RESOLVED DUPLICATE of bug 1890842

People

(Reporter: dholbert, Unassigned)

References

Details

Attachments

(4 files)

Attached file testcase 1

STR:

  1. Load attached testcase.
  2. Check your devtools console (ctrl shift k)

ACTUAL RESULTS:
The last logged line is undefined -- i.e. console.log(document.styleSheets[0].rules[3].style.size is undefined.

Despite that, the previous line does show that if I remove size, we stringify the whole style object as CSS2Properties { size → "3px" }

EXPECTED RESULTS:
We probably should be able to inspect the size descriptor via CSSOM, I think? Unless there's spec text to the contrary (since size has some specialness in terms of not being a real CSS property).

Chrome gives EXPECTED RESULTS fwiw, and it seems native google docs printing relies on that (not just inspecting this value, but also modifying it), in order to dynamically set the user's selected page size for a printed google doc.

Flags: needinfo?(emcdonough)

Here's something long the lines of what I think Google Docs depends on.

In this testcase, I'm dynamically modifying @page margin-top and size in the beforeprint handler. The margin-top modification does take effect, but the size one does not (I think because it's simply not wired up, per the undefined result noted in comment 0).

Not too surprisingly, this affects page-orientation as well -- not just size. Here's a testcase to demonstrate that.

(I don't think Google Docs dynamically sets page-orientation via the CSSOM, but it'd be good to make the same fix there, regardless.)

Blerg. It's not supposed to be exposed per spec. size is a descriptor and not a CSS property. Blink exposes it even in regular style declarations: "size" in document.body.style is true there.

But then again, style.setProperty does work here, so maybe we just expose these and call it a day?

As a workaround, we could ask google to use setProperty("size", ..) rather than .size, which should work?

That should probably work, yeah. Here's a modified version of testcase 2 that does that, which does work as-expected in Firefox Nightly.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)

Blerg. It's not supposed to be exposed per spec. size is a descriptor and not a CSS property. Blink exposes it even in regular style declarations: "size" in document.body.style is true there.

But then again, style.setProperty does work here, so maybe we just expose these and call it a day?

As a workaround, we could ask google to use setProperty("size", ..) rather than .size, which should work?

Yeah, I'm thinking about/looking into what it would look like to have size exist only on the style as returned from page-rules. I don't want to put size on all CSS2Properties, and it would be slightly weird to have a different properties object just for page-rules, but that would be more compatible and would let you set size in cases where it makes sense.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #3)

As a workaround, we could ask google to use setProperty("size", ..) rather than .size, which should work?

I asked our Google Docs contact if they could make this change, and they said that'd be fine.

So: that probably lowers the priority here, until/unless we're aware of other content that expects .size to work in this way.

Duplicate of this bug: 1865203
Blocks: 1865155
No longer duplicate of this bug: 1865203

Google is going to update Google Docs to use setProperty, so we don't need this for the Gsuite work.

No longer blocks: 1521655, 1865155

Emily has filed an issue for the WG to discuss: https://github.com/w3c/csswg-drafts/issues/9685

Thanks, Emily!

It was pointed out that we had discussed this in https://github.com/w3c/csswg-drafts/issues/5649. I should draft the spec changes but if somebody wants to get ahead please be my guest :)

Flags: needinfo?(emilio)
Flags: needinfo?(emilio)
See Also: → 1890842

Give we've got support for CSSPageDescriptors now, I think it's safe to close this.

Status: NEW → RESOLVED
Closed: 2 months ago
Flags: needinfo?(emcdonough)
Resolution: --- → FIXED

Yup, confirmed this is is fixed, with 2024-07-03 being the first good Nightly. (Nightly 2024-07-02 is "bad".)

I think we can just consider this a dupe of bug 1890842.

Duplicate of bug: 1890842
Resolution: FIXED → DUPLICATE
See Also: 1890842
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: