From 31f87234c86a0cd9e0e8190e5544a7f1de958c38 Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Fri, 25 Sep 1998 01:49:10 +0000 Subject: [PATCH] performance tweaks to apply style change --- layout/generic/nsHTMLContainerFrame.cpp | 39 ++++++++++++++++--- layout/html/base/src/nsHTMLContainerFrame.cpp | 39 ++++++++++++++++--- 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/layout/generic/nsHTMLContainerFrame.cpp b/layout/generic/nsHTMLContainerFrame.cpp index 56b16efcf070..00223a7a54cc 100644 --- a/layout/generic/nsHTMLContainerFrame.cpp +++ b/layout/generic/nsHTMLContainerFrame.cpp @@ -493,23 +493,44 @@ nsHTMLContainerFrame::AttributeChanged(nsIPresShell* aShell, 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; - nsIStyleContext* oldSC; aFrame->GetGeometricParent(geometricParent); aFrame->GetContent(content); - aFrame->GetStyleContext(&aPresContext, oldSC); 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 @@ -522,9 +543,17 @@ nsHTMLContainerFrame::ApplyStyleChangeToTree(nsIPresContext& aPresContext, // Update the children too... nsIFrame* kid; aFrame->FirstChild(kid); - while (nsnull != kid) { - ApplyStyleChangeToTree(aPresContext, kid); - kid->GetNextSibling(kid); + if (onlyRemap) { + while (nsnull != kid) { + RemapStyleInTree(&aPresContext, kid); + kid->GetNextSibling(kid); + } + } + else { + while (nsnull != kid) { + ApplyStyleChangeToTree(aPresContext, kid); + kid->GetNextSibling(kid); + } } } } diff --git a/layout/html/base/src/nsHTMLContainerFrame.cpp b/layout/html/base/src/nsHTMLContainerFrame.cpp index 56b16efcf070..00223a7a54cc 100644 --- a/layout/html/base/src/nsHTMLContainerFrame.cpp +++ b/layout/html/base/src/nsHTMLContainerFrame.cpp @@ -493,23 +493,44 @@ nsHTMLContainerFrame::AttributeChanged(nsIPresShell* aShell, 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; - nsIStyleContext* oldSC; aFrame->GetGeometricParent(geometricParent); aFrame->GetContent(content); - aFrame->GetStyleContext(&aPresContext, oldSC); 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 @@ -522,9 +543,17 @@ nsHTMLContainerFrame::ApplyStyleChangeToTree(nsIPresContext& aPresContext, // Update the children too... nsIFrame* kid; aFrame->FirstChild(kid); - while (nsnull != kid) { - ApplyStyleChangeToTree(aPresContext, kid); - kid->GetNextSibling(kid); + if (onlyRemap) { + while (nsnull != kid) { + RemapStyleInTree(&aPresContext, kid); + kid->GetNextSibling(kid); + } + } + else { + while (nsnull != kid) { + ApplyStyleChangeToTree(aPresContext, kid); + kid->GetNextSibling(kid); + } } } }