aFrame->SetStyleContext(presContext, newContext);
FrameManager::ReParentStyleContext(nsIFrame* aFrame,                                    nsStyleContext* aNewParentContext){  NS_ENSURE_TRUE(mPresShell, NS_ERROR_NOT_AVAILABLE);  nsresult result = NS_ERROR_NULL_POINTER;  if (aFrame) {#ifdef NS_DEBUG    DebugVerifyStyleTree(aFrame);#endif    nsStyleContext* oldContext = aFrame->GetStyleContext();    if (oldContext) {      nsIPresContext *presContext = GetPresContext();      nsRefPtr<nsStyleContext> newContext;      result = NS_OK;      newContext = mStyleSet->ReParentStyleContext(presContext, oldContext,                                                   aNewParentContext);      if (newContext) {        if (newContext != oldContext) {          PRInt32 listIndex = 0;          nsIAtom* childList = nsnull;          nsIFrame* child;          do {            child = nsnull;            result = aFrame->FirstChild(presContext, childList, &child);            while ((NS_SUCCEEDED(result)) && child) {              if (NS_FRAME_OUT_OF_FLOW != (child->GetStateBits() & NS_FRAME_OUT_OF_FLOW)) {                // only do frames that are in flow                if (nsLayoutAtoms::placeholderFrame == child->GetType()) {                  // get out of flow frame and recurse there                  nsIFrame* outOfFlowFrame = ((nsPlaceholderFrame*)child)->GetOutOfFlowFrame();                  NS_ASSERTION(outOfFlowFrame, "no out-of-flow frame");                  result = ReParentStyleContext(outOfFlowFrame, newContext);                  // reparent placeholder's context under out of flow frame                  nsStyleContext* outOfFlowContext = outOfFlowFrame->GetStyleContext();                  ReParentStyleContext(child, outOfFlowContext);                }                else { // regular frame                  result = ReParentStyleContext(child, newContext);                }              }              child = child->GetNextSibling();            }            NS_IF_RELEASE(childList);            aFrame->GetAdditionalChildListName(listIndex++, &childList);          } while (childList);                    aFrame->SetStyleContext(presContext, newContext);          // do additional contexts           PRInt32 contextIndex = -1;          while (1) {            nsStyleContext* oldExtraContext = aFrame->GetAdditionalStyleContext(++contextIndex);            if (oldExtraContext) {              nsRefPtr<nsStyleContext> newExtraContext;              newExtraContext = mStyleSet->ReParentStyleContext(presContext,                                                                oldExtraContext,                                                                newContext);              if (newExtraContext) {                aFrame->SetAdditionalStyleContext(contextIndex, newExtraContext);              }            }            else {              result = NS_OK; // ok not to have extras (or run out)              break;            }          }#ifdef NS_DEBUG          VerifyStyleTree(GetPresContext(), aFrame, aNewParentContext);#endif        }      }    }  }  return result;}