From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- dom/grid/Grid.cpp | 122 ++++++++ dom/grid/Grid.h | 54 ++++ dom/grid/GridArea.cpp | 86 ++++++ dom/grid/GridArea.h | 63 ++++ dom/grid/GridDimension.cpp | 72 +++++ dom/grid/GridDimension.h | 59 ++++ dom/grid/GridLine.cpp | 88 ++++++ dom/grid/GridLine.h | 64 ++++ dom/grid/GridLines.cpp | 250 +++++++++++++++ dom/grid/GridLines.h | 62 ++++ dom/grid/GridTrack.cpp | 80 +++++ dom/grid/GridTrack.h | 58 ++++ dom/grid/GridTracks.cpp | 134 ++++++++ dom/grid/GridTracks.h | 55 ++++ dom/grid/moz.build | 33 ++ dom/grid/test/chrome.ini | 7 + dom/grid/test/chrome/test_grid_areas.html | 143 +++++++++ dom/grid/test/chrome/test_grid_fragmentation.html | 88 ++++++ dom/grid/test/chrome/test_grid_implicit.html | 250 +++++++++++++++ dom/grid/test/chrome/test_grid_lines.html | 117 +++++++ dom/grid/test/chrome/test_grid_object.html | 69 +++++ dom/grid/test/chrome/test_grid_repeats.html | 358 ++++++++++++++++++++++ dom/grid/test/chrome/test_grid_tracks.html | 85 +++++ 23 files changed, 2397 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.ini create mode 100644 dom/grid/test/chrome/test_grid_areas.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_lines.html create mode 100644 dom/grid/test/chrome/test_grid_object.html create mode 100644 dom/grid/test/chrome/test_grid_repeats.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 000000000..d10d8b581 --- /dev/null +++ b/dom/grid/Grid.cpp @@ -0,0 +1,122 @@ +/* -*- 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/GridBinding.h" +#include "nsGridContainerFrame.h" + +namespace mozilla { +namespace dom { + +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Grid, mParent, mRows, mCols, mAreas) +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)) + , mRows(new GridDimension(this)) + , mCols(new GridDimension(this)) +{ + MOZ_ASSERT(aFrame, + "Should never be instantiated with a null nsGridContainerFrame"); + + // 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. + nsTHashtable namesSeen; + nsGridContainerFrame::ImplicitNamedAreas* implicitAreas = + aFrame->GetImplicitNamedAreas(); + if (implicitAreas) { + for (auto iter = implicitAreas->Iter(); !iter.Done(); iter.Next()) { + auto& areaInfo = iter.Data(); + namesSeen.PutEntry(areaInfo.mName); + GridArea* area = new GridArea(this, + areaInfo.mName, + GridDeclaration::Implicit, + areaInfo.mRowStart, + areaInfo.mRowEnd, + areaInfo.mColumnStart, + areaInfo.mColumnEnd); + 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. + nsGridContainerFrame::ExplicitNamedAreas* explicitAreas = + aFrame->GetExplicitNamedAreas(); + if (explicitAreas) { + for (auto& areaInfo : *explicitAreas) { + if (!namesSeen.Contains(areaInfo.mName)) { + GridArea* area = new GridArea(this, + areaInfo.mName, + GridDeclaration::Explicit, + areaInfo.mRowStart, + areaInfo.mRowEnd, + areaInfo.mColumnStart, + areaInfo.mColumnEnd); + 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() +{ +} + +JSObject* +Grid::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridBinding::Wrap(aCx, this, aGivenProto); +} + +GridDimension* +Grid::Rows() const +{ + return mRows; +} + +GridDimension* +Grid::Cols() const +{ + return mCols; +} + +void +Grid::GetAreas(nsTArray>& aAreas) const +{ + aAreas = mAreas; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/grid/Grid.h b/dom/grid/Grid.h new file mode 100644 index 000000000..426f33ec2 --- /dev/null +++ b/dom/grid/Grid.h @@ -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/. */ + +#ifndef mozilla_dom_Grid_h +#define mozilla_dom_Grid_h + +#include "GridArea.h" +#include "mozilla/dom/Element.h" +#include "nsGridContainerFrame.h" +#include "nsISupports.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +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_SCRIPT_HOLDER_CLASS(Grid) + + virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; + Element* GetParentObject() + { + return mParent; + } + + GridDimension* Rows() const; + GridDimension* Cols() const; + void GetAreas(nsTArray>& aAreas) const; + +protected: + nsCOMPtr mParent; + RefPtr mRows; + RefPtr mCols; + nsTArray> mAreas; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_Grid_h */ diff --git a/dom/grid/GridArea.cpp b/dom/grid/GridArea.cpp new file mode 100644 index 000000000..d8a7eca76 --- /dev/null +++ b/dom/grid/GridArea.cpp @@ -0,0 +1,86 @@ +/* -*- 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 { +namespace 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, + const nsString& 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() +{ +} + +JSObject* +GridArea::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridAreaBinding::Wrap(aCx, this, aGivenProto); +} + +void +GridArea::GetName(nsString& aName) const +{ + aName = mName; +} + +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 dom +} // namespace mozilla diff --git a/dom/grid/GridArea.h b/dom/grid/GridArea.h new file mode 100644 index 000000000..19b610ca2 --- /dev/null +++ b/dom/grid/GridArea.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_GridArea_h +#define mozilla_dom_GridArea_h + +#include "mozilla/dom/GridBinding.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +class Grid; + +class GridArea : public nsISupports + , public nsWrapperCache +{ +public: + explicit GridArea(Grid *aParent, + const nsString& 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_SCRIPT_HOLDER_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 nsString mName; + const GridDeclaration mType; + const uint32_t mRowStart; + const uint32_t mRowEnd; + const uint32_t mColumnStart; + const uint32_t mColumnEnd; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_GridTrack_h */ diff --git a/dom/grid/GridDimension.cpp b/dom/grid/GridDimension.cpp new file mode 100644 index 000000000..040f3a380 --- /dev/null +++ b/dom/grid/GridDimension.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 "GridDimension.h" + +#include "Grid.h" +#include "GridLines.h" +#include "GridTracks.h" +#include "mozilla/dom/GridBinding.h" +#include "nsGridContainerFrame.h" + +namespace mozilla { +namespace 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() +{ +} + +JSObject* +GridDimension::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridDimensionBinding::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 dom +} // namespace mozilla diff --git a/dom/grid/GridDimension.h b/dom/grid/GridDimension.h new file mode 100644 index 000000000..7a3373521 --- /dev/null +++ b/dom/grid/GridDimension.h @@ -0,0 +1,59 @@ +/* -*- 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" + +namespace mozilla { + +struct ComputedGridTrackInfo; + +namespace dom { + +class Grid; +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_SCRIPT_HOLDER_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 000000000..8e1e5ed7c --- /dev/null +++ b/dom/grid/GridLine.cpp @@ -0,0 +1,88 @@ +/* -*- 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" + +namespace mozilla { +namespace 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) +{ + MOZ_ASSERT(aParent, "Should never be instantiated with a null GridLines"); +} + +GridLine::~GridLine() +{ +} + +void +GridLine::GetNames(nsTArray& aNames) const +{ + aNames = mNames; +} + +JSObject* +GridLine::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridLineBinding::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; +} + +void +GridLine::SetLineValues(const nsTArray& aNames, + double aStart, + double aBreadth, + uint32_t aNumber, + GridDeclaration aType) +{ + mNames = aNames; + mStart = aStart; + mBreadth = aBreadth; + mNumber = aNumber; + mType = aType; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/grid/GridLine.h b/dom/grid/GridLine.h new file mode 100644 index 000000000..858f9d5e0 --- /dev/null +++ b/dom/grid/GridLine.h @@ -0,0 +1,64 @@ +/* -*- 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" + +namespace mozilla { +namespace 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_SCRIPT_HOLDER_CLASS(GridLine) + + void GetNames(nsTArray& aNames) const; + + 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; + + void SetLineValues(const nsTArray& aNames, + double aStart, + double aBreadth, + uint32_t aNumber, + GridDeclaration aType); + +protected: + RefPtr mParent; + nsTArray mNames; + double mStart; + double mBreadth; + GridDeclaration mType; + uint32_t mNumber; +}; + +} // namespace dom +} // namespace mozilla + +#endif /* mozilla_dom_GridLine_h */ diff --git a/dom/grid/GridLines.cpp b/dom/grid/GridLines.cpp new file mode 100644 index 000000000..fac645c64 --- /dev/null +++ b/dom/grid/GridLines.cpp @@ -0,0 +1,250 @@ +/* -*- 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 "nsGridContainerFrame.h" + +namespace mozilla { +namespace 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() +{ +} + +JSObject* +GridLines::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridLinesBinding::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]; +} + +void +GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + const nsTArray>& aAreas, + bool aIsRow) +{ + MOZ_ASSERT(aLineInfo); + mLines.Clear(); + + if (!aTrackInfo) { + return; + } + + uint32_t trackCount = aTrackInfo->mEndFragmentTrack - + aTrackInfo->mStartFragmentTrack; + + // If there is at least one track, line count is one more + // than the number of tracks. + if (trackCount > 0) { + nscoord lastTrackEdge = 0; + nscoord startOfNextTrack; + uint32_t repeatIndex = 0; + uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length(); + uint32_t numAddedLines = 0; + + for (uint32_t i = aTrackInfo->mStartFragmentTrack; + i < aTrackInfo->mEndFragmentTrack + 1; + i++) { + uint32_t line1Index = i + 1; + + startOfNextTrack = (i < aTrackInfo->mEndFragmentTrack) ? + aTrackInfo->mPositions[i] : + lastTrackEdge; + + nsTArray lineNames; + lineNames = aLineInfo->mNames.SafeElementAt(i, nsTArray()); + + // Add in names from grid areas where this line is used as a boundary. + for (auto area : aAreas) { + 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 && !lineNames.Contains(nameToAdd)) { + lineNames.AppendElement(nameToAdd); + } + } + + if (i >= aTrackInfo->mRepeatFirstTrack && + repeatIndex < numRepeatTracks) { + numAddedLines += AppendRemovedAutoFits(aTrackInfo, + aLineInfo, + lastTrackEdge, + repeatIndex, + numRepeatTracks, + lineNames); + } + + RefPtr line = new GridLine(this); + mLines.AppendElement(line); + line->SetLineValues( + lineNames, + nsPresContext::AppUnitsToDoubleCSSPixels(lastTrackEdge), + nsPresContext::AppUnitsToDoubleCSSPixels(startOfNextTrack - + lastTrackEdge), + line1Index + numAddedLines, + ( + // Implicit if there are no explicit tracks, or if the index + // is before the first explicit track, or after + // a track beyond the last explicit track. + (aTrackInfo->mNumExplicitTracks == 0) || + (i < aTrackInfo->mNumLeadingImplicitTracks) || + (i > aTrackInfo->mNumLeadingImplicitTracks + + aTrackInfo->mNumExplicitTracks) ? + GridDeclaration::Implicit : + GridDeclaration::Explicit + ) + ); + + if (i < aTrackInfo->mEndFragmentTrack) { + lastTrackEdge = aTrackInfo->mPositions[i] + aTrackInfo->mSizes[i]; + } + } + } +} + +uint32_t +GridLines::AppendRemovedAutoFits(const ComputedGridTrackInfo* aTrackInfo, + const ComputedGridLineInfo* aLineInfo, + nscoord aLastTrackEdge, + uint32_t& aRepeatIndex, + uint32_t aNumRepeatTracks, + nsTArray& aLineNames) +{ + // Check to see if lineNames contains ALL of the before line names. + bool alreadyHasBeforeLineNames = true; + for (const auto& beforeName : aLineInfo->mNamesBefore) { + if (!aLineNames.Contains(beforeName)) { + alreadyHasBeforeLineNames = false; + break; + } + } + + 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; + } + + // If this is the second or later time through, or didn't already + // have before names, add them. + if (linesAdded > 0 || !alreadyHasBeforeLineNames) { + aLineNames.AppendElements(aLineInfo->mNamesBefore); + } + + RefPtr line = new GridLine(this); + mLines.AppendElement(line); + line->SetLineValues( + aLineNames, + nsPresContext::AppUnitsToDoubleCSSPixels(aLastTrackEdge), + nsPresContext::AppUnitsToDoubleCSSPixels(0), + aTrackInfo->mRepeatFirstTrack + aRepeatIndex + 1, + 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; + aRepeatIndex++; + + linesAdded++; + } + aRepeatIndex++; + + if (extractedExplicitLineNames) { + // Pass on the explicit names we saved to the next explicit line. + aLineNames.AppendElements(explicitLineNames); + } + + if (alreadyHasBeforeLineNames && linesAdded > 0) { + // If we started with before names, pass them on to the next explicit + // line. + aLineNames.AppendElements(aLineInfo->mNamesBefore); + } + return linesAdded; +} + +} // namespace dom +} // namespace mozilla diff --git a/dom/grid/GridLines.h b/dom/grid/GridLines.h new file mode 100644 index 000000000..921168204 --- /dev/null +++ b/dom/grid/GridLines.h @@ -0,0 +1,62 @@ +/* -*- 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 "nsTArray.h" +#include "nsWrapperCache.h" + +namespace mozilla { +namespace dom { + +class GridDimension; +class GridLine; + +class GridLines : public nsISupports + , public nsWrapperCache +{ +public: + explicit GridLines(GridDimension* aParent); + +protected: + virtual ~GridLines(); + +public: + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_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, + 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 000000000..328af7d5c --- /dev/null +++ b/dom/grid/GridTrack.cpp @@ -0,0 +1,80 @@ +/* -*- 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 { +namespace 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() +{ +} + +JSObject* +GridTrack::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridTrackBinding::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 dom +} // namespace mozilla diff --git a/dom/grid/GridTrack.h b/dom/grid/GridTrack.h new file mode 100644 index 000000000..d1825c5ad --- /dev/null +++ b/dom/grid/GridTrack.h @@ -0,0 +1,58 @@ +/* -*- 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 { +namespace 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_SCRIPT_HOLDER_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 dom +} // namespace mozilla + +#endif /* mozilla_dom_GridTrack_h */ diff --git a/dom/grid/GridTracks.cpp b/dom/grid/GridTracks.cpp new file mode 100644 index 000000000..8b607973c --- /dev/null +++ b/dom/grid/GridTracks.cpp @@ -0,0 +1,134 @@ +/* -*- 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 { +namespace 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() +{ +} + +JSObject* +GridTracks::WrapObject(JSContext* aCx, JS::Handle aGivenProto) +{ + return GridTracksBinding::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 dom +} // namespace mozilla diff --git a/dom/grid/GridTracks.h b/dom/grid/GridTracks.h new file mode 100644 index 000000000..ab7faeacd --- /dev/null +++ b/dom/grid/GridTracks.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_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_SCRIPT_HOLDER_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 000000000..96d5c3151 --- /dev/null +++ b/dom/grid/moz.build @@ -0,0 +1,33 @@ +# -*- 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/. + +MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini'] + +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.ini b/dom/grid/test/chrome.ini new file mode 100644 index 000000000..2241cf9eb --- /dev/null +++ b/dom/grid/test/chrome.ini @@ -0,0 +1,7 @@ +[chrome/test_grid_areas.html] +[chrome/test_grid_fragmentation.html] +[chrome/test_grid_implicit.html] +[chrome/test_grid_lines.html] +[chrome/test_grid_object.html] +[chrome/test_grid_repeats.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 000000000..2f5d8ea44 --- /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_fragmentation.html b/dom/grid/test/chrome/test_grid_fragmentation.html new file mode 100644 index 000000000..cec03b12c --- /dev/null +++ b/dom/grid/test/chrome/test_grid_fragmentation.html @@ -0,0 +1,88 @@ + + + + + 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 000000000..c7782e0e5 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_implicit.html @@ -0,0 +1,250 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
D
+
+ +
+ +
+
A
+
+ +
+ +
+
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 000000000..3f98f3ca0 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_lines.html @@ -0,0 +1,117 @@ + + + + + + + + + + + + +
+
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 000000000..b68152b61 --- /dev/null +++ b/dom/grid/test/chrome/test_grid_object.html @@ -0,0 +1,69 @@ + + + + + + + + + + + + +
+
A
+
B
+
C
+
D
+
E
+
F
+
G
+
H
+
+ + + diff --git a/dom/grid/test/chrome/test_grid_repeats.html b/dom/grid/test/chrome/test_grid_repeats.html new file mode 100644 index 000000000..34ae7da4e --- /dev/null +++ b/dom/grid/test/chrome/test_grid_repeats.html @@ -0,0 +1,358 @@ + + + + + + + + + + + + +
+
B
+
+ +
+
+
B
+
C
+
+ +
+
+
B
+
C
+
D
+
+ +
+
+
A
+
+ +
+
+
+ +
+
+
B
+
+ +
+
+
B
+
+ +
+
+
+ +
+
+
B
+
E
+
+ +
+
+
B
+
E
+
+ + + 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 000000000..9b58cd50d --- /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