} }   if (localContent) { UndisplayedNode* undisplayed = mUndisplayedMap->GetFirstNode(localContent); while (undisplayed) { nsIStyleContext* undisplayedContext = nsnull; if (undisplayed->mContent) { aPresContext.ResolveStyleContextFor(undisplayed->mContent, newContext, PR_FALSE, &undisplayedContext); } else { undisplayed->mStyle->GetPseudoType(pseudoTag); NS_ASSERTION(pseudoTag, "pseudo element without tag"); aPresContext.ResolvePseudoStyleContextFor(localContent, pseudoTag, newContext, PR_FALSE, &undisplayedContext); NS_RELEASE(pseudoTag); } if (undisplayedContext) { if (undisplayedContext == undisplayed->mStyle) { undisplayedContext->RemapStyle(&aPresContext); } const nsStyleDisplay* display = (const nsStyleDisplay*)undisplayedContext->GetStyleData(eStyleStruct_Display); if (display->mDisplay != NS_STYLE_DISPLAY_NONE) { aChangeList.AppendChange(nsnull, ((undisplayed->mContent) ? undisplayed->mContent : localContent), NS_STYLE_HINT_FRAMECHANGE); } NS_RELEASE(undisplayedContext); } undisplayed = undisplayed->mNext;
FrameManager::ReResolveStyleContext(nsIPresContext& aPresContext,                                    nsIFrame* aFrame,                                    nsIStyleContext* aParentContext,                                    nsIContent* aParentContent,                                    nsStyleChangeList& aChangeList,                                     PRInt32 aMinChange,                                    PRInt32& aResultChange){  nsIStyleContext* oldContext = nsnull;   nsresult result = aFrame->GetStyleContext(&oldContext);  if (NS_SUCCEEDED(result) && oldContext) {    nsIAtom* pseudoTag = nsnull;    oldContext->GetPseudoType(pseudoTag);    nsIContent* localContent = nsnull;    nsIContent* content = nsnull;    result = aFrame->GetContent(&localContent);    if (NS_SUCCEEDED(result) && localContent) {      content = localContent;    }    else {      content = aParentContent;    }    // do primary context    nsIStyleContext* newContext = nsnull;    if (pseudoTag) {      aPresContext.ResolvePseudoStyleContextFor(content, pseudoTag, aParentContext, PR_FALSE,                                                &newContext);      NS_RELEASE(pseudoTag);    }    else {      NS_ASSERTION(localContent, "non pseudo-element frame without content node");      aPresContext.ResolveStyleContextFor(content, aParentContext, PR_FALSE, &newContext);    }    NS_ASSERTION(newContext, "failed to get new style context");    if (newContext) {      if (newContext != oldContext) {        aMinChange = CaptureChange(oldContext, newContext, aFrame, aChangeList, aMinChange);        if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) { // if frame gets regenerated, let it keep old context          aFrame->SetStyleContext(&aPresContext, newContext);        }      }      else {        oldContext->RemapStyle(&aPresContext, PR_FALSE);      }      NS_RELEASE(oldContext);    }    else {      NS_ERROR("resolve style context failed");      newContext = oldContext;  // new context failed, recover... (take ref)    }    // do additional contexts     PRInt32 contextIndex = -1;    while (1 == 1) {      nsIStyleContext* oldExtraContext = nsnull;      result = aFrame->GetAdditionalStyleContext(++contextIndex, &oldExtraContext);      if (NS_SUCCEEDED(result)) {        if (oldExtraContext) {          nsIStyleContext* newExtraContext = nsnull;          oldExtraContext->GetPseudoType(pseudoTag);          NS_ASSERTION(pseudoTag, "extra style context is not pseudo element");          result = aPresContext.ResolvePseudoStyleContextFor(content, pseudoTag, newContext,                                                             PR_FALSE, &newExtraContext);          NS_RELEASE(pseudoTag);          if (NS_SUCCEEDED(result) && newExtraContext) {            if (oldExtraContext != newExtraContext) {              aMinChange = CaptureChange(oldExtraContext, newExtraContext, aFrame,                                          aChangeList, aMinChange);              if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) {                aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);              }            }            NS_RELEASE(newExtraContext);          }          NS_RELEASE(oldExtraContext);        }      }      else {        break;      }    }    aResultChange = aMinChange;    // now do children    PRInt32 listIndex = 0;    nsIAtom* childList = nsnull;    PRInt32 childChange;    nsIFrame* child;    nsIAtom* frameType = nsnull;    do {      child = nsnull;      result = aFrame->FirstChild(childList, &child);      while ((NS_SUCCEEDED(result)) && (child)) {        nsFrameState  state;        child->GetFrameState(&state);        if (NS_FRAME_OUT_OF_FLOW != (state & NS_FRAME_OUT_OF_FLOW)) {          // only do frames that are in flow          child->GetFrameType(&frameType);          if (nsLayoutAtoms::placeholderFrame == frameType) { // placeholder            // get out of flow frame and recurse there            nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();            NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");            ReResolveStyleContext(aPresContext, outOfFlowFrame, newContext, content,                                  aChangeList, aMinChange, childChange);            // reresolve placeholder's context under out of flow frame            nsIStyleContext*  outOfFlowContext;            outOfFlowFrame->GetStyleContext(&outOfFlowContext);            ReResolveStyleContext(aPresContext, child, outOfFlowContext, content,                                  aChangeList, aMinChange, childChange);            NS_RELEASE(outOfFlowContext);          }          else {  // regular child frame            ReResolveStyleContext(aPresContext, child, newContext, content,                                  aChangeList, aMinChange, childChange);          }        }        child->GetNextSibling(&child);      }      NS_IF_RELEASE(childList);      aFrame->GetAdditionalChildListName(listIndex++, &childList);    } while (childList);    // XXX need to do overflow frames???    NS_RELEASE(newContext);    NS_IF_RELEASE(localContent);  }}