nsIStyleContext* oldContext = nsnull; aFrame->GetStyleContext(&oldContext);
nsStyleContext* oldContext = aFrame->GetStyleContext();
FrameManager::ReParentStyleContext(nsIPresContext* aPresContext,                                   nsIFrame* aFrame,                                    nsIStyleContext* aNewParentContext){  NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);  nsresult result = NS_ERROR_NULL_POINTER;  if (aFrame) {#ifdef NS_DEBUG    DebugVerifyStyleTree(aPresContext, aFrame);#endif    nsIStyleContext* oldContext = nsnull;    aFrame->GetStyleContext(&oldContext);    if (oldContext) {      nsIStyleContext* newContext = nsnull;      result = mStyleSet->ReParentStyleContext(aPresContext,                                                oldContext, aNewParentContext,                                               &newContext);      if (NS_SUCCEEDED(result) && newContext) {        if (newContext != oldContext) {          PRInt32 listIndex = 0;          nsIAtom* childList = nsnull;          nsIFrame* child;          nsIAtom*  frameType;          do {            child = nsnull;            result = aFrame->FirstChild(aPresContext, 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");                  result = ReParentStyleContext(aPresContext, outOfFlowFrame, newContext);                  // reparent placeholder's context under out of flow frame                  nsIStyleContext*  outOfFlowContext;                  outOfFlowFrame->GetStyleContext(&outOfFlowContext);                  ReParentStyleContext(aPresContext, child, outOfFlowContext);                  NS_RELEASE(outOfFlowContext);                }                else { // regular frame                  result = ReParentStyleContext(aPresContext, child, newContext);                }                NS_IF_RELEASE(frameType);              }              child->GetNextSibling(&child);            }            NS_IF_RELEASE(childList);            aFrame->GetAdditionalChildListName(listIndex++, &childList);          } while (childList);                    aFrame->SetStyleContext(aPresContext, newContext);          // 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;                result = mStyleSet->ReParentStyleContext(aPresContext,                                                         oldExtraContext, newContext,                                                         &newExtraContext);                if (NS_SUCCEEDED(result) && newExtraContext) {                  aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);                  NS_RELEASE(newExtraContext);                }                NS_RELEASE(oldExtraContext);              }            }            else {              result = NS_OK; // ok not to have extras (or run out)              break;            }          }#ifdef NS_DEBUG          VerifyStyleTree(aPresContext, aFrame, aNewParentContext);#endif        }        NS_RELEASE(newContext);      }      NS_RELEASE(oldContext);    }