2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-12-01 21:07:42 -08:00
|
|
|
#include "nsHTMLCSSUtils.h"
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
#include "ChangeStyleTxn.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "EditTxn.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2012-07-08 03:31:53 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
|
|
|
#include "mozilla/css/StyleRule.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAString.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsColor.h"
|
2012-07-08 02:50:31 -07:00
|
|
|
#include "nsComputedDOMStyle.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsDependentSubstring.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsHTMLEditor.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
#include "nsLiteralString.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsReadableUtils.h"
|
2012-07-12 23:33:42 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsStringIterator.h"
|
|
|
|
#include "nsSubstringTuple.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsUnicharUtils.h"
|
2011-06-16 17:59:29 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2014-08-29 04:43:24 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessBValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
if (aInputString && aInputString->EqualsLiteral("-moz-editor-invert-value")) {
|
|
|
|
aOutputString.AssignLiteral("normal");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aOutputString.AssignLiteral("bold");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessDefaultValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
CopyASCIItoUTF16(aDefaultValueString, aOutputString);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessSameValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Assign(*aInputString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aOutputString.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessExtendedValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aPrependString) {
|
|
|
|
AppendASCIItoUTF16(aPrependString, aOutputString);
|
|
|
|
}
|
|
|
|
aOutputString.Append(*aInputString);
|
|
|
|
if (aAppendString) {
|
|
|
|
AppendASCIItoUTF16(aAppendString, aOutputString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessLengthValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Append(*aInputString);
|
2014-01-04 07:02:17 -08:00
|
|
|
if (-1 == aOutputString.FindChar(char16_t('%'))) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aOutputString.AppendLiteral("px");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessListStyleTypeValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aInputString->EqualsLiteral("1")) {
|
|
|
|
aOutputString.AppendLiteral("decimal");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("a")) {
|
|
|
|
aOutputString.AppendLiteral("lower-alpha");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("A")) {
|
|
|
|
aOutputString.AppendLiteral("upper-alpha");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("i")) {
|
|
|
|
aOutputString.AppendLiteral("lower-roman");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("I")) {
|
|
|
|
aOutputString.AppendLiteral("upper-roman");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("square")
|
|
|
|
|| aInputString->EqualsLiteral("circle")
|
|
|
|
|| aInputString->EqualsLiteral("disc")) {
|
|
|
|
aOutputString.Append(*aInputString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessMarginLeftValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
|
|
|
aOutputString.AppendLiteral("auto");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("right") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-right")) {
|
|
|
|
aOutputString.AppendLiteral("auto");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aOutputString.AppendLiteral("0px");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void ProcessMarginRightValue(const nsAString * aInputString, nsAString & aOutputString,
|
|
|
|
const char * aDefaultValueString,
|
|
|
|
const char * aPrependString, const char* aAppendString)
|
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
|
|
|
aOutputString.AppendLiteral("auto");
|
|
|
|
}
|
|
|
|
else if (aInputString->EqualsLiteral("left") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-left")) {
|
|
|
|
aOutputString.AppendLiteral("auto");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aOutputString.AppendLiteral("0px");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable italicEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable underlineEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable strikeEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable ttEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontColorEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable fontFaceEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable bgcolorEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable backgroundImageEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nullptr, "url(", ")", true, true },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textColorEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable borderEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_border, ProcessExtendedValue, nullptr, nullptr, "px solid", true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable textAlignEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable captionAlignEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable verticalAlignEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable nowrapEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable widthEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_width, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable heightEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_height, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable listStyleTypeEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nullptr, nullptr, nullptr, true, true },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable tableAlignEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessDefaultValue, "left", nullptr, nullptr, false, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const nsHTMLCSSUtils::CSSEquivTable hrAlignEquivTable[] = {
|
2012-07-30 07:20:58 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nullptr, nullptr, nullptr, true, false },
|
2007-03-22 10:30:00 -07:00
|
|
|
{ nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
|
|
|
|
};
|
|
|
|
|
2011-05-15 03:07:30 -07:00
|
|
|
nsHTMLCSSUtils::nsHTMLCSSUtils(nsHTMLEditor* aEditor)
|
|
|
|
: mHTMLEditor(aEditor)
|
2012-04-03 07:16:05 -07:00
|
|
|
, mIsCSSPrefChecked(true)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// let's retrieve the value of the "CSS editing" pref
|
2011-06-16 17:59:29 -07:00
|
|
|
mIsCSSPrefChecked = Preferences::GetBool("editor.use_css", mIsCSSPrefChecked);
|
2011-05-15 03:07:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLCSSUtils::~nsHTMLCSSUtils()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true if we have some CSS equivalence for the HTML style defined
|
|
|
|
// by aProperty and/or aAttribute for the node aNode
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-04-24 03:57:49 -07:00
|
|
|
nsHTMLCSSUtils::IsCSSEditableProperty(nsIDOMNode* aNode,
|
|
|
|
nsIAtom* aProperty,
|
2013-02-05 22:00:59 -08:00
|
|
|
const nsAString* aAttribute)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aNode, "Shouldn't you pass aNode? - Bug 214025");
|
|
|
|
|
2012-02-10 02:04:47 -08:00
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_TRUE(content, false);
|
2013-02-05 22:00:59 -08:00
|
|
|
return IsCSSEditableProperty(content, aProperty, aAttribute);
|
2012-02-10 02:04:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsHTMLCSSUtils::IsCSSEditableProperty(nsIContent* aNode,
|
|
|
|
nsIAtom* aProperty,
|
2013-02-05 22:00:59 -08:00
|
|
|
const nsAString* aAttribute)
|
2012-02-10 02:04:47 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
|
|
|
|
nsIContent* content = aNode;
|
2007-03-22 10:30:00 -07:00
|
|
|
// we need an element node here
|
2012-02-10 02:04:47 -08:00
|
|
|
if (content->NodeType() == nsIDOMNode::TEXT_NODE) {
|
|
|
|
content = content->GetParent();
|
|
|
|
NS_ENSURE_TRUE(content, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// html inline styles B I TT U STRIKE and COLOR/FACE on FONT
|
2014-08-29 04:43:24 -07:00
|
|
|
if (nsGkAtoms::b == aProperty ||
|
|
|
|
nsGkAtoms::i == aProperty ||
|
|
|
|
nsGkAtoms::tt == aProperty ||
|
|
|
|
nsGkAtoms::u == aProperty ||
|
|
|
|
nsGkAtoms::strike == aProperty ||
|
|
|
|
(nsGkAtoms::font == aProperty && aAttribute &&
|
|
|
|
(aAttribute->EqualsLiteral("color") ||
|
|
|
|
aAttribute->EqualsLiteral("face")))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ALIGN attribute on elements supporting it
|
|
|
|
if (aAttribute && (aAttribute->EqualsLiteral("align")) &&
|
2015-03-03 03:08:59 -08:00
|
|
|
content->IsAnyOfHTMLElements(nsGkAtoms::div,
|
|
|
|
nsGkAtoms::p ,
|
|
|
|
nsGkAtoms::h1,
|
|
|
|
nsGkAtoms::h2,
|
|
|
|
nsGkAtoms::h3,
|
|
|
|
nsGkAtoms::h4,
|
|
|
|
nsGkAtoms::h5,
|
|
|
|
nsGkAtoms::h6,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th,
|
|
|
|
nsGkAtoms::table,
|
|
|
|
nsGkAtoms::hr,
|
|
|
|
// brade: for the above, why not use
|
|
|
|
// nsHTMLEditUtils::SupportsAlignAttr
|
|
|
|
// brade: but it also checks for tbody,
|
|
|
|
// tfoot, thead Let's add the following
|
|
|
|
// elements here even if ALIGN has not the
|
|
|
|
// same meaning for them
|
|
|
|
nsGkAtoms::legend,
|
|
|
|
nsGkAtoms::caption)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aAttribute && (aAttribute->EqualsLiteral("valign")) &&
|
2015-03-03 03:08:59 -08:00
|
|
|
content->IsAnyOfHTMLElements(nsGkAtoms::col,
|
|
|
|
nsGkAtoms::colgroup,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tr)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes TEXT, BACKGROUND and BGCOLOR on BODY
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aAttribute && content->IsHTMLElement(nsGkAtoms::body) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aAttribute->EqualsLiteral("text")
|
|
|
|
|| aAttribute->EqualsLiteral("background")
|
|
|
|
|| aAttribute->EqualsLiteral("bgcolor"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute BGCOLOR on other elements
|
|
|
|
if (aAttribute && aAttribute->EqualsLiteral("bgcolor")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT, WIDTH and NOWRAP on TD and TH
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aAttribute &&
|
|
|
|
content->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aAttribute->EqualsLiteral("height")
|
|
|
|
|| aAttribute->EqualsLiteral("width")
|
|
|
|
|| aAttribute->EqualsLiteral("nowrap"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT and WIDTH on TABLE
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aAttribute && content->IsHTMLElement(nsGkAtoms::table) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aAttribute->EqualsLiteral("height")
|
|
|
|
|| aAttribute->EqualsLiteral("width"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes SIZE and WIDTH on HR
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aAttribute && content->IsHTMLElement(nsGkAtoms::hr) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aAttribute->EqualsLiteral("size")
|
|
|
|
|| aAttribute->EqualsLiteral("width"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute TYPE on OL UL LI
|
2014-08-29 04:43:24 -07:00
|
|
|
if (aAttribute &&
|
2015-03-03 03:08:59 -08:00
|
|
|
content->IsAnyOfHTMLElements(nsGkAtoms::ol, nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::li) &&
|
|
|
|
aAttribute->EqualsLiteral("type")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aAttribute && content->IsHTMLElement(nsGkAtoms::img) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
(aAttribute->EqualsLiteral("border")
|
|
|
|
|| aAttribute->EqualsLiteral("width")
|
|
|
|
|| aAttribute->EqualsLiteral("height"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// other elements that we can align using CSS even if they
|
|
|
|
// can't carry the html ALIGN attribute
|
|
|
|
if (aAttribute && aAttribute->EqualsLiteral("align") &&
|
2015-03-03 03:08:59 -08:00
|
|
|
content->IsAnyOfHTMLElements(nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::ol,
|
|
|
|
nsGkAtoms::dl,
|
|
|
|
nsGkAtoms::li,
|
|
|
|
nsGkAtoms::dd,
|
|
|
|
nsGkAtoms::dt,
|
|
|
|
nsGkAtoms::address,
|
2015-03-26 17:42:57 -07:00
|
|
|
nsGkAtoms::pre)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
// The lowest level above the transaction; adds the CSS declaration
|
|
|
|
// "aProperty : aValue" to the inline styles carried by aElement
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2014-08-29 04:43:24 -07:00
|
|
|
nsHTMLCSSUtils::SetCSSProperty(Element& aElement, nsIAtom& aProperty,
|
|
|
|
const nsAString& aValue, bool aSuppressTxn)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-08-29 04:43:24 -07:00
|
|
|
nsRefPtr<ChangeStyleTxn> txn =
|
|
|
|
CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eSet);
|
|
|
|
if (aSuppressTxn) {
|
|
|
|
return txn->DoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
return mHTMLEditor->DoTransaction(txn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-08-29 04:43:24 -07:00
|
|
|
nsHTMLCSSUtils::SetCSSPropertyPixels(Element& aElement, nsIAtom& aProperty,
|
|
|
|
int32_t aIntValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
s.AppendInt(aIntValue);
|
|
|
|
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"),
|
2014-08-29 04:43:24 -07:00
|
|
|
/* suppress txn */ false);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
// The lowest level above the transaction; removes the value aValue from the
|
|
|
|
// list of values specified for the CSS property aProperty, or totally remove
|
|
|
|
// the declaration if this property accepts only one value
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2014-08-29 04:43:24 -07:00
|
|
|
nsHTMLCSSUtils::RemoveCSSProperty(Element& aElement, nsIAtom& aProperty,
|
|
|
|
const nsAString& aValue, bool aSuppressTxn)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-08-29 04:43:24 -07:00
|
|
|
nsRefPtr<ChangeStyleTxn> txn =
|
|
|
|
CreateCSSPropertyTxn(aElement, aProperty, aValue, ChangeStyleTxn::eRemove);
|
|
|
|
if (aSuppressTxn) {
|
|
|
|
return txn->DoTransaction();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
return mHTMLEditor->DoTransaction(txn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
already_AddRefed<ChangeStyleTxn>
|
|
|
|
nsHTMLCSSUtils::CreateCSSPropertyTxn(Element& aElement, nsIAtom& aAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString& aValue,
|
2014-08-29 04:43:24 -07:00
|
|
|
ChangeStyleTxn::EChangeType aChangeType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-08-29 04:43:24 -07:00
|
|
|
nsRefPtr<ChangeStyleTxn> txn =
|
|
|
|
new ChangeStyleTxn(aElement, aAttribute, aValue, aChangeType);
|
|
|
|
return txn.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetSpecifiedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|
|
|
nsAString & aValue)
|
|
|
|
{
|
2012-07-08 02:50:31 -07:00
|
|
|
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eSpecified);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetComputedProperty(nsIDOMNode *aNode, nsIAtom *aProperty,
|
|
|
|
nsAString & aValue)
|
|
|
|
{
|
2012-07-08 02:50:31 -07:00
|
|
|
return GetCSSInlinePropertyBase(aNode, aProperty, aValue, eComputed);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-10 02:04:47 -08:00
|
|
|
nsresult
|
2012-07-08 03:31:53 -07:00
|
|
|
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsIDOMNode* aNode, nsIAtom* aProperty,
|
2012-02-10 02:04:47 -08:00
|
|
|
nsAString& aValue,
|
2012-07-06 04:50:07 -07:00
|
|
|
StyleType aStyleType)
|
2012-02-10 02:04:47 -08:00
|
|
|
{
|
2012-07-08 03:31:53 -07:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
2012-07-08 02:50:31 -07:00
|
|
|
return GetCSSInlinePropertyBase(node, aProperty, aValue, aStyleType);
|
2012-02-10 02:04:47 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2012-07-08 03:31:53 -07:00
|
|
|
nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
|
2011-04-23 23:54:25 -07:00
|
|
|
nsAString& aValue,
|
2012-07-06 04:50:07 -07:00
|
|
|
StyleType aStyleType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-08 03:31:53 -07:00
|
|
|
MOZ_ASSERT(aNode && aProperty);
|
2007-03-22 10:30:00 -07:00
|
|
|
aValue.Truncate();
|
|
|
|
|
2012-07-08 03:31:53 -07:00
|
|
|
nsCOMPtr<dom::Element> element = GetElementContainerOrSelf(aNode);
|
2012-02-01 02:54:22 -08:00
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-08 03:31:53 -07:00
|
|
|
if (aStyleType == eComputed) {
|
|
|
|
// Get the all the computed css styles attached to the element node
|
|
|
|
nsRefPtr<nsComputedDOMStyle> cssDecl = GetComputedStyle(element);
|
|
|
|
NS_ENSURE_STATE(cssDecl);
|
|
|
|
|
|
|
|
// from these declarations, get the one we want and that one only
|
|
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
|
|
|
|
cssDecl->GetPropertyValue(nsDependentAtomString(aProperty), aValue)));
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-07-08 03:31:53 -07:00
|
|
|
}
|
2012-07-08 03:31:53 -07:00
|
|
|
|
|
|
|
MOZ_ASSERT(aStyleType == eSpecified);
|
|
|
|
nsRefPtr<css::StyleRule> rule = element->GetInlineStyleRule();
|
|
|
|
if (!rule) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsCSSProperty prop =
|
|
|
|
nsCSSProps::LookupProperty(nsDependentAtomString(aProperty),
|
2014-03-07 09:14:23 -08:00
|
|
|
nsCSSProps::eEnabledForAllContent);
|
2012-07-08 03:31:53 -07:00
|
|
|
MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
|
|
|
|
rule->GetDeclaration()->GetValue(prop, aValue);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-08 02:50:31 -07:00
|
|
|
already_AddRefed<nsComputedDOMStyle>
|
|
|
|
nsHTMLCSSUtils::GetComputedStyle(nsIDOMElement* aElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-08 02:50:31 -07:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
|
|
|
|
return GetComputedStyle(element);
|
2012-02-10 02:04:47 -08:00
|
|
|
}
|
|
|
|
|
2012-07-08 02:50:31 -07:00
|
|
|
already_AddRefed<nsComputedDOMStyle>
|
|
|
|
nsHTMLCSSUtils::GetComputedStyle(dom::Element* aElement)
|
2012-02-10 02:04:47 -08:00
|
|
|
{
|
2012-07-08 02:50:31 -07:00
|
|
|
MOZ_ASSERT(aElement);
|
2012-07-08 02:50:31 -07:00
|
|
|
|
2012-07-08 02:50:31 -07:00
|
|
|
nsIDocument* doc = aElement->GetCurrentDoc();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(doc, nullptr);
|
2012-07-08 02:50:31 -07:00
|
|
|
|
|
|
|
nsIPresShell* presShell = doc->GetShell();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(presShell, nullptr);
|
2012-07-08 02:50:31 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsComputedDOMStyle> style =
|
|
|
|
NS_NewComputedDOMStyle(aElement, EmptyString(), presShell);
|
|
|
|
|
|
|
|
return style.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove the CSS style "aProperty : aPropertyValue" and possibly remove the whole node
|
|
|
|
// if it is a span and if its only attribute is _moz_dirty
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::RemoveCSSInlineStyle(nsIDOMNode *aNode, nsIAtom *aProperty, const nsAString & aPropertyValue)
|
|
|
|
{
|
2014-08-29 04:43:24 -07:00
|
|
|
nsCOMPtr<Element> element = do_QueryInterface(aNode);
|
|
|
|
NS_ENSURE_STATE(element);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// remove the property from the style attribute
|
2014-08-29 04:43:24 -07:00
|
|
|
nsresult res = RemoveCSSProperty(*element, *aProperty, aPropertyValue);
|
2010-06-17 12:27:24 -07:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-03 03:08:59 -08:00
|
|
|
if (!element->IsHTMLElement(nsGkAtoms::span) ||
|
2012-02-10 02:04:46 -08:00
|
|
|
nsHTMLEditor::HasAttributes(element)) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-10 02:04:46 -08:00
|
|
|
|
2014-08-20 05:25:16 -07:00
|
|
|
return mHTMLEditor->RemoveContainer(element);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true is the property can be removed by setting a "none" CSS value
|
|
|
|
// on a node
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLCSSUtils::IsCSSInvertable(nsIAtom *aProperty, const nsAString *aAttribute)
|
|
|
|
{
|
2014-08-29 04:43:24 -07:00
|
|
|
return nsGkAtoms::b == aProperty;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default browser background color if we need it for GetCSSBackgroundColorState
|
2011-06-16 17:59:29 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLCSSUtils::GetDefaultBackgroundColor(nsAString & aColor)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("editor.use_custom_colors", false)) {
|
2011-06-16 17:59:29 -07:00
|
|
|
nsresult rv = Preferences::GetString("editor.background_color", &aColor);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to get editor.background_color");
|
|
|
|
aColor.AssignLiteral("#ffffff"); // Default to white
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-16 17:59:29 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-06-16 17:59:29 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
if (Preferences::GetBool("browser.display.use_system_colors", false)) {
|
2011-06-16 17:59:29 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv =
|
|
|
|
Preferences::GetString("browser.display.background_color", &aColor);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("failed to get browser.display.background_color");
|
|
|
|
aColor.AssignLiteral("#ffffff"); // Default to white
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default length unit used for CSS Indent/Outdent
|
2011-06-16 17:59:29 -07:00
|
|
|
void
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLCSSUtils::GetDefaultLengthUnit(nsAString & aLengthUnit)
|
|
|
|
{
|
2011-06-16 17:59:29 -07:00
|
|
|
nsresult rv =
|
|
|
|
Preferences::GetString("editor.css.default_length_unit", &aLengthUnit);
|
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aLengthUnit.AssignLiteral("px");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unfortunately, CSSStyleDeclaration::GetPropertyCSSValue is not yet implemented...
|
|
|
|
// We need then a way to determine the number part and the unit from aString, aString
|
|
|
|
// being the result of a GetPropertyValue query...
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::ParseLength(const nsAString & aString, float * aValue, nsIAtom ** aUnit)
|
|
|
|
{
|
|
|
|
nsAString::const_iterator iter;
|
|
|
|
aString.BeginReading(iter);
|
|
|
|
|
|
|
|
float a = 10.0f , b = 1.0f, value = 0;
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t sign = 1;
|
|
|
|
int32_t i = 0, j = aString.Length();
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t c;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool floatingPointFound = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
c = *iter;
|
2014-01-04 07:02:17 -08:00
|
|
|
if (char16_t('-') == c) { sign = -1; iter++; i++; }
|
|
|
|
else if (char16_t('+') == c) { iter++; i++; }
|
2007-03-22 10:30:00 -07:00
|
|
|
while (i < j) {
|
|
|
|
c = *iter;
|
2014-01-04 07:02:17 -08:00
|
|
|
if ((char16_t('0') == c) ||
|
|
|
|
(char16_t('1') == c) ||
|
|
|
|
(char16_t('2') == c) ||
|
|
|
|
(char16_t('3') == c) ||
|
|
|
|
(char16_t('4') == c) ||
|
|
|
|
(char16_t('5') == c) ||
|
|
|
|
(char16_t('6') == c) ||
|
|
|
|
(char16_t('7') == c) ||
|
|
|
|
(char16_t('8') == c) ||
|
|
|
|
(char16_t('9') == c)) {
|
|
|
|
value = (value * a) + (b * (c - char16_t('0')));
|
2007-03-22 10:30:00 -07:00
|
|
|
b = b / 10 * a;
|
|
|
|
}
|
2014-01-04 07:02:17 -08:00
|
|
|
else if (!floatingPointFound && (char16_t('.') == c)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
floatingPointFound = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
a = 1.0f; b = 0.1f;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
iter++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*aValue = value * sign;
|
2014-03-15 12:00:15 -07:00
|
|
|
*aUnit = NS_NewAtom(StringTail(aString, j-i)).take();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aAtom = nullptr;
|
2009-07-22 15:31:01 -07:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSEditableProperty_background_color:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::backgroundColor;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_background_image:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::background_image;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_border:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::border;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_caption_side:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::caption_side;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_color:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::color;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_float:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::_float;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_family:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::font_family;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_size:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::font_size;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_style:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::font_style;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_weight:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::fontWeight;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_height:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::height;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_list_style_type:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::list_style_type;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_left:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::marginLeft;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_right:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::marginRight;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_align:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::textAlign;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_decoration:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::text_decoration;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_vertical_align:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::vertical_align;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_whitespace:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::white_space;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_width:
|
2014-08-29 04:43:24 -07:00
|
|
|
*aAtom = nsGkAtoms::width;
|
2009-07-22 15:31:01 -07:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_NONE:
|
|
|
|
// intentionally empty
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate aProperty and aValueArray with the CSS declarations equivalent to the
|
|
|
|
// value aValue according to the equivalence table aEquivTable
|
|
|
|
void
|
2009-04-22 01:43:15 -07:00
|
|
|
nsHTMLCSSUtils::BuildCSSDeclarations(nsTArray<nsIAtom*> & aPropertyArray,
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString> & aValueArray,
|
2007-03-22 10:30:00 -07:00
|
|
|
const CSSEquivTable * aEquivTable,
|
|
|
|
const nsAString * aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aGetOrRemoveRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// clear arrays
|
|
|
|
aPropertyArray.Clear();
|
|
|
|
aValueArray.Clear();
|
|
|
|
|
|
|
|
// if we have an input value, let's use it
|
|
|
|
nsAutoString value, lowerCasedValue;
|
|
|
|
if (aValue) {
|
|
|
|
value.Assign(*aValue);
|
|
|
|
lowerCasedValue.Assign(*aValue);
|
|
|
|
ToLowerCase(lowerCasedValue);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int8_t index = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSEditableProperty cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
while (cssProperty) {
|
|
|
|
if (!aGetOrRemoveRequest|| aEquivTable[index].gettable) {
|
|
|
|
nsAutoString cssValue, cssPropertyString;
|
|
|
|
nsIAtom * cssPropertyAtom;
|
|
|
|
// find the equivalent css value for the index-th property in
|
|
|
|
// the equivalence table
|
|
|
|
(*aEquivTable[index].processValueFunctor) ((!aGetOrRemoveRequest || aEquivTable[index].caseSensitiveValue) ? &value : &lowerCasedValue,
|
|
|
|
cssValue,
|
|
|
|
aEquivTable[index].defaultValue,
|
|
|
|
aEquivTable[index].prependValue,
|
|
|
|
aEquivTable[index].appendValue);
|
|
|
|
GetCSSPropertyAtom(cssProperty, &cssPropertyAtom);
|
|
|
|
aPropertyArray.AppendElement(cssPropertyAtom);
|
2009-01-18 12:14:14 -08:00
|
|
|
aValueArray.AppendElement(cssValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate cssPropertyArray and cssValueArray with the declarations equivalent
|
|
|
|
// to aHTMLProperty/aAttribute/aValue for the node aNode
|
|
|
|
void
|
2012-02-10 02:04:47 -08:00
|
|
|
nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle(dom::Element* aElement,
|
|
|
|
nsIAtom* aHTMLProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue,
|
|
|
|
nsTArray<nsIAtom*>& cssPropertyArray,
|
|
|
|
nsTArray<nsString>& cssValueArray,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aGetOrRemoveRequest)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-10 02:04:47 -08:00
|
|
|
MOZ_ASSERT(aElement);
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsHTMLCSSUtils::CSSEquivTable* equivTable = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
if (nsGkAtoms::b == aHTMLProperty) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = boldEquivTable;
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::i == aHTMLProperty) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = italicEquivTable;
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::u == aHTMLProperty) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = underlineEquivTable;
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::strike == aHTMLProperty) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = strikeEquivTable;
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::tt == aHTMLProperty) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = ttEquivTable;
|
|
|
|
} else if (aAttribute) {
|
2014-08-29 04:43:24 -07:00
|
|
|
if (nsGkAtoms::font == aHTMLProperty &&
|
2007-03-22 10:30:00 -07:00
|
|
|
aAttribute->EqualsLiteral("color")) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = fontColorEquivTable;
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::font == aHTMLProperty &&
|
2012-04-24 03:57:23 -07:00
|
|
|
aAttribute->EqualsLiteral("face")) {
|
|
|
|
equivTable = fontFaceEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("bgcolor")) {
|
|
|
|
equivTable = bgcolorEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("background")) {
|
|
|
|
equivTable = backgroundImageEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("text")) {
|
|
|
|
equivTable = textColorEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("border")) {
|
|
|
|
equivTable = borderEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("align")) {
|
2015-03-03 03:08:59 -08:00
|
|
|
if (aElement->IsHTMLElement(nsGkAtoms::table)) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = tableAlignEquivTable;
|
2015-03-03 03:08:59 -08:00
|
|
|
} else if (aElement->IsHTMLElement(nsGkAtoms::hr)) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = hrAlignEquivTable;
|
2015-03-03 03:08:59 -08:00
|
|
|
} else if (aElement->IsAnyOfHTMLElements(nsGkAtoms::legend,
|
|
|
|
nsGkAtoms::caption)) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = captionAlignEquivTable;
|
|
|
|
} else {
|
|
|
|
equivTable = textAlignEquivTable;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-04-24 03:57:23 -07:00
|
|
|
} else if (aAttribute->EqualsLiteral("valign")) {
|
|
|
|
equivTable = verticalAlignEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("nowrap")) {
|
|
|
|
equivTable = nowrapEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("width")) {
|
|
|
|
equivTable = widthEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("height") ||
|
2015-03-03 03:08:59 -08:00
|
|
|
(aElement->IsHTMLElement(nsGkAtoms::hr) &&
|
2012-04-24 03:57:23 -07:00
|
|
|
aAttribute->EqualsLiteral("size"))) {
|
|
|
|
equivTable = heightEquivTable;
|
|
|
|
} else if (aAttribute->EqualsLiteral("type") &&
|
2015-03-03 03:08:59 -08:00
|
|
|
aElement->IsAnyOfHTMLElements(nsGkAtoms::ol,
|
|
|
|
nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::li)) {
|
2012-04-24 03:57:23 -07:00
|
|
|
equivTable = listStyleTypeEquivTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (equivTable) {
|
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, equivTable,
|
|
|
|
aValue, aGetOrRemoveRequest);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 00:12:51 -07:00
|
|
|
// Add to aNode the CSS inline style equivalent to HTMLProperty/aAttribute/
|
|
|
|
// aValue for the node, and return in aCount the number of CSS properties set
|
|
|
|
// by the call. The dom::Element version returns aCount instead.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t
|
2012-05-29 00:12:51 -07:00
|
|
|
nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(dom::Element* aElement,
|
|
|
|
nsIAtom* aProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue,
|
|
|
|
bool aSuppressTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aElement && aProperty);
|
|
|
|
MOZ_ASSERT_IF(aAttribute, aValue);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count;
|
2012-05-29 00:12:51 -07:00
|
|
|
// This can only fail if SetCSSProperty fails, which should only happen if
|
|
|
|
// something is pretty badly wrong. In this case we assert so that hopefully
|
|
|
|
// someone will notice, but there's nothing more sensible to do than just
|
|
|
|
// return the count and carry on.
|
|
|
|
nsresult res = SetCSSEquivalentToHTMLStyle(aElement->AsDOMNode(),
|
|
|
|
aProperty, aAttribute,
|
|
|
|
aValue, &count,
|
|
|
|
aSuppressTransaction);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(res), "SetCSSEquivalentToHTMLStyle failed");
|
|
|
|
NS_ENSURE_SUCCESS(res, count);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
|
|
|
const nsAString *aAttribute,
|
|
|
|
const nsAString *aValue,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t * aCount,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSuppressTransaction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-10 02:04:47 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aCount = 0;
|
2013-02-05 22:00:59 -08:00
|
|
|
if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) {
|
2012-02-10 02:04:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can apply the styles only if the node is an element and if we have
|
|
|
|
// an equivalence for the requested HTML style in this implementation
|
|
|
|
|
|
|
|
// Find the CSS equivalence to the HTML style
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(element, aHTMLProperty, aAttribute,
|
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// set the individual CSS inline styles
|
|
|
|
*aCount = cssPropertyArray.Length();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = 0; index < *aCount; index++) {
|
2014-08-29 04:43:24 -07:00
|
|
|
nsresult res = SetCSSProperty(*element, *cssPropertyArray[index],
|
2012-02-10 02:04:47 -08:00
|
|
|
cssValueArray[index], aSuppressTransaction);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from aNode the CSS inline style equivalent to HTMLProperty/aAttribute/aValue for the node
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
|
|
|
|
nsIAtom *aHTMLProperty,
|
|
|
|
const nsAString *aAttribute,
|
|
|
|
const nsAString *aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aSuppressTransaction)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-10 02:04:47 -08:00
|
|
|
nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
|
2013-03-09 23:58:34 -08:00
|
|
|
NS_ENSURE_TRUE(element, NS_OK);
|
|
|
|
|
|
|
|
return RemoveCSSEquivalentToHTMLStyle(element, aHTMLProperty, aAttribute,
|
|
|
|
aValue, aSuppressTransaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::RemoveCSSEquivalentToHTMLStyle(dom::Element* aElement,
|
|
|
|
nsIAtom* aHTMLProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString* aValue,
|
|
|
|
bool aSuppressTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
|
|
|
|
if (!IsCSSEditableProperty(aElement, aHTMLProperty, aAttribute)) {
|
2012-02-10 02:04:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can apply the styles only if the node is an element and if we have
|
|
|
|
// an equivalence for the requested HTML style in this implementation
|
|
|
|
|
|
|
|
// Find the CSS equivalence to the HTML style
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
2013-03-09 23:58:34 -08:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(aElement, aHTMLProperty, aAttribute,
|
2012-02-10 02:04:47 -08:00
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
true);
|
|
|
|
|
|
|
|
// remove the individual CSS inline styles
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = cssPropertyArray.Length();
|
|
|
|
for (int32_t index = 0; index < count; index++) {
|
2014-08-29 04:43:24 -07:00
|
|
|
nsresult res = RemoveCSSProperty(*aElement,
|
|
|
|
*cssPropertyArray[index],
|
2012-02-10 02:04:47 -08:00
|
|
|
cssValueArray[index],
|
|
|
|
aSuppressTransaction);
|
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns in aValueString the list of values for the CSS equivalences to
|
|
|
|
// the HTML style aHTMLProperty/aAttribute/aValueString for the node aNode;
|
|
|
|
// the value of aStyleType controls the styles we retrieve : specified or
|
|
|
|
// computed.
|
|
|
|
nsresult
|
2012-02-10 02:04:47 -08:00
|
|
|
nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *aHTMLProperty,
|
|
|
|
const nsAString *aAttribute,
|
|
|
|
nsAString & aValueString,
|
2012-07-06 04:50:07 -07:00
|
|
|
StyleType aStyleType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aValueString.Truncate();
|
2012-02-10 02:04:47 -08:00
|
|
|
nsCOMPtr<dom::Element> theElement = GetElementContainerOrSelf(aNode);
|
2012-02-01 02:54:22 -08:00
|
|
|
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-05 22:00:59 -08:00
|
|
|
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
|
2012-02-10 02:04:47 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
|
|
|
nsTArray<nsIAtom*> cssPropertyArray;
|
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
// get the CSS equivalence with last param true indicating we want only the
|
|
|
|
// "gettable" properties
|
2012-07-30 07:20:58 -07:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute, nullptr,
|
2012-02-10 02:04:47 -08:00
|
|
|
cssPropertyArray, cssValueArray, true);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t count = cssPropertyArray.Length();
|
|
|
|
for (int32_t index = 0; index < count; index++) {
|
2012-02-10 02:04:47 -08:00
|
|
|
nsAutoString valueString;
|
|
|
|
// retrieve the specified/computed value of the property
|
|
|
|
nsresult res = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
|
2012-07-08 02:50:31 -07:00
|
|
|
valueString, aStyleType);
|
2012-02-10 02:04:47 -08:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
|
|
|
// append the value to aValueString (possibly with a leading whitespace)
|
|
|
|
if (index) {
|
2014-01-04 07:02:17 -08:00
|
|
|
aValueString.Append(char16_t(' '));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-10 02:04:47 -08:00
|
|
|
aValueString.Append(valueString);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 10:50:19 -07:00
|
|
|
// Does the node aNode (or its parent, if it's not an element node) have a CSS
|
|
|
|
// style equivalent to the HTML style aHTMLProperty/aHTMLAttribute/valueString?
|
|
|
|
// The value of aStyleType controls the styles we retrieve: specified or
|
|
|
|
// computed. The return value aIsSet is true if the CSS styles are set.
|
2012-05-22 03:15:09 -07:00
|
|
|
//
|
|
|
|
// The nsIContent variant returns aIsSet instead of using an out parameter, and
|
|
|
|
// does not modify aValue.
|
|
|
|
bool
|
|
|
|
nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIContent* aContent,
|
|
|
|
nsIAtom* aProperty,
|
|
|
|
const nsAString* aAttribute,
|
|
|
|
const nsAString& aValue,
|
2012-07-06 04:50:07 -07:00
|
|
|
StyleType aStyleType)
|
2012-05-22 03:15:09 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aContent && aProperty);
|
|
|
|
bool isSet;
|
|
|
|
nsAutoString value(aValue);
|
|
|
|
nsresult res = IsCSSEquivalentToHTMLInlineStyleSet(aContent->AsDOMNode(),
|
|
|
|
aProperty, aAttribute,
|
|
|
|
isSet, value, aStyleType);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(res), "IsCSSEquivalentToHTMLInlineStyleSet failed");
|
|
|
|
NS_ENSURE_SUCCESS(res, false);
|
|
|
|
return isSet;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2012-04-17 10:50:19 -07:00
|
|
|
nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom *aHTMLProperty,
|
2012-04-17 10:50:19 -07:00
|
|
|
const nsAString *aHTMLAttribute,
|
|
|
|
bool& aIsSet,
|
|
|
|
nsAString& valueString,
|
2012-07-06 04:50:07 -07:00
|
|
|
StyleType aStyleType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
|
|
|
|
|
|
|
|
nsAutoString htmlValueString(valueString);
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = false;
|
2012-02-10 02:04:47 -08:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
do {
|
|
|
|
valueString.Assign(htmlValueString);
|
|
|
|
// get the value of the CSS equivalent styles
|
|
|
|
nsresult res = GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
|
|
|
|
valueString, aStyleType);
|
2010-06-17 12:27:24 -07:00
|
|
|
NS_ENSURE_SUCCESS(res, res);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// early way out if we can
|
2012-04-17 10:50:19 -07:00
|
|
|
if (valueString.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
if (nsGkAtoms::b == aHTMLProperty) {
|
2012-04-17 10:50:19 -07:00
|
|
|
if (valueString.EqualsLiteral("bold")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = true;
|
2012-04-17 10:50:19 -07:00
|
|
|
} else if (valueString.EqualsLiteral("normal")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = false;
|
2012-04-17 10:50:19 -07:00
|
|
|
} else if (valueString.EqualsLiteral("bolder")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = true;
|
2012-04-17 10:50:19 -07:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t weight = 0;
|
2012-07-27 06:59:29 -07:00
|
|
|
nsresult errorCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString value(valueString);
|
2013-04-24 05:36:09 -07:00
|
|
|
weight = value.ToInteger(&errorCode);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (400 < weight) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = true;
|
2012-04-17 10:50:19 -07:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
valueString.AssignLiteral("normal");
|
|
|
|
}
|
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::i == aHTMLProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (valueString.EqualsLiteral("italic") ||
|
|
|
|
valueString.EqualsLiteral("oblique")) {
|
2012-04-17 10:50:19 -07:00
|
|
|
aIsSet = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::u == aHTMLProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString val;
|
|
|
|
val.AssignLiteral("underline");
|
2014-08-29 04:43:24 -07:00
|
|
|
aIsSet = ChangeStyleTxn::ValueIncludes(valueString, val);
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::strike == aHTMLProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString val;
|
|
|
|
val.AssignLiteral("line-through");
|
2014-08-29 04:43:24 -07:00
|
|
|
aIsSet = ChangeStyleTxn::ValueIncludes(valueString, val);
|
2012-04-17 10:50:19 -07:00
|
|
|
} else if (aHTMLAttribute &&
|
2014-08-29 04:43:24 -07:00
|
|
|
((nsGkAtoms::font == aHTMLProperty &&
|
2012-04-17 10:50:19 -07:00
|
|
|
aHTMLAttribute->EqualsLiteral("color")) ||
|
|
|
|
aHTMLAttribute->EqualsLiteral("bgcolor"))) {
|
|
|
|
if (htmlValueString.IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = true;
|
2012-04-17 10:50:19 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
nscolor rgba;
|
|
|
|
nsAutoString subStr;
|
2012-04-17 10:50:19 -07:00
|
|
|
htmlValueString.Right(subStr, htmlValueString.Length() - 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_ColorNameToRGB(htmlValueString, &rgba) ||
|
|
|
|
NS_HexToRGB(subStr, &rgba)) {
|
|
|
|
nsAutoString htmlColor, tmpStr;
|
|
|
|
|
2012-05-28 04:20:27 -07:00
|
|
|
if (NS_GET_A(rgba) != 255) {
|
|
|
|
// This should only be hit by the "transparent" keyword, which
|
|
|
|
// currently serializes to "transparent" (not "rgba(0, 0, 0, 0)").
|
|
|
|
MOZ_ASSERT(NS_GET_R(rgba) == 0 && NS_GET_G(rgba) == 0 &&
|
|
|
|
NS_GET_B(rgba) == 0 && NS_GET_A(rgba) == 0);
|
|
|
|
htmlColor.AppendLiteral("transparent");
|
|
|
|
} else {
|
|
|
|
htmlColor.AppendLiteral("rgb(");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 04:20:27 -07:00
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 04:20:27 -07:00
|
|
|
tmpStr.AppendInt(NS_GET_R(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr + comma);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-28 04:20:27 -07:00
|
|
|
tmpStr.Truncate();
|
|
|
|
tmpStr.AppendInt(NS_GET_G(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr + comma);
|
|
|
|
|
|
|
|
tmpStr.Truncate();
|
|
|
|
tmpStr.AppendInt(NS_GET_B(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr);
|
|
|
|
|
2014-01-04 07:02:17 -08:00
|
|
|
htmlColor.Append(char16_t(')'));
|
2012-05-28 04:20:27 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
aIsSet = htmlColor.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 10:50:19 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
aIsSet = htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 10:50:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::tt == aHTMLProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aIsSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
|
2014-08-29 04:43:24 -07:00
|
|
|
} else if (nsGkAtoms::font == aHTMLProperty && aHTMLAttribute &&
|
2012-04-17 10:50:19 -07:00
|
|
|
aHTMLAttribute->EqualsLiteral("face")) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!htmlValueString.IsEmpty()) {
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t commaSpace[] = { char16_t(','), char16_t(' '), 0 };
|
|
|
|
const char16_t comma[] = { char16_t(','), 0 };
|
2007-03-22 10:30:00 -07:00
|
|
|
htmlValueString.ReplaceSubstring(commaSpace, comma);
|
|
|
|
nsAutoString valueStringNorm(valueString);
|
|
|
|
valueStringNorm.ReplaceSubstring(commaSpace, comma);
|
|
|
|
aIsSet = htmlValueString.Equals(valueStringNorm,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 10:50:19 -07:00
|
|
|
} else {
|
2007-03-22 10:30:00 -07:00
|
|
|
// ignore this, it's TT or our default
|
|
|
|
nsAutoString valueStringLower;
|
|
|
|
ToLowerCase(valueString, valueStringLower);
|
|
|
|
aIsSet = !valueStringLower.EqualsLiteral("monospace") &&
|
|
|
|
!valueStringLower.EqualsLiteral("serif");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2012-04-17 10:50:19 -07:00
|
|
|
} else if (aHTMLAttribute && aHTMLAttribute->EqualsLiteral("align")) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = true;
|
2012-04-17 10:50:19 -07:00
|
|
|
} else {
|
2011-10-17 07:59:28 -07:00
|
|
|
aIsSet = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 10:50:19 -07:00
|
|
|
if (!htmlValueString.IsEmpty() &&
|
|
|
|
htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
|
|
|
aIsSet = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 04:20:27 -07:00
|
|
|
if (htmlValueString.EqualsLiteral("-moz-editor-invert-value")) {
|
|
|
|
aIsSet = !aIsSet;
|
|
|
|
}
|
|
|
|
|
2014-08-29 04:43:24 -07:00
|
|
|
if (nsGkAtoms::u == aHTMLProperty || nsGkAtoms::strike == aHTMLProperty) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// unfortunately, the value of the text-decoration property is not inherited.
|
|
|
|
// that means that we have to look at ancestors of node to see if they are underlined
|
2013-01-11 00:43:01 -08:00
|
|
|
node = node->GetParentElement(); // set to null if it's not a dom element
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2014-08-29 04:43:24 -07:00
|
|
|
} while ((nsGkAtoms::u == aHTMLProperty ||
|
|
|
|
nsGkAtoms::strike == aHTMLProperty) && !aIsSet && node);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-01 04:03:17 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLCSSUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mIsCSSPrefChecked = aIsCSSPrefChecked;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHTMLCSSUtils::IsCSSPrefChecked()
|
|
|
|
{
|
|
|
|
return mIsCSSPrefChecked ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ElementsSameStyle compares two elements and checks if they have the same
|
|
|
|
// specified CSS declarations in the STYLE attribute
|
|
|
|
// The answer is always negative if at least one of them carries an ID or a class
|
2012-05-29 00:12:51 -07:00
|
|
|
bool
|
2013-01-11 00:43:01 -08:00
|
|
|
nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode)
|
2012-05-29 00:12:51 -07:00
|
|
|
{
|
2013-01-11 00:43:01 -08:00
|
|
|
nsCOMPtr<dom::Element> firstElement = do_QueryInterface(aFirstNode);
|
|
|
|
nsCOMPtr<dom::Element> secondElement = do_QueryInterface(aSecondNode);
|
|
|
|
|
|
|
|
NS_ASSERTION((firstElement && secondElement), "Non element nodes passed to ElementsSameStyle.");
|
|
|
|
NS_ENSURE_TRUE(firstElement, false);
|
|
|
|
NS_ENSURE_TRUE(secondElement, false);
|
|
|
|
|
|
|
|
return ElementsSameStyle(firstElement, secondElement);
|
2012-05-29 00:12:51 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-01-11 00:43:01 -08:00
|
|
|
nsHTMLCSSUtils::ElementsSameStyle(dom::Element* aFirstElement,
|
|
|
|
dom::Element* aSecondElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-01-11 00:43:01 -08:00
|
|
|
MOZ_ASSERT(aFirstElement);
|
|
|
|
MOZ_ASSERT(aSecondElement);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-11 00:43:01 -08:00
|
|
|
if (aFirstElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id) ||
|
|
|
|
aSecondElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// at least one of the spans carries an ID ; suspect a CSS rule applies to it and
|
|
|
|
// refuse to merge the nodes
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString firstClass, secondClass;
|
2013-01-11 00:43:01 -08:00
|
|
|
bool isFirstClassSet = aFirstElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, firstClass);
|
|
|
|
bool isSecondClassSet = aSecondElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, secondClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (isFirstClassSet && isSecondClassSet) {
|
|
|
|
// both spans carry a class, let's compare them
|
|
|
|
if (!firstClass.Equals(secondClass)) {
|
|
|
|
// WARNING : technically, the comparison just above is questionable :
|
|
|
|
// from a pure HTML/CSS point of view class="a b" is NOT the same than
|
|
|
|
// class="b a" because a CSS rule could test the exact value of the class
|
|
|
|
// attribute to be "a b" for instance ; from a user's point of view, a
|
|
|
|
// wysiwyg editor should probably NOT make any difference. CSS people
|
|
|
|
// need to discuss this issue before any modification.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-01-11 00:43:01 -08:00
|
|
|
} else if (isFirstClassSet || isSecondClassSet) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// one span only carries a class, early way out
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> firstCSSDecl, secondCSSDecl;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t firstLength, secondLength;
|
2013-01-11 00:43:01 -08:00
|
|
|
nsresult rv = GetInlineStyles(aFirstElement, getter_AddRefs(firstCSSDecl), &firstLength);
|
|
|
|
if (NS_FAILED(rv) || !firstCSSDecl) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rv = GetInlineStyles(aSecondElement, getter_AddRefs(secondCSSDecl), &secondLength);
|
|
|
|
if (NS_FAILED(rv) || !secondCSSDecl) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (firstLength != secondLength) {
|
|
|
|
// early way out if we can
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-01-11 00:43:01 -08:00
|
|
|
|
|
|
|
if (!firstLength) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// no inline style !
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString propertyNameString;
|
|
|
|
nsAutoString firstValue, secondValue;
|
2013-01-11 00:43:01 -08:00
|
|
|
for (uint32_t i = 0; i < firstLength; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
firstCSSDecl->Item(i, propertyNameString);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-01-11 00:43:01 -08:00
|
|
|
for (uint32_t i = 0; i < secondLength; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
secondCSSDecl->Item(i, propertyNameString);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-01-11 00:43:01 -08:00
|
|
|
nsHTMLCSSUtils::GetInlineStyles(dom::Element* aElement,
|
|
|
|
nsIDOMCSSStyleDeclaration** aCssDecl,
|
|
|
|
uint32_t* aLength)
|
|
|
|
{
|
|
|
|
return GetInlineStyles(static_cast<nsISupports*>(aElement), aCssDecl, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetInlineStyles(nsIDOMElement* aElement,
|
|
|
|
nsIDOMCSSStyleDeclaration** aCssDecl,
|
|
|
|
uint32_t* aLength)
|
|
|
|
{
|
|
|
|
return GetInlineStyles(static_cast<nsISupports*>(aElement), aCssDecl, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::GetInlineStyles(nsISupports *aElement,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMCSSStyleDeclaration **aCssDecl,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t *aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-17 12:41:16 -07:00
|
|
|
NS_ENSURE_TRUE(aElement && aLength, NS_ERROR_NULL_POINTER);
|
2007-03-22 10:30:00 -07:00
|
|
|
*aLength = 0;
|
|
|
|
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
|
2010-06-17 12:41:16 -07:00
|
|
|
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
|
2013-01-11 00:43:01 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult res = inlineStyles->GetStyle(aCssDecl);
|
2013-01-11 00:43:01 -08:00
|
|
|
NS_ENSURE_SUCCESS(res, NS_ERROR_NULL_POINTER);
|
|
|
|
MOZ_ASSERT(*aCssDecl);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
(*aCssDecl)->GetLength(aLength);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-02-01 02:54:22 -08:00
|
|
|
already_AddRefed<nsIDOMElement>
|
|
|
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode* aNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-02-01 02:54:22 -08:00
|
|
|
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(node, nullptr);
|
2012-02-10 02:04:46 -08:00
|
|
|
nsCOMPtr<nsIDOMElement> element =
|
|
|
|
do_QueryInterface(GetElementContainerOrSelf(node));
|
|
|
|
return element.forget();
|
|
|
|
}
|
2009-02-18 23:55:40 -08:00
|
|
|
|
2012-02-10 02:04:46 -08:00
|
|
|
dom::Element*
|
|
|
|
nsHTMLCSSUtils::GetElementContainerOrSelf(nsINode* aNode)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
if (nsIDOMNode::DOCUMENT_NODE == aNode->NodeType()) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-02-18 23:55:40 -08:00
|
|
|
}
|
|
|
|
|
2012-02-10 02:04:46 -08:00
|
|
|
nsINode* node = aNode;
|
2012-02-01 02:54:22 -08:00
|
|
|
// Loop until we find an element.
|
|
|
|
while (node && !node->IsElement()) {
|
2012-10-09 05:31:24 -07:00
|
|
|
node = node->GetParentNode();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-01 02:54:22 -08:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(node, nullptr);
|
2012-02-10 02:04:46 -08:00
|
|
|
return node->AsElement();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSProperty(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aProperty,
|
|
|
|
const nsAString & aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult res = GetInlineStyles(aElement, getter_AddRefs(cssDecl), &length);
|
|
|
|
if (NS_FAILED(res) || !cssDecl) return res;
|
|
|
|
|
|
|
|
return cssDecl->SetProperty(aProperty,
|
|
|
|
aValue,
|
|
|
|
EmptyString());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHTMLCSSUtils::SetCSSPropertyPixels(nsIDOMElement * aElement,
|
|
|
|
const nsAString & aProperty,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aIntValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
s.AppendInt(aIntValue);
|
|
|
|
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"));
|
|
|
|
}
|