Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "Grid.h"
8 :
9 : #include "GridArea.h"
10 : #include "GridDimension.h"
11 : #include "mozilla/dom/GridBinding.h"
12 : #include "nsGridContainerFrame.h"
13 :
14 : namespace mozilla {
15 : namespace dom {
16 :
17 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Grid, mParent, mRows, mCols, mAreas)
18 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(Grid)
19 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(Grid)
20 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Grid)
21 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
23 0 : NS_INTERFACE_MAP_END
24 :
25 0 : Grid::Grid(nsISupports* aParent,
26 0 : nsGridContainerFrame* aFrame)
27 : : mParent(do_QueryInterface(aParent))
28 0 : , mRows(new GridDimension(this))
29 0 : , mCols(new GridDimension(this))
30 : {
31 0 : MOZ_ASSERT(aFrame,
32 : "Should never be instantiated with a null nsGridContainerFrame");
33 :
34 : // Construct areas first, because lines may need to reference them
35 : // to extract additional names for boundary lines.
36 :
37 : // Add implicit areas first. Track the names that we add here, because
38 : // we will ignore future explicit areas with the same name.
39 0 : nsTHashtable<nsStringHashKey> namesSeen;
40 : nsGridContainerFrame::ImplicitNamedAreas* implicitAreas =
41 0 : aFrame->GetImplicitNamedAreas();
42 0 : if (implicitAreas) {
43 0 : for (auto iter = implicitAreas->Iter(); !iter.Done(); iter.Next()) {
44 0 : auto& areaInfo = iter.Data();
45 0 : namesSeen.PutEntry(areaInfo.mName);
46 : GridArea* area = new GridArea(this,
47 : areaInfo.mName,
48 : GridDeclaration::Implicit,
49 : areaInfo.mRowStart,
50 : areaInfo.mRowEnd,
51 : areaInfo.mColumnStart,
52 0 : areaInfo.mColumnEnd);
53 0 : mAreas.AppendElement(area);
54 : }
55 : }
56 :
57 : // Add explicit areas next, as long as they don't have the same name
58 : // as the implicit areas, because the implicit values override what was
59 : // initially available in the explicit areas.
60 : nsGridContainerFrame::ExplicitNamedAreas* explicitAreas =
61 0 : aFrame->GetExplicitNamedAreas();
62 0 : if (explicitAreas) {
63 0 : for (auto& areaInfo : *explicitAreas) {
64 0 : if (!namesSeen.Contains(areaInfo.mName)) {
65 : GridArea* area = new GridArea(this,
66 : areaInfo.mName,
67 : GridDeclaration::Explicit,
68 : areaInfo.mRowStart,
69 : areaInfo.mRowEnd,
70 : areaInfo.mColumnStart,
71 0 : areaInfo.mColumnEnd);
72 0 : mAreas.AppendElement(area);
73 : }
74 : }
75 : }
76 :
77 : // Now construct the tracks and lines.
78 : const ComputedGridTrackInfo* rowTrackInfo =
79 0 : aFrame->GetComputedTemplateRows();
80 : const ComputedGridLineInfo* rowLineInfo =
81 0 : aFrame->GetComputedTemplateRowLines();
82 0 : mRows->SetTrackInfo(rowTrackInfo);
83 0 : mRows->SetLineInfo(rowTrackInfo, rowLineInfo, mAreas, true);
84 :
85 : const ComputedGridTrackInfo* columnTrackInfo =
86 0 : aFrame->GetComputedTemplateColumns();
87 : const ComputedGridLineInfo* columnLineInfo =
88 0 : aFrame->GetComputedTemplateColumnLines();
89 0 : mCols->SetTrackInfo(columnTrackInfo);
90 0 : mCols->SetLineInfo(columnTrackInfo, columnLineInfo, mAreas, false);
91 0 : }
92 :
93 0 : Grid::~Grid()
94 : {
95 0 : }
96 :
97 : JSObject*
98 0 : Grid::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
99 : {
100 0 : return GridBinding::Wrap(aCx, this, aGivenProto);
101 : }
102 :
103 : GridDimension*
104 0 : Grid::Rows() const
105 : {
106 0 : return mRows;
107 : }
108 :
109 : GridDimension*
110 0 : Grid::Cols() const
111 : {
112 0 : return mCols;
113 : }
114 :
115 : void
116 0 : Grid::GetAreas(nsTArray<RefPtr<GridArea>>& aAreas) const
117 : {
118 0 : aAreas = mAreas;
119 0 : }
120 :
121 : } // namespace dom
122 : } // namespace mozilla
|