Commit 82358b9f authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1415445 - part 3: nsIEditActionListener's WillCreateElement() and...

Bug 1415445 - part 3: nsIEditActionListener's WillCreateElement() and DidCreateElement() should take child node at insertion point or new node itself rather than the container node and offset in it r=m_kato

nsIEditActionListener::WillCreateElement() and
nsIEditActionListener::DidCreateElement() are implemented only by m-c.

So, we can remove a set of container node and offset in it from their argument.
Instead, WillCreateElement() should take a node which will be next sibling of
the new node.

Note that only implementation of them is, HTMLEditRules::DidCreateElement().
So, we can get rid of them and can call HTMLEditRules::DidCreateElement()
directly from EditorBase::CreateNode().  However, such change should be done
in another bug which checks all nsIEditActionListener method implementations.

MozReview-Commit-ID: 4LQEs2WwrVC

--HG--
extra : rebase_source : ee1bee1413c578b2873a291c712b8ef46221db0f
parent 9dd0af51
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -1430,12 +1430,13 @@ EditorBase::CreateNode(nsAtom* aTag,
    pointToInsert.Set(aParent, aParent->Length());
  } else if (aChildAtPosition) {
    pointToInsert.Set(aChildAtPosition);
    // Ensure pointToInsert has offset for sending same offset for both
    // WillCreateNode() and DidCreateNode().
    Unused << pointToInsert.Offset();
  } else {
    pointToInsert.Set(aParent, aPosition);
  }
  // XXX We need to offset at new node to mRangeUpdater.  Therefore, we need
  //     to compute the offset now but this is expensive.  So, if it's possible,
  //     we need to redesign mRangeUpdater as avoiding using indices.
  int32_t offset = static_cast<int32_t>(pointToInsert.Offset());

  AutoRules beginRulesSniffing(this, EditAction::createNode, nsIEditor::eNext);

@@ -1443,8 +1444,7 @@ EditorBase::CreateNode(nsAtom* aTag,
    AutoActionListenerArray listeners(mActionListeners);
    for (auto& listener : listeners) {
      listener->WillCreateNode(nsDependentAtomString(aTag),
                               GetAsDOMNode(pointToInsert.Container()),
                               pointToInsert.Offset());
                               GetAsDOMNode(pointToInsert.GetChildAtOffset()));
    }
  }

@@ -1458,15 +1458,13 @@ EditorBase::CreateNode(nsAtom* aTag,
    MOZ_ASSERT(ret);
  }

  mRangeUpdater.SelAdjCreateNode(pointToInsert.Container(),
                                 pointToInsert.Offset());
  mRangeUpdater.SelAdjCreateNode(pointToInsert.Container(), offset);

  {
    AutoActionListenerArray listeners(mActionListeners);
    for (auto& listener : listeners) {
      listener->DidCreateNode(nsDependentAtomString(aTag), GetAsDOMNode(ret),
                              GetAsDOMNode(pointToInsert.Container()),
                              pointToInsert.Offset(), rv);
      listener->DidCreateNode(nsDependentAtomString(aTag),
                              GetAsDOMNode(ret), rv);
    }
  }

+3 −6
Original line number Diff line number Diff line
@@ -8518,24 +8518,21 @@ HTMLEditRules::InsertBRIfNeededInternal(nsINode& aNode,

NS_IMETHODIMP
HTMLEditRules::WillCreateNode(const nsAString& aTag,
                              nsIDOMNode* aParent,
                              int32_t aPosition)
                              nsIDOMNode* aNextSiblingOfNewNode)
{
  return NS_OK;
}

NS_IMETHODIMP
HTMLEditRules::DidCreateNode(const nsAString& aTag,
                             nsIDOMNode* aNode,
                             nsIDOMNode* aParent,
                             int32_t aPosition,
                             nsIDOMNode* aNewNode,
                             nsresult aResult)
{
  if (!mListenerEnabled) {
    return NS_OK;
  }
  // assumption that Join keeps the righthand node
  nsresult rv = mUtilRange->SelectNode(aNode);
  nsresult rv = mUtilRange->SelectNode(aNewNode);
  NS_ENSURE_SUCCESS(rv, rv);
  return UpdateDocChangeRange(mUtilRange);
}
+3 −4
Original line number Diff line number Diff line
@@ -106,10 +106,9 @@ public:

  // nsIEditActionListener methods

  NS_IMETHOD WillCreateNode(const nsAString& aTag, nsIDOMNode* aParent,
                            int32_t aPosition) override;
  NS_IMETHOD DidCreateNode(const nsAString& aTag, nsIDOMNode* aNode,
                           nsIDOMNode* aParent, int32_t aPosition,
  NS_IMETHOD WillCreateNode(const nsAString& aTag,
                            nsIDOMNode* aNextSiblingOfNewNode) override;
  NS_IMETHOD DidCreateNode(const nsAString& aTag, nsIDOMNode* aNewNode,
                           nsresult aResult) override;
  NS_IMETHOD WillInsertNode(nsIDOMNode* aNode, nsIDOMNode* aParent,
                            int32_t aPosition) override;
+8 −16
Original line number Diff line number Diff line
@@ -31,29 +31,21 @@ interface nsIEditActionListener : nsISupports{
  /**
   * Called before the editor creates a node.
   * @param aTag                    The tag name of the DOM Node to create.
   * @param aParent   The node to insert the new object into
   * @param aPosition The place in aParent to insert the new node
   *                  0=first child, 1=second child, etc.
   *                  any number > number of current children = last child
   * @param aNextSiblingOfNewNode   The node which will be next sibling of
   *                                new node.  If the new node will be appended,
   *                                this is null.
   */
  void WillCreateNode(in DOMString aTag,
                            in nsIDOMNode   aParent,
                            in long aPosition);
                      in nsIDOMNode aNextSiblingOfNewNode);

  /**
   * Called after the editor creates a node.
   * @param aTag      The tag name of the DOM Node to create.
   * @param aNode     The DOM Node that was created.
   * @param aParent   The node to insert the new object into
   * @param aPosition The place in aParent to insert the new node
   *                  0=first child, 1=second child, etc.
   *                  any number > number of current children = last child
   * @param aNewNode  The DOM Node that was created.
   * @param aResult   The result of the create node operation.
   */
  void DidCreateNode(in DOMString aTag,
                           in nsIDOMNode aNode,
                           in nsIDOMNode aParent,
                           in long          aPosition,
                     in nsIDOMNode aNewNode,
                     in nsresult aResult);

  /**
+5 −2
Original line number Diff line number Diff line
@@ -3373,13 +3373,16 @@ nsTextServicesDocument::WillJoinNodes(nsIDOMNode *aLeftNode,
// -------------------------------

NS_IMETHODIMP
nsTextServicesDocument::WillCreateNode(const nsAString& aTag, nsIDOMNode *aParent, int32_t aPosition)
nsTextServicesDocument::WillCreateNode(const nsAString& aTag,
                                       nsIDOMNode* aNextSiblingOfNewNode)
{
  return NS_OK;
}

NS_IMETHODIMP
nsTextServicesDocument::DidCreateNode(const nsAString& aTag, nsIDOMNode *aNode, nsIDOMNode *aParent, int32_t aPosition, nsresult aResult)
nsTextServicesDocument::DidCreateNode(const nsAString& aTag,
                                      nsIDOMNode* aNewNode,
                                      nsresult aResult)
{
  return NS_OK;
}
Loading