зеркало из https://github.com/mozilla/gecko-dev.git
Add support for class attribute in XTF, bug 283366, r=bryner, sr=bzbarsky, patch by smaug@welho.com
This commit is contained in:
Родитель
66b4bd19f7
Коммит
74514ee1bf
|
@ -40,7 +40,7 @@
|
|||
|
||||
interface nsIDOMElement;
|
||||
|
||||
[scriptable, uuid(1ea57817-73cc-4224-adb7-55aa83bb3f09)]
|
||||
[scriptable, uuid(59de39e3-56ff-47c0-a580-f15dbde45ed3)]
|
||||
interface nsIXTFVisual : nsIXTFElement
|
||||
{
|
||||
// The content tree rooted in 'visualContent' will be rendered where
|
||||
|
@ -72,4 +72,10 @@ interface nsIXTFVisual : nsIXTFElement
|
|||
|
||||
// Event notifications:
|
||||
void didLayout();
|
||||
|
||||
// Returns an atom holding the name of the "class" attribute.
|
||||
// This is called once during XTFVisual creation.
|
||||
// The xtf element doesn't have to keep a strong ref to the atom.
|
||||
// Note! nsIXTFAttributeHandler can't be used to handle class attribute.
|
||||
nsIAtom getClassAttributeName();
|
||||
};
|
||||
|
|
|
@ -116,3 +116,60 @@ nsXTFVisualWrapper::ApplyDocumentStyleSheets()
|
|||
GetXTFVisual()->GetApplyDocumentStyleSheets(&retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXTFVisualWrapper::Init()
|
||||
{
|
||||
nsresult rv = nsXTFVisualWrapperBase::Init();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return GetXTFVisual()->GetClassAttributeName(getter_AddRefs(mClassAttributeName));
|
||||
}
|
||||
|
||||
nsIAtom *
|
||||
nsXTFVisualWrapper::GetClassAttributeName() const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<nsIAtom> classAttr;
|
||||
GetXTFVisual()->GetClassAttributeName(getter_AddRefs(classAttr));
|
||||
NS_WARN_IF_FALSE(classAttr == mClassAttributeName,
|
||||
"The name of the class attribute has changed.");
|
||||
#endif
|
||||
return mClassAttributeName;
|
||||
}
|
||||
|
||||
const nsAttrValue*
|
||||
nsXTFVisualWrapper::GetClasses() const
|
||||
{
|
||||
const nsAttrValue* val = nsnull;
|
||||
nsIAtom* clazzAttr = GetClassAttributeName();
|
||||
if (clazzAttr) {
|
||||
val = mAttrsAndChildren.GetAttr(clazzAttr);
|
||||
// This is possibly the first time we need any classes.
|
||||
if (val && val->Type() == nsAttrValue::eString) {
|
||||
nsAutoString value;
|
||||
val->ToString(value);
|
||||
nsAttrValue newValue;
|
||||
newValue.ParseAtomArray(value);
|
||||
NS_CONST_CAST(nsAttrAndChildArray*, &mAttrsAndChildren)->
|
||||
SetAndTakeAttr(clazzAttr, newValue);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(PRBool)
|
||||
nsXTFVisualWrapper::HasClass(nsIAtom* aClass, PRBool /*aCaseSensitive*/) const
|
||||
{
|
||||
const nsAttrValue* val = GetClasses();
|
||||
if (val) {
|
||||
if (val->Type() == nsAttrValue::eAtom) {
|
||||
return aClass == val->GetAtomValue();
|
||||
}
|
||||
|
||||
if (val->Type() == nsAttrValue::eAtomArray) {
|
||||
return val->GetAtomArrayValue()->IndexOf(aClass) >= 0;
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,11 +63,19 @@ public:
|
|||
virtual void GetInsertionPoint(nsIDOMElement** insertionPoint);
|
||||
virtual PRBool ApplyDocumentStyleSheets();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
// nsIStyledContent
|
||||
virtual nsIAtom *GetClassAttributeName() const;
|
||||
virtual const nsAttrValue* GetClasses() const;
|
||||
NS_IMETHOD_(PRBool) HasClass(nsIAtom* aClass, PRBool aCaseSensitive) const;
|
||||
|
||||
protected:
|
||||
// to be implemented by subclasses:
|
||||
virtual nsIXTFVisual *GetXTFVisual() const = 0;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mVisualContent;
|
||||
nsCOMPtr<nsIAtom> mClassAttributeName;
|
||||
};
|
||||
|
||||
#endif // __NS_XTFVISUALWRAPPER_H__
|
||||
|
|
|
@ -58,6 +58,7 @@ nsIAtom *nsXFormsAtoms::model;
|
|||
nsIAtom *nsXFormsAtoms::selected;
|
||||
nsIAtom *nsXFormsAtoms::appearance;
|
||||
nsIAtom *nsXFormsAtoms::incremental;
|
||||
nsIAtom *nsXFormsAtoms::clazz;
|
||||
|
||||
const nsStaticAtom nsXFormsAtoms::Atoms_info[] = {
|
||||
{ "src", &nsXFormsAtoms::src },
|
||||
|
@ -78,7 +79,8 @@ const nsStaticAtom nsXFormsAtoms::Atoms_info[] = {
|
|||
{ "model", &nsXFormsAtoms::model },
|
||||
{ "selected", &nsXFormsAtoms::selected },
|
||||
{ "appearance", &nsXFormsAtoms::appearance },
|
||||
{ "incremental", &nsXFormsAtoms::incremental }
|
||||
{ "incremental", &nsXFormsAtoms::incremental },
|
||||
{ "class", &nsXFormsAtoms::clazz }
|
||||
};
|
||||
|
||||
void
|
||||
|
|
|
@ -63,6 +63,7 @@ class nsXFormsAtoms
|
|||
static NS_HIDDEN_(nsIAtom *) appearance;
|
||||
static NS_HIDDEN_(nsIAtom *) incremental;
|
||||
static NS_HIDDEN_(nsIAtom *) value;
|
||||
static NS_HIDDEN_(nsIAtom *) clazz;
|
||||
|
||||
static NS_HIDDEN_(void) InitAtoms();
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "nsIDOM3Node.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsXFormsUtils.h"
|
||||
#include "nsXFormsAtoms.h"
|
||||
|
||||
static const nsIID sScriptingIIDs[] = {
|
||||
NS_IDOMELEMENT_IID,
|
||||
|
@ -373,6 +374,13 @@ nsXFormsXMLVisualStub::DidLayout()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsXMLVisualStub::GetClassAttributeName(nsIAtom** aName)
|
||||
{
|
||||
NS_ADDREF(*aName = nsXFormsAtoms::clazz);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXFormsXMLVisualStub::OnCreated(nsIXTFXMLVisualWrapper *aWrapper)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче