/src/mozilla-central/dom/grid/Grid.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Grid, mParent, mRows, mCols, mAreas) |
18 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(Grid) |
19 | | 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 | | Grid::Grid(nsISupports* aParent, |
26 | | nsGridContainerFrame* aFrame) |
27 | | : mParent(do_QueryInterface(aParent)) |
28 | | , mRows(new GridDimension(this)) |
29 | | , mCols(new GridDimension(this)) |
30 | 0 | { |
31 | 0 | MOZ_ASSERT(aFrame, |
32 | 0 | "Should never be instantiated with a null nsGridContainerFrame"); |
33 | 0 |
|
34 | 0 | // Construct areas first, because lines may need to reference them |
35 | 0 | // to extract additional names for boundary lines. |
36 | 0 |
|
37 | 0 | // Add implicit areas first. Track the names that we add here, because |
38 | 0 | // we will ignore future explicit areas with the same name. |
39 | 0 | nsTHashtable<nsStringHashKey> namesSeen; |
40 | 0 | 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 | 0 | GridArea* area = new GridArea(this, |
47 | 0 | areaInfo.mName, |
48 | 0 | GridDeclaration::Implicit, |
49 | 0 | areaInfo.mRowStart, |
50 | 0 | areaInfo.mRowEnd, |
51 | 0 | areaInfo.mColumnStart, |
52 | 0 | areaInfo.mColumnEnd); |
53 | 0 | mAreas.AppendElement(area); |
54 | 0 | } |
55 | 0 | } |
56 | 0 |
|
57 | 0 | // Add explicit areas next, as long as they don't have the same name |
58 | 0 | // as the implicit areas, because the implicit values override what was |
59 | 0 | // initially available in the explicit areas. |
60 | 0 | 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 | 0 | GridArea* area = new GridArea(this, |
66 | 0 | areaInfo.mName, |
67 | 0 | GridDeclaration::Explicit, |
68 | 0 | areaInfo.mRowStart, |
69 | 0 | areaInfo.mRowEnd, |
70 | 0 | areaInfo.mColumnStart, |
71 | 0 | areaInfo.mColumnEnd); |
72 | 0 | mAreas.AppendElement(area); |
73 | 0 | } |
74 | 0 | } |
75 | 0 | } |
76 | 0 |
|
77 | 0 | // Now construct the tracks and lines. |
78 | 0 | const ComputedGridTrackInfo* rowTrackInfo = |
79 | 0 | aFrame->GetComputedTemplateRows(); |
80 | 0 | const ComputedGridLineInfo* rowLineInfo = |
81 | 0 | aFrame->GetComputedTemplateRowLines(); |
82 | 0 | mRows->SetTrackInfo(rowTrackInfo); |
83 | 0 | mRows->SetLineInfo(rowTrackInfo, rowLineInfo, mAreas, true); |
84 | 0 |
|
85 | 0 | const ComputedGridTrackInfo* columnTrackInfo = |
86 | 0 | aFrame->GetComputedTemplateColumns(); |
87 | 0 | const ComputedGridLineInfo* columnLineInfo = |
88 | 0 | aFrame->GetComputedTemplateColumnLines(); |
89 | 0 | mCols->SetTrackInfo(columnTrackInfo); |
90 | 0 | mCols->SetLineInfo(columnTrackInfo, columnLineInfo, mAreas, false); |
91 | 0 | } |
92 | | |
93 | | Grid::~Grid() |
94 | 0 | { |
95 | 0 | } |
96 | | |
97 | | JSObject* |
98 | | Grid::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
99 | 0 | { |
100 | 0 | return Grid_Binding::Wrap(aCx, this, aGivenProto); |
101 | 0 | } |
102 | | |
103 | | GridDimension* |
104 | | Grid::Rows() const |
105 | 0 | { |
106 | 0 | return mRows; |
107 | 0 | } |
108 | | |
109 | | GridDimension* |
110 | | Grid::Cols() const |
111 | 0 | { |
112 | 0 | return mCols; |
113 | 0 | } |
114 | | |
115 | | void |
116 | | Grid::GetAreas(nsTArray<RefPtr<GridArea>>& aAreas) const |
117 | 0 | { |
118 | 0 | aAreas = mAreas; |
119 | 0 | } |
120 | | |
121 | | } // namespace dom |
122 | | } // namespace mozilla |