Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1289200 - Adds GridAreas to grid css dev tools API. r=bz, mats
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwerth committed Aug 23, 2016
1 parent 227fef5 commit aea5633
Show file tree
Hide file tree
Showing 17 changed files with 556 additions and 28 deletions.
43 changes: 42 additions & 1 deletion dom/grid/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

#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)
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)
Expand Down Expand Up @@ -43,6 +44,40 @@ Grid::Grid(nsISupports* aParent,
aFrame->GetComputedTemplateColumnLines();
mCols->SetTrackInfo(columnTrackInfo);
mCols->SetLineInfo(columnTrackInfo, columnLineInfo);

// Add implicit areas first.
nsGridContainerFrame::ImplicitNamedAreas* implicitAreas =
aFrame->GetImplicitNamedAreas();
if (implicitAreas) {
for (auto iter = implicitAreas->Iter(); !iter.Done(); iter.Next()) {
nsStringHashKey* entry = iter.Get();

GridArea* area = new GridArea(this,
nsString(entry->GetKey()),
GridDeclaration::Implicit,
0,
0,
0,
0);
mAreas.AppendElement(area);
}
}

// Add explicit areas next.
nsGridContainerFrame::ExplicitNamedAreas* explicitAreas =
aFrame->GetExplicitNamedAreas();
if (explicitAreas) {
for (auto areaInfo : *explicitAreas) {
GridArea* area = new GridArea(this,
areaInfo.mName,
GridDeclaration::Explicit,
areaInfo.mRowStart,
areaInfo.mRowEnd,
areaInfo.mColumnStart,
areaInfo.mColumnEnd);
mAreas.AppendElement(area);
}
}
}

Grid::~Grid()
Expand All @@ -67,5 +102,11 @@ Grid::Cols() const
return mCols;
}

void
Grid::GetAreas(nsTArray<RefPtr<GridArea>>& aAreas) const
{
aAreas = mAreas;
}

} // namespace dom
} // namespace mozilla
3 changes: 3 additions & 0 deletions dom/grid/Grid.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef mozilla_dom_Grid_h
#define mozilla_dom_Grid_h

#include "GridArea.h"
#include "mozilla/dom/Element.h"
#include "nsGridContainerFrame.h"
#include "nsISupports.h"
Expand Down Expand Up @@ -38,11 +39,13 @@ class Grid : public nsISupports

GridDimension* Rows() const;
GridDimension* Cols() const;
void GetAreas(nsTArray<RefPtr<GridArea>>& aAreas) const;

protected:
nsCOMPtr<Element> mParent;
RefPtr<GridDimension> mRows;
RefPtr<GridDimension> mCols;
nsTArray<RefPtr<GridArea>> mAreas;
};

} // namespace dom
Expand Down
86 changes: 86 additions & 0 deletions dom/grid/GridArea.cpp
Original file line number Diff line number Diff line change
@@ -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<JSObject*> 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
63 changes: 63 additions & 0 deletions dom/grid/GridArea.h
Original file line number Diff line number Diff line change
@@ -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<JSObject*> 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<Grid> 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 */
15 changes: 12 additions & 3 deletions dom/grid/GridLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ 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");
Expand Down Expand Up @@ -57,22 +58,30 @@ GridLine::Breadth() const
return mBreadth;
}

GridDeclaration
GridLine::Type() const
{
return mType;
}

uint32_t
GridLine::Number() const
{
return mNumber;
}

void
GridLine::SetLineValues(double aStart,
GridLine::SetLineValues(const nsTArray<nsString>& aNames,
double aStart,
double aBreadth,
uint32_t aNumber,
const nsTArray<nsString>& aNames)
GridDeclaration aType)
{
mNames = aNames;
mStart = aStart;
mBreadth = aBreadth;
mNumber = aNumber;
mNames = aNames;
mType = aType;
}

} // namespace dom
Expand Down
10 changes: 7 additions & 3 deletions dom/grid/GridLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef mozilla_dom_GridLine_h
#define mozilla_dom_GridLine_h

#include "mozilla/dom/GridBinding.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
Expand Down Expand Up @@ -39,19 +40,22 @@ class GridLine : public nsISupports

double Start() const;
double Breadth() const;
GridDeclaration Type() const;
uint32_t Number() const;

void SetLineValues(double aStart,
void SetLineValues(const nsTArray<nsString>& aNames,
double aStart,
double aBreadth,
uint32_t aNumber,
const nsTArray<nsString>& aNames);
GridDeclaration aType);

protected:
RefPtr<GridLines> mParent;
nsTArray<nsString> mNames;
double mStart;
double mBreadth;
GridDeclaration mType;
uint32_t mNumber;
nsTArray<nsString> mNames;
};

} // namespace dom
Expand Down
13 changes: 12 additions & 1 deletion dom/grid/GridLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,22 @@ GridLines::SetLineInfo(const ComputedGridTrackInfo* aTrackInfo,
}

line->SetLineValues(
lineNames,
nsPresContext::AppUnitsToDoubleCSSPixels(endOfLastTrack),
nsPresContext::AppUnitsToDoubleCSSPixels(startOfNextTrack -
endOfLastTrack),
i + 1,
lineNames
(
// 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) {
Expand Down
6 changes: 3 additions & 3 deletions dom/grid/GridTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ GridTrack::GridTrack(GridTracks* aParent)
: mParent(aParent)
, mStart(0.0)
, mBreadth(0.0)
, mType(GridTrackType::Implicit)
, mType(GridDeclaration::Implicit)
, mState(GridTrackState::Static)
{
MOZ_ASSERT(aParent, "Should never be instantiated with a null GridTracks");
Expand Down Expand Up @@ -52,7 +52,7 @@ GridTrack::Breadth() const
return mBreadth;
}

GridTrackType
GridDeclaration
GridTrack::Type() const
{
return mType;
Expand All @@ -67,7 +67,7 @@ GridTrack::State() const
void
GridTrack::SetTrackValues(double aStart,
double aBreadth,
GridTrackType aType,
GridDeclaration aType,
GridTrackState aState)
{
mStart = aStart;
Expand Down
9 changes: 6 additions & 3 deletions dom/grid/GridTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ class GridTrack : public nsISupports

double Start() const;
double Breadth() const;
GridTrackType Type() const;
GridDeclaration Type() const;
GridTrackState State() const;

void SetTrackValues(double aStart, double aBreadth, GridTrackType aType, GridTrackState aState);
void SetTrackValues(double aStart,
double aBreadth,
GridDeclaration aType,
GridTrackState aState);

protected:
RefPtr<GridTracks> mParent;
double mStart;
double mBreadth;
GridTrackType mType;
GridDeclaration mType;
GridTrackState mState;
};

Expand Down
Loading

0 comments on commit aea5633

Please sign in to comment.