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 "GridLine.h"
8 
9 #include "GridLines.h"
10 #include "mozilla/dom/GridBinding.h"
11 #include "nsAtom.h"
12 
13 namespace mozilla::dom {
14 
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridLine,mParent)15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(GridLine, mParent)
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(GridLine)
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(GridLine)
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GridLine)
19   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20   NS_INTERFACE_MAP_ENTRY(nsISupports)
21 NS_INTERFACE_MAP_END
22 
23 GridLine::GridLine(GridLines* aParent)
24     : mParent(aParent),
25       mStart(0.0),
26       mBreadth(0.0),
27       mType(GridDeclaration::Implicit),
28       mNumber(0),
29       mNegativeNumber(0) {
30   MOZ_ASSERT(aParent, "Should never be instantiated with a null GridLines");
31 }
32 
33 GridLine::~GridLine() = default;
34 
GetNames(nsTArray<nsString> & aNames) const35 void GridLine::GetNames(nsTArray<nsString>& aNames) const {
36   aNames.SetCapacity(mNames.Length());
37   for (auto& name : mNames) {
38     aNames.AppendElement(nsDependentAtomString(name));
39   }
40 }
41 
WrapObject(JSContext * aCx,JS::Handle<JSObject * > aGivenProto)42 JSObject* GridLine::WrapObject(JSContext* aCx,
43                                JS::Handle<JSObject*> aGivenProto) {
44   return GridLine_Binding::Wrap(aCx, this, aGivenProto);
45 }
46 
Start() const47 double GridLine::Start() const { return mStart; }
48 
Breadth() const49 double GridLine::Breadth() const { return mBreadth; }
50 
Type() const51 GridDeclaration GridLine::Type() const { return mType; }
52 
Number() const53 uint32_t GridLine::Number() const { return mNumber; }
54 
NegativeNumber() const55 int32_t GridLine::NegativeNumber() const { return mNegativeNumber; }
56 
SetLineValues(const nsTArray<RefPtr<nsAtom>> & aNames,double aStart,double aBreadth,uint32_t aNumber,int32_t aNegativeNumber,GridDeclaration aType)57 void GridLine::SetLineValues(const nsTArray<RefPtr<nsAtom>>& aNames,
58                              double aStart, double aBreadth, uint32_t aNumber,
59                              int32_t aNegativeNumber, GridDeclaration aType) {
60   mNames = aNames.Clone();
61   mStart = aStart;
62   mBreadth = aBreadth;
63   mNumber = aNumber;
64   mNegativeNumber = aNegativeNumber;
65   mType = aType;
66 }
67 
SetLineNames(const nsTArray<RefPtr<nsAtom>> & aNames)68 void GridLine::SetLineNames(const nsTArray<RefPtr<nsAtom>>& aNames) {
69   mNames = aNames.Clone();
70 }
71 
72 }  // namespace mozilla::dom
73