Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/flex/FlexItem.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 "FlexItem.h"
8
9
#include "mozilla/dom/FlexBinding.h"
10
#include "nsFlexContainerFrame.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(FlexItem, mParent)
16
NS_IMPL_CYCLE_COLLECTING_ADDREF(FlexItem)
17
NS_IMPL_CYCLE_COLLECTING_RELEASE(FlexItem)
18
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlexItem)
19
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
20
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
21
0
NS_INTERFACE_MAP_END
22
23
/**
24
 * Utility function to convert a nscoord size to CSS pixel values, with
25
 * graceful treatment of NS_UNCONSTRAINEDSIZE (which this function converts to
26
 * the double "positive infinity" value).
27
 *
28
 * This function is suitable for converting quantities that are expected to
29
 * sometimes legitimately (rather than arbitrarily/accidentally) contain the
30
 * sentinel value NS_UNCONSTRAINEDSIZE -- e.g. to handle "max-width: none".
31
 */
32
static double
33
ToPossiblyUnconstrainedPixels(nscoord aSize)
34
0
{
35
0
  if (aSize == NS_UNCONSTRAINEDSIZE) {
36
0
    return std::numeric_limits<double>::infinity();
37
0
  }
38
0
  return nsPresContext::AppUnitsToDoubleCSSPixels(aSize);
39
0
}
40
41
FlexItem::FlexItem(FlexLine* aParent,
42
                   const ComputedFlexItemInfo* aItem)
43
  : mParent(aParent)
44
0
{
45
0
  MOZ_ASSERT(aItem,
46
0
    "Should never be instantiated with a null ComputedFlexLineInfo.");
47
0
48
0
  // Eagerly copy values from aItem, because we're not
49
0
  // going to keep it around.
50
0
  mNode = aItem->mNode;
51
0
52
0
  // Convert app unit sizes to css pixel sizes.
53
0
  mMainBaseSize = nsPresContext::AppUnitsToDoubleCSSPixels(
54
0
    aItem->mMainBaseSize);
55
0
  mMainDeltaSize = nsPresContext::AppUnitsToDoubleCSSPixels(
56
0
    aItem->mMainDeltaSize);
57
0
  mMainMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(
58
0
    aItem->mMainMinSize);
59
0
  mMainMaxSize = ToPossiblyUnconstrainedPixels(aItem->mMainMaxSize);
60
0
  mCrossMinSize = nsPresContext::AppUnitsToDoubleCSSPixels(
61
0
    aItem->mCrossMinSize);
62
0
  mCrossMaxSize = ToPossiblyUnconstrainedPixels(aItem->mCrossMaxSize);
63
0
}
64
65
JSObject*
66
FlexItem::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
67
0
{
68
0
  return FlexItem_Binding::Wrap(aCx, this, aGivenProto);
69
0
}
70
71
nsINode*
72
FlexItem::GetNode() const
73
0
{
74
0
  return mNode;
75
0
}
76
77
double
78
FlexItem::MainBaseSize() const
79
0
{
80
0
  return mMainBaseSize;
81
0
}
82
83
double
84
FlexItem::MainDeltaSize() const
85
0
{
86
0
  return mMainDeltaSize;
87
0
}
88
89
double
90
FlexItem::MainMinSize() const
91
0
{
92
0
  return mMainMinSize;
93
0
}
94
95
double
96
FlexItem::MainMaxSize() const
97
0
{
98
0
  return mMainMaxSize;
99
0
}
100
101
double
102
FlexItem::CrossMinSize() const
103
0
{
104
0
  return mCrossMinSize;
105
0
}
106
107
double
108
FlexItem::CrossMaxSize() const
109
0
{
110
0
  return mCrossMaxSize;
111
0
}
112
113
} // namespace dom
114
} // namespace mozilla