Bug 804970, patch 5: Handle dynamic changes to the basis for 'rem' units by rebuilding all style data. r=bzbarsky

This commit is contained in:
L. David Baron 2012-10-26 19:04:20 +02:00
parent bd2ade79c8
commit c0bec06ffc
4 changed files with 32 additions and 1 deletions

View File

@ -8307,6 +8307,25 @@ nsCSSFrameConstructor::RestyleElement(Element *aElement,
NS_ASSERTION(!aPrimaryFrame || aPrimaryFrame->GetContent() == aElement,
"frame/content mismatch");
// If we're restyling the root element and there are 'rem' units in
// use, handle dynamic changes to the definition of a 'rem' here.
if (GetPresContext()->UsesRootEMUnits() && aPrimaryFrame) {
nsStyleContext *oldContext = aPrimaryFrame->GetStyleContext();
if (!oldContext->GetParent()) { // check that we're the root element
nsRefPtr<nsStyleContext> newContext = mPresShell->StyleSet()->
ResolveStyleFor(aElement, nullptr /* == oldContext->GetParent() */);
if (oldContext->GetStyleFont()->mFont.size !=
newContext->GetStyleFont()->mFont.size) {
// The basis for 'rem' units has changed.
DoRebuildAllStyleData(aRestyleTracker, nsChangeHint(0));
if (aMinHint == 0) {
return;
}
aPrimaryFrame = aElement->GetPrimaryFrame();
}
}
}
if (aMinHint & nsChangeHint_ReconstructFrame) {
RecreateFramesForContent(aElement, false);
} else if (aPrimaryFrame) {

View File

@ -1661,6 +1661,7 @@ nsPresContext::RebuildAllStyleData(nsChangeHint aExtraHint)
return;
}
mUsesRootEMUnits = false;
mUsesViewportUnits = false;
RebuildUserFontSet();
AnimationManager()->KeyframesListIsDirty();

View File

@ -953,6 +953,14 @@ public:
mIsGlyph = aValue;
}
bool UsesRootEMUnits() const {
return mUsesRootEMUnits;
}
void SetUsesRootEMUnits(bool aValue) {
mUsesRootEMUnits = aValue;
}
bool UsesViewportUnits() const {
return mUsesViewportUnits;
}
@ -1216,7 +1224,9 @@ protected:
// Are we currently drawing an SVG glyph?
unsigned mIsGlyph : 1;
// Does the associated document use viewport units?
// Does the associated document use root-em (rem) units?
unsigned mUsesRootEMUnits : 1;
// Does the associated document use viewport units (vw/vh/vmin/vmax)?
unsigned mUsesViewportUnits : 1;
// Has there been a change to the viewport's dimensions?

View File

@ -322,6 +322,7 @@ static nscoord CalcLengthWith(const nsCSSValue& aValue,
}
switch (aValue.GetUnit()) {
case eCSSUnit_RootEM: {
aPresContext->SetUsesRootEMUnits(true);
nscoord rootFontSize;
if (aUseProvidedRootEmSize) {