rename from editor/libeditor/nsHTMLEditUtils.cpp
rename to editor/libeditor/HTMLEditUtils.cpp
--- a/editor/libeditor/nsHTMLEditUtils.cpp
+++ b/editor/libeditor/HTMLEditUtils.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 "nsHTMLEditUtils.h"
+#include "HTMLEditUtils.h"
#include "TextEditUtils.h" // for TextEditUtils
#include "mozilla/ArrayUtils.h" // for ArrayLength
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
#include "mozilla/dom/Element.h" // for Element, nsINode
#include "nsAString.h" // for nsAString_internal::IsEmpty
#include "nsCOMPtr.h" // for nsCOMPtr, operator==, etc
#include "nsCaseTreatment.h"
@@ -19,422 +19,407 @@
#include "nsHTMLTags.h"
#include "nsIAtom.h" // for nsIAtom
#include "nsIDOMHTMLAnchorElement.h" // for nsIDOMHTMLAnchorElement
#include "nsIDOMNode.h" // for nsIDOMNode
#include "nsNameSpaceManager.h" // for kNameSpaceID_None
#include "nsLiteralString.h" // for NS_LITERAL_STRING
#include "nsString.h" // for nsAutoString
-using namespace mozilla;
+namespace mozilla {
-///////////////////////////////////////////////////////////////////////////
-// IsInlineStyle true if node is an inline style
-//
+/**
+ * IsInlineStyle() returns true if aNode is an inline style.
+ */
bool
-nsHTMLEditUtils::IsInlineStyle(nsIDOMNode* aNode)
+HTMLEditUtils::IsInlineStyle(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsInlineStyle");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsInlineStyle(node);
}
bool
-nsHTMLEditUtils::IsInlineStyle(nsINode* aNode)
+HTMLEditUtils::IsInlineStyle(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::b,
nsGkAtoms::i,
nsGkAtoms::u,
nsGkAtoms::tt,
nsGkAtoms::s,
nsGkAtoms::strike,
nsGkAtoms::big,
nsGkAtoms::small,
nsGkAtoms::sub,
nsGkAtoms::sup,
nsGkAtoms::font);
}
-///////////////////////////////////////////////////////////////////////////
-// IsFormatNode true if node is a format node
-//
+/**
+ * IsFormatNode() returns true if aNode is a format node.
+ */
bool
-nsHTMLEditUtils::IsFormatNode(nsIDOMNode* aNode)
+HTMLEditUtils::IsFormatNode(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsFormatNode");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsFormatNode(node);
}
bool
-nsHTMLEditUtils::IsFormatNode(nsINode* aNode)
+HTMLEditUtils::IsFormatNode(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::p,
nsGkAtoms::pre,
nsGkAtoms::h1,
nsGkAtoms::h2,
nsGkAtoms::h3,
nsGkAtoms::h4,
nsGkAtoms::h5,
nsGkAtoms::h6,
nsGkAtoms::address);
}
-///////////////////////////////////////////////////////////////////////////
-// IsNodeThatCanOutdent true if node is a list, list item, or blockquote
-//
+/**
+ * IsNodeThatCanOutdent() returns true if aNode is a list, list item or
+ * blockquote.
+ */
bool
-nsHTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode* aNode)
+HTMLEditUtils::IsNodeThatCanOutdent(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsNodeThatCanOutdent");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
return (nodeAtom == nsGkAtoms::ul)
|| (nodeAtom == nsGkAtoms::ol)
|| (nodeAtom == nsGkAtoms::dl)
|| (nodeAtom == nsGkAtoms::li)
|| (nodeAtom == nsGkAtoms::dd)
|| (nodeAtom == nsGkAtoms::dt)
|| (nodeAtom == nsGkAtoms::blockquote);
}
-/********************************************************
- * helper methods from nsHTMLEditRules
- ********************************************************/
-
-///////////////////////////////////////////////////////////////////////////
-// IsHeader: true if node an html header
-//
+/**
+ * IsHeader() returns true if aNode is an html header.
+ */
bool
-nsHTMLEditUtils::IsHeader(nsINode& aNode)
+HTMLEditUtils::IsHeader(nsINode& aNode)
{
return aNode.IsAnyOfHTMLElements(nsGkAtoms::h1,
nsGkAtoms::h2,
nsGkAtoms::h3,
nsGkAtoms::h4,
nsGkAtoms::h5,
nsGkAtoms::h6);
}
bool
-nsHTMLEditUtils::IsHeader(nsIDOMNode* aNode)
+HTMLEditUtils::IsHeader(nsIDOMNode* aNode)
{
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
- NS_PRECONDITION(node, "null parent passed to nsHTMLEditUtils::IsHeader");
+ MOZ_ASSERT(node);
return IsHeader(*node);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsParagraph: true if node an html paragraph
-//
+/**
+ * IsParagraph() returns true if aNode is an html paragraph.
+ */
bool
-nsHTMLEditUtils::IsParagraph(nsIDOMNode* aNode)
+HTMLEditUtils::IsParagraph(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::p);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsHR: true if node an horizontal rule
-//
+/**
+ * IsHR() returns true if aNode is an horizontal rule.
+ */
bool
-nsHTMLEditUtils::IsHR(nsIDOMNode* aNode)
+HTMLEditUtils::IsHR(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::hr);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsListItem: true if node an html list item
-//
+/**
+ * IsListItem() returns true if aNode is an html list item.
+ */
bool
-nsHTMLEditUtils::IsListItem(nsIDOMNode* aNode)
+HTMLEditUtils::IsListItem(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsListItem");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsListItem(node);
}
bool
-nsHTMLEditUtils::IsListItem(nsINode* aNode)
+HTMLEditUtils::IsListItem(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::li,
nsGkAtoms::dd,
nsGkAtoms::dt);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsTableElement: true if node an html table, td, tr, ...
-//
+/**
+ * IsTableElement() returns true if aNode is an html table, td, tr, ...
+ */
bool
-nsHTMLEditUtils::IsTableElement(nsIDOMNode* aNode)
+HTMLEditUtils::IsTableElement(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null node passed to nsHTMLEditor::IsTableElement");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsTableElement(node);
}
bool
-nsHTMLEditUtils::IsTableElement(nsINode* aNode)
+HTMLEditUtils::IsTableElement(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::table,
nsGkAtoms::tr,
nsGkAtoms::td,
nsGkAtoms::th,
nsGkAtoms::thead,
nsGkAtoms::tfoot,
nsGkAtoms::tbody,
nsGkAtoms::caption);
}
-///////////////////////////////////////////////////////////////////////////
-// IsTableElementButNotTable: true if node an html td, tr, ... (doesn't include table)
-//
+/**
+ * IsTableElementButNotTable() returns true if aNode is an html td, tr, ...
+ * (doesn't include table)
+ */
bool
-nsHTMLEditUtils::IsTableElementButNotTable(nsIDOMNode* aNode)
+HTMLEditUtils::IsTableElementButNotTable(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null node passed to nsHTMLEditor::IsTableElementButNotTable");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsTableElementButNotTable(node);
}
bool
-nsHTMLEditUtils::IsTableElementButNotTable(nsINode* aNode)
+HTMLEditUtils::IsTableElementButNotTable(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::tr,
nsGkAtoms::td,
nsGkAtoms::th,
nsGkAtoms::thead,
nsGkAtoms::tfoot,
nsGkAtoms::tbody,
nsGkAtoms::caption);
}
-///////////////////////////////////////////////////////////////////////////
-// IsTable: true if node an html table
-//
+/**
+ * IsTable() returns true if aNode is an html table.
+ */
bool
-nsHTMLEditUtils::IsTable(nsIDOMNode* aNode)
+HTMLEditUtils::IsTable(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::table);
}
bool
-nsHTMLEditUtils::IsTable(nsINode* aNode)
+HTMLEditUtils::IsTable(nsINode* aNode)
{
return aNode && aNode->IsHTMLElement(nsGkAtoms::table);
}
-///////////////////////////////////////////////////////////////////////////
-// IsTableRow: true if node an html tr
-//
+/**
+ * IsTableRow() returns true if aNode is an html tr.
+ */
bool
-nsHTMLEditUtils::IsTableRow(nsIDOMNode* aNode)
+HTMLEditUtils::IsTableRow(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::tr);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsTableCell: true if node an html td or th
-//
+/**
+ * IsTableCell() returns true if aNode is an html td or th.
+ */
bool
-nsHTMLEditUtils::IsTableCell(nsIDOMNode* aNode)
+HTMLEditUtils::IsTableCell(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsTableCell");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsTableCell(node);
}
bool
-nsHTMLEditUtils::IsTableCell(nsINode* aNode)
+HTMLEditUtils::IsTableCell(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsTableCellOrCaption: true if node an html td or th or caption
-//
+/**
+ * IsTableCellOrCaption() returns true if aNode is an html td or th or caption.
+ */
bool
-nsHTMLEditUtils::IsTableCellOrCaption(nsINode& aNode)
+HTMLEditUtils::IsTableCellOrCaption(nsINode& aNode)
{
return aNode.IsAnyOfHTMLElements(nsGkAtoms::td, nsGkAtoms::th,
nsGkAtoms::caption);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsList: true if node an html list
-//
+/**
+ * IsList() returns true if aNode is an html list.
+ */
bool
-nsHTMLEditUtils::IsList(nsIDOMNode* aNode)
+HTMLEditUtils::IsList(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsList");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsList(node);
}
bool
-nsHTMLEditUtils::IsList(nsINode* aNode)
+HTMLEditUtils::IsList(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::ul,
nsGkAtoms::ol,
nsGkAtoms::dl);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsOrderedList: true if node an html ordered list
-//
+/**
+ * IsOrderedList() returns true if aNode is an html ordered list.
+ */
bool
-nsHTMLEditUtils::IsOrderedList(nsIDOMNode* aNode)
+HTMLEditUtils::IsOrderedList(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::ol);
}
-///////////////////////////////////////////////////////////////////////////
-// IsUnorderedList: true if node an html unordered list
-//
+/**
+ * IsUnorderedList() returns true if aNode is an html unordered list.
+ */
bool
-nsHTMLEditUtils::IsUnorderedList(nsIDOMNode* aNode)
+HTMLEditUtils::IsUnorderedList(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::ul);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsBlockquote: true if node an html blockquote node
-//
+/**
+ * IsBlockquote() returns true if aNode is an html blockquote node.
+ */
bool
-nsHTMLEditUtils::IsBlockquote(nsIDOMNode* aNode)
+HTMLEditUtils::IsBlockquote(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::blockquote);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsPre: true if node an html pre node
-//
+/**
+ * IsPre() returns true if aNode is an html pre node.
+ */
bool
-nsHTMLEditUtils::IsPre(nsIDOMNode* aNode)
+HTMLEditUtils::IsPre(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::pre);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsImage: true if node an html image node
-//
+/**
+ * IsImage() returns true if aNode is an html image node.
+ */
bool
-nsHTMLEditUtils::IsImage(nsINode* aNode)
+HTMLEditUtils::IsImage(nsINode* aNode)
{
return aNode && aNode->IsHTMLElement(nsGkAtoms::img);
}
bool
-nsHTMLEditUtils::IsImage(nsIDOMNode* aNode)
+HTMLEditUtils::IsImage(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::img);
}
bool
-nsHTMLEditUtils::IsLink(nsIDOMNode *aNode)
+HTMLEditUtils::IsLink(nsIDOMNode *aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsLink(node);
}
bool
-nsHTMLEditUtils::IsLink(nsINode* aNode)
+HTMLEditUtils::IsLink(nsINode* aNode)
{
MOZ_ASSERT(aNode);
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aNode);
if (anchor)
{
nsAutoString tmpText;
if (NS_SUCCEEDED(anchor->GetHref(tmpText)) && !tmpText.IsEmpty()) {
return true;
}
}
return false;
}
bool
-nsHTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
+HTMLEditUtils::IsNamedAnchor(nsIDOMNode *aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsNamedAnchor(node);
}
bool
-nsHTMLEditUtils::IsNamedAnchor(nsINode* aNode)
+HTMLEditUtils::IsNamedAnchor(nsINode* aNode)
{
MOZ_ASSERT(aNode);
if (!aNode->IsHTMLElement(nsGkAtoms::a)) {
return false;
}
nsAutoString text;
return aNode->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::name,
text) && !text.IsEmpty();
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsDiv: true if node an html div node
-//
+/**
+ * IsDiv() returns true if aNode is an html div node.
+ */
bool
-nsHTMLEditUtils::IsDiv(nsIDOMNode* aNode)
+HTMLEditUtils::IsDiv(nsIDOMNode* aNode)
{
return nsEditor::NodeIsType(aNode, nsGkAtoms::div);
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsMozDiv: true if node an html div node with type = _moz
-//
+/**
+ * IsMozDiv() returns true if aNode is an html div node with |type = _moz|.
+ */
bool
-nsHTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
+HTMLEditUtils::IsMozDiv(nsIDOMNode* aNode)
{
return IsDiv(aNode) && TextEditUtils::HasMozAttr(aNode);
}
bool
-nsHTMLEditUtils::IsMozDiv(nsINode* aNode)
+HTMLEditUtils::IsMozDiv(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsHTMLElement(nsGkAtoms::div) &&
TextEditUtils::HasMozAttr(GetAsDOMNode(aNode));
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsMailCite: true if node an html blockquote with type=cite
-//
+/**
+ * IsMailCite() returns true if aNode is an html blockquote with |type=cite|.
+ */
bool
-nsHTMLEditUtils::IsMailCite(nsIDOMNode* aNode)
+HTMLEditUtils::IsMailCite(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null parent passed to nsHTMLEditUtils::IsMailCite");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsMailCite(node);
}
bool
-nsHTMLEditUtils::IsMailCite(nsINode* aNode)
+HTMLEditUtils::IsMailCite(nsINode* aNode)
{
MOZ_ASSERT(aNode);
// don't ask me why, but our html mailcites are id'd by "type=cite"...
if (aNode->IsElement() &&
aNode->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::type,
NS_LITERAL_STRING("cite"),
eIgnoreCase)) {
@@ -447,46 +432,45 @@ nsHTMLEditUtils::IsMailCite(nsINode* aNo
NS_LITERAL_STRING("true"),
eIgnoreCase)) {
return true;
}
return false;
}
-
-///////////////////////////////////////////////////////////////////////////
-// IsFormWidget: true if node is a form widget of some kind
-//
+/**
+ * IsFormWidget() returns true if aNode is a form widget of some kind.
+ */
bool
-nsHTMLEditUtils::IsFormWidget(nsIDOMNode* aNode)
+HTMLEditUtils::IsFormWidget(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::IsFormWidget");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
return node && IsFormWidget(node);
}
bool
-nsHTMLEditUtils::IsFormWidget(nsINode* aNode)
+HTMLEditUtils::IsFormWidget(nsINode* aNode)
{
MOZ_ASSERT(aNode);
return aNode->IsAnyOfHTMLElements(nsGkAtoms::textarea,
nsGkAtoms::select,
nsGkAtoms::button,
nsGkAtoms::output,
nsGkAtoms::keygen,
nsGkAtoms::progress,
nsGkAtoms::meter,
nsGkAtoms::input);
}
bool
-nsHTMLEditUtils::SupportsAlignAttr(nsIDOMNode* aNode)
+HTMLEditUtils::SupportsAlignAttr(nsIDOMNode* aNode)
{
- NS_PRECONDITION(aNode, "null node passed to nsHTMLEditUtils::SupportsAlignAttr");
+ MOZ_ASSERT(aNode);
nsCOMPtr<nsIAtom> nodeAtom = nsEditor::GetTag(aNode);
return (nodeAtom == nsGkAtoms::hr)
|| (nodeAtom == nsGkAtoms::table)
|| (nodeAtom == nsGkAtoms::tbody)
|| (nodeAtom == nsGkAtoms::tfoot)
|| (nodeAtom == nsGkAtoms::thead)
|| (nodeAtom == nsGkAtoms::tr)
|| (nodeAtom == nsGkAtoms::td)
@@ -592,17 +576,17 @@ nsHTMLEditUtils::SupportsAlignAttr(nsIDO
#define GROUP_PICTURE_CONTENT (1 << 24)
#define GROUP_INLINE_ELEMENT \
(GROUP_FONTSTYLE | GROUP_PHRASE | GROUP_SPECIAL | GROUP_FORMCONTROL | \
GROUP_LEAF)
#define GROUP_FLOW_ELEMENT (GROUP_INLINE_ELEMENT | GROUP_BLOCK)
-struct nsElementInfo
+struct ElementInfo final
{
#ifdef DEBUG
eHTMLTags mTag;
#endif
uint32_t mGroup;
uint32_t mCanContainGroups;
bool mIsContainer;
bool mCanContainSelf;
@@ -611,17 +595,17 @@ struct nsElementInfo
#ifdef DEBUG
#define ELEM(_tag, _isContainer, _canContainSelf, _group, _canContainGroups) \
{ eHTMLTag_##_tag, _group, _canContainGroups, _isContainer, _canContainSelf }
#else
#define ELEM(_tag, _isContainer, _canContainSelf, _group, _canContainGroups) \
{ _group, _canContainGroups, _isContainer, _canContainSelf }
#endif
-static const nsElementInfo kElements[eHTMLTag_userdefined] = {
+static const ElementInfo kElements[eHTMLTag_userdefined] = {
ELEM(a, true, false, GROUP_SPECIAL, GROUP_INLINE_ELEMENT),
ELEM(abbr, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
ELEM(acronym, true, true, GROUP_PHRASE, GROUP_INLINE_ELEMENT),
ELEM(address, true, true, GROUP_BLOCK,
GROUP_INLINE_ELEMENT | GROUP_P),
ELEM(applet, true, true, GROUP_SPECIAL | GROUP_BLOCK,
GROUP_FLOW_ELEMENT | GROUP_OBJECT_CONTENT),
ELEM(area, false, false, GROUP_MAP_CONTENT, GROUP_NONE),
@@ -784,17 +768,17 @@ static const nsElementInfo kElements[eHT
ELEM(doctypeDecl, false, false, GROUP_NONE, GROUP_NONE),
ELEM(markupDecl, false, false, GROUP_NONE, GROUP_NONE),
ELEM(instruction, false, false, GROUP_NONE, GROUP_NONE),
ELEM(userdefined, true, false, GROUP_NONE, GROUP_FLOW_ELEMENT)
};
bool
-nsHTMLEditUtils::CanContain(int32_t aParent, int32_t aChild)
+HTMLEditUtils::CanContain(int32_t aParent, int32_t aChild)
{
NS_ASSERTION(aParent > eHTMLTag_unknown && aParent <= eHTMLTag_userdefined,
"aParent out of range!");
NS_ASSERTION(aChild > eHTMLTag_unknown && aChild <= eHTMLTag_userdefined,
"aChild out of range!");
#ifdef DEBUG
static bool checked = false;
@@ -833,25 +817,27 @@ nsHTMLEditUtils::CanContain(int32_t aPar
return false;
}
// Bug #67007, dont strip userdefined tags.
if (aChild == eHTMLTag_userdefined) {
return true;
}
- const nsElementInfo& parent = kElements[aParent - 1];
+ const ElementInfo& parent = kElements[aParent - 1];
if (aParent == aChild) {
return parent.mCanContainSelf;
}
- const nsElementInfo& child = kElements[aChild - 1];
+ const ElementInfo& child = kElements[aChild - 1];
return (parent.mCanContainGroups & child.mGroup) != 0;
}
bool
-nsHTMLEditUtils::IsContainer(int32_t aTag)
+HTMLEditUtils::IsContainer(int32_t aTag)
{
NS_ASSERTION(aTag > eHTMLTag_unknown && aTag <= eHTMLTag_userdefined,
"aTag out of range!");
return kElements[aTag - 1].mIsContainer;
}
+
+} // namespace mozilla
rename from editor/libeditor/nsHTMLEditUtils.h
rename to editor/libeditor/HTMLEditUtils.h
--- a/editor/libeditor/nsHTMLEditUtils.h
+++ b/editor/libeditor/HTMLEditUtils.h
@@ -1,65 +1,69 @@
/* -*- 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 nsHTMLEditUtils_h__
-#define nsHTMLEditUtils_h__
+#ifndef HTMLEditUtils_h
+#define HTMLEditUtils_h
#include <stdint.h>
class nsIDOMNode;
class nsINode;
-class nsHTMLEditUtils
+namespace mozilla {
+
+class HTMLEditUtils final
{
public:
// from nsHTMLEditRules:
static bool IsInlineStyle(nsINode* aNode);
static bool IsInlineStyle(nsIDOMNode *aNode);
static bool IsFormatNode(nsINode* aNode);
- static bool IsFormatNode(nsIDOMNode *aNode);
- static bool IsNodeThatCanOutdent(nsIDOMNode *aNode);
+ static bool IsFormatNode(nsIDOMNode* aNode);
+ static bool IsNodeThatCanOutdent(nsIDOMNode* aNode);
static bool IsHeader(nsINode& aNode);
- static bool IsHeader(nsIDOMNode *aNode);
- static bool IsParagraph(nsIDOMNode *aNode);
- static bool IsHR(nsIDOMNode *aNode);
+ static bool IsHeader(nsIDOMNode* aNode);
+ static bool IsParagraph(nsIDOMNode* aNode);
+ static bool IsHR(nsIDOMNode* aNode);
static bool IsListItem(nsINode* aNode);
- static bool IsListItem(nsIDOMNode *aNode);
- static bool IsTable(nsIDOMNode *aNode);
+ static bool IsListItem(nsIDOMNode* aNode);
+ static bool IsTable(nsIDOMNode* aNode);
static bool IsTable(nsINode* aNode);
- static bool IsTableRow(nsIDOMNode *aNode);
+ static bool IsTableRow(nsIDOMNode* aNode);
static bool IsTableElement(nsINode* aNode);
- static bool IsTableElement(nsIDOMNode *aNode);
+ static bool IsTableElement(nsIDOMNode* aNode);
static bool IsTableElementButNotTable(nsINode* aNode);
- static bool IsTableElementButNotTable(nsIDOMNode *aNode);
+ static bool IsTableElementButNotTable(nsIDOMNode* aNode);
static bool IsTableCell(nsINode* node);
- static bool IsTableCell(nsIDOMNode *aNode);
+ static bool IsTableCell(nsIDOMNode* aNode);
static bool IsTableCellOrCaption(nsINode& aNode);
static bool IsList(nsINode* aNode);
- static bool IsList(nsIDOMNode *aNode);
- static bool IsOrderedList(nsIDOMNode *aNode);
- static bool IsUnorderedList(nsIDOMNode *aNode);
- static bool IsBlockquote(nsIDOMNode *aNode);
- static bool IsPre(nsIDOMNode *aNode);
- static bool IsAnchor(nsIDOMNode *aNode);
+ static bool IsList(nsIDOMNode* aNode);
+ static bool IsOrderedList(nsIDOMNode* aNode);
+ static bool IsUnorderedList(nsIDOMNode* aNode);
+ static bool IsBlockquote(nsIDOMNode* aNode);
+ static bool IsPre(nsIDOMNode* aNode);
+ static bool IsAnchor(nsIDOMNode* aNode);
static bool IsImage(nsINode* aNode);
- static bool IsImage(nsIDOMNode *aNode);
- static bool IsLink(nsIDOMNode *aNode);
+ static bool IsImage(nsIDOMNode* aNode);
+ static bool IsLink(nsIDOMNode* aNode);
static bool IsLink(nsINode* aNode);
static bool IsNamedAnchor(nsINode* aNode);
- static bool IsNamedAnchor(nsIDOMNode *aNode);
- static bool IsDiv(nsIDOMNode *aNode);
+ static bool IsNamedAnchor(nsIDOMNode* aNode);
+ static bool IsDiv(nsIDOMNode* aNode);
static bool IsMozDiv(nsINode* aNode);
- static bool IsMozDiv(nsIDOMNode *aNode);
+ static bool IsMozDiv(nsIDOMNode* aNode);
static bool IsMailCite(nsINode* aNode);
- static bool IsMailCite(nsIDOMNode *aNode);
+ static bool IsMailCite(nsIDOMNode* aNode);
static bool IsFormWidget(nsINode* aNode);
- static bool IsFormWidget(nsIDOMNode *aNode);
- static bool SupportsAlignAttr(nsIDOMNode *aNode);
+ static bool IsFormWidget(nsIDOMNode* aNode);
+ static bool SupportsAlignAttr(nsIDOMNode* aNode);
static bool CanContain(int32_t aParent, int32_t aChild);
static bool IsContainer(int32_t aTag);
};
-#endif /* nsHTMLEditUtils_h__ */
+} // namespace mozilla
+#endif // #ifndef HTMLEditUtils_h
+
--- a/editor/libeditor/moz.build
+++ b/editor/libeditor/moz.build
@@ -18,33 +18,33 @@ UNIFIED_SOURCES += [
'ChangeStyleTxn.cpp',
'CreateElementTxn.cpp',
'DeleteNodeTxn.cpp',
'DeleteRangeTxn.cpp',
'DeleteTextTxn.cpp',
'EditAggregateTxn.cpp',
'EditorUtils.cpp',
'EditTxn.cpp',
+ 'HTMLEditUtils.cpp',
'IMETextTxn.cpp',
'InsertNodeTxn.cpp',
'InsertTextTxn.cpp',
'JoinNodeTxn.cpp',
'nsEditor.cpp',
'nsEditorCommands.cpp',
'nsEditorController.cpp',
'nsEditorEventListener.cpp',
'nsHTMLAbsPosition.cpp',
'nsHTMLAnonymousUtils.cpp',
'nsHTMLCSSUtils.cpp',
'nsHTMLDataTransfer.cpp',
'nsHTMLEditor.cpp',
'nsHTMLEditorEventListener.cpp',
'nsHTMLEditorStyle.cpp',
'nsHTMLEditRules.cpp',
- 'nsHTMLEditUtils.cpp',
'nsHTMLInlineTableEditor.cpp',
'nsHTMLObjectResizer.cpp',
'nsHTMLURIRefObject.cpp',
'nsInternetCiter.cpp',
'nsPlaintextDataTransfer.cpp',
'nsPlaintextEditor.cpp',
'nsSelectionState.cpp',
'nsStyleSheetTxns.cpp',
--- a/editor/libeditor/nsHTMLAbsPosition.cpp
+++ b/editor/libeditor/nsHTMLAbsPosition.cpp
@@ -1,32 +1,32 @@
/* 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 <math.h>
#include "EditorUtils.h"
+#include "HTMLEditUtils.h"
#include "TextEditUtils.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#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 "nsHTMLEditUtils.h"
#include "nsHTMLEditor.h"
#include "nsHTMLObjectResizer.h"
#include "nsIContent.h"
#include "nsROCSSPrimitiveValue.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventListener.h"
#include "nsIDOMEventTarget.h"
@@ -514,17 +514,17 @@ nsHTMLEditor::AbsolutelyPositionElement(
EmptyString());
mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::top,
EmptyString());
mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::left,
EmptyString());
mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::z_index,
EmptyString());
- if (!nsHTMLEditUtils::IsImage(aElement)) {
+ if (!HTMLEditUtils::IsImage(aElement)) {
mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::width,
EmptyString());
mHTMLCSSUtils->RemoveCSSProperty(*element, *nsGkAtoms::height,
EmptyString());
}
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
if (element && element->IsHTMLElement(nsGkAtoms::div) &&
--- a/editor/libeditor/nsHTMLCSSUtils.cpp
+++ b/editor/libeditor/nsHTMLCSSUtils.cpp
@@ -334,17 +334,17 @@ nsHTMLCSSUtils::IsCSSEditableProperty(ns
nsGkAtoms::h4,
nsGkAtoms::h5,
nsGkAtoms::h6,
nsGkAtoms::td,
nsGkAtoms::th,
nsGkAtoms::table,
nsGkAtoms::hr,
// For the above, why not use
- // nsHTMLEditUtils::SupportsAlignAttr?
+ // HTMLEditUtils::SupportsAlignAttr?
// It also checks for tbody, tfoot, thead.
// Let's add the following elements here even
// if "align" has a different meaning for them
nsGkAtoms::legend,
nsGkAtoms::caption)) {
return true;
}
--- a/editor/libeditor/nsHTMLDataTransfer.cpp
+++ b/editor/libeditor/nsHTMLDataTransfer.cpp
@@ -2,16 +2,17 @@
/* vim: set ts=2 sw=2 et tw=78: */
/* 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 <string.h>
#include "EditorUtils.h"
+#include "HTMLEditUtils.h"
#include "TextEditUtils.h"
#include "mozilla/dom/DataTransfer.h"
#include "mozilla/dom/DocumentFragment.h"
#include "mozilla/dom/DOMStringList.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/Base64.h"
#include "mozilla/BasicEvents.h"
@@ -25,17 +26,16 @@
#include "nsIScriptError.h"
#include "nsContentUtils.h"
#include "nsDebug.h"
#include "nsDependentSubstring.h"
#include "nsEditRules.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLEditUtils.h"
#include "nsHTMLEditor.h"
#include "nsIClipboard.h"
#include "nsIContent.h"
#include "nsIContentFilter.h"
#include "nsIDOMComment.h"
#include "nsIDOMDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIDOMElement.h"
@@ -327,17 +327,17 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
if (cellSelectionMode)
{
// do we have table content to paste? If so, we want to delete
// the selected table cells and replace with new table elements;
// but if not we want to delete _contents_ of cells and replace
// with non-table elements. Use cellSelectionMode bool to
// indicate results.
- if (!nsHTMLEditUtils::IsTableElement(nodeList[0])) {
+ if (!HTMLEditUtils::IsTableElement(nodeList[0])) {
cellSelectionMode = false;
}
}
if (!cellSelectionMode)
{
rv = DeleteSelectionAndPrepareToCreateNode();
NS_ENSURE_SUCCESS(rv, rv);
@@ -481,19 +481,20 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
if (EditorUtils::IsDescendantOf(curNode, insertedContextParent)) {
continue;
}
}
// give the user a hand on table element insertion. if they have
// a table or table row on the clipboard, and are trying to insert
// into a table or table row, insert the appropriate children instead.
- if ( (nsHTMLEditUtils::IsTableRow(curNode) && nsHTMLEditUtils::IsTableRow(parentNode))
- && (nsHTMLEditUtils::IsTable(curNode) || nsHTMLEditUtils::IsTable(parentNode)) )
- {
+ if (HTMLEditUtils::IsTableRow(curNode) &&
+ HTMLEditUtils::IsTableRow(parentNode) &&
+ (HTMLEditUtils::IsTable(curNode) ||
+ HTMLEditUtils::IsTable(parentNode))) {
nsCOMPtr<nsIDOMNode> child;
curNode->GetFirstChild(getter_AddRefs(child));
while (child)
{
rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
if (NS_FAILED(rv))
break;
@@ -503,29 +504,28 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
curNode->GetFirstChild(getter_AddRefs(child));
}
}
// give the user a hand on list insertion. if they have
// a list on the clipboard, and are trying to insert
// into a list or list item, insert the appropriate children instead,
// ie, merge the lists instead of pasting in a sublist.
- else if (nsHTMLEditUtils::IsList(curNode) &&
- (nsHTMLEditUtils::IsList(parentNode) || nsHTMLEditUtils::IsListItem(parentNode)) )
- {
+ else if (HTMLEditUtils::IsList(curNode) &&
+ (HTMLEditUtils::IsList(parentNode) ||
+ HTMLEditUtils::IsListItem(parentNode))) {
nsCOMPtr<nsIDOMNode> child, tmp;
curNode->GetFirstChild(getter_AddRefs(child));
while (child)
{
- if (nsHTMLEditUtils::IsListItem(child) || nsHTMLEditUtils::IsList(child))
- {
+ if (HTMLEditUtils::IsListItem(child) ||
+ HTMLEditUtils::IsList(child)) {
// Check if we are pasting into empty list item. If so
// delete it and paste into parent list instead.
- if (nsHTMLEditUtils::IsListItem(parentNode))
- {
+ if (HTMLEditUtils::IsListItem(parentNode)) {
bool isEmpty;
rv = IsEmptyNode(parentNode, &isEmpty, true);
if (NS_SUCCEEDED(rv) && isEmpty)
{
int32_t newOffset;
nsCOMPtr<nsIDOMNode> listNode = GetNodeLocation(parentNode, &newOffset);
if (listNode)
{
@@ -545,18 +545,18 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
}
else
{
curNode->RemoveChild(child, getter_AddRefs(tmp));
}
curNode->GetFirstChild(getter_AddRefs(child));
}
- } else if (parentBlock && nsHTMLEditUtils::IsPre(parentBlock) &&
- nsHTMLEditUtils::IsPre(curNode)) {
+ } else if (parentBlock && HTMLEditUtils::IsPre(parentBlock) &&
+ HTMLEditUtils::IsPre(curNode)) {
// Check for pre's going into pre's.
nsCOMPtr<nsIDOMNode> child, tmp;
curNode->GetFirstChild(getter_AddRefs(child));
while (child)
{
rv = InsertNodeAtPoint(child, address_of(parentNode), &offsetOfNewNode, true);
if (NS_FAILED(rv))
break;
@@ -607,37 +607,37 @@ nsHTMLEditor::DoInsertHTMLWithContext(co
// Now collapse the selection to the end of what we just inserted:
if (lastInsertNode)
{
// set selection to the end of what we just pasted.
nsCOMPtr<nsIDOMNode> selNode, tmp, highTable;
int32_t selOffset;
// but don't cross tables
- if (!nsHTMLEditUtils::IsTable(lastInsertNode))
- {
+ if (!HTMLEditUtils::IsTable(lastInsertNode)) {
nsCOMPtr<nsINode> lastInsertNode_ = do_QueryInterface(lastInsertNode);
NS_ENSURE_STATE(lastInsertNode_ || !lastInsertNode);
selNode = GetAsDOMNode(GetLastEditableLeaf(*lastInsertNode_));
tmp = selNode;
while (tmp && (tmp != lastInsertNode))
{
- if (nsHTMLEditUtils::IsTable(tmp))
+ if (HTMLEditUtils::IsTable(tmp)) {
highTable = tmp;
+ }
nsCOMPtr<nsIDOMNode> parent = tmp;
tmp->GetParentNode(getter_AddRefs(parent));
tmp = parent;
}
if (highTable)
selNode = highTable;
}
if (!selNode)
selNode = lastInsertNode;
- if (IsTextNode(selNode) || (IsContainer(selNode) && !nsHTMLEditUtils::IsTable(selNode)))
- {
+ if (IsTextNode(selNode) ||
+ (IsContainer(selNode) && !HTMLEditUtils::IsTable(selNode))) {
rv = GetLengthOfDOMNode(selNode, (uint32_t&)selOffset);
NS_ENSURE_SUCCESS(rv, rv);
}
else // we need to find a container for selection. Look up.
{
tmp = selNode;
selNode = GetNodeLocation(tmp, &selOffset);
// selNode might be null in case a mutation listener removed
@@ -764,18 +764,17 @@ bool
nsHTMLEditor::IsInLink(nsIDOMNode *aNode, nsCOMPtr<nsIDOMNode> *outLink)
{
NS_ENSURE_TRUE(aNode, false);
if (outLink)
*outLink = nullptr;
nsCOMPtr<nsIDOMNode> tmp, node = aNode;
while (node)
{
- if (nsHTMLEditUtils::IsLink(node))
- {
+ if (HTMLEditUtils::IsLink(node)) {
if (outLink)
*outLink = node;
return true;
}
tmp = node;
tmp->GetParentNode(getter_AddRefs(node));
}
return false;
@@ -783,17 +782,17 @@ nsHTMLEditor::IsInLink(nsIDOMNode *aNode
nsresult
nsHTMLEditor::StripFormattingNodes(nsIContent& aNode, bool aListOnly)
{
if (aNode.TextIsOnlyWhitespace()) {
nsCOMPtr<nsINode> parent = aNode.GetParentNode();
if (parent) {
- if (!aListOnly || nsHTMLEditUtils::IsList(parent)) {
+ if (!aListOnly || HTMLEditUtils::IsList(parent)) {
ErrorResult rv;
parent->RemoveChild(aNode, rv);
return rv.StealNSResult();
}
return NS_OK;
}
}
@@ -2270,51 +2269,51 @@ nsHTMLEditor::GetListAndTableParents(Sta
MOZ_ASSERT(aNodeList.Length());
// Build up list of parents of first (or last) node in list that are either
// lists, or tables.
int32_t idx = aStartOrEnd == StartOrEnd::end ? aNodeList.Length() - 1 : 0;
for (nsCOMPtr<nsINode> node = aNodeList[idx]; node;
node = node->GetParentNode()) {
- if (nsHTMLEditUtils::IsList(node) || nsHTMLEditUtils::IsTable(node)) {
+ if (HTMLEditUtils::IsList(node) || HTMLEditUtils::IsTable(node)) {
outArray.AppendElement(*node->AsElement());
}
}
}
int32_t
nsHTMLEditor::DiscoverPartialListsAndTables(nsTArray<OwningNonNull<nsINode>>& aPasteNodes,
nsTArray<OwningNonNull<Element>>& aListsAndTables)
{
int32_t ret = -1;
int32_t listAndTableParents = aListsAndTables.Length();
// Scan insertion list for table elements (other than table).
for (auto& curNode : aPasteNodes) {
- if (nsHTMLEditUtils::IsTableElement(curNode) &&
+ if (HTMLEditUtils::IsTableElement(curNode) &&
!curNode->IsHTMLElement(nsGkAtoms::table)) {
nsCOMPtr<Element> table = curNode->GetParentElement();
while (table && !table->IsHTMLElement(nsGkAtoms::table)) {
table = table->GetParentElement();
}
if (table) {
int32_t idx = aListsAndTables.IndexOf(table);
if (idx == -1) {
return ret;
}
ret = idx;
if (ret == listAndTableParents - 1) {
return ret;
}
}
}
- if (nsHTMLEditUtils::IsListItem(curNode)) {
+ if (HTMLEditUtils::IsListItem(curNode)) {
nsCOMPtr<Element> list = curNode->GetParentElement();
- while (list && !nsHTMLEditUtils::IsList(list)) {
+ while (list && !HTMLEditUtils::IsList(list)) {
list = list->GetParentElement();
}
if (list) {
int32_t idx = aListsAndTables.IndexOf(list);
if (idx == -1) {
return ret;
}
ret = idx;
@@ -2329,26 +2328,26 @@ nsHTMLEditor::DiscoverPartialListsAndTab
nsINode*
nsHTMLEditor::ScanForListAndTableStructure(StartOrEnd aStartOrEnd,
nsTArray<OwningNonNull<nsINode>>& aNodes,
Element& aListOrTable)
{
// Look upward from first/last paste node for a piece of this list/table
int32_t idx = aStartOrEnd == StartOrEnd::end ? aNodes.Length() - 1 : 0;
- bool isList = nsHTMLEditUtils::IsList(&aListOrTable);
+ bool isList = HTMLEditUtils::IsList(&aListOrTable);
for (nsCOMPtr<nsINode> node = aNodes[idx]; node;
node = node->GetParentNode()) {
- if ((isList && nsHTMLEditUtils::IsListItem(node)) ||
- (!isList && nsHTMLEditUtils::IsTableElement(node) &&
+ if ((isList && HTMLEditUtils::IsListItem(node)) ||
+ (!isList && HTMLEditUtils::IsTableElement(node) &&
!node->IsHTMLElement(nsGkAtoms::table))) {
nsCOMPtr<Element> structureNode = node->GetParentElement();
if (isList) {
- while (structureNode && !nsHTMLEditUtils::IsList(structureNode)) {
+ while (structureNode && !HTMLEditUtils::IsList(structureNode)) {
structureNode = structureNode->GetParentElement();
}
} else {
while (structureNode &&
!structureNode->IsHTMLElement(nsGkAtoms::table)) {
structureNode = structureNode->GetParentElement();
}
}
--- a/editor/libeditor/nsHTMLEditRules.cpp
+++ b/editor/libeditor/nsHTMLEditRules.cpp
@@ -4,16 +4,17 @@
* 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 "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"
#include "mozilla/OwningNonNull.h"
#include "mozilla/mozalloc.h"
@@ -24,17 +25,16 @@
#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 "nsHTMLEditUtils.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"
@@ -104,57 +104,56 @@ IsStyleCachePreservingAction(EditAction
action == EditAction::removeList ||
action == EditAction::makeDefListItem ||
action == EditAction::insertElement ||
action == EditAction::insertQuotation;
}
class nsTableCellAndListItemFunctor : public mozilla::BoolDomIterFunctor
{
- public:
- // Used to build list of all li's, td's & th's iterator covers
- virtual bool operator()(nsINode* aNode) const
- {
- if (nsHTMLEditUtils::IsTableCell(aNode)) return true;
- if (nsHTMLEditUtils::IsListItem(aNode)) return true;
- return false;
- }
+public:
+ // Used to build list of all li's, td's & th's iterator covers
+ virtual bool operator()(nsINode* aNode) const
+ {
+ return HTMLEditUtils::IsTableCell(aNode) ||
+ HTMLEditUtils::IsListItem(aNode);
+ }
};
class nsBRNodeFunctor : public mozilla::BoolDomIterFunctor
{
public:
virtual bool operator()(nsINode* aNode) const
{
if (aNode->IsHTMLElement(nsGkAtoms::br)) {
return true;
}
return false;
}
};
class nsEmptyEditableFunctor : public mozilla::BoolDomIterFunctor
{
- public:
- explicit nsEmptyEditableFunctor(nsHTMLEditor* editor) : mHTMLEditor(editor) {}
- virtual bool operator()(nsINode* aNode) const
- {
- if (mHTMLEditor->IsEditable(aNode) &&
- (nsHTMLEditUtils::IsListItem(aNode) ||
- nsHTMLEditUtils::IsTableCellOrCaption(*aNode))) {
- bool bIsEmptyNode;
- nsresult res = mHTMLEditor->IsEmptyNode(aNode, &bIsEmptyNode, false, false);
- NS_ENSURE_SUCCESS(res, false);
- if (bIsEmptyNode)
- return true;
- }
- return false;
- }
- protected:
- nsHTMLEditor* mHTMLEditor;
+public:
+ explicit nsEmptyEditableFunctor(nsHTMLEditor* editor) : mHTMLEditor(editor) {}
+ virtual bool operator()(nsINode* aNode) const
+ {
+ if (mHTMLEditor->IsEditable(aNode) &&
+ (HTMLEditUtils::IsListItem(aNode) ||
+ HTMLEditUtils::IsTableCellOrCaption(*aNode))) {
+ bool bIsEmptyNode;
+ nsresult res = mHTMLEditor->IsEmptyNode(aNode, &bIsEmptyNode, false, false);
+ NS_ENSURE_SUCCESS(res, false);
+ if (bIsEmptyNode)
+ return true;
+ }
+ return false;
+ }
+protected:
+ nsHTMLEditor* mHTMLEditor;
};
class nsEditableTextFunctor : public mozilla::BoolDomIterFunctor
{
public:
explicit nsEditableTextFunctor(nsHTMLEditor* editor) : mHTMLEditor(editor) {}
virtual bool operator()(nsINode* aNode) const
{
@@ -900,17 +899,17 @@ nsHTMLEditRules::GetAlignment(bool* aMix
for (; nodeToExamine; nodeToExamine = nodeToExamine->GetParentNode()) {
if (!isFirstNodeToExamine &&
nodeToExamine->IsHTMLElement(nsGkAtoms::table)) {
// The node to examine is a table and this is not the first node we
// examine; let's break here to materialize the 'inline-block' behaviour
// of html tables regarding to text alignment
return NS_OK;
}
- if (nsHTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(nodeToExamine))) {
+ if (HTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(nodeToExamine))) {
// Check for alignment
nsAutoString typeAttrVal;
nodeToExamine->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::align,
typeAttrVal);
ToLowerCase(typeAttrVal);
if (!typeAttrVal.IsEmpty()) {
if (typeAttrVal.EqualsLiteral("center")) {
*aAlign = nsIHTMLEditor::eCenter;
@@ -956,17 +955,17 @@ nsHTMLEditRules::GetIndentState(bool *aC
NS_ENSURE_SUCCESS(res, res);
// examine nodes in selection for blockquotes or list elements;
// these we can outdent. Note that we return true for canOutdent
// if *any* of the selection is outdentable, rather than all of it.
NS_ENSURE_STATE(mHTMLEditor);
bool useCSS = mHTMLEditor->IsCSSEnabled();
for (auto& curNode : Reversed(arrayOfNodes)) {
- if (nsHTMLEditUtils::IsNodeThatCanOutdent(GetAsDOMNode(curNode))) {
+ 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);
@@ -1004,33 +1003,31 @@ nsHTMLEditRules::GetIndentState(bool *aC
NS_ENSURE_TRUE(selection, NS_ERROR_NULL_POINTER);
// test start parent hierarchy
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetStartNodeAndOffset(selection, getter_AddRefs(parent), &selOffset);
NS_ENSURE_SUCCESS(res, res);
while (parent && (parent!=root))
{
- if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent))
- {
+ if (HTMLEditUtils::IsNodeThatCanOutdent(parent)) {
*aCanOutdent = true;
break;
}
tmp=parent;
tmp->GetParentNode(getter_AddRefs(parent));
}
// test end parent hierarchy
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetEndNodeAndOffset(selection, getter_AddRefs(parent), &selOffset);
NS_ENSURE_SUCCESS(res, res);
while (parent && (parent!=root))
{
- if (nsHTMLEditUtils::IsNodeThatCanOutdent(parent))
- {
+ if (HTMLEditUtils::IsNodeThatCanOutdent(parent)) {
*aCanOutdent = true;
break;
}
tmp=parent;
tmp->GetParentNode(getter_AddRefs(parent));
}
}
return res;
@@ -1056,17 +1053,17 @@ nsHTMLEditRules::GetParagraphState(bool
// post process list. We need to replace any block nodes that are not format
// nodes with their content. This is so we only have to look "up" the hierarchy
// to find format nodes, instead of both up and down.
for (int32_t i = arrayOfNodes.Length() - 1; i >= 0; i--) {
auto& curNode = arrayOfNodes[i];
nsAutoString format;
// if it is a known format node we have it easy
- if (IsBlockNode(curNode) && !nsHTMLEditUtils::IsFormatNode(curNode)) {
+ if (IsBlockNode(curNode) && !HTMLEditUtils::IsFormatNode(curNode)) {
// arrayOfNodes.RemoveObject(curNode);
res = AppendInnerFormatNodes(arrayOfNodes, curNode);
NS_ENSURE_SUCCESS(res, res);
}
}
// we might have an empty node list. if so, find selection parent
// and put that on the list
@@ -1087,38 +1084,35 @@ nsHTMLEditRules::GetParagraphState(bool
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIDOMElement> rootElem = do_QueryInterface(mHTMLEditor->GetRoot());
NS_ENSURE_TRUE(rootElem, NS_ERROR_NULL_POINTER);
// loop through the nodes in selection and examine their paragraph format
for (auto& curNode : Reversed(arrayOfNodes)) {
nsAutoString format;
// if it is a known format node we have it easy
- if (nsHTMLEditUtils::IsFormatNode(curNode)) {
+ if (HTMLEditUtils::IsFormatNode(curNode)) {
GetFormatString(GetAsDOMNode(curNode), format);
} else if (IsBlockNode(curNode)) {
// this is a div or some other non-format block.
// we should ignore it. Its children were appended to this list
// by AppendInnerFormatNodes() call above. We will get needed
// info when we examine them instead.
continue;
}
else
{
nsCOMPtr<nsIDOMNode> node, tmp = GetAsDOMNode(curNode);
tmp->GetParentNode(getter_AddRefs(node));
while (node)
{
- if (node == rootElem)
- {
+ if (node == rootElem) {
format.Truncate(0);
break;
- }
- else if (nsHTMLEditUtils::IsFormatNode(node))
- {
+ } else if (HTMLEditUtils::IsFormatNode(node)) {
GetFormatString(node, format);
break;
}
// else keep looking up
tmp = node;
tmp->GetParentNode(getter_AddRefs(node));
}
}
@@ -1149,17 +1143,17 @@ nsHTMLEditRules::AppendInnerFormatNodes(
// the list. They are all the same for purposes of determining
// paragraph style. We use foundInline to track this as we are
// going through the children in the loop below.
bool foundInline = false;
for (nsIContent* child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
bool isBlock = IsBlockNode(*child);
- bool isFormat = nsHTMLEditUtils::IsFormatNode(child);
+ bool isFormat = HTMLEditUtils::IsFormatNode(child);
if (isBlock && !isFormat) {
// if it's a div, etc, recurse
AppendInnerFormatNodes(aArray, child);
} else if (isFormat) {
aArray.AppendElement(*child);
} else if (!foundInline) {
// if this is the first inline we've found, use it
foundInline = true;
@@ -1169,18 +1163,17 @@ nsHTMLEditRules::AppendInnerFormatNodes(
return NS_OK;
}
nsresult
nsHTMLEditRules::GetFormatString(nsIDOMNode *aNode, nsAString &outFormat)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
- if (nsHTMLEditUtils::IsFormatNode(aNode))
- {
+ if (HTMLEditUtils::IsFormatNode(aNode)) {
nsCOMPtr<nsIAtom> atom = nsEditor::GetTag(aNode);
atom->ToString(outFormat);
}
else
outFormat.Truncate();
return NS_OK;
}
@@ -1567,17 +1560,17 @@ nsHTMLEditRules::WillInsertBreak(Selecti
NS_ENSURE_STATE(br);
}
nsCOMPtr<Element> listItem = IsInListItem(blockParent);
if (listItem && listItem != host) {
ReturnInListItem(aSelection, *listItem, node, offset);
*aHandled = true;
return NS_OK;
- } else if (nsHTMLEditUtils::IsHeader(*blockParent)) {
+ } else if (HTMLEditUtils::IsHeader(*blockParent)) {
// Headers: close (or split) header
ReturnInHeader(aSelection, *blockParent, node, offset);
*aHandled = true;
return NS_OK;
} else if (blockParent->IsHTMLElement(nsGkAtoms::p)) {
// Paragraphs: special rules to look for <br>s
res = ReturnInParagraph(&aSelection, GetAsDOMNode(blockParent),
GetAsDOMNode(node), offset, aCancel, aHandled);
@@ -2102,17 +2095,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel
res = InsertBRIfNeeded(aSelection);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
if (wsType == WSType::otherBlock) {
// Make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
- if (nsHTMLEditUtils::IsTableElement(visNode)) {
+ if (HTMLEditUtils::IsTableElement(visNode)) {
*aCancel = true;
return NS_OK;
}
// Next to a block. See if we are between a block and a br. If so, we
// really want to delete the br. Else join content at selection to the
// block.
bool bDeletedBR = false;
@@ -2187,17 +2180,17 @@ nsHTMLEditRules::WillDeleteSelection(Sel
}
if (wsType == WSType::thisBlock) {
// At edge of our block. Look beside it and see if we can join to an
// adjacent block
// Make sure it's not a table element. If so, cancel the operation
// (translation: users cannot backspace or delete across table cells)
- if (nsHTMLEditUtils::IsTableElement(visNode)) {
+ if (HTMLEditUtils::IsTableElement(visNode)) {
*aCancel = true;
return NS_OK;
}
// First find the relevant nodes
nsCOMPtr<nsINode> leftNode, rightNode;
if (aAction == nsIEditor::ePrevious) {
NS_ENSURE_STATE(mHTMLEditor);
@@ -2326,18 +2319,18 @@ nsHTMLEditRules::WillDeleteSelection(Sel
EditorDOMPoint pt =
mHTMLEditor->JoinNodeDeep(*leftParent, *rightParent);
NS_ENSURE_STATE(pt.node);
// Fix up selection
res = aSelection->Collapse(pt.node, pt.offset);
NS_ENSURE_SUCCESS(res, res);
return NS_OK;
}
- if (nsHTMLEditUtils::IsListItem(leftParent) ||
- nsHTMLEditUtils::IsHeader(*leftParent)) {
+ if (HTMLEditUtils::IsListItem(leftParent) ||
+ HTMLEditUtils::IsHeader(*leftParent)) {
// First delete the selection
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteSelectionImpl(aAction, aStripWrappers);
NS_ENSURE_SUCCESS(res, res);
// Join blocks
NS_ENSURE_STATE(mHTMLEditor);
EditorDOMPoint pt =
mHTMLEditor->JoinNodeDeep(*leftParent, *rightParent);
@@ -2564,18 +2557,18 @@ nsHTMLEditRules::JoinBlocks(nsIContent&
nsCOMPtr<Element> leftBlock = mHTMLEditor->GetBlock(aLeftNode);
nsCOMPtr<Element> rightBlock = mHTMLEditor->GetBlock(aRightNode);
// Sanity checks
NS_ENSURE_TRUE(leftBlock && rightBlock, NS_ERROR_NULL_POINTER);
NS_ENSURE_STATE(leftBlock != rightBlock);
- if (nsHTMLEditUtils::IsTableElement(leftBlock) ||
- nsHTMLEditUtils::IsTableElement(rightBlock)) {
+ if (HTMLEditUtils::IsTableElement(leftBlock) ||
+ HTMLEditUtils::IsTableElement(rightBlock)) {
// Do not try to merge table elements
*aCanceled = true;
return NS_OK;
}
// Make sure we don't try to move things into HR's, which look like blocks
// but aren't containers
if (leftBlock->IsHTMLElement(nsGkAtoms::hr)) {
@@ -2588,30 +2581,30 @@ nsHTMLEditRules::JoinBlocks(nsIContent&
// Bail if both blocks the same
if (leftBlock == rightBlock) {
*aCanceled = true;
return NS_OK;
}
// Joining a list item to its parent is a NOP.
- if (nsHTMLEditUtils::IsList(leftBlock) &&
- nsHTMLEditUtils::IsListItem(rightBlock) &&
+ if (HTMLEditUtils::IsList(leftBlock) &&
+ HTMLEditUtils::IsListItem(rightBlock) &&
rightBlock->GetParentNode() == leftBlock) {
return NS_OK;
}
// Special rule here: if we are trying to join list items, and they are in
// different lists, join the lists instead.
bool mergeLists = false;
nsIAtom* existingList = nsGkAtoms::_empty;
int32_t offset;
nsCOMPtr<Element> leftList, rightList;
- if (nsHTMLEditUtils::IsListItem(leftBlock) &&
- nsHTMLEditUtils::IsListItem(rightBlock)) {
+ if (HTMLEditUtils::IsListItem(leftBlock) &&
+ HTMLEditUtils::IsListItem(rightBlock)) {
leftList = leftBlock->GetParentElement();
rightList = rightBlock->GetParentElement();
if (leftList && rightList && leftList != rightList &&
!EditorUtils::IsDescendantOf(leftList, rightBlock, &offset) &&
!EditorUtils::IsDescendantOf(rightList, leftBlock, &offset)) {
// There are some special complications if the lists are descendants of
// the other lists' items. Note that it is okay for them to be
// descendants of the other lists themselves, which is the usual case for
@@ -2895,17 +2888,17 @@ nsHTMLEditRules::MoveContents(Element& a
return NS_OK;
}
nsresult
nsHTMLEditRules::DeleteNonTableElements(nsINode* aNode)
{
MOZ_ASSERT(aNode);
- if (!nsHTMLEditUtils::IsTableElementButNotTable(aNode)) {
+ if (!HTMLEditUtils::IsTableElementButNotTable(aNode)) {
NS_ENSURE_STATE(mHTMLEditor);
return mHTMLEditor->DeleteNode(aNode->AsDOMNode());
}
for (int32_t i = aNode->GetChildCount() - 1; i >= 0; --i) {
nsresult rv = DeleteNonTableElements(aNode->GetChildAt(i));
NS_ENSURE_SUCCESS(rv, rv);
}
@@ -3096,17 +3089,17 @@ nsHTMLEditRules::WillMakeList(Selection*
} else if (IsEmptyInline(curNode)) {
// if curNode is an empty inline container, delete it
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->DeleteNode(curNode);
NS_ENSURE_SUCCESS(res, res);
continue;
}
- if (nsHTMLEditUtils::IsList(curNode)) {
+ if (HTMLEditUtils::IsList(curNode)) {
// do we have a curList already?
if (curList && !EditorUtils::IsDescendantOf(curNode, curList)) {
// move all of our children into curList. cheezy way to do it: move
// whole list and then RemoveContainer() on the list. ConvertListType
// first: that routine handles converting the list item types, if
// needed
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, curList, -1);
@@ -3123,17 +3116,17 @@ nsHTMLEditRules::WillMakeList(Selection*
listType, itemType);
NS_ENSURE_SUCCESS(res, res);
curList = newBlock;
}
prevListItem = 0;
continue;
}
- if (nsHTMLEditUtils::IsListItem(curNode)) {
+ if (HTMLEditUtils::IsListItem(curNode)) {
NS_ENSURE_STATE(mHTMLEditor);
if (!curParent->IsHTMLElement(listType)) {
// list item is in wrong type of list. if we don't have a curList,
// split the old list and make a new list of correct type.
if (!curList || EditorUtils::IsDescendantOf(curNode, curList)) {
NS_ENSURE_STATE(mHTMLEditor);
NS_ENSURE_STATE(curParent->IsContent());
ErrorResult rv;
@@ -3215,17 +3208,17 @@ nsHTMLEditRules::WillMakeList(Selection*
// remember our new block for postprocessing
mNewBlock = curList;
// curList is now the correct thing to put curNode in
prevListItem = 0;
}
// if curNode isn't a list item, we must wrap it in one
nsCOMPtr<Element> listItem;
- if (!nsHTMLEditUtils::IsListItem(curNode)) {
+ if (!HTMLEditUtils::IsListItem(curNode)) {
if (IsInlineNode(curNode) && prevListItem) {
// this is a continuation of some inline nodes that belong together in
// the same list item. use prevListItem
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, prevListItem, -1);
NS_ENSURE_SUCCESS(res, res);
} else {
// don't wrap li around a paragraph. instead replace paragraph with li
@@ -3300,27 +3293,26 @@ nsHTMLEditRules::WillRemoveList(Selectio
}
// reset list count
listCount = arrayOfNodes.Length();
// Only act on lists or list items in the array
for (auto& curNode : arrayOfNodes) {
// here's where we actually figure out what to do
- if (nsHTMLEditUtils::IsListItem(curNode)) // unlist this listitem
- {
+ if (HTMLEditUtils::IsListItem(curNode)) {
+ // unlist this listitem
bool bOutOfList;
do
{
res = PopListItem(GetAsDOMNode(curNode), &bOutOfList);
NS_ENSURE_SUCCESS(res, res);
} while (!bOutOfList); // keep popping it out until it's not in a list anymore
- }
- else if (nsHTMLEditUtils::IsList(curNode)) // node is a list, move list items out
- {
+ } else if (HTMLEditUtils::IsList(curNode)) {
+ // node is a list, move list items out
res = RemoveListStructure(*curNode->AsElement());
NS_ENSURE_SUCCESS(res, res);
}
}
return res;
}
@@ -3382,17 +3374,17 @@ nsHTMLEditRules::WillMakeBasicBlock(Sele
*aSelection.GetRangeAt(0)->GetStartParent();
int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
if (blockType == nsGkAtoms::normal ||
blockType == nsGkAtoms::_empty) {
// We are removing blocks (going to "body text")
NS_ENSURE_TRUE(mHTMLEditor->GetBlock(parent), NS_ERROR_NULL_POINTER);
OwningNonNull<Element> curBlock = *mHTMLEditor->GetBlock(parent);
- if (nsHTMLEditUtils::IsFormatNode(curBlock)) {
+ if (HTMLEditUtils::IsFormatNode(curBlock)) {
// If the first editable node after selection is a br, consume it.
// Otherwise it gets pushed into a following block after the split,
// which is visually bad.
nsCOMPtr<nsIContent> brNode =
mHTMLEditor->GetNextHTMLNode(parent, offset);
if (brNode && brNode->IsHTMLElement(nsGkAtoms::br)) {
res = mHTMLEditor->DeleteNode(brNode);
NS_ENSURE_SUCCESS(res, res);
@@ -3523,18 +3515,19 @@ nsHTMLEditRules::WillCSSIndent(Selection
nsCOMPtr<Element> liNode;
if (aSelection->Collapsed()) {
nsCOMPtr<nsINode> node;
int32_t offset;
NS_ENSURE_STATE(mHTMLEditor);
nsresult res = mHTMLEditor->GetStartNodeAndOffset(aSelection, getter_AddRefs(node), &offset);
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*node);
- if (block && nsHTMLEditUtils::IsListItem(block))
+ if (block && HTMLEditUtils::IsListItem(block)) {
liNode = block;
+ }
}
if (liNode)
{
arrayOfNodes.AppendElement(*liNode);
}
else
{
@@ -3597,42 +3590,39 @@ nsHTMLEditRules::WillCSSIndent(Selection
// Ignore all non-editable nodes. Leave them be.
NS_ENSURE_STATE(mHTMLEditor);
if (!mHTMLEditor->IsEditable(curNode)) continue;
curParent = curNode->GetParentNode();
int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
// some logic for putting list items into nested lists...
- if (nsHTMLEditUtils::IsList(curParent))
- {
+ if (HTMLEditUtils::IsList(curParent)) {
sibling = nullptr;
// Check for whether we should join a list that follows curNode.
// We do this if the next element is a list, and the list is of the
// same type (li/ol) as curNode was a part it.
NS_ENSURE_STATE(mHTMLEditor);
sibling = mHTMLEditor->GetNextHTMLSibling(curNode);
- if (sibling && nsHTMLEditUtils::IsList(sibling))
- {
+ if (sibling && HTMLEditUtils::IsList(sibling)) {
if (curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, sibling, 0);
NS_ENSURE_SUCCESS(res, res);
continue;
}
}
// Check for whether we should join a list that preceeds curNode.
// We do this if the previous element is a list, and the list is of
// the same type (li/ol) as curNode was a part of.
NS_ENSURE_STATE(mHTMLEditor);
sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
- if (sibling && nsHTMLEditUtils::IsList(sibling))
- {
+ if (sibling && HTMLEditUtils::IsList(sibling)) {
if (curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, sibling, -1);
NS_ENSURE_SUCCESS(res, res);
continue;
}
}
@@ -3782,40 +3772,39 @@ nsHTMLEditRules::WillHTMLIndent(Selectio
// Ignore all non-editable nodes. Leave them be.
NS_ENSURE_STATE(mHTMLEditor);
if (!mHTMLEditor->IsEditable(curNode)) continue;
curParent = curNode->GetParentNode();
int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
// some logic for putting list items into nested lists...
- if (nsHTMLEditUtils::IsList(curParent))
- {
+ if (HTMLEditUtils::IsList(curParent)) {
sibling = nullptr;
// Check for whether we should join a list that follows curNode.
// We do this if the next element is a list, and the list is of the
// same type (li/ol) as curNode was a part it.
NS_ENSURE_STATE(mHTMLEditor);
sibling = mHTMLEditor->GetNextHTMLSibling(curNode);
- if (sibling && nsHTMLEditUtils::IsList(sibling) &&
+ if (sibling && HTMLEditUtils::IsList(sibling) &&
curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, sibling, 0);
NS_ENSURE_SUCCESS(res, res);
continue;
}
// Check for whether we should join a list that preceeds curNode.
// We do this if the previous element is a list, and the list is of
// the same type (li/ol) as curNode was a part of.
NS_ENSURE_STATE(mHTMLEditor);
sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
- if (sibling && nsHTMLEditUtils::IsList(sibling) &&
+ if (sibling && HTMLEditUtils::IsList(sibling) &&
curParent->NodeInfo()->NameAtom() == sibling->NodeInfo()->NameAtom() &&
curParent->NodeInfo()->NamespaceID() == sibling->NodeInfo()->NamespaceID()) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(curNode, sibling, -1);
NS_ENSURE_SUCCESS(res, res);
continue;
}
@@ -4010,17 +3999,17 @@ nsHTMLEditRules::WillOutdent(Selection&
NS_ENSURE_STATE(mHTMLEditor);
mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
if (f > 0) {
ChangeIndentation(*curNode->AsElement(), Change::minus);
continue;
}
}
// Is it a list item?
- if (nsHTMLEditUtils::IsListItem(curNode)) {
+ if (HTMLEditUtils::IsListItem(curNode)) {
// If it is a list item, that means we are not outdenting whole list.
// So we need to finish up dealing with any curBlockQuote, and then pop
// this list item.
if (curBlockQuote) {
res = OutdentPartOfBlock(*curBlockQuote, *firstBQChild, *lastBQChild,
curBlockQuoteIsIndentedWithCSS,
getter_AddRefs(rememberedLeftBQ),
getter_AddRefs(rememberedRightBQ));
@@ -4063,17 +4052,17 @@ nsHTMLEditRules::WillOutdent(Selection&
// Are we inside a blockquote?
OwningNonNull<nsINode> n = curNode;
curBlockQuoteIsIndentedWithCSS = false;
// Keep looking up the hierarchy as long as we don't hit the body or the
// active editing host or a table element (other than an entire table)
while (!n->IsHTMLElement(nsGkAtoms::body) &&
mHTMLEditor->IsDescendantOfEditorRoot(n) &&
(n->IsHTMLElement(nsGkAtoms::table) ||
- !nsHTMLEditUtils::IsTableElement(n))) {
+ !HTMLEditUtils::IsTableElement(n))) {
if (!n->GetParentNode()) {
break;
}
n = *n->GetParentNode();
if (n->IsHTMLElement(nsGkAtoms::blockquote)) {
// If so, remember it and the first node we are taking out of it.
curBlockQuote = n->AsElement();
firstBQChild = curNode;
@@ -4083,46 +4072,46 @@ nsHTMLEditRules::WillOutdent(Selection&
nsIAtom& marginProperty =
MarginPropertyAtomForIndent(*mHTMLEditor->mHTMLCSSUtils, curNode);
nsAutoString value;
mHTMLEditor->mHTMLCSSUtils->GetSpecifiedProperty(*n, marginProperty,
value);
float f;
nsCOMPtr<nsIAtom> unit;
mHTMLEditor->mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit));
- if (f > 0 && !(nsHTMLEditUtils::IsList(curParent) &&
- nsHTMLEditUtils::IsList(curNode))) {
+ if (f > 0 && !(HTMLEditUtils::IsList(curParent) &&
+ HTMLEditUtils::IsList(curNode))) {
curBlockQuote = n->AsElement();
firstBQChild = curNode;
lastBQChild = curNode;
curBlockQuoteIsIndentedWithCSS = true;
break;
}
}
}
if (!curBlockQuote) {
// Couldn't find enclosing blockquote. Handle list cases.
- if (nsHTMLEditUtils::IsList(curParent)) {
+ if (HTMLEditUtils::IsList(curParent)) {
// Move node out of list
- if (nsHTMLEditUtils::IsList(curNode)) {
+ if (HTMLEditUtils::IsList(curNode)) {
// Just unwrap this sublist
res = mHTMLEditor->RemoveBlockContainer(curNode);
NS_ENSURE_SUCCESS(res, res);
}
// handled list item case above
- } else if (nsHTMLEditUtils::IsList(curNode)) {
+ } else if (HTMLEditUtils::IsList(curNode)) {
// node is a list, but parent is non-list: move list items out
nsCOMPtr<nsIContent> child = curNode->GetLastChild();
while (child) {
- if (nsHTMLEditUtils::IsListItem(child)) {
+ if (HTMLEditUtils::IsListItem(child)) {
bool unused;
res = PopListItem(GetAsDOMNode(child), &unused);
NS_ENSURE_SUCCESS(res, res);
- } else if (nsHTMLEditUtils::IsList(child)) {
+ } else if (HTMLEditUtils::IsList(child)) {
// We have an embedded list, so move it out from under the parent
// list. Be sure to put it after the parent list because this
// loop iterates backwards through the parent's list of children.
res = mHTMLEditor->MoveNode(child, curParent, offset + 1);
NS_ENSURE_SUCCESS(res, res);
} else {
// Delete any non-list items for now
@@ -4299,21 +4288,21 @@ nsHTMLEditRules::ConvertListType(Element
MOZ_ASSERT(aListType);
MOZ_ASSERT(aItemType);
nsCOMPtr<nsINode> child = aList->GetFirstChild();
while (child)
{
if (child->IsElement()) {
dom::Element* element = child->AsElement();
- if (nsHTMLEditUtils::IsListItem(element) &&
+ if (HTMLEditUtils::IsListItem(element) &&
!element->IsHTMLElement(aItemType)) {
child = mHTMLEditor->ReplaceContainer(element, aItemType);
NS_ENSURE_STATE(child);
- } else if (nsHTMLEditUtils::IsList(element) &&
+ } else if (HTMLEditUtils::IsList(element) &&
!element->IsHTMLElement(aListType)) {
nsCOMPtr<dom::Element> temp;
nsresult rv = ConvertListType(child->AsElement(), getter_AddRefs(temp),
aListType, aItemType);
NS_ENSURE_SUCCESS(rv, rv);
child = temp.forget();
}
}
@@ -4501,17 +4490,17 @@ nsHTMLEditRules::WillAlign(Selection& aS
// If we don't have any nodes, or we have only a single br, then we are
// creating an empty alignment div. We have to do some different things for
// these.
bool emptyDiv = nodeArray.IsEmpty();
if (nodeArray.Length() == 1) {
OwningNonNull<nsINode> node = nodeArray[0];
- if (nsHTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(node))) {
+ if (HTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(node))) {
// The node is a table element, an hr, a paragraph, a div or a section
// header; in HTML 4, it can directly carry the ALIGN attribute and we
// don't need to make a div! If we are in CSS mode, all the work is done
// in AlignBlock
rv = AlignBlock(*node->AsElement(), aAlignType, ContentsOnly::yes);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@@ -4529,18 +4518,18 @@ nsHTMLEditRules::WillAlign(Selection& aS
// rely on the selection start node because of the fact that nodeArray
// can be empty? We should probably revisit this issue. - kin
NS_ENSURE_STATE(aSelection.GetRangeAt(0) &&
aSelection.GetRangeAt(0)->GetStartParent());
OwningNonNull<nsINode> parent =
*aSelection.GetRangeAt(0)->GetStartParent();
- emptyDiv = !nsHTMLEditUtils::IsTableElement(parent) ||
- nsHTMLEditUtils::IsTableCellOrCaption(parent);
+ emptyDiv = !HTMLEditUtils::IsTableElement(parent) ||
+ HTMLEditUtils::IsTableCellOrCaption(parent);
}
}
if (emptyDiv) {
nsCOMPtr<nsINode> parent =
aSelection.GetRangeAt(0) ? aSelection.GetRangeAt(0)->GetStartParent()
: nullptr;
NS_ENSURE_STATE(parent);
int32_t offset = aSelection.GetRangeAt(0)->StartOffset();
@@ -4600,52 +4589,52 @@ nsHTMLEditRules::WillAlign(Selection& aS
if (!mHTMLEditor->IsEditable(curNode)) {
continue;
}
// The node is a table element, an hr, a paragraph, a div or a section
// header; in HTML 4, it can directly carry the ALIGN attribute and we
// don't need to nest it, just set the alignment. In CSS, assign the
// corresponding CSS styles in AlignBlock
- if (nsHTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(curNode))) {
+ if (HTMLEditUtils::SupportsAlignAttr(GetAsDOMNode(curNode))) {
rv = AlignBlock(*curNode->AsElement(), aAlignType, ContentsOnly::no);
NS_ENSURE_SUCCESS(rv, rv);
// Clear out curDiv so that we don't put nodes after this one into it
curDiv = nullptr;
continue;
}
nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
// Skip insignificant formatting text nodes to prevent unnecessary
// structure splitting!
bool isEmptyTextNode = false;
if (curNode->GetAsText() &&
- ((nsHTMLEditUtils::IsTableElement(curParent) &&
- !nsHTMLEditUtils::IsTableCellOrCaption(*curParent)) ||
- nsHTMLEditUtils::IsList(curParent) ||
+ ((HTMLEditUtils::IsTableElement(curParent) &&
+ !HTMLEditUtils::IsTableCellOrCaption(*curParent)) ||
+ HTMLEditUtils::IsList(curParent) ||
(NS_SUCCEEDED(mHTMLEditor->IsEmptyNode(curNode, &isEmptyTextNode)) &&
isEmptyTextNode))) {
continue;
}
// 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 (nsHTMLEditUtils::IsListItem(curNode) ||
- nsHTMLEditUtils::IsList(curNode)) {
+ if (HTMLEditUtils::IsListItem(curNode) ||
+ HTMLEditUtils::IsList(curNode)) {
rv = RemoveAlignment(GetAsDOMNode(curNode), aAlignType, true);
NS_ENSURE_SUCCESS(rv, rv);
if (useCSS) {
mHTMLEditor->mHTMLCSSUtils->SetCSSEquivalentToHTMLStyle(
curNode->AsElement(), nullptr, &NS_LITERAL_STRING("align"),
&aAlignType, false);
curDiv = nullptr;
continue;
- } else if (nsHTMLEditUtils::IsList(curParent)) {
+ } 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);
NS_ENSURE_SUCCESS(rv, rv);
curDiv = nullptr;
continue;
}
// Clear out curDiv so that we don't put nodes after this one into it
@@ -4795,45 +4784,45 @@ nsHTMLEditRules::CheckForEmptyBlock(nsIN
nsCOMPtr<Element> block = mHTMLEditor->GetBlock(*aStartNode);
bool bIsEmptyNode;
nsCOMPtr<Element> emptyBlock;
nsresult res;
if (block && block != aBodyNode) {
// Efficiency hack, avoiding IsEmptyNode() call when in body
res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
NS_ENSURE_SUCCESS(res, res);
- while (block && bIsEmptyNode && !nsHTMLEditUtils::IsTableElement(block) &&
+ while (block && bIsEmptyNode && !HTMLEditUtils::IsTableElement(block) &&
block != aBodyNode) {
emptyBlock = block;
block = mHTMLEditor->GetBlockNodeParent(emptyBlock);
if (block) {
res = mHTMLEditor->IsEmptyNode(block, &bIsEmptyNode, true, false);
NS_ENSURE_SUCCESS(res, res);
}
}
}
if (emptyBlock && emptyBlock->IsEditable()) {
nsCOMPtr<nsINode> blockParent = emptyBlock->GetParentNode();
NS_ENSURE_TRUE(blockParent, NS_ERROR_FAILURE);
int32_t offset = blockParent->IndexOf(emptyBlock);
- if (nsHTMLEditUtils::IsListItem(emptyBlock)) {
+ if (HTMLEditUtils::IsListItem(emptyBlock)) {
// Are we the first list item in the list?
bool bIsFirst;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->IsFirstEditableChild(GetAsDOMNode(emptyBlock),
&bIsFirst);
NS_ENSURE_SUCCESS(res, res);
if (bIsFirst) {
nsCOMPtr<nsINode> listParent = blockParent->GetParentNode();
NS_ENSURE_TRUE(listParent, NS_ERROR_FAILURE);
int32_t listOffset = listParent->IndexOf(blockParent);
// If we are a sublist, skip the br creation
- if (!nsHTMLEditUtils::IsList(listParent)) {
+ if (!HTMLEditUtils::IsList(listParent)) {
// Create a br before list
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> br =
mHTMLEditor->CreateBR(listParent, listOffset);
NS_ENSURE_STATE(br);
// Adjust selection to be right before it
res = aSelection->Collapse(listParent, listOffset);
NS_ENSURE_SUCCESS(res, res);
@@ -4924,19 +4913,19 @@ void
nsHTMLEditRules::GetInnerContent(nsINode& aNode,
nsTArray<OwningNonNull<nsINode>>& aOutArrayOfNodes,
int32_t* aIndex, Lists aLists, Tables aTables)
{
MOZ_ASSERT(aIndex);
for (nsCOMPtr<nsIContent> node = mHTMLEditor->GetFirstEditableChild(aNode);
node; node = node->GetNextSibling()) {
- if ((aLists == Lists::yes && (nsHTMLEditUtils::IsList(node) ||
- nsHTMLEditUtils::IsListItem(node))) ||
- (aTables == Tables::yes && nsHTMLEditUtils::IsTableElement(node))) {
+ if ((aLists == Lists::yes && (HTMLEditUtils::IsList(node) ||
+ HTMLEditUtils::IsListItem(node))) ||
+ (aTables == Tables::yes && HTMLEditUtils::IsTableElement(node))) {
GetInnerContent(*node, aOutArrayOfNodes, aIndex, aLists, aTables);
} else {
aOutArrayOfNodes.InsertElementAt(*aIndex, *node);
(*aIndex)++;
}
}
}
@@ -4985,17 +4974,17 @@ nsHTMLEditRules::ExpandSelectionForDelet
nsWSRunObject wsObj(mHTMLEditor, selStartNode, selStartOffset);
wsObj.PriorVisibleNode(selStartNode, selStartOffset, address_of(unused),
&visOffset, &wsType);
if (wsType != WSType::thisBlock) {
break;
}
// We want to keep looking up. But stop if we are crossing table
// element boundaries, or if we hit the root.
- if (nsHTMLEditUtils::IsTableElement(wsObj.mStartReasonNode) ||
+ if (HTMLEditUtils::IsTableElement(wsObj.mStartReasonNode) ||
selCommon == wsObj.mStartReasonNode ||
root == wsObj.mStartReasonNode) {
break;
}
selStartNode = wsObj.mStartReasonNode->GetParentNode();
selStartOffset = selStartNode ?
selStartNode->IndexOf(wsObj.mStartReasonNode) : -1;
}
@@ -5016,17 +5005,17 @@ nsHTMLEditRules::ExpandSelectionForDelet
firstBROffset = selEndOffset;
}
selEndNode = wsObj.mEndReasonNode->GetParentNode();
selEndOffset = selEndNode
? selEndNode->IndexOf(wsObj.mEndReasonNode) + 1 : 0;
} else if (wsType == WSType::thisBlock) {
// We want to keep looking up. But stop if we are crossing table
// element boundaries, or if we hit the root.
- if (nsHTMLEditUtils::IsTableElement(wsObj.mEndReasonNode) ||
+ if (HTMLEditUtils::IsTableElement(wsObj.mEndReasonNode) ||
selCommon == wsObj.mEndReasonNode ||
root == wsObj.mEndReasonNode) {
break;
}
selEndNode = wsObj.mEndReasonNode->GetParentNode();
selEndOffset = 1 + selEndNode->IndexOf(wsObj.mEndReasonNode);
} else {
break;
@@ -5642,30 +5631,30 @@ nsHTMLEditRules::GetNodesForOperation(ns
}
}
// Certain operations should not act on li's and td's, but rather inside
// them. Alter the list as needed.
if (aOperationType == EditAction::makeBasicBlock) {
for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
OwningNonNull<nsINode> node = aOutArrayOfNodes[i];
- if (nsHTMLEditUtils::IsListItem(node)) {
+ if (HTMLEditUtils::IsListItem(node)) {
int32_t j = i;
aOutArrayOfNodes.RemoveElementAt(i);
GetInnerContent(*node, aOutArrayOfNodes, &j);
}
}
// Indent/outdent already do something special for list items, but we still
// need to make sure we don't act on table elements
} else if (aOperationType == EditAction::outdent ||
aOperationType == EditAction::indent ||
aOperationType == EditAction::setAbsolutePosition) {
for (int32_t i = aOutArrayOfNodes.Length() - 1; i >= 0; i--) {
OwningNonNull<nsINode> node = aOutArrayOfNodes[i];
- if (nsHTMLEditUtils::IsTableElementButNotTable(node)) {
+ if (HTMLEditUtils::IsTableElementButNotTable(node)) {
int32_t j = i;
aOutArrayOfNodes.RemoveElementAt(i);
GetInnerContent(*node, aOutArrayOfNodes, &j);
}
}
}
// Outdent should look inside of divs.
if (aOperationType == EditAction::outdent &&
@@ -5732,17 +5721,17 @@ nsHTMLEditRules::GetListActionNodes(nsTA
// Added this in so that ui code can ask to change an entire list, even if
// selection is only in part of it. used by list item dialog.
if (aEntireList == EntireList::yes) {
uint32_t rangeCount = selection->RangeCount();
for (uint32_t rangeIdx = 0; rangeIdx < rangeCount; ++rangeIdx) {
RefPtr<nsRange> range = selection->GetRangeAt(rangeIdx);
for (nsCOMPtr<nsINode> parent = range->GetCommonAncestor();
parent; parent = parent->GetParentNode()) {
- if (nsHTMLEditUtils::IsList(parent)) {
+ if (HTMLEditUtils::IsList(parent)) {
aOutArrayOfNodes.AppendElement(*parent);
break;
}
}
}
// If we didn't find any nodes this way, then try the normal way. Perhaps
// the selection spans multiple lists but with no common list parent.
if (aOutArrayOfNodes.Length()) {
@@ -5767,17 +5756,17 @@ nsHTMLEditRules::GetListActionNodes(nsTA
// Remove all non-editable nodes. Leave them be.
if (!mHTMLEditor->IsEditable(testNode)) {
aOutArrayOfNodes.RemoveElementAt(i);
continue;
}
// Scan for table elements and divs. If we find table elements other than
// table, replace it with a list of any editable non-table content.
- if (nsHTMLEditUtils::IsTableElementButNotTable(testNode)) {
+ if (HTMLEditUtils::IsTableElementButNotTable(testNode)) {
int32_t j = i;
aOutArrayOfNodes.RemoveElementAt(i);
GetInnerContent(*testNode, aOutArrayOfNodes, &j, Lists::no);
}
}
// If there is only one node in the array, and it is a list, div, or
// blockquote, then look inside of it until we find inner list or content.
@@ -5798,28 +5787,28 @@ nsHTMLEditRules::LookInsideDivBQandList(
int32_t listCount = aNodeArray.Length();
if (listCount != 1) {
return;
}
OwningNonNull<nsINode> curNode = aNodeArray[0];
while (curNode->IsHTMLElement(nsGkAtoms::div) ||
- nsHTMLEditUtils::IsList(curNode) ||
+ HTMLEditUtils::IsList(curNode) ||
curNode->IsHTMLElement(nsGkAtoms::blockquote)) {
// Dive as long as there's only one child, and it's a list, div, blockquote
uint32_t numChildren = mHTMLEditor->CountEditableChildren(curNode);
if (numChildren != 1) {
break;
}
// Keep diving! XXX One would expect to dive into the one editable node.
nsCOMPtr<nsIContent> child = curNode->GetFirstChild();
if (!child->IsHTMLElement(nsGkAtoms::div) &&
- !nsHTMLEditUtils::IsList(child) &&
+ !HTMLEditUtils::IsList(child) &&
!child->IsHTMLElement(nsGkAtoms::blockquote)) {
break;
}
// check editability XXX floppy moose
curNode = child;
}
@@ -5883,19 +5872,19 @@ nsHTMLEditRules::GetParagraphFormatNodes
if (!mHTMLEditor->IsEditable(testNode)) {
outArrayOfNodes.RemoveElementAt(i);
continue;
}
// Scan for table elements. If we find table elements other than table,
// replace it with a list of any editable non-table content. Ditto for
// list elements.
- if (nsHTMLEditUtils::IsTableElement(testNode) ||
- nsHTMLEditUtils::IsList(testNode) ||
- nsHTMLEditUtils::IsListItem(testNode)) {
+ if (HTMLEditUtils::IsTableElement(testNode) ||
+ HTMLEditUtils::IsList(testNode) ||
+ HTMLEditUtils::IsListItem(testNode)) {
int32_t j = i;
outArrayOfNodes.RemoveElementAt(i);
GetInnerContent(testNode, outArrayOfNodes, &j);
}
}
return NS_OK;
}
@@ -6114,24 +6103,24 @@ nsHTMLEditRules::MakeTransitionList(nsTA
// But table element boundaries are stoppers on the search.
// Also stops on the active editor host (contenteditable).
// Also test if aNode is an li itself.
//
Element*
nsHTMLEditRules::IsInListItem(nsINode* aNode)
{
NS_ENSURE_TRUE(aNode, nullptr);
- if (nsHTMLEditUtils::IsListItem(aNode)) {
+ if (HTMLEditUtils::IsListItem(aNode)) {
return aNode->AsElement();
}
Element* parent = aNode->GetParentElement();
while (parent && mHTMLEditor && mHTMLEditor->IsDescendantOfEditorRoot(parent) &&
- !nsHTMLEditUtils::IsTableElement(parent)) {
- if (nsHTMLEditUtils::IsListItem(parent)) {
+ !HTMLEditUtils::IsTableElement(parent)) {
+ if (HTMLEditUtils::IsListItem(parent)) {
return parent;
}
parent = parent->GetParentElement();
}
return nullptr;
}
@@ -6159,17 +6148,17 @@ nsHTMLEditRules::ReturnInHeader(Selectio
NS_ENSURE_SUCCESS(res, res);
// Split the header
NS_ENSURE_STATE(node->IsContent());
mHTMLEditor->SplitNodeDeep(aHeader, *node->AsContent(), aOffset);
// If the left-hand heading is empty, put a mozbr in it
nsCOMPtr<nsIContent> prevItem = mHTMLEditor->GetPriorHTMLSibling(&aHeader);
- if (prevItem && nsHTMLEditUtils::IsHeader(*prevItem)) {
+ if (prevItem && HTMLEditUtils::IsHeader(*prevItem)) {
bool isEmptyNode;
res = mHTMLEditor->IsEmptyNode(prevItem, &isEmptyNode);
NS_ENSURE_SUCCESS(res, res);
if (isEmptyNode) {
res = CreateMozBR(prevItem->AsDOMNode(), 0);
NS_ENSURE_SUCCESS(res, res);
}
}
@@ -6406,17 +6395,17 @@ nsHTMLEditRules::SplitParagraph(nsIDOMNo
* ReturnInListItem: do the right thing for returns pressed in list items
*/
nsresult
nsHTMLEditRules::ReturnInListItem(Selection& aSelection,
Element& aListItem,
nsINode& aNode,
int32_t aOffset)
{
- MOZ_ASSERT(nsHTMLEditUtils::IsListItem(&aListItem));
+ MOZ_ASSERT(HTMLEditUtils::IsListItem(&aListItem));
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
// Get the item parent and the active editing host.
nsCOMPtr<Element> root = mHTMLEditor->GetActiveEditingHost();
nsCOMPtr<Element> list = aListItem.GetParentElement();
@@ -6440,17 +6429,17 @@ nsHTMLEditRules::ReturnInListItem(Select
if (!isLast) {
// We need to split the list!
ErrorResult rv;
mHTMLEditor->SplitNode(*list, itemOffset, rv);
NS_ENSURE_TRUE(!rv.Failed(), rv.StealNSResult());
}
// Are we in a sublist?
- if (nsHTMLEditUtils::IsList(listParent)) {
+ if (HTMLEditUtils::IsList(listParent)) {
// If so, move item out of this list and into the grandparent list
res = mHTMLEditor->MoveNode(&aListItem, listParent, offset + 1);
NS_ENSURE_SUCCESS(res, res);
res = aSelection.Collapse(&aListItem, 0);
NS_ENSURE_SUCCESS(res, res);
} else {
// Otherwise kill this item
res = mHTMLEditor->DeleteNode(&aListItem);
@@ -6482,17 +6471,17 @@ nsHTMLEditRules::ReturnInListItem(Select
// Now split list item
NS_ENSURE_STATE(selNode->IsContent());
mHTMLEditor->SplitNodeDeep(aListItem, *selNode->AsContent(), aOffset);
// Hack: until I can change the damaged doc range code back to being
// extra-inclusive, I have to manually detect certain list items that may be
// left empty.
nsCOMPtr<nsIContent> prevItem = mHTMLEditor->GetPriorHTMLSibling(&aListItem);
- if (prevItem && nsHTMLEditUtils::IsListItem(prevItem)) {
+ if (prevItem && HTMLEditUtils::IsListItem(prevItem)) {
bool isEmptyNode;
res = mHTMLEditor->IsEmptyNode(prevItem, &isEmptyNode);
NS_ENSURE_SUCCESS(res, res);
if (isEmptyNode) {
res = CreateMozBR(prevItem->AsDOMNode(), 0);
NS_ENSURE_SUCCESS(res, res);
} else {
res = mHTMLEditor->IsEmptyNode(&aListItem, &isEmptyNode, true);
@@ -6573,18 +6562,18 @@ nsHTMLEditRules::MakeBlockquote(nsTArray
nsCOMPtr<Element> curBlock;
nsCOMPtr<nsINode> prevParent;
for (auto& curNode : aNodeArray) {
// Get the node to act on, and its location
NS_ENSURE_STATE(curNode->IsContent());
// If the node is a table element or list item, dive inside
- if (nsHTMLEditUtils::IsTableElementButNotTable(curNode) ||
- nsHTMLEditUtils::IsListItem(curNode)) {
+ if (HTMLEditUtils::IsTableElementButNotTable(curNode) ||
+ HTMLEditUtils::IsListItem(curNode)) {
// Forget any previous block
curBlock = nullptr;
// Recursion time
nsTArray<OwningNonNull<nsINode>> childArray;
GetChildNodesForOperation(*curNode, childArray);
res = MakeBlockquote(childArray);
NS_ENSURE_SUCCESS(res, res);
}
@@ -6636,34 +6625,34 @@ nsHTMLEditRules::RemoveBlockStyle(nsTArr
// paragraphs, pre, and address. Those blocks that pretty much just contain
// inline things...
nsresult res;
nsCOMPtr<Element> curBlock;
nsCOMPtr<nsIContent> firstNode, lastNode;
for (auto& curNode : aNodeArray) {
// If curNode is a address, p, header, address, or pre, remove it
- if (nsHTMLEditUtils::IsFormatNode(curNode)) {
+ if (HTMLEditUtils::IsFormatNode(curNode)) {
// Process any partial progress saved
if (curBlock) {
res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
NS_ENSURE_SUCCESS(res, res);
firstNode = lastNode = curBlock = nullptr;
}
// Remove current block
res = mHTMLEditor->RemoveBlockContainer(*curNode->AsContent());
NS_ENSURE_SUCCESS(res, res);
} else if (curNode->IsAnyOfHTMLElements(nsGkAtoms::table,
nsGkAtoms::tr,
nsGkAtoms::tbody,
nsGkAtoms::td,
nsGkAtoms::li,
nsGkAtoms::blockquote,
nsGkAtoms::div) ||
- nsHTMLEditUtils::IsList(curNode)) {
+ HTMLEditUtils::IsList(curNode)) {
// Process any partial progress saved
if (curBlock) {
res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
NS_ENSURE_SUCCESS(res, res);
firstNode = lastNode = curBlock = nullptr;
}
// Recursion time
nsTArray<OwningNonNull<nsINode>> childArray;
@@ -6683,17 +6672,17 @@ nsHTMLEditRules::RemoveBlockStyle(nsTArr
// contains [firstNode - lastNode].
res = RemovePartOfBlock(*curBlock, *firstNode, *lastNode);
NS_ENSURE_SUCCESS(res, res);
firstNode = lastNode = curBlock = nullptr;
// Fall out and handle curNode
}
}
curBlock = mHTMLEditor->GetBlockNodeParent(curNode);
- if (curBlock && nsHTMLEditUtils::IsFormatNode(curBlock)) {
+ if (curBlock && HTMLEditUtils::IsFormatNode(curBlock)) {
firstNode = lastNode = curNode->AsContent();
} else {
// Not a block kind that we care about.
curBlock = nullptr;
}
} else if (curBlock) {
// Some node that is already sans block style. Skip over it and process
// any partial progress saved.
@@ -6747,26 +6736,26 @@ nsHTMLEditRules::ApplyBlockStyle(nsTArra
curBlock = nullptr;
// Do nothing to this block
continue;
}
// If curNode is a address, p, header, address, or pre, replace it with a
// new block of correct type.
// XXX: pre can't hold everything the others can
- if (nsHTMLEditUtils::IsMozDiv(curNode) ||
- nsHTMLEditUtils::IsFormatNode(curNode)) {
+ if (HTMLEditUtils::IsMozDiv(curNode) ||
+ HTMLEditUtils::IsFormatNode(curNode)) {
// Forget any previous block used for previous inline nodes
curBlock = nullptr;
newBlock = mHTMLEditor->ReplaceContainer(curNode->AsElement(),
&aBlockTag, nullptr, nullptr,
nsEditor::eCloneAttributes);
NS_ENSURE_STATE(newBlock);
- } else if (nsHTMLEditUtils::IsTable(curNode) ||
- nsHTMLEditUtils::IsList(curNode) ||
+ } else if (HTMLEditUtils::IsTable(curNode) ||
+ HTMLEditUtils::IsList(curNode) ||
curNode->IsAnyOfHTMLElements(nsGkAtoms::tbody,
nsGkAtoms::tr,
nsGkAtoms::td,
nsGkAtoms::li,
nsGkAtoms::blockquote,
nsGkAtoms::div)) {
// Forget any previous block used for previous inline nodes
curBlock = nullptr;
@@ -6930,17 +6919,17 @@ nsHTMLEditRules::JoinNodesSmart(nsIConte
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
res = mHTMLEditor->MoveNode(&aNodeRight, parent, parOffset);
NS_ENSURE_SUCCESS(res, EditorDOMPoint());
}
EditorDOMPoint ret(&aNodeRight, aNodeLeft.Length());
// Separate join rules for differing blocks
- if (nsHTMLEditUtils::IsList(&aNodeLeft) || aNodeLeft.GetAsText()) {
+ if (HTMLEditUtils::IsList(&aNodeLeft) || aNodeLeft.GetAsText()) {
// For lists, merge shallow (wouldn't want to combine list items)
res = mHTMLEditor->JoinNodes(aNodeLeft, aNodeRight);
NS_ENSURE_SUCCESS(res, EditorDOMPoint());
return ret;
}
// Remember the last left child, and first right child
NS_ENSURE_TRUE(mHTMLEditor, EditorDOMPoint());
@@ -6971,17 +6960,17 @@ nsHTMLEditRules::JoinNodesSmart(nsIConte
Element*
nsHTMLEditRules::GetTopEnclosingMailCite(nsINode& aNode)
{
nsCOMPtr<Element> ret;
for (nsCOMPtr<nsINode> node = &aNode; node; node = node->GetParentNode()) {
if ((IsPlaintextEditor() && node->IsHTMLElement(nsGkAtoms::pre)) ||
- nsHTMLEditUtils::IsMailCite(node)) {
+ HTMLEditUtils::IsMailCite(node)) {
ret = node->AsElement();
}
if (node->IsHTMLElement(nsGkAtoms::body)) {
break;
}
}
return ret;
@@ -7367,17 +7356,17 @@ nsHTMLEditRules::AdjustSelection(Selecti
}
}
// we aren't in a textnode: are we adjacent to text or a break or an image?
NS_ENSURE_STATE(mHTMLEditor);
nearNode = mHTMLEditor->GetPriorHTMLNode(selNode, selOffset, true);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
nsEditor::IsTextNode(nearNode) ||
- nsHTMLEditUtils::IsImage(nearNode) ||
+ HTMLEditUtils::IsImage(nearNode) ||
nearNode->IsHTMLElement(nsGkAtoms::hr))) {
// this is a good place for the caret to be
return NS_OK;
}
NS_ENSURE_STATE(mHTMLEditor);
nearNode = mHTMLEditor->GetNextHTMLNode(selNode, selOffset, true);
if (nearNode && (TextEditUtils::IsBreak(nearNode) ||
nsEditor::IsTextNode(nearNode) ||
@@ -7454,17 +7443,17 @@ nsHTMLEditRules::FindNearSelectableNode(
NS_ENSURE_SUCCESS(res, res);
}
// scan in the right direction until we find an eligible text node,
// but don't cross any breaks, images, or table elements.
NS_ENSURE_STATE(mHTMLEditor);
while (nearNode && !(mHTMLEditor->IsTextNode(nearNode)
|| TextEditUtils::IsBreak(nearNode)
- || nsHTMLEditUtils::IsImage(nearNode)))
+ || HTMLEditUtils::IsImage(nearNode)))
{
curNode = nearNode;
if (aDirection == nsIEditor::ePrevious) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetPriorHTMLNode(curNode, address_of(nearNode));
} else {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->GetNextHTMLNode(curNode, address_of(nearNode));
@@ -7495,21 +7484,21 @@ bool nsHTMLEditRules::InDifferentTableEl
return InDifferentTableElements(node1, node2);
}
bool
nsHTMLEditRules::InDifferentTableElements(nsINode* aNode1, nsINode* aNode2)
{
MOZ_ASSERT(aNode1 && aNode2);
- while (aNode1 && !nsHTMLEditUtils::IsTableElement(aNode1)) {
+ while (aNode1 && !HTMLEditUtils::IsTableElement(aNode1)) {
aNode1 = aNode1->GetParentNode();
}
- while (aNode2 && !nsHTMLEditUtils::IsTableElement(aNode2)) {
+ while (aNode2 && !HTMLEditUtils::IsTableElement(aNode2)) {
aNode2 = aNode2->GetParentNode();
}
return aNode1 != aNode2;
}
nsresult
@@ -7566,25 +7555,25 @@ nsHTMLEditRules::RemoveEmptyNodes()
} else {
bool bIsCandidate = false;
bool bIsEmptyNode = false;
bool bIsMailCite = false;
if (node->IsElement()) {
if (node->IsHTMLElement(nsGkAtoms::body)) {
// Don't delete the body
- } else if ((bIsMailCite = nsHTMLEditUtils::IsMailCite(node)) ||
+ } else if ((bIsMailCite = HTMLEditUtils::IsMailCite(node)) ||
node->IsHTMLElement(nsGkAtoms::a) ||
- nsHTMLEditUtils::IsInlineStyle(node) ||
- nsHTMLEditUtils::IsList(node) ||
+ HTMLEditUtils::IsInlineStyle(node) ||
+ HTMLEditUtils::IsList(node) ||
node->IsHTMLElement(nsGkAtoms::div)) {
// Only consider certain nodes to be empty for purposes of removal
bIsCandidate = true;
- } else if (nsHTMLEditUtils::IsFormatNode(node) ||
- nsHTMLEditUtils::IsListItem(node) ||
+ } else if (HTMLEditUtils::IsFormatNode(node) ||
+ HTMLEditUtils::IsListItem(node) ||
node->IsHTMLElement(nsGkAtoms::blockquote)) {
// These node types are candidates if selection is not in them. If
// it is one of these, don't delete if selection inside. This is so
// we can create empty headings, etc., for the user to type into.
bool bIsSelInNode;
res = SelectionEndpointInNode(node, &bIsSelInNode);
NS_ENSURE_SUCCESS(res, res);
if (!bIsSelInNode) {
@@ -7752,17 +7741,17 @@ nsHTMLEditRules::PopListItem(nsIDOMNode
NS_ENSURE_TRUE(listItem && aOutOfList, NS_ERROR_NULL_POINTER);
// init out params
*aOutOfList = false;
nsCOMPtr<nsINode> curParent = listItem->GetParentNode();
int32_t offset = curParent ? curParent->IndexOf(listItem) : -1;
- if (!nsHTMLEditUtils::IsListItem(listItem)) {
+ if (!HTMLEditUtils::IsListItem(listItem)) {
return NS_ERROR_FAILURE;
}
// if it's first or last list item, don't need to split the list
// otherwise we do.
nsCOMPtr<nsINode> curParPar = curParent->GetParentNode();
int32_t parOffset = curParPar ? curParPar->IndexOf(curParent) : -1;
@@ -7789,18 +7778,18 @@ nsHTMLEditRules::PopListItem(nsIDOMNode
if (!bIsFirstListItem) parOffset++;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->MoveNode(listItem, curParPar, parOffset);
NS_ENSURE_SUCCESS(res, res);
// unwrap list item contents if they are no longer in a list
- if (!nsHTMLEditUtils::IsList(curParPar) &&
- nsHTMLEditUtils::IsListItem(listItem)) {
+ if (!HTMLEditUtils::IsList(curParPar) &&
+ HTMLEditUtils::IsListItem(listItem)) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->RemoveBlockContainer(*listItem);
NS_ENSURE_SUCCESS(res, res);
*aOutOfList = true;
}
return res;
}
@@ -7809,24 +7798,24 @@ nsHTMLEditRules::RemoveListStructure(Ele
{
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<nsIEditor> kungFuDeathGrip(mHTMLEditor);
nsresult res;
while (aList.GetFirstChild()) {
OwningNonNull<nsIContent> child = *aList.GetFirstChild();
- if (nsHTMLEditUtils::IsListItem(child)) {
+ if (HTMLEditUtils::IsListItem(child)) {
bool isOutOfList;
// Keep popping it out until it's not in a list anymore
do {
res = PopListItem(child->AsDOMNode(), &isOutOfList);
NS_ENSURE_SUCCESS(res, res);
} while (!isOutOfList);
- } else if (nsHTMLEditUtils::IsList(child)) {
+ } else if (HTMLEditUtils::IsList(child)) {
res = RemoveListStructure(*child->AsElement());
NS_ENSURE_SUCCESS(res, res);
} else {
// Delete any non-list items for now
res = mHTMLEditor->DeleteNode(child);
NS_ENSURE_SUCCESS(res, res);
}
}
@@ -8203,17 +8192,19 @@ nsHTMLEditRules::DidDeleteSelection(nsIS
// element (here we have to remove the container and keep its
// children). We break on tables and don't look at their children.
nsresult
nsHTMLEditRules::RemoveAlignment(nsIDOMNode * aNode, const nsAString & aAlignType, bool aChildrenOnly)
{
NS_ENSURE_TRUE(aNode, NS_ERROR_NULL_POINTER);
NS_ENSURE_STATE(mHTMLEditor);
- if (mHTMLEditor->IsTextNode(aNode) || nsHTMLEditUtils::IsTable(aNode)) return NS_OK;
+ if (mHTMLEditor->IsTextNode(aNode) || HTMLEditUtils::IsTable(aNode)) {
+ return NS_OK;
+ }
nsresult res = NS_OK;
nsCOMPtr<nsIDOMNode> child = aNode,tmp;
if (aChildrenOnly)
{
aNode->GetFirstChild(getter_AddRefs(child));
}
NS_ENSURE_STATE(mHTMLEditor);
@@ -8246,46 +8237,39 @@ nsHTMLEditRules::RemoveAlignment(nsIDOMN
NS_ENSURE_SUCCESS(res, res);
// now remove the CENTER container
NS_ENSURE_STATE(mHTMLEditor);
nsCOMPtr<Element> childAsElement = do_QueryInterface(child);
NS_ENSURE_STATE(childAsElement);
res = mHTMLEditor->RemoveContainer(childAsElement);
NS_ENSURE_SUCCESS(res, res);
- }
- else if (isBlock || nsHTMLEditUtils::IsHR(child))
- {
+ } else if (isBlock || HTMLEditUtils::IsHR(child)) {
// the current node is a block element
nsCOMPtr<nsIDOMElement> curElem = do_QueryInterface(child);
- if (nsHTMLEditUtils::SupportsAlignAttr(child))
- {
+ if (HTMLEditUtils::SupportsAlignAttr(child)) {
// remove the ALIGN attribute if this element can have it
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->RemoveAttribute(curElem, NS_LITERAL_STRING("align"));
NS_ENSURE_SUCCESS(res, res);
}
if (useCSS)
{
- if (nsHTMLEditUtils::IsTable(child) || nsHTMLEditUtils::IsHR(child))
- {
+ if (HTMLEditUtils::IsTable(child) || HTMLEditUtils::IsHR(child)) {
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->SetAttributeOrEquivalent(curElem, NS_LITERAL_STRING("align"), aAlignType, false);
- }
- else
- {
+ } else {
nsAutoString dummyCssValue;
NS_ENSURE_STATE(mHTMLEditor);
res = mHTMLEditor->mHTMLCSSUtils->RemoveCSSInlineStyle(child,
nsGkAtoms::textAlign, dummyCssValue);
}
NS_ENSURE_SUCCESS(res, res);
}
- if (!nsHTMLEditUtils::IsTable(child))
- {
+ if (!HTMLEditUtils::IsTable(child)) {
// unless this is a table, look at children
res = RemoveAlignment(child, aAlignType, true);
NS_ENSURE_SUCCESS(res, res);
}
}
child = tmp;
}
return NS_OK;
@@ -8394,17 +8378,17 @@ nsHTMLEditRules::AlignBlock(Element& aEl
// and text-align for other block-level elements
res = mHTMLEditor->SetAttributeOrEquivalent(
static_cast<nsIDOMElement*>(aElement.AsDOMNode()), attr, aAlignType,
false);
NS_ENSURE_SUCCESS(res, res);
} else {
// HTML case; this code is supposed to be called ONLY if the element
// supports the align attribute but we'll never know...
- if (nsHTMLEditUtils::SupportsAlignAttr(aElement.AsDOMNode())) {
+ if (HTMLEditUtils::SupportsAlignAttr(aElement.AsDOMNode())) {
res =
mHTMLEditor->SetAttribute(static_cast<nsIDOMElement*>(aElement.AsDOMNode()),
attr, aAlignType);
NS_ENSURE_SUCCESS(res, res);
}
}
return NS_OK;
}
@@ -8489,17 +8473,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se
WillInsert(aSelection, aCancel);
// We want to ignore result of WillInsert()
*aCancel = false;
*aHandled = true;
nsCOMPtr<Element> focusElement = mHTMLEditor->GetSelectionContainer();
- if (focusElement && nsHTMLEditUtils::IsImage(focusElement)) {
+ if (focusElement && HTMLEditUtils::IsImage(focusElement)) {
mNewBlock = focusElement;
return NS_OK;
}
nsresult res = NormalizeSelection(&aSelection);
NS_ENSURE_SUCCESS(res, res);
AutoSelectionRestorer selectionRestorer(&aSelection, mHTMLEditor);
@@ -8565,17 +8549,17 @@ nsHTMLEditRules::WillAbsolutePosition(Se
}
nsCOMPtr<nsIContent> sibling;
nsCOMPtr<nsINode> curParent = curNode->GetParentNode();
int32_t offset = curParent ? curParent->IndexOf(curNode) : -1;
// Some logic for putting list items into nested lists...
- if (nsHTMLEditUtils::IsList(curParent)) {
+ if (HTMLEditUtils::IsList(curParent)) {
// Check to see if curList is still appropriate. Which it is if curNode
// is still right after it in the same list.
if (curList) {
sibling = mHTMLEditor->GetPriorHTMLSibling(curNode);
}
if (!curList || (sibling && sibling != curList)) {
// Create a new nested list of correct type
--- a/editor/libeditor/nsHTMLEditor.cpp
+++ b/editor/libeditor/nsHTMLEditor.cpp
@@ -8,19 +8,19 @@
#include "mozilla/DebugOnly.h"
#include "mozilla/EventStates.h"
#include "mozilla/TextEvents.h"
#include "nsCRT.h"
#include "nsUnicharUtils.h"
+#include "HTMLEditUtils.h"
#include "TextEditUtils.h"
#include "nsHTMLEditRules.h"
-#include "nsHTMLEditUtils.h"
#include "nsHTMLEditorEventListener.h"
#include "TypeInState.h"
#include "nsHTMLURIRefObject.h"
#include "nsIDOMText.h"
#include "nsIDOMMozNamedAttrMap.h"
@@ -659,22 +659,22 @@ nsHTMLEditor::HandleKeyPressEvent(nsIDOM
nsCOMPtr<Element> blockParent = GetBlock(*node);
if (!blockParent) {
break;
}
bool handled = false;
nsresult rv = NS_OK;
- if (nsHTMLEditUtils::IsTableElement(blockParent)) {
+ if (HTMLEditUtils::IsTableElement(blockParent)) {
rv = TabInTable(nativeKeyEvent->IsShift(), &handled);
if (handled) {
ScrollSelectionIntoView(false);
}
- } else if (nsHTMLEditUtils::IsListItem(blockParent)) {
+ } else if (HTMLEditUtils::IsListItem(blockParent)) {
rv = Indent(nativeKeyEvent->IsShift()
? NS_LITERAL_STRING("outdent")
: NS_LITERAL_STRING("indent"));
handled = true;
}
NS_ENSURE_SUCCESS(rv, rv);
if (handled) {
return aKeyEvent->AsEvent()->PreventDefault(); // consumed
@@ -1082,17 +1082,17 @@ nsHTMLEditor::TabInTable(bool inIsShift,
if (inIsShift) {
iter->Prev();
} else {
iter->Next();
}
node = iter->GetCurrentNode();
- if (node && nsHTMLEditUtils::IsTableCell(node) &&
+ if (node && HTMLEditUtils::IsTableCell(node) &&
GetEnclosingTable(node) == table) {
CollapseSelectionToDeepestNonTableFirstChild(nullptr, node);
*outHandled = true;
return NS_OK;
}
} while (!iter->IsDone());
if (!(*outHandled) && !inIsShift) {
@@ -1161,17 +1161,17 @@ nsHTMLEditor::CollapseSelectionToDeepest
}
nsCOMPtr<nsINode> node = aNode;
for (nsCOMPtr<nsIContent> child = node->GetFirstChild();
child;
child = child->GetFirstChild()) {
// Stop if we find a table, don't want to go into nested tables
- if (nsHTMLEditUtils::IsTable(child) || !IsContainer(child)) {
+ if (HTMLEditUtils::IsTable(child) || !IsContainer(child)) {
break;
}
node = child;
}
selection->Collapse(node, 0);
}
@@ -1530,18 +1530,17 @@ nsHTMLEditor::InsertElementAtSelection(n
// If deleting, selection will be collapsed.
// so if not, we collapse it
if (!aDeleteSelection)
{
// Named Anchor is a special case,
// We collapse to insert element BEFORE the selection
// For all other tags, we insert AFTER the selection
- if (nsHTMLEditUtils::IsNamedAnchor(node))
- {
+ if (HTMLEditUtils::IsNamedAnchor(node)) {
selection->CollapseToStart();
} else {
selection->CollapseToEnd();
}
}
nsCOMPtr<nsIDOMNode> parentSelectedNode;
int32_t offsetForInsert;
@@ -1558,18 +1557,17 @@ nsHTMLEditor::InsertElementAtSelection(n
// Set caret after element, but check for special case
// of inserting table-related elements: set in first cell instead
if (!SetCaretInTableCell(aElement))
{
res = SetCaretAfterElement(aElement);
NS_ENSURE_SUCCESS(res, res);
}
// check for inserting a whole table at the end of a block. If so insert a br after it.
- if (nsHTMLEditUtils::IsTable(node))
- {
+ if (HTMLEditUtils::IsTable(node)) {
bool isLast;
res = IsLastEditableChild(node, &isLast);
NS_ENSURE_SUCCESS(res, res);
if (isLast)
{
nsCOMPtr<nsIDOMNode> brNode;
res = CreateBR(parentSelectedNode, offsetForInsert+1, address_of(brNode));
NS_ENSURE_SUCCESS(res, res);
@@ -1614,17 +1612,17 @@ nsHTMLEditor::InsertNodeAtPoint(nsIDOMNo
nsCOMPtr<nsIContent> topChild = parent;
nsCOMPtr<nsIContent> origParent = parent;
// Search up the parent chain to find a suitable container
while (!CanContain(*parent, *node)) {
// If the current parent is a root (body or table element)
// then go no further - we can't insert
if (parent->IsHTMLElement(nsGkAtoms::body) ||
- nsHTMLEditUtils::IsTableElement(parent)) {
+ HTMLEditUtils::IsTableElement(parent)) {
return NS_ERROR_FAILURE;
}
// Get the next parent
NS_ENSURE_TRUE(parent->GetParentNode(), NS_ERROR_FAILURE);
if (!IsEditable(parent->GetParentNode())) {
// There's no suitable place to put the node in this editing host. Maybe
// someone is trying to put block content in a span. So just put it
// where we were originally asked.
@@ -2278,28 +2276,28 @@ nsHTMLEditor::GetElementOrParentByTagNam
if (getLink || getNamedAnchor) {
tagName.Assign('a');
}
bool findTableCell = tagName.EqualsLiteral("td");
bool findList = tagName.EqualsLiteral("list");
for (; current; current = current->GetParentElement()) {
// Test if we have a link (an anchor with href set)
- if ((getLink && nsHTMLEditUtils::IsLink(current)) ||
- (getNamedAnchor && nsHTMLEditUtils::IsNamedAnchor(current))) {
+ if ((getLink && HTMLEditUtils::IsLink(current)) ||
+ (getNamedAnchor && HTMLEditUtils::IsNamedAnchor(current))) {
return current.forget();
}
if (findList) {
// Match "ol", "ul", or "dl" for lists
- if (nsHTMLEditUtils::IsList(current)) {
+ if (HTMLEditUtils::IsList(current)) {
return current.forget();
}
} else if (findTableCell) {
// Table cells are another special case: match either "td" or "th"
- if (nsHTMLEditUtils::IsTableCell(current)) {
+ if (HTMLEditUtils::IsTableCell(current)) {
return current.forget();
}
} else if (current->NodeName().Equals(tagName,
nsCaseInsensitiveStringComparator())) {
return current.forget();
}
// Stop searching if parent is a body tag. Note: Originally used IsRoot to
@@ -2382,19 +2380,18 @@ nsHTMLEditor::GetSelectedElement(const n
NS_ENSURE_SUCCESS(res, NS_OK);
if (selectedNode)
{
selectedNode->GetNodeName(domTagName);
ToLowerCase(domTagName);
// Test for appropriate node type requested
if (anyTag || (TagName == domTagName) ||
- (isLinkTag && nsHTMLEditUtils::IsLink(selectedNode)) ||
- (isNamedAnchorTag && nsHTMLEditUtils::IsNamedAnchor(selectedNode)))
- {
+ (isLinkTag && HTMLEditUtils::IsLink(selectedNode)) ||
+ (isNamedAnchorTag && HTMLEditUtils::IsNamedAnchor(selectedNode))) {
bNodeFound = true;
selectedElement = do_QueryInterface(selectedNode);
}
}
}
if (!bNodeFound)
{
@@ -2444,17 +2441,17 @@ nsHTMLEditor::GetSelectedElement(const n
NS_IF_ADDREF(*aReturn);
return NS_OK;
}
}
else if (anchorOffset >= 0) // Check if link node is the only thing selected
{
nsCOMPtr<nsIDOMNode> anchorChild;
anchorChild = GetChildAt(anchorNode,anchorOffset);
- if (anchorChild && nsHTMLEditUtils::IsLink(anchorChild) &&
+ if (anchorChild && HTMLEditUtils::IsLink(anchorChild) &&
(anchorNode == focusNode) && focusOffset == (anchorOffset+1))
{
selectedElement = do_QueryInterface(anchorChild);
bNodeFound = true;
}
}
}
}
@@ -2494,19 +2491,20 @@ nsHTMLEditor::GetSelectedElement(const n
selectedElement->GetTagName(TagName);
ToLowerCase(TagName);
anyTag = false;
}
// The "A" tag is a pain,
// used for both link(href is set) and "Named Anchor"
nsCOMPtr<nsIDOMNode> selectedNode = do_QueryInterface(selectedElement);
- if ( (isLinkTag && nsHTMLEditUtils::IsLink(selectedNode)) ||
- (isNamedAnchorTag && nsHTMLEditUtils::IsNamedAnchor(selectedNode)) )
- {
+ if ((isLinkTag &&
+ HTMLEditUtils::IsLink(selectedNode)) ||
+ (isNamedAnchorTag &&
+ HTMLEditUtils::IsNamedAnchor(selectedNode))) {
bNodeFound = true;
} else if (TagName == domTagName) { // All other tag names are handled here
bNodeFound = true;
}
if (!bNodeFound)
{
// Check if node we have is really part of the selection???
break;
@@ -3467,33 +3465,33 @@ nsHTMLEditor::TagCanContainTag(nsIAtom&
// XXX Should this handle #cdata-section too?
if (&aChildTag == nsGkAtoms::textTagName) {
childTagEnum = eHTMLTag_text;
} else {
childTagEnum = parserService->HTMLAtomTagToId(&aChildTag);
}
int32_t parentTagEnum = parserService->HTMLAtomTagToId(&aParentTag);
- return nsHTMLEditUtils::CanContain(parentTagEnum, childTagEnum);
+ return HTMLEditUtils::CanContain(parentTagEnum, childTagEnum);
}
bool
nsHTMLEditor::IsContainer(nsINode* aNode) {
MOZ_ASSERT(aNode);
int32_t tagEnum;
// XXX Should this handle #cdata-section too?
if (aNode->IsNodeOfType(nsINode::eTEXT)) {
tagEnum = eHTMLTag_text;
} else {
tagEnum =
nsContentUtils::GetParserService()->HTMLStringTagToId(aNode->NodeName());
}
- return nsHTMLEditUtils::IsContainer(tagEnum);
+ return HTMLEditUtils::IsContainer(tagEnum);
}
bool
nsHTMLEditor::IsContainer(nsIDOMNode *aNode)
{
nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
if (!node) {
return false;
@@ -3654,17 +3652,17 @@ void nsHTMLEditor::IsTextPropertySetByCo
//
bool
nsHTMLEditor::SetCaretInTableCell(nsIDOMElement* aElement)
{
nsCOMPtr<dom::Element> element = do_QueryInterface(aElement);
if (!element || !element->IsHTMLElement() ||
- !nsHTMLEditUtils::IsTableElement(element) ||
+ !HTMLEditUtils::IsTableElement(element) ||
!IsDescendantOfEditorRoot(element)) {
return false;
}
nsIContent* node = element;
while (node->HasChildren()) {
node = node->GetFirstChild();
}
@@ -3682,17 +3680,17 @@ nsHTMLEditor::SetCaretInTableCell(nsIDOM
Element*
nsHTMLEditor::GetEnclosingTable(nsINode* aNode)
{
MOZ_ASSERT(aNode);
for (nsCOMPtr<Element> block = GetBlockNodeParent(aNode);
block;
block = GetBlockNodeParent(block)) {
- if (nsHTMLEditUtils::IsTable(block)) {
+ if (HTMLEditUtils::IsTable(block)) {
return block;
}
}
return nullptr;
}
nsIDOMNode*
nsHTMLEditor::GetEnclosingTable(nsIDOMNode *aNode)
@@ -4317,28 +4315,28 @@ nsHTMLEditor::IsEmptyNodeImpl(nsINode* a
// if it's not a text node (handled above) and it's not a container,
// then we don't call it empty (it's an <hr>, or <br>, etc).
// Also, if it's an anchor then don't treat it as empty - even though
// anchors are containers, named anchors are "empty" but we don't
// want to treat them as such. Also, don't call ListItems or table
// cells empty if caller desires. Form Widgets not empty.
if (!IsContainer(aNode->AsDOMNode()) ||
- (nsHTMLEditUtils::IsNamedAnchor(aNode) ||
- nsHTMLEditUtils::IsFormWidget(aNode) ||
+ (HTMLEditUtils::IsNamedAnchor(aNode) ||
+ HTMLEditUtils::IsFormWidget(aNode) ||
(aListOrCellNotEmpty &&
- (nsHTMLEditUtils::IsListItem(aNode) ||
- nsHTMLEditUtils::IsTableCell(aNode))))) {
+ (HTMLEditUtils::IsListItem(aNode) ||
+ HTMLEditUtils::IsTableCell(aNode))))) {
*outIsEmptyNode = false;
return NS_OK;
}
// need this for later
- bool isListItemOrCell = nsHTMLEditUtils::IsListItem(aNode) ||
- nsHTMLEditUtils::IsTableCell(aNode);
+ bool isListItemOrCell = HTMLEditUtils::IsListItem(aNode) ||
+ HTMLEditUtils::IsTableCell(aNode);
// loop over children of node. if no children, or all children are either
// empty text nodes or non-editable, then node qualifies as empty
for (nsCOMPtr<nsIContent> child = aNode->GetFirstChild();
child;
child = child->GetNextSibling()) {
// Is the child editable and non-empty? if so, return false
if (nsEditor::IsEditable(child)) {
@@ -4360,23 +4358,23 @@ nsHTMLEditor::IsEmptyNodeImpl(nsINode* a
// the first br in a block doesn't count if the caller so indicated
*aSeenBR = true;
} else {
// is it an empty node of some sort?
// note: list items or table cells are not considered empty
// if they contain other lists or tables
if (child->IsElement()) {
if (isListItemOrCell) {
- if (nsHTMLEditUtils::IsList(child) ||
+ if (HTMLEditUtils::IsList(child) ||
child->IsHTMLElement(nsGkAtoms::table)) {
// break out if we find we aren't empty
*outIsEmptyNode = false;
return NS_OK;
}
- } else if (nsHTMLEditUtils::IsFormWidget(child)) {
+ } else if (HTMLEditUtils::IsFormWidget(child)) {
// is it a form widget?
// break out if we find we aren't empty
*outIsEmptyNode = false;
return NS_OK;
}
}
bool isEmptyNode = true;
@@ -4737,17 +4735,17 @@ nsHTMLEditor::CopyLastEditableChildStyle
nsCOMPtr<Element> newStyles, deepestStyle;
nsCOMPtr<nsINode> childNode = do_QueryInterface(child);
nsCOMPtr<Element> childElement;
if (childNode) {
childElement = childNode->IsElement() ? childNode->AsElement()
: childNode->GetParentElement();
}
while (childElement && (childElement->AsDOMNode() != aPreviousBlock)) {
- if (nsHTMLEditUtils::IsInlineStyle(childElement) ||
+ if (HTMLEditUtils::IsInlineStyle(childElement) ||
childElement->IsHTMLElement(nsGkAtoms::span)) {
if (newStyles) {
newStyles = InsertContainerAbove(newStyles,
childElement->NodeInfo()->NameAtom());
NS_ENSURE_STATE(newStyles);
} else {
deepestStyle = newStyles =
CreateNode(childElement->NodeInfo()->NameAtom(), newBlock, 0);
--- a/editor/libeditor/nsHTMLEditorEventListener.cpp
+++ b/editor/libeditor/nsHTMLEditorEventListener.cpp
@@ -1,21 +1,21 @@
/* -*- 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 "nsHTMLEditorEventListener.h"
+#include "HTMLEditUtils.h"
#include "mozilla/dom/Selection.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
-#include "nsHTMLEditUtils.h"
#include "nsHTMLEditor.h"
#include "nsIDOMElement.h"
#include "nsIDOMEvent.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMMouseEvent.h"
#include "nsIDOMNode.h"
#include "nsIEditor.h"
#include "nsIHTMLEditor.h"
@@ -170,17 +170,17 @@ nsHTMLEditorEventListener::MouseDown(nsI
if (selectAllNode) {
nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(selectAllNode);
if (newElement) {
node = selectAllNode;
element = newElement;
}
}
- if (isContextClick && !nsHTMLEditUtils::IsImage(node)) {
+ if (isContextClick && !HTMLEditUtils::IsImage(node)) {
selection->Collapse(parent, offset);
} else {
htmlEditor->SelectElement(element);
}
}
}
// HACK !!! Context click places the caret but the context menu consumes
// the event; so we need to check resizing state ourselves
--- a/editor/libeditor/nsHTMLEditorStyle.cpp
+++ b/editor/libeditor/nsHTMLEditorStyle.cpp
@@ -1,13 +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 "EditorUtils.h"
+#include "HTMLEditUtils.h"
#include "TextEditUtils.h"
#include "TypeInState.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
#include "mozilla/mozalloc.h"
#include "nsAString.h"
#include "nsAttrName.h"
@@ -15,17 +16,16 @@
#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 "nsHTMLEditUtils.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"
@@ -577,17 +577,17 @@ nsHTMLEditor::SplitStyleAbovePoint(nsCOM
// CSS styles
nsAutoString firstValue;
mHTMLCSSUtils->IsCSSEquivalentToHTMLInlineStyleSet(GetAsDOMNode(node),
aProperty, aAttribute, isSet, firstValue, nsHTMLCSSUtils::eSpecified);
}
if (// node is the correct inline prop
(aProperty && node->IsHTMLElement(aProperty)) ||
// node is href - test if really <a href=...
- (aProperty == nsGkAtoms::href && nsHTMLEditUtils::IsLink(node)) ||
+ (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
isSet) {
// Found a style node we need to split
int32_t offset = SplitNodeDeep(*node, *(*aNode)->AsContent(), *aOffset,
EmptyContainers::yes, aOutLeftNode,
aOutRightNode);
@@ -724,19 +724,19 @@ nsHTMLEditor::RemoveStyleInside(nsIConte
}
// then process the node itself
if (!aChildrenOnly &&
(
// node is prop we asked for
(aProperty && aNode.NodeInfo()->NameAtom() == aProperty) ||
// but check for link (<a href=...)
- (aProperty == nsGkAtoms::href && nsHTMLEditUtils::IsLink(&aNode)) ||
+ (aProperty == nsGkAtoms::href && HTMLEditUtils::IsLink(&aNode)) ||
// and for named anchors
- (aProperty == nsGkAtoms::name && nsHTMLEditUtils::IsNamedAnchor(&aNode)) ||
+ (aProperty == nsGkAtoms::name && HTMLEditUtils::IsNamedAnchor(&aNode)) ||
// or node is any prop and we asked for that
(!aProperty && NodeIsProperty(aNode))
)
) {
nsresult res;
// if we weren't passed an attribute, then we want to
// remove any matching inlinestyles entirely
if (!aAttribute || aAttribute->IsEmpty()) {
@@ -848,34 +848,34 @@ nsHTMLEditor::PromoteRangeIfStartsOrEnds
nsCOMPtr<nsINode> startNode = aRange.GetStartParent();
int32_t startOffset = aRange.StartOffset();
nsCOMPtr<nsINode> endNode = aRange.GetEndParent();
int32_t endOffset = aRange.EndOffset();
nsCOMPtr<nsINode> parent = startNode;
while (parent && !parent->IsHTMLElement(nsGkAtoms::body) &&
- !nsHTMLEditUtils::IsNamedAnchor(parent)) {
+ !HTMLEditUtils::IsNamedAnchor(parent)) {
parent = parent->GetParentNode();
}
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
- if (nsHTMLEditUtils::IsNamedAnchor(parent)) {
+ if (HTMLEditUtils::IsNamedAnchor(parent)) {
startNode = parent->GetParentNode();
startOffset = startNode ? startNode->IndexOf(parent) : -1;
}
parent = endNode;
while (parent && !parent->IsHTMLElement(nsGkAtoms::body) &&
- !nsHTMLEditUtils::IsNamedAnchor(parent)) {
+ !HTMLEditUtils::IsNamedAnchor(parent)) {
parent = parent->GetParentNode();
}
NS_ENSURE_TRUE(parent, NS_ERROR_NULL_POINTER);
- if (nsHTMLEditUtils::IsNamedAnchor(parent)) {
+ if (HTMLEditUtils::IsNamedAnchor(parent)) {
endNode = parent->GetParentNode();
endOffset = endNode ? endNode->IndexOf(parent) + 1 : 0;
}
nsresult res = aRange.SetStart(startNode, startOffset);
NS_ENSURE_SUCCESS(res, res);
res = aRange.SetEnd(endNode, endOffset);
NS_ENSURE_SUCCESS(res, res);
--- a/editor/libeditor/nsHTMLInlineTableEditor.cpp
+++ b/editor/libeditor/nsHTMLInlineTableEditor.cpp
@@ -1,32 +1,34 @@
/* 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 "HTMLEditUtils.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsError.h"
-#include "nsHTMLEditUtils.h"
#include "nsHTMLEditor.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMHTMLElement.h"
#include "nsIDOMNode.h"
#include "nsIHTMLEditor.h"
#include "nsIHTMLObjectResizer.h"
#include "nsIPresShell.h"
#include "nsLiteralString.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nscore.h"
+using namespace mozilla;
+
// Uncomment the following line if you want to disable
// table deletion when the only column/row is removed
// #define DISABLE_TABLE_DELETION 1
NS_IMETHODIMP
nsHTMLEditor::SetInlineTableEditingEnabled(bool aIsEnabled)
{
mIsInlineTableEditingEnabled = aIsEnabled;
@@ -41,18 +43,19 @@ nsHTMLEditor::GetInlineTableEditingEnabl
}
NS_IMETHODIMP
nsHTMLEditor::ShowInlineTableEditingUI(nsIDOMElement * aCell)
{
NS_ENSURE_ARG_POINTER(aCell);
// do nothing if aCell is not a table cell...
- if (!nsHTMLEditUtils::IsTableCell(aCell))
+ if (!HTMLEditUtils::IsTableCell(aCell)) {
return NS_OK;
+ }
if (mInlineEditedCell) {
NS_ERROR("call HideInlineTableEditingUI first");
return NS_ERROR_UNEXPECTED;
}
// the resizers and the shadow will be anonymous children of the body
nsCOMPtr<nsIDOMElement> bodyElement = do_QueryInterface(GetRoot());
--- a/editor/libeditor/nsHTMLObjectResizer.cpp
+++ b/editor/libeditor/nsHTMLObjectResizer.cpp
@@ -1,29 +1,29 @@
/* -*- 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 "nsHTMLObjectResizer.h"
#include "EditorUtils.h"
+#include "HTMLEditUtils.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/MathAlgorithms.h"
#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 "nsHTMLEditUtils.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"
@@ -45,18 +45,16 @@
#include "nscore.h"
#include <algorithm>
class nsISelection;
using namespace mozilla;
using namespace mozilla::dom;
-class nsHTMLEditUtils;
-
// ==================================================================
// DocumentResizeEventListener
// ==================================================================
NS_IMPL_ISUPPORTS(DocumentResizeEventListener, nsIDOMEventListener)
DocumentResizeEventListener::DocumentResizeEventListener(nsIHTMLEditor * aEditor)
{
mEditor = do_GetWeakReference(aEditor);
@@ -202,20 +200,21 @@ nsHTMLEditor::CreateResizer(int16_t aLoc
}
already_AddRefed<Element>
nsHTMLEditor::CreateShadow(nsIDOMNode* aParentNode,
nsIDOMElement* aOriginalObject)
{
// let's create an image through the element factory
nsAutoString name;
- if (nsHTMLEditUtils::IsImage(aOriginalObject))
+ if (HTMLEditUtils::IsImage(aOriginalObject)) {
name.AssignLiteral("img");
- else
+ } else {
name.AssignLiteral("span");
+ }
nsCOMPtr<nsIDOMElement> retDOM;
CreateAnonymousElement(name, aParentNode,
NS_LITERAL_STRING("mozResizingShadow"), true,
getter_AddRefs(retDOM));
NS_ENSURE_TRUE(retDOM, nullptr);
nsCOMPtr<Element> ret = do_QueryInterface(retDOM);
@@ -503,17 +502,17 @@ nsHTMLEditor::StartResizing(nsIDOMElemen
mIsResizing = true;
mActivatedHandle = do_QueryInterface(aHandle);
NS_ENSURE_STATE(mActivatedHandle || !aHandle);
mActivatedHandle->SetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated,
NS_LITERAL_STRING("true"), true);
// do we want to preserve ratio or not?
- bool preserveRatio = nsHTMLEditUtils::IsImage(mResizedObject) &&
+ bool preserveRatio = HTMLEditUtils::IsImage(mResizedObject) &&
Preferences::GetBool("editor.resizing.preserve_ratio", true);
// the way we change the position/size of the shadow depends on
// the handle
nsAutoString locationStr;
aHandle->GetAttribute(NS_LITERAL_STRING("anonlocation"), locationStr);
if (locationStr.Equals(kTopLeft)) {
SetResizeIncrements(1, 1, -1, -1, preserveRatio);
@@ -719,17 +718,17 @@ nsHTMLEditor::SetResizingInfoPosition(in
nsresult
nsHTMLEditor::SetShadowPosition(Element* aShadow,
Element* aOriginalObject,
int32_t aOriginalObjectX,
int32_t aOriginalObjectY)
{
SetAnonymousElementPosition(aOriginalObjectX, aOriginalObjectY, static_cast<nsIDOMElement*>(GetAsDOMNode(aShadow)));
- if (nsHTMLEditUtils::IsImage(aOriginalObject)) {
+ if (HTMLEditUtils::IsImage(aOriginalObject)) {
nsAutoString imageSource;
aOriginalObject->GetAttr(kNameSpaceID_None, nsGkAtoms::src, imageSource);
nsresult res = aShadow->SetAttr(kNameSpaceID_None, nsGkAtoms::src,
imageSource, true);
NS_ENSURE_SUCCESS(res, res);
}
return NS_OK;
}
--- a/editor/libeditor/nsTableEditor.cpp
+++ b/editor/libeditor/nsTableEditor.cpp
@@ -1,27 +1,27 @@
/* -*- 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 <stdio.h>
#include "EditorUtils.h"
+#include "HTMLEditUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/Selection.h"
#include "mozilla/dom/Element.h"
#include "nsAString.h"
#include "nsAlgorithm.h"
#include "nsCOMPtr.h"
#include "nsDebug.h"
#include "nsEditor.h"
#include "nsError.h"
#include "nsGkAtoms.h"
-#include "nsHTMLEditUtils.h"
#include "nsHTMLEditor.h"
#include "nsIAtom.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
#include "nsIEditor.h"
#include "nsIFrame.h"
#include "nsIHTMLEditor.h"
@@ -229,18 +229,17 @@ nsHTMLEditor::GetFirstRow(nsIDOMElement*
if (content->IsAnyOfHTMLElements(nsGkAtoms::tbody,
nsGkAtoms::thead,
nsGkAtoms::tfoot)) {
nsCOMPtr<nsIDOMNode> rowNode;
res = tableChild->GetFirstChild(getter_AddRefs(rowNode));
NS_ENSURE_SUCCESS(res, res);
// We can encounter textnodes here -- must find a row
- while (rowNode && !nsHTMLEditUtils::IsTableRow(rowNode))
- {
+ while (rowNode && !HTMLEditUtils::IsTableRow(rowNode)) {
nsCOMPtr<nsIDOMNode> nextNode;
res = rowNode->GetNextSibling(getter_AddRefs(nextNode));
NS_ENSURE_SUCCESS(res, res);
rowNode = nextNode;
}
if(rowNode)
{
@@ -268,28 +267,28 @@ NS_IMETHODIMP
nsHTMLEditor::GetNextRow(nsIDOMNode* aCurrentRowNode, nsIDOMNode **aRowNode)
{
NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
*aRowNode = nullptr;
NS_ENSURE_TRUE(aCurrentRowNode, NS_ERROR_NULL_POINTER);
- if (!nsHTMLEditUtils::IsTableRow(aCurrentRowNode))
+ if (!HTMLEditUtils::IsTableRow(aCurrentRowNode)) {
return NS_ERROR_FAILURE;
+ }
nsCOMPtr<nsIDOMNode> nextRow;
nsresult res = aCurrentRowNode->GetNextSibling(getter_AddRefs(nextRow));
NS_ENSURE_SUCCESS(res, res);
nsCOMPtr<nsIDOMNode> nextNode;
// Skip over any textnodes here
- while (nextRow && !nsHTMLEditUtils::IsTableRow(nextRow))
- {
+ while (nextRow && !HTMLEditUtils::IsTableRow(nextRow)) {
res = nextRow->GetNextSibling(getter_AddRefs(nextNode));
NS_ENSURE_SUCCESS(res, res);
nextRow = nextNode;
}
if(nextRow)
{
*aRowNode = nextRow.get();
@@ -308,18 +307,17 @@ nsHTMLEditor::GetNextRow(nsIDOMNode* aCu
NS_ENSURE_SUCCESS(res, res);
while (parentSibling)
{
res = parentSibling->GetFirstChild(getter_AddRefs(nextRow));
NS_ENSURE_SUCCESS(res, res);
// We can encounter textnodes here -- must find a row
- while (nextRow && !nsHTMLEditUtils::IsTableRow(nextRow))
- {
+ while (nextRow && !HTMLEditUtils::IsTableRow(nextRow)) {
res = nextRow->GetNextSibling(getter_AddRefs(nextNode));
NS_ENSURE_SUCCESS(res, res);
nextRow = nextNode;
}
if(nextRow)
{
*aRowNode = nextRow.get();
@@ -347,18 +345,17 @@ nsHTMLEditor::GetLastCellInRow(nsIDOMNod
*aCellNode = nullptr;
NS_ENSURE_TRUE(aRowNode, NS_ERROR_NULL_POINTER);
nsCOMPtr<nsIDOMNode> rowChild;
nsresult res = aRowNode->GetLastChild(getter_AddRefs(rowChild));
NS_ENSURE_SUCCESS(res, res);
- while (rowChild && !nsHTMLEditUtils::IsTableCell(rowChild))
- {
+ while (rowChild && !HTMLEditUtils::IsTableCell(rowChild)) {
// Skip over textnodes
nsCOMPtr<nsIDOMNode> previousChild;
res = rowChild->GetPreviousSibling(getter_AddRefs(previousChild));
NS_ENSURE_SUCCESS(res, res);
rowChild = previousChild;
}
if (rowChild)
@@ -2893,18 +2890,17 @@ nsHTMLEditor::GetCellFromRange(nsRange*
res = aRange->GetEndOffset(&endOffset);
NS_ENSURE_SUCCESS(res, res);
// If a cell is deleted, the range is collapse
// (startOffset == endOffset)
// so tell caller the cell wasn't found
if (startParent == endParent &&
endOffset == startOffset+1 &&
- nsHTMLEditUtils::IsTableCell(childNode))
- {
+ HTMLEditUtils::IsTableCell(childNode)) {
// Should we also test if frame is selected? (Use GetCellDataAt())
// (Let's not for now -- more efficient)
nsCOMPtr<nsIDOMElement> cellElement = do_QueryInterface(childNode);
*aCell = cellElement.get();
NS_ADDREF(*aCell);
return NS_OK;
}
return NS_EDITOR_ELEMENT_NOT_FOUND;
--- a/parser/htmlparser/nsHTMLTagList.h
+++ b/parser/htmlparser/nsHTMLTagList.h
@@ -25,17 +25,17 @@
nsHTMLContentSink.cpp to create a content object for a tag of that
type. Use NOTUSED, if the particular tag has a non-standard creator.
The HTML_OTHER macro is for values in the nsHTMLTag enum that are
not strictly tags.
Entries *must* use only lowercase characters.
- Don't forget to update /editor/libeditor/nsHTMLEditUtils.cpp as well.
+ Don't forget to update /editor/libeditor/HTMLEditUtils.cpp as well.
** Break these invariants and bad things will happen. **
******/
HTML_TAG(a, Anchor)
HTML_HTMLELEMENT_TAG(abbr)
HTML_HTMLELEMENT_TAG(acronym)
HTML_HTMLELEMENT_TAG(address)