From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/grid/Grid.cpp | 119 ++++ dom/grid/Grid.h | 51 ++ dom/grid/GridArea.cpp | 51 ++ dom/grid/GridArea.h | 55 ++ dom/grid/GridDimension.cpp | 54 ++ dom/grid/GridDimension.h | 57 ++ dom/grid/GridLine.cpp | 72 +++ dom/grid/GridLine.h | 63 ++ dom/grid/GridLines.cpp | 372 ++++++++++++ dom/grid/GridLines.h | 65 +++ dom/grid/GridTrack.cpp | 54 ++ dom/grid/GridTrack.h | 50 ++ dom/grid/GridTracks.cpp | 108 ++++ dom/grid/GridTracks.h | 51 ++ dom/grid/moz.build | 36 ++ dom/grid/test/chrome.toml | 23 + dom/grid/test/chrome/test_grid_areas.html | 143 +++++ dom/grid/test/chrome/test_grid_equality.html | 57 ++ dom/grid/test/chrome/test_grid_fragmentation.html | 86 +++ dom/grid/test/chrome/test_grid_implicit.html | 390 +++++++++++++ dom/grid/test/chrome/test_grid_line_numbers.html | 122 ++++ dom/grid/test/chrome/test_grid_lines.html | 104 ++++ dom/grid/test/chrome/test_grid_object.html | 114 ++++ .../test/chrome/test_grid_repeat_auto_fill.html | 648 +++++++++++++++++++++ .../test/chrome/test_grid_repeat_auto_fit.html | 614 +++++++++++++++++++ dom/grid/test/chrome/test_grid_subtree_dirty.html | 56 ++ dom/grid/test/chrome/test_grid_tracks.html | 85 +++ 27 files changed, 3700 insertions(+) create mode 100644 dom/grid/Grid.cpp create mode 100644 dom/grid/Grid.h create mode 100644 dom/grid/GridArea.cpp create mode 100644 dom/grid/GridArea.h create mode 100644 dom/grid/GridDimension.cpp create mode 100644 dom/grid/GridDimension.h create mode 100644 dom/grid/GridLine.cpp create mode 100644 dom/grid/GridLine.h create mode 100644 dom/grid/GridLines.cpp create mode 100644 dom/grid/GridLines.h create mode 100644 dom/grid/GridTrack.cpp create mode 100644 dom/grid/GridTrack.h create mode 100644 dom/grid/GridTracks.cpp create mode 100644 dom/grid/GridTracks.h create mode 100644 dom/grid/moz.build create mode 100644 dom/grid/test/chrome.toml create mode 100644 dom/grid/test/chrome/test_grid_areas.html create mode 100644 dom/grid/test/chrome/test_grid_equality.html create mode 100644 dom/grid/test/chrome/test_grid_fragmentation.html create mode 100644 dom/grid/test/chrome/test_grid_implicit.html create mode 100644 dom/grid/test/chrome/test_grid_line_numbers.html create mode 100644 dom/grid/test/chrome/test_grid_lines.html create mode 100644 dom/grid/test/chrome/test_grid_object.html create mode 100644 dom/grid/test/chrome/test_grid_repeat_auto_fill.html create mode 100644 dom/grid/test/chrome/test_grid_repeat_auto_fit.html create mode 100644 dom/grid/test/chrome/test_grid_subtree_dirty.html create mode 100644 dom/grid/test/chrome/test_grid_tracks.html (limited to 'dom/grid') diff --git a/dom/grid/Grid.cpp b/dom/grid/Grid.cpp new file mode 100644 index 0000000000..bda04abe4d --- /dev/null +++ b/dom/grid/Grid.cpp @@ -0,0 +1,119 @@ +/* -*- 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/. */ + +#include "Grid.h" + +#include "GridArea.h" +#include "GridDimension.h" +#include "mozilla/dom/Element.h" +#include "mozilla/dom/GridBinding.h" +#include "nsGridContainerFrame.h" +#include "nsTHashSet.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Grid) + +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Grid) + tmp->ForgetFrame(); + NS_IMPL_CYCLE_COLLECTION_UNLINK(mParent, mRows, mCols, mAreas) + NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER +NS_IMPL_CYCLE_COLLECTION_UNLINK_END + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Grid) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParent, mRows, mCols, mAreas) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(Grid) +NS_IMPL_CYCLE_COLLECTING_RELEASE(Grid) + +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Grid) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +Grid::Grid(nsISupports* aParent, nsGridContainerFrame* aFrame) + : mParent(do_QueryInterface(aParent)), + mFrame(aFrame), + mRows(new GridDimension(this)), + mCols(new GridDimension(this)) { + MOZ_ASSERT(aFrame, + "Should never be instantiated with a null nsGridContainerFrame"); + + aFrame->SetProperty(nsGridContainerFrame::GridFragmentInfo(), this); + + // Construct areas first, because lines may need to reference them + // to extract additional names for boundary lines. + + // Add implicit areas first. Track the names that we add here, because + // we will ignore future explicit areas with the same name. + nsTHashSet> namesSeen; + nsGridContainerFrame::ImplicitNamedAreas* implicitAreas = + aFrame->GetImplicitNamedAreas(); + if (implicitAreas) { + for (auto iter = implicitAreas->iter(); !iter.done(); iter.next()) { + auto& areaInfo = iter.get().value(); + namesSeen.Insert(areaInfo.name.AsAtom()); + GridArea* area = + new GridArea(this, areaInfo.name.AsAtom(), GridDeclaration::Implicit, + areaInfo.rows.start, areaInfo.rows.end, + areaInfo.columns.start, areaInfo.columns.end); + mAreas.AppendElement(area); + } + } + + // Add explicit areas next, as long as they don't have the same name + // as the implicit areas, because the implicit values override what was + // initially available in the explicit areas. + if (auto* explicitAreas = aFrame->GetExplicitNamedAreas()) { + for (auto& areaInfo : explicitAreas->AsSpan()) { + if (!namesSeen.Contains(areaInfo.name.AsAtom())) { + GridArea* area = new GridArea( + this, areaInfo.name.AsAtom(), GridDeclaration::Explicit, + areaInfo.rows.start, areaInfo.rows.end, areaInfo.columns.start, + areaInfo.columns.end); + mAreas.AppendElement(area); + } + } + } + + // Now construct the tracks and lines. + const ComputedGridTrackInfo* rowTrackInfo = aFrame->GetComputedTemplateRows(); + const ComputedGridLineInfo* rowLineInfo = + aFrame->GetComputedTemplateRowLines(); + mRows->SetTrackInfo(rowTrackInfo); + mRows->SetLineInfo(rowTrackInfo, rowLineInfo, mAreas, true); + + const ComputedGridTrackInfo* columnTrackInfo = + aFrame->GetComputedTemplateColumns(); + const ComputedGridLineInfo* columnLineInfo = + aFrame->GetComputedTemplateColumnLines(); + mCols->SetTrackInfo(columnTrackInfo); + mCols->SetLineInfo(columnTrackInfo, columnLineInfo, mAreas, false); +} + +Grid::~Grid() = default; + +JSObject* Grid::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { + return Grid_Binding::Wrap(aCx, this, aGivenProto); +} + +void Grid::ForgetFrame() { + if (mFrame.IsAlive()) { + mFrame->RemoveProperty(nsGridContainerFrame::GridFragmentInfo()); + mFrame.Clear(mFrame->PresContext()->GetPresShell()); + } +} + +GridDimension* Grid::Rows() const { return mRows; } + +GridDimension* Grid::Cols() const { return mCols; } + +void Grid::GetAreas(nsTArray>& aAreas) const { + aAreas = mAreas.Clone(); +} + +} // namespace mozilla::dom diff --git a/dom/grid/Grid.h b/dom/grid/Grid.h new file mode 100644 index 0000000000..d69aa2fe45 --- /dev/null +++ b/dom/grid/Grid.h @@ -0,0 +1,51 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_Grid_h +#define mozilla_dom_Grid_h + +#include "GridArea.h" +#include "nsGridContainerFrame.h" +#include "nsISupports.h" +#include "nsWrapperCache.h" + +namespace mozilla::dom { + +class Element; +class GridDimension; + +class Grid : public nsISupports, public nsWrapperCache { + public: + explicit Grid(nsISupports* aParent, nsGridContainerFrame* aFrame); + + protected: + virtual ~Grid(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(Grid) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + Element* GetParentObject() { return mParent; } + + void ForgetFrame(); + + GridDimension* Rows() const; + GridDimension* Cols() const; + void GetAreas(nsTArray>& aAreas) const; + + protected: + nsCOMPtr mParent; + WeakFrame mFrame; + RefPtr mRows; + RefPtr mCols; + nsTArray> mAreas; +}; + +} // namespace mozilla::dom + +#endif /* mozilla_dom_Grid_h */ diff --git a/dom/grid/GridArea.cpp b/dom/grid/GridArea.cpp new file mode 100644 index 0000000000..fb87bd5b2d --- /dev/null +++ b/dom/grid/GridArea.cpp @@ -0,0 +1,51 @@ +/* -*- 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/. */ + +#include "GridArea.h" +#include "mozilla/dom/GridBinding.h" +#include "Grid.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridArea, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridArea) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridArea) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridArea) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridArea::GridArea(Grid* aParent, nsAtom* aName, GridDeclaration aType, + uint32_t aRowStart, uint32_t aRowEnd, uint32_t aColumnStart, + uint32_t aColumnEnd) + : mParent(aParent), + mName(aName), + mType(aType), + mRowStart(aRowStart), + mRowEnd(aRowEnd), + mColumnStart(aColumnStart), + mColumnEnd(aColumnEnd) {} + +GridArea::~GridArea() = default; + +JSObject* GridArea::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridArea_Binding::Wrap(aCx, this, aGivenProto); +} + +void GridArea::GetName(nsString& aName) const { mName->ToString(aName); } + +GridDeclaration GridArea::Type() const { return mType; } + +uint32_t GridArea::RowStart() const { return mRowStart; } + +uint32_t GridArea::RowEnd() const { return mRowEnd; } + +uint32_t GridArea::ColumnStart() const { return mColumnStart; } + +uint32_t GridArea::ColumnEnd() const { return mColumnEnd; } + +} // namespace mozilla::dom diff --git a/dom/grid/GridArea.h b/dom/grid/GridArea.h new file mode 100644 index 0000000000..64734f7d91 --- /dev/null +++ b/dom/grid/GridArea.h @@ -0,0 +1,55 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridArea_h +#define mozilla_dom_GridArea_h + +#include "mozilla/dom/GridBinding.h" +#include "nsWrapperCache.h" + +class nsAtom; + +namespace mozilla::dom { + +class Grid; + +class GridArea : public nsISupports, public nsWrapperCache { + public: + explicit GridArea(Grid* aParent, nsAtom* aName, GridDeclaration aType, + uint32_t aRowStart, uint32_t aRowEnd, uint32_t aColumnStart, + uint32_t aColumnEnd); + + protected: + virtual ~GridArea(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridArea) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + Grid* GetParentObject() { return mParent; } + + void GetName(nsString& aName) const; + GridDeclaration Type() const; + uint32_t RowStart() const; + uint32_t RowEnd() const; + uint32_t ColumnStart() const; + uint32_t ColumnEnd() const; + + protected: + RefPtr mParent; + const RefPtr mName; + const GridDeclaration mType; + const uint32_t mRowStart; + const uint32_t mRowEnd; + const uint32_t mColumnStart; + const uint32_t mColumnEnd; +}; + +} // namespace mozilla::dom + +#endif /* mozilla_dom_GridTrack_h */ diff --git a/dom/grid/GridDimension.cpp b/dom/grid/GridDimension.cpp new file mode 100644 index 0000000000..f7dd997283 --- /dev/null +++ b/dom/grid/GridDimension.cpp @@ -0,0 +1,54 @@ +/* -*- 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/. */ + +#include "GridDimension.h" + +#include "Grid.h" +#include "GridLines.h" +#include "GridTracks.h" +#include "mozilla/dom/GridBinding.h" +#include "nsGridContainerFrame.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridDimension, mParent, mLines, mTracks) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridDimension) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridDimension) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridDimension) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridDimension::GridDimension(Grid* aParent) + : mParent(aParent), + mLines(new GridLines(this)), + mTracks(new GridTracks(this)) { + MOZ_ASSERT(aParent, "Should never be instantiated with a null Grid"); +} + +GridDimension::~GridDimension() = default; + +JSObject* GridDimension::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridDimension_Binding::Wrap(aCx, this, aGivenProto); +} + +GridLines* GridDimension::Lines() const { return mLines; } + +GridTracks* GridDimension::Tracks() const { return mTracks; } + +void GridDimension::SetTrackInfo(const ComputedGridTrackInfo* aTrackInfo) { + mTracks->SetTrackInfo(aTrackInfo); +} + +void GridDimension::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + const nsTArray>& aAreas, + bool aIsRow) { + mLines->SetLineInfo(aTrackInfo, aLineInfo, aAreas, aIsRow); +} + +} // namespace mozilla::dom diff --git a/dom/grid/GridDimension.h b/dom/grid/GridDimension.h new file mode 100644 index 0000000000..9d3b6174c7 --- /dev/null +++ b/dom/grid/GridDimension.h @@ -0,0 +1,57 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridDimension_h +#define mozilla_dom_GridDimension_h + +#include "nsWrapperCache.h" +#include "nsTArray.h" + +namespace mozilla { + +struct ComputedGridLineInfo; +struct ComputedGridTrackInfo; + +namespace dom { + +class Grid; +class GridArea; +class GridLines; +class GridTracks; + +class GridDimension : public nsISupports, public nsWrapperCache { + public: + explicit GridDimension(Grid* aParent); + + protected: + virtual ~GridDimension(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridDimension) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + Grid* GetParentObject() { return mParent; } + + GridLines* Lines() const; + GridTracks* Tracks() const; + + void SetTrackInfo(const ComputedGridTrackInfo* aTrackInfo); + void SetLineInfo(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + const nsTArray>& aAreas, bool aIsRow); + + protected: + RefPtr mParent; + RefPtr mLines; + RefPtr mTracks; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_GridDimension_h */ diff --git a/dom/grid/GridLine.cpp b/dom/grid/GridLine.cpp new file mode 100644 index 0000000000..ce65b5bbd8 --- /dev/null +++ b/dom/grid/GridLine.cpp @@ -0,0 +1,72 @@ +/* -*- 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/. */ + +#include "GridLine.h" + +#include "GridLines.h" +#include "mozilla/dom/GridBinding.h" +#include "nsAtom.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridLine, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridLine) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridLine) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridLine) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridLine::GridLine(GridLines* aParent) + : mParent(aParent), + mStart(0.0), + mBreadth(0.0), + mType(GridDeclaration::Implicit), + mNumber(0), + mNegativeNumber(0) { + MOZ_ASSERT(aParent, "Should never be instantiated with a null GridLines"); +} + +GridLine::~GridLine() = default; + +void GridLine::GetNames(nsTArray& aNames) const { + aNames.SetCapacity(mNames.Length()); + for (auto& name : mNames) { + aNames.AppendElement(nsDependentAtomString(name)); + } +} + +JSObject* GridLine::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridLine_Binding::Wrap(aCx, this, aGivenProto); +} + +double GridLine::Start() const { return mStart; } + +double GridLine::Breadth() const { return mBreadth; } + +GridDeclaration GridLine::Type() const { return mType; } + +uint32_t GridLine::Number() const { return mNumber; } + +int32_t GridLine::NegativeNumber() const { return mNegativeNumber; } + +void GridLine::SetLineValues(const nsTArray>& aNames, + double aStart, double aBreadth, uint32_t aNumber, + int32_t aNegativeNumber, GridDeclaration aType) { + mNames = aNames.Clone(); + mStart = aStart; + mBreadth = aBreadth; + mNumber = aNumber; + mNegativeNumber = aNegativeNumber; + mType = aType; +} + +void GridLine::SetLineNames(const nsTArray>& aNames) { + mNames = aNames.Clone(); +} + +} // namespace mozilla::dom diff --git a/dom/grid/GridLine.h b/dom/grid/GridLine.h new file mode 100644 index 0000000000..bcc3325583 --- /dev/null +++ b/dom/grid/GridLine.h @@ -0,0 +1,63 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridLine_h +#define mozilla_dom_GridLine_h + +#include "mozilla/dom/GridBinding.h" +#include "nsString.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +class nsAtom; + +namespace mozilla::dom { + +class GridLines; + +class GridLine : public nsISupports, public nsWrapperCache { + public: + explicit GridLine(GridLines* aParent); + + protected: + virtual ~GridLine(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridLine) + + void GetNames(nsTArray& aNames) const; + const nsTArray>& Names() const { return mNames; } + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + GridLines* GetParentObject() { return mParent; } + + double Start() const; + double Breadth() const; + GridDeclaration Type() const; + uint32_t Number() const; + int32_t NegativeNumber() const; + + void SetLineValues(const nsTArray>& aNames, double aStart, + double aBreadth, uint32_t aNumber, int32_t aNegativeNumber, + GridDeclaration aType); + + void SetLineNames(const nsTArray>& aNames); + + protected: + RefPtr mParent; + nsTArray> mNames; + double mStart; + double mBreadth; + GridDeclaration mType; + uint32_t mNumber; + int32_t mNegativeNumber; +}; + +} // namespace mozilla::dom + +#endif /* mozilla_dom_GridLine_h */ diff --git a/dom/grid/GridLines.cpp b/dom/grid/GridLines.cpp new file mode 100644 index 0000000000..4610f18eab --- /dev/null +++ b/dom/grid/GridLines.cpp @@ -0,0 +1,372 @@ +/* -*- 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/. */ + +#include "GridLines.h" + +#include "GridDimension.h" +#include "GridLine.h" +#include "mozilla/dom/GridBinding.h" +#include "mozilla/dom/GridArea.h" +#include "nsGridContainerFrame.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridLines, mParent, mLines) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridLines) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridLines) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridLines) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridLines::GridLines(GridDimension* aParent) : mParent(aParent) { + MOZ_ASSERT(aParent, "Should never be instantiated with a null GridDimension"); +} + +GridLines::~GridLines() = default; + +JSObject* GridLines::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridLines_Binding::Wrap(aCx, this, aGivenProto); +} + +uint32_t GridLines::Length() const { return mLines.Length(); } + +GridLine* GridLines::Item(uint32_t aIndex) { + return mLines.SafeElementAt(aIndex); +} + +GridLine* GridLines::IndexedGetter(uint32_t aIndex, bool& aFound) { + aFound = aIndex < mLines.Length(); + if (!aFound) { + return nullptr; + } + return mLines[aIndex]; +} + +static void AddLineNameIfNotPresent(nsTArray>& aLineNames, + nsAtom* aName) { + if (!aLineNames.Contains(aName)) { + aLineNames.AppendElement(aName); + } +} + +static void AddLineNamesIfNotPresent(nsTArray>& aLineNames, + const nsTArray>& aNames) { + for (const auto& name : aNames) { + AddLineNameIfNotPresent(aLineNames, name); + } +} + +void GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + const nsTArray>& aAreas, + bool aIsRow) { + MOZ_ASSERT(aLineInfo); + mLines.Clear(); + + if (!aTrackInfo) { + return; + } + + uint32_t lineCount = + aTrackInfo->mEndFragmentTrack - aTrackInfo->mStartFragmentTrack + 1; + + // If there is at least one track, line count is one more + // than the number of tracks. + if (lineCount > 0) { + nscoord lastTrackEdge = 0; + nscoord startOfNextTrack; + uint32_t repeatIndex = 0; + uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length(); + uint32_t numAddedLines = 0; + + // For the calculation of negative line numbers, we need to know + // the total number of leading implicit and explicit tracks. + // This might be different from the number of tracks sizes in + // aTrackInfo, because some of those tracks may be auto-fits that + // have been removed. + uint32_t leadingTrackCount = + aTrackInfo->mNumLeadingImplicitTracks + aTrackInfo->mNumExplicitTracks; + if (numRepeatTracks > 0) { + for (auto& removedTrack : aTrackInfo->mRemovedRepeatTracks) { + if (removedTrack) { + ++leadingTrackCount; + } + } + } + + for (uint32_t i = aTrackInfo->mStartFragmentTrack; + i < aTrackInfo->mEndFragmentTrack + 1; i++) { + // Since line indexes are 1-based, calculate a 1-based value + // for this track to simplify some calculations. + const uint32_t line1Index = i + 1; + + startOfNextTrack = (i < aTrackInfo->mEndFragmentTrack) + ? aTrackInfo->mPositions[i] + : lastTrackEdge; + + // Get the line names for the current line. aLineInfo->mNames + // may contain duplicate names. This is intentional, since grid + // layout works fine with duplicate names, and we don't want to + // detect and remove duplicates in layout since it is an O(n^2) + // problem. We do the work here since this is only run when + // requested by devtools, and slowness here will not affect + // normal browsing. + nsTArray> empty{}; + const nsTArray>& possiblyDuplicateLineNames( + aLineInfo->mNames.SafeElementAt(i, empty)); + + nsTArray> lineNames; + AddLineNamesIfNotPresent(lineNames, possiblyDuplicateLineNames); + + // Add in names from grid areas where this line is used as a boundary. + for (auto area : aAreas) { + // We specifically ignore line names from implicitly named areas, + // because it can be confusing for designers who might naturally use + // a named line of "-start" or "-end" and create an implicit named + // area without meaning to. + if (area->Type() == GridDeclaration::Implicit) { + continue; + } + + bool haveNameToAdd = false; + nsAutoString nameToAdd; + area->GetName(nameToAdd); + if (aIsRow) { + if (area->RowStart() == line1Index) { + haveNameToAdd = true; + nameToAdd.AppendLiteral("-start"); + } else if (area->RowEnd() == line1Index) { + haveNameToAdd = true; + nameToAdd.AppendLiteral("-end"); + } + } else { + if (area->ColumnStart() == line1Index) { + haveNameToAdd = true; + nameToAdd.AppendLiteral("-start"); + } else if (area->ColumnEnd() == line1Index) { + haveNameToAdd = true; + nameToAdd.AppendLiteral("-end"); + } + } + + if (haveNameToAdd) { + RefPtr name = NS_Atomize(nameToAdd); + AddLineNameIfNotPresent(lineNames, name); + } + } + + if (i >= (aTrackInfo->mRepeatFirstTrack + + aTrackInfo->mNumLeadingImplicitTracks) && + repeatIndex < numRepeatTracks) { + numAddedLines += AppendRemovedAutoFits( + aTrackInfo, aLineInfo, lastTrackEdge, repeatIndex, numRepeatTracks, + leadingTrackCount, lineNames); + } + + // If this line is the one that ends a repeat, then add + // in the mNamesFollowingRepeat names from aLineInfo. + if (numRepeatTracks > 0 && i == (aTrackInfo->mRepeatFirstTrack + + aTrackInfo->mNumLeadingImplicitTracks + + numRepeatTracks - numAddedLines)) { + AddLineNamesIfNotPresent(lineNames, aLineInfo->mNamesFollowingRepeat); + } + + RefPtr line = new GridLine(this); + mLines.AppendElement(line); + MOZ_ASSERT(line1Index > 0, "line1Index must be positive."); + bool isBeforeFirstExplicit = + (line1Index <= aTrackInfo->mNumLeadingImplicitTracks); + bool isAfterLastExplicit = line1Index > (leadingTrackCount + 1); + // Calculate an actionable line number for this line, that could be used + // in a css grid property to align a grid item or area at that line. + // For implicit lines that appear before line 1, report a number of 0. + // We can't report negative indexes, because those have a different + // meaning in the css grid spec (negative indexes are negative-1-based + // from the end of the grid decreasing towards the front). + uint32_t lineNumber = isBeforeFirstExplicit + ? 0 + : (line1Index + numAddedLines - + aTrackInfo->mNumLeadingImplicitTracks); + + // The negativeNumber is counted back from the leadingTrackCount. + int32_t lineNegativeNumber = + isAfterLastExplicit + ? 0 + : (line1Index + numAddedLines - (leadingTrackCount + 2)); + GridDeclaration lineType = (isBeforeFirstExplicit || isAfterLastExplicit) + ? GridDeclaration::Implicit + : GridDeclaration::Explicit; + line->SetLineValues( + lineNames, nsPresContext::AppUnitsToDoubleCSSPixels(lastTrackEdge), + nsPresContext::AppUnitsToDoubleCSSPixels(startOfNextTrack - + lastTrackEdge), + lineNumber, lineNegativeNumber, lineType); + + if (i < aTrackInfo->mEndFragmentTrack) { + lastTrackEdge = aTrackInfo->mPositions[i] + aTrackInfo->mSizes[i]; + } + } + + // Define a function that gets the mLines index for a given line number. + // This is necessary since it's possible for a line number to not be + // represented in mLines. If this is the case, then return -1. + const int32_t lineCount = mLines.Length(); + const uint32_t lastLineNumber = mLines[lineCount - 1]->Number(); + auto IndexForLineNumber = + [lineCount, lastLineNumber](uint32_t aLineNumber) -> int32_t { + if (lastLineNumber == 0) { + // None of the lines have addressable numbers, so none of them can have + // aLineNumber + return -1; + } + + int32_t possibleIndex = (int32_t)aLineNumber - 1; + if (possibleIndex < 0 || possibleIndex > lineCount - 1) { + // aLineNumber is not represented in mLines. + return -1; + } + + return possibleIndex; + }; + + // Post-processing loop for implicit grid areas. + for (const auto& area : aAreas) { + if (area->Type() == GridDeclaration::Implicit) { + // Get the appropriate indexes for the area's start and end lines as + // they are represented in mLines. + int32_t startIndex = + IndexForLineNumber(aIsRow ? area->RowStart() : area->ColumnStart()); + int32_t endIndex = + IndexForLineNumber(aIsRow ? area->RowEnd() : area->ColumnEnd()); + + // If both start and end indexes are -1, then stop here since we cannot + // reason about the naming for either lines. + if (startIndex < 0 && endIndex < 0) { + break; + } + + // Get the "-start" and "-end" line names of the grid area. + nsAutoString startLineName; + area->GetName(startLineName); + startLineName.AppendLiteral("-start"); + nsAutoString endLineName; + area->GetName(endLineName); + endLineName.AppendLiteral("-end"); + + // Get the list of existing line names for the start and end of the grid + // area. In the case where one of the start or end indexes are -1, use a + // dummy line as a substitute for the start/end line. + RefPtr dummyLine = new GridLine(this); + RefPtr areaStartLine = + startIndex > -1 ? mLines[startIndex] : dummyLine; + nsTArray> startLineNames(areaStartLine->Names().Clone()); + + RefPtr areaEndLine = + endIndex > -1 ? mLines[endIndex] : dummyLine; + nsTArray> endLineNames(areaEndLine->Names().Clone()); + + RefPtr start = NS_Atomize(startLineName); + RefPtr end = NS_Atomize(endLineName); + if (startLineNames.Contains(end) || endLineNames.Contains(start)) { + // Add the reversed line names. + AddLineNameIfNotPresent(startLineNames, end); + AddLineNameIfNotPresent(endLineNames, start); + } else { + // Add the normal line names. + AddLineNameIfNotPresent(startLineNames, start); + AddLineNameIfNotPresent(endLineNames, end); + } + + areaStartLine->SetLineNames(startLineNames); + areaEndLine->SetLineNames(endLineNames); + } + } + } +} + +uint32_t GridLines::AppendRemovedAutoFits( + const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, nscoord aLastTrackEdge, + uint32_t& aRepeatIndex, uint32_t aNumRepeatTracks, + uint32_t aNumLeadingTracks, nsTArray>& aLineNames) { + bool extractedExplicitLineNames = false; + nsTArray> explicitLineNames; + uint32_t linesAdded = 0; + while (aRepeatIndex < aNumRepeatTracks && + aTrackInfo->mRemovedRepeatTracks[aRepeatIndex]) { + // If this is not the very first call to this function, and if we + // haven't already added a line this call, pull all the explicit + // names to pass along to the next line that will be added after + // this function completes. + if (aRepeatIndex > 0 && linesAdded == 0) { + // Find the names that didn't match the before or after names, + // and extract them. + for (const auto& name : aLineNames) { + if (!aLineInfo->mNamesBefore.Contains(name) && + !aLineInfo->mNamesAfter.Contains(name)) { + explicitLineNames.AppendElement(name); + } + } + for (const auto& extractedName : explicitLineNames) { + aLineNames.RemoveElement(extractedName); + } + extractedExplicitLineNames = true; + } + + AddLineNamesIfNotPresent(aLineNames, aLineInfo->mNamesBefore); + + RefPtr line = new GridLine(this); + mLines.AppendElement(line); + + // Time to calculate the line numbers. For the positive numbers + // we count with a 1-based index from mRepeatFirstTrack. Although + // this number is the index of the first repeat track AFTER all + // the leading implicit tracks, that's still what we want since + // all those leading implicit tracks have line number 0. + uint32_t lineNumber = aTrackInfo->mRepeatFirstTrack + aRepeatIndex + 1; + + // The negative number does have to account for the leading + // implicit tracks. We've been passed aNumLeadingTracks which is + // the total of the leading implicit tracks plus the explicit + // tracks. So all we have to do is subtract that number plus one + // from the 0-based index of this track. + int32_t lineNegativeNumber = + (aTrackInfo->mNumLeadingImplicitTracks + aTrackInfo->mRepeatFirstTrack + + aRepeatIndex) - + (aNumLeadingTracks + 1); + line->SetLineValues( + aLineNames, nsPresContext::AppUnitsToDoubleCSSPixels(aLastTrackEdge), + nsPresContext::AppUnitsToDoubleCSSPixels(0), lineNumber, + lineNegativeNumber, GridDeclaration::Explicit); + + // No matter what, the next line should have the after names associated + // with it. If we go through the loop again, the before names will also + // be added. + aLineNames = aLineInfo->mNamesAfter.Clone(); + aRepeatIndex++; + + linesAdded++; + } + + aRepeatIndex++; + + if (extractedExplicitLineNames) { + // Pass on the explicit names we saved to the next explicit line. + AddLineNamesIfNotPresent(aLineNames, explicitLineNames); + } + + // If we haven't finished adding auto-repeated tracks, then we need to put + // back the before names, in case we cleared them above. + if (aRepeatIndex < aNumRepeatTracks) { + AddLineNamesIfNotPresent(aLineNames, aLineInfo->mNamesBefore); + } + + return linesAdded; +} + +} // namespace mozilla::dom diff --git a/dom/grid/GridLines.h b/dom/grid/GridLines.h new file mode 100644 index 0000000000..f95993dc6d --- /dev/null +++ b/dom/grid/GridLines.h @@ -0,0 +1,65 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridLines_h +#define mozilla_dom_GridLines_h + +#include "nsCoord.h" +#include "nsTArray.h" +#include "nsWrapperCache.h" + +class nsAtom; + +namespace mozilla { + +struct ComputedGridTrackInfo; +struct ComputedGridLineInfo; + +namespace dom { + +class GridDimension; +class GridLine; +class GridArea; + +class GridLines : public nsISupports, public nsWrapperCache { + public: + explicit GridLines(GridDimension* aParent); + + protected: + virtual ~GridLines(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridLines) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + GridDimension* GetParentObject() { return mParent; } + + uint32_t Length() const; + GridLine* Item(uint32_t aIndex); + GridLine* IndexedGetter(uint32_t aIndex, bool& aFound); + + void SetLineInfo(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + const nsTArray>& aAreas, bool aIsRow); + + protected: + uint32_t AppendRemovedAutoFits(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + nscoord aLastTrackEdge, uint32_t& aRepeatIndex, + uint32_t aNumRepeatTracks, + uint32_t aNumLeadingTracks, + nsTArray>& aLineNames); + + RefPtr mParent; + nsTArray> mLines; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_GridLines_h */ diff --git a/dom/grid/GridTrack.cpp b/dom/grid/GridTrack.cpp new file mode 100644 index 0000000000..b2d9d0b3b3 --- /dev/null +++ b/dom/grid/GridTrack.cpp @@ -0,0 +1,54 @@ +/* -*- 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/. */ + +#include "GridTrack.h" + +#include "GridTracks.h" +#include "mozilla/dom/GridBinding.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridTrack, mParent) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridTrack) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridTrack) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridTrack) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridTrack::GridTrack(GridTracks* aParent) + : mParent(aParent), + mStart(0.0), + mBreadth(0.0), + mType(GridDeclaration::Implicit), + mState(GridTrackState::Static) { + MOZ_ASSERT(aParent, "Should never be instantiated with a null GridTracks"); +} + +GridTrack::~GridTrack() = default; + +JSObject* GridTrack::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridTrack_Binding::Wrap(aCx, this, aGivenProto); +} + +double GridTrack::Start() const { return mStart; } + +double GridTrack::Breadth() const { return mBreadth; } + +GridDeclaration GridTrack::Type() const { return mType; } + +GridTrackState GridTrack::State() const { return mState; } + +void GridTrack::SetTrackValues(double aStart, double aBreadth, + GridDeclaration aType, GridTrackState aState) { + mStart = aStart; + mBreadth = aBreadth; + mType = aType; + mState = aState; +} + +} // namespace mozilla::dom diff --git a/dom/grid/GridTrack.h b/dom/grid/GridTrack.h new file mode 100644 index 0000000000..fa78c2d5d0 --- /dev/null +++ b/dom/grid/GridTrack.h @@ -0,0 +1,50 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridTrack_h +#define mozilla_dom_GridTrack_h + +#include "mozilla/dom/GridBinding.h" +#include "nsWrapperCache.h" + +namespace mozilla::dom { + +class GridTracks; + +class GridTrack : public nsISupports, public nsWrapperCache { + public: + explicit GridTrack(GridTracks* parent); + + protected: + virtual ~GridTrack(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridTrack) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + GridTracks* GetParentObject() { return mParent; } + + double Start() const; + double Breadth() const; + GridDeclaration Type() const; + GridTrackState State() const; + + void SetTrackValues(double aStart, double aBreadth, GridDeclaration aType, + GridTrackState aState); + + protected: + RefPtr mParent; + double mStart; + double mBreadth; + GridDeclaration mType; + GridTrackState mState; +}; + +} // namespace mozilla::dom + +#endif /* mozilla_dom_GridTrack_h */ diff --git a/dom/grid/GridTracks.cpp b/dom/grid/GridTracks.cpp new file mode 100644 index 0000000000..f3f4b98961 --- /dev/null +++ b/dom/grid/GridTracks.cpp @@ -0,0 +1,108 @@ +/* -*- 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/. */ + +#include "GridTracks.h" + +#include "GridDimension.h" +#include "GridTrack.h" +#include "mozilla/dom/GridBinding.h" +#include "nsGridContainerFrame.h" + +namespace mozilla::dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridTracks, mParent, mTracks) +NS_IMPL_CYCLE_COLLECTING_ADDREF(GridTracks) +NS_IMPL_CYCLE_COLLECTING_RELEASE(GridTracks) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridTracks) + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY + NS_INTERFACE_MAP_ENTRY(nsISupports) +NS_INTERFACE_MAP_END + +GridTracks::GridTracks(GridDimension* aParent) : mParent(aParent) { + MOZ_ASSERT(aParent, "Should never be instantiated with a null GridDimension"); +} + +GridTracks::~GridTracks() = default; + +JSObject* GridTracks::WrapObject(JSContext* aCx, + JS::Handle aGivenProto) { + return GridTracks_Binding::Wrap(aCx, this, aGivenProto); +} + +uint32_t GridTracks::Length() const { return mTracks.Length(); } + +GridTrack* GridTracks::Item(uint32_t aIndex) { + return mTracks.SafeElementAt(aIndex); +} + +GridTrack* GridTracks::IndexedGetter(uint32_t aIndex, bool& aFound) { + aFound = aIndex < mTracks.Length(); + if (!aFound) { + return nullptr; + } + return mTracks[aIndex]; +} + +void GridTracks::SetTrackInfo(const ComputedGridTrackInfo* aTrackInfo) { + // rebuild the tracks based on aTrackInfo + mTracks.Clear(); + + if (!aTrackInfo) { + return; + } + + nscoord lastTrackEdge = 0; + uint32_t repeatIndex = 0; + auto AppendRemovedAutoFits = [this, &aTrackInfo, &lastTrackEdge, + &repeatIndex]() { + uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length(); + // Add in removed auto-fit tracks + while (repeatIndex < numRepeatTracks && + aTrackInfo->mRemovedRepeatTracks[repeatIndex]) { + RefPtr track = new GridTrack(this); + mTracks.AppendElement(track); + track->SetTrackValues( + nsPresContext::AppUnitsToDoubleCSSPixels(lastTrackEdge), + nsPresContext::AppUnitsToDoubleCSSPixels(0), + GridDeclaration::Explicit, GridTrackState::Removed); + repeatIndex++; + } + repeatIndex++; + }; + + for (size_t i = aTrackInfo->mStartFragmentTrack; + i < aTrackInfo->mEndFragmentTrack; i++) { + if (i >= aTrackInfo->mRepeatFirstTrack) { + // Append removed auto-fit tracks, if appropriate. The + // AppendRemovedAutoFits function exits early once it has been called + // aTrackInfo->mRemovedRepeatTracks.Length() times -- a check we don't + // replicate here or at subsequent calling sites. + AppendRemovedAutoFits(); + } + + RefPtr track = new GridTrack(this); + mTracks.AppendElement(track); + track->SetTrackValues( + nsPresContext::AppUnitsToDoubleCSSPixels(aTrackInfo->mPositions[i]), + nsPresContext::AppUnitsToDoubleCSSPixels(aTrackInfo->mSizes[i]), + ( + // Implicit if index is before the first explicit track, or after + // the last explicit track. + (i < aTrackInfo->mNumLeadingImplicitTracks) || + (i >= aTrackInfo->mNumLeadingImplicitTracks + + aTrackInfo->mNumExplicitTracks) + ? GridDeclaration::Implicit + : GridDeclaration::Explicit), + GridTrackState(aTrackInfo->mStates[i])); + + lastTrackEdge = aTrackInfo->mPositions[i] + aTrackInfo->mSizes[i]; + } + + // Append any trailing removed auto-fit tracks. + AppendRemovedAutoFits(); +} + +} // namespace mozilla::dom diff --git a/dom/grid/GridTracks.h b/dom/grid/GridTracks.h new file mode 100644 index 0000000000..d20da5e12b --- /dev/null +++ b/dom/grid/GridTracks.h @@ -0,0 +1,51 @@ +/* -*- 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/. */ + +#ifndef mozilla_dom_GridTracks_h +#define mozilla_dom_GridTracks_h + +#include "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { + +struct ComputedGridTrackInfo; + +namespace dom { + +class GridDimension; +class GridTrack; + +class GridTracks : public nsISupports, public nsWrapperCache { + public: + explicit GridTracks(GridDimension* aParent); + + protected: + virtual ~GridTracks(); + + public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(GridTracks) + + virtual JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + GridDimension* GetParentObject() { return mParent; } + + uint32_t Length() const; + GridTrack* Item(uint32_t aIndex); + GridTrack* IndexedGetter(uint32_t aIndex, bool& aFound); + + void SetTrackInfo(const mozilla::ComputedGridTrackInfo* aTrackInfo); + + protected: + RefPtr mParent; + nsTArray> mTracks; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_GridTracks_h */ diff --git a/dom/grid/moz.build b/dom/grid/moz.build new file mode 100644 index 0000000000..d90a421317 --- /dev/null +++ b/dom/grid/moz.build @@ -0,0 +1,36 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +with Files("**"): + BUG_COMPONENT = ("Core", "CSS Parsing and Computation") + +MOCHITEST_CHROME_MANIFESTS += ["test/chrome.toml"] + +EXPORTS.mozilla.dom += [ + "Grid.h", + "GridArea.h", + "GridDimension.h", + "GridLine.h", + "GridLines.h", + "GridTrack.h", + "GridTracks.h", +] + +UNIFIED_SOURCES += [ + "Grid.cpp", + "GridArea.cpp", + "GridDimension.cpp", + "GridLine.cpp", + "GridLines.cpp", + "GridTrack.cpp", + "GridTracks.cpp", +] + +LOCAL_INCLUDES += [ + "/layout/generic", +] + +FINAL_LIBRARY = "xul" diff --git a/dom/grid/test/chrome.toml b/dom/grid/test/chrome.toml new file mode 100644 index 0000000000..47aba99351 --- /dev/null +++ b/dom/grid/test/chrome.toml @@ -0,0 +1,23 @@ +[DEFAULT] + +["chrome/test_grid_areas.html"] + +["chrome/test_grid_equality.html"] + +["chrome/test_grid_fragmentation.html"] + +["chrome/test_grid_implicit.html"] + +["chrome/test_grid_line_numbers.html"] + +["chrome/test_grid_lines.html"] + +["chrome/test_grid_object.html"] + +["chrome/test_grid_repeat_auto_fill.html"] + +["chrome/test_grid_repeat_auto_fit.html"] + +["chrome/test_grid_subtree_dirty.html"] + +["chrome/test_grid_tracks.html"] diff --git a/dom/grid/test/chrome/test_grid_areas.html b/dom/grid/test/chrome/test_grid_areas.html new file mode 100644 index 0000000000..22c7cc53dd --- /dev/null +++ b/dom/grid/test/chrome/test_grid_areas.html @@ -0,0 +1,143 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_equality.html b/dom/grid/test/chrome/test_grid_equality.html new file mode 100644 index 0000000000..741f54d016 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_equality.html @@ -0,0 +1,57 @@ + + + + + + + + + + +
+
+
+ + diff --git a/dom/grid/test/chrome/test_grid_fragmentation.html b/dom/grid/test/chrome/test_grid_fragmentation.html new file mode 100644 index 0000000000..f9a28ee1a9 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_fragmentation.html @@ -0,0 +1,86 @@ + + + + + CSS Grid Test: Fragmentation of height:auto grid, not top-of-page + + + + + + + + + + + + + +
+
+
+ + + + +
+ + + diff --git a/dom/grid/test/chrome/test_grid_implicit.html b/dom/grid/test/chrome/test_grid_implicit.html new file mode 100644 index 0000000000..82f3284dad --- /dev/null +++ b/dom/grid/test/chrome/test_grid_implicit.html @@ -0,0 +1,390 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
D
+
+ +
+ +
+
A
+
+ +
+ +
+
C
+
+ +
+
E
+
+ +
+
F
+
G
+
+
+
H
+
+ + diff --git a/dom/grid/test/chrome/test_grid_line_numbers.html b/dom/grid/test/chrome/test_grid_line_numbers.html new file mode 100644 index 0000000000..b5c5b5e534 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_line_numbers.html @@ -0,0 +1,122 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
+ +
+
A
+
B
+
C
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_lines.html b/dom/grid/test/chrome/test_grid_lines.html new file mode 100644 index 0000000000..c8fa8b6850 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_lines.html @@ -0,0 +1,104 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
D
+
E
+
F
+
G
+
H
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_object.html b/dom/grid/test/chrome/test_grid_object.html new file mode 100644 index 0000000000..ab8b9abfa0 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_object.html @@ -0,0 +1,114 @@ + + + + + + + + + + + + +
+
A
+
+ +
+ a fieldset + + +
+ + + +
+
A
+
+ +
+ a fieldset + + +
+ + + + + diff --git a/dom/grid/test/chrome/test_grid_repeat_auto_fill.html b/dom/grid/test/chrome/test_grid_repeat_auto_fill.html new file mode 100644 index 0000000000..4a558c434a --- /dev/null +++ b/dom/grid/test/chrome/test_grid_repeat_auto_fill.html @@ -0,0 +1,648 @@ + + + + + + + + + + + + +
+
B
+
+ +
+
+
B
+
C
+
+ +
+
+
B
+
C
+
D
+
+ +
+
+
A
+
+ +
+
+
+ +
+
+
B
+
+ +
+
+
B
+
+ +
+
+
+ +
+
+
F
+
+ +
+
+
B
+
E
+
x
+
+ +
+
+
B
+
E
+
y
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_repeat_auto_fit.html b/dom/grid/test/chrome/test_grid_repeat_auto_fit.html new file mode 100644 index 0000000000..6643521d43 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_repeat_auto_fit.html @@ -0,0 +1,614 @@ + + + + + + + + + + + + +
+
B
+
+ +
+
+
B
+
C
+
+ +
+
+
B
+
C
+
D
+
+ +
+
+
A
+
+ +
+
+
+ +
+
+
B
+
+ +
+
+
B
+
+ +
+
+
+ +
+
+
F
+
+ +
+
+
B
+
E
+
+ +
+
+
B
+
E
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_subtree_dirty.html b/dom/grid/test/chrome/test_grid_subtree_dirty.html new file mode 100644 index 0000000000..4baa94872e --- /dev/null +++ b/dom/grid/test/chrome/test_grid_subtree_dirty.html @@ -0,0 +1,56 @@ + + + + + + + + + + +
+
+
+
+
+ PASS +
+
+
+
+
+ + diff --git a/dom/grid/test/chrome/test_grid_tracks.html b/dom/grid/test/chrome/test_grid_tracks.html new file mode 100644 index 0000000000..39697ef799 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_tracks.html @@ -0,0 +1,85 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
D
+
E
+
F
+
G
+
H
+
+ + + -- cgit v1.2.3