rename from editor/libeditor/nsHTMLCSSUtils.cpp
rename to editor/libeditor/CSSEditUtils.cpp
--- a/editor/libeditor/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/CSSEditUtils.cpp
@@ -1,14 +1,14 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include "nsHTMLCSSUtils.h"
+#include "CSSEditUtils.h"
#include "ChangeStyleTransaction.h"
#include "mozilla/Assertions.h"
#include "mozilla/Preferences.h"
#include "mozilla/css/Declaration.h"
#include "mozilla/css/StyleRule.h"
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
@@ -37,87 +37,100 @@
#include "nsPIDOMWindow.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsStringFwd.h"
#include "nsStringIterator.h"
#include "nsSubstringTuple.h"
#include "nsUnicharUtils.h"
-using namespace mozilla;
-using namespace mozilla::dom;
+namespace mozilla {
+
+using namespace dom;
static
-void ProcessBValue(const nsAString * aInputString, nsAString & aOutputString,
- const char * aDefaultValueString,
- const char * aPrependString, const char* aAppendString)
+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)
+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)
+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)
+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)
+void ProcessLengthValue(const nsAString* aInputString,
+ nsAString& aOutputString,
+ const char* aDefaultValueString,
+ const char* aPrependString,
+ const char* aAppendString)
{
aOutputString.Truncate();
if (aInputString) {
aOutputString.Append(*aInputString);
if (-1 == aOutputString.FindChar(char16_t('%'))) {
aOutputString.AppendLiteral("px");
}
}
}
static
-void ProcessListStyleTypeValue(const nsAString * aInputString, nsAString & aOutputString,
- const char * aDefaultValueString,
- const char * aPrependString, const char* aAppendString)
+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");
@@ -135,19 +148,21 @@ void ProcessListStyleTypeValue(const nsA
|| 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)
+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") ||
@@ -156,19 +171,21 @@ void ProcessMarginLeftValue(const nsAStr
}
else {
aOutputString.AppendLiteral("0px");
}
}
}
static
-void ProcessMarginRightValue(const nsAString * aInputString, nsAString & aOutputString,
- const char * aDefaultValueString,
- const char * aPrependString, const char* aAppendString)
+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") ||
@@ -176,136 +193,137 @@ void ProcessMarginRightValue(const nsASt
aOutputString.AppendLiteral("auto");
}
else {
aOutputString.AppendLiteral("0px");
}
}
}
-const nsHTMLCSSUtils::CSSEquivTable boldEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable boldEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_font_weight, ProcessBValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable italicEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable italicEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_font_style, ProcessDefaultValue, "italic", nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable underlineEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable underlineEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "underline", nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable strikeEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable strikeEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_text_decoration, ProcessDefaultValue, "line-through", nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable ttEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable ttEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_font_family, ProcessDefaultValue, "monospace", nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable fontColorEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable fontColorEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable fontFaceEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_font_family, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable fontFaceEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_font_family, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable bgcolorEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_background_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable bgcolorEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_background_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable backgroundImageEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nullptr, "url(", ")", true, true },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable backgroundImageEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_background_image, ProcessExtendedValue, nullptr, "url(", ")", true, true },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable textColorEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable textColorEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_color, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable borderEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_border, ProcessExtendedValue, nullptr, nullptr, "px solid", true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable borderEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_border, ProcessExtendedValue, nullptr, nullptr, "px solid", true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable textAlignEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_text_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable textAlignEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_text_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable captionAlignEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable captionAlignEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_caption_side, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable verticalAlignEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable verticalAlignEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_vertical_align, ProcessSameValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable nowrapEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable nowrapEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_whitespace, ProcessDefaultValue, "nowrap", nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable widthEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_width, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable widthEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_width, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable heightEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_height, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable heightEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_height, ProcessLengthValue, nullptr, nullptr, nullptr, true, false },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable listStyleTypeEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nullptr, nullptr, nullptr, true, true },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+const CSSEditUtils::CSSEquivTable listStyleTypeEquivTable[] = {
+ { CSSEditUtils::eCSSEditableProperty_list_style_type, ProcessListStyleTypeValue, nullptr, nullptr, nullptr, true, true },
+ { CSSEditUtils::eCSSEditableProperty_NONE, 0 }
};
-const nsHTMLCSSUtils::CSSEquivTable tableAlignEquivTable[] = {
- { 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 },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+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 }
};
-const nsHTMLCSSUtils::CSSEquivTable hrAlignEquivTable[] = {
- { nsHTMLCSSUtils::eCSSEditableProperty_margin_left, ProcessMarginLeftValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_margin_right, ProcessMarginRightValue, nullptr, nullptr, nullptr, true, false },
- { nsHTMLCSSUtils::eCSSEditableProperty_NONE, 0 }
+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 }
};
-nsHTMLCSSUtils::nsHTMLCSSUtils(nsHTMLEditor* aEditor)
- : mHTMLEditor(aEditor)
+CSSEditUtils::CSSEditUtils(nsHTMLEditor* aHTMLEditor)
+ : mHTMLEditor(aHTMLEditor)
, mIsCSSPrefChecked(true)
{
// let's retrieve the value of the "CSS editing" pref
mIsCSSPrefChecked = Preferences::GetBool("editor.use_css", mIsCSSPrefChecked);
}
-nsHTMLCSSUtils::~nsHTMLCSSUtils()
+CSSEditUtils::~CSSEditUtils()
{
}
// Answers true if we have some CSS equivalence for the HTML style defined
// by aProperty and/or aAttribute for the node aNode
bool
-nsHTMLCSSUtils::IsCSSEditableProperty(nsINode* aNode, nsIAtom* aProperty,
- const nsAString* aAttribute)
+CSSEditUtils::IsCSSEditableProperty(nsINode* aNode,
+ nsIAtom* aProperty,
+ const nsAString* aAttribute)
{
MOZ_ASSERT(aNode);
nsINode* node = aNode;
// we need an element node here
if (node->NodeType() == nsIDOMNode::TEXT_NODE) {
node = node->GetParentNode();
NS_ENSURE_TRUE(node, false);
@@ -425,89 +443,97 @@ nsHTMLCSSUtils::IsCSSEditableProperty(ns
}
return false;
}
// The lowest level above the transaction; adds the CSS declaration
// "aProperty : aValue" to the inline styles carried by aElement
nsresult
-nsHTMLCSSUtils::SetCSSProperty(Element& aElement, nsIAtom& aProperty,
- const nsAString& aValue, bool aSuppressTxn)
+CSSEditUtils::SetCSSProperty(Element& aElement,
+ nsIAtom& aProperty,
+ const nsAString& aValue,
+ bool aSuppressTxn)
{
RefPtr<ChangeStyleTransaction> transaction =
CreateCSSPropertyTxn(aElement, aProperty, aValue,
ChangeStyleTransaction::eSet);
if (aSuppressTxn) {
return transaction->DoTransaction();
}
return mHTMLEditor->DoTransaction(transaction);
}
nsresult
-nsHTMLCSSUtils::SetCSSPropertyPixels(Element& aElement, nsIAtom& aProperty,
- int32_t aIntValue)
+CSSEditUtils::SetCSSPropertyPixels(Element& aElement,
+ nsIAtom& aProperty,
+ int32_t aIntValue)
{
nsAutoString s;
s.AppendInt(aIntValue);
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"),
/* suppress txn */ false);
}
// 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
nsresult
-nsHTMLCSSUtils::RemoveCSSProperty(Element& aElement, nsIAtom& aProperty,
- const nsAString& aValue, bool aSuppressTxn)
+CSSEditUtils::RemoveCSSProperty(Element& aElement,
+ nsIAtom& aProperty,
+ const nsAString& aValue,
+ bool aSuppressTxn)
{
RefPtr<ChangeStyleTransaction> transaction =
CreateCSSPropertyTxn(aElement, aProperty, aValue,
ChangeStyleTransaction::eRemove);
if (aSuppressTxn) {
return transaction->DoTransaction();
}
return mHTMLEditor->DoTransaction(transaction);
}
already_AddRefed<ChangeStyleTransaction>
-nsHTMLCSSUtils::CreateCSSPropertyTxn(
- Element& aElement,
- nsIAtom& aAttribute,
- const nsAString& aValue,
- ChangeStyleTransaction::EChangeType aChangeType)
+CSSEditUtils::CreateCSSPropertyTxn(
+ Element& aElement,
+ nsIAtom& aAttribute,
+ const nsAString& aValue,
+ ChangeStyleTransaction::EChangeType aChangeType)
{
RefPtr<ChangeStyleTransaction> transaction =
new ChangeStyleTransaction(aElement, aAttribute, aValue, aChangeType);
return transaction.forget();
}
nsresult
-nsHTMLCSSUtils::GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
- nsAString& aValue)
+CSSEditUtils::GetSpecifiedProperty(nsINode& aNode,
+ nsIAtom& aProperty,
+ nsAString& aValue)
{
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eSpecified);
}
nsresult
-nsHTMLCSSUtils::GetComputedProperty(nsINode& aNode, nsIAtom& aProperty,
- nsAString& aValue)
+CSSEditUtils::GetComputedProperty(nsINode& aNode,
+ nsIAtom& aProperty,
+ nsAString& aValue)
{
return GetCSSInlinePropertyBase(&aNode, &aProperty, aValue, eComputed);
}
nsresult
-nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
- nsAString& aValue,
- StyleType aStyleType)
+CSSEditUtils::GetCSSInlinePropertyBase(nsINode* aNode,
+ nsIAtom* aProperty,
+ nsAString& aValue,
+ StyleType aStyleType)
{
MOZ_ASSERT(aNode && aProperty);
aValue.Truncate();
- nsCOMPtr<dom::Element> element = GetElementContainerOrSelf(aNode);
+ nsCOMPtr<Element> element = GetElementContainerOrSelf(aNode);
NS_ENSURE_TRUE(element, NS_ERROR_NULL_POINTER);
if (aStyleType == eComputed) {
// Get the all the computed css styles attached to the element node
RefPtr<nsComputedDOMStyle> cssDecl = GetComputedStyle(element);
NS_ENSURE_STATE(cssDecl);
// from these declarations, get the one we want and that one only
@@ -527,17 +553,17 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase
CSSEnabledState::eForAllContent);
MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
decl->GetValue(prop, aValue);
return NS_OK;
}
already_AddRefed<nsComputedDOMStyle>
-nsHTMLCSSUtils::GetComputedStyle(dom::Element* aElement)
+CSSEditUtils::GetComputedStyle(Element* aElement)
{
MOZ_ASSERT(aElement);
nsIDocument* doc = aElement->GetUncomposedDoc();
NS_ENSURE_TRUE(doc, nullptr);
nsIPresShell* presShell = doc->GetShell();
NS_ENSURE_TRUE(presShell, nullptr);
@@ -546,17 +572,19 @@ nsHTMLCSSUtils::GetComputedStyle(dom::El
NS_NewComputedDOMStyle(aElement, EmptyString(), presShell);
return style.forget();
}
// 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)
+CSSEditUtils::RemoveCSSInlineStyle(nsIDOMNode* aNode,
+ nsIAtom* aProperty,
+ const nsAString& aPropertyValue)
{
nsCOMPtr<Element> element = do_QueryInterface(aNode);
NS_ENSURE_STATE(element);
// remove the property from the style attribute
nsresult res = RemoveCSSProperty(*element, *aProperty, aPropertyValue);
NS_ENSURE_SUCCESS(res, res);
@@ -566,24 +594,25 @@ nsHTMLCSSUtils::RemoveCSSInlineStyle(nsI
}
return mHTMLEditor->RemoveContainer(element);
}
// Answers true if the property can be removed by setting a "none" CSS value
// on a node
bool
-nsHTMLCSSUtils::IsCSSInvertible(nsIAtom& aProperty, const nsAString* aAttribute)
+CSSEditUtils::IsCSSInvertible(nsIAtom& aProperty,
+ const nsAString* aAttribute)
{
return nsGkAtoms::b == &aProperty;
}
// Get the default browser background color if we need it for GetCSSBackgroundColorState
void
-nsHTMLCSSUtils::GetDefaultBackgroundColor(nsAString & aColor)
+CSSEditUtils::GetDefaultBackgroundColor(nsAString& aColor)
{
if (Preferences::GetBool("editor.use_custom_colors", false)) {
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
}
@@ -600,32 +629,33 @@ nsHTMLCSSUtils::GetDefaultBackgroundColo
if (NS_FAILED(rv)) {
NS_WARNING("failed to get browser.display.background_color");
aColor.AssignLiteral("#ffffff"); // Default to white
}
}
// Get the default length unit used for CSS Indent/Outdent
void
-nsHTMLCSSUtils::GetDefaultLengthUnit(nsAString & aLengthUnit)
+CSSEditUtils::GetDefaultLengthUnit(nsAString& aLengthUnit)
{
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");
}
}
// 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)
+CSSEditUtils::ParseLength(const nsAString& aString,
+ float* aValue,
+ nsIAtom** aUnit)
{
if (aString.IsEmpty()) {
*aValue = 0;
*aUnit = NS_Atomize(aString).take();
return;
}
nsAString::const_iterator iter;
@@ -662,17 +692,18 @@ nsHTMLCSSUtils::ParseLength(const nsAStr
iter++;
i++;
}
*aValue = value * sign;
*aUnit = NS_Atomize(StringTail(aString, j-i)).take();
}
void
-nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom)
+CSSEditUtils::GetCSSPropertyAtom(nsCSSEditableProperty aProperty,
+ nsIAtom** aAtom)
{
*aAtom = nullptr;
switch (aProperty) {
case eCSSEditableProperty_background_color:
*aAtom = nsGkAtoms::backgroundColor;
break;
case eCSSEditableProperty_background_image:
*aAtom = nsGkAtoms::background_image;
@@ -732,21 +763,21 @@ nsHTMLCSSUtils::GetCSSPropertyAtom(nsCSS
// intentionally empty
break;
}
}
// Populate aProperty and aValueArray with the CSS declarations equivalent to the
// value aValue according to the equivalence table aEquivTable
void
-nsHTMLCSSUtils::BuildCSSDeclarations(nsTArray<nsIAtom*> & aPropertyArray,
- nsTArray<nsString> & aValueArray,
- const CSSEquivTable * aEquivTable,
- const nsAString * aValue,
- bool aGetOrRemoveRequest)
+CSSEditUtils::BuildCSSDeclarations(nsTArray<nsIAtom*>& aPropertyArray,
+ nsTArray<nsString>& aValueArray,
+ const CSSEquivTable* aEquivTable,
+ const nsAString* aValue,
+ bool aGetOrRemoveRequest)
{
// clear arrays
aPropertyArray.Clear();
aValueArray.Clear();
// if we have an input value, let's use it
nsAutoString value, lowerCasedValue;
if (aValue) {
@@ -775,26 +806,27 @@ nsHTMLCSSUtils::BuildCSSDeclarations(nsT
index++;
cssProperty = aEquivTable[index].cssProperty;
}
}
// Populate cssPropertyArray and cssValueArray with the declarations equivalent
// to aHTMLProperty/aAttribute/aValue for the node aNode
void
-nsHTMLCSSUtils::GenerateCSSDeclarationsFromHTMLStyle(dom::Element* aElement,
- nsIAtom* aHTMLProperty,
- const nsAString* aAttribute,
- const nsAString* aValue,
- nsTArray<nsIAtom*>& cssPropertyArray,
- nsTArray<nsString>& cssValueArray,
- bool aGetOrRemoveRequest)
+CSSEditUtils::GenerateCSSDeclarationsFromHTMLStyle(
+ Element* aElement,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ nsTArray<nsIAtom*>& cssPropertyArray,
+ nsTArray<nsString>& cssValueArray,
+ bool aGetOrRemoveRequest)
{
MOZ_ASSERT(aElement);
- const nsHTMLCSSUtils::CSSEquivTable* equivTable = nullptr;
+ const CSSEditUtils::CSSEquivTable* equivTable = nullptr;
if (nsGkAtoms::b == aHTMLProperty) {
equivTable = boldEquivTable;
} else if (nsGkAtoms::i == aHTMLProperty) {
equivTable = italicEquivTable;
} else if (nsGkAtoms::u == aHTMLProperty) {
equivTable = underlineEquivTable;
} else if (nsGkAtoms::strike == aHTMLProperty) {
@@ -847,23 +879,23 @@ nsHTMLCSSUtils::GenerateCSSDeclarationsF
if (equivTable) {
BuildCSSDeclarations(cssPropertyArray, cssValueArray, equivTable,
aValue, aGetOrRemoveRequest);
}
}
// 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.
+// by the call. The Element version returns aCount instead.
int32_t
-nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(dom::Element* aElement,
- nsIAtom* aProperty,
- const nsAString* aAttribute,
- const nsAString* aValue,
- bool aSuppressTransaction)
+CSSEditUtils::SetCSSEquivalentToHTMLStyle(Element* aElement,
+ nsIAtom* aProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ bool aSuppressTransaction)
{
MOZ_ASSERT(aElement && aProperty);
MOZ_ASSERT_IF(aAttribute, aValue);
int32_t count;
// 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.
@@ -872,24 +904,24 @@ nsHTMLCSSUtils::SetCSSEquivalentToHTMLSt
aValue, &count,
aSuppressTransaction);
NS_ASSERTION(NS_SUCCEEDED(res), "SetCSSEquivalentToHTMLStyle failed");
NS_ENSURE_SUCCESS(res, count);
return count;
}
nsresult
-nsHTMLCSSUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
- nsIAtom *aHTMLProperty,
- const nsAString *aAttribute,
- const nsAString *aValue,
- int32_t * aCount,
- bool aSuppressTransaction)
+CSSEditUtils::SetCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ int32_t* aCount,
+ bool aSuppressTransaction)
{
- nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
+ nsCOMPtr<Element> element = do_QueryInterface(aNode);
*aCount = 0;
if (!element || !IsCSSEditableProperty(element, aHTMLProperty, aAttribute)) {
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
@@ -907,35 +939,35 @@ nsHTMLCSSUtils::SetCSSEquivalentToHTMLSt
cssValueArray[index], aSuppressTransaction);
NS_ENSURE_SUCCESS(res, res);
}
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,
- bool aSuppressTransaction)
+CSSEditUtils::RemoveCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ bool aSuppressTransaction)
{
- nsCOMPtr<dom::Element> element = do_QueryInterface(aNode);
+ nsCOMPtr<Element> element = do_QueryInterface(aNode);
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)
+CSSEditUtils::RemoveCSSEquivalentToHTMLStyle(Element* aElement,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ bool aSuppressTransaction)
{
MOZ_ASSERT(aElement);
if (!IsCSSEditableProperty(aElement, aHTMLProperty, aAttribute)) {
return NS_OK;
}
// we can apply the styles only if the node is an element and if we have
@@ -960,24 +992,24 @@ nsHTMLCSSUtils::RemoveCSSEquivalentToHTM
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
-nsHTMLCSSUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
- nsIAtom *aHTMLProperty,
- const nsAString *aAttribute,
- nsAString & aValueString,
- StyleType aStyleType)
+CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ nsAString& aValueString,
+ StyleType aStyleType)
{
aValueString.Truncate();
- nsCOMPtr<dom::Element> theElement = GetElementContainerOrSelf(aNode);
+ nsCOMPtr<Element> theElement = GetElementContainerOrSelf(aNode);
NS_ENSURE_TRUE(theElement, NS_ERROR_NULL_POINTER);
if (!theElement || !IsCSSEditableProperty(theElement, aHTMLProperty, aAttribute)) {
return NS_OK;
}
// Yes, the requested HTML style has a CSS equivalence in this implementation
nsTArray<nsIAtom*> cssPropertyArray;
@@ -1005,51 +1037,52 @@ nsHTMLCSSUtils::GetCSSEquivalentToHTMLIn
// 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.
//
// The nsIContent variant returns aIsSet instead of using an out parameter, and
// does not modify aValue.
bool
-nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
- nsIAtom* aProperty,
- const nsAString* aAttribute,
- const nsAString& aValue,
- StyleType aStyleType)
+CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
+ nsIAtom* aProperty,
+ const nsAString* aAttribute,
+ const nsAString& aValue,
+ StyleType aStyleType)
{
// Use aValue as only an in param, not in-out
nsAutoString value(aValue);
return IsCSSEquivalentToHTMLInlineStyleSet(aNode, aProperty, aAttribute,
value, aStyleType);
}
bool
-nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
- nsIAtom* aProperty,
- const nsAString* aAttribute,
- nsAString& aValue,
- StyleType aStyleType)
+CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
+ nsIAtom* aProperty,
+ const nsAString* aAttribute,
+ nsAString& aValue,
+ StyleType aStyleType)
{
MOZ_ASSERT(aNode && aProperty);
bool isSet;
nsresult res = IsCSSEquivalentToHTMLInlineStyleSet(aNode->AsDOMNode(),
aProperty, aAttribute,
isSet, aValue, aStyleType);
NS_ENSURE_SUCCESS(res, false);
return isSet;
}
nsresult
-nsHTMLCSSUtils::IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode *aNode,
- nsIAtom *aHTMLProperty,
- const nsAString *aHTMLAttribute,
- bool& aIsSet,
- nsAString& valueString,
- StyleType aStyleType)
+CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSet(
+ nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aHTMLAttribute,
+ bool& aIsSet,
+ nsAString& valueString,
+ StyleType aStyleType)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
nsAutoString htmlValueString(valueString);
aIsSet = false;
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
do {
valueString.Assign(htmlValueString);
@@ -1182,46 +1215,47 @@ nsHTMLCSSUtils::IsCSSEquivalentToHTMLInl
node = node->GetParentElement(); // set to null if it's not a dom element
}
} while ((nsGkAtoms::u == aHTMLProperty ||
nsGkAtoms::strike == aHTMLProperty) && !aIsSet && node);
return NS_OK;
}
void
-nsHTMLCSSUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
+CSSEditUtils::SetCSSEnabled(bool aIsCSSPrefChecked)
{
mIsCSSPrefChecked = aIsCSSPrefChecked;
}
bool
-nsHTMLCSSUtils::IsCSSPrefChecked()
+CSSEditUtils::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
bool
-nsHTMLCSSUtils::ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode)
+CSSEditUtils::ElementsSameStyle(nsIDOMNode* aFirstNode,
+ nsIDOMNode* aSecondNode)
{
- nsCOMPtr<dom::Element> firstElement = do_QueryInterface(aFirstNode);
- nsCOMPtr<dom::Element> secondElement = do_QueryInterface(aSecondNode);
+ nsCOMPtr<Element> firstElement = do_QueryInterface(aFirstNode);
+ nsCOMPtr<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);
}
bool
-nsHTMLCSSUtils::ElementsSameStyle(dom::Element* aFirstElement,
- dom::Element* aSecondElement)
+CSSEditUtils::ElementsSameStyle(Element* aFirstElement,
+ Element* aSecondElement)
{
MOZ_ASSERT(aFirstElement);
MOZ_ASSERT(aSecondElement);
if (aFirstElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id) ||
aSecondElement->HasAttr(kNameSpaceID_None, nsGkAtoms::id)) {
// at least one of the spans carries an ID ; suspect a CSS rule applies to it and
// refuse to merge the nodes
@@ -1286,61 +1320,61 @@ nsHTMLCSSUtils::ElementsSameStyle(dom::E
return false;
}
}
return true;
}
nsresult
-nsHTMLCSSUtils::GetInlineStyles(dom::Element* aElement,
- nsIDOMCSSStyleDeclaration** aCssDecl,
- uint32_t* aLength)
+CSSEditUtils::GetInlineStyles(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)
+CSSEditUtils::GetInlineStyles(nsIDOMElement* aElement,
+ nsIDOMCSSStyleDeclaration** aCssDecl,
+ uint32_t* aLength)
{
return GetInlineStyles(static_cast<nsISupports*>(aElement), aCssDecl, aLength);
}
nsresult
-nsHTMLCSSUtils::GetInlineStyles(nsISupports *aElement,
- nsIDOMCSSStyleDeclaration **aCssDecl,
- uint32_t *aLength)
+CSSEditUtils::GetInlineStyles(nsISupports* aElement,
+ nsIDOMCSSStyleDeclaration** aCssDecl,
+ uint32_t* aLength)
{
NS_ENSURE_TRUE(aElement && aLength, NS_ERROR_NULL_POINTER);
*aLength = 0;
nsCOMPtr<nsIDOMElementCSSInlineStyle> inlineStyles = do_QueryInterface(aElement);
NS_ENSURE_TRUE(inlineStyles, NS_ERROR_NULL_POINTER);
nsresult res = inlineStyles->GetStyle(aCssDecl);
NS_ENSURE_SUCCESS(res, NS_ERROR_NULL_POINTER);
MOZ_ASSERT(*aCssDecl);
(*aCssDecl)->GetLength(aLength);
return NS_OK;
}
already_AddRefed<nsIDOMElement>
-nsHTMLCSSUtils::GetElementContainerOrSelf(nsIDOMNode* aNode)
+CSSEditUtils::GetElementContainerOrSelf(nsIDOMNode* aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
NS_ENSURE_TRUE(node, nullptr);
nsCOMPtr<nsIDOMElement> element =
do_QueryInterface(GetElementContainerOrSelf(node));
return element.forget();
}
-dom::Element*
-nsHTMLCSSUtils::GetElementContainerOrSelf(nsINode* aNode)
+Element*
+CSSEditUtils::GetElementContainerOrSelf(nsINode* aNode)
{
MOZ_ASSERT(aNode);
if (nsIDOMNode::DOCUMENT_NODE == aNode->NodeType()) {
return nullptr;
}
nsINode* node = aNode;
// Loop until we find an element.
@@ -1348,31 +1382,33 @@ nsHTMLCSSUtils::GetElementContainerOrSel
node = node->GetParentNode();
}
NS_ENSURE_TRUE(node, nullptr);
return node->AsElement();
}
nsresult
-nsHTMLCSSUtils::SetCSSProperty(nsIDOMElement * aElement,
- const nsAString & aProperty,
- const nsAString & aValue)
+CSSEditUtils::SetCSSProperty(nsIDOMElement* aElement,
+ const nsAString& aProperty,
+ const nsAString& aValue)
{
nsCOMPtr<nsIDOMCSSStyleDeclaration> cssDecl;
uint32_t length;
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,
- int32_t aIntValue)
+CSSEditUtils::SetCSSPropertyPixels(nsIDOMElement* aElement,
+ const nsAString& aProperty,
+ int32_t aIntValue)
{
nsAutoString s;
s.AppendInt(aIntValue);
return SetCSSProperty(aElement, aProperty, s + NS_LITERAL_STRING("px"));
}
+
+} // namespace mozilla
rename from editor/libeditor/nsHTMLCSSUtils.h
rename to editor/libeditor/CSSEditUtils.h
--- a/editor/libeditor/nsHTMLCSSUtils.h
+++ b/editor/libeditor/CSSEditUtils.h
@@ -1,48 +1,51 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#ifndef nsHTMLCSSUtils_h__
-#define nsHTMLCSSUtils_h__
+#ifndef CSSEditUtils_h
+#define CSSEditUtils_h
#include "ChangeStyleTransaction.h" // for ChangeStyleTransaction::EChangeType
#include "nsCOMPtr.h" // for already_AddRefed
#include "nsTArray.h" // for nsTArray
#include "nscore.h" // for nsAString, nsresult, nullptr
class nsComputedDOMStyle;
+class nsHTMLEditor;
class nsIAtom;
class nsIContent;
class nsIDOMCSSStyleDeclaration;
class nsIDOMElement;
class nsIDOMNode;
class nsINode;
class nsString;
+
namespace mozilla {
+
namespace dom {
class Element;
} // namespace dom
-} // namespace mozilla
-
-class nsHTMLEditor;
-typedef void (*nsProcessValueFunc)(const nsAString * aInputString, nsAString & aOutputString,
- const char * aDefaultValueString,
- const char * aPrependString, const char* aAppendString);
+typedef void (*nsProcessValueFunc)(const nsAString* aInputString,
+ nsAString& aOutputString,
+ const char* aDefaultValueString,
+ const char* aPrependString,
+ const char* aAppendString);
-class nsHTMLCSSUtils
+class CSSEditUtils final
{
public:
- explicit nsHTMLCSSUtils(nsHTMLEditor* aEditor);
- ~nsHTMLCSSUtils();
+ explicit CSSEditUtils(nsHTMLEditor* aEditor);
+ ~CSSEditUtils();
- enum nsCSSEditableProperty {
+ enum nsCSSEditableProperty
+ {
eCSSEditableProperty_NONE=0,
eCSSEditableProperty_background_color,
eCSSEditableProperty_background_image,
eCSSEditableProperty_border,
eCSSEditableProperty_caption_side,
eCSSEditableProperty_color,
eCSSEditableProperty_float,
eCSSEditableProperty_font_family,
@@ -58,363 +61,413 @@ public:
eCSSEditableProperty_vertical_align,
eCSSEditableProperty_whitespace,
eCSSEditableProperty_width
};
enum StyleType { eSpecified, eComputed };
- struct CSSEquivTable {
+ struct CSSEquivTable
+ {
nsCSSEditableProperty cssProperty;
nsProcessValueFunc processValueFunctor;
- const char * defaultValue;
- const char * prependValue;
- const char * appendValue;
+ const char* defaultValue;
+ const char* prependValue;
+ const char* appendValue;
bool gettable;
bool caseSensitiveValue;
};
- /** answers true if the given combination element_name/attribute_name
- * has a CSS equivalence in this implementation
- *
- * @return a boolean saying if the tag/attribute has a css equiv
- * @param aNode [IN] a DOM node
- * @param aProperty [IN] an atom containing a HTML tag name
- * @param aAttribute [IN] a string containing the name of a HTML
- * attribute carried by the element above
- */
+ /**
+ * Answers true if the given combination element_name/attribute_name
+ * has a CSS equivalence in this implementation.
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aProperty [IN] An atom containing a HTML tag name.
+ * @param aAttribute [IN] A string containing the name of a HTML
+ * attribute carried by the element above.
+ * @return A boolean saying if the tag/attribute has a CSS
+ * equiv.
+ */
bool IsCSSEditableProperty(nsINode* aNode, nsIAtom* aProperty,
const nsAString* aAttribute);
- /** adds/remove a CSS declaration to the STYLE atrribute carried by a given element
- *
- * @param aElement [IN] a DOM element
- * @param aProperty [IN] an atom containing the CSS property to set
- * @param aValue [IN] a string containing the value of the CSS property
- * @param aSuppressTransaction [IN] a boolean indicating, when true,
- * that no transaction should be recorded
- */
- nsresult SetCSSProperty(mozilla::dom::Element& aElement, nsIAtom& aProperty,
+ /**
+ * Adds/remove a CSS declaration to the STYLE atrribute carried by a given
+ * element.
+ *
+ * @param aElement [IN] A DOM element.
+ * @param aProperty [IN] An atom containing the CSS property to set.
+ * @param aValue [IN] A string containing the value of the CSS
+ * property.
+ * @param aSuppressTransaction [IN] A boolean indicating, when true,
+ * that no transaction should be recorded.
+ */
+ nsresult SetCSSProperty(dom::Element& aElement, nsIAtom& aProperty,
const nsAString& aValue, bool aSuppressTxn = false);
- nsresult SetCSSPropertyPixels(mozilla::dom::Element& aElement,
+ nsresult SetCSSPropertyPixels(dom::Element& aElement,
nsIAtom& aProperty, int32_t aIntValue);
- nsresult RemoveCSSProperty(mozilla::dom::Element& aElement,
+ nsresult RemoveCSSProperty(dom::Element& aElement,
nsIAtom& aProperty,
const nsAString& aPropertyValue,
bool aSuppressTxn = false);
- /** directly adds/remove a CSS declaration to the STYLE atrribute carried by
- * a given element without going through the txn manager
- *
- * @param aElement [IN] a DOM element
- * @param aProperty [IN] a string containing the CSS property to set/remove
- * @param aValue [IN] a string containing the new value of the CSS property
- */
- nsresult SetCSSProperty(nsIDOMElement * aElement,
- const nsAString & aProperty,
- const nsAString & aValue);
- nsresult SetCSSPropertyPixels(nsIDOMElement * aElement,
- const nsAString & aProperty,
- int32_t aIntValue);
+ /**
+ * Directly adds/remove a CSS declaration to the STYLE atrribute carried by
+ * a given element without going through the transaction manager.
+ *
+ * @param aElement [IN] A DOM element.
+ * @param aProperty [IN] A string containing the CSS property to
+ * set/remove.
+ * @param aValue [IN] A string containing the new value of the CSS
+ * property.
+ */
+ nsresult SetCSSProperty(nsIDOMElement* aElement,
+ const nsAString& aProperty,
+ const nsAString& aValue);
+ nsresult SetCSSPropertyPixels(nsIDOMElement* aElement,
+ const nsAString& aProperty,
+ int32_t aIntValue);
- /** Gets the specified/computed style value of a CSS property for a given
- * node (or its element ancestor if it is not an element)
- *
- * @param aNode [IN] a DOM node
- * @param aProperty [IN] an atom containing the CSS property to get
- * @param aPropertyValue [OUT] the retrieved value of the property
- */
- nsresult GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
- nsAString& aValue);
- nsresult GetComputedProperty(nsINode& aNode, nsIAtom& aProperty,
- nsAString& aValue);
+ /**
+ * Gets the specified/computed style value of a CSS property for a given
+ * node (or its element ancestor if it is not an element).
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aProperty [IN] An atom containing the CSS property to get.
+ * @param aPropertyValue [OUT] The retrieved value of the property.
+ */
+ nsresult GetSpecifiedProperty(nsINode& aNode, nsIAtom& aProperty,
+ nsAString& aValue);
+ nsresult GetComputedProperty(nsINode& aNode, nsIAtom& aProperty,
+ nsAString& aValue);
- /** Removes a CSS property from the specified declarations in STYLE attribute
- ** and removes the node if it is an useless span
+ /**
+ * Removes a CSS property from the specified declarations in STYLE attribute
+ * and removes the node if it is an useless span.
*
- * @param aNode [IN] the specific node we want to remove a style from
- * @param aProperty [IN] the CSS property atom to remove
- * @param aPropertyValue [IN] the value of the property we have to rremove if the property
- * accepts more than one value
+ * @param aNode [IN] The specific node we want to remove a style
+ * from.
+ * @param aProperty [IN] The CSS property atom to remove.
+ * @param aPropertyValue [IN] The value of the property we have to remove
+ * if the property accepts more than one value.
*/
- nsresult RemoveCSSInlineStyle(nsIDOMNode * aNode, nsIAtom * aProperty, const nsAString & aPropertyValue);
+ nsresult RemoveCSSInlineStyle(nsIDOMNode* aNode, nsIAtom* aProperty,
+ const nsAString& aPropertyValue);
- /** Answers true is the property can be removed by setting a "none" CSS value
- * on a node
- *
- * @return a boolean saying if the property can be remove by setting a "none" value
- * @param aProperty [IN] an atom containing a CSS property
- * @param aAttribute [IN] pointer to an attribute name or null if this information is irrelevant
- */
- bool IsCSSInvertible(nsIAtom& aProperty, const nsAString* aAttribute);
+ /**
+ * Answers true is the property can be removed by setting a "none" CSS value
+ * on a node.
+ *
+ * @param aProperty [IN] An atom containing a CSS property.
+ * @param aAttribute [IN] Pointer to an attribute name or null if this
+ * information is irrelevant.
+ * @return A boolean saying if the property can be remove by
+ * setting a "none" value.
+ */
+ bool IsCSSInvertible(nsIAtom& aProperty, const nsAString* aAttribute);
- /** Get the default browser background color if we need it for GetCSSBackgroundColorState
- *
- * @param aColor [OUT] the default color as it is defined in prefs
- */
- void GetDefaultBackgroundColor(nsAString & aColor);
+ /**
+ * Get the default browser background color if we need it for
+ * GetCSSBackgroundColorState().
+ *
+ * @param aColor [OUT] The default color as it is defined in prefs.
+ */
+ void GetDefaultBackgroundColor(nsAString& aColor);
- /** Get the default length unit used for CSS Indent/Outdent
- *
- * @param aLengthUnit [OUT] the default length unit as it is defined in prefs
- */
- void GetDefaultLengthUnit(nsAString & aLengthUnit);
+ /**
+ * Get the default length unit used for CSS Indent/Outdent.
+ *
+ * @param aLengthUnit [OUT] The default length unit as it is defined in
+ * prefs.
+ */
+ void GetDefaultLengthUnit(nsAString & aLengthUnit);
- /** returns the list of values for the CSS equivalences to
- * the passed HTML style for the passed node
- *
- * @param aNode [IN] a DOM node
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aValueString [OUT] the list of css values
- * @param aStyleType [IN] eSpecified or eComputed
- */
- nsresult GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
- nsIAtom * aHTMLProperty,
- const nsAString * aAttribute,
- nsAString & aValueString,
- StyleType aStyleType);
+ /**
+ * Returns the list of values for the CSS equivalences to
+ * the passed HTML style for the passed node.
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr if
+ * irrelevant.
+ * @param aValueString [OUT] The list of CSS values.
+ * @param aStyleType [IN] eSpecified or eComputed.
+ */
+ nsresult GetCSSEquivalentToHTMLInlineStyleSet(nsINode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ nsAString& aValueString,
+ StyleType aStyleType);
- /** Does the node aNode (or his parent if it is not an element node) carries
- * the CSS equivalent styles to the HTML style for this node ?
- *
- * @param aNode [IN] a DOM node
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aIsSet [OUT] a boolean being true if the css properties are set
- * @param aValueString [IN/OUT] the attribute value (in) the list of css values (out)
- * @param aStyleType [IN] eSpecified or eComputed
- *
- * The nsIContent variant returns aIsSet instead of using an out parameter.
- */
+ /**
+ * Does the node aNode (or his parent if it is not an element node) carries
+ * the CSS equivalent styles to the HTML style for this node ?
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr if
+ * irrelevant.
+ * @param aIsSet [OUT] A boolean being true if the css properties are
+ * set.
+ * @param aValueString [IN/OUT] The attribute value (in) the list of CSS
+ * values (out).
+ * @param aStyleType [IN] eSpecified or eComputed.
+ *
+ * The nsIContent variant returns aIsSet instead of using an out parameter.
+ */
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
nsIAtom* aProperty,
const nsAString* aAttribute,
const nsAString& aValue,
StyleType aStyleType);
bool IsCSSEquivalentToHTMLInlineStyleSet(nsINode* aContent,
nsIAtom* aProperty,
const nsAString* aAttribute,
nsAString& aValue,
StyleType aStyleType);
- nsresult IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode * aNode,
- nsIAtom * aHTMLProperty,
- const nsAString * aAttribute,
- bool & aIsSet,
- nsAString & aValueString,
- StyleType aStyleType);
+ nsresult IsCSSEquivalentToHTMLInlineStyleSet(nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ bool& aIsSet,
+ nsAString& aValueString,
+ StyleType aStyleType);
- /** Adds to the node the CSS inline styles equivalent to the HTML style
- * and return the number of CSS properties set by the call
- *
- * @param aNode [IN] a DOM node
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aValue [IN] the attribute value
- * @param aCount [OUT] the number of CSS properties set by the call
- * @param aSuppressTransaction [IN] a boolean indicating, when true,
- * that no transaction should be recorded
- *
- * aCount is returned by the dom::Element variant instead of being an out
- * parameter.
- */
- int32_t SetCSSEquivalentToHTMLStyle(mozilla::dom::Element* aElement,
- nsIAtom* aProperty,
+ /**
+ * Adds to the node the CSS inline styles equivalent to the HTML style
+ * and return the number of CSS properties set by the call.
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr if
+ * irrelevant.
+ * @param aValue [IN] The attribute value.
+ * @param aCount [OUT] The number of CSS properties set by the call.
+ * @param aSuppressTransaction [IN] A boolean indicating, when true,
+ * that no transaction should be recorded.
+ *
+ * aCount is returned by the dom::Element variant instead of being an out
+ * parameter.
+ */
+ int32_t SetCSSEquivalentToHTMLStyle(dom::Element* aElement,
+ nsIAtom* aProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ bool aSuppressTransaction);
+ nsresult SetCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ int32_t* aCount,
+ bool aSuppressTransaction);
+
+ /**
+ * Removes from the node the CSS inline styles equivalent to the HTML style.
+ *
+ * @param aNode [IN] A DOM node.
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr if
+ * irrelevant.
+ * @param aValue [IN] The attribute value.
+ * @param aSuppressTransaction [IN] A boolean indicating, when true,
+ * that no transaction should be recorded.
+ */
+ nsresult RemoveCSSEquivalentToHTMLStyle(nsIDOMNode* aNode,
+ nsIAtom* aHTMLProperty,
const nsAString* aAttribute,
const nsAString* aValue,
bool aSuppressTransaction);
- nsresult SetCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
- nsIAtom * aHTMLProperty,
- const nsAString * aAttribute,
- const nsAString * aValue,
- int32_t * aCount,
+
+ /**
+ * Removes from the node the CSS inline styles equivalent to the HTML style.
+ *
+ * @param aElement [IN] A DOM Element (must not be null).
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr if
+ * irrelevant.
+ * @param aValue [IN] The attribute value.
+ * @param aSuppressTransaction [IN] A boolean indicating, when true,
+ * that no transaction should be recorded.
+ */
+ nsresult RemoveCSSEquivalentToHTMLStyle(dom::Element* aElement,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
bool aSuppressTransaction);
- /** removes from the node the CSS inline styles equivalent to the HTML style
- *
- * @param aNode [IN] a DOM node
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aValue [IN] the attribute value
- * @param aSuppressTransaction [IN] a boolean indicating, when true,
- * that no transaction should be recorded
- */
- nsresult RemoveCSSEquivalentToHTMLStyle(nsIDOMNode * aNode,
- nsIAtom *aHTMLProperty,
- const nsAString *aAttribute,
- const nsAString *aValue,
- bool aSuppressTransaction);
- /** removes from the node the CSS inline styles equivalent to the HTML style
- *
- * @param aElement [IN] a DOM Element (must not be null)
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aValue [IN] the attribute value
- * @param aSuppressTransaction [IN] a boolean indicating, when true,
- * that no transaction should be recorded
- */
- nsresult RemoveCSSEquivalentToHTMLStyle(mozilla::dom::Element* aElement,
- nsIAtom* aHTMLProperty,
- const nsAString* aAttribute,
- const nsAString* aValue,
- bool aSuppressTransaction);
+ /**
+ * Parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char
+ * we need such a parser because
+ * nsIDOMCSSStyleDeclaration::GetPropertyCSSValue() is not implemented.
+ *
+ * @param aString [IN] Input string to parse.
+ * @param aValue [OUT] Numeric part.
+ * @param aUnit [OUT] Unit part.
+ */
+ void ParseLength(const nsAString& aString, float* aValue, nsIAtom** aUnit);
+
+ /**
+ * Sets the mIsCSSPrefChecked private member; used as callback from observer
+ * when the CSS pref state is changed.
+ *
+ * @param aIsCSSPrefChecked [IN] The new boolean state for the pref.
+ */
+ void SetCSSEnabled(bool aIsCSSPrefChecked);
- /** parses a "xxxx.xxxxxuuu" string where x is a digit and u an alpha char
- * we need such a parser because nsIDOMCSSStyleDeclaration::GetPropertyCSSValue() is not
- * implemented
- *
- * @param aString [IN] input string to parse
- * @param aValue [OUT] numeric part
- * @param aUnit [OUT] unit part
- */
- void ParseLength(const nsAString & aString, float * aValue, nsIAtom ** aUnit);
-
- /** sets the mIsCSSPrefChecked private member ; used as callback from observer when
- * the css pref state is changed
- *
- * @param aIsCSSPrefChecked [IN] the new boolean state for the pref
- */
- void SetCSSEnabled(bool aIsCSSPrefChecked);
+ /**
+ * Retrieves the mIsCSSPrefChecked private member, true if the CSS pref is
+ * checked, false if it is not.
+ *
+ * @return the boolean value of the CSS pref.
+ */
+ bool IsCSSPrefChecked();
- /** retrieves the mIsCSSPrefChecked private member, true if the css pref is checked,
- * false if it is not
- *
- * @return the boolean value of the css pref
- */
- bool IsCSSPrefChecked();
+ /**
+ * ElementsSameStyle compares two elements and checks if they have the same
+ * specified CSS declarations in the STYLE attribute.
+ * The answer is always false if at least one of them carries an ID or a
+ * class.
+ *
+ * @param aFirstNode [IN] A DOM node.
+ * @param aSecondNode [IN] A DOM node.
+ * @return true if the two elements are considered to
+ * have same styles.
+ */
+ bool ElementsSameStyle(dom::Element* aFirstNode,
+ dom::Element* aSecondNode);
+ bool ElementsSameStyle(nsIDOMNode* aFirstNode, nsIDOMNode* aSecondNode);
- /** ElementsSameStyle compares two elements and checks if they have the same
- * specified CSS declarations in the STYLE attribute
- * The answer is always false if at least one of them carries an ID or a class
- *
- * @return true if the two elements are considered to have same styles
- * @param aFirstNode [IN] a DOM node
- * @param aSecondNode [IN] a DOM node
- */
- bool ElementsSameStyle(mozilla::dom::Element* aFirstNode,
- mozilla::dom::Element* aSecondNode);
- bool ElementsSameStyle(nsIDOMNode *aFirstNode, nsIDOMNode *aSecondNode);
-
- /** get the specified inline styles (style attribute) for an element
- *
- * @param aElement [IN] the element node
- * @param aCssDecl [OUT] the CSS declaration corresponding to the style attr
- * @param aLength [OUT] the number of declarations in aCssDecl
- */
- nsresult GetInlineStyles(mozilla::dom::Element* aElement,
+ /**
+ * Get the specified inline styles (style attribute) for an element.
+ *
+ * @param aElement [IN] The element node.
+ * @param aCssDecl [OUT] The CSS declaration corresponding to the
+ * style attribute.
+ * @param aLength [OUT] The number of declarations in aCssDecl.
+ */
+ nsresult GetInlineStyles(dom::Element* aElement,
nsIDOMCSSStyleDeclaration** aCssDecl,
uint32_t* aLength);
nsresult GetInlineStyles(nsIDOMElement* aElement,
nsIDOMCSSStyleDeclaration** aCssDecl,
uint32_t* aLength);
private:
nsresult GetInlineStyles(nsISupports* aElement,
nsIDOMCSSStyleDeclaration** aCssDecl,
uint32_t* aLength);
public:
- /** returns aNode itself if it is an element node, or the first ancestors being an element
- * node if aNode is not one itself
- *
- * @param aNode [IN] a node
- * @param aElement [OUT] the deepest element node containing aNode (possibly aNode itself)
- */
- mozilla::dom::Element* GetElementContainerOrSelf(nsINode* aNode);
+ /**
+ * Returns aNode itself if it is an element node, or the first ancestors
+ * being an element node if aNode is not one itself.
+ *
+ * @param aNode [IN] A node
+ * @param aElement [OUT] The deepest element node containing aNode
+ * (possibly aNode itself)
+ */
+ dom::Element* GetElementContainerOrSelf(nsINode* aNode);
already_AddRefed<nsIDOMElement> GetElementContainerOrSelf(nsIDOMNode* aNode);
/**
* Gets the computed style for a given element. Can return null.
*/
- already_AddRefed<nsComputedDOMStyle>
- GetComputedStyle(mozilla::dom::Element* aElement);
-
+ already_AddRefed<nsComputedDOMStyle> GetComputedStyle(dom::Element* aElement);
private:
-
- /** retrieves the css property atom from an enum
- *
- * @param aProperty [IN] the enum value for the property
- * @param aAtom [OUT] the corresponding atom
- */
- void GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom ** aAtom);
+ /**
+ * Retrieves the CSS property atom from an enum.
+ *
+ * @param aProperty [IN] The enum value for the property.
+ * @param aAtom [OUT] The corresponding atom.
+ */
+ void GetCSSPropertyAtom(nsCSSEditableProperty aProperty, nsIAtom** aAtom);
- /** retrieves the CSS declarations equivalent to a HTML style value for
- * a given equivalence table
- *
- * @param aPropertyArray [OUT] the array of css properties
- * @param aValueArray [OUT] the array of values for the css properties above
- * @param aEquivTable [IN] the equivalence table
- * @param aValue [IN] the HTML style value
- * @param aGetOrRemoveRequest [IN] a boolean value being true if the call to the current method
- * is made for GetCSSEquivalentToHTMLInlineStyleSet or
- * RemoveCSSEquivalentToHTMLInlineStyleSet
- */
-
- void BuildCSSDeclarations(nsTArray<nsIAtom*> & aPropertyArray,
- nsTArray<nsString> & cssValueArray,
- const CSSEquivTable * aEquivTable,
- const nsAString * aValue,
- bool aGetOrRemoveRequest);
+ /**
+ * Retrieves the CSS declarations equivalent to a HTML style value for
+ * a given equivalence table.
+ *
+ * @param aPropertyArray [OUT] The array of css properties.
+ * @param aValueArray [OUT] The array of values for the CSS properties
+ * above.
+ * @param aEquivTable [IN] The equivalence table.
+ * @param aValue [IN] The HTML style value.
+ * @param aGetOrRemoveRequest [IN] A boolean value being true if the call to
+ * the current method is made for
+ * GetCSSEquivalentToHTMLInlineStyleSet() or
+ * RemoveCSSEquivalentToHTMLInlineStyleSet().
+ */
+ void BuildCSSDeclarations(nsTArray<nsIAtom*>& aPropertyArray,
+ nsTArray<nsString>& cssValueArray,
+ const CSSEquivTable* aEquivTable,
+ const nsAString* aValue,
+ bool aGetOrRemoveRequest);
- /** retrieves the CSS declarations equivalent to the given HTML property/attribute/value
- * for a given node
- *
- * @param aNode [IN] the DOM node
- * @param aHTMLProperty [IN] an atom containing an HTML property
- * @param aAttribute [IN] a pointer to an attribute name or nullptr if irrelevant
- * @param aValue [IN] the attribute value
- * @param aPropertyArray [OUT] the array of css properties
- * @param aValueArray [OUT] the array of values for the css properties above
- * @param aGetOrRemoveRequest [IN] a boolean value being true if the call to the current method
- * is made for GetCSSEquivalentToHTMLInlineStyleSet or
- * RemoveCSSEquivalentToHTMLInlineStyleSet
- */
- void GenerateCSSDeclarationsFromHTMLStyle(mozilla::dom::Element* aNode,
- nsIAtom* aHTMLProperty,
- const nsAString* aAttribute,
- const nsAString* aValue,
- nsTArray<nsIAtom*>& aPropertyArray,
- nsTArray<nsString>& aValueArray,
- bool aGetOrRemoveRequest);
+ /**
+ * Retrieves the CSS declarations equivalent to the given HTML
+ * property/attribute/value for a given node.
+ *
+ * @param aNode [IN] The DOM node.
+ * @param aHTMLProperty [IN] An atom containing an HTML property.
+ * @param aAttribute [IN] A pointer to an attribute name or nullptr
+ * if irrelevant
+ * @param aValue [IN] The attribute value.
+ * @param aPropertyArray [OUT] The array of CSS properties.
+ * @param aValueArray [OUT] The array of values for the CSS properties
+ * above.
+ * @param aGetOrRemoveRequest [IN] A boolean value being true if the call to
+ * the current method is made for
+ * GetCSSEquivalentToHTMLInlineStyleSet() or
+ * RemoveCSSEquivalentToHTMLInlineStyleSet().
+ */
+ void GenerateCSSDeclarationsFromHTMLStyle(dom::Element* aNode,
+ nsIAtom* aHTMLProperty,
+ const nsAString* aAttribute,
+ const nsAString* aValue,
+ nsTArray<nsIAtom*>& aPropertyArray,
+ nsTArray<nsString>& aValueArray,
+ bool aGetOrRemoveRequest);
- /** Creates a Transaction for setting or removing a CSS property. Never
- * returns null.
- *
- * @param aElement [IN] a DOM element
- * @param aProperty [IN] a CSS property
- * @param aValue [IN] the value to set for this CSS property
- * @param aChangeType [IN] eSet to set, eRemove to remove
- */
- already_AddRefed<mozilla::ChangeStyleTransaction>
- CreateCSSPropertyTxn(mozilla::dom::Element& aElement,
- nsIAtom& aProperty, const nsAString& aValue,
- mozilla::ChangeStyleTransaction::EChangeType aChangeType);
+ /**
+ * Creates a Transaction for setting or removing a CSS property. Never
+ * returns null.
+ *
+ * @param aElement [IN] A DOM element.
+ * @param aProperty [IN] A CSS property.
+ * @param aValue [IN] The value to set for this CSS property.
+ * @param aChangeType [IN] eSet to set, eRemove to remove.
+ */
+ already_AddRefed<ChangeStyleTransaction>
+ CreateCSSPropertyTxn(dom::Element& aElement,
+ nsIAtom& aProperty, const nsAString& aValue,
+ ChangeStyleTransaction::EChangeType aChangeType);
- /** back-end for GetSpecifiedProperty and GetComputedProperty
+ /**
+ * Back-end for GetSpecifiedProperty and GetComputedProperty.
*
- * @param aNode [IN] a DOM node
- * @param aProperty [IN] a CSS property
- * @param aValue [OUT] the retrieved value for this property
- * @param aStyleType [IN] eSpecified or eComputed
+ * @param aNode [IN] A DOM node.
+ * @param aProperty [IN] A CSS property.
+ * @param aValue [OUT] The retrieved value for this property.
+ * @param aStyleType [IN] eSpecified or eComputed.
*/
nsresult GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
nsAString& aValue, StyleType aStyleType);
-
private:
- nsHTMLEditor *mHTMLEditor;
- bool mIsCSSPrefChecked;
+ nsHTMLEditor* mHTMLEditor;
+ bool mIsCSSPrefChecked;
};
#define NS_EDITOR_INDENT_INCREMENT_IN 0.4134f
#define NS_EDITOR_INDENT_INCREMENT_CM 1.05f
#define NS_EDITOR_INDENT_INCREMENT_MM 10.5f
#define NS_EDITOR_INDENT_INCREMENT_PT 29.76f
#define NS_EDITOR_INDENT_INCREMENT_PC 2.48f
#define NS_EDITOR_INDENT_INCREMENT_EM 3
#define NS_EDITOR_INDENT_INCREMENT_EX 6
#define NS_EDITOR_INDENT_INCREMENT_PX 40
#define NS_EDITOR_INDENT_INCREMENT_PERCENT 4
-#endif /* nsHTMLCSSUtils_h__ */
+} // namespace mozilla
+
+#endif // #ifndef CSSEditUtils_h
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -17,16 +17,17 @@ EXPORTS.mozilla += [
'EditorController.h',
]
UNIFIED_SOURCES += [
'ChangeAttributeTransaction.cpp',
'ChangeStyleTransaction.cpp',
'CompositionTransaction.cpp',
'CreateElementTransaction.cpp',
+ 'CSSEditUtils.cpp',
'DeleteNodeTransaction.cpp',
'DeleteRangeTransaction.cpp',
'DeleteTextTransaction.cpp',
'EditAggregateTransaction.cpp',
'EditorCommands.cpp',
'EditorController.cpp',
'EditorUtils.cpp',
'EditTransactionBase.cpp',
@@ -34,17 +35,16 @@ UNIFIED_SOURCES += [
'InsertNodeTransaction.cpp',
'InsertTextTransaction.cpp',
'InternetCiter.cpp',
'JoinNodeTransaction.cpp',
'nsEditor.cpp',
'nsEditorEventListener.cpp',
'nsHTMLAbsPosition.cpp',
'nsHTMLAnonymousUtils.cpp',
- 'nsHTMLCSSUtils.cpp',
'nsHTMLDataTransfer.cpp',
'nsHTMLEditor.cpp',
'nsHTMLEditorEventListener.cpp',
'nsHTMLEditorStyle.cpp',
'nsHTMLEditRules.cpp',
'nsHTMLInlineTableEditor.cpp',
'nsHTMLObjectResizer.cpp',
'nsHTMLURIRefObject.cpp',
--- a/editor/libeditor/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/nsHTMLAbsPosition.cpp
@@ -15,17 +15,16 @@
#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsComputedDOMStyle.h"
#include "nsDebug.h"
#include "nsEditRules.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLCSSUtils.h"
#include "nsHTMLEditRules.h"
#include "nsHTMLEditor.h"
#include "nsHTMLObjectResizer.h"
#include "nsIContent.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
@@ -83,17 +82,17 @@ NS_IMETHODIMP
nsHTMLEditor::GetAbsolutelyPositionedSelectionContainer(nsIDOMElement **_retval)
{
nsAutoString positionStr;
nsCOMPtr<nsINode> node = GetSelectionContainer();
nsCOMPtr<nsIDOMNode> resultNode;
while (!resultNode && node && !node->IsHTMLElement(nsGkAtoms::html)) {
nsresult res =
- mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
+ mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
NS_ENSURE_SUCCESS(res, res);
if (positionStr.EqualsLiteral("absolute"))
resultNode = GetAsDOMNode(node);
else {
node = node->GetParentNode();
}
}
@@ -149,17 +148,17 @@ NS_IMETHODIMP
nsHTMLEditor::SetElementZIndex(nsIDOMElement* aElement, int32_t aZindex)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_ARG_POINTER(element);
nsAutoString zIndexStr;
zIndexStr.AppendInt(aZindex);
- mHTMLCSSUtils->SetCSSProperty(*element, *nsGkAtoms::z_index, zIndexStr);
+ mCSSEditUtils->SetCSSProperty(*element, *nsGkAtoms::z_index, zIndexStr);
return NS_OK;
}
NS_IMETHODIMP
nsHTMLEditor::RelativeChangeZIndex(int32_t aChange)
{
AutoEditBatch beginBatching(this);
AutoRules beginRulesSniffing(this,
@@ -187,37 +186,37 @@ NS_IMETHODIMP
nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement,
int32_t * aZindex)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_STATE(element || !aElement);
nsAutoString zIndexStr;
*aZindex = 0;
- nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(*element,
+ nsresult res = mCSSEditUtils->GetSpecifiedProperty(*element,
*nsGkAtoms::z_index,
zIndexStr);
NS_ENSURE_SUCCESS(res, res);
if (zIndexStr.EqualsLiteral("auto")) {
// we have to look at the positioned ancestors
// cf. CSS 2 spec section 9.9.1
nsCOMPtr<nsIDOMNode> parentNode;
res = aElement->GetParentNode(getter_AddRefs(parentNode));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsINode> node = do_QueryInterface(parentNode);
nsAutoString positionStr;
while (node && zIndexStr.EqualsLiteral("auto") &&
!node->IsHTMLElement(nsGkAtoms::body)) {
- res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::position,
+ res = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::position,
positionStr);
NS_ENSURE_SUCCESS(res, res);
if (positionStr.EqualsLiteral("absolute")) {
// ah, we found one, what's its z-index ? If its z-index is auto,
// we have to continue climbing the document's tree
- res = mHTMLCSSUtils->GetComputedProperty(*node, *nsGkAtoms::z_index,
+ res = mCSSEditUtils->GetComputedProperty(*node, *nsGkAtoms::z_index,
zIndexStr);
NS_ENSURE_SUCCESS(res, res);
}
node = node->GetParentNode();
}
}
if (!zIndexStr.EqualsLiteral("auto")) {
@@ -341,19 +340,19 @@ nsHTMLEditor::StartMoving(nsIDOMElement
mAbsolutelyPositionedObject,
mPositionedObjectX, mPositionedObjectY);
NS_ENSURE_SUCCESS(res,res);
// make the shadow appear
mPositioningShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
// position it
- mHTMLCSSUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::width,
mPositionedObjectWidth);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::height,
mPositionedObjectHeight);
mIsMoving = true;
return res;
}
void
nsHTMLEditor::SnapToGrid(int32_t & newX, int32_t & newY)
@@ -441,19 +440,19 @@ nsHTMLEditor::SetFinalPosition(int32_t a
y.AppendInt(newY);
// we want one transaction only from a user's point of view
AutoEditBatch batchIt(this);
nsCOMPtr<Element> absolutelyPositionedObject =
do_QueryInterface(mAbsolutelyPositionedObject);
NS_ENSURE_STATE(absolutelyPositionedObject);
- mHTMLCSSUtils->SetCSSPropertyPixels(*absolutelyPositionedObject,
+ mCSSEditUtils->SetCSSPropertyPixels(*absolutelyPositionedObject,
*nsGkAtoms::top, newY);
- mHTMLCSSUtils->SetCSSPropertyPixels(*absolutelyPositionedObject,
+ mCSSEditUtils->SetCSSPropertyPixels(*absolutelyPositionedObject,
*nsGkAtoms::left, newX);
// keep track of that size
mPositionedObjectX = newX;
mPositionedObjectY = newY;
return RefreshResizers();
}
@@ -471,31 +470,31 @@ nsHTMLEditor::AddPositioningOffset(int32
NS_IMETHODIMP
nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement* aElement,
bool aEnabled)
{
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_ARG_POINTER(element);
nsAutoString positionStr;
- mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::position,
+ mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::position,
positionStr);
bool isPositioned = (positionStr.EqualsLiteral("absolute"));
// nothing to do if the element is already in the state we want
if (isPositioned == aEnabled)
return NS_OK;
AutoEditBatch batchIt(this);
if (aEnabled) {
int32_t x, y;
GetElementOrigin(aElement, x, y);
- mHTMLCSSUtils->SetCSSProperty(*element, *nsGkAtoms::position,
+ mCSSEditUtils->SetCSSProperty(*element, *nsGkAtoms::position,
NS_LITERAL_STRING("absolute"));
AddPositioningOffset(x, y);
SnapToGrid(x, y);
SetElementPosition(*element, x, y);
// we may need to create a br if the positioned element is alone in its
// container
@@ -505,29 +504,29 @@ nsHTMLEditor::AbsolutelyPositionElement(
nsINode* parentNode = element->GetParentNode();
if (parentNode->GetChildCount() == 1) {
nsCOMPtr<nsIDOMNode> brNode;
nsresult res = CreateBR(parentNode->AsDOMNode(), 0, address_of(brNode));
NS_ENSURE_SUCCESS(res, res);
}
}
else {
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::position,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::position,
EmptyString());
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::top,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::top,
EmptyString());
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::left,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::left,
EmptyString());
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::z_index,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::z_index,
EmptyString());
if (!HTMLEditUtils::IsImage(aElement)) {
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::width,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::width,
EmptyString());
- mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::height,
+ mCSSEditUtils->RemoveCSSProperty(*element, *nsGkAtoms::height,
EmptyString());
}
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
if (element && element->IsHTMLElement(nsGkAtoms::div) &&
!HasStyleOrIdOrClass(element)) {
RefPtr<nsHTMLEditRules> htmlRules = static_cast<nsHTMLEditRules*>(mRules.get());
NS_ENSURE_TRUE(htmlRules, NS_ERROR_FAILURE);
@@ -578,18 +577,18 @@ nsHTMLEditor::SetElementPosition(nsIDOME
SetElementPosition(*element, aX, aY);
return NS_OK;
}
void
nsHTMLEditor::SetElementPosition(dom::Element& aElement, int32_t aX, int32_t aY)
{
AutoEditBatch batchIt(this);
- mHTMLCSSUtils->SetCSSPropertyPixels(aElement, *nsGkAtoms::left, aX);
- mHTMLCSSUtils->SetCSSPropertyPixels(aElement, *nsGkAtoms::top, aY);
+ mCSSEditUtils->SetCSSPropertyPixels(aElement, *nsGkAtoms::left, aX);
+ mCSSEditUtils->SetCSSPropertyPixels(aElement, *nsGkAtoms::top, aY);
}
// self-explanatory
NS_IMETHODIMP
nsHTMLEditor::GetPositionedElement(nsIDOMElement ** aReturn)
{
nsCOMPtr<nsIDOMElement> ret =
static_cast<nsIDOMElement*>(GetAsDOMNode(mAbsolutelyPositionedObject));
@@ -613,28 +612,28 @@ nsHTMLEditor::CheckPositionedElementBGan
// Otherwise don't change background/foreground
nsCOMPtr<Element> element = do_QueryInterface(aElement);
NS_ENSURE_STATE(element || !aElement);
aReturn.Truncate();
nsAutoString bgImageStr;
nsresult res =
- mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::background_image,
+ mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::background_image,
bgImageStr);
NS_ENSURE_SUCCESS(res, res);
if (bgImageStr.EqualsLiteral("none")) {
nsAutoString bgColorStr;
res =
- mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::backgroundColor,
+ mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::backgroundColor,
bgColorStr);
NS_ENSURE_SUCCESS(res, res);
if (bgColorStr.EqualsLiteral("transparent")) {
RefPtr<nsComputedDOMStyle> cssDecl =
- mHTMLCSSUtils->GetComputedStyle(element);
+ mCSSEditUtils->GetComputedStyle(element);
NS_ENSURE_STATE(cssDecl);
// from these declarations, get the one we want and that one only
ErrorResult error;
RefPtr<dom::CSSValue> cssVal = cssDecl->GetPropertyCSSValue(NS_LITERAL_STRING("color"), error);
NS_ENSURE_TRUE(!error.Failed(), error.StealNSResult());
nsROCSSPrimitiveValue* val = cssVal->AsPrimitiveValue();
--- a/editor/libeditor/nsHTMLAnonymousUtils.cpp
+++ b/editor/libeditor/nsHTMLAnonymousUtils.cpp
@@ -6,17 +6,16 @@
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsComputedDOMStyle.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLCSSUtils.h"
#include "nsHTMLEditor.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsID.h"
#include "nsIDOMCSSPrimitiveValue.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSSValue.h"
#include "nsIDOMElement.h"
@@ -419,28 +418,28 @@ nsHTMLEditor::GetPositionAndDimensions(n
// Is the element positioned ? let's check the cheap way first...
bool isPositioned = false;
nsresult res = aElement->HasAttribute(NS_LITERAL_STRING("_moz_abspos"), &isPositioned);
NS_ENSURE_SUCCESS(res, res);
if (!isPositioned) {
// hmmm... the expensive way now...
nsAutoString positionStr;
- mHTMLCSSUtils->GetComputedProperty(*element, *nsGkAtoms::position,
+ mCSSEditUtils->GetComputedProperty(*element, *nsGkAtoms::position,
positionStr);
isPositioned = positionStr.EqualsLiteral("absolute");
}
if (isPositioned) {
// Yes, it is absolutely positioned
mResizedObjectIsAbsolutelyPositioned = true;
// Get the all the computed css styles attached to the element node
RefPtr<nsComputedDOMStyle> cssDecl =
- mHTMLCSSUtils->GetComputedStyle(element);
+ mCSSEditUtils->GetComputedStyle(element);
NS_ENSURE_STATE(cssDecl);
aBorderLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-left-width"));
aBorderTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("border-top-width"));
aMarginLeft = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-left"));
aMarginTop = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("margin-top"));
aX = GetCSSFloatValue(cssDecl, NS_LITERAL_STRING("left")) +
@@ -469,11 +468,11 @@ nsHTMLEditor::GetPositionAndDimensions(n
}
return res;
}
// self-explanatory
void
nsHTMLEditor::SetAnonymousElementPosition(int32_t aX, int32_t aY, nsIDOMElement *aElement)
{
- mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("left"), aX);
- mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("top"), aY);
+ mCSSEditUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("left"), aX);
+ mCSSEditUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("top"), aY);
}
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -3,16 +3,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsHTMLEditRules.h"
#include <stdlib.h>
+#include "CSSEditUtils.h"
#include "EditorUtils.h"
#include "HTMLEditUtils.h"
#include "TextEditUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/MathAlgorithms.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
@@ -24,17 +25,16 @@
#include "nsCRT.h"
#include "nsCRTGlue.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLCSSUtils.h"
#include "nsHTMLEditor.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsID.h"
#include "nsIDOMCharacterData.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
@@ -862,23 +862,23 @@ nsHTMLEditRules::GetAlignment(bool* aMix
NS_ENSURE_TRUE(nodeToExamine, NS_ERROR_NULL_POINTER);
NS_NAMED_LITERAL_STRING(typeAttrName, "align");
nsCOMPtr<Element> blockParent = mHTMLEditor->GetBlock(*nodeToExamine);
NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
if (mHTMLEditor->IsCSSEnabled() &&
- mHTMLEditor->mHTMLCSSUtils->IsCSSEditableProperty(blockParent, nullptr,
+ mHTMLEditor->mCSSEditUtils->IsCSSEditableProperty(blockParent, nullptr,
&typeAttrName)) {
// We are in CSS mode and we know how to align this element with CSS
nsAutoString value;
// Let's get the value(s) of text-align or margin-left/margin-right
- mHTMLEditor->mHTMLCSSUtils->GetCSSEquivalentToHTMLInlineStyleSet(
- blockParent, nullptr, &typeAttrName, value, nsHTMLCSSUtils::eComputed);
+ mHTMLEditor->mCSSEditUtils->GetCSSEquivalentToHTMLInlineStyleSet(
+ blockParent, nullptr, &typeAttrName, value, CSSEditUtils::eComputed);
if (value.EqualsLiteral("center") ||
value.EqualsLiteral("-moz-center") ||
value.EqualsLiteral("auto auto")) {
*aAlign = nsIHTMLEditor::eCenter;
return NS_OK;
}
if (value.EqualsLiteral("right") ||
value.EqualsLiteral("-moz-right") ||
@@ -923,17 +923,17 @@ nsHTMLEditRules::GetAlignment(bool* aMix
return NS_OK;
}
}
isFirstNodeToExamine = false;
}
return NS_OK;
}
-static nsIAtom& MarginPropertyAtomForIndent(nsHTMLCSSUtils& aHTMLCSSUtils,
+static nsIAtom& MarginPropertyAtomForIndent(CSSEditUtils& aHTMLCSSUtils,
nsINode& aNode)
{
nsAutoString direction;
aHTMLCSSUtils.GetComputedProperty(aNode, *nsGkAtoms::direction, direction);
return direction.EqualsLiteral("rtl") ?
*nsGkAtoms::marginRight : *nsGkAtoms::marginLeft;
}
@@ -963,27 +963,27 @@ nsHTMLEditRules::GetIndentState(bool *aC
if (HTMLEditUtils::IsNodeThatCanOutdent(GetAsDOMNode(curNode))) {
*aCanOutdent = true;
break;
}
else if (useCSS) {
// we are in CSS mode, indentation is done using the margin-left (or margin-right) property
NS_ENSURE_STATE(mHTMLEditor);
nsIAtom& marginProperty =
- MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
+ MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, curNode);
nsAutoString value;
// retrieve its specified value
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*curNode,
+ mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(*curNode,
marginProperty, value);
float f;
nsCOMPtr<nsIAtom> unit;
// get its number part and its unit
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
+ mHTMLEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
// if the number part is strictly positive, outdent is possible
if (0 < f) {
*aCanOutdent = true;
break;
}
}
}
@@ -3983,25 +3983,26 @@ nsHTMLEditRules::WillOutdent(Selection&
}
res = mHTMLEditor->RemoveBlockContainer(curNode);
NS_ENSURE_SUCCESS(res, res);
continue;
}
// Is it a block with a 'margin' property?
if (useCSS && IsBlockNode(curNode)) {
nsIAtom& marginProperty =
- MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
+ MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, curNode);
nsAutoString value;
- mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(curNode,
+ mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(curNode,
marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
+ mHTMLEditor->mCSSEditUtils->ParseLength(value, &f,
+ getter_AddRefs(unit));
if (f > 0) {
ChangeIndentation(*curNode->AsElement(), Change::minus);
continue;
}
}
// Is it a list item?
if (HTMLEditUtils::IsListItem(curNode)) {
// If it is a list item, that means we are not outdenting whole list.
@@ -4064,23 +4065,23 @@ nsHTMLEditRules::WillOutdent(Selection&
if (n->IsHTMLElement(nsGkAtoms::blockquote)) {
// If so, remember it and the first node we are taking out of it.
curBlockQuote = n->AsElement();
firstBQChild = curNode;
lastBQChild = curNode;
break;
} else if (useCSS) {
nsIAtom& marginProperty =
- MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
+ MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, curNode);
nsAutoString value;
- mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*n, marginProperty,
+ mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(*n, marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
- mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
+ mHTMLEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
if (f > 0 && !(HTMLEditUtils::IsList(curParent) &&
HTMLEditUtils::IsList(curNode))) {
curBlockQuote = n->AsElement();
firstBQChild = curNode;
lastBQChild = curNode;
curBlockQuoteIsIndentedWithCSS = true;
break;
}
@@ -4618,17 +4619,17 @@ nsHTMLEditRules::WillAlign(Selection& aS
// If it's a list item, or a list inside a list, forget any "current" div,
// and instead put divs inside the appropriate block (td, li, etc)
if (HTMLEditUtils::IsListItem(curNode) ||
HTMLEditUtils::IsList(curNode)) {
rv = RemoveAlignment(GetAsDOMNode(curNode), aAlignType, true);
NS_ENSURE_SUCCESS(rv, rv);
if (useCSS) {
- mHTMLEditor->mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(
+ mHTMLEditor->mCSSEditUtils->SetCSSEquivalentToHTMLStyle(
curNode->AsElement(), nullptr, &NS_LITERAL_STRING("align"),
&aAlignType, false);
curDiv = nullptr;
continue;
} else if (HTMLEditUtils::IsList(curParent)) {
// If we don't use CSS, add a contraint to list element: they have to
// be inside another list, i.e., >= second level of nesting
rv = AlignInnerBlocks(*curNode, &aAlignType);
@@ -6943,17 +6944,17 @@ nsHTMLEditRules::JoinNodesSmart(nsIConte
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
NS_ENSURE_SUCCESS(res, EditorDOMPoint());
if (lastLeft && firstRight && mHTMLEditor &&
mHTMLEditor->AreNodesSameType(lastLeft, firstRight) &&
(lastLeft->GetAsText() || !mHTMLEditor ||
(lastLeft->IsElement() && firstRight->IsElement() &&
- mHTMLEditor->mHTMLCSSUtils->ElementsSameStyle(lastLeft->AsElement(),
+ mHTMLEditor->mCSSEditUtils->ElementsSameStyle(lastLeft->AsElement(),
firstRight->AsElement())))) {
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
return JoinNodesSmart(*lastLeft, *firstRight);
}
return ret;
}
@@ -6994,19 +6995,19 @@ nsHTMLEditRules::CacheInlineStyles(nsIDO
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->IsTextPropertySetByContent(aNode, mCachedStyles[j].tag,
&(mCachedStyles[j].attr), nullptr,
isSet, &outValue);
}
else
{
NS_ENSURE_STATE(mHTMLEditor);
- mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode,
+ mHTMLEditor->mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(aNode,
mCachedStyles[j].tag, &(mCachedStyles[j].attr), isSet, outValue,
- nsHTMLCSSUtils::eComputed);
+ CSSEditUtils::eComputed);
}
if (isSet)
{
mCachedStyles[j].mPresent = true;
mCachedStyles[j].value.Assign(outValue);
}
}
return NS_OK;
@@ -7048,19 +7049,19 @@ nsHTMLEditRules::ReapplyCachedStyles()
if (mCachedStyles[i].mPresent) {
bool bFirst, bAny, bAll;
bFirst = bAny = bAll = false;
nsAutoString curValue;
if (useCSS) {
// check computed style first in css case
NS_ENSURE_STATE(mHTMLEditor);
- bAny = mHTMLEditor->mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
+ bAny = mHTMLEditor->mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
selNode, mCachedStyles[i].tag, &(mCachedStyles[i].attr), curValue,
- nsHTMLCSSUtils::eComputed);
+ CSSEditUtils::eComputed);
}
if (!bAny) {
// then check typeinstate and html style
NS_ENSURE_STATE(mHTMLEditor);
nsresult res = mHTMLEditor->GetInlinePropertyBase(
*mCachedStyles[i].tag,
&(mCachedStyles[i].attr),
&(mCachedStyles[i].value),
@@ -8253,17 +8254,17 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMN
if (useCSS)
{
if (HTMLEditUtils::IsTable(child) || HTMLEditUtils::IsHR(child)) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->SetAttributeOrEquivalent(curElem, NS_LITERAL_STRING("align"), aAlignType, false);
} else {
nsAutoString dummyCssValue;
NS_ENSURE_STATE(mHTMLEditor);
- res = mHTMLEditor->mHTMLCSSUtils->RemoveCSSInlineStyle(child,
+ res = mHTMLEditor->mCSSEditUtils->RemoveCSSInlineStyle(child,
nsGkAtoms::textAlign, dummyCssValue);
}
NS_ENSURE_SUCCESS(res, res);
}
if (!HTMLEditUtils::IsTable(child)) {
// unless this is a table, look at children
res = RemoveAlignment(child, aAlignType, true);
NS_ENSURE_SUCCESS(res, res);
@@ -8394,26 +8395,26 @@ nsHTMLEditRules::AlignBlock(Element& aEl
nsresult
nsHTMLEditRules::ChangeIndentation(Element& aElement, Change aChange)
{
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
nsIAtom& marginProperty =
- MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, aElement);
+ MarginPropertyAtomForIndent(*mHTMLEditor->mCSSEditUtils, aElement);
nsAutoString value;
- mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(aElement, marginProperty,
+ mHTMLEditor->mCSSEditUtils->GetSpecifiedProperty(aElement, marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
- mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
+ mHTMLEditor->mCSSEditUtils->ParseLength(value, &f, getter_AddRefs(unit));
if (0 == f) {
nsAutoString defaultLengthUnit;
- mHTMLEditor->mHTMLCSSUtils->GetDefaultLengthUnit(defaultLengthUnit);
+ mHTMLEditor->mCSSEditUtils->GetDefaultLengthUnit(defaultLengthUnit);
unit = NS_Atomize(defaultLengthUnit);
}
int8_t multiplier = aChange == Change::plus ? +1 : -1;
if (nsGkAtoms::in == unit) {
f += NS_EDITOR_INDENT_INCREMENT_IN * multiplier;
} else if (nsGkAtoms::cm == unit) {
f += NS_EDITOR_INDENT_INCREMENT_CM * multiplier;
} else if (nsGkAtoms::mm == unit) {
@@ -8431,22 +8432,22 @@ nsHTMLEditRules::ChangeIndentation(Eleme
} else if (nsGkAtoms::percentage == unit) {
f += NS_EDITOR_INDENT_INCREMENT_PERCENT * multiplier;
}
if (0 < f) {
nsAutoString newValue;
newValue.AppendFloat(f);
newValue.Append(nsDependentAtomString(unit));
- mHTMLEditor->mHTMLCSSUtils->SetCSSProperty(aElement, marginProperty,
+ mHTMLEditor->mCSSEditUtils->SetCSSProperty(aElement, marginProperty,
newValue);
return NS_OK;
}
- mHTMLEditor->mHTMLCSSUtils->RemoveCSSProperty(aElement, marginProperty,
+ mHTMLEditor->mCSSEditUtils->RemoveCSSProperty(aElement, marginProperty,
value);
// Remove unnecessary divs
if (!aElement.IsHTMLElement(nsGkAtoms::div) ||
&aElement == mHTMLEditor->GetActiveEditingHost() ||
!mHTMLEditor->IsDescendantOfEditorRoot(&aElement) ||
nsHTMLEditor::HasAttributes(&aElement)) {
return NS_OK;
--- a/editor/libeditor/nsHTMLEditor.cpp
+++ b/editor/libeditor/nsHTMLEditor.cpp
@@ -279,17 +279,17 @@ nsHTMLEditor::Init(nsIDOMDocument *aDoc,
// disable Composer-only features
if (IsMailEditor())
{
SetAbsolutePositioningEnabled(false);
SetSnapToGridEnabled(false);
}
// Init the HTML-CSS utils
- mHTMLCSSUtils = new nsHTMLCSSUtils(this);
+ mCSSEditUtils = new CSSEditUtils(this);
// disable links
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
NS_ENSURE_TRUE(presShell, NS_ERROR_FAILURE);
nsPresContext *context = presShell->GetPresContext();
NS_ENSURE_TRUE(context, NS_ERROR_NULL_POINTER);
if (!IsPlaintextEditor() && !IsInteractionAllowed()) {
mLinkHandler = context->GetLinkHandler();
@@ -1782,28 +1782,28 @@ nsHTMLEditor::GetCSSBackgroundColorState
// we are querying the block background (and not the text background), let's
// climb to the block container
nsCOMPtr<Element> blockParent = GetBlock(*nodeToExamine);
NS_ENSURE_TRUE(blockParent, NS_OK);
// Make sure to not walk off onto the Document node
do {
// retrieve the computed style of background-color for blockParent
- mHTMLCSSUtils->GetComputedProperty(*blockParent,
+ mCSSEditUtils->GetComputedProperty(*blockParent,
*nsGkAtoms::backgroundColor,
aOutColor);
blockParent = blockParent->GetParentElement();
// look at parent if the queried color is transparent and if the node to
// examine is not the root of the document
} while (aOutColor.EqualsLiteral("transparent") && blockParent);
if (aOutColor.EqualsLiteral("transparent")) {
// we have hit the root of the document and the color is still transparent !
// Grumble... Let's look at the default background color because that's the
// color we are looking for
- mHTMLCSSUtils->GetDefaultBackgroundColor(aOutColor);
+ mCSSEditUtils->GetDefaultBackgroundColor(aOutColor);
}
}
else {
// no, we are querying the text background for the Text Highlight button
if (IsTextNode(nodeToExamine)) {
// if the node of interest is a text node, let's climb a level
nodeToExamine = nodeToExamine->GetParentNode();
}
@@ -1812,17 +1812,17 @@ nsHTMLEditor::GetCSSBackgroundColorState
if (NodeIsBlockStatic(nodeToExamine)) {
// yes it is a block; in that case, the text background color is transparent
aOutColor.AssignLiteral("transparent");
break;
}
else {
// no, it's not; let's retrieve the computed style of background-color for the
// node to examine
- mHTMLCSSUtils->GetComputedProperty(*nodeToExamine,
+ mCSSEditUtils->GetComputedProperty(*nodeToExamine,
*nsGkAtoms::backgroundColor,
aOutColor);
if (!aOutColor.EqualsLiteral("transparent")) {
break;
}
}
nodeToExamine = nodeToExamine->GetParentNode();
} while ( aOutColor.EqualsLiteral("transparent") && nodeToExamine );
@@ -4401,19 +4401,21 @@ nsresult
nsHTMLEditor::SetAttributeOrEquivalent(nsIDOMElement * aElement,
const nsAString & aAttribute,
const nsAString & aValue,
bool aSuppressTransaction)
{
nsAutoScriptBlocker scriptBlocker;
nsresult res = NS_OK;
- if (IsCSSEnabled() && mHTMLCSSUtils) {
+ if (IsCSSEnabled() && mCSSEditUtils) {
int32_t count;
- res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(aElement, nullptr, &aAttribute, &aValue, &count,
+ res = mCSSEditUtils->SetCSSEquivalentToHTMLStyle(aElement, nullptr,
+ &aAttribute, &aValue,
+ &count,
aSuppressTransaction);
NS_ENSURE_SUCCESS(res, res);
if (count) {
// we found an equivalence ; let's remove the HTML attribute itself if it is set
nsAutoString existingValue;
bool wasSet = false;
res = GetAttributeValue(aElement, aAttribute, existingValue, &wasSet);
NS_ENSURE_SUCCESS(res, res);
@@ -4469,18 +4471,18 @@ nsHTMLEditor::RemoveAttributeOrEquivalen
{
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
NS_ENSURE_TRUE(element, NS_OK);
nsCOMPtr<nsIAtom> attribute = NS_Atomize(aAttribute);
MOZ_ASSERT(attribute);
nsresult res = NS_OK;
- if (IsCSSEnabled() && mHTMLCSSUtils) {
- res = mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(
+ if (IsCSSEnabled() && mCSSEditUtils) {
+ res = mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(
element, nullptr, &aAttribute, nullptr, aSuppressTransaction);
NS_ENSURE_SUCCESS(res, res);
}
if (element->HasAttr(kNameSpaceID_None, attribute)) {
if (aSuppressTransaction) {
res = element->UnsetAttr(kNameSpaceID_None, attribute,
/* aNotify = */ true);
@@ -4489,21 +4491,21 @@ nsHTMLEditor::RemoveAttributeOrEquivalen
}
}
return res;
}
nsresult
nsHTMLEditor::SetIsCSSEnabled(bool aIsCSSPrefChecked)
{
- if (!mHTMLCSSUtils) {
+ if (!mCSSEditUtils) {
return NS_ERROR_NOT_INITIALIZED;
}
- mHTMLCSSUtils->SetCSSEnabled(aIsCSSPrefChecked);
+ mCSSEditUtils->SetCSSEnabled(aIsCSSPrefChecked);
// Disable the eEditorNoCSSMask flag if we're enabling StyleWithCSS.
uint32_t flags = mFlags;
if (aIsCSSPrefChecked) {
// Turn off NoCSS as we're enabling CSS
flags &= ~eEditorNoCSSMask;
} else {
// Turn on NoCSS, as we're disabling CSS.
@@ -4553,34 +4555,34 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
nsCOMPtr<nsINode> endNode = range->GetEndParent();
int32_t endOffset = range->EndOffset();
if (startNode == endNode && IsTextNode(startNode)) {
// Let's find the block container of the text node
nsCOMPtr<Element> blockParent = GetBlockNodeParent(startNode);
// And apply the background color to that block container
if (blockParent && cachedBlockParent != blockParent) {
cachedBlockParent = blockParent;
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
&bgcolor, &aColor, false);
}
} else if (startNode == endNode &&
startNode->IsHTMLElement(nsGkAtoms::body) && isCollapsed) {
// No block in the document, let's apply the background to the body
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(startNode->AsElement(),
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(startNode->AsElement(),
nullptr, &bgcolor, &aColor,
false);
} else if (startNode == endNode && (endOffset - startOffset == 1 ||
(!startOffset && !endOffset))) {
// A unique node is selected, let's also apply the background color to
// the containing block, possibly the node itself
nsCOMPtr<nsIContent> selectedNode = startNode->GetChildAt(startOffset);
nsCOMPtr<Element> blockParent = GetBlock(*selectedNode);
if (blockParent && cachedBlockParent != blockParent) {
cachedBlockParent = blockParent;
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
&bgcolor, &aColor, false);
}
} else {
// Not the easy case. Range not contained in single text node. There
// are up to three phases here. There are all the nodes reported by
// the subtree iterator to be processed. And there are potentially a
// starting textnode and an ending textnode which are only partially
// contained by the range.
@@ -4613,42 +4615,42 @@ nsHTMLEditor::SetCSSBackgroundColor(cons
}
// First check the start parent of the range to see if it needs to be
// separately handled (it does if it's a text node, due to how the
// subtree iterator works - it will not have reported it).
if (IsTextNode(startNode) && IsEditable(startNode)) {
nsCOMPtr<Element> blockParent = GetBlockNodeParent(startNode);
if (blockParent && cachedBlockParent != blockParent) {
cachedBlockParent = blockParent;
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
&bgcolor, &aColor,
false);
}
}
// Then loop through the list, set the property on each node
for (auto& node : arrayOfNodes) {
nsCOMPtr<Element> blockParent = GetBlock(node);
if (blockParent && cachedBlockParent != blockParent) {
cachedBlockParent = blockParent;
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
&bgcolor, &aColor,
false);
}
}
arrayOfNodes.Clear();
// Last, check the end parent of the range to see if it needs to be
// separately handled (it does if it's a text node, due to how the
// subtree iterator works - it will not have reported it).
if (IsTextNode(endNode) && IsEditable(endNode)) {
nsCOMPtr<Element> blockParent = GetBlockNodeParent(endNode);
if (blockParent && cachedBlockParent != blockParent) {
cachedBlockParent = blockParent;
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(blockParent, nullptr,
&bgcolor, &aColor,
false);
}
}
}
}
}
if (!cancel) {
@@ -4690,17 +4692,17 @@ nsHTMLEditor::AreNodesSameType(nsIConten
return false;
}
if (!IsCSSEnabled() || !aNode1->IsHTMLElement(nsGkAtoms::span)) {
return true;
}
// If CSS is enabled, we are stricter about span nodes.
- return mHTMLCSSUtils->ElementsSameStyle(aNode1->AsDOMNode(),
+ return mCSSEditUtils->ElementsSameStyle(aNode1->AsDOMNode(),
aNode2->AsDOMNode());
}
nsresult
nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNode * aNewBlock,
Element** aOutBrNode)
{
nsCOMPtr<nsINode> newBlock = do_QueryInterface(aNewBlock);
--- a/editor/libeditor/nsHTMLEditor.h
+++ b/editor/libeditor/nsHTMLEditor.h
@@ -17,17 +17,17 @@
#include "nsEditor.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsICSSLoaderObserver.h"
#include "nsEditRules.h"
-#include "nsHTMLCSSUtils.h"
+#include "CSSEditUtils.h"
#include "nsHTMLObjectResizer.h"
#include "nsIHTMLAbsPosEditor.h"
#include "nsIHTMLInlineTableEditor.h"
#include "nsIHTMLObjectResizeListener.h"
#include "nsIHTMLObjectResizer.h"
#include "nsIContentFilter.h"
@@ -36,33 +36,33 @@
#include "nsPoint.h"
#include "nsTArray.h"
#include "nsAutoPtr.h"
#include "nsAttrName.h"
#include "nsStubMutationObserver.h"
#include "mozilla/Attributes.h"
#include "mozilla/dom/Element.h"
+#include "mozilla/dom/File.h"
#include "mozilla/StyleSheetHandle.h"
class nsDocumentFragment;
class nsIDOMKeyEvent;
class nsITransferable;
class nsIClipboard;
class nsILinkHandler;
class nsTableWrapperFrame;
class nsIDOMRange;
class nsRange;
namespace mozilla {
class TypeInState;
struct PropItem;
template<class T> class OwningNonNull;
namespace dom {
-class BlobImpl;
class DocumentFragment;
} // namespace dom
namespace widget {
struct IMEState;
} // namespace widget
} // namespace mozilla
/**
@@ -391,18 +391,18 @@ public:
// Add a url + known style sheet to the internal lists:
nsresult AddNewStyleSheetToList(const nsAString &aURL,
mozilla::StyleSheetHandle aStyleSheet);
nsresult RemoveStyleSheetFromList(const nsAString &aURL);
bool IsCSSEnabled()
{
- // TODO: removal of mCSSAware and use only the presence of mHTMLCSSUtils
- return mCSSAware && mHTMLCSSUtils && mHTMLCSSUtils->IsCSSPrefChecked();
+ // TODO: removal of mCSSAware and use only the presence of mCSSEditUtils
+ return mCSSAware && mCSSEditUtils && mCSSEditUtils->IsCSSPrefChecked();
}
static bool HasAttributes(Element* aElement)
{
MOZ_ASSERT(aElement);
uint32_t attrCount = aElement->GetAttrCount();
return attrCount > 1 ||
(1 == attrCount && !aElement->GetAttrNameAt(0)->Equals(nsGkAtoms::mozdirty));
@@ -786,17 +786,17 @@ protected:
nsTArray<OwningNonNull<nsIContentFilter>> mContentFilters;
RefPtr<mozilla::TypeInState> mTypeInState;
bool mCRInParagraphCreatesParagraph;
bool mCSSAware;
- nsAutoPtr<nsHTMLCSSUtils> mHTMLCSSUtils;
+ nsAutoPtr<mozilla::CSSEditUtils> mCSSEditUtils;
// Used by GetFirstSelectedCell and GetNextSelectedCell
int32_t mSelectedCellIndex;
nsString mLastStyleSheetURL;
nsString mLastOverrideStyleSheetURL;
// Maintain a list of associated style sheets and their urls.
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -1,12 +1,13 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
#include "EditorUtils.h"
#include "HTMLEditUtils.h"
#include "SelectionState.h"
#include "TextEditUtils.h"
#include "TypeInState.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
@@ -16,17 +17,16 @@
#include "nsCOMPtr.h"
#include "nsCaseTreatment.h"
#include "nsComponentManagerUtils.h"
#include "nsDebug.h"
#include "nsEditRules.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLCSSUtils.h"
#include "nsHTMLEditor.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIContentIterator.h"
#include "nsIDOMElement.h"
#include "nsIEditor.h"
#include "nsIEditorIMESupport.h"
#include "nsNameSpaceManager.h"
@@ -273,35 +273,35 @@ nsHTMLEditor::IsSimpleModifiableNode(nsI
// Property-specific handling is needed (bug 760211).
return true;
}
}
// No luck so far. Now we check for a <span> with a single style=""
// attribute that sets only the style we're looking for, if this type of
// style supports it
- if (!mHTMLCSSUtils->IsCSSEditableProperty(element, aProperty, aAttribute) ||
+ if (!mCSSEditUtils->IsCSSEditableProperty(element, aProperty, aAttribute) ||
!element->IsHTMLElement(nsGkAtoms::span) ||
element->GetAttrCount() != 1 ||
!element->HasAttr(kNameSpaceID_None, nsGkAtoms::style)) {
return false;
}
// Some CSS styles are not so simple. For instance, underline is
// "text-decoration: underline", which decomposes into four different text-*
// properties. So for now, we just create a span, add the desired style, and
// see if it matches.
nsCOMPtr<Element> newSpan = CreateHTMLContent(nsGkAtoms::span);
NS_ASSERTION(newSpan, "CreateHTMLContent failed");
NS_ENSURE_TRUE(newSpan, false);
- mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(newSpan, aProperty,
+ mCSSEditUtils->SetCSSEquivalentToHTMLStyle(newSpan, aProperty,
aAttribute, aValue,
/*suppress transaction*/ true);
- return mHTMLCSSUtils->ElementsSameStyle(newSpan, element);
+ return mCSSEditUtils->ElementsSameStyle(newSpan, element);
}
nsresult
nsHTMLEditor::SetInlinePropertyOnTextNode(Text& aText,
int32_t aStartOffset,
int32_t aEndOffset,
nsIAtom& aProperty,
@@ -314,21 +314,21 @@ nsHTMLEditor::SetInlinePropertyOnTextNod
}
// Don't need to do anything if no characters actually selected
if (aStartOffset == aEndOffset) {
return NS_OK;
}
// Don't need to do anything if property already set on node
- if (mHTMLCSSUtils->IsCSSEditableProperty(&aText, &aProperty, aAttribute)) {
+ if (mCSSEditUtils->IsCSSEditableProperty(&aText, &aProperty, aAttribute)) {
// The HTML styles defined by aProperty/aAttribute have a CSS equivalence
// for node; let's check if it carries those CSS styles
- if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(&aText, &aProperty,
- aAttribute, aValue, nsHTMLCSSUtils::eComputed)) {
+ if (mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(&aText, &aProperty,
+ aAttribute, aValue, CSSEditUtils::eComputed)) {
return NS_OK;
}
} else if (IsTextPropertySetByContent(&aText, &aProperty, aAttribute,
&aValue)) {
return NS_OK;
}
// Do we need to split the text node?
@@ -413,28 +413,29 @@ nsHTMLEditor::SetInlinePropertyOnNodeImp
}
if (IsSimpleModifiableNode(nextSibling, &aProperty, aAttribute, &aValue)) {
res = MoveNode(&aNode, nextSibling, 0);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
// Don't need to do anything if property already set on node
- if (mHTMLCSSUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) {
- if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(
- &aNode, &aProperty, aAttribute, aValue, nsHTMLCSSUtils::eComputed)) {
+ if (mCSSEditUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) {
+ if (mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(
+ &aNode, &aProperty, aAttribute, aValue, CSSEditUtils::eComputed)) {
return NS_OK;
}
} else if (IsTextPropertySetByContent(&aNode, &aProperty,
aAttribute, &aValue)) {
return NS_OK;
}
bool useCSS = (IsCSSEnabled() &&
- mHTMLCSSUtils->IsCSSEditableProperty(&aNode, &aProperty, aAttribute)) ||
+ mCSSEditUtils->IsCSSEditableProperty(&aNode, &aProperty,
+ aAttribute)) ||
// bgcolor is always done using CSS
aAttribute->EqualsLiteral("bgcolor");
if (useCSS) {
nsCOMPtr<dom::Element> tmp;
// We only add style="" to <span>s with no attributes (bug 746515). If we
// don't have one, we need to make one.
if (aNode.IsHTMLElement(nsGkAtoms::span) &&
@@ -442,17 +443,17 @@ nsHTMLEditor::SetInlinePropertyOnNodeImp
tmp = aNode.AsElement();
} else {
tmp = InsertContainerAbove(&aNode, nsGkAtoms::span);
NS_ENSURE_STATE(tmp);
}
// Add the CSS styles corresponding to the HTML style request
int32_t count;
- res = mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(tmp->AsDOMNode(),
+ res = mCSSEditUtils->SetCSSEquivalentToHTMLStyle(tmp->AsDOMNode(),
&aProperty, aAttribute,
&aValue, &count, false);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
// is it already the right kind of node, but with wrong attribute?
if (aNode.IsHTMLElement(&aProperty)) {
@@ -565,24 +566,24 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOM
OwningNonNull<nsIContent> node = *(*aNode)->AsContent();
bool useCSS = IsCSSEnabled();
bool isSet;
while (!IsBlockNode(node) && node->GetParent() &&
IsEditable(node->GetParent())) {
isSet = false;
- if (useCSS && mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
+ if (useCSS && mCSSEditUtils->IsCSSEditableProperty(node, aProperty,
aAttribute)) {
// The HTML style defined by aProperty/aAttribute has a CSS equivalence
// in this implementation for the node; let's check if it carries those
// CSS styles
nsAutoString firstValue;
- mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node),
- aProperty, aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified);
+ mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node),
+ aProperty, aAttribute, isSet, firstValue, CSSEditUtils::eSpecified);
}
if (// node is the correct inline prop
(aProperty && node->IsHTMLElement(aProperty)) ||
// node is href - test if really <a href=...
(aProperty == nsGkAtoms::href && HTMLEditUtils::IsLink(node)) ||
// or node is any prop, and we asked to split them all
(!aProperty && NodeIsProperty(node)) ||
// or the style is specified in the style attribute
@@ -774,27 +775,27 @@ nsHTMLEditor::RemoveStyleInside(nsIConte
res = RemoveAttribute(elem, *aAttribute);
}
NS_ENSURE_SUCCESS(res, res);
}
}
}
if (!aChildrenOnly &&
- mHTMLCSSUtils->IsCSSEditableProperty(&aNode, aProperty, aAttribute)) {
+ mCSSEditUtils->IsCSSEditableProperty(&aNode, aProperty, aAttribute)) {
// the HTML style defined by aProperty/aAttribute has a CSS equivalence in
// this implementation for the node aNode; let's check if it carries those
// css styles
nsAutoString propertyValue;
- bool isSet = mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(&aNode,
- aProperty, aAttribute, propertyValue, nsHTMLCSSUtils::eSpecified);
+ bool isSet = mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(&aNode,
+ aProperty, aAttribute, propertyValue, CSSEditUtils::eSpecified);
if (isSet && aNode.IsElement()) {
// yes, tmp has the corresponding css declarations in its style attribute
// let's remove them
- mHTMLCSSUtils->RemoveCSSEquivalentToHTMLStyle(aNode.AsElement(),
+ mCSSEditUtils->RemoveCSSEquivalentToHTMLStyle(aNode.AsElement(),
aProperty,
aAttribute,
&propertyValue,
false);
// remove the node if it is a span or font, if its style attribute is
// empty or absent, and if it does not have a class nor an id
RemoveElementIfNoStyleOrIdOrClass(*aNode.AsElement());
}
@@ -996,24 +997,24 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
} else {
mTypeInState->GetTypingState(isSet, theSetting, &aProperty);
}
if (isSet) {
*aFirst = *aAny = *aAll = theSetting;
return NS_OK;
}
- if (mHTMLCSSUtils->IsCSSEditableProperty(collapsedNode, &aProperty,
+ if (mCSSEditUtils->IsCSSEditableProperty(collapsedNode, &aProperty,
aAttribute)) {
if (aValue) {
tOutString.Assign(*aValue);
}
*aFirst = *aAny = *aAll =
- mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(collapsedNode,
- &aProperty, aAttribute, tOutString, nsHTMLCSSUtils::eComputed);
+ mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(collapsedNode,
+ &aProperty, aAttribute, tOutString, CSSEditUtils::eComputed);
if (outValue) {
outValue->Assign(tOutString);
}
return NS_OK;
}
isSet = IsTextPropertySetByContent(collapsedNode, &aProperty,
aAttribute, aValue, outValue);
@@ -1070,46 +1071,46 @@ nsHTMLEditor::GetInlinePropertyBase(nsIA
}
} else if (content->IsElement()) {
// handle non-text leaf nodes here
continue;
}
bool isSet = false;
if (first) {
- if (mHTMLCSSUtils->IsCSSEditableProperty(content, &aProperty,
+ if (mCSSEditUtils->IsCSSEditableProperty(content, &aProperty,
aAttribute)) {
// The HTML styles defined by aProperty/aAttribute have a CSS
// equivalence in this implementation for node; let's check if it
// carries those CSS styles
if (aValue) {
firstValue.Assign(*aValue);
}
- isSet = mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(content,
- &aProperty, aAttribute, firstValue, nsHTMLCSSUtils::eComputed);
+ isSet = mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(content,
+ &aProperty, aAttribute, firstValue, CSSEditUtils::eComputed);
} else {
isSet = IsTextPropertySetByContent(content, &aProperty, aAttribute,
aValue, &firstValue);
}
*aFirst = isSet;
first = false;
if (outValue) {
*outValue = firstValue;
}
} else {
- if (mHTMLCSSUtils->IsCSSEditableProperty(content, &aProperty,
+ if (mCSSEditUtils->IsCSSEditableProperty(content, &aProperty,
aAttribute)) {
// The HTML styles defined by aProperty/aAttribute have a CSS
// equivalence in this implementation for node; let's check if it
// carries those CSS styles
if (aValue) {
theValue.Assign(*aValue);
}
- isSet = mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(content,
- &aProperty, aAttribute, theValue, nsHTMLCSSUtils::eComputed);
+ isSet = mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(content,
+ &aProperty, aAttribute, theValue, CSSEditUtils::eComputed);
} else {
isSet = IsTextPropertySetByContent(content, &aProperty, aAttribute,
aValue, &theValue);
}
if (firstValue != theValue) {
*aAll = false;
}
}
@@ -1245,28 +1246,28 @@ nsHTMLEditor::RemoveInlinePropertyImpl(n
NS_ENSURE_SUCCESS(res, res);
// Check for easy case: both range endpoints in same text node
nsCOMPtr<nsINode> startNode = range->GetStartParent();
nsCOMPtr<nsINode> endNode = range->GetEndParent();
if (startNode && startNode == endNode && startNode->GetAsText()) {
// We're done with this range!
if (IsCSSEnabled() &&
- mHTMLCSSUtils->IsCSSEditableProperty(startNode, aProperty,
+ mCSSEditUtils->IsCSSEditableProperty(startNode, aProperty,
aAttribute)) {
// The HTML style defined by aProperty/aAttribute has a CSS
// equivalence in this implementation for startNode
- if (mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(startNode,
+ if (mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(startNode,
aProperty, aAttribute, EmptyString(),
- nsHTMLCSSUtils::eComputed)) {
+ CSSEditUtils::eComputed)) {
// startNode's computed style indicates the CSS equivalence to the
// HTML style to remove is applied; but we found no element in the
// ancestors of startNode carrying specified styles; assume it
// comes from a rule and try to insert a span "inverting" the style
- if (mHTMLCSSUtils->IsCSSInvertible(*aProperty, aAttribute)) {
+ if (mCSSEditUtils->IsCSSInvertible(*aProperty, aAttribute)) {
NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value");
SetInlinePropertyOnTextNode(*startNode->GetAsText(),
range->StartOffset(),
range->EndOffset(), *aProperty,
aAttribute, value);
}
}
}
@@ -1286,27 +1287,27 @@ nsHTMLEditor::RemoveInlinePropertyImpl(n
}
}
// Loop through the list, remove the property on each node
for (auto& node : arrayOfNodes) {
res = RemoveStyleInside(node, aProperty, aAttribute);
NS_ENSURE_SUCCESS(res, res);
if (IsCSSEnabled() &&
- mHTMLCSSUtils->IsCSSEditableProperty(node, aProperty,
+ mCSSEditUtils->IsCSSEditableProperty(node, aProperty,
aAttribute) &&
- mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(node,
+ mCSSEditUtils->IsCSSEquivalentToHTMLInlineStyleSet(node,
aProperty, aAttribute, EmptyString(),
- nsHTMLCSSUtils::eComputed) &&
+ CSSEditUtils::eComputed) &&
// startNode's computed style indicates the CSS equivalence to
// the HTML style to remove is applied; but we found no element
// in the ancestors of startNode carrying specified styles;
// assume it comes from a rule and let's try to insert a span
// "inverting" the style
- mHTMLCSSUtils->IsCSSInvertible(*aProperty, aAttribute)) {
+ mCSSEditUtils->IsCSSInvertible(*aProperty, aAttribute)) {
NS_NAMED_LITERAL_STRING(value, "-moz-editor-invert-value");
SetInlinePropertyOnNode(node, *aProperty, aAttribute, value);
}
}
}
}
}
if (!cancel) {
--- a/editor/libeditor/nsHTMLObjectResizer.cpp
+++ b/editor/libeditor/nsHTMLObjectResizer.cpp
@@ -13,17 +13,16 @@
#include "mozilla/Preferences.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLCSSUtils.h"
#include "nsHTMLEditor.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsID.h"
#include "nsIDOMDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
@@ -245,22 +244,22 @@ nsHTMLEditor::SetAllResizersPosition()
int32_t h = mResizedObjectHeight;
// now let's place all the resizers around the image
// get the size of resizers
nsAutoString value;
float resizerWidth, resizerHeight;
nsCOMPtr<nsIAtom> dummyUnit;
- mHTMLCSSUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::width,
+ mCSSEditUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::width,
value);
- mHTMLCSSUtils->ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
- mHTMLCSSUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::height,
+ mCSSEditUtils->ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
+ mCSSEditUtils->GetComputedProperty(*mTopLeftHandle, *nsGkAtoms::height,
value);
- mHTMLCSSUtils->ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit));
+ mCSSEditUtils->ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit));
int32_t rw = (int32_t)((resizerWidth + 1) / 2);
int32_t rh = (int32_t)((resizerHeight+ 1) / 2);
SetAnonymousElementPosition(x-rw, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopLeftHandle)));
SetAnonymousElementPosition(x+w/2-rw, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopHandle)));
SetAnonymousElementPosition(x+w-rw-1, y-rh, static_cast<nsIDOMElement*>(GetAsDOMNode(mTopRightHandle)));
@@ -538,19 +537,19 @@ nsHTMLEditor::StartResizing(nsIDOMElemen
else if (locationStr.Equals(kBottomRight)) {
SetResizeIncrements(0, 0, 1, 1, preserveRatio);
}
// make the shadow appear
mResizingShadow->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_class, true);
// position it
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
mResizedObjectWidth);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
mResizedObjectHeight);
// add a mouse move listener to the editor
nsresult result = NS_OK;
if (!mMouseMotionListenerP) {
mMouseMotionListenerP = new ResizerMouseMotionListener(this);
if (!mMouseMotionListenerP) {
return NS_ERROR_OUT_OF_MEMORY;
@@ -668,19 +667,19 @@ nsHTMLEditor::SetResizingInfoPosition(in
infoYPosition = aY + (aH / 2);
else
// should only occur when mActivatedHandle is one of the 3 bottom-side
// handles, but this is a reasonable default if it isn't any of them (?)
infoYPosition = aY + aH;
// Offset info box by 20 so it's not directly under the mouse cursor.
const int mouseCursorOffset = 20;
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::left,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::left,
infoXPosition + mouseCursorOffset);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::top,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingInfo, *nsGkAtoms::top,
infoYPosition + mouseCursorOffset);
nsCOMPtr<nsIContent> textInfo = mResizingInfo->GetFirstChild();
ErrorResult rv;
if (textInfo) {
mResizingInfo->RemoveChild(*textInfo, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
textInfo = nullptr;
@@ -824,23 +823,23 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMo
mouseEvent->GetClientX(&clientX);
mouseEvent->GetClientY(&clientY);
int32_t newX = GetNewResizingX(clientX, clientY);
int32_t newY = GetNewResizingY(clientX, clientY);
int32_t newWidth = GetNewResizingWidth(clientX, clientY);
int32_t newHeight = GetNewResizingHeight(clientX, clientY);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::left,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::left,
newX);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::top,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::top,
newY);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::width,
newWidth);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*mResizingShadow, *nsGkAtoms::height,
newHeight);
return SetResizingInfoPosition(newX, newY, newWidth, newHeight);
}
if (mGrabberClicked) {
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
int32_t clientX, clientY;
@@ -864,19 +863,19 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMo
mouseEvent->GetClientX(&clientX);
mouseEvent->GetClientY(&clientY);
int32_t newX = mPositionedObjectX + clientX - mOriginalX;
int32_t newY = mPositionedObjectY + clientY - mOriginalY;
SnapToGrid(newX, newY);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::left,
+ mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::left,
newX);
- mHTMLCSSUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::top,
+ mCSSEditUtils->SetCSSPropertyPixels(*mPositioningShadow, *nsGkAtoms::top,
newY);
}
return NS_OK;
}
void
nsHTMLEditor::SetFinalSize(int32_t aX, int32_t aY)
{
@@ -909,66 +908,66 @@ nsHTMLEditor::SetFinalSize(int32_t aX, i
NS_NAMED_LITERAL_STRING(widthStr, "width");
NS_NAMED_LITERAL_STRING(heightStr, "height");
nsCOMPtr<Element> resizedObject = do_QueryInterface(mResizedObject);
NS_ENSURE_TRUE(resizedObject, );
if (mResizedObjectIsAbsolutelyPositioned) {
if (setHeight)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::top, y);
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::top, y);
if (setWidth)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::left, x);
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::left, x);
}
if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) {
if (setWidth && mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) {
RemoveAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), widthStr);
}
if (setHeight && mResizedObject->HasAttr(kNameSpaceID_None,
nsGkAtoms::height)) {
RemoveAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), heightStr);
}
if (setWidth)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
width);
if (setHeight)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
height);
}
else {
// we use HTML size and remove all equivalent CSS properties
// we set the CSS width and height to remove it later,
// triggering an immediate reflow; otherwise, we have problems
// with asynchronous reflow
if (setWidth)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::width,
width);
if (setHeight)
- mHTMLCSSUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->SetCSSPropertyPixels(*resizedObject, *nsGkAtoms::height,
height);
if (setWidth) {
nsAutoString w;
w.AppendInt(width);
SetAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), widthStr, w);
}
if (setHeight) {
nsAutoString h;
h.AppendInt(height);
SetAttribute(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)), heightStr, h);
}
if (setWidth)
- mHTMLCSSUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::width,
+ mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::width,
EmptyString());
if (setHeight)
- mHTMLCSSUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::height,
+ mCSSEditUtils->RemoveCSSProperty(*resizedObject, *nsGkAtoms::height,
EmptyString());
}
// finally notify the listeners if any
for (auto& listener : mObjectResizeEventListeners) {
listener->OnEndResizing(static_cast<nsIDOMElement*>(GetAsDOMNode(mResizedObject)),
mResizedObjectWidth, mResizedObjectHeight, width,
height);
}