commit 38dc93ccf1549b964930c50bbc3f55f2377b6e23 Author: Simon Montagu smontagu@smontagu.org Date: Wed Aug 6 12:02:59 2014 +0300
Bug 1037641 - Split SetDirectionFromChangedTextNode into TextNodeWillChangeDirection and TextNodeChangedDirection. r=ehsan, a=abillings --- content/base/public/DirectionalityUtils.h | 18 +++++++++++++----- content/base/src/DirectionalityUtils.cpp | 26 ++++++++++++++------------ content/base/src/nsGenericDOMDataNode.cpp | 10 +++++++--- 3 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/content/base/public/DirectionalityUtils.h b/content/base/public/DirectionalityUtils.h index 85a7e78..4b1758c 100644 --- a/content/base/public/DirectionalityUtils.h +++ b/content/base/public/DirectionalityUtils.h @@ -79,12 +79,20 @@ void WalkDescendantsSetDirAuto(mozilla::dom::Element* aElement, void WalkDescendantsClearAncestorDirAuto(mozilla::dom::Element* aElement);
/** - * When the contents of a text node have changed, deal with any elements whose - * directionality needs to change + * When the contents of a text node are about to change, retrieve the current + * directionality of the text + * + * @return whether the text node affects the directionality of any element + */ +bool TextNodeWillChangeDirection(nsIContent* aTextNode, Directionality* aOldDir, + uint32_t aOffset); + +/** + * After the contents of a text node have changed, change the directionality + * of any elements whose directionality is determined by that node */ -void SetDirectionFromChangedTextNode(nsIContent* aTextNode, uint32_t aOffset, - const PRUnichar* aBuffer, uint32_t aLength, - bool aNotify); +void TextNodeChangedDirection(nsIContent* aTextNode, Directionality aOldDir, + bool aNotify);
/** * When a text node is appended to an element, find any ancestors with dir=auto diff --git a/content/base/src/DirectionalityUtils.cpp b/content/base/src/DirectionalityUtils.cpp index 9fa8a12..a689a19 100644 --- a/content/base/src/DirectionalityUtils.cpp +++ b/content/base/src/DirectionalityUtils.cpp @@ -316,6 +316,7 @@ GetDirectionFromText(const PRUnichar* aText, const uint32_t aLength, start < end && NS_IS_LOW_SURROGATE(*start)) { ch = SURROGATE_TO_UCS4(ch, *start++); + current++; }
Directionality dir = GetDirectionFromChar(ch); @@ -822,26 +823,27 @@ void SetAncestorDirectionIfAuto(nsINode* aTextNode, Directionality aDir, } }
-void -SetDirectionFromChangedTextNode(nsIContent* aTextNode, uint32_t aOffset, - const PRUnichar* aBuffer, uint32_t aLength, - bool aNotify) +bool +TextNodeWillChangeDirection(nsIContent* aTextNode, Directionality* aOldDir, + uint32_t aOffset) { if (!NodeAffectsDirAutoAncestor(aTextNode)) { nsTextNodeDirectionalityMap::EnsureMapIsClearFor(aTextNode); - return; + return false; }
uint32_t firstStrong; - Directionality oldDir = GetDirectionFromText(aTextNode->GetText(), - &firstStrong); - if (aOffset > firstStrong) { - return; - } + *aOldDir = GetDirectionFromText(aTextNode->GetText(), &firstStrong); + return (aOffset <= firstStrong); +}
- Directionality newDir = GetDirectionFromText(aBuffer, aLength); +void +TextNodeChangedDirection(nsIContent* aTextNode, Directionality aOldDir, + bool aNotify) +{ + Directionality newDir = GetDirectionFromText(aTextNode->GetText()); if (newDir == eDir_NotSet) { - if (oldDir != eDir_NotSet && aTextNode->HasTextNodeDirectionalityMap()) { + if (aOldDir != eDir_NotSet && aTextNode->HasTextNodeDirectionalityMap()) { // This node used to have a strong directional character but no // longer does. ResetTextNodeDirection() will re-resolve the // directionality of any elements whose directionality was diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index 2efc6cd..69ee693 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -294,9 +294,9 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount, nsNodeUtils::CharacterDataWillChange(this, &info); }
- if (NodeType() == nsIDOMNode::TEXT_NODE) { - SetDirectionFromChangedTextNode(this, aOffset, aBuffer, aLength, aNotify); - } + Directionality oldDir = eDir_NotSet; + bool dirAffectsAncestor = (NodeType() == nsIDOMNode::TEXT_NODE && + TextNodeWillChangeDirection(this, &oldDir, aOffset));
if (aOffset == 0 && endOffset == textLength) { // Replacing whole text or old text was empty. Don't bother to check for @@ -338,6 +338,10 @@ nsGenericDOMDataNode::SetTextInternal(uint32_t aOffset, uint32_t aCount, document->SetBidiEnabled(); }
+ if (dirAffectsAncestor) { + TextNodeChangedDirection(this, oldDir, aNotify); + } + // Notify observers if (aNotify) { CharacterDataChangeInfo info = {
tbb-commits@lists.torproject.org