LCOV - code coverage report
Current view: directory - accessible/src/base - StyleInfo.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 51 0 0.0 %
Date: 2012-06-02 Functions: 8 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim:expandtab:shiftwidth=2:tabstop=2: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Mozilla Foundation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 2012
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *   Alexander Surkov <surkov.alexander@gmail.com> (original author)
      25                 :  *
      26                 :  * Alternatively, the contents of this file may be used under the terms of
      27                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30                 :  * of those above. If you wish to allow use of your version of this file only
      31                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32                 :  * use your version of this file under the terms of the MPL, indicate your
      33                 :  * decision by deleting the provisions above and replace them with the notice
      34                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35                 :  * the provisions above, a recipient may use your version of this file under
      36                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      37                 :  *
      38                 :  * ***** END LICENSE BLOCK ***** */
      39                 : 
      40                 : #include "StyleInfo.h"
      41                 : 
      42                 : #include "mozilla/dom/Element.h"
      43                 : #include "nsComputedDOMStyle.h"
      44                 : 
      45                 : using namespace mozilla;
      46                 : using namespace mozilla::a11y;
      47                 : 
      48               0 : StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) :
      49               0 :   mElement(aElement)
      50                 : {
      51                 :   mStyleContext =
      52                 :     nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
      53                 :                                                          nsnull,
      54               0 :                                                          aPresShell);
      55               0 : }
      56                 : 
      57                 : void
      58               0 : StyleInfo::Display(nsAString& aValue)
      59                 : {
      60               0 :   aValue.Truncate();
      61                 :   AppendASCIItoUTF16(
      62               0 :     nsCSSProps::ValueToKeyword(mStyleContext->GetStyleDisplay()->mDisplay,
      63               0 :                                nsCSSProps::kDisplayKTable), aValue);
      64               0 : }
      65                 : 
      66                 : void
      67               0 : StyleInfo::TextAlign(nsAString& aValue)
      68                 : {
      69               0 :   aValue.Truncate();
      70                 :   AppendASCIItoUTF16(
      71               0 :     nsCSSProps::ValueToKeyword(mStyleContext->GetStyleText()->mTextAlign,
      72               0 :                                nsCSSProps::kTextAlignKTable), aValue);
      73               0 : }
      74                 : 
      75                 : void
      76               0 : StyleInfo::TextIndent(nsAString& aValue)
      77                 : {
      78               0 :   aValue.Truncate();
      79                 : 
      80                 :   const nsStyleCoord& styleCoord =
      81               0 :     mStyleContext->GetStyleText()->mTextIndent;
      82                 : 
      83                 :   nscoord coordVal;
      84               0 :   switch (styleCoord.GetUnit()) {
      85                 :     case eStyleUnit_Coord:
      86               0 :       coordVal = styleCoord.GetCoordValue();
      87               0 :       break;
      88                 : 
      89                 :     case eStyleUnit_Percent:
      90                 :     {
      91               0 :       nsIFrame* frame = mElement->GetPrimaryFrame();
      92               0 :       nsIFrame* containerFrame = frame->GetContainingBlock();
      93               0 :       nscoord percentageBase = containerFrame->GetContentRect().width;
      94                 :       coordVal = NSCoordSaturatingMultiply(percentageBase,
      95               0 :                                            styleCoord.GetPercentValue());
      96               0 :       break;
      97                 :     }
      98                 :   }
      99                 : 
     100               0 :   aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
     101               0 :   aValue.AppendLiteral("px");
     102               0 : }
     103                 : 
     104                 : void
     105               0 : StyleInfo::Margin(css::Side aSide, nsAString& aValue)
     106                 : {
     107               0 :   aValue.Truncate();
     108                 : 
     109               0 :   nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
     110               0 :   aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
     111               0 :   aValue.AppendLiteral("px");
     112               0 : }
     113                 : 
     114                 : void
     115               0 : StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
     116                 : {
     117                 :   // Combine the string like rgb(R, G, B) from nscolor.
     118               0 :   aFormattedValue.AppendLiteral("rgb(");
     119               0 :   aFormattedValue.AppendInt(NS_GET_R(aValue));
     120               0 :   aFormattedValue.AppendLiteral(", ");
     121               0 :   aFormattedValue.AppendInt(NS_GET_G(aValue));
     122               0 :   aFormattedValue.AppendLiteral(", ");
     123               0 :   aFormattedValue.AppendInt(NS_GET_B(aValue));
     124               0 :   aFormattedValue.Append(')');
     125               0 : }
     126                 : 
     127                 : void
     128               0 : StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
     129                 : {
     130                 :   nsCSSKeyword keyword =
     131               0 :     nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
     132               0 :   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
     133               0 : }
     134                 : 
     135                 : void
     136               0 : StyleInfo::FormatTextDecorationStyle(PRUint8 aValue, nsAString& aFormattedValue)
     137                 : {
     138                 :   nsCSSKeyword keyword =
     139                 :     nsCSSProps::ValueToKeywordEnum(aValue,
     140               0 :                                    nsCSSProps::kTextDecorationStyleKTable);
     141               0 :   AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
     142               0 : }

Generated by: LCOV version 1.7