Skip to content

[css-typed-om] Describe what setting is2D on CSSTransformComponent should do #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wilddamon opened this issue Jun 19, 2017 · 9 comments
Closed

Comments

@wilddamon
Copy link
Contributor

wilddamon commented Jun 19, 2017

https://drafts.css-houdini.org/css-typed-om/#dom-csstransformcomponent-is2d

Should setting is2D to true clear out any 3D attributes on a component? For example:

  let rotation = new CSSRotation(1, 2, 3, new CSSUnitValue(10, 'deg'));
  assert_false(rotation.is2D);
  assert_equals(rotation.z, 3);

  rotation.is2D = true;
  assert_true(rotation.is2D);
  assert_equals(rotation.z, 1);

Additionally, should setting is2D to false again after that restore the previous value? My guess is no, but if it did, then the following would work

  let rotation = new CSSRotation(1, 2, 3, new CSSUnitValue(10, 'deg'));
  rotation.is2D = true;
  assert_true(rotation.is2D);
  assert_equals(rotation.z, 1);
  rotation.is2D = false;
  assert_false(rotation.is2D);
  assert_equals(rotation.z, 3);

The difference is whether the 3D attributes are still "there but hidden" when is2D is set to true, or whether setting is2D clobbers them.

@tabatkins
Copy link
Member

No, under the current spec setting it to true just makes the 3d portions irrelevant. They're not affected in any way, it just changes how you interpret the object when translating to a CSS value.

@tabatkins
Copy link
Member

tabatkins commented Jun 19, 2017

In other words:

let rotation = new CSSRotation(1, 2, 3, CSS.deg(10));
assert_false(rotation.is2D);
assert_equals(rotation.z, 3);
assert_equals(rotation+"", "rotate3d(1, 2, 3, 10deg)");

rotation.is2D = true;
assert_true(rotation.is2D);
assert_equals(rotation.z, 3);
assert_equals(rotation+"", "rotate(10deg)");

(Actually defining the stringifiers is still on my TODO list, but this is what's intended.)

@wilddamon
Copy link
Contributor Author

Oh, so the getters should still return "3d" values for the transform, even when the component is set to being 2D? So you can set things, and see that they've been set, but they don't get applied. Isn't that potentially confusing for authors?

@wilddamon
Copy link
Contributor Author

wilddamon commented Jun 22, 2017

Oh, and for CSSTransformValue, if all the contained components have is2D set to true, should toMatrix still return the 3D matrix?
https://drafts.css-houdini.org/css-typed-om/#dom-csstransformvalue-tomatrix

If yes, should there be a way for developers to be able to get the 2D matrix?

@tabatkins
Copy link
Member

Oh, so the getters should still return "3d" values for the transform, even when the component is set to being 2D? So you can set things, and see that they've been set, but they don't get applied. Isn't that potentially confusing for authors?

Yes, yes, and potentially yes, but the alternatives were more confusing and/or had very bad ergonomics. For example, say that when is2D is set, we replace the 3d components with appropriately "null" objects, and ignore any writes to those values. But the values are objects themselves in some cases, like CSSTranslation.z, where it's a CSSUnitValue - we'd have to somehow communicate to that object that it should ignore writes as well. That requires either a hidden flag that I check in all the algorithms, or a parallel object hierarchy of silently-readonly objects.

Oh, and for CSSTransformValue, if all the contained components have is2D set to true, should toMatrix still return the 3D matrix?

The spec says that it multiplies their "equivalent 4x4 transform matrix"es. This should change based on whether it's 2d or not, just like the serialization does; I should put in a note making that clearer. Then I need to see if DOMMatrix automatically gets is2D set correctly for this case; if not, I'll need an explicit check for it.

@wilddamon
Copy link
Contributor Author

I see what you mean - I had prototyped returning a new value for CSSTranslation.z each time if is2D was true, but that's a bit weird too.

Cool, I'll implement CSSTransformValue changing the resultant matrix depending on the is2D-ness.

@tabatkins
Copy link
Member

I had prototyped returning a new value for CSSTranslation.z each time if is2D was true, but that's a bit weird too.

Yeah, that's precisely the behavior that bz complained about elsewhere - attributes "feel" cheap/static, so they shouldn't create fresh objects on every read, only methods should do that.

@tabatkins
Copy link
Member

Okay, added a note about this in 7873bee

@tabatkins
Copy link
Member

And just checked - the is2D flag of DOMMatrix is not automagically set, so the algorithm now handles that.

msisov pushed a commit to msisov/chromium that referenced this issue Jul 3, 2017
…tch new spec

- is2D is now handled at the base class (CSSTransformComponent) level

- Setting is2D doesn't affect values returned from getters, but does
affect ToCSSValue and AsMatrix (used by CSSTransformValue)
(w3c/css-houdini-drafts#414)

- CSSMatrixComponent takes an options dictionary to specify its 2D-ness.

Spec:
https://drafts.css-houdini.org/css-typed-om/#dom-csstransformcomponent-is2d

BUG=545318

Review-Url: https://codereview.chromium.org/2943303002
Cr-Commit-Position: refs/heads/master@{#483944}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants