- From: Olli Pettay <olli@pettay.fi>
- Date: Sun, 10 Jan 2016 04:25:56 +0200
- To: Ryosuke Niwa <rniwa@apple.com>, public-webapps WG <public-webapps@w3.org>
- Cc: public-editing-tf <public-editing-tf@w3.org>
Hard to judge this proposal before seeing an API using StaticRange objects. One thing though, if apps were to create an undo stack of their own, they could easily have their own Range-like API implemented in JS. So if that is the only use case, probably not worth to add anything to make the platform more complicated. Especially since StaticRange API might be good for some script library, but not for some other. -Olli On 01/10/2016 01:42 AM, Ryosuke Niwa wrote: > Hi, > > This is yet another feedback from multiple browser vendors (Apple, Google, Microsoft) that got together in Redmond last Thursday to discuss editing API and related events. > > For editing APIs, it's desirable to have a variant of Range that is immutable. For example, if apps were to create an undo stack of its own, then storing the selection state using Range would be problematic because those Ranges would get updated whenever DOM is mutated. Furthermore, live ranges are expensive if browsers had to keep updating them as DOM is mutated. This is analogous to how we're moving away form LiveNodeList/HTMLCollection to use StaticNodeList in various new DOM APIs. > > So we came up with a proposal to add StaticRange: a static, immutable variant of Range defined as follows: > > [Constructor, > Exposed=Window] > interface StaticRange { > readonly attribute Node startContainer; > readonly attribute unsigned long startOffset; > readonly attribute Node endContainer; > readonly attribute unsigned long endOffset; > readonly attribute boolean collapsed; > readonly attribute Node commonAncestorContainer; > > const unsigned short START_TO_START = 0; > const unsigned short START_TO_END = 1; > const unsigned short END_TO_END = 2; > const unsigned short END_TO_START = 3; > short compareBoundaryPoints(unsigned short how, Range sourceRange); > > [NewObject] > Range cloneRange(); > > boolean isPointInRange(Node node, unsigned long offset); > short comparePoint(Node node, unsigned long offset); > > boolean intersectsNode(Node node); > }; > > Along with range extensions from CSS OM view also added as follows: > https://drafts.csswg.org/cssom-view/#extensions-to-the-range-interface > > partial interface StaticRange > { > [NewObject] sequence<DOMRect> getClientRects(); > [NewObject] DOMRect getBoundingClientRect(); > }; > > with one difference, which is to throw an exception (perhaps InvalidStateError?) when StaticRange's boundary points don't share a common ancestor, not in a document, or offsets are out of bounds. > > - R. Niwa > >
Received on Sunday, 10 January 2016 02:26:30 UTC