/src/mozilla-central/dom/grid/GridTracks.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 "GridTracks.h" |
8 | | |
9 | | #include "GridDimension.h" |
10 | | #include "GridTrack.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(GridTracks, mParent, mTracks) |
18 | | NS_IMPL_CYCLE_COLLECTING_ADDREF(GridTracks) |
19 | | NS_IMPL_CYCLE_COLLECTING_RELEASE(GridTracks) |
20 | 0 | NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridTracks) |
21 | 0 | NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
22 | 0 | NS_INTERFACE_MAP_ENTRY(nsISupports) |
23 | 0 | NS_INTERFACE_MAP_END |
24 | | |
25 | | GridTracks::GridTracks(GridDimension *aParent) |
26 | | : mParent(aParent) |
27 | 0 | { |
28 | 0 | MOZ_ASSERT(aParent, |
29 | 0 | "Should never be instantiated with a null GridDimension"); |
30 | 0 | } |
31 | | |
32 | | GridTracks::~GridTracks() |
33 | 0 | { |
34 | 0 | } |
35 | | |
36 | | JSObject* |
37 | | GridTracks::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) |
38 | 0 | { |
39 | 0 | return GridTracks_Binding::Wrap(aCx, this, aGivenProto); |
40 | 0 | } |
41 | | |
42 | | uint32_t |
43 | | GridTracks::Length() const |
44 | 0 | { |
45 | 0 | return mTracks.Length(); |
46 | 0 | } |
47 | | |
48 | | GridTrack* |
49 | | GridTracks::Item(uint32_t aIndex) |
50 | 0 | { |
51 | 0 | return mTracks.SafeElementAt(aIndex); |
52 | 0 | } |
53 | | |
54 | | GridTrack* |
55 | | GridTracks::IndexedGetter(uint32_t aIndex, |
56 | | bool& aFound) |
57 | 0 | { |
58 | 0 | aFound = aIndex < mTracks.Length(); |
59 | 0 | if (!aFound) { |
60 | 0 | return nullptr; |
61 | 0 | } |
62 | 0 | return mTracks[aIndex]; |
63 | 0 | } |
64 | | |
65 | | void |
66 | | GridTracks::SetTrackInfo(const ComputedGridTrackInfo* aTrackInfo) |
67 | 0 | { |
68 | 0 | // rebuild the tracks based on aTrackInfo |
69 | 0 | mTracks.Clear(); |
70 | 0 |
|
71 | 0 | if (!aTrackInfo) { |
72 | 0 | return; |
73 | 0 | } |
74 | 0 | |
75 | 0 | nscoord lastTrackEdge = 0; |
76 | 0 | uint32_t repeatIndex = 0; |
77 | 0 | auto AppendRemovedAutoFits = [this, &aTrackInfo, &lastTrackEdge, |
78 | 0 | &repeatIndex]() |
79 | 0 | { |
80 | 0 | uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length(); |
81 | 0 | // Add in removed auto-fit tracks |
82 | 0 | while (repeatIndex < numRepeatTracks && |
83 | 0 | aTrackInfo->mRemovedRepeatTracks[repeatIndex]) { |
84 | 0 |
|
85 | 0 | RefPtr<GridTrack> track = new GridTrack(this); |
86 | 0 | mTracks.AppendElement(track); |
87 | 0 | track->SetTrackValues( |
88 | 0 | nsPresContext::AppUnitsToDoubleCSSPixels(lastTrackEdge), |
89 | 0 | nsPresContext::AppUnitsToDoubleCSSPixels(0), |
90 | 0 | GridDeclaration::Explicit, |
91 | 0 | GridTrackState::Removed |
92 | 0 | ); |
93 | 0 | repeatIndex++; |
94 | 0 | } |
95 | 0 | repeatIndex++; |
96 | 0 | }; |
97 | 0 |
|
98 | 0 | for (size_t i = aTrackInfo->mStartFragmentTrack; |
99 | 0 | i < aTrackInfo->mEndFragmentTrack; |
100 | 0 | i++) { |
101 | 0 | if (i >= aTrackInfo->mRepeatFirstTrack) { |
102 | 0 | // Append removed auto-fit tracks, if appropriate. The |
103 | 0 | // AppendRemovedAutoFits function exits early once it has been called |
104 | 0 | // aTrackInfo->mRemovedRepeatTracks.Length() times -- a check we don't |
105 | 0 | // replicate here or at subsequent calling sites. |
106 | 0 | AppendRemovedAutoFits(); |
107 | 0 | } |
108 | 0 |
|
109 | 0 | RefPtr<GridTrack> track = new GridTrack(this); |
110 | 0 | mTracks.AppendElement(track); |
111 | 0 | track->SetTrackValues( |
112 | 0 | nsPresContext::AppUnitsToDoubleCSSPixels(aTrackInfo->mPositions[i]), |
113 | 0 | nsPresContext::AppUnitsToDoubleCSSPixels(aTrackInfo->mSizes[i]), |
114 | 0 | ( |
115 | 0 | // Implicit if index is before the first explicit track, or after |
116 | 0 | // the last explicit track. |
117 | 0 | (i < aTrackInfo->mNumLeadingImplicitTracks) || |
118 | 0 | (i >= aTrackInfo->mNumLeadingImplicitTracks + |
119 | 0 | aTrackInfo->mNumExplicitTracks) ? |
120 | 0 | GridDeclaration::Implicit : |
121 | 0 | GridDeclaration::Explicit |
122 | 0 | ), |
123 | 0 | GridTrackState(aTrackInfo->mStates[i]) |
124 | 0 | ); |
125 | 0 |
|
126 | 0 | lastTrackEdge = aTrackInfo->mPositions[i] + aTrackInfo->mSizes[i]; |
127 | 0 | } |
128 | 0 |
|
129 | 0 | // Append any trailing removed auto-fit tracks. |
130 | 0 | AppendRemovedAutoFits(); |
131 | 0 | } |
132 | | |
133 | | } // namespace dom |
134 | | } // namespace mozilla |