diff --git a/mozilla/editor/base/nsEditor.cpp b/mozilla/editor/base/nsEditor.cpp index b88c1d1eb1b..ea677112254 100644 --- a/mozilla/editor/base/nsEditor.cpp +++ b/mozilla/editor/base/nsEditor.cpp @@ -148,7 +148,6 @@ nsEditor::nsEditor() , mActionListeners(nsnull) , mDocDirtyState(-1) , mDocWeak(nsnull) -, mPrefs(nsnull) { //initialize member variables here NS_INIT_REFCNT(); @@ -176,11 +175,6 @@ nsEditor::~nsEditor() delete mActionListeners; mActionListeners = 0; } - - // Release service pointers - if (mPrefs) - nsServiceManager::ReleaseService(kPrefCID, mPrefs); - } @@ -278,44 +272,6 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) caret->SetCaretReadOnly(PR_FALSE); } - // NOTE: We don't fail if we can't get prefs or string bundles - // since we could still be used as the text edit widget without prefs - - // Get the prefs service (Note: can't use nsCOMPtr for service pointers) - nsresult ignoredResult = nsServiceManager::GetService(kPrefCID, - nsIPref::GetIID(), - (nsISupports**)&mPrefs); - if (NS_FAILED(ignoredResult) || !mPrefs) - { - if (gNoisy) { printf("ERROR: Failed to get Prefs Service instance.\n");} - } - - // TODO: Cache basic preferences? - // Register callbacks for preferences that we need to - // respond to while running - - nsIStringBundleService* service; - ignoredResult = nsServiceManager::GetService(kStringBundleServiceCID, - nsIStringBundleService::GetIID(), - (nsISupports**)&service); - - if (NS_SUCCEEDED(ignoredResult) && service) - { - nsILocale* locale = nsnull; - ignoredResult = service->CreateBundle(EDITOR_BUNDLE_URL, locale, - getter_AddRefs(mStringBundle)); - // We don't need to keep service around once we created the bundle - nsServiceManager::ReleaseService(kStringBundleServiceCID, service); - } else { - if (gNoisy) printf("ERROR: Failed to get StringBundle Service instance.\n"); - } - -/* - Example of getting a string: - nsString value; - ret = mStringBundle->GetStringFromName("editor.foo", value); -*/ - // Set the selection to the beginning: BeginningOfDocument(); diff --git a/mozilla/editor/base/nsEditor.h b/mozilla/editor/base/nsEditor.h index 51c7b934989..b374a3d4a7f 100644 --- a/mozilla/editor/base/nsEditor.h +++ b/mozilla/editor/base/nsEditor.h @@ -607,8 +607,6 @@ protected: nsWeakPtr mDocWeak; // weak reference to the nsIDOMDocument nsCOMPtr mDTD; - // Services are not nsCOMPtr friendly - nsIPref *mPrefs; static PRInt32 gInstanceCount; diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index 570169fb7bd..e893575d2b9 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -1871,24 +1871,6 @@ nsEditorShell::InsertElement(nsIDOMElement *element, PRBool deleteSelection) return result; } -NS_IMETHODIMP -nsEditorShell::SaveHLineSettings(nsIDOMElement* aElement) -{ - nsresult result = NS_NOINTERFACE; - switch (mEditorType) - { - case eHTMLTextEditorType: - // this is bogus. We should save the HLine settings (or HRule, as it's more properly known) here. - result = mEditor->SaveHLineSettings(aElement); - break; - - case ePlainTextEditorType: - default: - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; -} - NS_IMETHODIMP nsEditorShell::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { diff --git a/mozilla/editor/base/nsHTMLEditor.cpp b/mozilla/editor/base/nsHTMLEditor.cpp index 600cc1e1081..af5f9b635e9 100644 --- a/mozilla/editor/base/nsHTMLEditor.cpp +++ b/mozilla/editor/base/nsHTMLEditor.cpp @@ -108,13 +108,12 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif -// Some utilities to handle stupid overloading of "A" tag for link and named anchor +// Some utilities to handle annoying overloading of "A" tag for link and named anchor static char hrefText[] = "href"; -static char linkText[] = "link"; static char anchorTxt[] = "anchor"; static char namedanchorText[] = "namedanchor"; -#define IsLink(s) (s.EqualsIgnoreCase(hrefText) || s.EqualsIgnoreCase(linkText)) +#define IsLink(s) (s.EqualsIgnoreCase(hrefText)) #define IsNamedAnchor(s) (s.EqualsIgnoreCase(anchorTxt) || s.EqualsIgnoreCase(namedanchorText)) static PRBool IsLinkNode(nsIDOMNode *aNode) @@ -1277,7 +1276,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { // Collapse selection to just after desired element, res = selection->Collapse(parent, offsetInParent+1); -#ifdef DEBUG_cmanske +#if 0 //def DEBUG_cmanske { nsAutoString name; parent->GetNodeName(name); @@ -2127,64 +2126,10 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // Set default values for new elements if (TagName.Equals("hr")) { - // Hard coded defaults in case there's no prefs - nsAutoString align("center"); - nsAutoString width("100%"); - nsAutoString height("2"); - PRBool bNoShade = PR_FALSE; - - if (mPrefs) - { - char buf[16]; - PRInt32 iAlign; - // Currently using 0=left, 1=center, and 2=right - // XXX: ERROR_HANDLING if these results are intentionally thrown away, it should be documented here - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.align", &iAlign))) - { - switch (iAlign) { - case 0: - align = "left"; - break; - case 2: - align = "right"; - break; - } - } - PRInt32 iHeight; - PRUint32 count; - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.height", &iHeight))) - { - count = PR_snprintf(buf, 16, "%d", iHeight); - if (count > 0) - { - height = buf; - } - } - PRInt32 iWidth; - PRBool bPercent; - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.width", &iWidth)) && - NS_SUCCEEDED(mPrefs->GetBoolPref("editor.hrule.width_percent", &bPercent))) - { - count = PR_snprintf(buf, 16, "%d", iWidth); - if (count > 0) - { - width = buf; - if (bPercent) - width.Append("%"); - } - } - PRBool bShading; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("editor.hrule.shading", &bShading))) - { - bNoShade = !bShading; - } - } - newElement->SetAttribute("align", align); - newElement->SetAttribute("height", height); - newElement->SetAttribute("width", width); - if (bNoShade) - newElement->SetAttribute("noshade", ""); - + // Note that we read the user's attributes for these from prefs (in InsertHLine JS) + newElement->SetAttribute("align","center"); + newElement->SetAttribute("width","100%"); + newElement->SetAttribute("height","2"); } else if (TagName.Equals("table")) { newElement->SetAttribute("cellpadding","2"); @@ -2227,49 +2172,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* return res; } -NS_IMETHODIMP -nsHTMLEditor::SaveHLineSettings(nsIDOMElement* aElement) -{ - nsresult res=NS_ERROR_NOT_INITIALIZED; - if (!aElement || !mPrefs) - return res; - - nsAutoString align, width, height, noshade; - res = NS_ERROR_UNEXPECTED; - // XXX: ERROR_HANDLING if return codes are intentionally thrown away, it should be documented here - // it looks like if any GetAttribute call failes, an error is returned - // is that the desired behavior? - if (NS_SUCCEEDED(aElement->GetAttribute("align", align)) && - NS_SUCCEEDED(aElement->GetAttribute("height", height)) && - NS_SUCCEEDED(aElement->GetAttribute("width", width)) && - NS_SUCCEEDED(aElement->GetAttribute("noshade", noshade))) - { - PRInt32 iAlign = 0; - if (align == "center") - iAlign = 1; - else if (align == "right") - iAlign = 2; - mPrefs->SetIntPref("editor.hrule.align", iAlign); - - PRInt32 errorCode; - PRInt32 iHeight = height.ToInteger(&errorCode); - - if (errorCode == NS_OK && iHeight > 0) - mPrefs->SetIntPref("editor.hrule.height", iHeight); - - PRInt32 iWidth = width.ToInteger(&errorCode); - if (errorCode == NS_OK && iWidth > 0) { - mPrefs->SetIntPref("editor.hrule.width", iWidth); - mPrefs->SetBoolPref("editor.hrule.width_percent", (width.Find("%") > 0)); - } - - mPrefs->SetBoolPref("editor.hrule.shading", (noshade == "")); - res = NS_OK; - } - - return res; -} - NS_IMETHODIMP nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { @@ -2325,28 +2227,21 @@ DELETE_ANCHOR: return res; } -// XXX: this method sets the attribute on the body element directly, -// and is not undoable. It should go through the transaction system! NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) { -// nsresult result; NS_PRECONDITION(mDocWeak, "Missing Editor DOM Document"); // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level // For initial testing, just set the background on the BODY tag (the document's background) - // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level - // For initial testing, just set the background on the BODY tag (the document's background) - // Set the background color attribute on the body tag nsCOMPtr bodyElement; nsresult res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); if (!bodyElement) res = NS_ERROR_NULL_POINTER; if (NS_SUCCEEDED(res)) { - nsAutoEditBatch beginBatching(this); - // XXX: ERROR_HANDLING should this be "res = SetAttribute..." - bodyElement->SetAttribute("bgcolor", aColor); + // Use the editor method that goes through the transaction system + res = SetAttribute(bodyElement, "bgcolor", aColor); } return res; @@ -2366,9 +2261,8 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n if (!bodyElement) res = NS_ERROR_NULL_POINTER; if (NS_SUCCEEDED(res)) { - // Use the editor's method which goes through the transaction system - // XXX: ERROR_HANDLING should this be "res = SetAttribute..." - SetAttribute(bodyElement, aAttribute, aValue); + // Use the editor method that goes through the transaction system + res = SetAttribute(bodyElement, aAttribute, aValue); } return res; } diff --git a/mozilla/editor/base/nsHTMLEditor.h b/mozilla/editor/base/nsHTMLEditor.h index 4c8db8246e9..d7ce78f2e61 100644 --- a/mozilla/editor/base/nsHTMLEditor.h +++ b/mozilla/editor/base/nsHTMLEditor.h @@ -105,7 +105,6 @@ public: NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); diff --git a/mozilla/editor/base/nsJSEditorLog.cpp b/mozilla/editor/base/nsJSEditorLog.cpp index 6344d85b9b6..424484ee590 100644 --- a/mozilla/editor/base/nsJSEditorLog.cpp +++ b/mozilla/editor/base/nsJSEditorLog.cpp @@ -699,12 +699,6 @@ nsJSEditorLog::InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection) return NS_OK; } -NS_IMETHODIMP -nsJSEditorLog::SaveHLineSettings(nsIDOMElement* aElement) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - NS_IMETHODIMP nsJSEditorLog::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { diff --git a/mozilla/editor/base/nsJSEditorLog.h b/mozilla/editor/base/nsJSEditorLog.h index 044a938b40c..d8bdf6c8031 100644 --- a/mozilla/editor/base/nsJSEditorLog.h +++ b/mozilla/editor/base/nsJSEditorLog.h @@ -124,7 +124,6 @@ public: NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD InsertElement(nsIDOMElement* aElement, PRBool aDeleteSelection); - NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); NS_IMETHOD SelectElement(nsIDOMElement* aElement); NS_IMETHOD SetCaretAfterElement(nsIDOMElement* aElement); diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index 570169fb7bd..e893575d2b9 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -1871,24 +1871,6 @@ nsEditorShell::InsertElement(nsIDOMElement *element, PRBool deleteSelection) return result; } -NS_IMETHODIMP -nsEditorShell::SaveHLineSettings(nsIDOMElement* aElement) -{ - nsresult result = NS_NOINTERFACE; - switch (mEditorType) - { - case eHTMLTextEditorType: - // this is bogus. We should save the HLine settings (or HRule, as it's more properly known) here. - result = mEditor->SaveHLineSettings(aElement); - break; - - case ePlainTextEditorType: - default: - result = NS_ERROR_NOT_IMPLEMENTED; - } - return result; -} - NS_IMETHODIMP nsEditorShell::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { diff --git a/mozilla/editor/idl/nsIEditorShell.idl b/mozilla/editor/idl/nsIEditorShell.idl index 3ba5bb5d3d1..187f2c189c8 100644 --- a/mozilla/editor/idl/nsIEditorShell.idl +++ b/mozilla/editor/idl/nsIEditorShell.idl @@ -120,7 +120,6 @@ interface nsIEditorShell : nsISupports nsIDOMElement GetElementOrParentByTagName(in wstring tagName, in nsIDOMNode node); nsIDOMElement CreateElementWithDefaults(in wstring tagName); void InsertElement(in nsIDOMElement element, in boolean deleteSelection); - void SaveHLineSettings(in nsIDOMElement element); void InsertLinkAroundSelection(in nsIDOMElement anchorElement); void SelectElement(in nsIDOMElement element); void SetSelectionAfterElement(in nsIDOMElement element); diff --git a/mozilla/editor/libeditor/base/nsEditor.cpp b/mozilla/editor/libeditor/base/nsEditor.cpp index b88c1d1eb1b..ea677112254 100644 --- a/mozilla/editor/libeditor/base/nsEditor.cpp +++ b/mozilla/editor/libeditor/base/nsEditor.cpp @@ -148,7 +148,6 @@ nsEditor::nsEditor() , mActionListeners(nsnull) , mDocDirtyState(-1) , mDocWeak(nsnull) -, mPrefs(nsnull) { //initialize member variables here NS_INIT_REFCNT(); @@ -176,11 +175,6 @@ nsEditor::~nsEditor() delete mActionListeners; mActionListeners = 0; } - - // Release service pointers - if (mPrefs) - nsServiceManager::ReleaseService(kPrefCID, mPrefs); - } @@ -278,44 +272,6 @@ nsEditor::Init(nsIDOMDocument *aDoc, nsIPresShell* aPresShell, PRUint32 aFlags) caret->SetCaretReadOnly(PR_FALSE); } - // NOTE: We don't fail if we can't get prefs or string bundles - // since we could still be used as the text edit widget without prefs - - // Get the prefs service (Note: can't use nsCOMPtr for service pointers) - nsresult ignoredResult = nsServiceManager::GetService(kPrefCID, - nsIPref::GetIID(), - (nsISupports**)&mPrefs); - if (NS_FAILED(ignoredResult) || !mPrefs) - { - if (gNoisy) { printf("ERROR: Failed to get Prefs Service instance.\n");} - } - - // TODO: Cache basic preferences? - // Register callbacks for preferences that we need to - // respond to while running - - nsIStringBundleService* service; - ignoredResult = nsServiceManager::GetService(kStringBundleServiceCID, - nsIStringBundleService::GetIID(), - (nsISupports**)&service); - - if (NS_SUCCEEDED(ignoredResult) && service) - { - nsILocale* locale = nsnull; - ignoredResult = service->CreateBundle(EDITOR_BUNDLE_URL, locale, - getter_AddRefs(mStringBundle)); - // We don't need to keep service around once we created the bundle - nsServiceManager::ReleaseService(kStringBundleServiceCID, service); - } else { - if (gNoisy) printf("ERROR: Failed to get StringBundle Service instance.\n"); - } - -/* - Example of getting a string: - nsString value; - ret = mStringBundle->GetStringFromName("editor.foo", value); -*/ - // Set the selection to the beginning: BeginningOfDocument(); diff --git a/mozilla/editor/libeditor/base/nsEditor.h b/mozilla/editor/libeditor/base/nsEditor.h index 51c7b934989..b374a3d4a7f 100644 --- a/mozilla/editor/libeditor/base/nsEditor.h +++ b/mozilla/editor/libeditor/base/nsEditor.h @@ -607,8 +607,6 @@ protected: nsWeakPtr mDocWeak; // weak reference to the nsIDOMDocument nsCOMPtr mDTD; - // Services are not nsCOMPtr friendly - nsIPref *mPrefs; static PRInt32 gInstanceCount; diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp index 600cc1e1081..af5f9b635e9 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp @@ -108,13 +108,12 @@ static PRBool gNoisy = PR_FALSE; static const PRBool gNoisy = PR_FALSE; #endif -// Some utilities to handle stupid overloading of "A" tag for link and named anchor +// Some utilities to handle annoying overloading of "A" tag for link and named anchor static char hrefText[] = "href"; -static char linkText[] = "link"; static char anchorTxt[] = "anchor"; static char namedanchorText[] = "namedanchor"; -#define IsLink(s) (s.EqualsIgnoreCase(hrefText) || s.EqualsIgnoreCase(linkText)) +#define IsLink(s) (s.EqualsIgnoreCase(hrefText)) #define IsNamedAnchor(s) (s.EqualsIgnoreCase(anchorTxt) || s.EqualsIgnoreCase(namedanchorText)) static PRBool IsLinkNode(nsIDOMNode *aNode) @@ -1277,7 +1276,7 @@ nsHTMLEditor::SetCaretAfterElement(nsIDOMElement* aElement) { // Collapse selection to just after desired element, res = selection->Collapse(parent, offsetInParent+1); -#ifdef DEBUG_cmanske +#if 0 //def DEBUG_cmanske { nsAutoString name; parent->GetNodeName(name); @@ -2127,64 +2126,10 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* // Set default values for new elements if (TagName.Equals("hr")) { - // Hard coded defaults in case there's no prefs - nsAutoString align("center"); - nsAutoString width("100%"); - nsAutoString height("2"); - PRBool bNoShade = PR_FALSE; - - if (mPrefs) - { - char buf[16]; - PRInt32 iAlign; - // Currently using 0=left, 1=center, and 2=right - // XXX: ERROR_HANDLING if these results are intentionally thrown away, it should be documented here - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.align", &iAlign))) - { - switch (iAlign) { - case 0: - align = "left"; - break; - case 2: - align = "right"; - break; - } - } - PRInt32 iHeight; - PRUint32 count; - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.height", &iHeight))) - { - count = PR_snprintf(buf, 16, "%d", iHeight); - if (count > 0) - { - height = buf; - } - } - PRInt32 iWidth; - PRBool bPercent; - if( NS_SUCCEEDED(mPrefs->GetIntPref("editor.hrule.width", &iWidth)) && - NS_SUCCEEDED(mPrefs->GetBoolPref("editor.hrule.width_percent", &bPercent))) - { - count = PR_snprintf(buf, 16, "%d", iWidth); - if (count > 0) - { - width = buf; - if (bPercent) - width.Append("%"); - } - } - PRBool bShading; - if (NS_SUCCEEDED(mPrefs->GetBoolPref("editor.hrule.shading", &bShading))) - { - bNoShade = !bShading; - } - } - newElement->SetAttribute("align", align); - newElement->SetAttribute("height", height); - newElement->SetAttribute("width", width); - if (bNoShade) - newElement->SetAttribute("noshade", ""); - + // Note that we read the user's attributes for these from prefs (in InsertHLine JS) + newElement->SetAttribute("align","center"); + newElement->SetAttribute("width","100%"); + newElement->SetAttribute("height","2"); } else if (TagName.Equals("table")) { newElement->SetAttribute("cellpadding","2"); @@ -2227,49 +2172,6 @@ nsHTMLEditor::CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement* return res; } -NS_IMETHODIMP -nsHTMLEditor::SaveHLineSettings(nsIDOMElement* aElement) -{ - nsresult res=NS_ERROR_NOT_INITIALIZED; - if (!aElement || !mPrefs) - return res; - - nsAutoString align, width, height, noshade; - res = NS_ERROR_UNEXPECTED; - // XXX: ERROR_HANDLING if return codes are intentionally thrown away, it should be documented here - // it looks like if any GetAttribute call failes, an error is returned - // is that the desired behavior? - if (NS_SUCCEEDED(aElement->GetAttribute("align", align)) && - NS_SUCCEEDED(aElement->GetAttribute("height", height)) && - NS_SUCCEEDED(aElement->GetAttribute("width", width)) && - NS_SUCCEEDED(aElement->GetAttribute("noshade", noshade))) - { - PRInt32 iAlign = 0; - if (align == "center") - iAlign = 1; - else if (align == "right") - iAlign = 2; - mPrefs->SetIntPref("editor.hrule.align", iAlign); - - PRInt32 errorCode; - PRInt32 iHeight = height.ToInteger(&errorCode); - - if (errorCode == NS_OK && iHeight > 0) - mPrefs->SetIntPref("editor.hrule.height", iHeight); - - PRInt32 iWidth = width.ToInteger(&errorCode); - if (errorCode == NS_OK && iWidth > 0) { - mPrefs->SetIntPref("editor.hrule.width", iWidth); - mPrefs->SetBoolPref("editor.hrule.width_percent", (width.Find("%") > 0)); - } - - mPrefs->SetBoolPref("editor.hrule.shading", (noshade == "")); - res = NS_OK; - } - - return res; -} - NS_IMETHODIMP nsHTMLEditor::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement) { @@ -2325,28 +2227,21 @@ DELETE_ANCHOR: return res; } -// XXX: this method sets the attribute on the body element directly, -// and is not undoable. It should go through the transaction system! NS_IMETHODIMP nsHTMLEditor::SetBackgroundColor(const nsString& aColor) { -// nsresult result; NS_PRECONDITION(mDocWeak, "Missing Editor DOM Document"); // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level // For initial testing, just set the background on the BODY tag (the document's background) - // TODO: Check selection for Cell, Row, Column or table and do color on appropriate level - // For initial testing, just set the background on the BODY tag (the document's background) - // Set the background color attribute on the body tag nsCOMPtr bodyElement; nsresult res = nsEditor::GetBodyElement(getter_AddRefs(bodyElement)); if (!bodyElement) res = NS_ERROR_NULL_POINTER; if (NS_SUCCEEDED(res)) { - nsAutoEditBatch beginBatching(this); - // XXX: ERROR_HANDLING should this be "res = SetAttribute..." - bodyElement->SetAttribute("bgcolor", aColor); + // Use the editor method that goes through the transaction system + res = SetAttribute(bodyElement, "bgcolor", aColor); } return res; @@ -2366,9 +2261,8 @@ NS_IMETHODIMP nsHTMLEditor::SetBodyAttribute(const nsString& aAttribute, const n if (!bodyElement) res = NS_ERROR_NULL_POINTER; if (NS_SUCCEEDED(res)) { - // Use the editor's method which goes through the transaction system - // XXX: ERROR_HANDLING should this be "res = SetAttribute..." - SetAttribute(bodyElement, aAttribute, aValue); + // Use the editor method that goes through the transaction system + res = SetAttribute(bodyElement, aAttribute, aValue); } return res; } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.h b/mozilla/editor/libeditor/html/nsHTMLEditor.h index 4c8db8246e9..d7ce78f2e61 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditor.h +++ b/mozilla/editor/libeditor/html/nsHTMLEditor.h @@ -105,7 +105,6 @@ public: NS_IMETHOD GetSelectedElement(const nsString& aTagName, nsIDOMElement** aReturn); NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn); - NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement); NS_IMETHOD InsertLinkAroundSelection(nsIDOMElement* aAnchorElement); diff --git a/mozilla/editor/provisional/nsIHighLevelHTMLEditor.h b/mozilla/editor/provisional/nsIHighLevelHTMLEditor.h index 08d5ad1ffdb..cd4a71b6ec1 100644 --- a/mozilla/editor/provisional/nsIHighLevelHTMLEditor.h +++ b/mozilla/editor/provisional/nsIHighLevelHTMLEditor.h @@ -277,15 +277,6 @@ public: */ NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn)=0; - /** Save the attributes of a Horizontal Rule in user preferences - * These prefs are used when the user inserts a new Horizontal line - * - * XXX this functionality should move to the editorShell. - * - * @param aElement An HR element - */ - NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement)=0; - /** Insert an link element as the parent of the current selection * be useful for other elements. * diff --git a/mozilla/editor/public/nsIHTMLEditor.h b/mozilla/editor/public/nsIHTMLEditor.h index 0b4c13b2e2b..03f626f63da 100644 --- a/mozilla/editor/public/nsIHTMLEditor.h +++ b/mozilla/editor/public/nsIHTMLEditor.h @@ -306,15 +306,6 @@ public: */ NS_IMETHOD CreateElementWithDefaults(const nsString& aTagName, nsIDOMElement** aReturn)=0; - /** Save the attributes of a Horizontal Rule in user preferences - * These prefs are used when the user inserts a new Horizontal line - * - * XXX this functionality should move to the editorShell. - * - * @param aElement An HR element - */ - NS_IMETHOD SaveHLineSettings(nsIDOMElement* aElement)=0; - /** Insert an link element as the parent of the current selection * be useful for other elements. * diff --git a/mozilla/editor/ui/composer/content/EditorCommands.js b/mozilla/editor/ui/composer/content/EditorCommands.js index 704b867b9e0..b38dd2190c2 100644 --- a/mozilla/editor/ui/composer/content/EditorCommands.js +++ b/mozilla/editor/ui/composer/content/EditorCommands.js @@ -21,6 +21,7 @@ var toolbar; var documentModified; var EditorDisplayStyle = true; +var prefs = null; var gTagToFormat = { "P" : "Normal", // these should really be entities. Not sure how to do that from JS @@ -552,7 +553,59 @@ function EditorInsertHLine() window.openDialog("chrome://editor/content/EdHLineProps.xul", "HLineDlg", "chrome,close,titlebar,modal"); } else { hLine = editorShell.CreateElementWithDefaults(tagName); + if (hLine) { + // We change the default attributes to those saved in the user prefs + var prefs = Components.classes['component://netscape/preferences']; + if (prefs) { + prefs = prefs.getService(); + } + if (prefs) { + prefs = prefs.QueryInterface(Components.interfaces.nsIPref); + } + if (prefs) { + dump(" We found the Prefs Service\n"); + var percent; + var height; + var shading; + var ud = "undefined"; + + try { + var align = prefs.GetIntPref("editor.hrule.align"); + dump("Align pref: "+align+"\n"); + if (align == 0 ) { + hLine.setAttribute("align", "left"); + } else if (align == 2) { + hLine.setAttribute("align", "right"); + } else { + // Default is center + hLine.setAttribute("align", "center"); + } + + var width = prefs.GetIntPref("editor.hrule.width"); + var percent = prefs.GetBoolPref("editor.hrule.width_percent"); + dump("Width pref: "+width+", percent:"+percent+"\n"); + if (percent) + width = width +"%"; + + hLine.setAttribute("width", width); + + var height = prefs.GetIntPref("editor.hrule.height"); + dump("Size pref: "+height+"\n"); + hLine.setAttribute("size", String(height)); + + var shading = prefs.GetBoolPref("editor.hrule.shading"); + dump("Shading pref:"+shading+"\n"); + if (shading) { + hLine.removeAttribute("noshade"); + } else { + hLine.setAttribute("noshade", ""); + } + } + catch (ex) { + dump("failed to get HLine prefs\n"); + } + } editorShell.InsertElement(hLine, false); } } diff --git a/mozilla/editor/ui/dialogs/content/EdHLineProps.js b/mozilla/editor/ui/dialogs/content/EdHLineProps.js index e550ab5e733..2cd910493b7 100644 --- a/mozilla/editor/ui/dialogs/content/EdHLineProps.js +++ b/mozilla/editor/ui/dialogs/content/EdHLineProps.js @@ -25,7 +25,10 @@ var tagName = "hr"; var hLineElement; var tempLineElement; var percentChar = ""; -var shading = true; +var width; +var height; +var align; +var shading; // dialog initialization code function Startup() @@ -92,8 +95,47 @@ function onSaveDefault() // "false" means set attributes on the tempLineElement, // not the real element being edited if (ValidateData(false)) { - editorShell.SaveHLineSettings(tempLineElement); - dump("Saving HLine settings to preferences\n"); + var prefs = Components.classes['component://netscape/preferences']; + if (prefs) { + prefs = prefs.getService(); + } + if (prefs) { + prefs = prefs.QueryInterface(Components.interfaces.nsIPref); + } + if (prefs) { + dump("Setting HLine prefs\n"); + + var alignInt; + if (align == "left") { + alignInt = 0; + } else if (align == "right") { + alignInt = 2; + } else { + alignInt = 1; + } + prefs.SetIntPref("editor.hrule.align", alignInt); + + var percentIndex = width.search(/%/); + var percent; + var widthInt; + if (percentIndex > 0) { + percent = true; + widthInt = Number(width.substr(0, percentIndex)); + } else { + percent = false; + widthInt = Number(width); + } + prefs.SetIntPref("editor.hrule.width", widthInt); + prefs.SetBoolPref("editor.hrule.width_percent", percent); + + // Convert string to number + prefs.SetIntPref("editor.hrule.height", Number(height)); + + prefs.SetBoolPref("editor.hrule.shading", shading); + + // Write the prefs out NOW! + prefs.SavePrefFile(); + } } } @@ -142,7 +184,6 @@ function ValidateData(setAttributes) tempLineElement.setAttribute("width", width); } - align = "left"; if (dialog.centerAlign.checked) { align = "center"; @@ -156,12 +197,14 @@ function ValidateData(setAttributes) } if (dialog.shading.checked) { + shading = true; if (setAttributes) { hLineElement.removeAttribute("noshade"); } else { tempLineElement.removeAttribute("noshade"); } } else { + shading = false; if (setAttributes) { hLineElement.setAttribute("noshade", ""); } else {