aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext, &undisplayedContext);
nsIContent *theContent = undisplayed->mContent; if (theContent->IsContentOfType(nsIContent::eHTML)) {  aPresContext->ResolveStyleContextFor(theContent, newContext, &undisplayedContext); } else {  aPresContext->ResolveStyleContextFor(theContent, newContext, &undisplayedContext); }
FrameManager::ReResolveStyleContext(nsIPresContext* aPresContext,                                    nsIFrame* aFrame,                                    nsIContent* aParentContent,                                    PRInt32 aAttrNameSpaceID,                                    nsIAtom* aAttribute,                                    nsStyleChangeList& aChangeList,                                     PRInt32 aMinChange,                                    PRInt32& aResultChange){  // XXXldb get new context from prev-in-flow if possible, to avoid  // duplication.  (Or should we just let |GetContext| handle that?)  // Getting the hint would be nice too, but that's harder.  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;    }    if (aParentContent && aAttribute) { // attribute came from parent, we don't care about it here when recursing      nsFrameState  frameState;      aFrame->GetFrameState(&frameState);      if (0 == (frameState & NS_FRAME_GENERATED_CONTENT)) { // keep it for generated content        aAttribute = nsnull;      }    }    nsCOMPtr<nsIStyleContext> parentContext;     nsIFrame* resolvedChild = nsnull;    // Get the frame providing the parent style context.  If it is a    // child, then resolve the provider first.    nsIFrame* providerFrame = nsnull;    PRBool providerIsChild = PR_FALSE;    aFrame->GetParentStyleContextFrame(aPresContext,                                       &providerFrame, &providerIsChild);     if (!providerIsChild) {      if (providerFrame)        providerFrame->GetStyleContext(getter_AddRefs(parentContext));      }    else {      // resolve the provider here (before aFrame below)      ReResolveStyleContext(aPresContext, providerFrame, content,                             aAttrNameSpaceID, aAttribute, aChangeList,                            aMinChange, aResultChange);      // The provider's new context becomes the parent context of      // aFrame's context.      providerFrame->GetStyleContext(getter_AddRefs(parentContext));       // Set |resolvedChild| so we don't bother resolving the      // provider again.      resolvedChild = providerFrame;    }        // do primary context    nsIStyleContext* newContext = nsnull;    if (pseudoTag == nsHTMLAtoms::mozNonElementPseudo) {      NS_ASSERTION(localContent,                   "non pseudo-element frame without content node");      aPresContext->ResolveStyleContextForNonElement(parentContext,                                                     &newContext);    }    else if (pseudoTag) {      nsIContent* pseudoContent =          aParentContent ? aParentContent : localContent;      aPresContext->ResolvePseudoStyleContextFor(pseudoContent, pseudoTag,                                                 parentContext,                                                  &newContext);      NS_RELEASE(pseudoTag);    }    else {      NS_ASSERTION(localContent,                   "non pseudo-element frame without content node");      aPresContext->ResolveStyleContextFor(content, parentContext,                                           &newContext);    }    NS_ASSERTION(newContext, "failed to get new style context");    if (newContext) {      if (!parentContext) {        nsRuleNode *oldNode, *newNode;        oldContext->GetRuleNode(&oldNode);        newContext->GetRuleNode(&newNode);        if (oldNode == newNode) {          // We're the root of the style context tree and the new style          // context returned has the same rule node.  This means that          // we can use FindChildWithRules to keep a lot of the old          // style contexts around.  However, we need to start from the          // same root.          NS_RELEASE(newContext);          newContext = oldContext;          NS_ADDREF(newContext);        }      }      if (newContext != oldContext) {        aMinChange = CaptureChange(oldContext, newContext, aFrame, content, aChangeList, aMinChange);        if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) { // if frame gets regenerated, let it keep old context          aFrame->SetStyleContext(aPresContext, newContext);        }        // if old context had image and new context does not have the same image,         // stop the image load for the frame        const nsStyleBackground* oldColor = (const nsStyleBackground*)oldContext->GetStyleData(eStyleStruct_Background);         const nsStyleBackground* newColor = (const nsStyleBackground*)newContext->GetStyleData(eStyleStruct_Background);        if(oldColor->mBackgroundImage.Length() > 0 &&          oldColor->mBackgroundImage != newColor->mBackgroundImage ){          // stop the image loading for the frame, the image has changed          aPresContext->StopImagesFor(aFrame);        }      }      else {        // XXXdwh figure this out.        // oldContext->RemapStyle(aPresContext, PR_FALSE);        if (pseudoTag && pseudoTag != nsHTMLAtoms::mozNonElementPseudo &&            aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&            HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {          aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);        }      }      NS_RELEASE(oldContext);    }    else {      NS_ERROR("resolve style context failed");      newContext = oldContext;  // new context failed, recover... (take ref)      oldContext = nsnull;    }    // 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 &&                       pseudoTag != nsHTMLAtoms::mozNonElementPseudo,                       "extra style context is not pseudo element");          result = aPresContext->ResolvePseudoStyleContextFor(content, pseudoTag, newContext,                                                              &newExtraContext);          NS_RELEASE(pseudoTag);          if (NS_SUCCEEDED(result) && newExtraContext) {            if (oldExtraContext != newExtraContext) {              aMinChange = CaptureChange(oldExtraContext, newExtraContext, aFrame,                                          content, aChangeList, aMinChange);              if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) {                aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);              }            }            else {              // XXXdwh figure this out.              // oldExtraContext->RemapStyle(aPresContext, PR_FALSE);              // XXXldb |oldContext| is null by this point, so this will              // never do anything.              if (pseudoTag && pseudoTag != nsHTMLAtoms::mozNonElementPseudo &&                  aAttribute && (aMinChange < NS_STYLE_HINT_REFLOW) &&                  HasAttributeContent(oldContext, aAttrNameSpaceID, aAttribute)) {                aChangeList.AppendChange(aFrame, content, NS_STYLE_HINT_REFLOW);              }            }            NS_RELEASE(newExtraContext);          }          NS_RELEASE(oldExtraContext);        }      }      else {        break;      }    }    // now look for undisplayed child content and pseudos    if (localContent && mUndisplayedMap) {      UndisplayedNode* undisplayed = mUndisplayedMap->GetFirstNode(localContent);      while (undisplayed) {        nsIStyleContext* undisplayedContext = nsnull;        undisplayed->mStyle->GetPseudoType(pseudoTag);        if (undisplayed->mContent && pseudoTag == nsnull) {  // child content          aPresContext->ResolveStyleContextFor(undisplayed->mContent, newContext,                                                &undisplayedContext);        }        else if (pseudoTag == nsHTMLAtoms::mozNonElementPseudo) {          aPresContext->ResolveStyleContextForNonElement(newContext,                                                          &undisplayedContext);        }        else {  // pseudo element          NS_ASSERTION(pseudoTag, "pseudo element without tag");          aPresContext->ResolvePseudoStyleContextFor(localContent, pseudoTag,                                                     newContext,                                                     &undisplayedContext);        }        NS_IF_RELEASE(pseudoTag);        if (undisplayedContext) {          if (undisplayedContext == undisplayed->mStyle) {            // XXXdwh figure this out.            // 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);          } else {            // update the undisplayed node with the new context            NS_RELEASE(undisplayed->mStyle);            undisplayed->mStyle = undisplayedContext;          }        }        undisplayed = undisplayed->mNext;      }    }    aResultChange = aMinChange;    if (aMinChange < NS_STYLE_HINT_FRAMECHANGE) {      // There is no need to waste time crawling into a frame's children on a frame change.      // The act of reconstructing frames will force new style contexts to be resolved on all      // of this frame's descendants anyway, so we want to avoid wasting time processing      // style contexts that we're just going to throw away anyway. - dwh      // now do children      PRInt32 listIndex = 0;      nsIAtom* childList = nsnull;      PRInt32 childChange;      do {        nsIFrame* child = nsnull;        result = aFrame->FirstChild(aPresContext, childList, &child);        while (NS_SUCCEEDED(result) && child) {          nsFrameState  state;          child->GetFrameState(&state);          if (!(state & NS_FRAME_OUT_OF_FLOW)) {            // only do frames that are in flow            nsCOMPtr<nsIAtom> frameType;            child->GetFrameType(getter_AddRefs(frameType));            if (nsLayoutAtoms::placeholderFrame == frameType) { // placeholder              // get out of flow frame and recur there              nsIFrame* outOfFlowFrame =                NS_STATIC_CAST(nsPlaceholderFrame*,child)->GetOutOfFlowFrame();              NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");              NS_ASSERTION(outOfFlowFrame != resolvedChild,                           "out-of-flow frame not a true descendant");              // |nsFrame::GetParentStyleContextFrame| checks being out              // of flow so that this works correctly.              ReResolveStyleContext(aPresContext, outOfFlowFrame, content,                                    aAttrNameSpaceID, aAttribute,                                    aChangeList, aMinChange, childChange);              // reresolve placeholder's context under the same parent              // as the out-of-flow frame              ReResolveStyleContext(aPresContext, child, content,                                    kNameSpaceID_Unknown, nsnull,                                    aChangeList, aMinChange, childChange);            }            else {  // regular child frame              if (child != resolvedChild) {                ReResolveStyleContext(aPresContext, child, content,                                      aAttrNameSpaceID, aAttribute,                                      aChangeList, aMinChange, childChange);              } else {                NOISY_TRACE_FRAME("child frame already resolved as descendent, skipping",aFrame);              }            }          }          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);  }}