2002-01-09 16:51:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/CSSEditUtils.h"
|
2014-12-02 08:07:42 +03:00
|
|
|
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Assertions.h"
|
2016-07-08 08:03:31 +03:00
|
|
|
#include "mozilla/ChangeStyleTransaction.h"
|
2016-07-09 05:42:33 +03:00
|
|
|
#include "mozilla/HTMLEditor.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2018-05-30 19:15:25 +03:00
|
|
|
#include "mozilla/DeclarationBlock.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/mozalloc.h"
|
|
|
|
#include "nsAString.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2018-04-29 14:17:26 +03:00
|
|
|
#include "nsCSSProps.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsColor.h"
|
2012-07-08 13:50:31 +04:00
|
|
|
#include "nsComputedDOMStyle.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsDebug.h"
|
|
|
|
#include "nsDependentSubstring.h"
|
|
|
|
#include "nsError.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIContent.h"
|
2018-01-11 11:17:57 +03:00
|
|
|
#include "nsICSSDeclaration.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsISupportsUtils.h"
|
|
|
|
#include "nsLiteralString.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2003-07-14 11:37:39 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "nsStringIterator.h"
|
2016-08-02 21:05:38 +03:00
|
|
|
#include "nsStyledElement.h"
|
2002-01-09 16:51:37 +03:00
|
|
|
#include "nsUnicharUtils.h"
|
2011-06-17 04:59:29 +04:00
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
using namespace dom;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessBValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString && aInputString->EqualsLiteral("-moz-editor-invert-value")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AssignLiteral("normal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AssignLiteral("bold");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessDefaultValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2018-07-06 10:44:43 +03:00
|
|
|
CopyASCIItoUTF16(MakeStringSpan(aDefaultValueString), aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessSameValue(const nsAString* aInputString,
|
|
|
|
nsAString & aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Assign(*aInputString);
|
|
|
|
}
|
2003-09-03 17:54:36 +04:00
|
|
|
else
|
|
|
|
aOutputString.Truncate();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessExtendedValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
if (aPrependString) {
|
2018-07-06 10:44:43 +03:00
|
|
|
AppendASCIItoUTF16(MakeStringSpan(aPrependString), aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2002-01-21 12:30:02 +03:00
|
|
|
aOutputString.Append(*aInputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (aAppendString) {
|
2018-07-06 10:44:43 +03:00
|
|
|
AppendASCIItoUTF16(MakeStringSpan(aAppendString), aOutputString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessLengthValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
|
|
|
aOutputString.Append(*aInputString);
|
2014-01-04 19:02:17 +04:00
|
|
|
if (-1 == aOutputString.FindChar(char16_t('%'))) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessListStyleTypeValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("1")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("decimal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("a")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("lower-alpha");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("A")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("upper-alpha");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("i")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("lower-roman");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("I")) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aOutputString.AppendLiteral("upper-roman");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("square")
|
|
|
|
|| aInputString->EqualsLiteral("circle")
|
|
|
|
|| aInputString->EqualsLiteral("disc")) {
|
2002-01-09 16:51:37 +03:00
|
|
|
aOutputString.Append(*aInputString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessMarginLeftValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("right") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-right")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("0px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2016-07-07 12:35:13 +03:00
|
|
|
void ProcessMarginRightValue(const nsAString* aInputString,
|
|
|
|
nsAString& aOutputString,
|
|
|
|
const char* aDefaultValueString,
|
|
|
|
const char* aPrependString,
|
|
|
|
const char* aAppendString)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
aOutputString.Truncate();
|
|
|
|
if (aInputString) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (aInputString->EqualsLiteral("center") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-center")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (aInputString->EqualsLiteral("left") ||
|
|
|
|
aInputString->EqualsLiteral("-moz-left")) {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("auto");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
else {
|
2015-05-28 18:58:42 +03:00
|
|
|
aOutputString.AppendLiteral("0px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable boldEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable italicEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable underlineEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable strikeEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable ttEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable fontColorEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable fontFaceEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_font_family, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable bgcolorEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_background_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable backgroundImageEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nullptr, "url(", ")", true, true },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable textColorEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable borderEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_border, ProcessExtendedValue, nullptr, nullptr, "px solid", true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable textAlignEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_text_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable captionAlignEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable verticalAlignEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable nowrapEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable widthEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_width, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable heightEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_height, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable listStyleTypeEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nullptr, nullptr, nullptr, true, true },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable tableAlignEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_text_align, ProcessDefaultValue, "left", nullptr, nullptr, false, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable hrAlignEquivTable[] = {
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nullptr, nullptr, nullptr, true, false },
|
|
|
|
{ CSSEditUtils::eCSSEditableProperty_NONE, 0 }
|
2002-01-09 16:51:37 +03:00
|
|
|
};
|
|
|
|
|
2016-07-09 05:42:33 +03:00
|
|
|
CSSEditUtils::CSSEditUtils(HTMLEditor* aHTMLEditor)
|
2016-07-07 12:35:13 +03:00
|
|
|
: mHTMLEditor(aHTMLEditor)
|
2012-04-03 18:16:05 +04:00
|
|
|
, mIsCSSPrefChecked(true)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
// let's retrieve the value of the "CSS editing" pref
|
2011-06-17 04:59:29 +04:00
|
|
|
mIsCSSPrefChecked = Preferences::GetBool("editor.use_css", mIsCSSPrefChecked);
|
2011-05-15 14:07:30 +04:00
|
|
|
}
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::~CSSEditUtils()
|
2011-05-15 14:07:30 +04:00
|
|
|
{
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Answers true if we have some CSS equivalence for the HTML style defined
|
|
|
|
// by aProperty and/or aAttribute for the node aNode
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2016-12-12 13:03:36 +03:00
|
|
|
bool
|
|
|
|
CSSEditUtils::IsCSSEditableProperty(nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aProperty,
|
|
|
|
nsAtom* aAttribute)
|
2012-02-10 14:04:47 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
nsINode* node = aNode;
|
2002-01-09 16:51:37 +03:00
|
|
|
// we need an element node here
|
2018-01-30 07:10:53 +03:00
|
|
|
if (node->NodeType() == nsINode::TEXT_NODE) {
|
2015-04-19 15:28:50 +03:00
|
|
|
node = node->GetParentNode();
|
|
|
|
NS_ENSURE_TRUE(node, false);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2003-07-29 18:48:44 +04:00
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
// html inline styles B I TT U STRIKE and COLOR/FACE on FONT
|
2014-08-29 15:43:24 +04:00
|
|
|
if (nsGkAtoms::b == aProperty ||
|
|
|
|
nsGkAtoms::i == aProperty ||
|
|
|
|
nsGkAtoms::tt == aProperty ||
|
|
|
|
nsGkAtoms::u == aProperty ||
|
|
|
|
nsGkAtoms::strike == aProperty ||
|
|
|
|
(nsGkAtoms::font == aProperty && aAttribute &&
|
2016-12-12 13:03:36 +03:00
|
|
|
(aAttribute == nsGkAtoms::color || aAttribute == nsGkAtoms::face))) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// ALIGN attribute on elements supporting it
|
2016-12-12 13:03:36 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align &&
|
2015-04-19 15:28:50 +03:00
|
|
|
node->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,
|
|
|
|
// For the above, why not use
|
2016-07-07 08:01:12 +03:00
|
|
|
// HTMLEditUtils::SupportsAlignAttr?
|
2015-04-19 15:28:50 +03:00
|
|
|
// It also checks for tbody, tfoot, thead.
|
|
|
|
// Let's add the following elements here even
|
|
|
|
// if "align" has a different meaning for them
|
|
|
|
nsGkAtoms::legend,
|
|
|
|
nsGkAtoms::caption)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2016-12-12 13:03:36 +03:00
|
|
|
if (aAttribute == nsGkAtoms::valign &&
|
2015-04-19 15:28:50 +03:00
|
|
|
node->IsAnyOfHTMLElements(nsGkAtoms::col,
|
|
|
|
nsGkAtoms::colgroup,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th,
|
|
|
|
nsGkAtoms::tfoot,
|
|
|
|
nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tr)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-09-17 16:04:59 +04:00
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
// attributes TEXT, BACKGROUND and BGCOLOR on BODY
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsHTMLElement(nsGkAtoms::body) &&
|
|
|
|
(aAttribute == nsGkAtoms::text || aAttribute == nsGkAtoms::background ||
|
|
|
|
aAttribute == nsGkAtoms::bgcolor)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute BGCOLOR on other elements
|
2016-12-12 13:03:36 +03:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT, WIDTH and NOWRAP on TD and TH
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th) &&
|
|
|
|
(aAttribute == nsGkAtoms::height || aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::nowrap)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes HEIGHT and WIDTH on TABLE
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsHTMLElement(nsGkAtoms::table) &&
|
|
|
|
(aAttribute == nsGkAtoms::height || aAttribute == nsGkAtoms::width)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attributes SIZE and WIDTH on HR
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsHTMLElement(nsGkAtoms::hr) &&
|
|
|
|
(aAttribute == nsGkAtoms::size || aAttribute == nsGkAtoms::width)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// attribute TYPE on OL UL LI
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsAnyOfHTMLElements(nsGkAtoms::ol, nsGkAtoms::ul,
|
2015-04-19 15:28:50 +03:00
|
|
|
nsGkAtoms::li) &&
|
2016-12-12 13:03:36 +03:00
|
|
|
aAttribute == nsGkAtoms::type) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2016-12-12 13:03:36 +03:00
|
|
|
if (node->IsHTMLElement(nsGkAtoms::img) &&
|
|
|
|
(aAttribute == nsGkAtoms::border || aAttribute == nsGkAtoms::width ||
|
|
|
|
aAttribute == nsGkAtoms::height)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// other elements that we can align using CSS even if they
|
|
|
|
// can't carry the html ALIGN attribute
|
2016-12-12 13:03:36 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align &&
|
2015-04-19 15:28:50 +03:00
|
|
|
node->IsAnyOfHTMLElements(nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::ol,
|
|
|
|
nsGkAtoms::dl,
|
|
|
|
nsGkAtoms::li,
|
|
|
|
nsGkAtoms::dd,
|
|
|
|
nsGkAtoms::dt,
|
|
|
|
nsGkAtoms::address,
|
|
|
|
nsGkAtoms::pre)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2014-08-29 15:43:24 +04:00
|
|
|
// The lowest level above the transaction; adds the CSS declaration
|
|
|
|
// "aProperty : aValue" to the inline styles carried by aElement
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::SetCSSProperty(Element& aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom& aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
bool aSuppressTxn)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2016-07-07 08:23:25 +03:00
|
|
|
RefPtr<ChangeStyleTransaction> transaction =
|
2017-12-18 11:46:57 +03:00
|
|
|
ChangeStyleTransaction::Create(aElement, aProperty, aValue);
|
2014-08-29 15:43:24 +04:00
|
|
|
if (aSuppressTxn) {
|
2016-07-07 08:23:25 +03:00
|
|
|
return transaction->DoTransaction();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2017-12-18 11:46:57 +03:00
|
|
|
if (NS_WARN_IF(!mHTMLEditor)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
|
|
|
|
return htmlEditor->DoTransaction(transaction);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2003-09-03 17:54:36 +04:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::SetCSSPropertyPixels(Element& aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom& aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
int32_t aIntValue)
|
2003-09-03 17:54:36 +04:00
|
|
|
{
|
|
|
|
nsAutoString s;
|
|
|
|
s.AppendInt(aIntValue);
|
|
|
|
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"),
|
2014-08-29 15:43:24 +04:00
|
|
|
/* suppress txn */ false);
|
2003-09-03 17:54:36 +04:00
|
|
|
}
|
|
|
|
|
2014-08-29 15:43:24 +04: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
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::RemoveCSSProperty(Element& aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom& aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
bool aSuppressTxn)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2016-07-07 08:23:25 +03:00
|
|
|
RefPtr<ChangeStyleTransaction> transaction =
|
2017-12-18 11:46:57 +03:00
|
|
|
ChangeStyleTransaction::CreateToRemove(aElement, aProperty, aValue);
|
2014-08-29 15:43:24 +04:00
|
|
|
if (aSuppressTxn) {
|
2016-07-07 08:23:25 +03:00
|
|
|
return transaction->DoTransaction();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2017-12-18 11:46:57 +03:00
|
|
|
if (NS_WARN_IF(!mHTMLEditor)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
RefPtr<HTMLEditor> htmlEditor(mHTMLEditor);
|
|
|
|
return htmlEditor->DoTransaction(transaction);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetSpecifiedProperty(nsINode& aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom& aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsAString& aValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2015-04-19 15:28:50 +03:00
|
|
|
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eSpecified);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetComputedProperty(nsINode& aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom& aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsAString& aValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2015-04-19 15:28:50 +03:00
|
|
|
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eComputed);
|
2012-02-10 14:04:47 +04:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetCSSInlinePropertyBase(nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsAString& aValue,
|
|
|
|
StyleType aStyleType)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-07-08 14:31:53 +04:00
|
|
|
MOZ_ASSERT(aNode && aProperty);
|
2002-01-09 16:51:37 +03:00
|
|
|
aValue.Truncate();
|
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
nsCOMPtr<Element> element = GetElementContainerOrSelf(aNode);
|
2012-02-01 14:54:22 +04:00
|
|
|
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2012-07-08 14:31:53 +04:00
|
|
|
if (aStyleType == eComputed) {
|
|
|
|
// Get the all the computed css styles attached to the element node
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsComputedDOMStyle> cssDecl = GetComputedStyle(element);
|
2012-07-08 14:31:53 +04:00
|
|
|
NS_ENSURE_STATE(cssDecl);
|
|
|
|
|
|
|
|
// from these declarations, get the one we want and that one only
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
cssDecl->GetPropertyValue(nsDependentAtomString(aProperty), aValue));
|
2012-07-08 14:31:53 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2012-07-08 14:31:53 +04:00
|
|
|
}
|
2012-07-08 14:31:53 +04:00
|
|
|
|
|
|
|
MOZ_ASSERT(aStyleType == eSpecified);
|
2016-10-18 07:29:03 +03:00
|
|
|
RefPtr<DeclarationBlock> decl = element->GetInlineStyleDeclaration();
|
2015-11-09 10:57:16 +03:00
|
|
|
if (!decl) {
|
2012-07-08 14:31:53 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-05-25 10:27:40 +03:00
|
|
|
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID prop =
|
2018-07-30 18:32:17 +03:00
|
|
|
nsCSSProps::LookupProperty(nsDependentAtomString(aProperty));
|
2012-07-08 14:31:53 +04:00
|
|
|
MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
|
2017-05-25 10:27:40 +03:00
|
|
|
|
|
|
|
decl->GetPropertyValueByID(prop, aValue);
|
2012-07-08 14:31:53 +04:00
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2012-07-08 13:50:31 +04:00
|
|
|
already_AddRefed<nsComputedDOMStyle>
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetComputedStyle(Element* aElement)
|
2012-02-10 14:04:47 +04:00
|
|
|
{
|
2012-07-08 13:50:31 +04:00
|
|
|
MOZ_ASSERT(aElement);
|
2012-07-08 13:50:31 +04:00
|
|
|
|
2018-01-23 17:49:00 +03:00
|
|
|
nsIDocument* doc = aElement->GetComposedDoc();
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(doc, nullptr);
|
2012-07-08 13:50:31 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsComputedDOMStyle> style =
|
2018-06-08 12:15:34 +03:00
|
|
|
NS_NewComputedDOMStyle(aElement, EmptyString(), doc);
|
2012-07-08 13:50:31 +04:00
|
|
|
|
|
|
|
return style.forget();
|
2002-01-09 16:51:37 +03: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
|
2017-03-03 07:13:21 +03:00
|
|
|
CSSEditUtils::RemoveCSSInlineStyle(nsINode& aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString& aPropertyValue)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2017-03-03 07:13:21 +03:00
|
|
|
RefPtr<Element> element = aNode.AsElement();
|
2014-08-29 15:43:24 +04:00
|
|
|
NS_ENSURE_STATE(element);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
// remove the property from the style attribute
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = RemoveCSSProperty(*element, *aProperty, aPropertyValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!element->IsHTMLElement(nsGkAtoms::span) ||
|
2016-07-09 05:42:33 +03:00
|
|
|
HTMLEditor::HasAttributes(element)) {
|
2012-02-10 14:04:46 +04:00
|
|
|
return NS_OK;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-10 14:04:46 +04:00
|
|
|
|
2018-04-12 16:23:04 +03:00
|
|
|
return mHTMLEditor->RemoveContainerWithTransaction(*element);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2015-04-19 15:28:50 +03:00
|
|
|
// Answers true if the property can be removed by setting a "none" CSS value
|
2002-01-09 16:51:37 +03:00
|
|
|
// on a node
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2017-10-03 01:05:19 +03:00
|
|
|
CSSEditUtils::IsCSSInvertible(nsAtom& aProperty,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsAtom* aAttribute)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2015-04-19 15:28:50 +03:00
|
|
|
return nsGkAtoms::b == &aProperty;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default browser background color if we need it for GetCSSBackgroundColorState
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2011-06-17 04:59:29 +04:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetDefaultBackgroundColor(nsAString& aColor)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
if (Preferences::GetBool("editor.use_custom_colors", false)) {
|
2017-07-31 03:52:51 +03:00
|
|
|
nsresult rv = Preferences::GetString("editor.background_color", aColor);
|
2011-06-17 04:59:29 +04:00
|
|
|
// 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
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2011-06-17 04:59:29 +04:00
|
|
|
return;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2011-06-17 04:59:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
if (Preferences::GetBool("browser.display.use_system_colors", false)) {
|
2011-06-17 04:59:29 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv =
|
2017-07-31 03:52:51 +03:00
|
|
|
Preferences::GetString("browser.display.background_color", aColor);
|
2011-06-17 04:59:29 +04:00
|
|
|
// 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
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the default length unit used for CSS Indent/Outdent
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2011-06-17 04:59:29 +04:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetDefaultLengthUnit(nsAString& aLengthUnit)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2011-06-17 04:59:29 +04:00
|
|
|
nsresult rv =
|
2017-07-31 03:52:51 +03:00
|
|
|
Preferences::GetString("editor.css.default_length_unit", aLengthUnit);
|
2011-06-17 04:59:29 +04:00
|
|
|
// XXX Why don't you validate the pref value?
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aLengthUnit.AssignLiteral("px");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::ParseLength(const nsAString& aString,
|
|
|
|
float* aValue,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom** aUnit)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2015-06-15 19:08:50 +03:00
|
|
|
if (aString.IsEmpty()) {
|
|
|
|
*aValue = 0;
|
2016-03-29 02:09:43 +03:00
|
|
|
*aUnit = NS_Atomize(aString).take();
|
2015-06-15 19:08:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAString::const_iterator iter;
|
|
|
|
aString.BeginReading(iter);
|
|
|
|
|
|
|
|
float a = 10.0f , b = 1.0f, value = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
int8_t sign = 1;
|
|
|
|
int32_t i = 0, j = aString.Length();
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t c;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool floatingPointFound = false;
|
2002-01-09 16:51:37 +03:00
|
|
|
c = *iter;
|
2014-01-04 19:02:17 +04:00
|
|
|
if (char16_t('-') == c) { sign = -1; iter++; i++; }
|
|
|
|
else if (char16_t('+') == c) { iter++; i++; }
|
2002-01-09 16:51:37 +03:00
|
|
|
while (i < j) {
|
|
|
|
c = *iter;
|
2014-01-04 19:02:17 +04: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')));
|
2002-01-09 16:51:37 +03:00
|
|
|
b = b / 10 * a;
|
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
else if (!floatingPointFound && (char16_t('.') == c)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
floatingPointFound = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
a = 1.0f; b = 0.1f;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
iter++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
*aValue = value * sign;
|
2016-03-29 02:09:43 +03:00
|
|
|
*aUnit = NS_Atomize(StringTail(aString, j-i)).take();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom** aAtom)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aAtom = nullptr;
|
2009-07-23 02:31:01 +04:00
|
|
|
switch (aProperty) {
|
|
|
|
case eCSSEditableProperty_background_color:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::backgroundColor;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_background_image:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::background_image;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_border:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::border;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_caption_side:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::caption_side;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_color:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::color;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_float:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::_float;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_family:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::font_family;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_size:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::font_size;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_style:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::font_style;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_font_weight:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::fontWeight;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_height:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::height;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_list_style_type:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::list_style_type;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_left:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::marginLeft;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_margin_right:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::marginRight;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_align:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::textAlign;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_text_decoration:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::text_decoration;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_vertical_align:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::vertical_align;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_whitespace:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::white_space;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_width:
|
2014-08-29 15:43:24 +04:00
|
|
|
*aAtom = nsGkAtoms::width;
|
2009-07-23 02:31:01 +04:00
|
|
|
break;
|
|
|
|
case eCSSEditableProperty_NONE:
|
|
|
|
// intentionally empty
|
|
|
|
break;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate aProperty and aValueArray with the CSS declarations equivalent to the
|
|
|
|
// value aValue according to the equivalence table aEquivTable
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
void
|
2017-10-03 01:05:19 +03:00
|
|
|
CSSEditUtils::BuildCSSDeclarations(nsTArray<nsAtom*>& aPropertyArray,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsTArray<nsString>& aValueArray,
|
|
|
|
const CSSEquivTable* aEquivTable,
|
|
|
|
const nsAString* aValue,
|
|
|
|
bool aGetOrRemoveRequest)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
// clear arrays
|
|
|
|
aPropertyArray.Clear();
|
|
|
|
aValueArray.Clear();
|
|
|
|
|
|
|
|
// if we have an input value, let's use it
|
2002-08-23 13:24:47 +04:00
|
|
|
nsAutoString value, lowerCasedValue;
|
2002-01-09 16:51:37 +03:00
|
|
|
if (aValue) {
|
|
|
|
value.Assign(*aValue);
|
2002-08-23 13:24:47 +04:00
|
|
|
lowerCasedValue.Assign(*aValue);
|
|
|
|
ToLowerCase(lowerCasedValue);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int8_t index = 0;
|
2002-01-09 16:51:37 +03:00
|
|
|
nsCSSEditableProperty cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
while (cssProperty) {
|
|
|
|
if (!aGetOrRemoveRequest|| aEquivTable[index].gettable) {
|
|
|
|
nsAutoString cssValue, cssPropertyString;
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom * cssPropertyAtom;
|
2002-01-09 16:51:37 +03:00
|
|
|
// find the equivalent css value for the index-th property in
|
|
|
|
// the equivalence table
|
2004-06-28 16:43:49 +04:00
|
|
|
(*aEquivTable[index].processValueFunctor) ((!aGetOrRemoveRequest || aEquivTable[index].caseSensitiveValue) ? &value : &lowerCasedValue,
|
2002-08-23 13:24:47 +04:00
|
|
|
cssValue,
|
2002-01-09 16:51:37 +03:00
|
|
|
aEquivTable[index].defaultValue,
|
|
|
|
aEquivTable[index].prependValue,
|
|
|
|
aEquivTable[index].appendValue);
|
|
|
|
GetCSSPropertyAtom(cssProperty, &cssPropertyAtom);
|
|
|
|
aPropertyArray.AppendElement(cssPropertyAtom);
|
2009-01-18 23:14:14 +03:00
|
|
|
aValueArray.AppendElement(cssValue);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
cssProperty = aEquivTable[index].cssProperty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Populate cssPropertyArray and cssValueArray with the declarations equivalent
|
|
|
|
// to aHTMLProperty/aAttribute/aValue for the node aNode
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GenerateCSSDeclarationsFromHTMLStyle(
|
|
|
|
Element* aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aAttribute,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString* aValue,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<nsAtom*>& cssPropertyArray,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsTArray<nsString>& cssValueArray,
|
|
|
|
bool aGetOrRemoveRequest)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2012-02-10 14:04:47 +04:00
|
|
|
MOZ_ASSERT(aElement);
|
2016-07-07 12:35:13 +03:00
|
|
|
const CSSEditUtils::CSSEquivTable* equivTable = nullptr;
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2014-08-29 15:43:24 +04:00
|
|
|
if (nsGkAtoms::b == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = boldEquivTable;
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::i == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = italicEquivTable;
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::u == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = underlineEquivTable;
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::strike == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = strikeEquivTable;
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::tt == aHTMLProperty) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = ttEquivTable;
|
|
|
|
} else if (aAttribute) {
|
2016-12-12 13:03:36 +03:00
|
|
|
if (nsGkAtoms::font == aHTMLProperty && aAttribute == nsGkAtoms::color) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = fontColorEquivTable;
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::font == aHTMLProperty &&
|
2016-12-12 13:03:36 +03:00
|
|
|
aAttribute == nsGkAtoms::face) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = fontFaceEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::bgcolor) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = bgcolorEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::background) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = backgroundImageEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::text) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = textColorEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::border) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = borderEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::align) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (aElement->IsHTMLElement(nsGkAtoms::table)) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = tableAlignEquivTable;
|
2015-03-03 14:08:59 +03:00
|
|
|
} else if (aElement->IsHTMLElement(nsGkAtoms::hr)) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = hrAlignEquivTable;
|
2015-03-03 14:08:59 +03:00
|
|
|
} else if (aElement->IsAnyOfHTMLElements(nsGkAtoms::legend,
|
|
|
|
nsGkAtoms::caption)) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = captionAlignEquivTable;
|
|
|
|
} else {
|
|
|
|
equivTable = textAlignEquivTable;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::valign) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = verticalAlignEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::nowrap) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = nowrapEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::width) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = widthEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::height ||
|
2015-03-03 14:08:59 +03:00
|
|
|
(aElement->IsHTMLElement(nsGkAtoms::hr) &&
|
2016-12-12 13:03:36 +03:00
|
|
|
aAttribute == nsGkAtoms::size)) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = heightEquivTable;
|
2016-12-12 13:03:36 +03:00
|
|
|
} else if (aAttribute == nsGkAtoms::type &&
|
2015-03-03 14:08:59 +03:00
|
|
|
aElement->IsAnyOfHTMLElements(nsGkAtoms::ol,
|
|
|
|
nsGkAtoms::ul,
|
|
|
|
nsGkAtoms::li)) {
|
2012-04-24 14:57:23 +04:00
|
|
|
equivTable = listStyleTypeEquivTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (equivTable) {
|
|
|
|
BuildCSSDeclarations(cssPropertyArray, cssValueArray, equivTable,
|
|
|
|
aValue, aGetOrRemoveRequest);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-29 11:12:51 +04: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
|
2016-07-07 12:35:13 +03:00
|
|
|
// by the call. The Element version returns aCount instead.
|
2016-12-12 13:03:36 +03:00
|
|
|
int32_t
|
|
|
|
CSSEditUtils::SetCSSEquivalentToHTMLStyle(Element* aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aAttribute,
|
2016-12-12 13:03:36 +03:00
|
|
|
const nsAString* aValue,
|
|
|
|
bool aSuppressTransaction)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aElement);
|
|
|
|
|
|
|
|
if (!IsCSSEditableProperty(aElement, aHTMLProperty, aAttribute)) {
|
|
|
|
return 0;
|
2012-02-10 14:04:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<nsAtom*> cssPropertyArray;
|
2012-02-10 14:04:47 +04:00
|
|
|
nsTArray<nsString> cssValueArray;
|
2016-12-12 13:03:36 +03:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(aElement, aHTMLProperty, aAttribute,
|
2012-02-10 14:04:47 +04:00
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// set the individual CSS inline styles
|
2016-12-12 13:03:36 +03:00
|
|
|
size_t count = cssPropertyArray.Length();
|
|
|
|
for (size_t index = 0; index < count; index++) {
|
|
|
|
nsresult rv = SetCSSProperty(*aElement, *cssPropertyArray[index],
|
2016-10-19 12:09:33 +03:00
|
|
|
cssValueArray[index], aSuppressTransaction);
|
2016-12-12 13:03:36 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return 0;
|
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2016-12-12 13:03:36 +03:00
|
|
|
return count;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-01-04 08:27:15 +03:00
|
|
|
// Remove from aNode the CSS inline style equivalent to
|
|
|
|
// HTMLProperty/aAttribute/aValue for the node
|
2013-03-10 11:58:34 +04:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::RemoveCSSEquivalentToHTMLStyle(Element* aElement,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aAttribute,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString* aValue,
|
|
|
|
bool aSuppressTransaction)
|
2013-03-10 11:58:34 +04:00
|
|
|
{
|
2016-12-12 13:03:36 +03:00
|
|
|
if (NS_WARN_IF(!aElement)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-03-10 11:58:34 +04:00
|
|
|
|
|
|
|
if (!IsCSSEditableProperty(aElement, aHTMLProperty, aAttribute)) {
|
2012-02-10 14:04:47 +04: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
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<nsAtom*> cssPropertyArray;
|
2012-02-10 14:04:47 +04:00
|
|
|
nsTArray<nsString> cssValueArray;
|
2013-03-10 11:58:34 +04:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(aElement, aHTMLProperty, aAttribute,
|
2012-02-10 14:04:47 +04:00
|
|
|
aValue, cssPropertyArray, cssValueArray,
|
|
|
|
true);
|
|
|
|
|
|
|
|
// remove the individual CSS inline styles
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = cssPropertyArray.Length();
|
|
|
|
for (int32_t index = 0; index < count; index++) {
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = RemoveCSSProperty(*aElement,
|
|
|
|
*cssPropertyArray[index],
|
|
|
|
cssValueArray[index],
|
|
|
|
aSuppressTransaction);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-01-09 16:51:37 +03: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.
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aAttribute,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsAString& aValueString,
|
|
|
|
StyleType aStyleType)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2003-09-03 17:54:36 +04:00
|
|
|
aValueString.Truncate();
|
2016-07-07 12:35:13 +03:00
|
|
|
nsCOMPtr<Element> theElement = GetElementContainerOrSelf(aNode);
|
2012-02-01 14:54:22 +04:00
|
|
|
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2013-02-06 10:00:59 +04:00
|
|
|
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
|
2012-02-10 14:04:47 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Yes, the requested HTML style has a CSS equivalence in this implementation
|
2017-10-03 01:05:19 +03:00
|
|
|
nsTArray<nsAtom*> cssPropertyArray;
|
2012-02-10 14:04:47 +04:00
|
|
|
nsTArray<nsString> cssValueArray;
|
|
|
|
// get the CSS equivalence with last param true indicating we want only the
|
|
|
|
// "gettable" properties
|
2016-12-12 13:03:36 +03:00
|
|
|
GenerateCSSDeclarationsFromHTMLStyle(theElement, aHTMLProperty, aAttribute,
|
|
|
|
nullptr,
|
2012-02-10 14:04:47 +04:00
|
|
|
cssPropertyArray, cssValueArray, true);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = cssPropertyArray.Length();
|
|
|
|
for (int32_t index = 0; index < count; index++) {
|
2012-02-10 14:04:47 +04:00
|
|
|
nsAutoString valueString;
|
|
|
|
// retrieve the specified/computed value of the property
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv = GetCSSInlinePropertyBase(theElement, cssPropertyArray[index],
|
|
|
|
valueString, aStyleType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2012-02-10 14:04:47 +04:00
|
|
|
// append the value to aValueString (possibly with a leading whitespace)
|
|
|
|
if (index) {
|
2014-01-04 19:02:17 +04:00
|
|
|
aValueString.Append(char16_t(' '));
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-10 14:04:47 +04:00
|
|
|
aValueString.Append(valueString);
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-17 21:50:19 +04: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 14:15:09 +04:00
|
|
|
//
|
|
|
|
// The nsIContent variant returns aIsSet instead of using an out parameter, and
|
|
|
|
// does not modify aValue.
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2012-05-22 14:15:09 +04:00
|
|
|
bool
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aProperty,
|
2017-12-26 06:25:45 +03:00
|
|
|
nsAtom* aAttribute,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
StyleType aStyleType)
|
2015-04-19 15:28:50 +03:00
|
|
|
{
|
|
|
|
// Use aValue as only an in param, not in-out
|
|
|
|
nsAutoString value(aValue);
|
|
|
|
return IsCSSEquivalentToHTMLInlineStyleSet(aNode, aProperty, aAttribute,
|
|
|
|
value, aStyleType);
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2015-04-19 15:28:50 +03:00
|
|
|
bool
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aProperty,
|
2016-07-07 12:35:13 +03:00
|
|
|
const nsAString* aAttribute,
|
|
|
|
nsAString& aValue,
|
|
|
|
StyleType aStyleType)
|
2012-05-22 14:15:09 +04:00
|
|
|
{
|
2015-04-19 15:28:50 +03:00
|
|
|
MOZ_ASSERT(aNode && aProperty);
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> attribute = aAttribute ? NS_Atomize(*aAttribute) : nullptr;
|
2016-12-12 13:03:36 +03:00
|
|
|
return IsCSSEquivalentToHTMLInlineStyleSet(aNode,
|
|
|
|
aProperty, attribute,
|
|
|
|
aValue, aStyleType);
|
2012-05-22 14:15:09 +04:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2016-12-12 13:03:36 +03:00
|
|
|
bool
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
|
2016-12-12 13:03:36 +03:00
|
|
|
nsINode* aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aHTMLAttribute,
|
2016-07-07 12:35:13 +03:00
|
|
|
nsAString& valueString,
|
|
|
|
StyleType aStyleType)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2016-12-12 13:03:36 +03:00
|
|
|
NS_ENSURE_TRUE(aNode, false);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
nsAutoString htmlValueString(valueString);
|
2016-12-12 13:03:36 +03:00
|
|
|
bool isSet = false;
|
2002-01-09 16:51:37 +03:00
|
|
|
do {
|
|
|
|
valueString.Assign(htmlValueString);
|
|
|
|
// get the value of the CSS equivalent styles
|
2016-10-19 12:09:33 +03:00
|
|
|
nsresult rv =
|
2016-12-12 13:03:36 +03:00
|
|
|
GetCSSEquivalentToHTMLInlineStyleSet(aNode, aHTMLProperty, aHTMLAttribute,
|
2016-10-19 12:09:33 +03:00
|
|
|
valueString, aStyleType);
|
2016-12-12 13:03:36 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
// early way out if we can
|
2012-04-17 21:50:19 +04:00
|
|
|
if (valueString.IsEmpty()) {
|
2016-12-12 13:03:36 +03:00
|
|
|
return isSet;
|
2012-04-17 21:50:19 +04:00
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2014-08-29 15:43:24 +04:00
|
|
|
if (nsGkAtoms::b == aHTMLProperty) {
|
2012-04-17 21:50:19 +04:00
|
|
|
if (valueString.EqualsLiteral("bold")) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (valueString.EqualsLiteral("normal")) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = false;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else if (valueString.EqualsLiteral("bolder")) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t weight = 0;
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult errorCode;
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString value(valueString);
|
2013-04-24 16:36:09 +04:00
|
|
|
weight = value.ToInteger(&errorCode);
|
2002-01-09 16:51:37 +03:00
|
|
|
if (400 < weight) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
valueString.AssignLiteral("bold");
|
|
|
|
} else {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = false;
|
2004-06-17 04:13:25 +04:00
|
|
|
valueString.AssignLiteral("normal");
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::i == aHTMLProperty) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (valueString.EqualsLiteral("italic") ||
|
|
|
|
valueString.EqualsLiteral("oblique")) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::u == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString val;
|
2004-06-17 04:13:25 +04:00
|
|
|
val.AssignLiteral("underline");
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = ChangeStyleTransaction::ValueIncludes(valueString, val);
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::strike == aHTMLProperty) {
|
2002-01-09 16:51:37 +03:00
|
|
|
nsAutoString val;
|
2004-06-17 04:13:25 +04:00
|
|
|
val.AssignLiteral("line-through");
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = ChangeStyleTransaction::ValueIncludes(valueString, val);
|
|
|
|
} else if ((nsGkAtoms::font == aHTMLProperty &&
|
|
|
|
aHTMLAttribute == nsGkAtoms::color) ||
|
|
|
|
aHTMLAttribute == nsGkAtoms::bgcolor) {
|
2012-04-17 21:50:19 +04:00
|
|
|
if (htmlValueString.IsEmpty()) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2002-12-13 11:56:21 +03:00
|
|
|
nscolor rgba;
|
|
|
|
nsAutoString subStr;
|
2012-04-17 21:50:19 +04:00
|
|
|
htmlValueString.Right(subStr, htmlValueString.Length() - 1);
|
2002-12-13 11:56:21 +03:00
|
|
|
if (NS_ColorNameToRGB(htmlValueString, &rgba) ||
|
2016-05-09 08:16:41 +03:00
|
|
|
NS_HexToRGBA(subStr, nsHexColorType::NoAlpha, &rgba)) {
|
2002-12-13 11:56:21 +03:00
|
|
|
nsAutoString htmlColor, tmpStr;
|
|
|
|
|
2012-05-28 15:20:27 +04: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(");
|
2002-12-13 11:56:21 +03:00
|
|
|
|
2012-05-28 15:20:27 +04:00
|
|
|
NS_NAMED_LITERAL_STRING(comma, ", ");
|
2002-12-13 11:56:21 +03:00
|
|
|
|
2012-05-28 15:20:27 +04:00
|
|
|
tmpStr.AppendInt(NS_GET_R(rgba), 10);
|
|
|
|
htmlColor.Append(tmpStr + comma);
|
2002-12-13 11:56:21 +03:00
|
|
|
|
2012-05-28 15:20:27 +04: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 19:02:17 +04:00
|
|
|
htmlColor.Append(char16_t(')'));
|
2012-05-28 15:20:27 +04:00
|
|
|
}
|
2002-12-13 11:56:21 +03:00
|
|
|
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = htmlColor.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 21:50:19 +04:00
|
|
|
}
|
2002-12-13 11:56:21 +03:00
|
|
|
}
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::tt == aHTMLProperty) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = StringBeginsWith(valueString, NS_LITERAL_STRING("monospace"));
|
2014-08-29 15:43:24 +04:00
|
|
|
} else if (nsGkAtoms::font == aHTMLProperty && aHTMLAttribute &&
|
2016-12-12 13:03:36 +03:00
|
|
|
aHTMLAttribute == nsGkAtoms::face) {
|
2003-04-17 11:35:55 +04:00
|
|
|
if (!htmlValueString.IsEmpty()) {
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t commaSpace[] = { char16_t(','), char16_t(' '), 0 };
|
|
|
|
const char16_t comma[] = { char16_t(','), 0 };
|
2003-04-17 11:35:55 +04:00
|
|
|
htmlValueString.ReplaceSubstring(commaSpace, comma);
|
|
|
|
nsAutoString valueStringNorm(valueString);
|
|
|
|
valueStringNorm.ReplaceSubstring(commaSpace, comma);
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = htmlValueString.Equals(valueStringNorm,
|
|
|
|
nsCaseInsensitiveStringComparator());
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2016-12-12 13:03:36 +03:00
|
|
|
return isSet;
|
|
|
|
} else if (aHTMLAttribute == nsGkAtoms::align) {
|
|
|
|
isSet = true;
|
2012-04-17 21:50:19 +04:00
|
|
|
} else {
|
2016-12-12 13:03:36 +03:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2012-04-17 21:50:19 +04:00
|
|
|
if (!htmlValueString.IsEmpty() &&
|
|
|
|
htmlValueString.Equals(valueString,
|
|
|
|
nsCaseInsensitiveStringComparator())) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2012-05-28 15:20:27 +04:00
|
|
|
if (htmlValueString.EqualsLiteral("-moz-editor-invert-value")) {
|
2016-12-12 13:03:36 +03:00
|
|
|
isSet = !isSet;
|
2012-05-28 15:20:27 +04:00
|
|
|
}
|
|
|
|
|
2014-08-29 15:43:24 +04:00
|
|
|
if (nsGkAtoms::u == aHTMLProperty || nsGkAtoms::strike == aHTMLProperty) {
|
2002-01-09 16:51:37 +03: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
|
2016-12-12 13:03:36 +03:00
|
|
|
aNode = aNode->GetParentElement(); // set to null if it's not a dom element
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2014-08-29 15:43:24 +04:00
|
|
|
} while ((nsGkAtoms::u == aHTMLProperty ||
|
2016-12-12 13:03:36 +03:00
|
|
|
nsGkAtoms::strike == aHTMLProperty) && !isSet && aNode);
|
|
|
|
return isSet;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2017-02-23 11:10:27 +03:00
|
|
|
bool
|
|
|
|
CSSEditUtils::HaveCSSEquivalentStyles(
|
|
|
|
nsINode& aNode,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aHTMLProperty,
|
|
|
|
nsAtom* aHTMLAttribute,
|
2017-02-23 11:10:27 +03:00
|
|
|
StyleType aStyleType)
|
|
|
|
{
|
|
|
|
nsAutoString valueString;
|
|
|
|
nsCOMPtr<nsINode> node = &aNode;
|
|
|
|
do {
|
|
|
|
// get the value of the CSS equivalent styles
|
|
|
|
nsresult rv =
|
|
|
|
GetCSSEquivalentToHTMLInlineStyleSet(node, aHTMLProperty, aHTMLAttribute,
|
|
|
|
valueString, aStyleType);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valueString.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsGkAtoms::u != aHTMLProperty && nsGkAtoms::strike != aHTMLProperty) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// set to null if it's not a dom element
|
|
|
|
node = node->GetParentElement();
|
|
|
|
} while (node);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-01 15:03:17 +04:00
|
|
|
void
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
mIsCSSPrefChecked = aIsCSSPrefChecked;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2018-02-06 06:57:37 +03:00
|
|
|
CSSEditUtils::IsCSSPrefChecked() const
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
|
|
|
return mIsCSSPrefChecked ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ElementsSameStyle compares two elements and checks if they have the same
|
2015-05-28 18:58:42 +03:00
|
|
|
// specified CSS declarations in the STYLE attribute
|
2002-01-09 16:51:37 +03:00
|
|
|
// The answer is always negative if at least one of them carries an ID or a class
|
2018-02-06 06:57:37 +03:00
|
|
|
|
|
|
|
// static
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::ElementsSameStyle(Element* aFirstElement,
|
|
|
|
Element* aSecondElement)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2013-01-11 12:43:01 +04:00
|
|
|
MOZ_ASSERT(aFirstElement);
|
|
|
|
MOZ_ASSERT(aSecondElement);
|
2002-01-09 16:51:37 +03:00
|
|
|
|
2013-01-11 12:43:01 +04:00
|
|
|
if (aFirstElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id) ||
|
|
|
|
aSecondElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id)) {
|
2002-01-09 16:51:37 +03: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 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString firstClass, secondClass;
|
2013-01-11 12:43:01 +04:00
|
|
|
bool isFirstClassSet = aFirstElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, firstClass);
|
|
|
|
bool isSecondClassSet = aSecondElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, secondClass);
|
2002-01-09 16:51:37 +03: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 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2013-01-11 12:43:01 +04:00
|
|
|
} else if (isFirstClassSet || isSecondClassSet) {
|
2002-01-09 16:51:37 +03:00
|
|
|
// one span only carries a class, early way out
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:17:57 +03:00
|
|
|
nsCOMPtr<nsICSSDeclaration> firstCSSDecl, secondCSSDecl;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t firstLength, secondLength;
|
2013-01-11 12:43:01 +04: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;
|
|
|
|
}
|
2002-01-09 16:51:37 +03:00
|
|
|
|
|
|
|
if (firstLength != secondLength) {
|
|
|
|
// early way out if we can
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2013-01-11 12:43:01 +04:00
|
|
|
|
|
|
|
if (!firstLength) {
|
2002-01-09 16:51:37 +03:00
|
|
|
// no inline style !
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString propertyNameString;
|
|
|
|
nsAutoString firstValue, secondValue;
|
2013-01-11 12:43:01 +04:00
|
|
|
for (uint32_t i = 0; i < firstLength; i++) {
|
2002-01-09 16:51:37 +03:00
|
|
|
firstCSSDecl->Item(i, propertyNameString);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
2013-01-11 12:43:01 +04:00
|
|
|
for (uint32_t i = 0; i < secondLength; i++) {
|
2002-01-09 16:51:37 +03:00
|
|
|
secondCSSDecl->Item(i, propertyNameString);
|
|
|
|
secondCSSDecl->GetPropertyValue(propertyNameString, secondValue);
|
|
|
|
firstCSSDecl->GetPropertyValue(propertyNameString, firstValue);
|
|
|
|
if (!firstValue.Equals(secondValue)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2002-01-09 16:51:37 +03:00
|
|
|
nsresult
|
2016-07-07 12:35:13 +03:00
|
|
|
CSSEditUtils::GetInlineStyles(Element* aElement,
|
2018-01-11 11:17:57 +03:00
|
|
|
nsICSSDeclaration** aCssDecl,
|
2016-07-07 12:35:13 +03:00
|
|
|
uint32_t* aLength)
|
2002-01-09 16:51:37 +03:00
|
|
|
{
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(aElement && aLength, NS_ERROR_NULL_POINTER);
|
2002-01-09 16:51:37 +03:00
|
|
|
*aLength = 0;
|
2016-08-02 21:05:38 +03:00
|
|
|
nsCOMPtr<nsStyledElement> inlineStyles = do_QueryInterface(aElement);
|
2010-06-17 23:41:16 +04:00
|
|
|
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
|
2013-01-11 12:43:01 +04:00
|
|
|
|
2018-01-11 11:17:57 +03:00
|
|
|
nsCOMPtr<nsICSSDeclaration> cssDecl = inlineStyles->Style();
|
2016-08-02 21:05:38 +03:00
|
|
|
MOZ_ASSERT(cssDecl);
|
2013-01-11 12:43:01 +04:00
|
|
|
|
2016-08-02 21:05:38 +03:00
|
|
|
cssDecl.forget(aCssDecl);
|
2018-01-30 22:48:27 +03:00
|
|
|
*aLength = (*aCssDecl)->Length();
|
2002-01-09 16:51:37 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-06 06:57:37 +03:00
|
|
|
// static
|
2016-07-07 12:35:13 +03:00
|
|
|
Element*
|
|
|
|
CSSEditUtils::GetElementContainerOrSelf(nsINode* aNode)
|
2012-02-10 14:04:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aNode);
|
2018-01-30 07:10:53 +03:00
|
|
|
if (nsINode::DOCUMENT_NODE == aNode->NodeType()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-02-19 10:55:40 +03:00
|
|
|
}
|
|
|
|
|
2012-02-10 14:04:46 +04:00
|
|
|
nsINode* node = aNode;
|
2012-02-01 14:54:22 +04:00
|
|
|
// Loop until we find an element.
|
|
|
|
while (node && !node->IsElement()) {
|
2012-10-09 16:31:24 +04:00
|
|
|
node = node->GetParentNode();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2012-02-01 14:54:22 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ENSURE_TRUE(node, nullptr);
|
2012-02-10 14:04:46 +04:00
|
|
|
return node->AsElement();
|
2002-01-09 16:51:37 +03:00
|
|
|
}
|
2003-06-25 12:50:48 +04:00
|
|
|
|
2016-07-07 12:35:13 +03:00
|
|
|
} // namespace mozilla
|