Implement element.style for XUL elements. Fully fault XUL attributes when style attribute is modified, and ensure that string and style rule versions of style attribute stay in sync. (HTML elements only store the latter.) b=7639 r+sr=bzbarsky

This commit is contained in:
dbaron%dbaron.org 2003-10-30 01:40:33 +00:00
parent 01d5d607e0
commit ec0bfea4ea
29 changed files with 237 additions and 125 deletions

View File

@ -42,7 +42,7 @@
#include "nsChangeHint.h"
class nsString;
class nsIStyleRule;
class nsICSSStyleRule;
class nsISupportsArray;
class nsRuleWalker;
@ -65,7 +65,9 @@ public:
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const = 0;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0;
NS_IMETHOD GetInlineStyleRule(nsIStyleRule** aStyleRule) = 0;
NS_IMETHOD GetInlineStyleRule(nsICSSStyleRule** aStyleRule) = 0;
NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify) = 0;
/**
* Does the list of style rules walked by |WalkContentStyleRules|

View File

@ -2111,12 +2111,20 @@ nsGenericElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
}
NS_IMETHODIMP
nsGenericElement::GetInlineStyleRule(nsIStyleRule** aStyleRule)
nsGenericElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
{
*aStyleRule = nsnull;
return NS_OK;
}
NS_IMETHODIMP
nsGenericElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule,
PRBool aNotify)
{
NS_NOTYETIMPLEMENTED("nsGenericElement::SetInlineStyleRule");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP_(PRBool)
nsGenericElement::HasAttributeDependentStyle(const nsIAtom* aAttribute) const
{

View File

@ -400,7 +400,8 @@ public:
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
NS_IMETHOD GetInlineStyleRule(nsIStyleRule** aStyleRule);
NS_IMETHOD GetInlineStyleRule(nsICSSStyleRule** aStyleRule);
NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
NS_IMETHOD_(PRBool)
HasAttributeDependentStyle(const nsIAtom* aAttribute) const;
NS_IMETHOD GetAttributeChangeHint(const nsIAtom* aAttribute,

View File

@ -2294,7 +2294,7 @@ nsGenericHTMLElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
}
nsresult
nsGenericHTMLElement::GetInlineStyleRule(nsIStyleRule** aStyleRule)
nsGenericHTMLElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
{
*aStyleRule = nsnull;
@ -2317,6 +2317,14 @@ nsGenericHTMLElement::GetInlineStyleRule(nsIStyleRule** aStyleRule)
return NS_OK;
}
nsresult
nsGenericHTMLElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule,
PRBool aNotify)
{
return SetHTMLAttribute(nsHTMLAtoms::style, nsHTMLValue(aStyleRule),
aNotify);
}
nsresult
nsGenericHTMLElement::GetBaseURL(nsIURI** aBaseURL) const
{
@ -3120,7 +3128,7 @@ nsGenericHTMLElement::ParseStyleAttribute(const nsAString& aValue, nsHTMLValue&
nsCOMPtr<nsIURI> baseURL;
GetBaseURL(getter_AddRefs(baseURL));
nsCOMPtr<nsIStyleRule> rule;
nsCOMPtr<nsICSSStyleRule> rule;
result = cssParser->ParseStyleAttribute(aValue, baseURL,
getter_AddRefs(rule));
if (cssLoader) {

View File

@ -227,7 +227,8 @@ public:
NS_IMETHOD_(nsIAtom*) GetClassAttributeName() const;
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
NS_IMETHOD GetInlineStyleRule(nsIStyleRule** aStyleRule);
NS_IMETHOD GetInlineStyleRule(nsICSSStyleRule** aStyleRule);
NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
NS_IMETHOD GetBaseURL(nsIURI** aBaseURL) const;
NS_IMETHOD GetBaseTarget(nsAString& aBaseTarget) const;

View File

@ -41,7 +41,7 @@
#include "nsISupports.h"
#include "nsAString.h"
class nsIStyleRule;
class nsICSSStyleRule;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURI;
@ -84,7 +84,7 @@ public:
// the declaration.
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult) = 0;
nsICSSStyleRule** aResult) = 0;
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aBaseURL,

View File

@ -51,7 +51,7 @@ nsCSSOMFactory::~nsCSSOMFactory()
NS_IMPL_ISUPPORTS1(nsCSSOMFactory, nsICSSOMFactory)
NS_IMETHODIMP
nsCSSOMFactory::CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
nsCSSOMFactory::CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult)
{
nsDOMCSSDeclaration *result = new nsDOMCSSAttributeDeclaration(aContent);

View File

@ -51,7 +51,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult);
};

View File

@ -111,9 +111,9 @@ public:
nsIURI* aInputURL,
nsICSSStyleSheet*& aResult);
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult);
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsICSSStyleRule** aResult);
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aBaseURL,
@ -596,7 +596,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
NS_IMETHODIMP
CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult)
nsICSSStyleRule** aResult)
{
NS_ASSERTION(nsnull != aBaseURL, "need base URL");

View File

@ -40,7 +40,7 @@
#include "nsCSSDeclaration.h"
#include "nsIDocument.h"
#include "nsHTMLAtoms.h"
#include "nsIHTMLContent.h"
#include "nsIStyledContent.h"
#include "nsIDOMMutationEvent.h"
#include "nsHTMLValue.h"
#include "nsICSSStyleRule.h"
@ -54,7 +54,7 @@
MOZ_DECL_CTOR_COUNTER(nsDOMCSSAttributeDeclaration)
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent)
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIStyledContent *aContent)
{
MOZ_COUNT_CTOR(nsDOMCSSAttributeDeclaration);
@ -81,25 +81,16 @@ nsresult
nsDOMCSSAttributeDeclaration::DeclarationChanged()
{
NS_ASSERTION(mContent, "Must have content node to set the decl!");
nsHTMLValue val;
#ifdef DEBUG
nsresult rv =
#endif
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
NS_ASSERTION(rv == NS_CONTENT_ATTR_HAS_VALUE &&
eHTMLUnit_ISupports == val.GetUnit(),
"content must have rule");
nsCOMPtr<nsICSSStyleRule> oldRule =
do_QueryInterface(nsCOMPtr<nsISupports>(val.GetISupportsValue()));
nsCOMPtr<nsICSSStyleRule> oldRule;
mContent->GetInlineStyleRule(getter_AddRefs(oldRule));
NS_ASSERTION(oldRule, "content must have rule");
nsCOMPtr<nsICSSStyleRule> newRule = oldRule->DeclarationChanged(PR_FALSE);
if (!newRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
return mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(newRule),
PR_TRUE);
return mContent->SetInlineStyleRule(newRule, PR_TRUE);
}
nsresult
@ -110,15 +101,10 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
*aDecl = nsnull;
if (mContent) {
nsHTMLValue val;
result = mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (result == NS_CONTENT_ATTR_HAS_VALUE &&
eHTMLUnit_ISupports == val.GetUnit()) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
}
nsCOMPtr<nsICSSStyleRule> cssRule;
mContent->GetInlineStyleRule(getter_AddRefs(cssRule));
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
}
else if (aAllocate) {
nsCSSDeclaration *decl = new nsCSSDeclaration();
@ -136,9 +122,7 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
return result;
}
result = mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(cssRule),
PR_FALSE);
result = mContent->SetInlineStyleRule(cssRule, PR_FALSE);
if (NS_SUCCEEDED(result)) {
*aDecl = decl;
}

View File

@ -45,14 +45,14 @@
#include "nsString.h"
class nsIContent;
class nsIHTMLContent;
class nsIStyledContent;
class nsICSSLoader;
class nsICSSParser;
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
{
public:
nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent);
nsDOMCSSAttributeDeclaration(nsIStyledContent *aContent);
~nsDOMCSSAttributeDeclaration();
// impl AddRef/Release; QI is implemented by our parent class
@ -75,7 +75,7 @@ protected:
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
nsIHTMLContent *mContent;
nsIStyledContent *mContent;
};
#endif /* nsDOMCSSAttributeDeclaration_h___ */

View File

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMCSSDeclaration_h___
#define nsDOMCSSSDeclaration_h___
#define nsDOMCSSDeclaration_h___
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSS2Properties.h"

View File

@ -452,7 +452,7 @@ HTMLCSSStyleSheetImpl::RulesMatching(ElementRuleProcessorData* aData,
if (styledContent) {
// just get the one and only style rule from the content's STYLE attribute
nsCOMPtr<nsIStyleRule> rule;
nsCOMPtr<nsICSSStyleRule> rule;
styledContent->GetInlineStyleRule(getter_AddRefs(rule));
if (rule)
aData->mRuleWalker->Forward(rule);

View File

@ -42,7 +42,7 @@
#include "nsISupports.h"
class nsDOMCSSDeclaration;
class nsIHTMLContent;
class nsIStyledContent;
// bfdd87bd-79c8-4041-ae14-91fa8536ce61
#define NS_ICSSOMFACTORY_IID \
@ -58,7 +58,7 @@ class nsICSSOMFactory : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSSOMFACTORY_IID)
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult) = 0;
};

View File

@ -39,7 +39,7 @@
#include "nsSVGValue.h"
#include "nsISVGStyleValue.h"
#include "nsSVGStyleValue.h"
#include "nsIStyleRule.h"
#include "nsICSSStyleRule.h"
#include "nsIContent.h"
#include "nsIURI.h"
#include "nsICSSParser.h"
@ -72,7 +72,7 @@ protected:
void UpdateStyleRule(nsIContent* aContent);
nsString mValue;
nsCOMPtr<nsIStyleRule> mRule; // lazily cached
nsCOMPtr<nsICSSStyleRule> mRule; // lazily cached
};
//----------------------------------------------------------------------

View File

@ -69,5 +69,6 @@ LOCAL_INCLUDES = \
-I$(srcdir)/../../../xml/content/src \
-I$(srcdir)/../../../base/src \
-I$(srcdir)/../../../xml/document/src \
-I$(srcdir)/../../../html/style/src \
$(NULL)

View File

@ -60,6 +60,7 @@
#include "nsIContent.h"
#include "nsINodeInfo.h"
#include "nsICSSParser.h"
#include "nsICSSStyleRule.h"
#include "nsIDOMElement.h"
#include "nsINameSpaceManager.h"
#include "nsIServiceManager.h"
@ -729,7 +730,7 @@ nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsAString& aVal
return result;
}
nsCOMPtr<nsIStyleRule> rule;
nsCOMPtr<nsICSSStyleRule> rule;
result = css->ParseStyleAttribute(aValue, aDocURL, getter_AddRefs(rule));
if ((NS_OK == result) && rule) {
@ -740,13 +741,13 @@ nsresult nsXULAttributes::UpdateStyleRule(nsIURI* aDocURL, const nsAString& aVal
}
nsresult nsXULAttributes::SetInlineStyleRule(nsIStyleRule* aRule)
nsresult nsXULAttributes::SetInlineStyleRule(nsICSSStyleRule* aRule)
{
mStyleRule = aRule;
return NS_OK;
}
nsresult nsXULAttributes::GetInlineStyleRule(nsIStyleRule*& aRule)
nsresult nsXULAttributes::GetInlineStyleRule(nsICSSStyleRule*& aRule)
{
nsresult result = NS_ERROR_NULL_POINTER;
if (mStyleRule != nsnull)

View File

@ -53,6 +53,8 @@
#include "nsIAtom.h"
#include "nsVoidArray.h"
#include "nsXULAttributeValue.h"
#include "nsDOMCSSDeclaration.h"
#include "nsAutoPtr.h"
class nsIURI;
class nsINodeInfo;
@ -186,8 +188,11 @@ public:
nsresult UpdateClassList(const nsAString& aValue);
nsresult UpdateStyleRule(nsIURI* aDocURL, const nsAString& aValue);
nsresult SetInlineStyleRule(nsIStyleRule* aRule);
nsresult GetInlineStyleRule(nsIStyleRule*& aRule);
nsresult SetInlineStyleRule(nsICSSStyleRule* aRule);
nsresult GetInlineStyleRule(nsICSSStyleRule*& aRule);
void SetDOMStyle(nsDOMCSSDeclaration *aDOMDecl) { mDOMStyle = aDOMDecl; }
nsDOMCSSDeclaration* GetDOMStyle() { return mDOMStyle; }
protected:
nsXULAttributes(nsIContent* aContent);
@ -195,7 +200,8 @@ protected:
nsIContent* mContent;
nsClassList* mClassList;
nsCOMPtr<nsIStyleRule> mStyleRule;
nsCOMPtr<nsICSSStyleRule> mStyleRule;
nsRefPtr<nsDOMCSSDeclaration> mDOMStyle;
nsAutoVoidArray mAttributes;
private:
// Hide so that all construction and destruction use Create and Destroy.

View File

@ -98,7 +98,7 @@
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIServiceManager.h"
#include "nsIStyleRule.h"
#include "nsICSSStyleRule.h"
#include "nsIStyleSheet.h"
#include "nsIStyledContent.h"
#include "nsISupportsArray.h"
@ -125,6 +125,7 @@
#include "nsRuleWalker.h"
#include "nsIDOMViewCSS.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsCSSDeclaration.h"
#include "nsXULAtoms.h"
#include "nsIListBoxObject.h"
#include "nsContentUtils.h"
@ -155,6 +156,8 @@ class nsIDocShell;
nsICSSParser* nsXULPrototypeElement::sCSSParser = nsnull;
nsIXULPrototypeCache* nsXULPrototypeScript::sXULPrototypeCache = nsnull;
nsIXBLService * nsXULElement::gXBLService = nsnull;
nsICSSOMFactory* nsXULElement::gCSSOMFactory = nsnull;
//----------------------------------------------------------------------
@ -162,6 +165,7 @@ static NS_DEFINE_CID(kEventListenerManagerCID, NS_EVENTLISTENERMANAGER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
static NS_DEFINE_CID(kCSSOMFactoryCID, NS_CSSOMFACTORY_CID);
//----------------------------------------------------------------------
@ -2299,6 +2303,8 @@ nsXULElement::UnregisterAccessKey(const nsAString& aOldValue)
// XXX attribute code swiped from nsGenericContainerElement
// this class could probably just use nsGenericContainerElement
// needed to maintain attribute namespace ID as well as ordering
// NOTE: Changes to this function may need to be made in
// |SetInlineStyleRule| as well.
NS_IMETHODIMP
nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
const nsAString& aValue,
@ -2366,7 +2372,10 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
// to unhook the old one.
// Save whether this is a modification before we muck with the attr pointer.
PRBool modification = attr || protoattr;
PRInt32 modHint = (attr || protoattr)
? PRInt32(nsIDOMMutationEvent::MODIFICATION)
: PRInt32(nsIDOMMutationEvent::ADDITION);
if (attr) {
attr->SetValueInternal(aValue);
@ -2391,12 +2400,22 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
if (aNodeInfo->Equals(nsXULAtoms::accesskey, kNameSpaceID_None))
UnregisterAccessKey(oldValue);
FinishSetAttr(attrns, attrName, oldValue, aValue, modHint, aNotify);
return NS_OK;
}
void
nsXULElement::FinishSetAttr(PRInt32 aAttrNS, nsIAtom* aAttrName,
const nsAString& aOldValue, const nsAString& aValue,
PRInt32 aModHint, PRBool aNotify)
{
if (mDocument) {
nsCOMPtr<nsIXBLBinding> binding;
mDocument->GetBindingManager()->GetBinding(NS_STATIC_CAST(nsIStyledContent*, this), getter_AddRefs(binding));
if (binding)
binding->AttributeChanged(attrName, attrns, PR_FALSE, aNotify);
binding->AttributeChanged(aAttrName, aAttrNS, PR_FALSE, aNotify);
if (HasMutationListeners(NS_STATIC_CAST(nsIStyledContent*, this), NS_EVENT_BITS_MUTATION_ATTRMODIFIED)) {
nsCOMPtr<nsIDOMEventTarget> node(do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)));
@ -2406,34 +2425,25 @@ nsXULElement::SetAttr(nsINodeInfo* aNodeInfo,
mutation.mTarget = node;
nsAutoString attrName2;
attrName->ToString(attrName2);
aAttrName->ToString(attrName2);
nsCOMPtr<nsIDOMAttr> attrNode;
GetAttributeNode(attrName2, getter_AddRefs(attrNode));
mutation.mRelatedNode = attrNode;
mutation.mAttrName = attrName;
if (!oldValue.IsEmpty())
mutation.mPrevAttrValue = do_GetAtom(oldValue);
mutation.mAttrName = aAttrName;
if (!aOldValue.IsEmpty())
mutation.mPrevAttrValue = do_GetAtom(aOldValue);
if (!aValue.IsEmpty())
mutation.mNewAttrValue = do_GetAtom(aValue);
if (modification)
mutation.mAttrChange = nsIDOMMutationEvent::MODIFICATION;
else
mutation.mAttrChange = nsIDOMMutationEvent::ADDITION;
mutation.mAttrChange = aModHint;
nsEventStatus status = nsEventStatus_eIgnore;
HandleDOMEvent(nsnull, &mutation, nsnull, NS_EVENT_FLAG_INIT, &status);
}
if (aNotify) {
PRInt32 modHint = modification
? PRInt32(nsIDOMMutationEvent::MODIFICATION)
: PRInt32(nsIDOMMutationEvent::ADDITION);
mDocument->AttributeChanged(this, attrns, attrName, modHint);
mDocument->AttributeChanged(this, aAttrNS, aAttrName, aModHint);
}
}
return NS_OK;
}
NS_IMETHODIMP
@ -3516,7 +3526,7 @@ nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
}
NS_IMETHODIMP
nsXULElement::GetInlineStyleRule(nsIStyleRule** aStyleRule)
nsXULElement::GetInlineStyleRule(nsICSSStyleRule** aStyleRule)
{
// Fetch the cached style rule from the attributes.
nsresult result = NS_OK;
@ -3533,6 +3543,73 @@ nsXULElement::GetInlineStyleRule(nsIStyleRule** aStyleRule)
return result;
}
NS_IMETHODIMP
nsXULElement::SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify)
{
// Fault everything, for the same reason as |GetAttributes|, and
// force the creation of the attributes struct.
nsCOMPtr<nsIDOMNamedNodeMap> domattrs;
nsresult rv = GetAttributes(getter_AddRefs(domattrs));
if (NS_FAILED(rv)) return rv;
aNotify = aNotify && mDocument;
// This function does roughly the same things that |SetAttr| does.
mozAutoDocUpdate updateBatch(mDocument, UPDATE_CONTENT_MODEL, aNotify);
if (aNotify) {
mDocument->AttributeWillChange(this, kNameSpaceID_None,
nsXULAtoms::style);
}
PRInt32 modHint;
nsCOMPtr<nsICSSStyleRule> oldRule;
nsAutoString oldValue;
GetInlineStyleRule(getter_AddRefs(oldRule));
if (oldRule) {
modHint = PRInt32(nsIDOMMutationEvent::MODIFICATION);
oldRule->GetDeclaration()->ToString(oldValue);
} else {
modHint = PRInt32(nsIDOMMutationEvent::ADDITION);
}
rv = Attributes()->SetInlineStyleRule(aStyleRule);
nsAutoString stringValue;
aStyleRule->GetDeclaration()->ToString(stringValue);
// Fix the copy stored as a string too.
nsXULAttribute* attr = FindLocalAttribute(kNameSpaceID_None,
nsXULAtoms::style);
if (attr) {
attr->SetValueInternal(stringValue);
}
else {
nsCOMPtr<nsINodeInfoManager> nimgr;
NodeInfo()->GetNodeInfoManager(getter_AddRefs(nimgr));
NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE);
nsCOMPtr<nsINodeInfo> ni;
rv = nimgr->GetNodeInfo(nsXULAtoms::style, nsnull, kNameSpaceID_None,
getter_AddRefs(ni));
NS_ENSURE_SUCCESS(rv, rv);
// Need to create a local attr
rv = nsXULAttribute::Create(NS_STATIC_CAST(nsIStyledContent*, this),
ni, stringValue, &attr);
if (NS_FAILED(rv)) return rv;
// transfer ownership here...
nsXULAttributes *attrs = mSlots->GetAttributes();
attrs->AppendElement(attr);
}
FinishSetAttr(kNameSpaceID_None, nsXULAtoms::style,
oldValue, stringValue, modHint, aNotify);
return rv;
}
NS_IMETHODIMP
nsXULElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
PRInt32 aModType,
@ -4056,8 +4133,33 @@ nsXULElement::SetStatusText(const nsAString& aAttr)
nsresult
nsXULElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
// Fault everything, for the same reason as |GetAttributes|, and
// force the creation of the attributes struct.
nsCOMPtr<nsIDOMNamedNodeMap> domattrs;
nsresult rv = GetAttributes(getter_AddRefs(domattrs));
if (NS_FAILED(rv)) return rv;
nsXULAttributes *attrs = Attributes();
if (!attrs->GetDOMStyle()) {
if (!gCSSOMFactory) {
rv = CallGetService(kCSSOMFactoryCID, &gCSSOMFactory);
if (NS_FAILED(rv)) {
return rv;
}
}
nsRefPtr<nsDOMCSSDeclaration> domStyle;
rv = gCSSOMFactory->CreateDOMCSSAttributeDeclaration(this,
getter_AddRefs(domStyle));
if (NS_FAILED(rv)) {
return rv;
}
attrs->SetDOMStyle(domStyle);
}
// Why bother with QI?
NS_IF_ADDREF(*aStyle = attrs->GetDOMStyle());
return NS_OK;
}
NS_IMETHODIMP
@ -4520,6 +4622,7 @@ nsXULElement::Slots::~Slots()
nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
{
MOZ_COUNT_DTOR(nsXULPrototypeAttribute);
if (mEventHandler)
RemoveJSGCRoot(&mEventHandler);
}

View File

@ -56,6 +56,7 @@
#include "nsINodeInfo.h"
#include "nsIControllers.h"
#include "nsICSSParser.h"
#include "nsICSSStyleRule.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOM3EventTarget.h"
@ -78,6 +79,7 @@
#include "nsIChromeEventHandler.h"
#include "nsXULAttributeValue.h"
#include "nsIXBLService.h"
#include "nsICSSOMFactory.h"
#include "nsLayoutCID.h"
#include "nsGenericElement.h" // for nsCheapVoidArray
@ -113,6 +115,8 @@ static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
*/
MOZ_DECL_CTOR_COUNTER(nsXULPrototypeAttribute)
class nsXULPrototypeAttribute
{
public:
@ -120,6 +124,7 @@ public:
: mEventHandler(nsnull)
{
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumAttributes);
MOZ_COUNT_CTOR(nsXULPrototypeAttribute);
}
~nsXULPrototypeAttribute();
@ -271,7 +276,7 @@ public:
PRUint32 mNumAttributes;
nsXULPrototypeAttribute* mAttributes; // [OWNER]
nsCOMPtr<nsIStyleRule> mInlineStyleRule; // [OWNER]
nsCOMPtr<nsICSSStyleRule> mInlineStyleRule; // [OWNER]
nsClassList* mClassList;
nsresult GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, nsAString& aValue);
@ -387,12 +392,17 @@ public:
CallGetService("@mozilla.org/xbl;1", &gXBLService);
return gXBLService;
}
static void ReleaseGlobals() { NS_IF_RELEASE(gXBLService); }
static void ReleaseGlobals() {
NS_IF_RELEASE(gXBLService);
NS_IF_RELEASE(gCSSOMFactory);
}
protected:
static nsrefcnt gRefCnt;
// pseudo-constants
static nsIRDFService* gRDFService;
static nsIXBLService* gXBLService;
static nsICSSOMFactory* gCSSOMFactory;
public:
static nsresult
@ -473,7 +483,8 @@ public:
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
NS_IMETHOD GetInlineStyleRule(nsIStyleRule** aStyleRule);
NS_IMETHOD GetInlineStyleRule(nsICSSStyleRule** aStyleRule);
NS_IMETHOD SetInlineStyleRule(nsICSSStyleRule* aStyleRule, PRBool aNotify);
NS_IMETHOD GetAttributeChangeHint(const nsIAtom* aAttribute,
PRInt32 aModType,
nsChangeHint& aHint) const;
@ -651,6 +662,10 @@ protected:
nsresult HideWindowChrome(PRBool aShouldHide);
void FinishSetAttr(PRInt32 aAttrNS, nsIAtom* aAttrName,
const nsAString& aOldValue, const nsAString& aNewValue,
PRInt32 aModHint, PRBool aNotify);
protected:
// Internal accessors. These shadow the 'Slots', and return
// appropriate default values if there are no slots defined in the
@ -660,8 +675,6 @@ protected:
nsXULAttributes *Attributes() const { return mSlots ? mSlots->GetAttributes() : nsnull; }
void UnregisterAccessKey(const nsAString& aOldValue);
static nsIXBLService *gXBLService;
};

View File

@ -51,7 +51,7 @@ nsCSSOMFactory::~nsCSSOMFactory()
NS_IMPL_ISUPPORTS1(nsCSSOMFactory, nsICSSOMFactory)
NS_IMETHODIMP
nsCSSOMFactory::CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
nsCSSOMFactory::CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult)
{
nsDOMCSSDeclaration *result = new nsDOMCSSAttributeDeclaration(aContent);

View File

@ -51,7 +51,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult);
};

View File

@ -111,9 +111,9 @@ public:
nsIURI* aInputURL,
nsICSSStyleSheet*& aResult);
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult);
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsICSSStyleRule** aResult);
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aBaseURL,
@ -596,7 +596,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
NS_IMETHODIMP
CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult)
nsICSSStyleRule** aResult)
{
NS_ASSERTION(nsnull != aBaseURL, "need base URL");

View File

@ -40,7 +40,7 @@
#include "nsCSSDeclaration.h"
#include "nsIDocument.h"
#include "nsHTMLAtoms.h"
#include "nsIHTMLContent.h"
#include "nsIStyledContent.h"
#include "nsIDOMMutationEvent.h"
#include "nsHTMLValue.h"
#include "nsICSSStyleRule.h"
@ -54,7 +54,7 @@
MOZ_DECL_CTOR_COUNTER(nsDOMCSSAttributeDeclaration)
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent)
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIStyledContent *aContent)
{
MOZ_COUNT_CTOR(nsDOMCSSAttributeDeclaration);
@ -81,25 +81,16 @@ nsresult
nsDOMCSSAttributeDeclaration::DeclarationChanged()
{
NS_ASSERTION(mContent, "Must have content node to set the decl!");
nsHTMLValue val;
#ifdef DEBUG
nsresult rv =
#endif
mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
NS_ASSERTION(rv == NS_CONTENT_ATTR_HAS_VALUE &&
eHTMLUnit_ISupports == val.GetUnit(),
"content must have rule");
nsCOMPtr<nsICSSStyleRule> oldRule =
do_QueryInterface(nsCOMPtr<nsISupports>(val.GetISupportsValue()));
nsCOMPtr<nsICSSStyleRule> oldRule;
mContent->GetInlineStyleRule(getter_AddRefs(oldRule));
NS_ASSERTION(oldRule, "content must have rule");
nsCOMPtr<nsICSSStyleRule> newRule = oldRule->DeclarationChanged(PR_FALSE);
if (!newRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
return mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(newRule),
PR_TRUE);
return mContent->SetInlineStyleRule(newRule, PR_TRUE);
}
nsresult
@ -110,15 +101,10 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
*aDecl = nsnull;
if (mContent) {
nsHTMLValue val;
result = mContent->GetHTMLAttribute(nsHTMLAtoms::style, val);
if (result == NS_CONTENT_ATTR_HAS_VALUE &&
eHTMLUnit_ISupports == val.GetUnit()) {
nsCOMPtr<nsISupports> rule = val.GetISupportsValue();
nsCOMPtr<nsICSSStyleRule> cssRule = do_QueryInterface(rule, &result);
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
}
nsCOMPtr<nsICSSStyleRule> cssRule;
mContent->GetInlineStyleRule(getter_AddRefs(cssRule));
if (cssRule) {
*aDecl = cssRule->GetDeclaration();
}
else if (aAllocate) {
nsCSSDeclaration *decl = new nsCSSDeclaration();
@ -136,9 +122,7 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
return result;
}
result = mContent->SetHTMLAttribute(nsHTMLAtoms::style,
nsHTMLValue(cssRule),
PR_FALSE);
result = mContent->SetInlineStyleRule(cssRule, PR_FALSE);
if (NS_SUCCEEDED(result)) {
*aDecl = decl;
}

View File

@ -45,14 +45,14 @@
#include "nsString.h"
class nsIContent;
class nsIHTMLContent;
class nsIStyledContent;
class nsICSSLoader;
class nsICSSParser;
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
{
public:
nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent);
nsDOMCSSAttributeDeclaration(nsIStyledContent *aContent);
~nsDOMCSSAttributeDeclaration();
// impl AddRef/Release; QI is implemented by our parent class
@ -75,7 +75,7 @@ protected:
nsAutoRefCnt mRefCnt;
NS_DECL_OWNINGTHREAD
nsIHTMLContent *mContent;
nsIStyledContent *mContent;
};
#endif /* nsDOMCSSAttributeDeclaration_h___ */

View File

@ -36,7 +36,7 @@
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsDOMCSSDeclaration_h___
#define nsDOMCSSSDeclaration_h___
#define nsDOMCSSDeclaration_h___
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSS2Properties.h"

View File

@ -452,7 +452,7 @@ HTMLCSSStyleSheetImpl::RulesMatching(ElementRuleProcessorData* aData,
if (styledContent) {
// just get the one and only style rule from the content's STYLE attribute
nsCOMPtr<nsIStyleRule> rule;
nsCOMPtr<nsICSSStyleRule> rule;
styledContent->GetInlineStyleRule(getter_AddRefs(rule));
if (rule)
aData->mRuleWalker->Forward(rule);

View File

@ -42,7 +42,7 @@
#include "nsISupports.h"
class nsDOMCSSDeclaration;
class nsIHTMLContent;
class nsIStyledContent;
// bfdd87bd-79c8-4041-ae14-91fa8536ce61
#define NS_ICSSOMFACTORY_IID \
@ -58,7 +58,7 @@ class nsICSSOMFactory : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSSOMFACTORY_IID)
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIHTMLContent *aContent,
NS_IMETHOD CreateDOMCSSAttributeDeclaration(nsIStyledContent *aContent,
nsDOMCSSDeclaration **aResult) = 0;
};

View File

@ -41,7 +41,7 @@
#include "nsISupports.h"
#include "nsAString.h"
class nsIStyleRule;
class nsICSSStyleRule;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURI;
@ -84,7 +84,7 @@ public:
// the declaration.
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aBaseURL,
nsIStyleRule** aResult) = 0;
nsICSSStyleRule** aResult) = 0;
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aBaseURL,