diff --git a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
index 7a83903d2a3..62401f45881 100644
--- a/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLDataTransfer.cpp
@@ -190,59 +190,68 @@ NS_IMETHODIMP nsHTMLEditor::LoadHTMLWithCharset(const nsAReadableString & aInput
// force IME commit; set up rules sniffing and batching
ForceCompositionEnd();
nsAutoEditBatch beginBatching(this);
- nsAutoRules beginRulesSniffing(this, kOpHTMLLoad, nsIEditor::eNext);
+ nsAutoRules beginRulesSniffing(this, kOpLoadHTML, nsIEditor::eNext);
// Get selection
nsCOMPtrselection;
res = GetSelection(getter_AddRefs(selection));
if (NS_FAILED(res)) return res;
- PRBool isCollapsed;
- res = selection->GetIsCollapsed(&isCollapsed);
+ nsTextRulesInfo ruleInfo(nsTextEditRules::kLoadHTML);
+ PRBool cancel, handled;
+ res = mRules->WillDoAction(selection, &ruleInfo, &cancel, &handled);
if (NS_FAILED(res)) return res;
-
- // Delete Selection, but only if it isn't collapsed, see bug #106269
- if (!isCollapsed)
+ if (cancel) return NS_OK; // rules canceled the operation
+ if (!handled)
{
- res = DeleteSelection(eNone);
+ PRBool isCollapsed;
+ res = selection->GetIsCollapsed(&isCollapsed);
if (NS_FAILED(res)) return res;
- }
- // Get the first range in the selection, for context:
- nsCOMPtr range, clone;
- res = selection->GetRangeAt(0, getter_AddRefs(range));
- NS_ENSURE_SUCCESS(res, res);
- if (!range)
- return NS_ERROR_NULL_POINTER;
- nsCOMPtr nsrange (do_QueryInterface(range));
- if (!nsrange)
- return NS_ERROR_NO_INTERFACE;
+ // Delete Selection, but only if it isn't collapsed, see bug #106269
+ if (!isCollapsed)
+ {
+ res = DeleteSelection(eNone);
+ if (NS_FAILED(res)) return res;
+ }
- // create fragment for pasted html
- nsCOMPtr docfrag;
- {
- res = nsrange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
+ // Get the first range in the selection, for context:
+ nsCOMPtr range, clone;
+ res = selection->GetRangeAt(0, getter_AddRefs(range));
NS_ENSURE_SUCCESS(res, res);
- }
- // put the fragment into the document
- nsCOMPtr parent, junk;
- res = range->GetStartContainer(getter_AddRefs(parent));
- NS_ENSURE_SUCCESS(res, res);
- if (!parent)
- return NS_ERROR_NULL_POINTER;
- PRInt32 childOffset;
- res = range->GetStartOffset(&childOffset);
- NS_ENSURE_SUCCESS(res, res);
-
- nsCOMPtr nodeToInsert;
- docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
- while (nodeToInsert)
- {
- res = InsertNode(nodeToInsert, parent, childOffset++);
+ if (!range)
+ return NS_ERROR_NULL_POINTER;
+ nsCOMPtr nsrange (do_QueryInterface(range));
+ if (!nsrange)
+ return NS_ERROR_NO_INTERFACE;
+
+ // create fragment for pasted html
+ nsCOMPtr docfrag;
+ {
+ res = nsrange->CreateContextualFragment(aInputString, getter_AddRefs(docfrag));
NS_ENSURE_SUCCESS(res, res);
+ }
+ // put the fragment into the document
+ nsCOMPtr parent, junk;
+ res = range->GetStartContainer(getter_AddRefs(parent));
+ NS_ENSURE_SUCCESS(res, res);
+ if (!parent)
+ return NS_ERROR_NULL_POINTER;
+ PRInt32 childOffset;
+ res = range->GetStartOffset(&childOffset);
+ NS_ENSURE_SUCCESS(res, res);
+
+ nsCOMPtr nodeToInsert;
docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
+ while (nodeToInsert)
+ {
+ res = InsertNode(nodeToInsert, parent, childOffset++);
+ NS_ENSURE_SUCCESS(res, res);
+ docfrag->GetFirstChild(getter_AddRefs(nodeToInsert));
+ }
}
- return res;
+
+ return mRules->DidDoAction(selection, &ruleInfo, res);
}
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
index 7e639e64a0f..6dd93e1ee9e 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -407,7 +407,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection
(action == nsHTMLEditor::kOpInsertQuotation) ||
(action == nsEditor::kOpInsertNode) ||
(action == nsHTMLEditor::kOpHTMLPaste ||
- (action == nsHTMLEditor::kOpHTMLLoad)))
+ (action == nsHTMLEditor::kOpLoadHTML)))
{
res = ReplaceNewlines(mDocChangeRange);
}
@@ -436,7 +436,7 @@ nsHTMLEditRules::AfterEditInner(PRInt32 action, nsIEditor::EDirection aDirection
(action == nsEditor::kOpDeleteSelection) ||
(action == nsEditor::kOpInsertBreak) ||
(action == nsHTMLEditor::kOpHTMLPaste ||
- (action == nsHTMLEditor::kOpHTMLLoad)))
+ (action == nsHTMLEditor::kOpLoadHTML)))
{
res = AdjustSelection(selection, aDirection);
if (NS_FAILED(res)) return res;
@@ -483,6 +483,8 @@ nsHTMLEditRules::WillDoAction(nsISelection *aSelection,
info->inString,
info->outString,
info->maxLength);
+ case kLoadHTML:
+ return WillLoadHTML(aSelection, aCancel);
case kInsertBreak:
return WillInsertBreak(aSelection, aCancel, aHandled);
case kDeleteSelection:
@@ -1241,6 +1243,25 @@ nsHTMLEditRules::WillInsertText(PRInt32 aAction,
return res;
}
+nsresult
+nsHTMLEditRules::WillLoadHTML(nsISelection *aSelection, PRBool *aCancel)
+{
+ if (!aSelection || !aCancel) return NS_ERROR_NULL_POINTER;
+
+ *aCancel = PR_FALSE;
+
+ // Delete mBogusNode if it exists. If we really need one,
+ // it will be added during post-processing in AfterEditInner().
+
+ if (mBogusNode)
+ {
+ mEditor->DeleteNode(mBogusNode);
+ mBogusNode = nsnull;
+ }
+
+ return NS_OK;
+}
+
nsresult
nsHTMLEditRules::WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBool *aHandled)
{
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditRules.h b/mozilla/editor/libeditor/html/nsHTMLEditRules.h
index 2d364aa2f52..9d9bba43f23 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditRules.h
+++ b/mozilla/editor/libeditor/html/nsHTMLEditRules.h
@@ -117,6 +117,7 @@ protected:
const nsAReadableString *inString,
nsAWritableString *outString,
PRInt32 aMaxLength);
+ nsresult WillLoadHTML(nsISelection *aSelection, PRBool *aCancel);
nsresult WillInsertBreak(nsISelection *aSelection, PRBool *aCancel, PRBool *aHandled);
nsresult DidInsertBreak(nsISelection *aSelection, nsresult aResult);
nsresult WillDeleteSelection(nsISelection *aSelection, nsIEditor::EDirection aAction,
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h
index 65aef6919c3..8d4a9a8ee6b 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.h
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h
@@ -96,7 +96,7 @@ public:
kOpSetTextProperty = 3010,
kOpRemoveTextProperty = 3011,
kOpHTMLPaste = 3012,
- kOpHTMLLoad = 3013
+ kOpLoadHTML = 3013
};
diff --git a/mozilla/editor/libeditor/text/nsTextEditRules.h b/mozilla/editor/libeditor/text/nsTextEditRules.h
index 4fee83dc64e..f739466810c 100644
--- a/mozilla/editor/libeditor/text/nsTextEditRules.h
+++ b/mozilla/editor/libeditor/text/nsTextEditRules.h
@@ -98,7 +98,8 @@ public:
kMakeBasicBlock = 3005,
kRemoveList = 3006,
kMakeDefListItem = 3007,
- kInsertElement = 3008
+ kInsertElement = 3008,
+ kLoadHTML = 3013
};
public: