Bug 1261754 - Part 8: Move box-shadow from nsStyleBorder to a new nsStyleEffects struct. r=dholbert

This commit is contained in:
Cameron McCormack 2016-04-12 15:52:42 +10:00
Родитель 6f4ce86293
Коммит 0718df89c3
17 изменённых файлов: 166 добавлений и 71 удалений

Просмотреть файл

@ -1247,8 +1247,7 @@ nsCSSRendering::PaintBoxShadowOuter(nsPresContext* aPresContext,
float aOpacity)
{
DrawTarget& aDrawTarget = *aRenderingContext.GetDrawTarget();
const nsStyleBorder* styleBorder = aForFrame->StyleBorder();
nsCSSShadowArray* shadows = styleBorder->mBoxShadow;
nsCSSShadowArray* shadows = aForFrame->StyleEffects()->mBoxShadow;
if (!shadows)
return;
@ -1484,8 +1483,7 @@ nsCSSRendering::PaintBoxShadowInner(nsPresContext* aPresContext,
nsIFrame* aForFrame,
const nsRect& aFrameArea)
{
const nsStyleBorder* styleBorder = aForFrame->StyleBorder();
nsCSSShadowArray* shadows = styleBorder->mBoxShadow;
nsCSSShadowArray* shadows = aForFrame->StyleEffects()->mBoxShadow;
if (!shadows)
return;
if (aForFrame->IsThemed() && aForFrame->GetContent() &&

Просмотреть файл

@ -2419,8 +2419,9 @@ nsDisplayBackgroundImage::AppendBackgroundItemsToTop(nsDisplayListBuilder* aBuil
}
const nsStyleBorder* borderStyle = aFrame->StyleBorder();
bool hasInsetShadow = borderStyle->mBoxShadow &&
borderStyle->mBoxShadow->HasShadowWithInset(true);
const nsStyleEffects* effectsStyle = aFrame->StyleEffects();
bool hasInsetShadow = effectsStyle->mBoxShadow &&
effectsStyle->mBoxShadow->HasShadowWithInset(true);
bool willPaintBorder = !isThemed && !hasInsetShadow &&
borderStyle->HasBorder();

Просмотреть файл

@ -8041,7 +8041,7 @@ nsLayoutUtils::FontSizeInflationEnabled(nsPresContext *aPresContext)
nsLayoutUtils::GetBoxShadowRectForFrame(nsIFrame* aFrame,
const nsSize& aFrameSize)
{
nsCSSShadowArray* boxShadows = aFrame->StyleBorder()->mBoxShadow;
nsCSSShadowArray* boxShadows = aFrame->StyleEffects()->mBoxShadow;
if (!boxShadows) {
return nsRect();
}

Просмотреть файл

@ -259,7 +259,7 @@ nsButtonFrameRenderer::DisplayButton(nsDisplayListBuilder* aBuilder,
nsDisplayList* aBackground,
nsDisplayList* aForeground)
{
if (mFrame->StyleBorder()->mBoxShadow) {
if (mFrame->StyleEffects()->mBoxShadow) {
aBackground->AppendNewToTop(new (aBuilder)
nsDisplayButtonBoxShadowOuter(aBuilder, this));
}

Просмотреть файл

@ -166,7 +166,7 @@ nsFieldSetFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
// we need to paint the outline
if (!(GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) &&
IsVisibleForPainting(aBuilder)) {
if (StyleBorder()->mBoxShadow) {
if (StyleEffects()->mBoxShadow) {
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
nsDisplayBoxShadowOuter(aBuilder, this));
}

Просмотреть файл

@ -1860,7 +1860,7 @@ nsFrame::DisplayBorderBackgroundOutline(nsDisplayListBuilder* aBuilder,
if (!IsVisibleForPainting(aBuilder))
return;
nsCSSShadowArray* shadows = StyleBorder()->mBoxShadow;
nsCSSShadowArray* shadows = StyleEffects()->mBoxShadow;
if (shadows && shadows->HasShadowWithInset(false)) {
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
nsDisplayBoxShadowOuter(aBuilder, this));

Просмотреть файл

@ -48,6 +48,7 @@ STYLE_STRUCTS = [("INHERITED",) + x for x in [
("XUL", "nullptr", NORMAL_DEP),
("SVGReset", "nullptr", NORMAL_DEP + LENGTH_DEP + COLOR_DEP),
("Column", "nullptr", NORMAL_DEP + LENGTH_DEP + COLOR_DEP),
("Effects", "nullptr", NORMAL_DEP + LENGTH_DEP + COLOR_DEP),
]]

Просмотреть файл

@ -156,6 +156,7 @@
#define CSS_PROP_SVG(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, SVG, stylestructoffset_, animtype_)
#define CSS_PROP_SVGRESET(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, SVGReset, stylestructoffset_, animtype_)
#define CSS_PROP_VARIABLES(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, Variables, stylestructoffset_, animtype_)
#define CSS_PROP_EFFECTS(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, Effects, stylestructoffset_, animtype_)
// And similarly for logical properties. An includer can define
// CSS_PROP_LOGICAL to capture all logical properties, but otherwise they
@ -279,6 +280,10 @@
#define CSS_PROP_VARIABLES(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) /* nothing */
#define DEFINED_CSS_PROP_VARIABLES
#endif
#ifndef CSS_PROP_EFFECTS
#define CSS_PROP_EFFECTS(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, stylestructoffset_, animtype_) /* nothing */
#define DEFINED_CSS_PROP_EFFECTS
#endif
#ifndef CSS_PROP_LOGICAL
#define CSS_PROP_LOGICAL(name_, id_, method_, flags_, pref_, parsevariant_, kwtable_, group_, struct_, stylestructoffset_, animtype_) /* nothing */
@ -1314,7 +1319,7 @@ CSS_PROP_BORDER(
kBoxDecorationBreakKTable,
CSS_PROP_NO_OFFSET,
eStyleAnimType_None)
CSS_PROP_BORDER(
CSS_PROP_EFFECTS(
box-shadow,
box_shadow,
BoxShadow,
@ -1326,7 +1331,7 @@ CSS_PROP_BORDER(
"",
0,
kBoxShadowTypeKTable,
offsetof(nsStyleBorder, mBoxShadow),
offsetof(nsStyleEffects, mBoxShadow),
eStyleAnimType_Shadow)
CSS_PROP_POSITION(
box-sizing,
@ -4463,6 +4468,7 @@ CSS_PROP_FONT(
#undef CSS_PROP_SVG
#undef CSS_PROP_SVGRESET
#undef CSS_PROP_VARIABLES
#undef CSS_PROP_EFFECTS
#else /* !defined(USED_CSS_PROP) */
@ -4558,6 +4564,10 @@ CSS_PROP_FONT(
#undef CSS_PROP_VARIABLES
#undef DEFINED_CSS_PROP_VARIABLES
#endif
#ifdef DEFINED_CSS_PROP_EFFECTS
#undef CSS_PROP_EFFECTS
#undef DEFINED_CSS_PROP_EFFECTS
#endif
#endif /* !defined(USED_CSS_PROP) */

Просмотреть файл

@ -3208,6 +3208,13 @@ enum VariablesCheckCounter {
ePropertyCount_for_Variables
};
enum EffectsCheckCounter {
#define CSS_PROP_EFFECTS ENUM_DATA_FOR_PROPERTY
#include "nsCSSPropList.h"
#undef CSS_PROP_EFFECTS
ePropertyCount_for_Effects
};
#undef ENUM_DATA_FOR_PROPERTY
/* static */ const size_t

Просмотреть файл

@ -3380,7 +3380,7 @@ nsComputedDOMStyle::DoGetBoxDecorationBreak()
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetBoxShadow()
{
return GetCSSShadowArray(StyleBorder()->mBoxShadow,
return GetCSSShadowArray(StyleEffects()->mBoxShadow,
StyleColor()->mColor,
true);
}

Просмотреть файл

@ -1976,6 +1976,12 @@ static_assert(sizeof(gVariablesFlags) == sizeof(uint32_t),
"if nsStyleVariables has properties now you can remove the dummy "
"gVariablesFlags entry");
static const uint32_t gEffectsFlags[] = {
#define CSS_PROP_EFFECTS FLAG_DATA_FOR_PROPERTY
#include "nsCSSPropList.h"
#undef CSS_PROP_EFFECTS
};
#undef FLAG_DATA_FOR_PROPERTY
static const uint32_t* gFlagsByStruct[] = {
@ -2575,6 +2581,12 @@ nsRuleNode::SetDefaultOnRoot(const nsStyleStructID aSID, nsStyleContext* aContex
aContext->SetStyle(eStyleStruct_Variables, vars);
return vars;
}
case eStyleStruct_Effects:
{
nsStyleEffects* effects = new (mPresContext) nsStyleEffects(mPresContext);
aContext->SetStyle(eStyleStruct_Effects, effects);
return effects;
}
default:
/*
* unhandled case: nsStyleStructID_Length.
@ -7211,33 +7223,6 @@ nsRuleNode::ComputeBorderData(void* aStartStruct,
parentBorder->mBoxDecorationBreak,
NS_STYLE_BOX_DECORATION_BREAK_SLICE, 0, 0, 0, 0);
// box-shadow: none, list, inherit, initial
const nsCSSValue* boxShadowValue = aRuleData->ValueForBoxShadow();
switch (boxShadowValue->GetUnit()) {
case eCSSUnit_Null:
break;
case eCSSUnit_Initial:
case eCSSUnit_Unset:
case eCSSUnit_None:
border->mBoxShadow = nullptr;
break;
case eCSSUnit_Inherit:
border->mBoxShadow = parentBorder->mBoxShadow;
conditions.SetUncacheable();
break;
case eCSSUnit_List:
case eCSSUnit_ListDep:
border->mBoxShadow = GetShadowData(boxShadowValue->GetListValue(),
aContext, true, conditions);
break;
default:
MOZ_ASSERT(false, "unrecognized shadow unit");
}
// border-width, border-*-width: length, enum, inherit
nsStyleCoord coord;
{
@ -10010,6 +9995,46 @@ nsRuleNode::ComputeVariablesData(void* aStartStruct,
COMPUTE_END_INHERITED(Variables, variables)
}
const void*
nsRuleNode::ComputeEffectsData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
nsRuleNode* aHighestNode,
const RuleDetail aRuleDetail,
const RuleNodeCacheConditions aConditions)
{
COMPUTE_START_RESET(Effects, effects, parentEffects)
// box-shadow: none, list, inherit, initial
const nsCSSValue* boxShadowValue = aRuleData->ValueForBoxShadow();
switch (boxShadowValue->GetUnit()) {
case eCSSUnit_Null:
break;
case eCSSUnit_Initial:
case eCSSUnit_Unset:
case eCSSUnit_None:
effects->mBoxShadow = nullptr;
break;
case eCSSUnit_Inherit:
effects->mBoxShadow = parentEffects->mBoxShadow;
conditions.SetUncacheable();
break;
case eCSSUnit_List:
case eCSSUnit_ListDep:
effects->mBoxShadow = GetShadowData(boxShadowValue->GetListValue(),
aContext, true, conditions);
break;
default:
MOZ_ASSERT(false, "unrecognized shadow unit");
}
COMPUTE_END_RESET(Effects, effects)
}
const void*
nsRuleNode::GetStyleData(nsStyleStructID aSID,
nsStyleContext* aContext,

Просмотреть файл

@ -746,6 +746,13 @@ protected:
RuleDetail aRuleDetail,
const mozilla::RuleNodeCacheConditions aConditions);
const void*
ComputeEffectsData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext, nsRuleNode* aHighestNode,
RuleDetail aRuleDetail,
const mozilla::RuleNodeCacheConditions aConditions);
// helpers for |ComputeFontData| that need access to |mNoneBits|:
static void SetFontSize(nsPresContext* aPresContext,
const nsRuleData* aRuleData,

Просмотреть файл

@ -978,6 +978,7 @@ nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
DO_STRUCT_DIFFERENCE(Padding);
DO_STRUCT_DIFFERENCE(Border);
DO_STRUCT_DIFFERENCE(TextReset);
DO_STRUCT_DIFFERENCE(Effects);
DO_STRUCT_DIFFERENCE(Background);
DO_STRUCT_DIFFERENCE(Color);
#undef EXTRA_DIFF_ARGS

Просмотреть файл

@ -375,7 +375,6 @@ nsChangeHint nsStylePadding::CalcDifference(const nsStylePadding& aOther) const
nsStyleBorder::nsStyleBorder(StyleStructContext aContext)
: mBorderColors(nullptr),
mBoxShadow(nullptr),
mBorderImageFill(NS_STYLE_BORDER_IMAGE_SLICE_NOFILL),
mBorderImageRepeatH(NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH),
mBorderImageRepeatV(NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH),
@ -422,7 +421,6 @@ nsBorderColors::Clone(bool aDeep) const
nsStyleBorder::nsStyleBorder(const nsStyleBorder& aSrc)
: mBorderColors(nullptr),
mBoxShadow(aSrc.mBoxShadow),
mBorderRadius(aSrc.mBorderRadius),
mBorderImageSource(aSrc.mBorderImageSource),
mBorderImageSlice(aSrc.mBorderImageSlice),
@ -509,18 +507,6 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const
mBoxDecorationBreak != aOther.mBoxDecorationBreak)
return NS_STYLE_HINT_REFLOW;
nsChangeHint boxShadowHint = nsChangeHint(0);
if (!AreShadowArraysEqual(mBoxShadow, aOther.mBoxShadow)) {
// Update overflow regions & trigger DLBI to be sure it's noticed:
NS_UpdateHint(boxShadowHint, nsChangeHint_UpdateOverflow);
NS_UpdateHint(boxShadowHint, nsChangeHint_SchedulePaint);
// Also request a repaint, since it's possible that only the color
// of the shadow is changing (and UpdateOverflow/SchedulePaint won't
// repaint for that, since they won't know what needs invalidating.)
NS_UpdateHint(boxShadowHint, nsChangeHint_RepaintFrame);
// Don't return yet; we may also need nsChangeHint_BorderStyleNoneChange.
}
NS_FOR_CSS_SIDES(ix) {
// See the explanation in nsChangeHint.h of
// nsChangeHint_BorderStyleNoneChange .
@ -528,19 +514,11 @@ nsChangeHint nsStyleBorder::CalcDifference(const nsStyleBorder& aOther) const
// assume a repaint hint for some other change rather than bother
// tracking this result through the rest of the function.
if (HasVisibleStyle(ix) != aOther.HasVisibleStyle(ix)) {
return NS_CombineHint(boxShadowHint,
nsChangeHint_RepaintFrame |
nsChangeHint_BorderStyleNoneChange);
return nsChangeHint_RepaintFrame |
nsChangeHint_BorderStyleNoneChange;
}
}
if (boxShadowHint) {
// NOTE: This hint (UpdateOverflow + SchedulePaint + RepaintFrame) is
// expected to subsume all hints returned after this point. (Hence, we're
// OK to return early.)
return boxShadowHint;
}
// Note that mBorderStyle stores not only the border style but also
// color-related flags. Given that we've already done an mComputedBorder
// comparison, border-style differences can only lead to a repaint hint. So
@ -4015,3 +3993,42 @@ nsStyleVariables::CalcDifference(const nsStyleVariables& aOther) const
{
return nsChangeHint(0);
}
//-----------------------
// nsStyleEffects
//
nsStyleEffects::nsStyleEffects(StyleStructContext aContext)
: mBoxShadow(nullptr)
{
MOZ_COUNT_CTOR(nsStyleEffects);
}
nsStyleEffects::nsStyleEffects(const nsStyleEffects& aSource)
: mBoxShadow(aSource.mBoxShadow)
{
MOZ_COUNT_CTOR(nsStyleEffects);
}
nsStyleEffects::~nsStyleEffects()
{
MOZ_COUNT_DTOR(nsStyleEffects);
}
nsChangeHint
nsStyleEffects::CalcDifference(const nsStyleEffects& aOther) const
{
nsChangeHint hint = nsChangeHint(0);
if (!AreShadowArraysEqual(mBoxShadow, aOther.mBoxShadow)) {
// Update overflow regions & trigger DLBI to be sure it's noticed.
// Also request a repaint, since it's possible that only the color
// of the shadow is changing (and UpdateOverflow/SchedulePaint won't
// repaint for that, since they won't know what needs invalidating.)
hint |= nsChangeHint_UpdateOverflow |
nsChangeHint_SchedulePaint |
nsChangeHint_RepaintFrame;
}
return hint;
}

Просмотреть файл

@ -48,7 +48,7 @@ struct nsStyleVisibility;
// Bits for each struct.
// NS_STYLE_INHERIT_BIT defined in nsStyleStructFwd.h
#define NS_STYLE_INHERIT_MASK 0x0007fffff
#define NS_STYLE_INHERIT_MASK 0x000ffffff
// Bits for inherited structs.
#define NS_STYLE_INHERITED_STRUCT_MASK \
@ -59,7 +59,6 @@ struct nsStyleVisibility;
<< nsStyleStructID_Inherited_Count)
// Additional bits for nsStyleContext's mBits:
// Free bit 0x000800000
// See nsStyleContext::HasTextDecorationLines
#define NS_STYLE_HAS_TEXT_DECORATION_LINES 0x001000000
// See nsStyleContext::HasPseudoElementData.
@ -87,7 +86,6 @@ struct nsStyleVisibility;
#define NS_STYLE_CONTEXT_TYPE_SHIFT 35
// Additional bits for nsRuleNode's mDependentBits:
// Free bit 0x00800000
#define NS_RULE_NODE_IS_ANIMATION_RULE 0x01000000
// Free bit 0x02000000
#define NS_RULE_NODE_USED_DIRECTLY 0x04000000
@ -1207,7 +1205,6 @@ struct nsStyleBorder
public:
nsBorderColors** mBorderColors; // [reset] composite (stripe) colors
RefPtr<nsCSSShadowArray> mBoxShadow; // [reset] nullptr for 'none'
public:
nsStyleCorners mBorderRadius; // [reset] coord, percent
@ -3567,4 +3564,36 @@ struct nsStyleVariables
mozilla::CSSVariableValues mVariables;
};
struct nsStyleEffects
{
explicit nsStyleEffects(StyleStructContext aContext);
nsStyleEffects(const nsStyleEffects& aSource);
~nsStyleEffects();
void* operator new(size_t sz, nsStyleEffects* aSelf) CPP_THROW_NEW { return aSelf; }
void* operator new(size_t sz, nsPresContext* aContext) CPP_THROW_NEW {
return aContext->PresShell()->
AllocateByObjectID(mozilla::eArenaObjectID_nsStyleEffects, sz);
}
void Destroy(nsPresContext* aContext) {
this->~nsStyleEffects();
aContext->PresShell()->
FreeByObjectID(mozilla::eArenaObjectID_nsStyleEffects, this);
}
nsChangeHint CalcDifference(const nsStyleEffects& aOther) const;
static nsChangeHint MaxDifference() {
return nsChangeHint_UpdateOverflow |
nsChangeHint_SchedulePaint |
nsChangeHint_RepaintFrame;
}
static nsChangeHint DifferenceAlwaysHandledForDescendants() {
// CalcDifference never returns the reflow hints that are sometimes
// handled for descendants as hints not handled for descendants.
return nsChangeHint(0);
}
RefPtr<nsCSSShadowArray> mBoxShadow; // [reset] nullptr for 'none'
};
#endif /* nsStyleStruct_h___ */

Просмотреть файл

@ -489,8 +489,7 @@ nsTableCellFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
if (StyleVisibility()->IsVisible() &&
(NS_STYLE_TABLE_EMPTY_CELLS_HIDE != emptyCellStyle)) {
// display outset box-shadows if we need to.
const nsStyleBorder* borderStyle = StyleBorder();
bool hasBoxShadow = !!borderStyle->mBoxShadow;
bool hasBoxShadow = !!StyleEffects()->mBoxShadow;
if (hasBoxShadow) {
aLists.BorderBackground()->AppendNewToTop(
new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, this));

Просмотреть файл

@ -1242,7 +1242,7 @@ nsTableFrame::DisplayGenericTablePart(nsDisplayListBuilder* aBuilder,
}
// Paint the outset box-shadows for the table frames
bool hasBoxShadow = aFrame->StyleBorder()->mBoxShadow != nullptr;
bool hasBoxShadow = aFrame->StyleEffects()->mBoxShadow != nullptr;
if (hasBoxShadow) {
lists->BorderBackground()->AppendNewToTop(
new (aBuilder) nsDisplayBoxShadowOuter(aBuilder, aFrame));