PRINTF("Unique SC Data - Not Shared :(\n");
StyleContextImpl::RemapStyle(nsIPresContext* aPresContext, PRBool aRecurse){  mDataCode = -1;  if (NS_FAILED(EnsureStyleData(aPresContext))) {    return NS_ERROR_UNEXPECTED;  }  if (nsnull != mParent) {    GETSCDATA(Font).ResetFrom(&(mParent->GETSCDATA(Font)), aPresContext);    GETSCDATA(Color).ResetFrom(&(mParent->GETSCDATA(Color)), aPresContext);    GETSCDATA(Spacing).ResetFrom(&(mParent->GETSCDATA(Spacing)), aPresContext);    GETSCDATA(List).ResetFrom(&(mParent->GETSCDATA(List)), aPresContext);    GETSCDATA(Position).ResetFrom(&(mParent->GETSCDATA(Position)), aPresContext);    GETSCDATA(Text).ResetFrom(&(mParent->GETSCDATA(Text)), aPresContext);    GETSCDATA(Display).ResetFrom(&(mParent->GETSCDATA(Display)), aPresContext);    GETSCDATA(Table).ResetFrom(&(mParent->GETSCDATA(Table)), aPresContext);    GETSCDATA(Content).ResetFrom(&(mParent->GETSCDATA(Content)), aPresContext);    GETSCDATA(UserInterface).ResetFrom(&(mParent->GETSCDATA(UserInterface)), aPresContext);    GETSCDATA(Print).ResetFrom(&(mParent->GETSCDATA(Print)), aPresContext);  }  else {    GETSCDATA(Font).ResetFrom(nsnull, aPresContext);    GETSCDATA(Color).ResetFrom(nsnull, aPresContext);    GETSCDATA(Spacing).ResetFrom(nsnull, aPresContext);    GETSCDATA(List).ResetFrom(nsnull, aPresContext);    GETSCDATA(Position).ResetFrom(nsnull, aPresContext);    GETSCDATA(Text).ResetFrom(nsnull, aPresContext);    GETSCDATA(Display).ResetFrom(nsnull, aPresContext);    GETSCDATA(Table).ResetFrom(nsnull, aPresContext);    GETSCDATA(Content).ResetFrom(nsnull, aPresContext);    GETSCDATA(UserInterface).ResetFrom(nsnull, aPresContext);    GETSCDATA(Print).ResetFrom(nsnull, aPresContext);  }  PRUint32 cnt = 0;  if (mRules) {    nsresult rv = mRules->Count(&cnt);    NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");  }  if (0 < cnt) {    MapStyleData  data(this, aPresContext);    mRules->EnumerateForwards(MapStyleRuleFont, &data);    if (GETSCDATA(Font).mFlags & NS_STYLE_FONT_USE_FIXED) {      GETSCDATA(Font).mFont = GETSCDATA(Font).mFixedFont;    }    mRules->EnumerateForwards(MapStyleRule, &data);  }  if (-1 == mDataCode) {    mDataCode = 0;  }  // CSS2 specified fixups:  //  - these must be done after all declarations are mapped since they can cross style-structs  // 1) if float is not none, and display is not none, then we must set display to block  //    XXX - there are problems with following the spec here: what we will do instead of  //          following the letter of the spec is to make sure that floated elements are  //          some kind of block, not strictly 'block' - see EnsureBlockDisplay method  nsStyleDisplay *disp = (nsStyleDisplay *)GetMutableStyleData(eStyleStruct_Display);  if (disp) {    if (disp->mDisplay != NS_STYLE_DISPLAY_NONE &&        disp->mFloats != NS_STYLE_FLOAT_NONE ) {      EnsureBlockDisplay(disp->mDisplay);    }  }  // 2) if position is 'absolute' or 'fixed' then display must be 'block and float must be 'none'  //    XXX - see note for fixup 1) above...  nsStylePosition *pos = (nsStylePosition *)GetStyleData(eStyleStruct_Position);  if (pos) {    if (pos->IsAbsolutelyPositioned()) {      if (disp) {        if(disp->mDisplay != NS_STYLE_DISPLAY_NONE) {          EnsureBlockDisplay(disp->mDisplay);          disp->mFloats = NS_STYLE_FLOAT_NONE;        }      }    }  }  nsCompatibility quirkMode = eCompatibility_Standard;  aPresContext->GetCompatibilityMode(&quirkMode);  if (eCompatibility_NavQuirks == quirkMode) {    if (((GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) ||          (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE_CAPTION)) &&        (nsnull == mPseudoTag)) {      StyleContextImpl* holdParent = mParent;      mParent = nsnull; // cut off all inheritance. this really blows      // XXX the style we do preserve is visibility, direction, language      PRUint8 visible = GETSCDATA(Display).mVisible;      PRUint8 direction = GETSCDATA(Display).mDirection;      nsCOMPtr<nsILanguageAtom> language = GETSCDATA(Display).mLanguage;      // time to emulate a sub-document      // This is ugly, but we need to map style once to determine display type      // then reset and map it again so that all local style is preserved      if (GETSCDATA(Display).mDisplay != NS_STYLE_DISPLAY_TABLE) {        GETSCDATA(Font).ResetFrom(nsnull, aPresContext);      }      GETSCDATA(Color).ResetFrom(nsnull, aPresContext);      GETSCDATA(Spacing).ResetFrom(nsnull, aPresContext);      GETSCDATA(List).ResetFrom(nsnull, aPresContext);      GETSCDATA(Text).ResetFrom(nsnull, aPresContext);      GETSCDATA(Position).ResetFrom(nsnull, aPresContext);      GETSCDATA(Display).ResetFrom(nsnull, aPresContext);      GETSCDATA(Table).ResetFrom(nsnull, aPresContext);      GETSCDATA(Content).ResetFrom(nsnull, aPresContext);      GETSCDATA(UserInterface).ResetFrom(nsnull, aPresContext);      GETSCDATA(Print).ResetFrom(nsnull, aPresContext);      GETSCDATA(Display).mVisible = visible;      GETSCDATA(Display).mDirection = direction;      GETSCDATA(Display).mLanguage = language;      PRUint32 numRules = 0;      if (mRules) {        nsresult rv = mRules->Count(&numRules);        NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");      }      if (0 < numRules) {        MapStyleData  data(this, aPresContext);        mRules->EnumerateForwards(MapStyleRuleFont, &data);        if (GETSCDATA(Font).mFlags & NS_STYLE_FONT_USE_FIXED) {          GETSCDATA(Font).mFont = GETSCDATA(Font).mFixedFont;        }        mRules->EnumerateForwards(MapStyleRule, &data);      }      // reset all font data for tables again      if (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) {        // get the font-name to reset: this property we preserve        nsAutoString strName(GETSCDATA(Font).mFont.name);        nsAutoString strMixedName(GETSCDATA(Font).mFixedFont.name);           GETSCDATA(Font).ResetFrom(nsnull, aPresContext);           // now reset the font names back to original        GETSCDATA(Font).mFont.name = strName;        GETSCDATA(Font).mFixedFont.name = strMixedName;      }      mParent = holdParent;    }  } else {    // In strict mode, we still have to support one "quirky" thing    // for tables.  HTML's alignment attributes have always worked    // so they don't inherit into tables, but instead align the    // tables.  We should keep doing this, because HTML alignment    // is just weird, and we shouldn't force it to match CSS.    if (GETSCDATA(Display).mDisplay == NS_STYLE_DISPLAY_TABLE) {      // -moz-center and -moz-right are used for HTML's alignment      if ((GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) ||          (GETSCDATA(Text).mTextAlign == NS_STYLE_TEXT_ALIGN_MOZ_RIGHT))      {        GETSCDATA(Text).mTextAlign = NS_STYLE_TEXT_ALIGN_DEFAULT;      }    }  }  RecalcAutomaticData(aPresContext);#ifdef SHARE_STYLECONTEXTS  static PRBool bEnableSharing = PR_FALSE;     // set to FALSE in debugger to turn off sharing of sc data  if (bEnableSharing) {    // set the CRC    mStyleData->SetCRC32();    NS_ASSERTION(mStyleSet, "Expected to have a style set ref...");    nsIStyleContext *matchingSC = nsnull;    // check if there is a matching context...    if ((NS_SUCCEEDED(mStyleSet->FindMatchingContext(this, &matchingSC))) &&         (nsnull != matchingSC)) {      ShareStyleDataFrom(matchingSC);#ifdef NOISY_DEBUG      printf("SC Data Shared :)\n");#endif      NS_IF_RELEASE(matchingSC);    } else {#ifdef NOISY_DEBUG      printf("Unique SC Data - Not Shared :(\n");#endif    }  } // if(bDisableSharing==false)#endif  if (aRecurse) {    if (nsnull != mChild) {      StyleContextImpl* child = mChild;      do {        child->RemapStyle(aPresContext);        child = child->mNextSibling;      } while (mChild != child);    }    if (nsnull != mEmptyChild) {      StyleContextImpl* child = mEmptyChild;      do {        child->RemapStyle(aPresContext);        child = child->mNextSibling;      } while (mEmptyChild != child);    }  }  return NS_OK;}