LCOV - code coverage report
Current view: top level - accessible/base - StyleInfo.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 56 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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           0 : StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) :
      18           0 :   mElement(aElement)
      19             : {
      20             :   mStyleContext =
      21           0 :     nsComputedDOMStyle::GetStyleContextNoFlush(aElement, nullptr, aPresShell);
      22           0 : }
      23             : 
      24             : void
      25           0 : StyleInfo::Display(nsAString& aValue)
      26             : {
      27           0 :   aValue.Truncate();
      28           0 :   AppendASCIItoUTF16(
      29           0 :     nsCSSProps::ValueToKeyword(mStyleContext->StyleDisplay()->mDisplay,
      30           0 :                                nsCSSProps::kDisplayKTable), aValue);
      31           0 : }
      32             : 
      33             : void
      34           0 : StyleInfo::TextAlign(nsAString& aValue)
      35             : {
      36           0 :   aValue.Truncate();
      37           0 :   AppendASCIItoUTF16(
      38           0 :     nsCSSProps::ValueToKeyword(mStyleContext->StyleText()->mTextAlign,
      39           0 :                                nsCSSProps::kTextAlignKTable), aValue);
      40           0 : }
      41             : 
      42             : void
      43           0 : StyleInfo::TextIndent(nsAString& aValue)
      44             : {
      45           0 :   aValue.Truncate();
      46             : 
      47             :   const nsStyleCoord& styleCoord =
      48           0 :     mStyleContext->StyleText()->mTextIndent;
      49             : 
      50           0 :   nscoord coordVal = 0;
      51           0 :   switch (styleCoord.GetUnit()) {
      52             :     case eStyleUnit_Coord:
      53           0 :       coordVal = styleCoord.GetCoordValue();
      54           0 :       aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
      55           0 :       aValue.AppendLiteral("px");
      56           0 :       break;
      57             : 
      58             :     case eStyleUnit_Percent:
      59           0 :       aValue.AppendFloat(styleCoord.GetPercentValue() * 100);
      60           0 :       aValue.AppendLiteral("%");
      61           0 :       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           0 :       aValue.AppendLiteral("0px");
      77           0 :       break;
      78             :   }
      79           0 : }
      80             : 
      81             : void
      82           0 : StyleInfo::Margin(Side aSide, nsAString& aValue)
      83             : {
      84           0 :   MOZ_ASSERT(mElement->GetPrimaryFrame(), " mElement->GetPrimaryFrame() needs to be valid pointer");
      85           0 :   aValue.Truncate();
      86             : 
      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           0 : StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
      94             : {
      95             :   // 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           0 : StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
     107             : {
     108             :   nsCSSKeyword keyword =
     109           0 :     nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
     110           0 :   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
     111           0 : }
     112             : 
     113             : void
     114           0 : StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue)
     115             : {
     116             :   nsCSSKeyword keyword =
     117           0 :     nsCSSProps::ValueToKeywordEnum(aValue,
     118           0 :                                    nsCSSProps::kTextDecorationStyleKTable);
     119           0 :   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
     120           0 : }

Generated by: LCOV version 1.13