2016-07-06 21:45:18 +03:00
|
|
|
/* -*- 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"
|
|
|
|
|
2016-08-23 23:34:51 +03:00
|
|
|
#include "GridArea.h"
|
2016-07-06 21:45:18 +03:00
|
|
|
#include "GridDimension.h"
|
|
|
|
#include "mozilla/dom/GridBinding.h"
|
|
|
|
#include "nsGridContainerFrame.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2016-08-23 23:34:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Grid, mParent, mRows, mCols, mAreas)
|
2016-07-06 21:45:18 +03:00
|
|
|
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");
|
|
|
|
|
2016-09-03 02:28:27 +03:00
|
|
|
// Construct areas first, because lines may need to reference them
|
|
|
|
// to extract additional names for boundary lines.
|
2016-08-23 23:34:51 +03:00
|
|
|
|
2016-09-03 02:28:27 +03:00
|
|
|
// Add implicit areas first. Track the names that we add here, because
|
|
|
|
// we will ignore future explicit areas with the same name.
|
2019-06-19 08:58:11 +03:00
|
|
|
nsTHashtable<nsRefPtrHashKey<nsAtom>> namesSeen;
|
2016-08-23 23:34:51 +03:00
|
|
|
nsGridContainerFrame::ImplicitNamedAreas* implicitAreas =
|
|
|
|
aFrame->GetImplicitNamedAreas();
|
|
|
|
if (implicitAreas) {
|
2019-06-19 08:58:11 +03:00
|
|
|
for (auto iter = implicitAreas->iter(); !iter.done(); iter.next()) {
|
|
|
|
auto& areaInfo = iter.get().value();
|
|
|
|
namesSeen.PutEntry(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);
|
2016-08-23 23:34:51 +03:00
|
|
|
mAreas.AppendElement(area);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-03 02:28:27 +03:00
|
|
|
// 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.
|
2019-06-19 01:29:58 +03:00
|
|
|
if (auto* explicitAreas = aFrame->GetExplicitNamedAreas()) {
|
|
|
|
for (auto& areaInfo : explicitAreas->AsSpan()) {
|
2019-06-19 08:58:11 +03:00
|
|
|
if (!namesSeen.Contains(areaInfo.name.AsAtom())) {
|
2016-09-03 02:28:27 +03:00
|
|
|
GridArea* area = new GridArea(
|
2019-06-19 08:58:11 +03:00
|
|
|
this, areaInfo.name.AsAtom(), GridDeclaration::Explicit,
|
2019-06-19 01:29:58 +03:00
|
|
|
areaInfo.rows.start, areaInfo.rows.end, areaInfo.columns.start,
|
|
|
|
areaInfo.columns.end);
|
2016-09-03 02:28:27 +03:00
|
|
|
mAreas.AppendElement(area);
|
|
|
|
}
|
2016-08-23 23:34:51 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-03 02:28:27 +03:00
|
|
|
|
|
|
|
// 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);
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Grid::~Grid() {}
|
|
|
|
|
|
|
|
JSObject* Grid::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return Grid_Binding::Wrap(aCx, this, aGivenProto);
|
2016-07-06 21:45:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GridDimension* Grid::Rows() const { return mRows; }
|
|
|
|
|
|
|
|
GridDimension* Grid::Cols() const { return mCols; }
|
|
|
|
|
2016-08-23 23:34:51 +03:00
|
|
|
void Grid::GetAreas(nsTArray<RefPtr<GridArea>>& aAreas) const {
|
|
|
|
aAreas = mAreas;
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:45:18 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|