inline styles were not saved because gElement was outside of document's tree; b=91548, r=brade, sr=kin

git-svn-id: svn://10.0.0.236/trunk@113041 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
glazman%netscape.com
2002-01-28 16:00:12 +00:00
parent 1f1c0c3523
commit d5dadcf26c
4 changed files with 77 additions and 28 deletions

View File

@@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Daniel Glazman <glazman@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
@@ -451,5 +452,6 @@ interface nsIHTMLEditor : nsISupports
*/
void IsCSSEnabled(out boolean aIsCSSEnabled);
nsIDOMCSSStyleRule ParseStyleAttrIntoCSSRule(in wstring aString);
};

View File

@@ -52,6 +52,8 @@
#include "nsHTMLURIRefObject.h"
#include "nsICSSParser.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMText.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMDocument.h"
@@ -142,6 +144,7 @@ static NS_DEFINE_CID(kCDOMSelectionCID, NS_DOMSELECTION_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kParserServiceCID, NS_PARSERSERVICE_CID);
static NS_DEFINE_CID(kCTransitionalDTDCID, NS_CTRANSITIONAL_DTD_CID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
#if defined(NS_DEBUG) && defined(DEBUG_buster)
static PRBool gNoisy = PR_FALSE;
@@ -5319,3 +5322,34 @@ nsHTMLEditor::NodesSameType(nsIDOMNode *aNode1, nsIDOMNode *aNode2)
return PR_FALSE;
}
NS_IMETHODIMP
nsHTMLEditor::ParseStyleAttrIntoCSSRule(const PRUnichar *aString, nsIDOMCSSStyleRule **_retval)
{
nsCOMPtr<nsIDOMDocument> domdoc;
nsEditor::GetDocument(getter_AddRefs(domdoc));
if (!domdoc)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIDocument> doc (do_QueryInterface(domdoc));
if (!doc)
return NS_ERROR_UNEXPECTED;
nsCOMPtr <nsIURI> docURL;
doc->GetBaseURL(*getter_AddRefs(docURL));
nsCOMPtr<nsICSSParser> css;
nsCOMPtr<nsIStyleRule> mRule;
nsComponentManager::CreateInstance(kCSSParserCID,
nsnull,
NS_GET_IID(nsICSSParser),
getter_AddRefs(css));
NS_ASSERTION(css, "can't get a css parser");
if (!css) return NS_ERROR_NULL_POINTER;
nsAutoString value(aString);
css->ParseStyleAttribute(value, docURL, getter_AddRefs(mRule));
nsCOMPtr<nsIDOMCSSStyleRule> styleRule = do_QueryInterface(mRule);
if (styleRule) {
*_retval = styleRule;
NS_ADDREF(*_retval);
}
return NS_OK;
}

View File

@@ -119,6 +119,8 @@ public:
/* ------------ nsIHTMLEditor methods -------------- */
NS_IMETHOD ParseStyleAttrIntoCSSRule(const PRUnichar *aString, nsIDOMCSSStyleRule **_retval);
NS_IMETHOD SetCSSInlineProperty(nsIAtom *aProperty,
const nsAReadableString & aAttribute,
const nsAReadableString & aValue);
@@ -754,6 +756,5 @@ friend class nsTextEditRules;
friend class nsWSRunObject;
};
#endif //nsHTMLEditor_h__

View File

@@ -19,41 +19,53 @@
*
* Contributor(s):
* Ben "Count XULula" Goodger
* Daniel Glazman <glazman@netscape.com>
*/
// build attribute list in tree form from element attributes
function BuildCSSAttributeTable()
{
// get the CSS declaration from DOM 2 ElementCSSInlineStyle
var style = gElement.style;
if (style == undefined)
{
dump("Inline styles undefined\n");
return;
}
var l = style.length;
if (l == undefined || l == 0)
{
if (l == undefined) {
dump("Failed to query the number of inline style declarations\n");
}
return;
}
if (l > 0)
{
var added = false;
for (i = 0; i < l; i++)
// we can't trust DOM 2 ElementCSSInlineStyle because gElement can be
// outside of the document's tree
var styleAttr = gElement.getAttribute("style");
// we need the
var editorShell = window.opener.editorShell;
if (editorShell) {
editorShell = editorShell.QueryInterface(Components.interfaces.nsIEditorShell);
var editor = editorShell.editor.QueryInterface(Components.interfaces.nsIHTMLEditor);
var styleRule = editor.ParseStyleAttrIntoCSSRule(styleAttr);
if (styleRule == undefined)
{
name = style.item(i);
value = style.getPropertyValue(name);
AddTreeItem( name, value, "CSSAList", CSSAttrs );
dump("Inline styles undefined\n");
return;
}
}
ClearCSSInputWidgets();
var style = styleRule.style;
var declLength = style.length;
if (declLength == undefined || declLength == 0)
{
if (declLength == undefined) {
dump("Failed to query the number of inline style declarations\n");
}
return;
}
if (declLength > 0)
{
var added = false;
for (i = 0; i < declLength; i++)
{
name = style.item(i);
value = style.getPropertyValue(name);
AddTreeItem( name, value, "CSSAList", CSSAttrs );
}
}
ClearCSSInputWidgets();
}
}
function onChangeCSSAttribute()