moved attribute change code to style sheete

cleaned up content change api
This commit is contained in:
peterl@netscape.com
1998-09-29 23:48:07 +00:00
parent df00bc2652
commit d09a2186f8
21 changed files with 82 additions and 480 deletions

View File

@@ -412,141 +412,4 @@ nsHTMLContainerFrame::CreateViewForFrame(nsIPresContext& aPresContext,
return NS_OK;
}
NS_IMETHODIMP
nsHTMLContainerFrame::AttributeChanged(nsIPresShell* aShell,
nsIPresContext* aPresContext,
nsIContent* aChild,
nsIAtom* aAttribute)
{
if (nsHTMLAtoms::style == aAttribute) {
ApplyStyleChangeToTree(*aPresContext, this);
StyleChangeReflow(*aPresContext, this);
}
return NS_OK;
}
static void
RemapStyleInTree(nsIPresContext* aPresContext,
nsIFrame* aFrame)
{
nsIStyleContext* sc;
aFrame->GetStyleContext(nsnull, sc);
if (nsnull != sc) {
sc->RemapStyle(aPresContext);
// Update the children too...
nsIFrame* kid;
aFrame->FirstChild(kid);
while (nsnull != kid) {
RemapStyleInTree(aPresContext, kid);
kid->GetNextSibling(kid);
}
}
}
void
nsHTMLContainerFrame::ApplyStyleChangeToTree(nsIPresContext& aPresContext,
nsIFrame* aFrame)
{
nsIContent* content;
nsIFrame* geometricParent;
aFrame->GetGeometricParent(geometricParent);
aFrame->GetContent(content);
if (nsnull != content) {
PRBool onlyRemap = PR_FALSE;
nsIStyleContext* oldSC;
aFrame->GetStyleContext(nsnull, oldSC);
nsIStyleContext* newSC =
aPresContext.ResolveStyleContextFor(content, geometricParent);
if (newSC == oldSC) {
// Force cached style data to be recomputed
newSC->RemapStyle(&aPresContext);
onlyRemap = PR_TRUE;
}
else {
// Switch to new style context
aFrame->SetStyleContext(&aPresContext, newSC);
}
NS_IF_RELEASE(oldSC);
NS_RELEASE(newSC);
NS_RELEASE(content);
// Update the children too...
nsIFrame* kid;
aFrame->FirstChild(kid);
if (onlyRemap) {
while (nsnull != kid) {
RemapStyleInTree(&aPresContext, kid);
kid->GetNextSibling(kid);
}
}
else {
while (nsnull != kid) {
ApplyStyleChangeToTree(aPresContext, kid);
kid->GetNextSibling(kid);
}
}
}
}
void
nsHTMLContainerFrame::ApplyRenderingChangeToTree(nsIPresContext& aPresContext,
nsIFrame* aFrame)
{
nsIViewManager* viewManager = nsnull;
// Trigger rendering updates by damaging this frame and any
// continuations of this frame.
while (nsnull != aFrame) {
// Get the frame's bounding rect
nsRect r;
aFrame->GetRect(r);
r.x = 0;
r.y = 0;
// Get view if this frame has one and trigger an update. If the
// frame doesn't have a view, find the nearest containing view
// (adjusting r's coordinate system to reflect the nesting) and
// update there.
nsIView* view;
aFrame->GetView(view);
if (nsnull != view) {
} else {
nsPoint offset;
aFrame->GetOffsetFromView(offset, view);
NS_ASSERTION(nsnull != view, "no view");
r += offset;
}
if (nsnull == viewManager) {
view->GetViewManager(viewManager);
}
viewManager->UpdateView(view, r, NS_VMREFRESH_NO_SYNC);
aFrame->GetNextInFlow(aFrame);
}
if (nsnull != viewManager) {
viewManager->Composite();
NS_RELEASE(viewManager);
}
}
void
nsHTMLContainerFrame::StyleChangeReflow(nsIPresContext& aPresContext,
nsIFrame* aFrame)
{
nsIPresShell* shell;
shell = aPresContext.GetShell();
nsIReflowCommand* reflowCmd;
nsresult rv = NS_NewHTMLReflowCommand(&reflowCmd, aFrame,
nsIReflowCommand::StyleChanged);
if (NS_SUCCEEDED(rv)) {
shell->AppendReflowCommand(reflowCmd);
NS_RELEASE(reflowCmd);
}
NS_RELEASE(shell);
}