2012-02-20 07:45:29 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-06-29 03:42:59 -07:00
|
|
|
/* vim: set expandtab shiftwidth=2 tabstop=2: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-02-20 07:45:29 -08:00
|
|
|
|
|
|
|
#include "StyleInfo.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2012-08-05 20:00:56 -07:00
|
|
|
#include "nsIFrame.h"
|
2012-02-20 07:45:29 -08:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
|
|
|
StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) :
|
|
|
|
mElement(aElement)
|
|
|
|
{
|
|
|
|
mStyleContext =
|
|
|
|
nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2012-02-20 07:45:29 -08:00
|
|
|
aPresShell);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::Display(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
|
|
|
nsCSSProps::ValueToKeyword(mStyleContext->GetStyleDisplay()->mDisplay,
|
|
|
|
nsCSSProps::kDisplayKTable), aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::TextAlign(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
|
|
|
nsCSSProps::ValueToKeyword(mStyleContext->GetStyleText()->mTextAlign,
|
|
|
|
nsCSSProps::kTextAlignKTable), aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::TextIndent(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
const nsStyleCoord& styleCoord =
|
|
|
|
mStyleContext->GetStyleText()->mTextIndent;
|
|
|
|
|
2012-06-18 13:14:01 -07:00
|
|
|
nscoord coordVal = 0;
|
2012-02-20 07:45:29 -08:00
|
|
|
switch (styleCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
coordVal = styleCoord.GetCoordValue();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Percent:
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mElement->GetPrimaryFrame();
|
|
|
|
nsIFrame* containerFrame = frame->GetContainingBlock();
|
|
|
|
nscoord percentageBase = containerFrame->GetContentRect().width;
|
|
|
|
coordVal = NSCoordSaturatingMultiply(percentageBase,
|
|
|
|
styleCoord.GetPercentValue());
|
|
|
|
break;
|
|
|
|
}
|
2012-06-18 13:14:01 -07:00
|
|
|
|
|
|
|
case eStyleUnit_Null:
|
|
|
|
case eStyleUnit_Normal:
|
|
|
|
case eStyleUnit_Auto:
|
|
|
|
case eStyleUnit_None:
|
|
|
|
case eStyleUnit_Factor:
|
|
|
|
case eStyleUnit_Degree:
|
|
|
|
case eStyleUnit_Grad:
|
|
|
|
case eStyleUnit_Radian:
|
|
|
|
case eStyleUnit_Turn:
|
|
|
|
case eStyleUnit_Integer:
|
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
case eStyleUnit_Calc:
|
|
|
|
break;
|
2012-02-20 07:45:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
|
|
|
|
aValue.AppendLiteral("px");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::Margin(css::Side aSide, nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
|
|
|
|
aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
|
|
|
|
aValue.AppendLiteral("px");
|
|
|
|
}
|
2012-02-27 06:43:39 -08:00
|
|
|
|
|
|
|
void
|
2012-02-28 23:35:51 -08:00
|
|
|
StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
|
2012-02-27 06:43:39 -08:00
|
|
|
{
|
|
|
|
// Combine the string like rgb(R, G, B) from nscolor.
|
|
|
|
aFormattedValue.AppendLiteral("rgb(");
|
|
|
|
aFormattedValue.AppendInt(NS_GET_R(aValue));
|
|
|
|
aFormattedValue.AppendLiteral(", ");
|
|
|
|
aFormattedValue.AppendInt(NS_GET_G(aValue));
|
|
|
|
aFormattedValue.AppendLiteral(", ");
|
|
|
|
aFormattedValue.AppendInt(NS_GET_B(aValue));
|
|
|
|
aFormattedValue.Append(')');
|
|
|
|
}
|
2012-02-28 23:35:51 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue)
|
|
|
|
{
|
|
|
|
nsCSSKeyword keyword =
|
|
|
|
nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable);
|
|
|
|
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
|
|
|
|
}
|
2012-03-10 07:35:02 -08:00
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::FormatTextDecorationStyle(PRUint8 aValue, nsAString& aFormattedValue)
|
|
|
|
{
|
|
|
|
nsCSSKeyword keyword =
|
|
|
|
nsCSSProps::ValueToKeywordEnum(aValue,
|
|
|
|
nsCSSProps::kTextDecorationStyleKTable);
|
|
|
|
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
|
|
|
|
}
|