Teaching XUL overlays how to do positioning.

This commit is contained in:
hyatt%netscape.com 1999-07-17 21:50:01 +00:00
parent ba2f8f9be7
commit f043918b1e

View File

@ -128,6 +128,8 @@ static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Utility routines // Utility routines
@ -264,10 +266,10 @@ protected:
nsIDocument* mChildDocument; nsIDocument* mChildDocument;
nsIParser* mParser; nsIParser* mParser;
nsVoidArray* mOverlayArray; nsVoidArray* mOverlayArray;
PRInt32 mCurrentOverlay; PRInt32 mCurrentOverlay;
nsIXULContentSink* mParentContentSink; nsIXULContentSink* mParentContentSink;
nsString mPreferredStyle; nsString mPreferredStyle;
PRInt32 mStyleSheetCount; PRInt32 mStyleSheetCount;
nsICSSLoader* mCSSLoader; nsICSSLoader* mCSSLoader;
@ -300,8 +302,8 @@ XULContentSinkImpl::XULContentSinkImpl()
mChildDocument(nsnull), mChildDocument(nsnull),
mParser(nsnull), mParser(nsnull),
mOverlayArray(nsnull), mOverlayArray(nsnull),
mCurrentOverlay(0), mCurrentOverlay(0),
mParentContentSink(nsnull), mParentContentSink(nsnull),
mStyleSheetCount(0), mStyleSheetCount(0),
mCSSLoader(nsnull) mCSSLoader(nsnull)
{ {
@ -443,16 +445,16 @@ XULContentSinkImpl::~XULContentSinkImpl()
NS_IF_RELEASE(kXUL_element); NS_IF_RELEASE(kXUL_element);
} }
// Delete all the elements from our overlay array // Delete all the elements from our overlay array
if (mOverlayArray) { if (mOverlayArray) {
PRInt32 count = mOverlayArray->Count(); PRInt32 count = mOverlayArray->Count();
for (PRInt32 i = 0; i < count; i++) { for (PRInt32 i = 0; i < count; i++) {
nsString* element = (nsString*)(mOverlayArray->ElementAt(i)); nsString* element = (nsString*)(mOverlayArray->ElementAt(i));
delete element; delete element;
} }
delete mOverlayArray; delete mOverlayArray;
} }
} }
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -620,7 +622,7 @@ XULContentSinkImpl::OpenContainer(const nsIParserNode& aNode)
break; break;
} }
//NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected content"); //NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected content");
return rv; return rv;
} }
@ -657,16 +659,16 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode)
FlushText(); FlushText();
} }
// XXX The following code is a hack to make forms work in XUL. Forms aren't // XXX The following code is a hack to make forms work in XUL. Forms aren't
// really pushed and popped like other elements. // really pushed and popped like other elements.
nsAutoString tag; nsAutoString tag;
PRInt32 nameSpaceID; PRInt32 nameSpaceID;
SplitQualifiedName(aNode.GetText(), nameSpaceID, tag); SplitQualifiedName(aNode.GetText(), nameSpaceID, tag);
PRBool popContent = PR_TRUE; PRBool popContent = PR_TRUE;
if (nameSpaceID == kNameSpaceID_HTML) { if (nameSpaceID == kNameSpaceID_HTML) {
if (tag.Equals("form")) if (tag.Equals("form"))
popContent = PR_FALSE; popContent = PR_FALSE;
} }
if (popContent) { if (popContent) {
nsIRDFResource* resource; nsIRDFResource* resource;
@ -690,25 +692,25 @@ XULContentSinkImpl::CloseContainer(const nsIParserNode& aNode)
PRInt32 nestLevel = mContextStack->Count(); PRInt32 nestLevel = mContextStack->Count();
if (nestLevel == 0) { if (nestLevel == 0) {
mState = eXULContentSinkState_InEpilog; mState = eXULContentSinkState_InEpilog;
// We're about to finish parsing. Now we want to kick off the processing // We're about to finish parsing. Now we want to kick off the processing
// of our child overlays. // of our child overlays.
PRInt32 count; PRInt32 count;
if (mOverlayArray && (count = mOverlayArray->Count())) { if (mOverlayArray && (count = mOverlayArray->Count())) {
nsString* href = (nsString*)mOverlayArray->ElementAt(0); nsString* href = (nsString*)mOverlayArray->ElementAt(0);
ProcessOverlay(*href); ProcessOverlay(*href);
// Block the parser. It will only be unblocked after all // Block the parser. It will only be unblocked after all
// of our child overlays have finished parsing. // of our child overlays have finished parsing.
rv = NS_ERROR_HTMLPARSER_BLOCK; rv = NS_ERROR_HTMLPARSER_BLOCK;
} }
// Unblock the next sibling overlay. If there is no next sibling // Unblock the next sibling overlay. If there is no next sibling
// overlay, unblock our parent. // overlay, unblock our parent.
if (mParentContentSink) { if (mParentContentSink) {
mParentContentSink->UnblockNextOverlay(); mParentContentSink->UnblockNextOverlay();
} }
} }
PopNameSpaces(); PopNameSpaces();
@ -1437,7 +1439,7 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
SplitQualifiedName(aNode.GetText(), nameSpaceID, tag); SplitQualifiedName(aNode.GetText(), nameSpaceID, tag);
// HTML tags must be lowercase // HTML tags must be lowercase
PRBool pushContent = PR_TRUE; PRBool pushContent = PR_TRUE;
if (nameSpaceID == kNameSpaceID_HTML) { if (nameSpaceID == kNameSpaceID_HTML) {
if (tag.Equals("script")) { if (tag.Equals("script")) {
return OpenScript(aNode); return OpenScript(aNode);
@ -1486,8 +1488,8 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to assert tag type"); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to assert tag type");
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// Make arcs from us to all of our attribute values (with the attribute names // Make arcs from us to all of our attribute values (with the attribute names
// as the labels of the arcs). // as the labels of the arcs).
if (NS_FAILED(rv = AddAttributes(aNode, rdfResource))) { if (NS_FAILED(rv = AddAttributes(aNode, rdfResource))) {
NS_ERROR("problem adding properties to node"); NS_ERROR("problem adding properties to node");
return rv; return rv;
@ -1498,15 +1500,7 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
// container). // container).
mHaveSetRootResource = PR_TRUE; mHaveSetRootResource = PR_TRUE;
/*if (mFragmentRoot) { if (!mParentContentSink) {
// We're a subdocument. We need to take this fragment
// node (which is the root of the fragment) and completely
// discard it. The fragment root's resource is actually what
// should become the root of this subtree.
rdfResource = dont_QueryInterface(mFragmentRoot);
}
else*/
if (!mParentContentSink) {
nsCOMPtr<nsIRDFDocument> rdfDoc; nsCOMPtr<nsIRDFDocument> rdfDoc;
if (NS_SUCCEEDED(mDocument->QueryInterface(nsIRDFDocument::GetIID(), if (NS_SUCCEEDED(mDocument->QueryInterface(nsIRDFDocument::GetIID(),
(void**) getter_AddRefs(rdfDoc)))) { (void**) getter_AddRefs(rdfDoc)))) {
@ -1524,14 +1518,54 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
rv = NS_NewRDFContainer(mDataSource, GetTopResource(), getter_AddRefs(container)); rv = NS_NewRDFContainer(mDataSource, GetTopResource(), getter_AddRefs(container));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = container->AppendElement(rdfResource); // Find out if a position is specified. If so, we use that as the arc
// label instead of appending the object to the end.
// Add the attribute to RDF
nsCOMPtr<nsIRDFResource> property;
nsAutoString attr("#position");
rv = gRDFService->GetUnicodeResource(attr.GetUnicode(), getter_AddRefs(property));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIRDFNode> positionValue;
rv = mDataSource->GetTarget(rdfResource, property, PR_TRUE, getter_AddRefs(positionValue));
if (NS_FAILED(rv)) return rv;
if (positionValue) {
nsCOMPtr<nsIRDFLiteral> positionLiteral = do_QueryInterface(positionValue);
if (positionLiteral) {
// Retrieve the value that represents the position.
const PRUnichar* valueStr;
positionLiteral->GetValueConst(&valueStr);
nsCOMPtr<nsIRDFResource> posResource;
nsAutoString posStr(valueStr);
nsAutoString nextValStr = kRDFNameSpaceURI;
nextValStr.Append("_");
nextValStr.Append(posStr, 10);
rv = gRDFService->GetUnicodeResource(nextValStr.GetUnicode(), getter_AddRefs(posResource));
if (NS_FAILED(rv)) return rv;
rv = mDataSource->Assert(GetTopResource(), posResource, rdfResource, PR_TRUE);
}
else rv = container->AppendElement(rdfResource);
}
else {
// XXX We could be an overlay node indicating a removal. If so, then we
// want to find the original assertion that linked us to the parent
// and perform a removal.
// Otherwise we're just a normal child and should be appended just like anyone
// else.
rv = container->AppendElement(rdfResource);
}
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add child to container"); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add child to container");
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
// Push the element onto the context stack, so that child // Push the element onto the context stack, so that child
// containers will hook up to us as their parent. // containers will hook up to us as their parent.
// (XXX The push content hack is for HTML form content. See above.) // (XXX The push content hack is for HTML form content. See above.)
if (pushContent) if (pushContent)
PushResourceAndState(rdfResource, mState); PushResourceAndState(rdfResource, mState);
mState = eXULContentSinkState_InDocumentElement; mState = eXULContentSinkState_InDocumentElement;