From 65ac5c1602a642de8f598d9984a164d1a76a466c Mon Sep 17 00:00:00 2001 From: "jfrancis%netscape.com" Date: Mon, 9 Aug 1999 22:51:40 +0000 Subject: [PATCH] fixing bug 9366 --- editor/base/nsHTMLEditRules.cpp | 2 ++ editor/base/nsHTMLEditor.cpp | 9 ++++++++- editor/base/nsTextEditRules.h | 11 +++++++++-- editor/libeditor/html/nsHTMLEditRules.cpp | 2 ++ editor/libeditor/html/nsHTMLEditor.cpp | 9 ++++++++- editor/libeditor/text/nsTextEditRules.h | 11 +++++++++-- 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/editor/base/nsHTMLEditRules.cpp b/editor/base/nsHTMLEditRules.cpp index 331730d32e1..1a256866c2a 100644 --- a/editor/base/nsHTMLEditRules.cpp +++ b/editor/base/nsHTMLEditRules.cpp @@ -113,6 +113,8 @@ nsHTMLEditRules::WillDoAction(nsIDOMSelection *aSelection, return WillMakeAddress(aSelection, aCancel); case kMakePRE: return WillMakePRE(aSelection, aCancel); + case kInsertElement: + return WillInsert(aSelection, aCancel); } return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel); } diff --git a/editor/base/nsHTMLEditor.cpp b/editor/base/nsHTMLEditor.cpp index d43989fa871..53c231da410 100644 --- a/editor/base/nsHTMLEditor.cpp +++ b/editor/base/nsHTMLEditor.cpp @@ -1063,6 +1063,13 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) if (!NS_SUCCEEDED(res) || !selection) return NS_ERROR_FAILURE; + // hand off to the rules system, see if it has anything to say about this + PRBool cancel; + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertElement); + ruleInfo.insertElement = aElement; + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; + // Clear current selection. // Should put caret at anchor point? if (!aDeleteSelection) @@ -1164,7 +1171,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } // Now we can insert the new node res = InsertNode(aElement, parent, offsetForInsert); - + // Set caret after element, but check for special case // of inserting table-related elements: set in first cell instead if (!SetCaretInTableCell(aElement)) diff --git a/editor/base/nsTextEditRules.h b/editor/base/nsTextEditRules.h index 158d1400c90..ccc7b5414ac 100644 --- a/editor/base/nsTextEditRules.h +++ b/editor/base/nsTextEditRules.h @@ -75,7 +75,8 @@ public: kAlign = 3004, kMakeHeader = 3005, kMakeAddress = 3006, - kMakePRE = 3007 + kMakePRE = 3007, + kInsertElement = 3008 }; protected: @@ -175,7 +176,10 @@ class nsTextRulesInfo : public nsRulesInfo outString(0), typeInState(), maxLength(-1), - collapsedAction(nsIEditor::eDeleteNext) + collapsedAction(nsIEditor::eDeleteNext), + bOrdered(PR_FALSE), + alignType(0), + insertElement(0) {}; virtual ~nsTextRulesInfo() {}; @@ -195,6 +199,9 @@ class nsTextRulesInfo : public nsRulesInfo // kAlign const nsString *alignType; + + // kInsertElement + const nsIDOMElement* insertElement; }; #endif //nsTextEditRules_h__ diff --git a/editor/libeditor/html/nsHTMLEditRules.cpp b/editor/libeditor/html/nsHTMLEditRules.cpp index 331730d32e1..1a256866c2a 100644 --- a/editor/libeditor/html/nsHTMLEditRules.cpp +++ b/editor/libeditor/html/nsHTMLEditRules.cpp @@ -113,6 +113,8 @@ nsHTMLEditRules::WillDoAction(nsIDOMSelection *aSelection, return WillMakeAddress(aSelection, aCancel); case kMakePRE: return WillMakePRE(aSelection, aCancel); + case kInsertElement: + return WillInsert(aSelection, aCancel); } return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel); } diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index d43989fa871..53c231da410 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -1063,6 +1063,13 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) if (!NS_SUCCEEDED(res) || !selection) return NS_ERROR_FAILURE; + // hand off to the rules system, see if it has anything to say about this + PRBool cancel; + nsTextRulesInfo ruleInfo(nsHTMLEditRules::kInsertElement); + ruleInfo.insertElement = aElement; + res = mRules->WillDoAction(selection, &ruleInfo, &cancel); + if (cancel || (NS_FAILED(res))) return res; + // Clear current selection. // Should put caret at anchor point? if (!aDeleteSelection) @@ -1164,7 +1171,7 @@ nsHTMLEditor::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) } // Now we can insert the new node res = InsertNode(aElement, parent, offsetForInsert); - + // Set caret after element, but check for special case // of inserting table-related elements: set in first cell instead if (!SetCaretInTableCell(aElement)) diff --git a/editor/libeditor/text/nsTextEditRules.h b/editor/libeditor/text/nsTextEditRules.h index 158d1400c90..ccc7b5414ac 100644 --- a/editor/libeditor/text/nsTextEditRules.h +++ b/editor/libeditor/text/nsTextEditRules.h @@ -75,7 +75,8 @@ public: kAlign = 3004, kMakeHeader = 3005, kMakeAddress = 3006, - kMakePRE = 3007 + kMakePRE = 3007, + kInsertElement = 3008 }; protected: @@ -175,7 +176,10 @@ class nsTextRulesInfo : public nsRulesInfo outString(0), typeInState(), maxLength(-1), - collapsedAction(nsIEditor::eDeleteNext) + collapsedAction(nsIEditor::eDeleteNext), + bOrdered(PR_FALSE), + alignType(0), + insertElement(0) {}; virtual ~nsTextRulesInfo() {}; @@ -195,6 +199,9 @@ class nsTextRulesInfo : public nsRulesInfo // kAlign const nsString *alignType; + + // kInsertElement + const nsIDOMElement* insertElement; }; #endif //nsTextEditRules_h__