Backed out 4 changesets (bug 1559814) for causing bustages. CLOSED TREE

Backed out changeset 11ec9de59076 (bug 1559814)
Backed out changeset fec03c5d3661 (bug 1559814)
Backed out changeset 62f9d89fb827 (bug 1559814)
Backed out changeset 362d9435ca4e (bug 1559814)
This commit is contained in:
Mihai Alexandru Michis 2019-06-27 00:04:50 +03:00
Родитель c8de244aee
Коммит 0f86a6b30b
17 изменённых файлов: 286 добавлений и 214 удалений

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

@ -39,16 +39,13 @@ using namespace mozilla;
typedef nsAbsoluteContainingBlock::AbsPosReflowFlags AbsPosReflowFlags;
typedef nsGridContainerFrame::TrackSize TrackSize;
const uint32_t nsGridContainerFrame::kTranslatedMaxLine =
uint32_t(nsStyleGridLine::kMaxLine - nsStyleGridLine::kMinLine);
const uint32_t nsGridContainerFrame::kAutoLine = kTranslatedMaxLine + 3457U;
typedef nsTHashtable<nsPtrHashKey<nsIFrame>> FrameHashtable;
typedef mozilla::CSSAlignUtils::AlignJustifyFlags AlignJustifyFlags;
typedef nsLayoutUtils::IntrinsicISizeType IntrinsicISizeType;
static const int32_t kMaxLine = StyleMAX_GRID_LINE;
static const int32_t kMinLine = StyleMIN_GRID_LINE;
// The maximum line number, in the zero-based translated grid.
static const uint32_t kTranslatedMaxLine = uint32_t(kMaxLine - kMinLine);
static const uint32_t kAutoLine = kTranslatedMaxLine + 3457U;
static const nsFrameState kIsSubgridBits =
(NS_STATE_GRID_IS_COL_SUBGRID | NS_STATE_GRID_IS_ROW_SUBGRID);
@ -388,13 +385,17 @@ struct nsGridContainerFrame::LineRange {
#ifdef DEBUG
if (!IsAutoAuto()) {
if (IsAuto()) {
MOZ_ASSERT(aEnd >= kMinLine && aEnd <= kMaxLine, "invalid span");
MOZ_ASSERT(aEnd >= nsStyleGridLine::kMinLine &&
aEnd <= nsStyleGridLine::kMaxLine,
"invalid span");
} else {
MOZ_ASSERT(aStart >= kMinLine && aStart <= kMaxLine,
MOZ_ASSERT(aStart >= nsStyleGridLine::kMinLine &&
aStart <= nsStyleGridLine::kMaxLine,
"invalid start line");
MOZ_ASSERT(aEnd == int32_t(kAutoLine) ||
(aEnd >= kMinLine && aEnd <= kMaxLine),
"invalid end line");
MOZ_ASSERT(
aEnd == int32_t(kAutoLine) || (aEnd >= nsStyleGridLine::kMinLine &&
aEnd <= nsStyleGridLine::kMaxLine),
"invalid end line");
}
}
#endif
@ -405,7 +406,8 @@ struct nsGridContainerFrame::LineRange {
uint32_t Extent() const {
MOZ_ASSERT(mEnd != kAutoLine, "Extent is undefined for abs.pos. 'auto'");
if (IsAuto()) {
MOZ_ASSERT(mEnd >= 1 && mEnd < uint32_t(kMaxLine), "invalid span");
MOZ_ASSERT(mEnd >= 1 && mEnd < uint32_t(nsStyleGridLine::kMaxLine),
"invalid span");
return mEnd;
}
return mEnd - mStart;
@ -459,11 +461,12 @@ struct nsGridContainerFrame::LineRange {
*/
void AdjustAbsPosForRemovedTracks(
const nsTArray<uint32_t>& aNumRemovedTracks) {
if (mStart != kAutoLine) {
if (mStart != nsGridContainerFrame::kAutoLine) {
mStart -= aNumRemovedTracks[mStart];
}
if (mEnd != kAutoLine) {
MOZ_ASSERT(mStart == kAutoLine || mEnd > mStart, "invalid line range");
if (mEnd != nsGridContainerFrame::kAutoLine) {
MOZ_ASSERT(mStart == nsGridContainerFrame::kAutoLine || mEnd > mStart,
"invalid line range");
mEnd -= aNumRemovedTracks[mEnd];
}
}
@ -1355,7 +1358,7 @@ struct nsGridContainerFrame::TrackSizingFunctions {
}
// Clamp the number of repeat tracks so that the last line <= kMaxLine.
// (note that |numTracks| already includes one repeat() track)
const uint32_t maxRepeatTracks = kMaxLine - numTracks;
const uint32_t maxRepeatTracks = nsStyleGridLine::kMaxLine - numTracks;
return std::min(numRepeatTracks, maxRepeatTracks);
}
@ -1366,7 +1369,7 @@ struct nsGridContainerFrame::TrackSizingFunctions {
uint32_t ComputeExplicitGridEnd(uint32_t aGridTemplateAreasEnd) {
uint32_t end = NumExplicitTracks() + 1;
end = std::max(end, aGridTemplateAreasEnd);
end = std::min(end, uint32_t(kMaxLine));
end = std::min(end, uint32_t(nsStyleGridLine::kMaxLine));
return end;
}
@ -2538,8 +2541,8 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Grid {
* @param aGridStart the first line in the final, but untranslated grid
* @param aGridEnd the last line in the final, but untranslated grid
*/
LineRange ResolveAbsPosLineRange(const StyleGridLine& aStart,
const StyleGridLine& aEnd,
LineRange ResolveAbsPosLineRange(const nsStyleGridLine& aStart,
const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap,
LogicalAxis aAxis, uint32_t aExplicitGridEnd,
int32_t aGridStart, int32_t aGridEnd,
@ -2660,7 +2663,7 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Grid {
* @return a definite line (1-based), clamped to
* the mClampMinLine..mClampMaxLine range
*/
int32_t ResolveLine(const StyleGridLine& aLine, int32_t aNth,
int32_t ResolveLine(const nsStyleGridLine& aLine, int32_t aNth,
uint32_t aFromIndex, const LineNameMap& aNameMap,
LogicalSide aSide, uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle);
@ -2671,8 +2674,8 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Grid {
* @return a pair (start,end) of lines
*/
typedef std::pair<int32_t, int32_t> LinePair;
LinePair ResolveLineRangeHelper(const StyleGridLine& aStart,
const StyleGridLine& aEnd,
LinePair ResolveLineRangeHelper(const nsStyleGridLine& aStart,
const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap,
LogicalAxis aAxis, uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle);
@ -2691,8 +2694,8 @@ struct MOZ_STACK_CLASS nsGridContainerFrame::Grid {
* @param aExplicitGridEnd the last line in the explicit grid
* @param aStyle the StylePosition() for the grid container
*/
LineRange ResolveLineRange(const StyleGridLine& aStart,
const StyleGridLine& aEnd,
LineRange ResolveLineRange(const nsStyleGridLine& aStart,
const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap, LogicalAxis aAxis,
uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle);
@ -3331,7 +3334,8 @@ void nsGridContainerFrame::AddImplicitNamedAreas(
const nsTArray<nsTArray<RefPtr<nsAtom>>>& aLineNameLists) {
// http://dev.w3.org/csswg/css-grid/#implicit-named-areas
// Note: recording these names for fast lookup later is just an optimization.
const uint32_t len = std::min(aLineNameLists.Length(), size_t(kMaxLine));
const uint32_t len =
std::min(aLineNameLists.Length(), size_t(nsStyleGridLine::kMaxLine));
nsTHashtable<nsStringHashKey> currentStarts;
ImplicitNamedAreas* areas = GetImplicitNamedAreas();
for (uint32_t i = 0; i < len; ++i) {
@ -3379,12 +3383,12 @@ void nsGridContainerFrame::InitImplicitNamedAreas(
}
int32_t nsGridContainerFrame::Grid::ResolveLine(
const StyleGridLine& aLine, int32_t aNth, uint32_t aFromIndex,
const nsStyleGridLine& aLine, int32_t aNth, uint32_t aFromIndex,
const LineNameMap& aNameMap, LogicalSide aSide, uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle) {
MOZ_ASSERT(!aLine.IsAuto());
int32_t line = 0;
if (aLine.LineName()->IsEmpty()) {
if (aLine.mLineName->IsEmpty()) {
MOZ_ASSERT(aNth != 0, "css-grid 9.2: <integer> must not be zero.");
line = int32_t(aFromIndex) + aNth;
} else {
@ -3392,16 +3396,16 @@ int32_t nsGridContainerFrame::Grid::ResolveLine(
// <integer> was omitted; treat it as 1.
aNth = 1;
}
bool isNameOnly = !aLine.is_span && aLine.line_num == 0;
bool isNameOnly = !aLine.mHasSpan && aLine.mInteger == 0;
if (isNameOnly) {
AutoTArray<uint32_t, 16> implicitLines;
aNameMap.FindNamedAreas(aLine.ident.AsAtom(), aSide, implicitLines);
aNameMap.FindNamedAreas(aLine.mLineName, aSide, implicitLines);
if (!implicitLines.IsEmpty() ||
aNameMap.HasImplicitNamedArea(aLine.LineName())) {
aNameMap.HasImplicitNamedArea(aLine.mLineName)) {
// aName is a named area - look for explicit lines named
// <name>-start/-end depending on which side we're resolving.
// http://dev.w3.org/csswg/css-grid/#grid-placement-slot
nsAutoString lineName(nsDependentAtomString(aLine.LineName()));
nsAutoString lineName(nsDependentAtomString(aLine.mLineName));
if (IsStart(aSide)) {
lineName.AppendLiteral("-start");
} else {
@ -3413,25 +3417,25 @@ int32_t nsGridContainerFrame::Grid::ResolveLine(
}
if (line == 0) {
// If LineName() ends in -start/-end, try the prefix as a named area.
// If mLineName ends in -start/-end, try the prefix as a named area.
AutoTArray<uint32_t, 16> implicitLines;
uint32_t index;
bool useStart = IsNameWithStartSuffix(aLine.LineName(), &index);
if (useStart || IsNameWithEndSuffix(aLine.LineName(), &index)) {
bool useStart = IsNameWithStartSuffix(aLine.mLineName, &index);
if (useStart || IsNameWithEndSuffix(aLine.mLineName, &index)) {
auto side = MakeLogicalSide(
GetAxis(aSide), useStart ? eLogicalEdgeStart : eLogicalEdgeEnd);
RefPtr<nsAtom> name = NS_Atomize(nsDependentSubstring(
nsDependentAtomString(aLine.LineName()), 0, index));
nsDependentAtomString(aLine.mLineName), 0, index));
aNameMap.FindNamedAreas(name, side, implicitLines);
}
line = aNameMap.FindNamedLine(aLine.LineName(), &aNth, aFromIndex,
line = aNameMap.FindNamedLine(aLine.mLineName, &aNth, aFromIndex,
implicitLines);
}
if (line == 0) {
MOZ_ASSERT(aNth != 0, "we found all N named lines but 'line' is zero!");
int32_t edgeLine;
if (aLine.is_span) {
if (aLine.mHasSpan) {
// http://dev.w3.org/csswg/css-grid/#grid-placement-span-int
// 'span <custom-ident> N'
edgeLine = IsStart(aSide) ? 1 : aExplicitGridEnd;
@ -3450,29 +3454,30 @@ int32_t nsGridContainerFrame::Grid::ResolveLine(
nsGridContainerFrame::Grid::LinePair
nsGridContainerFrame::Grid::ResolveLineRangeHelper(
const StyleGridLine& aStart, const StyleGridLine& aEnd,
const nsStyleGridLine& aStart, const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap, LogicalAxis aAxis, uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle) {
MOZ_ASSERT(int32_t(kAutoLine) > kMaxLine);
MOZ_ASSERT(int32_t(nsGridContainerFrame::kAutoLine) >
nsStyleGridLine::kMaxLine);
if (aStart.is_span) {
if (aEnd.is_span || aEnd.IsAuto()) {
if (aStart.mHasSpan) {
if (aEnd.mHasSpan || aEnd.IsAuto()) {
// http://dev.w3.org/csswg/css-grid/#grid-placement-errors
if (aStart.LineName()->IsEmpty()) {
if (aStart.mLineName->IsEmpty()) {
// span <integer> / span *
// span <integer> / auto
return LinePair(kAutoLine, aStart.line_num);
return LinePair(kAutoLine, aStart.mInteger);
}
// span <custom-ident> / span *
// span <custom-ident> / auto
return LinePair(kAutoLine, 1); // XXX subgrid explicit size instead of 1?
}
uint32_t from = aEnd.line_num < 0 ? aExplicitGridEnd + 1 : 0;
auto end = ResolveLine(aEnd, aEnd.line_num, from, aNameMap,
uint32_t from = aEnd.mInteger < 0 ? aExplicitGridEnd + 1 : 0;
auto end = ResolveLine(aEnd, aEnd.mInteger, from, aNameMap,
MakeLogicalSide(aAxis, eLogicalEdgeEnd),
aExplicitGridEnd, aStyle);
int32_t span = aStart.line_num == 0 ? 1 : aStart.line_num;
int32_t span = aStart.mInteger == 0 ? 1 : aStart.mInteger;
if (end <= 1) {
// The end is at or before the first explicit line, thus all lines before
// it match <custom-ident> since they're implicit.
@ -3491,19 +3496,19 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper(
// auto / auto
return LinePair(start, 1); // XXX subgrid explicit size instead of 1?
}
if (aEnd.is_span) {
if (aEnd.LineName()->IsEmpty()) {
if (aEnd.mHasSpan) {
if (aEnd.mLineName->IsEmpty()) {
// auto / span <integer>
MOZ_ASSERT(aEnd.line_num != 0);
return LinePair(start, aEnd.line_num);
MOZ_ASSERT(aEnd.mInteger != 0);
return LinePair(start, aEnd.mInteger);
}
// http://dev.w3.org/csswg/css-grid/#grid-placement-errors
// auto / span <custom-ident>
return LinePair(start, 1); // XXX subgrid explicit size instead of 1?
}
} else {
uint32_t from = aStart.line_num < 0 ? aExplicitGridEnd + 1 : 0;
start = ResolveLine(aStart, aStart.line_num, from, aNameMap,
uint32_t from = aStart.mInteger < 0 ? aExplicitGridEnd + 1 : 0;
start = ResolveLine(aStart, aStart.mInteger, from, aNameMap,
MakeLogicalSide(aAxis, eLogicalEdgeStart),
aExplicitGridEnd, aStyle);
if (aEnd.IsAuto()) {
@ -3515,10 +3520,10 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper(
}
uint32_t from;
int32_t nth = aEnd.line_num == 0 ? 1 : aEnd.line_num;
if (aEnd.is_span) {
int32_t nth = aEnd.mInteger == 0 ? 1 : aEnd.mInteger;
if (aEnd.mHasSpan) {
if (MOZ_UNLIKELY(start < 0)) {
if (aEnd.LineName()->IsEmpty()) {
if (aEnd.mLineName->IsEmpty()) {
return LinePair(start, start + nth);
}
from = 0;
@ -3531,7 +3536,7 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper(
from = start;
}
} else {
from = aEnd.line_num < 0 ? aExplicitGridEnd + 1 : 0;
from = aEnd.mInteger < 0 ? aExplicitGridEnd + 1 : 0;
}
auto end = ResolveLine(aEnd, nth, from, aNameMap,
MakeLogicalSide(aAxis, eLogicalEdgeEnd),
@ -3544,7 +3549,7 @@ nsGridContainerFrame::Grid::ResolveLineRangeHelper(
}
nsGridContainerFrame::LineRange nsGridContainerFrame::Grid::ResolveLineRange(
const StyleGridLine& aStart, const StyleGridLine& aEnd,
const nsStyleGridLine& aStart, const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap, LogicalAxis aAxis, uint32_t aExplicitGridEnd,
const nsStylePosition* aStyle) {
LinePair r = ResolveLineRangeHelper(aStart, aEnd, aNameMap, aAxis,
@ -3585,18 +3590,18 @@ nsGridContainerFrame::GridArea nsGridContainerFrame::Grid::PlaceDefinite(
nsGridContainerFrame::LineRange
nsGridContainerFrame::Grid::ResolveAbsPosLineRange(
const StyleGridLine& aStart, const StyleGridLine& aEnd,
const nsStyleGridLine& aStart, const nsStyleGridLine& aEnd,
const LineNameMap& aNameMap, LogicalAxis aAxis, uint32_t aExplicitGridEnd,
int32_t aGridStart, int32_t aGridEnd, const nsStylePosition* aStyle) {
if (aStart.IsAuto()) {
if (aEnd.IsAuto()) {
return LineRange(kAutoLine, kAutoLine);
}
uint32_t from = aEnd.line_num < 0 ? aExplicitGridEnd + 1 : 0;
int32_t end = ResolveLine(aEnd, aEnd.line_num, from, aNameMap,
uint32_t from = aEnd.mInteger < 0 ? aExplicitGridEnd + 1 : 0;
int32_t end = ResolveLine(aEnd, aEnd.mInteger, from, aNameMap,
MakeLogicalSide(aAxis, eLogicalEdgeEnd),
aExplicitGridEnd, aStyle);
if (aEnd.is_span) {
if (aEnd.mHasSpan) {
++end;
}
// A line outside the existing grid is treated as 'auto' for abs.pos (10.1).
@ -3605,11 +3610,11 @@ nsGridContainerFrame::Grid::ResolveAbsPosLineRange(
}
if (aEnd.IsAuto()) {
uint32_t from = aStart.line_num < 0 ? aExplicitGridEnd + 1 : 0;
int32_t start = ResolveLine(aStart, aStart.line_num, from, aNameMap,
uint32_t from = aStart.mInteger < 0 ? aExplicitGridEnd + 1 : 0;
int32_t start = ResolveLine(aStart, aStart.mInteger, from, aNameMap,
MakeLogicalSide(aAxis, eLogicalEdgeStart),
aExplicitGridEnd, aStyle);
if (aStart.is_span) {
if (aStart.mHasSpan) {
start = std::max(aGridEnd - start, aGridStart);
}
start = AutoIfOutside(start, aGridStart, aGridEnd);
@ -3619,7 +3624,7 @@ nsGridContainerFrame::Grid::ResolveAbsPosLineRange(
LineRange r =
ResolveLineRange(aStart, aEnd, aNameMap, aAxis, aExplicitGridEnd, aStyle);
if (r.IsAuto()) {
MOZ_ASSERT(aStart.is_span && aEnd.is_span,
MOZ_ASSERT(aStart.mHasSpan && aEnd.mHasSpan,
"span / span is the only case "
"leading to IsAuto here -- we dealt with the other cases above");
// The second span was ignored per 9.2.1. For abs.pos., 10.1 says that this
@ -3876,8 +3881,8 @@ void nsGridContainerFrame::Grid::PlaceGridItems(
// to a 0,0 based grid after placing definite lines.
const nsStylePosition* const gridStyle = aState.mGridStyle;
const auto* areas = gridStyle->mGridTemplateAreas.IsNone() ? nullptr : &*gridStyle->mGridTemplateAreas.AsAreas();
int32_t clampMinColLine = kMinLine;
int32_t clampMaxColLine = kMaxLine;
int32_t clampMinColLine = nsStyleGridLine::kMinLine;
int32_t clampMaxColLine = nsStyleGridLine::kMaxLine;
uint32_t numRepeatCols;
const LineNameMap* parentLineNameMap = nullptr;
const LineRange* subgridRange = nullptr;
@ -3913,8 +3918,9 @@ void nsGridContainerFrame::Grid::PlaceGridItems(
clampMinColLine, clampMaxColLine, parentLineNameMap, subgridRange,
subgridAxisIsSameDirection);
int32_t clampMinRowLine = kMinLine;
int32_t clampMaxRowLine = kMaxLine;
int32_t clampMinRowLine = nsStyleGridLine::kMinLine;
int32_t clampMaxRowLine = nsStyleGridLine::kMaxLine;
uint32_t numRepeatRows;
if (!aState.mFrame->IsRowSubgrid()) {
numRepeatRows = aState.mRowFunctions.InitRepeatTracks(
@ -4295,8 +4301,8 @@ void nsGridContainerFrame::Grid::PlaceGridItems(
// Resolve the lines for the area. We use the name of the area as the
// name of the lines, knowing that the line placement algorithm will
// add the -start and -end suffixes as appropriate for layout.
StyleGridLine lineStartAndEnd;
lineStartAndEnd.ident = areaInfo.name;
nsStyleGridLine lineStartAndEnd;
lineStartAndEnd.mLineName = areaInfo.name.AsAtom();
LineRange columnLines =
ResolveLineRange(lineStartAndEnd, lineStartAndEnd, colLineNameMap,

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

@ -286,6 +286,9 @@ class nsGridContainerFrame final : public nsContainerFrame {
nsGridContainerFrame* ParentGridContainerForSubgrid() const;
protected:
static const uint32_t kAutoLine;
// The maximum line number, in the zero-based translated grid.
static const uint32_t kTranslatedMaxLine;
typedef mozilla::LogicalPoint LogicalPoint;
typedef mozilla::LogicalRect LogicalRect;
typedef mozilla::LogicalSize LogicalSize;

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

@ -513,7 +513,6 @@ cbindgen-types = [
{ gecko = "StyleGenericGradient", servo = "values::generics::image::Gradient" },
{ gecko = "StyleLineDirection", servo = "values::computed::image::LineDirection" },
{ gecko = "StyleGridTemplateAreas", servo = "values::computed::position::GridTemplateAreas" },
{ gecko = "StyleGenericGridLine", servo = "values::generics::grid::GridLine" },
]
mapped-generic-types = [

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

@ -236,13 +236,7 @@ inline nsAtom* StyleAtom::AsAtom() const {
return reinterpret_cast<nsAtom*>(_0);
}
inline void StyleAtom::AddRef() {
if (!IsStatic()) {
AsAtom()->AddRef();
}
}
inline void StyleAtom::Release() {
inline StyleAtom::~StyleAtom() {
if (!IsStatic()) {
AsAtom()->Release();
}
@ -262,20 +256,11 @@ inline StyleAtom::StyleAtom(already_AddRefed<nsAtom> aAtom) {
}
inline StyleAtom::StyleAtom(const StyleAtom& aOther) : _0(aOther._0) {
AddRef();
}
inline StyleAtom& StyleAtom::operator=(const StyleAtom& aOther) {
if (MOZ_LIKELY(this != &aOther)) {
Release();
_0 = aOther._0;
AddRef();
if (!IsStatic()) {
reinterpret_cast<nsAtom*>(_0)->AddRef();
}
return *this;
}
inline StyleAtom::~StyleAtom() { Release(); }
inline nsAtom* StyleCustomIdent::AsAtom() const { return _0.AsAtom(); }
inline nsDependentCSubstring StyleOwnedStr::AsString() const {
@ -384,22 +369,6 @@ inline bool StyleComputedUrl::HasRef() const {
template <>
bool StyleGradient::IsOpaque() const;
template <typename Integer>
inline StyleGenericGridLine<Integer>::StyleGenericGridLine()
: ident(do_AddRef(static_cast<nsAtom*>(nsGkAtoms::_empty))),
line_num(0),
is_span(false) {}
template <>
inline nsAtom* StyleGridLine::LineName() const {
return ident.AsAtom();
}
template <>
inline bool StyleGridLine::IsAuto() const {
return LineName()->IsEmpty() && line_num == 0 && !is_span;
}
} // namespace mozilla
#endif

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

@ -1619,6 +1619,42 @@ already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetGridTemplateRows() {
return GetGridTemplateColumnsRows(StylePosition()->GridTemplateRows(), info);
}
already_AddRefed<CSSValue> nsComputedDOMStyle::GetGridLine(
const nsStyleGridLine& aGridLine) {
if (aGridLine.IsAuto()) {
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
val->SetIdent(eCSSKeyword_auto);
return val.forget();
}
RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
if (aGridLine.mHasSpan) {
RefPtr<nsROCSSPrimitiveValue> span = new nsROCSSPrimitiveValue;
span->SetIdent(eCSSKeyword_span);
valueList->AppendCSSValue(span.forget());
}
if (aGridLine.mInteger != 0) {
RefPtr<nsROCSSPrimitiveValue> integer = new nsROCSSPrimitiveValue;
integer->SetNumber(aGridLine.mInteger);
valueList->AppendCSSValue(integer.forget());
}
if (aGridLine.mLineName != nsGkAtoms::_empty) {
RefPtr<nsROCSSPrimitiveValue> lineName = new nsROCSSPrimitiveValue;
nsString escapedLineName;
nsStyleUtil::AppendEscapedCSSIdent(
nsDependentAtomString(aGridLine.mLineName), escapedLineName);
lineName->SetString(escapedLineName);
valueList->AppendCSSValue(lineName.forget());
}
NS_ASSERTION(valueList->Length() > 0,
"Should have appended at least one value");
return valueList.forget();
}
already_AddRefed<CSSValue> nsComputedDOMStyle::DoGetPaddingTop() {
return GetPaddingWidthFor(eSideTop);
}

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

@ -206,6 +206,7 @@ class nsComputedDOMStyle final : public nsDOMCSSDeclaration,
already_AddRefed<CSSValue> GetGridTemplateColumnsRows(
const nsStyleGridTemplate& aTrackList,
const mozilla::ComputedGridTrackInfo* aTrackInfo);
already_AddRefed<CSSValue> GetGridLine(const nsStyleGridLine& aGridLine);
bool GetLineHeightCoord(nscoord& aCoord);

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

@ -46,6 +46,9 @@
using namespace mozilla;
using namespace mozilla::dom;
/* static */ const int32_t nsStyleGridLine::kMinLine;
/* static */ const int32_t nsStyleGridLine::kMaxLine;
static const nscoord kMediumBorderWidth = nsPresContext::CSSPixelsToAppUnits(3);
// We set the size limit of style structs to 504 bytes so that when they

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

@ -945,6 +945,44 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleList {
mMozListReversed; // true in an <ol reversed> scope
};
struct nsStyleGridLine {
// http://dev.w3.org/csswg/css-grid/#typedef-grid-line
// XXXmats we could optimize memory size here
bool mHasSpan;
int32_t mInteger; // 0 means not provided
RefPtr<nsAtom> mLineName; // Empty string means not provided.
// These are the limits that we choose to clamp grid line numbers to.
// http://dev.w3.org/csswg/css-grid/#overlarge-grids
// mInteger is clamped to this range:
static const int32_t kMinLine = -10000;
static const int32_t kMaxLine = 10000;
nsStyleGridLine()
: mHasSpan(false), mInteger(0), mLineName(nsGkAtoms::_empty) {}
nsStyleGridLine(const nsStyleGridLine& aOther) { (*this) = aOther; }
void operator=(const nsStyleGridLine& aOther) {
mHasSpan = aOther.mHasSpan;
mInteger = aOther.mInteger;
mLineName = aOther.mLineName;
}
bool operator!=(const nsStyleGridLine& aOther) const {
return mHasSpan != aOther.mHasSpan || mInteger != aOther.mInteger ||
mLineName != aOther.mLineName;
}
bool IsAuto() const {
bool haveInitialValues = mInteger == 0 && mLineName == nsGkAtoms::_empty;
MOZ_ASSERT(!(haveInitialValues && mHasSpan),
"should not have 'span' when other components are "
"at their initial values");
return haveInitialValues;
}
};
// Computed value of the grid-template-columns or grid-template-rows property
// (but *not* grid-template-areas.)
// http://dev.w3.org/csswg/css-grid/#track-sizing
@ -1013,7 +1051,7 @@ struct nsStyleGridTemplate {
bool HasRepeatAuto() const { return mRepeatAutoIndex != -1; }
bool IsRepeatAutoIndex(uint32_t aIndex) const {
MOZ_ASSERT(aIndex < uint32_t(2 * mozilla::StyleMAX_GRID_LINE));
MOZ_ASSERT(aIndex < uint32_t(2 * nsStyleGridLine::kMaxLine));
return int32_t(aIndex) == mRepeatAutoIndex;
}
};
@ -1104,10 +1142,10 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStylePosition {
mozilla::StyleGridTemplateAreas mGridTemplateAreas;
mozilla::StyleGridLine mGridColumnStart;
mozilla::StyleGridLine mGridColumnEnd;
mozilla::StyleGridLine mGridRowStart;
mozilla::StyleGridLine mGridRowEnd;
nsStyleGridLine mGridColumnStart;
nsStyleGridLine mGridColumnEnd;
nsStyleGridLine mGridRowStart;
nsStyleGridLine mGridRowEnd;
mozilla::NonNegativeLengthPercentageOrNormal mColumnGap;
mozilla::NonNegativeLengthPercentageOrNormal mRowGap;

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

@ -182,7 +182,7 @@ impl<T> Arc<T> {
// FIXME(emilio): Would be so amazing to have
// std::intrinsics::type_name() around, so that we could also report
// a real size.
NS_LogCtor(ptr as *mut _, b"ServoArc\0".as_ptr() as *const _, 8);
NS_LogCtor(ptr as *const _, b"ServoArc\0".as_ptr() as *const _, 8);
}
unsafe {
@ -315,7 +315,7 @@ impl<T: ?Sized> Arc<T> {
#[cfg(feature = "gecko_refcount_logging")]
unsafe {
NS_LogDtor(
self.ptr() as *mut _,
self.ptr() as *const _,
b"ServoArc\0".as_ptr() as *const _,
8,
);
@ -355,12 +355,12 @@ impl<T: ?Sized> Arc<T> {
#[cfg(feature = "gecko_refcount_logging")]
extern "C" {
fn NS_LogCtor(
aPtr: *mut std::os::raw::c_void,
aPtr: *const std::os::raw::c_void,
aTypeName: *const std::os::raw::c_char,
aSize: u32,
);
fn NS_LogDtor(
aPtr: *mut std::os::raw::c_void,
aPtr: *const std::os::raw::c_void,
aTypeName: *const std::os::raw::c_char,
aSize: u32,
);
@ -762,7 +762,7 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
if !is_static {
// FIXME(emilio): Would be so amazing to have
// std::intrinsics::type_name() around.
NS_LogCtor(ptr as *mut _, b"ServoArc\0".as_ptr() as *const _, 8)
NS_LogCtor(ptr as *const _, b"ServoArc\0".as_ptr() as *const _, 8)
}
}

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

@ -880,8 +880,15 @@ class Side(object):
self.ident = name.lower()
self.index = index
class GridLine(object):
def __init__(self, name):
self.ident = "grid-" + name.lower()
self.name = self.ident.replace('-', '_')
self.gecko = "m" + to_camel_case(self.ident)
SIDES = [Side("Top", 0), Side("Right", 1), Side("Bottom", 2), Side("Left", 3)]
CORNERS = ["top_left", "top_right", "bottom_right", "bottom_left"]
GRID_LINES = map(GridLine, ["row-start", "row-end", "column-start", "column-end"])
%>
#[allow(dead_code)]
@ -1070,7 +1077,7 @@ fn static_assert() {
% endfor
</%self:impl_trait>
<% skip_position_longhands = " ".join(x.ident for x in SIDES) %>
<% skip_position_longhands = " ".join(x.ident for x in SIDES + GRID_LINES) %>
<%self:impl_trait style_struct_name="Position"
skip_longhands="${skip_position_longhands} order
align-content justify-content align-self
@ -1125,6 +1132,64 @@ fn static_assert() {
${impl_simple_copy('order', 'mOrder')}
% for value in GRID_LINES:
pub fn set_${value.name}(&mut self, v: longhands::${value.name}::computed_value::T) {
use crate::gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine};
let line = &mut self.gecko.${value.gecko};
line.mLineName.set_move(unsafe {
RefPtr::from_addrefed(match v.ident {
Some(i) => i.0,
None => atom!(""),
}.into_addrefed())
});
line.mHasSpan = v.is_span;
if let Some(integer) = v.line_num {
// clamping the integer between a range
line.mInteger = cmp::max(
nsStyleGridLine_kMinLine,
cmp::min(integer, nsStyleGridLine_kMaxLine),
);
}
}
pub fn copy_${value.name}_from(&mut self, other: &Self) {
self.gecko.${value.gecko}.mHasSpan = other.gecko.${value.gecko}.mHasSpan;
self.gecko.${value.gecko}.mInteger = other.gecko.${value.gecko}.mInteger;
unsafe {
self.gecko.${value.gecko}.mLineName.set(&other.gecko.${value.gecko}.mLineName);
}
}
pub fn reset_${value.name}(&mut self, other: &Self) {
self.copy_${value.name}_from(other)
}
pub fn clone_${value.name}(&self) -> longhands::${value.name}::computed_value::T {
use crate::gecko_bindings::structs::{nsStyleGridLine_kMinLine, nsStyleGridLine_kMaxLine};
longhands::${value.name}::computed_value::T {
is_span: self.gecko.${value.gecko}.mHasSpan,
ident: {
let name = unsafe { Atom::from_raw(self.gecko.${value.gecko}.mLineName.mRawPtr) };
if name == atom!("") {
None
} else {
Some(CustomIdent(name))
}
},
line_num:
if self.gecko.${value.gecko}.mInteger == 0 {
None
} else {
debug_assert!(nsStyleGridLine_kMinLine <= self.gecko.${value.gecko}.mInteger);
debug_assert!(self.gecko.${value.gecko}.mInteger <= nsStyleGridLine_kMaxLine);
Some(self.gecko.${value.gecko}.mInteger)
},
}
}
% endfor
% for kind in ["rows", "columns"]:
pub fn set_grid_auto_${kind}(&mut self, v: longhands::grid_auto_${kind}::computed_value::T) {
let gecko = &mut *self.gecko;
@ -1148,11 +1213,11 @@ fn static_assert() {
pub fn set_grid_template_${kind}(&mut self, v: longhands::grid_template_${kind}::computed_value::T) {
<% self_grid = "self.gecko.mGridTemplate%s" % kind.title() %>
use crate::gecko_bindings::structs::nsTArray;
use crate::gecko_bindings::structs::{nsTArray, nsStyleGridLine_kMaxLine};
use std::usize;
use crate::values::CustomIdent;
use crate::values::generics::grid::TrackListType::Auto;
use crate::values::generics::grid::{GridTemplateComponent, RepeatCount, MAX_GRID_LINE};
use crate::values::generics::grid::{GridTemplateComponent, RepeatCount};
#[inline]
fn set_line_names(servo_names: &[CustomIdent], gecko_names: &mut nsTArray<structs::RefPtr<structs::nsAtom>>) {
@ -1167,7 +1232,7 @@ fn static_assert() {
}
}
let max_lines = MAX_GRID_LINE as usize - 1; // for accounting the final <line-names>
let max_lines = nsStyleGridLine_kMaxLine as usize - 1; // for accounting the final <line-names>
let result = match v {
GridTemplateComponent::None => ptr::null_mut(),

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

@ -144,7 +144,6 @@
products="gecko">
use crate::values::specified::GridLine;
use crate::parser::Parse;
use crate::Zero;
// NOTE: Since both the shorthands have the same code, we should (re-)use code from one to implement
// the other. This might not be a big deal for now, but we should consider looking into this in the future
@ -158,8 +157,8 @@
GridLine::parse(context, input)?
} else {
let mut line = GridLine::auto();
if start.line_num.is_zero() && !start.is_span {
line.ident = start.ident.clone(); // ident from start value should be taken
if start.line_num.is_none() && !start.is_span {
line.ident = start.ident.clone(); // ident from start value should be taken
}
line
@ -187,7 +186,6 @@
products="gecko">
use crate::values::specified::GridLine;
use crate::parser::Parse;
use crate::Zero;
// The code is the same as `grid-{row,column}` except that this can have four values at most.
pub fn parse_value<'i, 't>(
@ -196,7 +194,7 @@
) -> Result<Longhands, ParseError<'i>> {
fn line_with_ident_from(other: &GridLine) -> GridLine {
let mut this = GridLine::auto();
if other.line_num.is_zero() && !other.is_span {
if other.line_num.is_none() && !other.is_span {
this.ident = other.ident.clone();
}

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

@ -950,8 +950,8 @@ mod gecko_leak_checking {
use std::os::raw::{c_char, c_void};
extern "C" {
fn NS_LogCtor(aPtr: *mut c_void, aTypeName: *const c_char, aSize: u32);
fn NS_LogDtor(aPtr: *mut c_void, aTypeName: *const c_char, aSize: u32);
pub fn NS_LogCtor(aPtr: *const c_void, aTypeName: *const c_char, aSize: u32);
pub fn NS_LogDtor(aPtr: *const c_void, aTypeName: *const c_char, aSize: u32);
}
static NAME: &'static [u8] = b"RuleNode\0";
@ -960,7 +960,7 @@ mod gecko_leak_checking {
pub fn log_ctor(ptr: *const RuleNode) {
let s = NAME as *const [u8] as *const u8 as *const c_char;
unsafe {
NS_LogCtor(ptr as *mut c_void, s, size_of::<RuleNode>() as u32);
NS_LogCtor(ptr as *const c_void, s, size_of::<RuleNode>() as u32);
}
}
@ -968,7 +968,7 @@ mod gecko_leak_checking {
pub fn log_dtor(ptr: *const RuleNode) {
let s = NAME as *const [u8] as *const u8 as *const c_char;
unsafe {
NS_LogDtor(ptr as *mut c_void, s, size_of::<RuleNode>() as u32);
NS_LogDtor(ptr as *const c_void, s, size_of::<RuleNode>() as u32);
}
}

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

@ -62,7 +62,10 @@ impl Animate for TrackSize {
}
}
impl Animate for generics::TrackRepeat<LengthPercentage, Integer> {
impl Animate for generics::TrackRepeat<LengthPercentage, Integer>
where
generics::RepeatCount<Integer>: PartialEq,
{
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
// If the keyword, auto-fit/fill, is the same it can result in different
// number of tracks. For both auto-fit/fill, the number of columns isn't

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

@ -7,7 +7,7 @@
use self::transform::DirectionVector;
use super::animated::ToAnimatedValue;
use super::generics::grid::GridTemplateComponent as GenericGridTemplateComponent;
use super::generics::grid::{GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
use super::generics::transform::IsParallelTo;
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative, ZeroToOne};

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

@ -5,7 +5,6 @@
//! Generic types for the handling of
//! [grids](https://drafts.csswg.org/css-grid/).
use crate::{Atom, Zero};
use crate::parser::{Parse, ParserContext};
use crate::values::computed::{Context, ToComputedValue};
use crate::values::specified;
@ -13,17 +12,9 @@ use crate::values::specified::grid::parse_line_names;
use crate::values::{CSSFloat, CustomIdent};
use cssparser::Parser;
use std::fmt::{self, Write};
use std::{cmp, mem, usize};
use std::{mem, usize};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// These are the limits that we choose to clamp grid line numbers to.
/// http://drafts.csswg.org/css-grid/#overlarge-grids
/// line_num is clamped to this range at parse time.
pub const MIN_GRID_LINE: i32 = -10000;
/// See above.
pub const MAX_GRID_LINE: i32 = 10000;
/// A `<grid-line>` type.
///
/// <https://drafts.csswg.org/css-grid/#typedef-grid-row-start-grid-line>
@ -38,48 +29,36 @@ pub const MAX_GRID_LINE: i32 = 10000;
ToResolvedValue,
ToShmem,
)]
#[repr(C)]
pub struct GenericGridLine<Integer> {
/// A custom identifier for named lines, or the empty atom otherwise.
///
/// <https://drafts.csswg.org/css-grid/#grid-placement-slot>
pub ident: Atom,
/// Denotes the nth grid line from grid item's placement.
///
/// This is clamped by MIN_GRID_LINE and MAX_GRID_LINE.
///
/// NOTE(emilio): If we ever allow animating these we need to either do
/// something more complicated for the clamping, or do this clamping at
/// used-value time.
pub line_num: Integer,
pub struct GridLine<Integer> {
/// Flag to check whether it's a `span` keyword.
pub is_span: bool,
/// A custom identifier for named lines.
///
/// <https://drafts.csswg.org/css-grid/#grid-placement-slot>
pub ident: Option<CustomIdent>,
/// Denotes the nth grid line from grid item's placement.
pub line_num: Option<Integer>,
}
pub use self::GenericGridLine as GridLine;
impl<Integer> GridLine<Integer>
where
Integer: Zero,
{
impl<Integer> GridLine<Integer> {
/// The `auto` value.
pub fn auto() -> Self {
Self {
is_span: false,
line_num: Zero::zero(),
ident: atom!(""),
line_num: None,
ident: None,
}
}
/// Check whether this `<grid-line>` represents an `auto` value.
pub fn is_auto(&self) -> bool {
self.ident == atom!("") && self.line_num.is_zero() && !self.is_span
self.ident.is_none() && self.line_num.is_none() && !self.is_span
}
}
impl<Integer> ToCss for GridLine<Integer>
where
Integer: ToCss + Zero,
Integer: ToCss,
{
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
@ -93,18 +72,18 @@ where
dest.write_str("span")?;
}
if !self.line_num.is_zero() {
if let Some(ref i) = self.line_num {
if self.is_span {
dest.write_str(" ")?;
}
self.line_num.to_css(dest)?;
i.to_css(dest)?;
}
if self.ident != atom!("") {
if self.is_span || !self.line_num.is_zero() {
if let Some(ref s) = self.ident {
if self.is_span || self.line_num.is_some() {
dest.write_str(" ")?;
}
CustomIdent(self.ident.clone()).to_css(dest)?;
s.to_css(dest)?;
}
Ok(())
@ -135,26 +114,25 @@ impl Parse for GridLine<specified::Integer> {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
if !grid_line.line_num.is_zero() || grid_line.ident != atom!("") {
if grid_line.line_num.is_some() || grid_line.ident.is_some() {
val_before_span = true;
}
grid_line.is_span = true;
} else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) {
// FIXME(emilio): Probably shouldn't reject if it's calc()...
let value = i.value();
if value == 0 || val_before_span || !grid_line.line_num.is_zero() {
if i.value() == 0 || val_before_span || grid_line.line_num.is_some() {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
grid_line.line_num = specified::Integer::new(cmp::max(MIN_GRID_LINE, cmp::min(value, MAX_GRID_LINE)));
grid_line.line_num = Some(i);
} else if let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
if val_before_span || grid_line.ident != atom!("") {
if val_before_span || grid_line.ident.is_some() {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
// NOTE(emilio): `span` is consumed above, so we only need to
// reject `auto`.
grid_line.ident = CustomIdent::from_ident(location, &name, &["auto"])?.0;
grid_line.ident = Some(CustomIdent::from_ident(location, &name, &["auto"])?);
} else {
break;
}
@ -165,12 +143,12 @@ impl Parse for GridLine<specified::Integer> {
}
if grid_line.is_span {
if !grid_line.line_num.is_zero() {
if grid_line.line_num.value() <= 0 {
if let Some(i) = grid_line.line_num {
if i.value() <= 0 {
// disallow negative integers for grid spans
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
} else if grid_line.ident == atom!("") {
} else if grid_line.ident.is_none() {
// integer could be omitted
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}

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

@ -17,9 +17,9 @@ use crate::context::QuirksMode;
use crate::parser::{Parse, ParserContext};
use crate::values::serialize_atom_identifier;
use crate::values::specified::calc::CalcNode;
use crate::{Atom, Namespace, Prefix, Zero};
use crate::{Atom, Namespace, Prefix};
use cssparser::{Parser, Token};
use num_traits::One;
use num_traits::{One, Zero};
use std::f32;
use std::fmt::{self, Write};
use std::ops::Add;
@ -449,18 +449,6 @@ pub struct Integer {
was_calc: bool,
}
impl Zero for Integer {
#[inline]
fn zero() -> Self {
Self::new(0)
}
#[inline]
fn is_zero(&self) -> bool {
self.value() == 0
}
}
impl One for Integer {
#[inline]
fn one() -> Self {

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

@ -29,7 +29,6 @@ includes = ["mozilla/ServoStyleConstsForwards.h"]
[parse]
parse_deps = true
extra_bindings = ["style"]
include = ["style", "cssparser", "style_traits", "servo_arc"]
[struct]
@ -52,10 +51,6 @@ cast_assert_name = "MOZ_ASSERT"
[export]
prefix = "Style"
exclude = [
"NS_LogCtor",
"NS_LogDtor",
]
include = [
"Appearance",
"BreakBetween",
@ -156,9 +151,8 @@ include = [
"Filter",
"Gradient",
"GridTemplateAreas",
"GridLine",
]
item_types = ["enums", "structs", "typedefs", "functions", "constants"]
item_types = ["enums", "structs", "typedefs", "functions"]
renaming_overrides_prefixing = true
# Prevent some renaming for Gecko types that cbindgen doesn't otherwise understand.
@ -468,17 +462,16 @@ renaming_overrides_prefixing = true
StyleAtom(size_t) = delete;
StyleAtom() = delete;
// NOTE(emilio): For now we don't need to expose anything else, but it'd be trivial if we wanted to.
inline bool IsStatic() const;
inline nsAtom* AsAtom() const;
private:
inline void AddRef();
inline void Release();
public:
inline explicit StyleAtom(already_AddRefed<nsAtom> aAtom);
// Could be implemented if wanted.
StyleAtom& operator=(const StyleAtom&) = delete;
inline StyleAtom(const StyleAtom& aOther);
inline StyleAtom& operator=(const StyleAtom&);
inline ~StyleAtom();
"""
@ -598,11 +591,3 @@ renaming_overrides_prefixing = true
StyleGridTemplateAreas() {}
public:
"""
"GenericGridLine" = """
// Returns the `auto` value.
inline StyleGenericGridLine();
inline bool IsAuto() const;
// The line name, or nsGkAtoms::_empty if not present.
inline nsAtom* LineName() const;
"""