2018-03-22 22:04:20 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/* the interface (to internal code) for retrieving computed style data */
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
#include "mozilla/ComputedStyle.h"
|
2018-03-22 22:04:20 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2019-02-21 22:50:22 +03:00
|
|
|
#include "mozilla/ToString.h"
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
#include "nsCSSAnonBoxes.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
#include "nsFontMetrics.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsStyleStruct.h"
|
|
|
|
#include "nsStyleStructInlines.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsPresContext.h"
|
2018-03-28 02:44:49 +03:00
|
|
|
#include "nsWindowSizes.h"
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "GeckoProfiler.h"
|
2019-01-02 16:05:23 +03:00
|
|
|
#include "mozilla/dom/Document.h"
|
2018-03-22 22:04:20 +03:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "RubyUtils.h"
|
2018-03-24 17:47:44 +03:00
|
|
|
#include "mozilla/ComputedStyleInlines.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
#include "mozilla/ReflowInput.h"
|
|
|
|
#include "nsLayoutUtils.h"
|
|
|
|
#include "nsCoord.h"
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
// Ensure the binding function declarations in ComputedStyle.h matches
|
2018-03-22 22:04:20 +03:00
|
|
|
// those in ServoBindings.h.
|
|
|
|
#include "mozilla/ServoBindings.h"
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
namespace mozilla {
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
ComputedStyle::ComputedStyle(PseudoStyleType aPseudoType,
|
2018-03-22 21:20:41 +03:00
|
|
|
ServoComputedDataForgotten aComputedValues)
|
2019-03-20 00:10:30 +03:00
|
|
|
: mSource(aComputedValues), mPseudoType(aPseudoType) {}
|
2018-03-22 22:04:20 +03:00
|
|
|
|
2019-02-05 22:47:29 +03:00
|
|
|
nsChangeHint ComputedStyle::CalcStyleDifference(const ComputedStyle& aNewStyle,
|
|
|
|
uint32_t* aEqualStructs) const {
|
2018-05-19 00:40:52 +03:00
|
|
|
AUTO_PROFILER_LABEL("ComputedStyle::CalcStyleDifference", LAYOUT);
|
2018-05-24 18:49:24 +03:00
|
|
|
static_assert(StyleStructConstants::kStyleStructCount <= 32,
|
2018-03-22 22:04:20 +03:00
|
|
|
"aEqualStructs is not big enough");
|
|
|
|
|
|
|
|
*aEqualStructs = 0;
|
|
|
|
|
|
|
|
nsChangeHint hint = nsChangeHint(0);
|
|
|
|
// We must always ensure that we populate the structs on the new style
|
|
|
|
// context that are filled in on the old context, so that if we get
|
|
|
|
// two style changes in succession, the second of which causes a real
|
|
|
|
// style change, the PeekStyleData doesn't return null (implying that
|
|
|
|
// nobody ever looked at that struct's data). In other words, we
|
|
|
|
// can't skip later structs if we get a big change up front, because
|
|
|
|
// we could later get a small change in one of those structs that we
|
|
|
|
// don't want to miss.
|
|
|
|
|
|
|
|
DebugOnly<uint32_t> structsFound = 0;
|
|
|
|
|
2018-04-10 08:11:12 +03:00
|
|
|
DebugOnly<int> styleStructCount = 0;
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
// Servo's optimization to stop the cascade when there are no style changes
|
|
|
|
// that children need to be recascade for relies on comparing all of the
|
|
|
|
// structs, not just those that are returned from PeekStyleData, although
|
|
|
|
// if PeekStyleData does return null we could avoid to accumulate any change
|
|
|
|
// hints for those structs.
|
|
|
|
//
|
|
|
|
// FIXME(emilio): Reintroduce that optimization either for all kind of structs
|
|
|
|
// after bug 1368290 with a weak parent pointer from text, or just for reset
|
|
|
|
// structs.
|
2018-05-24 18:49:24 +03:00
|
|
|
#define STYLE_STRUCT_BIT(name_) \
|
|
|
|
StyleStructConstants::BitFor(StyleStructID::name_)
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
#define EXPAND(...) __VA_ARGS__
|
2019-02-05 22:47:29 +03:00
|
|
|
#define DO_STRUCT_DIFFERENCE_WITH_ARGS(struct_, extra_args_) \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
const nsStyle##struct_* this##struct_ = Style##struct_(); \
|
|
|
|
structsFound |= STYLE_STRUCT_BIT(struct_); \
|
|
|
|
\
|
|
|
|
const nsStyle##struct_* other##struct_ = aNewStyle.Style##struct_(); \
|
|
|
|
if (this##struct_ == other##struct_) { \
|
|
|
|
/* The very same struct, so we know that there will be no */ \
|
|
|
|
/* differences. */ \
|
|
|
|
*aEqualStructs |= STYLE_STRUCT_BIT(struct_); \
|
|
|
|
} else { \
|
|
|
|
nsChangeHint difference = \
|
|
|
|
this##struct_->CalcDifference(*other##struct_ EXPAND extra_args_); \
|
|
|
|
hint |= difference; \
|
|
|
|
if (!difference) { \
|
|
|
|
*aEqualStructs |= STYLE_STRUCT_BIT(struct_); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
styleStructCount++; \
|
2018-03-22 22:04:20 +03:00
|
|
|
PR_END_MACRO
|
|
|
|
#define DO_STRUCT_DIFFERENCE(struct_) \
|
|
|
|
DO_STRUCT_DIFFERENCE_WITH_ARGS(struct_, ())
|
|
|
|
|
|
|
|
// FIXME: The order of these DO_STRUCT_DIFFERENCE calls is no longer
|
|
|
|
// significant. With a small amount of effort, we could replace them with a
|
|
|
|
// #include "nsStyleStructList.h".
|
|
|
|
DO_STRUCT_DIFFERENCE(Display);
|
|
|
|
DO_STRUCT_DIFFERENCE(XUL);
|
|
|
|
DO_STRUCT_DIFFERENCE(Column);
|
|
|
|
DO_STRUCT_DIFFERENCE(Content);
|
2018-08-14 11:37:37 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(UI);
|
2018-03-22 22:04:20 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Visibility);
|
|
|
|
DO_STRUCT_DIFFERENCE(Outline);
|
|
|
|
DO_STRUCT_DIFFERENCE(TableBorder);
|
|
|
|
DO_STRUCT_DIFFERENCE(Table);
|
|
|
|
DO_STRUCT_DIFFERENCE(UIReset);
|
|
|
|
DO_STRUCT_DIFFERENCE(Text);
|
2019-02-15 02:30:19 +03:00
|
|
|
DO_STRUCT_DIFFERENCE_WITH_ARGS(List, (, *StyleDisplay()));
|
2018-03-22 22:04:20 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(SVGReset);
|
|
|
|
DO_STRUCT_DIFFERENCE(SVG);
|
2019-02-15 02:30:19 +03:00
|
|
|
DO_STRUCT_DIFFERENCE_WITH_ARGS(Position, (, *StyleVisibility()));
|
2018-03-22 22:04:20 +03:00
|
|
|
DO_STRUCT_DIFFERENCE(Font);
|
|
|
|
DO_STRUCT_DIFFERENCE(Margin);
|
|
|
|
DO_STRUCT_DIFFERENCE(Padding);
|
|
|
|
DO_STRUCT_DIFFERENCE(Border);
|
|
|
|
DO_STRUCT_DIFFERENCE(TextReset);
|
|
|
|
DO_STRUCT_DIFFERENCE(Effects);
|
|
|
|
DO_STRUCT_DIFFERENCE(Background);
|
|
|
|
|
|
|
|
#undef DO_STRUCT_DIFFERENCE
|
|
|
|
#undef DO_STRUCT_DIFFERENCE_WITH_ARGS
|
|
|
|
#undef EXPAND
|
|
|
|
|
2018-05-24 18:49:24 +03:00
|
|
|
MOZ_ASSERT(styleStructCount == StyleStructConstants::kStyleStructCount,
|
2018-03-22 22:04:20 +03:00
|
|
|
"missing a call to DO_STRUCT_DIFFERENCE");
|
|
|
|
|
|
|
|
// Note that we do not check whether this->RelevantLinkVisited() !=
|
|
|
|
// aNewContext->RelevantLinkVisited(); we don't need to since
|
|
|
|
// nsCSSFrameConstructor::DoContentStateChanged always adds
|
|
|
|
// nsChangeHint_RepaintFrame for NS_EVENT_STATE_VISITED changes (and
|
|
|
|
// needs to, since HasStateDependentStyle probably doesn't work right
|
|
|
|
// for NS_EVENT_STATE_VISITED). Hopefully this doesn't actually
|
|
|
|
// expose whether links are visited to performance tests since all
|
|
|
|
// link coloring happens asynchronously at a time when it's hard for
|
|
|
|
// the page to measure.
|
|
|
|
// However, we do need to compute the larger of the changes that can
|
|
|
|
// happen depending on whether the link is visited or unvisited, since
|
|
|
|
// doing only the one that's currently appropriate would expose which
|
|
|
|
// links are in history to easy performance measurement. Therefore,
|
|
|
|
// here, we add nsChangeHint_RepaintFrame hints (the maximum for
|
|
|
|
// things that can depend on :visited) for the properties on which we
|
|
|
|
// call GetVisitedDependentColor.
|
2019-02-05 22:47:29 +03:00
|
|
|
const ComputedStyle* thisVis = GetStyleIfVisited();
|
|
|
|
const ComputedStyle* otherVis = aNewStyle.GetStyleIfVisited();
|
2018-03-22 22:04:20 +03:00
|
|
|
if (!thisVis != !otherVis) {
|
2018-03-22 21:20:41 +03:00
|
|
|
// One style has a style-if-visited and the other doesn't.
|
2018-03-22 22:04:20 +03:00
|
|
|
// Presume a difference.
|
2018-05-24 18:49:24 +03:00
|
|
|
#define STYLE_STRUCT(name_, fields_) *aEqualStructs &= ~STYLE_STRUCT_BIT(name_);
|
2018-03-22 22:04:20 +03:00
|
|
|
#include "nsCSSVisitedDependentPropList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
hint |= nsChangeHint_RepaintFrame;
|
|
|
|
} else if (thisVis) {
|
2018-03-22 21:20:41 +03:00
|
|
|
// Both styles have a style-if-visited.
|
2018-03-22 22:04:20 +03:00
|
|
|
bool change = false;
|
|
|
|
|
|
|
|
// NB: Calling Peek on |this|, not |thisVis|, since callers may look
|
|
|
|
// at a struct on |this| without looking at the same struct on
|
|
|
|
// |thisVis| (including this function if we skip one of these checks
|
2018-03-22 21:20:41 +03:00
|
|
|
// due to change being true already or due to the old style not having a
|
|
|
|
// style-if-visited), but not the other way around.
|
2018-03-22 22:04:20 +03:00
|
|
|
#define STYLE_FIELD(name_) thisVisStruct->name_ != otherVisStruct->name_
|
2019-02-05 22:47:29 +03:00
|
|
|
#define STYLE_STRUCT(name_, fields_) \
|
|
|
|
{ \
|
|
|
|
const nsStyle##name_* thisVisStruct = thisVis->Style##name_(); \
|
|
|
|
const nsStyle##name_* otherVisStruct = otherVis->Style##name_(); \
|
|
|
|
if (MOZ_FOR_EACH_SEPARATED(STYLE_FIELD, (||), (), fields_)) { \
|
|
|
|
*aEqualStructs &= ~STYLE_STRUCT_BIT(name_); \
|
|
|
|
change = true; \
|
|
|
|
} \
|
|
|
|
}
|
2018-03-22 22:04:20 +03:00
|
|
|
#include "nsCSSVisitedDependentPropList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
#undef STYLE_FIELD
|
2018-05-24 18:49:24 +03:00
|
|
|
#undef STYLE_STRUCT_BIT
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
if (change) {
|
|
|
|
hint |= nsChangeHint_RepaintFrame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hint & nsChangeHint_UpdateContainingBlock) {
|
|
|
|
// If a struct returned nsChangeHint_UpdateContainingBlock, that
|
|
|
|
// means that one property's influence on whether we're a containing
|
|
|
|
// block for abs-pos or fixed-pos elements has changed. However, we
|
|
|
|
// only need to return the hint if the overall computation of
|
|
|
|
// whether we establish a containing block has changed.
|
|
|
|
|
2018-06-25 09:42:38 +03:00
|
|
|
// This depends on data in nsStyleDisplay and nsStyleEffects, so we do it
|
|
|
|
// here
|
2018-03-22 22:04:20 +03:00
|
|
|
|
|
|
|
// Note that it's perhaps good for this test to be last because it
|
|
|
|
// doesn't use Peek* functions to get the structs on the old
|
|
|
|
// context. But this isn't a big concern because these struct
|
|
|
|
// getters should be called during frame construction anyway.
|
2019-02-05 22:47:29 +03:00
|
|
|
const nsStyleDisplay* oldDisp = StyleDisplay();
|
|
|
|
const nsStyleDisplay* newDisp = aNewStyle.StyleDisplay();
|
Bug 1479859 patch 2 - Send nsChangeHint_UpdateContainingBlock when containing block-ness changes due to one property change, while another property that might trigger containing block-ness doesn't do so because of the frame type. r=emilio
This fixes a rather subtle bug. What the underlying code here is trying
to do is remove nsChangeHint_UpdateContainingBlock when some properties
that influence whether a frame is a containing block for absolutely
positioned or fixed positioned elements have changed, but the final
calculation of being a containing block has not changed. However, the
old code was using a function that tested whether the style could
*possibly* lead to a frame being a containing block. Some of the
properties (like the transform properties) that lead to being a
containing block, for example, don't apply to non-replaced inlines.
Some, however, do (such as 'filter'). So if there's a dynamic change
adding or removing a filter, on an inline that also has an *ignored*
transform property (like 'transform' or 'perspective') set, then the
code prior to this patch causes us to remove the UpdateContainingBlock
hint.
This patch fixes things by testing whether being a containing block
could have changed for *any* type of frame, by separately testing the
changes.
The added tests fail without the patch and pass with the patch, viewed
in isolation. However, without the previous patch, test 003 passes.
Test 003 also fails in Chrome (but 001 and 002 pass).
Differential Revision: https://phabricator.services.mozilla.com/D2814
--HG--
extra : rebase_source : 0a5dbb15a058cf4a43d989bf53f042c5b718e24d
2018-08-08 01:02:07 +03:00
|
|
|
bool isFixedCB;
|
|
|
|
if (oldDisp->IsAbsPosContainingBlockForNonSVGTextFrames() ==
|
|
|
|
newDisp->IsAbsPosContainingBlockForNonSVGTextFrames() &&
|
|
|
|
(isFixedCB =
|
|
|
|
oldDisp->IsFixedPosContainingBlockForNonSVGTextFrames(*this)) ==
|
2019-02-05 22:47:29 +03:00
|
|
|
newDisp->IsFixedPosContainingBlockForNonSVGTextFrames(aNewStyle) &&
|
Bug 1479859 patch 2 - Send nsChangeHint_UpdateContainingBlock when containing block-ness changes due to one property change, while another property that might trigger containing block-ness doesn't do so because of the frame type. r=emilio
This fixes a rather subtle bug. What the underlying code here is trying
to do is remove nsChangeHint_UpdateContainingBlock when some properties
that influence whether a frame is a containing block for absolutely
positioned or fixed positioned elements have changed, but the final
calculation of being a containing block has not changed. However, the
old code was using a function that tested whether the style could
*possibly* lead to a frame being a containing block. Some of the
properties (like the transform properties) that lead to being a
containing block, for example, don't apply to non-replaced inlines.
Some, however, do (such as 'filter'). So if there's a dynamic change
adding or removing a filter, on an inline that also has an *ignored*
transform property (like 'transform' or 'perspective') set, then the
code prior to this patch causes us to remove the UpdateContainingBlock
hint.
This patch fixes things by testing whether being a containing block
could have changed for *any* type of frame, by separately testing the
changes.
The added tests fail without the patch and pass with the patch, viewed
in isolation. However, without the previous patch, test 003 passes.
Test 003 also fails in Chrome (but 001 and 002 pass).
Differential Revision: https://phabricator.services.mozilla.com/D2814
--HG--
extra : rebase_source : 0a5dbb15a058cf4a43d989bf53f042c5b718e24d
2018-08-08 01:02:07 +03:00
|
|
|
// transform-supporting frames are a subcategory of non-SVG-text
|
|
|
|
// frames, so no need to test this if isFixedCB is true (both
|
|
|
|
// before and after the change)
|
|
|
|
(isFixedCB ||
|
|
|
|
oldDisp->IsFixedPosContainingBlockForTransformSupportingFrames() ==
|
2018-08-08 01:02:08 +03:00
|
|
|
newDisp
|
|
|
|
->IsFixedPosContainingBlockForTransformSupportingFrames()) &&
|
|
|
|
// contain-layout-and-paint-supporting frames are a subset of
|
|
|
|
// non-SVG-text frames, so no need to test this if isFixedCB is true
|
|
|
|
// (both before and after the change).
|
|
|
|
//
|
|
|
|
// Note, however, that neither of these last two sets is a
|
|
|
|
// subset of the other, because table frames support contain:
|
|
|
|
// layout/paint but not transforms (which are instead inherited
|
|
|
|
// to the table wrapper), and quite a few frame types support
|
|
|
|
// transforms but not contain: layout/paint (e.g., table rows
|
|
|
|
// and row groups, many SVG frames).
|
|
|
|
(isFixedCB ||
|
|
|
|
oldDisp->IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames() ==
|
|
|
|
newDisp
|
|
|
|
->IsFixedPosContainingBlockForContainLayoutAndPaintSupportingFrames())) {
|
2018-03-22 22:04:20 +03:00
|
|
|
// While some styles that cause the frame to be a containing block
|
Bug 1479859 patch 2 - Send nsChangeHint_UpdateContainingBlock when containing block-ness changes due to one property change, while another property that might trigger containing block-ness doesn't do so because of the frame type. r=emilio
This fixes a rather subtle bug. What the underlying code here is trying
to do is remove nsChangeHint_UpdateContainingBlock when some properties
that influence whether a frame is a containing block for absolutely
positioned or fixed positioned elements have changed, but the final
calculation of being a containing block has not changed. However, the
old code was using a function that tested whether the style could
*possibly* lead to a frame being a containing block. Some of the
properties (like the transform properties) that lead to being a
containing block, for example, don't apply to non-replaced inlines.
Some, however, do (such as 'filter'). So if there's a dynamic change
adding or removing a filter, on an inline that also has an *ignored*
transform property (like 'transform' or 'perspective') set, then the
code prior to this patch causes us to remove the UpdateContainingBlock
hint.
This patch fixes things by testing whether being a containing block
could have changed for *any* type of frame, by separately testing the
changes.
The added tests fail without the patch and pass with the patch, viewed
in isolation. However, without the previous patch, test 003 passes.
Test 003 also fails in Chrome (but 001 and 002 pass).
Differential Revision: https://phabricator.services.mozilla.com/D2814
--HG--
extra : rebase_source : 0a5dbb15a058cf4a43d989bf53f042c5b718e24d
2018-08-08 01:02:07 +03:00
|
|
|
// has changed, the overall result cannot have changed (no matter
|
|
|
|
// what the frame type is).
|
2018-03-22 22:04:20 +03:00
|
|
|
hint &= ~nsChangeHint_UpdateContainingBlock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsHintSubset(hint, nsChangeHint_AllHints),
|
|
|
|
"Added a new hint without bumping AllHints?");
|
|
|
|
return hint & ~nsChangeHint_NeutralChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-03-24 07:50:14 +03:00
|
|
|
void ComputedStyle::List(FILE* out, int32_t aIndent) {
|
2018-03-22 22:04:20 +03:00
|
|
|
nsAutoCString str;
|
|
|
|
// Indent
|
|
|
|
int32_t ix;
|
|
|
|
for (ix = aIndent; --ix >= 0;) {
|
|
|
|
str.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
str.Append(nsPrintfCString("%p(%d) parent=%p ", (void*)this, 0, nullptr));
|
2019-02-19 16:44:33 +03:00
|
|
|
if (mPseudoType != PseudoStyleType::NotPseudo) {
|
2019-02-21 22:50:22 +03:00
|
|
|
str.Append(nsPrintfCString("%s ", ToString(mPseudoType).c_str()));
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
fprintf_stderr(out, "%s{ServoComputedData}\n", str.get());
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename Func>
|
2018-03-22 21:20:41 +03:00
|
|
|
static nscolor GetVisitedDependentColorInternal(ComputedStyle* aSc,
|
|
|
|
Func aColorFunc) {
|
2018-03-22 22:04:20 +03:00
|
|
|
nscolor colors[2];
|
|
|
|
colors[0] = aColorFunc(aSc);
|
2018-03-22 21:20:41 +03:00
|
|
|
if (ComputedStyle* visitedStyle = aSc->GetStyleIfVisited()) {
|
2018-03-22 22:04:20 +03:00
|
|
|
colors[1] = aColorFunc(visitedStyle);
|
|
|
|
return ComputedStyle::CombineVisitedColors(colors,
|
|
|
|
aSc->RelevantLinkVisited());
|
|
|
|
}
|
|
|
|
return colors[0];
|
|
|
|
}
|
|
|
|
|
2019-04-04 14:35:16 +03:00
|
|
|
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
2019-04-06 20:47:58 +03:00
|
|
|
const StyleRGBA& aColor) {
|
|
|
|
return aColor.ToColor();
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:35:16 +03:00
|
|
|
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
2019-04-04 14:35:33 +03:00
|
|
|
const StyleColor& aColor) {
|
2018-05-09 10:03:02 +03:00
|
|
|
return aColor.CalcColor(aStyle);
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
|
|
|
|
2019-04-04 14:35:16 +03:00
|
|
|
// Currently caret-color, the only property in the list which is a ColorOrAuto,
|
|
|
|
// always maps auto to currentcolor.
|
|
|
|
static nscolor ExtractColor(const ComputedStyle& aStyle,
|
|
|
|
const StyleColorOrAuto& aColor) {
|
|
|
|
if (aColor.IsAuto()) {
|
|
|
|
return ExtractColor(aStyle, StyleColor::CurrentColor());
|
|
|
|
}
|
|
|
|
return ExtractColor(aStyle, aColor.AsColor());
|
|
|
|
}
|
|
|
|
|
|
|
|
static nscolor ExtractColor(ComputedStyle& aStyle,
|
2018-03-22 21:20:41 +03:00
|
|
|
const nsStyleSVGPaint& aPaintServer) {
|
2018-03-22 22:04:20 +03:00
|
|
|
return aPaintServer.Type() == eStyleSVGPaintType_Color
|
2019-04-04 14:35:16 +03:00
|
|
|
? aPaintServer.GetColor(&aStyle)
|
2018-06-27 10:07:37 +03:00
|
|
|
: NS_RGBA(0, 0, 0, 0);
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#define STYLE_FIELD(struct_, field_) aField == &struct_::field_ ||
|
|
|
|
#define STYLE_STRUCT(name_, fields_) \
|
|
|
|
template <> \
|
2018-03-22 21:20:41 +03:00
|
|
|
nscolor ComputedStyle::GetVisitedDependentColor( \
|
2018-03-22 22:04:20 +03:00
|
|
|
decltype(nsStyle##name_::MOZ_ARG_1 fields_) nsStyle##name_::*aField) { \
|
|
|
|
MOZ_ASSERT(MOZ_FOR_EACH(STYLE_FIELD, (nsStyle##name_, ), fields_) false, \
|
|
|
|
"Getting visited-dependent color for a field in nsStyle" #name_ \
|
|
|
|
" which is not listed in nsCSSVisitedDependentPropList.h"); \
|
|
|
|
return GetVisitedDependentColorInternal( \
|
2018-03-22 21:20:41 +03:00
|
|
|
this, [aField](ComputedStyle* sc) { \
|
2019-04-04 14:35:16 +03:00
|
|
|
return ExtractColor(*sc, sc->Style##name_()->*aField); \
|
2018-03-22 22:04:20 +03:00
|
|
|
}); \
|
|
|
|
}
|
|
|
|
#include "nsCSSVisitedDependentPropList.h"
|
|
|
|
#undef STYLE_STRUCT
|
|
|
|
#undef STYLE_FIELD
|
|
|
|
|
|
|
|
struct ColorIndexSet {
|
|
|
|
uint8_t colorIndex, alphaIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ColorIndexSet gVisitedIndices[2] = {{0, 0}, {1, 0}};
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
nscolor ComputedStyle::CombineVisitedColors(nscolor* aColors,
|
|
|
|
bool aLinkIsVisited) {
|
2018-03-22 22:04:20 +03:00
|
|
|
if (NS_GET_A(aColors[1]) == 0) {
|
|
|
|
// If the style-if-visited is transparent, then just use the
|
|
|
|
// unvisited style rather than using the (meaningless) color
|
|
|
|
// components of the visited style along with a potentially
|
|
|
|
// non-transparent alpha value.
|
|
|
|
aLinkIsVisited = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: We want this code to have as little timing dependence as
|
|
|
|
// possible on whether this->RelevantLinkVisited() is true.
|
|
|
|
const ColorIndexSet& set = gVisitedIndices[aLinkIsVisited ? 1 : 0];
|
|
|
|
|
|
|
|
nscolor colorColor = aColors[set.colorIndex];
|
|
|
|
nscolor alphaColor = aColors[set.alphaIndex];
|
|
|
|
return NS_RGBA(NS_GET_R(colorColor), NS_GET_G(colorColor),
|
|
|
|
NS_GET_B(colorColor), NS_GET_A(alphaColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2018-05-24 18:49:24 +03:00
|
|
|
/* static */ const char* ComputedStyle::StructName(StyleStructID aSID) {
|
2018-03-22 22:04:20 +03:00
|
|
|
switch (aSID) {
|
2018-03-26 12:09:17 +03:00
|
|
|
# define STYLE_STRUCT(name_) \
|
2018-05-24 18:49:24 +03:00
|
|
|
case StyleStructID::name_: \
|
2018-03-22 22:04:20 +03:00
|
|
|
return #name_;
|
|
|
|
# include "nsStyleStructList.h"
|
|
|
|
# undef STYLE_STRUCT
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:09:24 +03:00
|
|
|
/* static */
|
|
|
|
Maybe<StyleStructID> ComputedStyle::LookupStruct(const nsACString& aName) {
|
2018-03-26 12:09:17 +03:00
|
|
|
# define STYLE_STRUCT(name_) \
|
2018-05-24 18:49:24 +03:00
|
|
|
if (aName.EqualsLiteral(#name_)) return Some(StyleStructID::name_);
|
2018-03-22 22:04:20 +03:00
|
|
|
# include "nsStyleStructList.h"
|
|
|
|
# undef STYLE_STRUCT
|
2018-05-24 18:49:24 +03:00
|
|
|
return Nothing();
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
2018-03-22 21:20:41 +03:00
|
|
|
#endif // DEBUG
|
2018-03-22 22:04:20 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
ComputedStyle* ComputedStyle::GetCachedLazyPseudoStyle(
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudo) const {
|
|
|
|
MOZ_ASSERT(PseudoStyle::IsPseudoElement(aPseudo));
|
2018-03-22 22:04:20 +03:00
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
if (nsCSSPseudoElements::PseudoElementSupportsUserActionState(aPseudo)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
return mCachedInheritingStyles.Lookup(aPseudo);
|
2018-03-22 22:04:20 +03:00
|
|
|
}
|
2018-03-22 21:20:41 +03:00
|
|
|
|
2018-03-28 02:57:35 +03:00
|
|
|
MOZ_DEFINE_MALLOC_ENCLOSING_SIZE_OF(ServoComputedValuesMallocEnclosingSizeOf)
|
|
|
|
|
2018-03-28 02:44:49 +03:00
|
|
|
void ComputedStyle::AddSizeOfIncludingThis(nsWindowSizes& aSizes,
|
|
|
|
size_t* aCVsSize) const {
|
|
|
|
// Note: |this| sits within a servo_arc::Arc, i.e. it is preceded by a
|
|
|
|
// refcount. So we need to measure it with a function that can handle an
|
|
|
|
// interior pointer. We use ServoComputedValuesMallocEnclosingSizeOf to
|
|
|
|
// clearly identify in DMD's output the memory measured here.
|
|
|
|
*aCVsSize += ServoComputedValuesMallocEnclosingSizeOf(this);
|
|
|
|
mSource.AddSizeOfExcludingThis(aSizes);
|
|
|
|
mCachedInheritingStyles.AddSizeOfIncludingThis(aSizes, aCVsSize);
|
|
|
|
}
|
|
|
|
|
2018-03-22 21:20:41 +03:00
|
|
|
} // namespace mozilla
|