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

Commit

Permalink
Bug 1241932 - Expose decoded CSS grid track properties in a Chrome AP…
Browse files Browse the repository at this point in the history
…I. r=heycam, r=khuey
  • Loading branch information
bradwerth committed Jun 24, 2016
1 parent d9be2b5 commit 5695974
Show file tree
Hide file tree
Showing 26 changed files with 1,242 additions and 24 deletions.
17 changes: 16 additions & 1 deletion dom/base/Element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/Animation.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/Grid.h"
#include "nsDOMAttributeMap.h"
#include "nsIAtom.h"
#include "nsIContentInlines.h"
Expand Down Expand Up @@ -953,7 +954,6 @@ Element::GetClientRects()
return rectList.forget();
}


//----------------------------------------------------------------------

void
Expand Down Expand Up @@ -3289,6 +3289,21 @@ Element::MozRequestPointerLock()
OwnerDoc()->RequestPointerLock(this);
}

void
Element::GetGridFragments(nsTArray<RefPtr<Grid>>& aResult)
{
nsIFrame* frame = GetPrimaryFrame();
if (frame && (frame->GetType() == nsGkAtoms::gridContainerFrame)) {
// If primary frame is a nsGridContainerFrame, all the next frames
// in flow will also be nsGridContainerFrame.
for (; frame != nullptr; frame = frame->GetNextInFlow()) {
aResult.AppendElement(
new Grid(this, static_cast<nsGridContainerFrame*>(frame))
);
}
}
}

already_AddRefed<Animation>
Element::Animate(JSContext* aContext,
JS::Handle<JSObject*> aKeyframes,
Expand Down
3 changes: 3 additions & 0 deletions dom/base/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class UndoManager;
class DOMRect;
class DOMRectList;
class DestinationInsertionPointList;
class Grid;

// IID for the dom::Element interface
#define NS_ELEMENT_IID \
Expand Down Expand Up @@ -830,6 +831,8 @@ class Element : public FragmentOrElement
0;
}

void GetGridFragments(nsTArray<RefPtr<Grid>>& aResult);

virtual already_AddRefed<UndoManager> GetUndoManager()
{
return nullptr;
Expand Down
1 change: 1 addition & 0 deletions dom/bindings/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ LOCAL_INCLUDES += [
'/dom/xul',
'/js/xpconnect/src',
'/js/xpconnect/wrappers',
'/layout/generic',
'/layout/style',
'/layout/xul/tree',
'/media/mtransport',
Expand Down
65 changes: 65 additions & 0 deletions dom/grid/Grid.cpp
Original file line number Diff line number Diff line change
@@ -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/. */

#include "Grid.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_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");

const ComputedGridTrackInfo* rowTrackInfo = aFrame->GetComputedTemplateRows();
mRows->SetTrackInfo(rowTrackInfo);
mRows->SetLineInfo(rowTrackInfo);

const ComputedGridTrackInfo* colTrackInfo = aFrame->GetComputedTemplateColumns();
mCols->SetTrackInfo(colTrackInfo);
mCols->SetLineInfo(colTrackInfo);
}

Grid::~Grid()
{
}

JSObject*
Grid::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return GridBinding::Wrap(aCx, this, aGivenProto);
}

GridDimension*
Grid::Rows() const
{
return mRows;
}

GridDimension*
Grid::Cols() const
{
return mCols;
}

} // namespace dom
} // namespace mozilla
51 changes: 51 additions & 0 deletions dom/grid/Grid.h
Original file line number Diff line number Diff line change
@@ -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 "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:
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<JSObject*> aGivenProto) override;
Element* GetParentObject()
{
return mParent;
}

GridDimension* Rows() const;
GridDimension* Cols() const;

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

} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_Grid_h */
69 changes: 69 additions & 0 deletions dom/grid/GridDimension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* -*- 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<JSObject*> 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)
{
mLines->SetLineInfo(aTrackInfo);
}

} // namespace dom
} // namespace mozilla
56 changes: 56 additions & 0 deletions dom/grid/GridDimension.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* -*- 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:
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<JSObject*> aGivenProto) override;
Grid* GetParentObject()
{
return mParent;
}

GridLines* Lines() const;
GridTracks* Tracks() const;

void SetTrackInfo(const ComputedGridTrackInfo* aTrackInfo);
void SetLineInfo(const ComputedGridTrackInfo* aTrackInfo);

protected:
RefPtr<Grid> mParent;
RefPtr<GridLines> mLines;
RefPtr<GridTracks> mTracks;
};

} // namespace dom
} // namespace mozilla

#endif /* mozilla_dom_GridDimension_h */
79 changes: 79 additions & 0 deletions dom/grid/GridLine.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* -*- 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)
, mNumber(0)
{
MOZ_ASSERT(aParent, "Should never be instantiated with a null GridLines");
}

GridLine::~GridLine()
{
}

void
GridLine::GetNames(nsTArray<nsString>& aNames) const
{
aNames = mNames;
}

JSObject*
GridLine::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
{
return GridLineBinding::Wrap(aCx, this, aGivenProto);
}

double
GridLine::Start() const
{
return mStart;
}

double
GridLine::Breadth() const
{
return mBreadth;
}

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

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

} // namespace dom
} // namespace mozilla
Loading

0 comments on commit 5695974

Please sign in to comment.