Closed
Bug 1407305
Opened 7 years ago
Closed 7 years ago
Avoid using nsINode::GetChildAt() in EditorBase::GetPriorNode() and EditorBase::GetNextNode()
Categories
(Core :: DOM: Editor, enhancement)
Core
DOM: Editor
Tracking
()
RESOLVED
FIXED
mozilla58
Tracking | Status | |
---|---|---|
firefox58 | --- | fixed |
People
(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)
References
Details
Attachments
(4 files, 1 obsolete file)
24.25 KB,
patch
|
masayuki
:
review+
|
Details | Diff | Splinter Review |
5.76 KB,
patch
|
masayuki
:
review+
|
Details | Diff | Splinter Review |
7.19 KB,
patch
|
masayuki
:
review+
|
Details | Diff | Splinter Review |
15.40 KB,
patch
|
masayuki
:
review+
|
Details | Diff | Splinter Review |
No description provided.
Assignee | ||
Updated•7 years ago
|
Summary: Avoid using jsINode::GetChildAt() in EditorBase::GetPriorNode() and EditorBase::GetNextNode() → Avoid using nsINode::GetChildAt() in EditorBase::GetPriorNode() and EditorBase::GetNextNode()
Assignee | ||
Comment 1•7 years ago
|
||
Attachment #8917052 -
Flags: review?(masayuki)
Assignee | ||
Comment 2•7 years ago
|
||
Attachment #8917053 -
Flags: review?(masayuki)
Assignee | ||
Comment 3•7 years ago
|
||
Attachment #8917054 -
Flags: review?(masayuki)
Assignee | ||
Comment 4•7 years ago
|
||
Attachment #8917055 -
Flags: review?(masayuki)
Assignee | ||
Comment 5•7 years ago
|
||
Attachment #8917175 -
Flags: review?(masayuki)
Assignee | ||
Updated•7 years ago
|
Attachment #8917053 -
Attachment is obsolete: true
Attachment #8917053 -
Flags: review?(masayuki)
Comment 6•7 years ago
|
||
Comment on attachment 8917052 [details] [diff] [review]
Part 1: Add a aChildAtOffset argument to HTMLEditor::GetPriorHTMLNode()
Although, this review is not requested with MozReview. So, I cannot check other blocks which are not shown in this diff easily. Therefore, I don't check whether you forget to add lines to modify |child| variable around |offset| in each method which calls GetPrioerHTMLNode(). Please double check it before landing by yourself.
>@@ -5545,42 +5554,45 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
> // aWhere == kEnd
> // some special casing for text nodes
> if (node->IsNodeOfType(nsINode::eTEXT)) {
> if (!node->GetParentNode()) {
> // Okay, can't promote any further
> return EditorDOMPoint(node, offset);
> }
> // want to be after the text node
> offset = 1 + node->GetParentNode()->IndexOf(node);
>+ child = node;
> node = node->GetParentNode();
The offset includes |+1|. So, I guess that the child should be node->GetNextSibling().
> }
>
> // look ahead through any further inline nodes that aren't across a <br> from
> // us, and that are enclosed in the same block.
> nsCOMPtr<nsIContent> nextNode =
> htmlEditor->GetNextHTMLNode(node, offset, true);
>
> while (nextNode && !IsBlockNode(*nextNode) && nextNode->GetParentNode()) {
> offset = 1 + nextNode->GetParentNode()->IndexOf(nextNode);
>+ child = node;
ditto.
>@@ -5614,16 +5626,17 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
> // Don't walk past the editable section. Note that we need to check before
> // walking up to a parent because we need to return the parent object, so
> // the parent itself might not be in the editable area, but it's OK.
> if (!htmlEditor->IsDescendantOfEditorRoot(node) &&
> !htmlEditor->IsDescendantOfEditorRoot(parent)) {
> break;
> }
>
>+ child = node;
> node = parent;
> // we want to be AFTER nearNode
> offset = parentOffset + 1;
ditto.
>@@ -6537,17 +6551,17 @@ HTMLEditRules::ReturnInParagraph(Selection* aSelection,
> sibling = mHTMLEditor->CreateBR(parent, offset);
> if (newSelNode) {
> // We split the parent after the br we've just inserted.
> selNode = GetAsDOMNode(parent);
> selOffset = offset + 1;
> }
> }
> *aHandled = true;
>- return SplitParagraph(aPara, sibling, aSelection, address_of(selNode), &selOffset);
>+ return SplitParagraph(GetAsDOMNode(aPara), sibling, aSelection, address_of(selNode), &selOffset);
nit: too long line. please break after |aSelection,|.
>@@ -7528,16 +7542,17 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
>
> // get the (collapsed) selection location
> nsCOMPtr<nsINode> selNode, temp;
> int32_t selOffset;
> nsresult rv =
> EditorBase::GetStartNodeAndOffset(aSelection,
> getter_AddRefs(selNode), &selOffset);
> NS_ENSURE_SUCCESS(rv, rv);
>+ nsIContent* child = aSelection->GetRangeAt(0)->GetChildAtStartOffset();
I wonder, if GetStartNodeAndOffset() returns RawRangeBoundary, we don't need to call GetChildAtStartOffset() at every caller. However, it must cause changing a lot of lines. So, shouldn't be scope of this bug.
Attachment #8917052 -
Flags: review?(masayuki) → review+
Updated•7 years ago
|
Attachment #8917054 -
Flags: review?(masayuki) → review+
Updated•7 years ago
|
Attachment #8917055 -
Flags: review?(masayuki) → review+
Comment 7•7 years ago
|
||
Comment on attachment 8917175 [details] [diff] [review]
Part 2: Add a aChildAtOffset argument to HTMLEditor::GetNextHTMLNode()
>@@ -5579,21 +5582,21 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
> offset = 1 + node->GetParentNode()->IndexOf(node);
> child = node;
> node = node->GetParentNode();
> }
>
> // look ahead through any further inline nodes that aren't across a <br> from
> // us, and that are enclosed in the same block.
> nsCOMPtr<nsIContent> nextNode =
>- htmlEditor->GetNextHTMLNode(node, offset, true);
>+ htmlEditor->GetNextHTMLNode(node, offset, child, true);
>
> while (nextNode && !IsBlockNode(*nextNode) && nextNode->GetParentNode()) {
> offset = 1 + nextNode->GetParentNode()->IndexOf(nextNode);
>- child = node;
>+ child = nextNode->GetNextSibling();
Oh, you're fixing the bug of part 1 in part 2... Please do this in part 1.
>@@ -5606,42 +5609,42 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
> // Don't walk past the editable section. Note that we need to check before
> // walking up to a parent because we need to return the parent object, so
> // the parent itself might not be in the editable area, but it's OK.
> if (!htmlEditor->IsDescendantOfEditorRoot(node) &&
> !htmlEditor->IsDescendantOfEditorRoot(parent)) {
> break;
> }
>
>- child = node;
>+ child = node->GetNextSibling();
Ditto.
>@@ -7543,23 +7546,24 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
>
> // get the (collapsed) selection location
> nsCOMPtr<nsINode> selNode, temp;
> int32_t selOffset;
> nsresult rv =
> EditorBase::GetStartNodeAndOffset(aSelection,
> getter_AddRefs(selNode), &selOffset);
> NS_ENSURE_SUCCESS(rv, rv);
>- nsIContent* child = aSelection->GetRangeAt(0)->GetChildAtStartOffset();
>+ nsINode* child = aSelection->GetRangeAt(0)->GetChildAtStartOffset();
Really sad...
>@@ -7673,34 +7677,35 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
> }
> return NS_OK;
> }
>
>
> nsresult
> HTMLEditRules::FindNearSelectableNode(nsINode* aSelNode,
> int32_t aSelOffset,
>- nsIContent* aChildAtOffset,
>+ nsINode* aChildAtOffset,
Sad...
Attachment #8917175 -
Flags: review?(masayuki) → review+
Assignee | ||
Comment 8•7 years ago
|
||
(In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #7)
> >@@ -7543,23 +7546,24 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
> >
> > // get the (collapsed) selection location
> > nsCOMPtr<nsINode> selNode, temp;
> > int32_t selOffset;
> > nsresult rv =
> > EditorBase::GetStartNodeAndOffset(aSelection,
> > getter_AddRefs(selNode), &selOffset);
> > NS_ENSURE_SUCCESS(rv, rv);
> >- nsIContent* child = aSelection->GetRangeAt(0)->GetChildAtStartOffset();
> >+ nsINode* child = aSelection->GetRangeAt(0)->GetChildAtStartOffset();
>
> Really sad...
>
> >@@ -7673,34 +7677,35 @@ HTMLEditRules::AdjustSelection(Selection* aSelection,
> > }
> > return NS_OK;
> > }
> >
> >
> > nsresult
> > HTMLEditRules::FindNearSelectableNode(nsINode* aSelNode,
> > int32_t aSelOffset,
> >- nsIContent* aChildAtOffset,
> >+ nsINode* aChildAtOffset,
>
> Sad...
FWIW while testing I found out that we actually observe document nodes here from EditorBase::GetNodeLocation(), so using nsIContent* was just the only option here.
Assignee | ||
Comment 9•7 years ago
|
||
(In reply to Masayuki Nakano [:masayuki] (JST, +0900) from comment #6)
> >@@ -5545,42 +5554,45 @@ HTMLEditRules::GetPromotedPoint(RulesEndpoint aWhere,
> > // aWhere == kEnd
> > // some special casing for text nodes
> > if (node->IsNodeOfType(nsINode::eTEXT)) {
> > if (!node->GetParentNode()) {
> > // Okay, can't promote any further
> > return EditorDOMPoint(node, offset);
> > }
> > // want to be after the text node
> > offset = 1 + node->GetParentNode()->IndexOf(node);
> >+ child = node;
> > node = node->GetParentNode();
>
> The offset includes |+1|. So, I guess that the child should be
> node->GetNextSibling().
FWIW this one was actually correct since the node here is a text node.
Comment 10•7 years ago
|
||
Pushed by eakhgari@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/aa6c322a98b0
Part 1: Add a aChildAtOffset argument to HTMLEditor::GetPriorHTMLNode(); r=masayuki
https://hg.mozilla.org/integration/mozilla-inbound/rev/dc1c6227e652
Part 2: Add a aChildAtOffset argument to HTMLEditor::GetNextHTMLNode(); r=masayuki
https://hg.mozilla.org/integration/mozilla-inbound/rev/8c6f9b6b56eb
Part 3: Avoid using GetChildAt() in EditorBase::GetPriorNode(); r=masayuki
https://hg.mozilla.org/integration/mozilla-inbound/rev/e22de36807c6
Part 4: Avoid using GetChildAt() in EditorBase::GetNextNode(); r=masayuki
Comment 11•7 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/aa6c322a98b0
https://hg.mozilla.org/mozilla-central/rev/dc1c6227e652
https://hg.mozilla.org/mozilla-central/rev/8c6f9b6b56eb
https://hg.mozilla.org/mozilla-central/rev/e22de36807c6
Status: NEW → RESOLVED
Closed: 7 years ago
status-firefox58:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla58
You need to log in
before you can comment on or make changes to this bug.
Description
•