2012-02-20 15:45:29 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-06-29 10:42:59 +00:00
|
|
|
/* vim: set expandtab shiftwidth=2 tabstop=2: */
|
2012-05-21 11:12:37 +00: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 15:45:29 +00:00
|
|
|
|
|
|
|
#include "StyleInfo.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "nsComputedDOMStyle.h"
|
2013-03-03 00:31:48 +00:00
|
|
|
#include "nsCSSProps.h"
|
2012-08-06 03:00:56 +00:00
|
|
|
#include "nsIFrame.h"
|
2012-02-20 15:45:29 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2018-01-23 14:49:00 +00:00
|
|
|
StyleInfo::StyleInfo(dom::Element* aElement) : mElement(aElement) {
|
2018-03-22 18:20:41 +00:00
|
|
|
mComputedStyle =
|
|
|
|
nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
|
2012-02-20 15:45:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleInfo::Display(nsAString& aValue) {
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
2018-03-22 18:20:41 +00:00
|
|
|
nsCSSProps::ValueToKeyword(mComputedStyle->StyleDisplay()->mDisplay,
|
2012-02-20 15:45:29 +00:00
|
|
|
nsCSSProps::kDisplayKTable),
|
|
|
|
aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleInfo::TextAlign(nsAString& aValue) {
|
|
|
|
aValue.Truncate();
|
|
|
|
AppendASCIItoUTF16(
|
2018-03-22 18:20:41 +00:00
|
|
|
nsCSSProps::ValueToKeyword(mComputedStyle->StyleText()->mTextAlign,
|
2012-02-20 15:45:29 +00:00
|
|
|
nsCSSProps::kTextAlignKTable),
|
|
|
|
aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StyleInfo::TextIndent(nsAString& aValue) {
|
|
|
|
aValue.Truncate();
|
|
|
|
|
2019-01-26 10:00:06 +00:00
|
|
|
const auto& textIndent = mComputedStyle->StyleText()->mTextIndent;
|
|
|
|
if (textIndent.ConvertsToLength()) {
|
|
|
|
aValue.AppendFloat(textIndent.LengthInCSSPixels());
|
|
|
|
aValue.AppendLiteral("px");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (textIndent.ConvertsToPercentage()) {
|
|
|
|
aValue.AppendFloat(textIndent.ToPercentage() * 100);
|
|
|
|
aValue.AppendLiteral("%");
|
|
|
|
return;
|
2012-02-20 15:45:29 +00:00
|
|
|
}
|
2019-01-26 10:00:06 +00:00
|
|
|
// FIXME: This doesn't handle calc in any meaningful way?
|
|
|
|
aValue.AppendLiteral("0px");
|
2012-02-20 15:45:29 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 08:28:38 +00:00
|
|
|
void StyleInfo::Margin(Side aSide, nsAString& aValue) {
|
2015-12-28 11:25:00 +00:00
|
|
|
MOZ_ASSERT(mElement->GetPrimaryFrame(),
|
|
|
|
" mElement->GetPrimaryFrame() needs to be valid pointer");
|
2012-02-20 15:45:29 +00:00
|
|
|
aValue.Truncate();
|
|
|
|
|
|
|
|
nscoord coordVal = mElement->GetPrimaryFrame()->GetUsedMargin().Side(aSide);
|
|
|
|
aValue.AppendFloat(nsPresContext::AppUnitsToFloatCSSPixels(coordVal));
|
|
|
|
aValue.AppendLiteral("px");
|
|
|
|
}
|
2012-02-27 14:43:39 +00:00
|
|
|
|
2012-02-29 07:35:51 +00:00
|
|
|
void StyleInfo::FormatColor(const nscolor& aValue, nsString& aFormattedValue) {
|
2012-02-27 14:43:39 +00: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 07:35:51 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
void StyleInfo::FormatTextDecorationStyle(uint8_t aValue,
|
|
|
|
nsAString& aFormattedValue) {
|
2012-03-10 15:35:02 +00:00
|
|
|
nsCSSKeyword keyword = nsCSSProps::ValueToKeywordEnum(
|
|
|
|
aValue, nsCSSProps::kTextDecorationStyleKTable);
|
|
|
|
AppendUTF8toUTF16(nsCSSKeywords::GetStringValue(keyword), aFormattedValue);
|
|
|
|
}
|