Index: editor/libeditor/html/nsHTMLEditor.cpp
===================================================================
RCS file: /cvsroot/mozilla/editor/libeditor/html/nsHTMLEditor.cpp,v
retrieving revision 1.559
diff -u -9 -p -r1.559 nsHTMLEditor.cpp
--- editor/libeditor/html/nsHTMLEditor.cpp 26 Aug 2007 05:53:38 -0000 1.559
+++ editor/libeditor/html/nsHTMLEditor.cpp 21 Sep 2007 03:37:32 -0000
@@ -279,20 +279,19 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc,
if (1)
{
// block to scope nsAutoEditInitRulesTrigger
nsAutoEditInitRulesTrigger rulesTrigger(static_cast(this), rulesRes);
// Init the plaintext editor
result = nsPlaintextEditor::Init(aDoc, aPresShell, aRoot, aSelCon, aFlags);
if (NS_FAILED(result)) { return result; }
- // the HTML Editor is CSS-aware only in the case of Composer
- mCSSAware = (0 == aFlags);
+ UpdateCSSAwareForFlags(aFlags);
// disable Composer-only features
if (aFlags & eEditorMailMask)
{
SetAbsolutePositioningEnabled(PR_FALSE);
SetSnapToGridEnabled(PR_FALSE);
}
// Init the HTML-CSS utils
@@ -411,24 +410,31 @@ nsHTMLEditor::RemoveEventListeners()
}
NS_IMETHODIMP
nsHTMLEditor::GetFlags(PRUint32 *aFlags)
{
if (!mRules || !aFlags) { return NS_ERROR_NULL_POINTER; }
return mRules->GetFlags(aFlags);
}
+void
+nsHTMLEditor::UpdateCSSAwareForFlags(PRUint32 aFlags) {
+ mCSSAware = ((aFlags & (eEditorNoCSSMask | eEditorMailMask)) == 0);
+}
+
+
NS_IMETHODIMP
nsHTMLEditor::SetFlags(PRUint32 aFlags)
{
if (!mRules) { return NS_ERROR_NULL_POINTER; }
- mCSSAware = ((aFlags & (eEditorNoCSSMask | eEditorMailMask)) == 0);
+
+ UpdateCSSAwareForFlags(aFlags);
return mRules->SetFlags(aFlags);
}
NS_IMETHODIMP
nsHTMLEditor::InitRules()
{
// instantiate the rules for the html editor
nsresult res = NS_NewHTMLEditRules(getter_AddRefs(mRules));
@@ -5438,18 +5444,37 @@ nsHTMLEditor::RemoveAttributeOrEquivalen
nsresult
nsHTMLEditor::SetIsCSSEnabled(PRBool aIsCSSPrefChecked)
{
nsresult err = NS_ERROR_NOT_INITIALIZED;
if (mHTMLCSSUtils)
{
err = mHTMLCSSUtils->SetCSSEnabled(aIsCSSPrefChecked);
}
+ // Disable the eEditorNoCSSMask flag if we're enabling CSS.
+ if (NS_SUCCEEDED(err)) {
+ PRUint32 flags = 0;
+ NS_ENSURE_SUCCESS(GetFlags(&flags), NS_OK);
+
+ if (aIsCSSPrefChecked) {
+ // Turn off NoCSS as we're enabling CSS
+ if (flags & eEditorNoCSSMask) {
+ flags -= eEditorNoCSSMask;
+ }
+ } else {
+ // Turn on NoCSS, as we're disabling CSS.
+ if (!(flags & eEditorNoCSSMask)) {
+ flags += eEditorNoCSSMask;
+ }
+ }
+
+ NS_ENSURE_SUCCESS(SetFlags(flags), NS_OK);
+ }
return err;
}
// Set the block background color
NS_IMETHODIMP
nsHTMLEditor::SetCSSBackgroundColor(const nsAString& aColor)
{
if (!mRules) { return NS_ERROR_NOT_INITIALIZED; }
ForceCompositionEnd();
Index: editor/libeditor/html/nsHTMLEditor.h
===================================================================
RCS file: /cvsroot/mozilla/editor/libeditor/html/nsHTMLEditor.h,v
retrieving revision 1.233
diff -u -9 -p -r1.233 nsHTMLEditor.h
--- editor/libeditor/html/nsHTMLEditor.h 26 Aug 2007 05:53:38 -0000 1.233
+++ editor/libeditor/html/nsHTMLEditor.h 21 Sep 2007 03:37:32 -0000
@@ -444,18 +444,23 @@ public:
protected:
NS_IMETHOD InitRules();
// Create the event listeners for the editor to install
virtual nsresult CreateEventListeners();
virtual void RemoveEventListeners();
+ // Sets mCSSAware to correspond to aFlags. This toggles whether CSS is
+ // used to style elements in the editor. Note that the editor is only CSS
+ // aware by default in Composer and in the mail editor.
+ void UpdateCSSAwareForFlags(PRUint32 aFlags);
+
/** returns the layout object (nsIFrame in the real world) for aNode
* @param aNode the content to get a frame for
* @param aLayoutObject the "primary frame" for aNode, if one exists. May be null
* @return NS_OK whether a frame is found or not
* an error if some serious error occurs
*/
NS_IMETHOD GetLayoutObject(nsIDOMNode *aInNode, nsISupports **aOutLayoutObject);
// Return TRUE if aElement is a table-related elemet and caret was set