This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13164 - Centralize changes to CharacterData so other specs can hook in easily
Summary: Centralize changes to CharacterData so other specs can hook in easily
Status: RESOLVED FIXED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 13248 13250
  Show dependency treegraph
 
Reported: 2011-07-06 20:30 UTC by Aryeh Gregor
Modified: 2011-07-24 18:04 UTC (History)
4 users (show)

See Also:


Attachments

Description Aryeh Gregor 2011-07-06 20:30:14 UTC
Bug 13153 is related.  If this is fixed, that becomes invalid.

There are at least two things that currently care about when CharacterData changes: range mutations and mutation events.  Currently CharacterData is changed directly by lots of different parts of the spec.  This leads to ugly stuff like

"""
This includes (but is not limited to) if a script or specification sets a data or nodeValue or textContent attribute, or if a script or specification calls the replaceWholeText() method, or if a specification says to set the node's data without specifically referring to its data attribute.
"""
http://html5.org/specs/dom-range.html#range-behavior-under-document-mutation

This could be simplified a bunch if all CharacterData changes were funneled through one algorithm.  It could be replaceData().  Thus you'd change deleteData(offset, count) to work the same as replaceData(offset, count, 0), and insertData(offset, data) to work the same as replaceData(offset, 0, data), and text.data = s to work the same as replaceData(0, -1, s), and so on.  This is probably how implementations work anyway (I've been told it's how Gecko works).  You might then add an explicit hook for other specs to use, as the last step of the algorithm, like "Run <span>CharacterData change steps</span>" or something, with "CharacterData change steps" defined as "whatever other specs say".

If you do this, one thing to keep in mind is what to do about no-ops.  If the new data winds up being the same as the old data, how is it treated?  WebKit doesn't mutate ranges in this case, and that's the behavior I specced.  Presumably if we do that, we don't want to fire mutation events (or their replacements) either.  So you could add a step to the effect of "if this isn't going to actually change anything, abort" somewhere before the hook that other specs use.
Comment 1 Anne 2011-07-06 21:12:04 UTC
Define common algorithm to define the methods in is one way to have less text in that section. Addressing this bug would involve having a single callback for other specifications, but that needs to wait for a solution to mutation events.
Comment 2 Aryeh Gregor 2011-07-06 21:41:18 UTC
Even before mutation events are solved, it would be useful to have a single callback so that the description of range mutation can be simplified.  DOM Range is currently pretty ugly on this subject, as you can see in the part of the spec I linked to in comment 0.
Comment 3 Anne 2011-07-14 11:43:45 UTC
They now use a single algorithm.
Comment 4 Aryeh Gregor 2011-07-14 14:45:00 UTC
Looks good to me, thanks!