Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/base/StyleInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set expandtab shiftwidth=2 tabstop=2: */
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 "StyleInfo.h"
8
9
#include "mozilla/dom/Element.h"
10
#include "nsComputedDOMStyle.h"
11
#include "nsCSSProps.h"
12
#include "nsIFrame.h"
13
14
using namespace mozilla;
15
using namespace mozilla::a11y;
16
17
StyleInfo::StyleInfo(dom::Element* aElement) :
18
  mElement(aElement)
19
0
{
20
0
  mComputedStyle =
21
0
    nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
22
0
}
23
24
void
25
StyleInfo::Display(nsAString& aValue)
26
0
{
27
0
  aValue.Truncate();
28
0
  AppendASCIItoUTF16(
29
0
    nsCSSProps::ValueToKeyword(mComputedStyle->StyleDisplay()->mDisplay,
30
0
                               nsCSSProps::kDisplayKTable), aValue);
31
0
}
32
33
void
34
StyleInfo::TextAlign(nsAString& aValue)
35
0
{
36
0
  aValue.Truncate();
37
0
  AppendASCIItoUTF16(
38
0
    nsCSSProps::ValueToKeyword(mComputedStyle->StyleText()->mTextAlign,
39
0
                               nsCSSProps::kTextAlignKTable), aValue);
40
0
}
41
42
void
43
StyleInfo::TextIndent(nsAString& aValue)
44
{
45
  aValue.Truncate();
46
47
  const nsStyleCoord& styleCoord =
48
    mComputedStyle->StyleText()->mTextIndent;
49
50
  nscoord coordVal = 0;
51
  switch (styleCoord.GetUnit()) {
52
    case eStyleUnit_Coord:
53
      coordVal = styleCoord.GetCoordValue();
54
      aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
55
      aValue.AppendLiteral("px");
56
      break;
57
58
    case eStyleUnit_Percent:
59
      aValue.AppendFloat(styleCoord.GetPercentValue() * 100);
60
      aValue.AppendLiteral("%");
61
      break;
62
63
    case eStyleUnit_Null:
64
    case eStyleUnit_Normal:
65
    case eStyleUnit_Auto:
66
    case eStyleUnit_None:
67
    case eStyleUnit_Factor:
68
    case eStyleUnit_Degree:
69
    case eStyleUnit_Grad:
70
    case eStyleUnit_Radian:
71
    case eStyleUnit_Turn:
72
    case eStyleUnit_FlexFraction:
73
    case eStyleUnit_Integer:
74
    case eStyleUnit_Enumerated:
75
    case eStyleUnit_Calc:
76
      aValue.AppendLiteral("0px");
77
      break;
78
  }
79
}
80
81
void
82
StyleInfo::Margin(Side aSide, nsAString& aValue)
83
0
{
84
0
  MOZ_ASSERT(mElement->GetPrimaryFrame(), " mElement->GetPrimaryFrame() needs to be valid pointer");
85
0
  aValue.Truncate();
86
0
87
0
  nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
88
0
  aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
89
0
  aValue.AppendLiteral("px");
90
0
}
91
92
void
93
StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
94
0
{
95
0
  // Combine the string like rgb(R, G, B) from nscolor.
96
0
  aFormattedValue.AppendLiteral("rgb(");
97
0
  aFormattedValue.AppendInt(NS_GET_R(aValue));
98
0
  aFormattedValue.AppendLiteral(", ");
99
0
  aFormattedValue.AppendInt(NS_GET_G(aValue));
100
0
  aFormattedValue.AppendLiteral(", ");
101
0
  aFormattedValue.AppendInt(NS_GET_B(aValue));
102
0
  aFormattedValue.Append(')');
103
0
}
104
105
void
106
StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue)
107
0
{
108
0
  nsCSSKeyword keyword =
109
0
    nsCSSProps::ValueToKeywordEnum(aValue,
110
0
                                   nsCSSProps::kTextDecorationStyleKTable);
111
0
  AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
112
0
}