From 1c0239e18b430f9850043b8a191838a0b190edd2 Mon Sep 17 00:00:00 2001 From: Alexander Surkov Date: Sat, 5 Mar 2016 12:26:18 -0500 Subject: [PATCH] Bug 1251871 - text removal from a hypertext may result in empty text nodes, r=davidb --- accessible/generic/HyperTextAccessible.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/accessible/generic/HyperTextAccessible.cpp b/accessible/generic/HyperTextAccessible.cpp index 6dcf89241db9..b34522e75848 100644 --- a/accessible/generic/HyperTextAccessible.cpp +++ b/accessible/generic/HyperTextAccessible.cpp @@ -408,15 +408,23 @@ HyperTextAccessible::OffsetToDOMPoint(int32_t aOffset) Accessible* child = GetChildAt(childIdx); int32_t innerOffset = aOffset - GetChildOffset(childIdx); - // A text leaf case. The point is inside the text node. + // A text leaf case. if (child->IsTextLeaf()) { - nsIContent* content = child->GetContent(); - int32_t idx = 0; - if (NS_FAILED(RenderedToContentOffset(content->GetPrimaryFrame(), - innerOffset, &idx))) - return DOMPoint(); + // The point is inside the text node. This is always true for any text leaf + // except a last child one. See assertion below. + if (aOffset < GetChildOffset(childIdx + 1)) { + nsIContent* content = child->GetContent(); + int32_t idx = 0; + if (NS_FAILED(RenderedToContentOffset(content->GetPrimaryFrame(), + innerOffset, &idx))) + return DOMPoint(); - return DOMPoint(content, idx); + return DOMPoint(content, idx); + } + + // Set the DOM point right after the text node. + MOZ_ASSERT(static_cast(aOffset) == CharacterCount()); + innerOffset = 1; } // Case of embedded object. The point is either before or after the element.