diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /accessible/base/StyleInfo.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'accessible/base/StyleInfo.cpp')
-rw-r--r-- | accessible/base/StyleInfo.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/accessible/base/StyleInfo.cpp b/accessible/base/StyleInfo.cpp new file mode 100644 index 000000000..d49152cba --- /dev/null +++ b/accessible/base/StyleInfo.cpp @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set expandtab shiftwidth=2 tabstop=2: */ +/* 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/. */ + +#include "StyleInfo.h" + +#include "mozilla/dom/Element.h" +#include "nsComputedDOMStyle.h" +#include "nsCSSProps.h" +#include "nsIFrame.h" + +using namespace mozilla; +using namespace mozilla::a11y; + +StyleInfo::StyleInfo(dom::Element* aElement, nsIPresShell* aPresShell) : + mElement(aElement) +{ + mStyleContext = + nsComputedDOMStyle::GetStyleContextForElementNoFlush(aElement, + nullptr, + aPresShell); +} + +void +StyleInfo::Display(nsAString& aValue) +{ + aValue.Truncate(); + AppendASCIItoUTF16( + nsCSSProps::ValueToKeyword(mStyleContext->StyleDisplay()->mDisplay, + nsCSSProps::kDisplayKTable), aValue); +} + +void +StyleInfo::TextAlign(nsAString& aValue) +{ + aValue.Truncate(); + AppendASCIItoUTF16( + nsCSSProps::ValueToKeyword(mStyleContext->StyleText()->mTextAlign, + nsCSSProps::kTextAlignKTable), aValue); +} + +void +StyleInfo::TextIndent(nsAString& aValue) +{ + aValue.Truncate(); + + const nsStyleCoord& styleCoord = + mStyleContext->StyleText()->mTextIndent; + + nscoord coordVal = 0; + switch (styleCoord.GetUnit()) { + case eStyleUnit_Coord: + coordVal = styleCoord.GetCoordValue(); + aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); + aValue.AppendLiteral("px"); + break; + + case eStyleUnit_Percent: + aValue.AppendFloat(styleCoord.GetPercentValue() * 100); + aValue.AppendLiteral("%"); + break; + + 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_FlexFraction: + case eStyleUnit_Integer: + case eStyleUnit_Enumerated: + case eStyleUnit_Calc: + aValue.AppendLiteral("0px"); + break; + } +} + +void +StyleInfo::Margin(css::Side aSide, nsAString& aValue) +{ + MOZ_ASSERT(mElement->GetPrimaryFrame(), " mElement->GetPrimaryFrame() needs to be valid pointer"); + aValue.Truncate(); + + nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide); + aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal)); + aValue.AppendLiteral("px"); +} + +void +StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue) +{ + // 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(')'); +} + +void +StyleInfo::FormatFontStyle(const nscoord& aValue, nsAString& aFormattedValue) +{ + nsCSSKeyword keyword = + nsCSSProps::ValueToKeywordEnum(aValue, nsCSSProps::kFontStyleKTable); + AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue); +} + +void +StyleInfo::FormatTextDecorationStyle(uint8_t aValue, nsAString& aFormattedValue) +{ + nsCSSKeyword keyword = + nsCSSProps::ValueToKeywordEnum(aValue, + nsCSSProps::kTextDecorationStyleKTable); + AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue); +} |