accessible/src/base/StyleInfo.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     7 #include "StyleInfo.h"
     9 #include "mozilla/dom/Element.h"
    10 #include "nsComputedDOMStyle.h"
    11 #include "nsCSSProps.h"
    12 #include "nsIFrame.h"
    14 using namespace mozilla;
    15 using namespace mozilla::a11y;
    17 StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) :
    18   mElement(aElement)
    19 {
    20   mStyleContext =
    21     nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
    22                                                          nullptr,
    23                                                          aPresShell);
    24 }
    26 void
    27 StyleInfo::Display(nsAString& aValue)
    28 {
    29   aValue.Truncate();
    30   AppendASCIItoUTF16(
    31     nsCSSProps::ValueToKeyword(mStyleContext->StyleDisplay()->mDisplay,
    32                                nsCSSProps::kDisplayKTable), aValue);
    33 }
    35 void
    36 StyleInfo::TextAlign(nsAString& aValue)
    37 {
    38   aValue.Truncate();
    39   AppendASCIItoUTF16(
    40     nsCSSProps::ValueToKeyword(mStyleContext->StyleText()->mTextAlign,
    41                                nsCSSProps::kTextAlignKTable), aValue);
    42 }
    44 void
    45 StyleInfo::TextIndent(nsAString& aValue)
    46 {
    47   aValue.Truncate();
    49   const nsStyleCoord& styleCoord =
    50     mStyleContext->StyleText()->mTextIndent;
    52   nscoord coordVal = 0;
    53   switch (styleCoord.GetUnit()) {
    54     case eStyleUnit_Coord:
    55       coordVal = styleCoord.GetCoordValue();
    56       break;
    58     case eStyleUnit_Percent:
    59     {
    60       nsIFrame* frame = mElement->GetPrimaryFrame();
    61       nsIFrame* containerFrame = frame->GetContainingBlock();
    62       nscoord percentageBase = containerFrame->GetContentRect().width;
    63       coordVal = NSCoordSaturatingMultiply(percentageBase,
    64                                            styleCoord.GetPercentValue());
    65       break;
    66     }
    68     case eStyleUnit_Null:
    69     case eStyleUnit_Normal:
    70     case eStyleUnit_Auto:
    71     case eStyleUnit_None:
    72     case eStyleUnit_Factor:
    73     case eStyleUnit_Degree:
    74     case eStyleUnit_Grad:
    75     case eStyleUnit_Radian:
    76     case eStyleUnit_Turn:
    77     case eStyleUnit_FlexFraction:
    78     case eStyleUnit_Integer:
    79     case eStyleUnit_Enumerated:
    80     case eStyleUnit_Calc:
    81       break;
    82   }
    84   aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
    85   aValue.AppendLiteral("px");
    86 }
    88 void
    89 StyleInfo::Margin(css::Side aSide, nsAString& aValue)
    90 {
    91   aValue.Truncate();
    93   nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
    94   aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
    95   aValue.AppendLiteral("px");
    96 }
    98 void
    99 StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
   100 {
   101   // Combine the string like rgb(R, G, B) from nscolor.
   102   aFormattedValue.AppendLiteral("rgb(");
   103   aFormattedValue.AppendInt(NS_GET_R(aValue));
   104   aFormattedValue.AppendLiteral(", ");
   105   aFormattedValue.AppendInt(NS_GET_G(aValue));
   106   aFormattedValue.AppendLiteral(", ");
   107   aFormattedValue.AppendInt(NS_GET_B(aValue));
   108   aFormattedValue.Append(')');
   109 }
   111 void
   112 StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
   113 {
   114   nsCSSKeyword keyword =
   115     nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
   116   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
   117 }
   119 void
   120 StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue)
   121 {
   122   nsCSSKeyword keyword =
   123     nsCSSProps::ValueToKeywordEnum(aValue,
   124                                    nsCSSProps::kTextDecorationStyleKTable);
   125   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
   126 }

mercurial