2012-02-20 19:45:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-06-29 14:42:59 +04:00
|
|
|
/* vim: set expandtab shiftwidth=2 tabstop=2: */
|
2012-05-21 15:12:37 +04: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 19:45:29 +04:00
|
|
|
|
|
|
|
#include "StyleInfo.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2013-03-03 04:31:48 +04:00
|
|
|
#include "nsCSSProps.h"
|
2012-08-06 07:00:56 +04:00
|
|
|
#include "nsIFrame.h"
|
2012-02-20 19:45:29 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2018-01-23 17:49:00 +03:00
|
|
|
StyleInfo::StyleInfo(dom::Element* aElement) :
|
2012-02-20 19:45:29 +04:00
|
|
|
mElement(aElement)
|
|
|
|
{
|
2018-03-22 21:20:41 +03:00
|
|
|
mComputedStyle =
|
|
|
|
nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
|
2012-02-20 19:45:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::Display(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
2018-03-22 21:20:41 +03:00
|
|
|
nsCSSProps::ValueToKeyword(mComputedStyle->StyleDisplay()->mDisplay,
|
2012-02-20 19:45:29 +04:00
|
|
|
nsCSSProps::kDisplayKTable), aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::TextAlign(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
2018-03-22 21:20:41 +03:00
|
|
|
nsCSSProps::ValueToKeyword(mComputedStyle->StyleText()->mTextAlign,
|
2012-02-20 19:45:29 +04:00
|
|
|
nsCSSProps::kTextAlignKTable), aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StyleInfo::TextIndent(nsAString& aValue)
|
|
|
|
{
|
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
const nsStyleCoord& styleCoord =
|
2018-03-22 21:20:41 +03:00
|
|
|
mComputedStyle->StyleText()->mTextIndent;
|
2012-02-20 19:45:29 +04:00
|
|
|
|
2012-06-19 00:14:01 +04:00
|
|
|
nscoord coordVal = 0;
|
2012-02-20 19:45:29 +04:00
|
|
|
switch (styleCoord.GetUnit()) {
|
|
|
|
case eStyleUnit_Coord:
|
|
|
|
coordVal = styleCoord.GetCoordValue();
|
2016-10-03 13:14:21 +03:00
|
|
|
aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
|
|
|
|
aValue.AppendLiteral("px");
|
2012-02-20 19:45:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case eStyleUnit_Percent:
|
2016-10-03 13:14:21 +03:00
|
|
|
aValue.AppendFloat(styleCoord.GetPercentValue() * 100);
|
|
|
|
aValue.AppendLiteral("%");
|
2012-02-20 19:45:29 +04:00
|
|
|
break;
|
2012-06-19 00:14:01 +04: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:
|
2014-03-21 05:16:23 +04:00
|
|
|
case eStyleUnit_FlexFraction:
|
2012-06-19 00:14:01 +04:00
|
|
|
case eStyleUnit_Integer:
|
|
|
|
case eStyleUnit_Enumerated:
|
|
|
|
case eStyleUnit_Calc:
|
2016-10-03 13:14:21 +03:00
|
|
|
aValue.AppendLiteral("0px");
|
2012-06-19 00:14:01 +04:00
|
|
|
break;
|
2012-02-20 19:45:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-11-18 11:28:38 +03:00
|
|
|
StyleInfo::Margin(Side aSide, nsAString& aValue)
|
2012-02-20 19:45:29 +04:00
|
|
|
{
|
2015-12-28 14:25:00 +03:00
|
|
|
MOZ_ASSERT(mElement->GetPrimaryFrame(), " mElement->GetPrimaryFrame() needs to be valid pointer");
|
2012-02-20 19:45:29 +04:00
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
|
|
|
|
aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
|
|
|
|
aValue.AppendLiteral("px");
|
|
|
|
}
|
2012-02-27 18:43:39 +04:00
|
|
|
|
|
|
|
void
|
2012-02-29 11:35:51 +04:00
|
|
|
StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue)
|
2012-02-27 18:43:39 +04: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-29 11:35:51 +04:00
|
|
|
|
2012-03-10 19:35:02 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue)
|
2012-03-10 19:35:02 +04:00
|
|
|
{
|
|
|
|
nsCSSKeyword keyword =
|
|
|
|
nsCSSProps::ValueToKeywordEnum(aValue,
|
|
|
|
nsCSSProps::kTextDecorationStyleKTable);
|
|
|
|
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
|
|
|
|
}
|