Changes to the builder APIs to distinguish folder items from leaf

items (although we're not quite there yet).
This commit is contained in:
hyatt%netscape.com 1999-03-07 23:18:26 +00:00
Родитель 48f57c2848
Коммит 10c3453c14
7 изменённых файлов: 75 добавлений и 63 удалений

Просмотреть файл

@ -742,13 +742,8 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a
// Now do the work to change the attribute. There are a couple of
// special cases that we need to check for here...
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are possibly changing the value of the "open"
@ -866,12 +861,8 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are removing the value of the "open" attribute. This may
@ -1097,13 +1088,15 @@ RDFGenericBuilderImpl::FindWidgetRootElement(nsIContent* aElement,
PRBool
RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
RDFGenericBuilderImpl::IsWidgetElement(nsIContent* aElement)
{
// Returns PR_TRUE if the element is a <xul:treeitem> element.
// Returns PR_TRUE if the element is an item in the widget.
nsresult rv;
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) ||
NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1112,7 +1105,7 @@ RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag))))
return PR_FALSE;
if (tag.get() != itemAtom)
if (tag.get() != itemAtom && tag.get() != folderAtom)
return PR_FALSE;
return PR_TRUE;
@ -1243,8 +1236,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1252,8 +1245,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
if (tag.get() == insertionAtom)
return PR_TRUE;
// If it's not a widget item, then it's not open.
if (tag.get() != itemAtom)
// If it's not a widget folder item, then it's not open.
if (tag.get() != folderAtom)
return PR_FALSE;
nsAutoString value;

Просмотреть файл

@ -742,13 +742,8 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a
// Now do the work to change the attribute. There are a couple of
// special cases that we need to check for here...
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are possibly changing the value of the "open"
@ -866,12 +861,8 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are removing the value of the "open" attribute. This may
@ -1097,13 +1088,15 @@ RDFGenericBuilderImpl::FindWidgetRootElement(nsIContent* aElement,
PRBool
RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
RDFGenericBuilderImpl::IsWidgetElement(nsIContent* aElement)
{
// Returns PR_TRUE if the element is a <xul:treeitem> element.
// Returns PR_TRUE if the element is an item in the widget.
nsresult rv;
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) ||
NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1112,7 +1105,7 @@ RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag))))
return PR_FALSE;
if (tag.get() != itemAtom)
if (tag.get() != itemAtom && tag.get() != folderAtom)
return PR_FALSE;
return PR_TRUE;
@ -1243,8 +1236,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1252,8 +1245,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
if (tag.get() == insertionAtom)
return PR_TRUE;
// If it's not a widget item, then it's not open.
if (tag.get() != itemAtom)
// If it's not a widget folder item, then it's not open.
if (tag.get() != folderAtom)
return PR_FALSE;
nsAutoString value;

Просмотреть файл

@ -107,7 +107,7 @@ public:
IsElementInWidget(nsIContent* aElement);
PRBool
IsWidgetItemElement(nsIContent* aElement);
IsWidgetElement(nsIContent* aElement);
PRBool
IsWidgetInsertionRootElement(nsIContent* aElement);
@ -141,6 +141,9 @@ public:
virtual nsresult
GetWidgetItemAtom(nsIAtom** aResult) = 0;
virtual nsresult
GetWidgetFolderAtom(nsIAtom** aResult) = 0;
virtual nsresult
GetInsertionRootAtom(nsIAtom** aResult) = 0;

Просмотреть файл

@ -106,12 +106,19 @@ public:
}
nsresult
GetInsertionRootAtom(nsIAtom** aResult) {
GetWidgetFolderAtom(nsIAtom** aResult) {
NS_ADDREF(kMenuAtom);
*aResult = kMenuAtom;
return NS_OK;
}
nsresult
GetInsertionRootAtom(nsIAtom** aResult) {
NS_ADDREF(kMenuBarAtom);
*aResult = kMenuBarAtom;
return NS_OK;
}
nsresult
GetItemAtomThatContainsTheChildren(nsIAtom** aResult) {
NS_ADDREF(kMenuAtom);
@ -122,6 +129,7 @@ public:
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIAtom* kMenuBarAtom;
static nsIAtom* kMenuAtom;
static nsIAtom* kMenuItemAtom;
};
@ -132,6 +140,7 @@ nsrefcnt RDFMenuBuilderImpl::gRefCnt = 0;
nsIAtom* RDFMenuBuilderImpl::kMenuAtom;
nsIAtom* RDFMenuBuilderImpl::kMenuItemAtom;
nsIAtom* RDFMenuBuilderImpl::kMenuBarAtom;
////////////////////////////////////////////////////////////////////////
@ -159,6 +168,7 @@ RDFMenuBuilderImpl::RDFMenuBuilderImpl(void)
if (gRefCnt == 0) {
kMenuAtom = NS_NewAtom("menu");
kMenuItemAtom = NS_NewAtom("menuitem");
kMenuBarAtom = NS_NewAtom("menubar");
}
++gRefCnt;
@ -171,6 +181,7 @@ RDFMenuBuilderImpl::~RDFMenuBuilderImpl(void)
NS_RELEASE(kMenuAtom);
NS_RELEASE(kMenuItemAtom);
NS_RELEASE(kMenuBarAtom);
}
}
@ -187,7 +198,7 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
nsCOMPtr<nsIContent> menuParent;
menuParent = dont_QueryInterface(aElement);
if (!IsWidgetItemElement(aElement) && !IsWidgetInsertionRootElement(aElement))
if (!IsWidgetElement(aElement) && !IsWidgetInsertionRootElement(aElement))
{
NS_ERROR("Can't add something here!");
return NS_ERROR_UNEXPECTED;

Просмотреть файл

@ -158,6 +158,13 @@ public:
return NS_OK;
}
nsresult
GetWidgetFolderAtom(nsIAtom** aResult) {
NS_ADDREF(kTreeItemAtom);
*aResult = kTreeItemAtom;
return NS_OK;
}
nsresult
GetInsertionRootAtom(nsIAtom** aResult) {
NS_ADDREF(kTreeBodyAtom);
@ -301,7 +308,7 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
nsresult rv;
nsCOMPtr<nsIContent> treeChildren;
if (IsWidgetItemElement(aElement)) {
if (IsWidgetElement(aElement)) {
// Ensure that the <xul:treechildren> element exists on the parent.
if (NS_FAILED(rv = EnsureElementHasGenericChild(aElement,
kNameSpaceID_XUL,

Просмотреть файл

@ -84,6 +84,7 @@ static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID)
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFMenuBuilderCID, NS_RDFMENUBUILDER_CID);
static NS_DEFINE_CID(kRDFToolbarBuilderCID, NS_RDFTOOLBARBUILDER_CID);
////////////////////////////////////////////////////////////////////////
// standard vocabulary items
@ -128,6 +129,8 @@ private:
static nsIAtom* kIdAtom;
static nsIAtom* kTreeAtom;
static nsIAtom* kMenuAtom;
static nsIAtom* kMenuBarAtom;
static nsIAtom* kToolbarAtom;
static nsIRDFResource* kRDF_instanceOf;
static nsIRDFResource* kRDF_nextVal;
@ -230,6 +233,8 @@ nsIAtom* RDFXULBuilderImpl::kIdAtom;
nsIAtom* RDFXULBuilderImpl::kDataSourcesAtom;
nsIAtom* RDFXULBuilderImpl::kTreeAtom;
nsIAtom* RDFXULBuilderImpl::kMenuAtom;
nsIAtom* RDFXULBuilderImpl::kMenuBarAtom;
nsIAtom* RDFXULBuilderImpl::kToolbarAtom;
nsIRDFResource* RDFXULBuilderImpl::kRDF_instanceOf;
nsIRDFResource* RDFXULBuilderImpl::kRDF_nextVal;
@ -286,6 +291,8 @@ RDFXULBuilderImpl::RDFXULBuilderImpl(void)
kDataSourcesAtom = NS_NewAtom("datasources");
kTreeAtom = NS_NewAtom("tree");
kMenuAtom = NS_NewAtom("menu");
kMenuBarAtom = NS_NewAtom("menubar");
kToolbarAtom = NS_NewAtom("toolbar");
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
@ -339,6 +346,8 @@ RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
NS_IF_RELEASE(kDataSourcesAtom);
NS_IF_RELEASE(kTreeAtom);
NS_IF_RELEASE(kMenuAtom);
NS_IF_RELEASE(kMenuBarAtom);
NS_IF_RELEASE(kToolbarAtom);
}
}
@ -1517,7 +1526,8 @@ RDFXULBuilderImpl::CreateXULElement(nsIRDFResource* aResource,
}
// There are some tags that we need to pay extra-special attention to...
if (aTag == kTreeAtom || aTag == kMenuAtom) {
if (aTag == kTreeAtom || aTag == kMenuAtom || aTag == kMenuBarAtom ||
aTag == kToolbarAtom) {
nsAutoString dataSources;
if (NS_CONTENT_ATTR_HAS_VALUE ==
element->GetAttribute(kNameSpaceID_None,
@ -1527,8 +1537,10 @@ RDFXULBuilderImpl::CreateXULElement(nsIRDFResource* aResource,
nsCID builderCID;
if (aTag == kTreeAtom)
builderCID = kRDFTreeBuilderCID;
else if (aTag == kMenuAtom)
else if (aTag == kMenuAtom || aTag == kMenuBarAtom)
builderCID = kRDFMenuBuilderCID;
else if (aTag == kToolbarAtom)
builderCID = kRDFToolbarBuilderCID;
rv = CreateBuilder(builderCID, element, dataSources);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add datasources");

Просмотреть файл

@ -742,13 +742,8 @@ RDFGenericBuilderImpl::OnSetAttribute(nsIDOMElement* aElement, const nsString& a
// Now do the work to change the attribute. There are a couple of
// special cases that we need to check for here...
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are possibly changing the value of the "open"
@ -866,12 +861,8 @@ RDFGenericBuilderImpl::OnRemoveAttribute(nsIDOMElement* aElement, const nsString
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
return rv;
}
if ((elementNameSpaceID == kNameSpaceID_XUL) &&
(elementNameAtom.get() == itemAtom) &&
IsWidgetElement(element) &&
(attrNameSpaceID == kNameSpaceID_None) &&
(attrNameAtom.get() == kOpenAtom)) {
// We are removing the value of the "open" attribute. This may
@ -1097,13 +1088,15 @@ RDFGenericBuilderImpl::FindWidgetRootElement(nsIContent* aElement,
PRBool
RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
RDFGenericBuilderImpl::IsWidgetElement(nsIContent* aElement)
{
// Returns PR_TRUE if the element is a <xul:treeitem> element.
// Returns PR_TRUE if the element is an item in the widget.
nsresult rv;
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom))) ||
NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1112,7 +1105,7 @@ RDFGenericBuilderImpl::IsWidgetItemElement(nsIContent* aElement)
if (NS_FAILED(rv = aElement->GetTag(*getter_AddRefs(tag))))
return PR_FALSE;
if (tag.get() != itemAtom)
if (tag.get() != itemAtom && tag.get() != folderAtom)
return PR_FALSE;
return PR_TRUE;
@ -1243,8 +1236,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
return rv;
}
nsCOMPtr<nsIAtom> itemAtom;
if (NS_FAILED(rv = GetWidgetItemAtom(getter_AddRefs(itemAtom)))) {
nsCOMPtr<nsIAtom> folderAtom;
if (NS_FAILED(rv = GetWidgetFolderAtom(getter_AddRefs(folderAtom)))) {
return rv;
}
@ -1252,8 +1245,8 @@ RDFGenericBuilderImpl::IsOpen(nsIContent* aElement)
if (tag.get() == insertionAtom)
return PR_TRUE;
// If it's not a widget item, then it's not open.
if (tag.get() != itemAtom)
// If it's not a widget folder item, then it's not open.
if (tag.get() != folderAtom)
return PR_FALSE;
nsAutoString value;