better base url support

added support for "none" style change hint
added assert for recycling of html attributes

Checkin during red tree approved by sar
This commit is contained in:
peterl%netscape.com 1999-01-15 02:09:29 +00:00
parent c251f70e4b
commit b37a2f5b7a
3 changed files with 123 additions and 99 deletions

View File

@ -585,17 +585,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) && if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) &&
(nsnull != linkHandler)) { (nsnull != linkHandler)) {
nsAutoString base, href; // XXX base?? nsAutoString base, href;
nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href); nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href);
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) { if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURL* docURL = nsnull; nsIURL* docURL = nsnull;
nsIDocument* doc = nsnull; htmlContent->GetBaseURL(docURL);
aContent->GetDocument(doc);
if (nsnull != doc) {
docURL = doc->GetDocumentURL();
NS_RELEASE(doc);
}
nsAutoString absURLSpec; nsAutoString absURLSpec;
nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec); nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);
@ -835,6 +830,16 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute,
return result; return result;
} }
#ifdef NS_DEBUG
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
nsrefcnt count = ptr->AddRef(); \
ptr->Release(); \
NS_ASSERTION(--count == cnt, msg); \
}
#else
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) {}
#endif
NS_IMETHODIMP NS_IMETHODIMP
HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes, HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
nsMapAttributesFunc aMapFunc, nsMapAttributesFunc aMapFunc,
@ -847,6 +852,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
if (nsnull == aAttributes) { if (nsnull == aAttributes) {
if (PR_TRUE == aCreate) { if (PR_TRUE == aCreate) {
if (nsnull != mRecycledAttrs) { if (nsnull != mRecycledAttrs) {
NS_ASSERT_REFCOUNT(mRecycledAttrs, 1, "attributes used elsewhere");
aSingleAttrs = mRecycledAttrs; aSingleAttrs = mRecycledAttrs;
mRecycledAttrs = nsnull; mRecycledAttrs = nsnull;
aSingleAttrs->SetMappingFunction(aMapFunc); aSingleAttrs->SetMappingFunction(aMapFunc);
@ -2712,9 +2718,10 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2729,18 +2736,18 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
NS_IF_RELEASE(parentContext); NS_IF_RELEASE(parentContext);
NS_RELEASE(frameContext); NS_RELEASE(frameContext);
} }
} if (PR_TRUE == reframe) {
if (PR_TRUE == reframe) { NS_NOTYETIMPLEMENTED("frame change reflow");
NS_NOTYETIMPLEMENTED("frame change reflow"); }
} else if (PR_TRUE == reflow) {
else if (PR_TRUE == reflow) { StyleChangeReflow(aPresContext, frame, aAttribute);
StyleChangeReflow(aPresContext, frame, aAttribute); }
} else if (PR_TRUE == render) {
else if (PR_TRUE == render) { ApplyRenderingChangeToTree(aPresContext, frame);
ApplyRenderingChangeToTree(aPresContext, frame); }
} else { // let the frame deal with it, since we don't know how to
else { // let the frame deal with it, since we don't know how to frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint);
frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint); }
} }
} }
@ -2773,9 +2780,10 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2784,19 +2792,19 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
frame->GetStyleContext(sc); frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext); sc->RemapStyle(aPresContext);
NS_RELEASE(sc); NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames // XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
if (reframe) { if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow"); NS_NOTYETIMPLEMENTED("frame change reflow");
} }
else if (reflow) { else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull); StyleChangeReflow(aPresContext, frame, nsnull);
} }
else if (render) { else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame); ApplyRenderingChangeToTree(aPresContext, frame);
}
} }
NS_RELEASE(shell); NS_RELEASE(shell);

View File

@ -585,17 +585,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) && if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) &&
(nsnull != linkHandler)) { (nsnull != linkHandler)) {
nsAutoString base, href; // XXX base?? nsAutoString base, href;
nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href); nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href);
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) { if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURL* docURL = nsnull; nsIURL* docURL = nsnull;
nsIDocument* doc = nsnull; htmlContent->GetBaseURL(docURL);
aContent->GetDocument(doc);
if (nsnull != doc) {
docURL = doc->GetDocumentURL();
NS_RELEASE(doc);
}
nsAutoString absURLSpec; nsAutoString absURLSpec;
nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec); nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);
@ -835,6 +830,16 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute,
return result; return result;
} }
#ifdef NS_DEBUG
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
nsrefcnt count = ptr->AddRef(); \
ptr->Release(); \
NS_ASSERTION(--count == cnt, msg); \
}
#else
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) {}
#endif
NS_IMETHODIMP NS_IMETHODIMP
HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes, HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
nsMapAttributesFunc aMapFunc, nsMapAttributesFunc aMapFunc,
@ -847,6 +852,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
if (nsnull == aAttributes) { if (nsnull == aAttributes) {
if (PR_TRUE == aCreate) { if (PR_TRUE == aCreate) {
if (nsnull != mRecycledAttrs) { if (nsnull != mRecycledAttrs) {
NS_ASSERT_REFCOUNT(mRecycledAttrs, 1, "attributes used elsewhere");
aSingleAttrs = mRecycledAttrs; aSingleAttrs = mRecycledAttrs;
mRecycledAttrs = nsnull; mRecycledAttrs = nsnull;
aSingleAttrs->SetMappingFunction(aMapFunc); aSingleAttrs->SetMappingFunction(aMapFunc);
@ -2712,9 +2718,10 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2729,18 +2736,18 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
NS_IF_RELEASE(parentContext); NS_IF_RELEASE(parentContext);
NS_RELEASE(frameContext); NS_RELEASE(frameContext);
} }
} if (PR_TRUE == reframe) {
if (PR_TRUE == reframe) { NS_NOTYETIMPLEMENTED("frame change reflow");
NS_NOTYETIMPLEMENTED("frame change reflow"); }
} else if (PR_TRUE == reflow) {
else if (PR_TRUE == reflow) { StyleChangeReflow(aPresContext, frame, aAttribute);
StyleChangeReflow(aPresContext, frame, aAttribute); }
} else if (PR_TRUE == render) {
else if (PR_TRUE == render) { ApplyRenderingChangeToTree(aPresContext, frame);
ApplyRenderingChangeToTree(aPresContext, frame); }
} else { // let the frame deal with it, since we don't know how to
else { // let the frame deal with it, since we don't know how to frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint);
frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint); }
} }
} }
@ -2773,9 +2780,10 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2784,19 +2792,19 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
frame->GetStyleContext(sc); frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext); sc->RemapStyle(aPresContext);
NS_RELEASE(sc); NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames // XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
if (reframe) { if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow"); NS_NOTYETIMPLEMENTED("frame change reflow");
} }
else if (reflow) { else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull); StyleChangeReflow(aPresContext, frame, nsnull);
} }
else if (render) { else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame); ApplyRenderingChangeToTree(aPresContext, frame);
}
} }
NS_RELEASE(shell); NS_RELEASE(shell);

View File

@ -585,17 +585,12 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) && if ((NS_OK == aPresContext->GetLinkHandler(&linkHandler)) &&
(nsnull != linkHandler)) { (nsnull != linkHandler)) {
nsAutoString base, href; // XXX base?? nsAutoString base, href;
nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href); nsresult attrState = htmlContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::href, href);
if (NS_CONTENT_ATTR_HAS_VALUE == attrState) { if (NS_CONTENT_ATTR_HAS_VALUE == attrState) {
nsIURL* docURL = nsnull; nsIURL* docURL = nsnull;
nsIDocument* doc = nsnull; htmlContent->GetBaseURL(docURL);
aContent->GetDocument(doc);
if (nsnull != doc) {
docURL = doc->GetDocumentURL();
NS_RELEASE(doc);
}
nsAutoString absURLSpec; nsAutoString absURLSpec;
nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec); nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec);
@ -835,6 +830,16 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetAttributeFor(nsIAtom* aAttribute,
return result; return result;
} }
#ifdef NS_DEBUG
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) { \
nsrefcnt count = ptr->AddRef(); \
ptr->Release(); \
NS_ASSERTION(--count == cnt, msg); \
}
#else
#define NS_ASSERT_REFCOUNT(ptr,cnt,msg) {}
#endif
NS_IMETHODIMP NS_IMETHODIMP
HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes, HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
nsMapAttributesFunc aMapFunc, nsMapAttributesFunc aMapFunc,
@ -847,6 +852,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
if (nsnull == aAttributes) { if (nsnull == aAttributes) {
if (PR_TRUE == aCreate) { if (PR_TRUE == aCreate) {
if (nsnull != mRecycledAttrs) { if (nsnull != mRecycledAttrs) {
NS_ASSERT_REFCOUNT(mRecycledAttrs, 1, "attributes used elsewhere");
aSingleAttrs = mRecycledAttrs; aSingleAttrs = mRecycledAttrs;
mRecycledAttrs = nsnull; mRecycledAttrs = nsnull;
aSingleAttrs->SetMappingFunction(aMapFunc); aSingleAttrs->SetMappingFunction(aMapFunc);
@ -2712,9 +2718,10 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2729,18 +2736,18 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
NS_IF_RELEASE(parentContext); NS_IF_RELEASE(parentContext);
NS_RELEASE(frameContext); NS_RELEASE(frameContext);
} }
} if (PR_TRUE == reframe) {
if (PR_TRUE == reframe) { NS_NOTYETIMPLEMENTED("frame change reflow");
NS_NOTYETIMPLEMENTED("frame change reflow"); }
} else if (PR_TRUE == reflow) {
else if (PR_TRUE == reflow) { StyleChangeReflow(aPresContext, frame, aAttribute);
StyleChangeReflow(aPresContext, frame, aAttribute); }
} else if (PR_TRUE == render) {
else if (PR_TRUE == render) { ApplyRenderingChangeToTree(aPresContext, frame);
ApplyRenderingChangeToTree(aPresContext, frame); }
} else { // let the frame deal with it, since we don't know how to
else { // let the frame deal with it, since we don't know how to frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint);
frame->AttributeChanged(aPresContext, aContent, aAttribute, aHint); }
} }
} }
@ -2773,9 +2780,10 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
case NS_STYLE_HINT_VISUAL: case NS_STYLE_HINT_VISUAL:
render = PR_TRUE; render = PR_TRUE;
case NS_STYLE_HINT_CONTENT: case NS_STYLE_HINT_CONTENT:
case NS_STYLE_HINT_AURAL:
restyle = PR_TRUE; restyle = PR_TRUE;
break; break;
case NS_STYLE_HINT_AURAL: case NS_STYLE_HINT_NONE:
break; break;
} }
@ -2784,19 +2792,19 @@ HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
frame->GetStyleContext(sc); frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext); sc->RemapStyle(aPresContext);
NS_RELEASE(sc); NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames // XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame); frame->FirstChild(nsnull, frame);
if (reframe) { if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow"); NS_NOTYETIMPLEMENTED("frame change reflow");
} }
else if (reflow) { else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull); StyleChangeReflow(aPresContext, frame, nsnull);
} }
else if (render) { else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame); ApplyRenderingChangeToTree(aPresContext, frame);
}
} }
NS_RELEASE(shell); NS_RELEASE(shell);