Thoughts on nsHTMLEditor::SetInlineProperty
By glazou on Friday 11 January 2013, 15:09 - Mozilla - Permalink
- get the selection
- for each range in the selection
- get the startNode, endNode, startOffset, endOffset of the range
- if startNode is an element, let startNode be the startOffset-nth child of startNode
- if endNode is an element, let endNode be the (endOffset-1)-nth child of endNode
- promote selection to an array of nodes, iterating all nodes in the selection from startNode to endNode in traversal order
- if the iterated node is entirely contained in the
selection
- if the descendant node is an HTML element equivalent to the style to set, replace it by its contents; continue iterating with first child of the original node
- if the node is an element and carries the CSS property to set, delete that CSS style ; if the element carries no CSS style and no other attribute after that, replace it by its contents; continue iterating with first child of the original node
- if the node is a significant text node, store it in the array, continue iterating
- if the node is an inline element node, store it in the array, continue iterating skipping all children of the node
- else continue iterating
- else if the node is only partially contained in the selection
- if the node is an inline node or a text node, split node deep to selection boundaries; resulting node is now entirely contained in selection, apply steps above.
- else continue interating
- if the iterated node is entirely contained in the
selection
- let startNode be the first node in the array and endNode the last one
- let direction be 1
- if startNode is not an element and endNode is an element, let direction be -1
- for each node in the array browsed in increasing index order if
direction is 1 and decreasing order otherwise:
- if the ancestors of the node set the requested style, do nothing and continue with next node in array
- let refNode be the previousSibling if direction is 1 and the nextSibling otherwise
- in HTML mode:
- if refNode is the HTML equivalent to the style to set and carries no attribute, append the node to the children of refNode; continue
- encapsulate the node into the HTML equivalent element to the style to set
- in CSS mode:
- if refNode carries only the CSS style to set and no other attribute, append the node to the children of refNode; continue
- encapsulate the node into a span carrying the style to set
