Commit ed2f2242 authored by Masayuki Nakano's avatar Masayuki Nakano
Browse files

Bug 1727844 - part 7: Make `HTMLEditor` related classes use constants in...

Bug 1727844 - part 7: Make `HTMLEditor` related classes use constants in `HTMLEditUtils` to use specific character code point r=m_kato

Although we should move it into `EditorUtils`, currently, this is enough.

Differential Revision: https://phabricator.services.mozilla.com/D123874
parent 62f8f1ee
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

#include "mozilla/CSSEditUtils.h"

#include "HTMLEditUtils.h"
#include "mozilla/Assertions.h"
#include "mozilla/ChangeStyleTransaction.h"
#include "mozilla/HTMLEditor.h"
@@ -971,7 +972,7 @@ nsresult CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSetInternal(
    }
    // append the value to aValue (possibly with a leading white-space)
    if (index) {
      aValue.Append(char16_t(' '));
      aValue.Append(HTMLEditUtils::kSpace);
    }
    aValue.Append(valueString);
  }
@@ -1102,7 +1103,7 @@ bool CSSEditUtils::IsCSSEquivalentToHTMLInlineStyleSetInternal(
    } else if (nsGkAtoms::font == aHTMLProperty && aAttribute &&
               aAttribute == nsGkAtoms::face) {
      if (!htmlValueString.IsEmpty()) {
        const char16_t commaSpace[] = {char16_t(','), char16_t(' '), 0};
        const char16_t commaSpace[] = {char16_t(','), HTMLEditUtils::kSpace, 0};
        const char16_t comma[] = {char16_t(','), 0};
        htmlValueString.ReplaceSubstring(commaSpace, comma);
        nsAutoString valueStringNorm(aValue);
+3 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

#include "ChangeStyleTransaction.h"

#include "HTMLEditUtils.h"
#include "mozilla/Logging.h"
#include "mozilla/ToString.h"
#include "mozilla/dom/Element.h"  // for Element
@@ -154,7 +155,7 @@ void ChangeStyleTransaction::RemoveValueFromListOfValues(

    if (start < end && !aRemoveValue.Equals(start)) {
      outString.Append(start);
      outString.Append(' ');
      outString.Append(HTMLEditUtils::kSpace);
    }

    start = ++end;
@@ -336,7 +337,7 @@ void ChangeStyleTransaction::AddValueToMultivalueProperty(
    aValues.Assign(aNewValue);
  } else if (!ValueIncludes(aValues, aNewValue)) {
    // We already have another value but not this one; add it
    aValues.Append(char16_t(' '));
    aValues.Append(HTMLEditUtils::kSpace);
    aValues.Append(aNewValue);
  }
}
+7 −4
Original line number Diff line number Diff line
@@ -35,8 +35,11 @@ class HTMLEditUtils final {
  using Selection = dom::Selection;

 public:
  static const char16_t kSpace = 0x0020;
  static const char16_t kNBSP = 0x00A0;
  static constexpr char16_t kNewLine = '\n';
  static constexpr char16_t kCarridgeReturn = '\r';
  static constexpr char16_t kSpace = ' ';
  static constexpr char16_t kNBSP = 0x00A0;
  static constexpr char16_t kGreaterThan = '>';

  /**
   * IsSimplyEditableNode() returns true when aNode is simply editable.
@@ -1460,7 +1463,7 @@ class HTMLEditUtils final {
    MOZ_ASSERT(aOffset <= textFragment.GetLength());
    for (uint32_t i = aOffset; i; i--) {
      char16_t ch = textFragment.CharAt(i - 1);
      if (!nsCRT::IsAsciiSpace(ch) && ch != kNBSP) {
      if (!nsCRT::IsAsciiSpace(ch) && ch != HTMLEditUtils::kNBSP) {
        return Some(i - 1);
      }
    }
@@ -1484,7 +1487,7 @@ class HTMLEditUtils final {
    MOZ_ASSERT(aOffset <= textFragment.GetLength());
    for (uint32_t i = aOffset; i < textFragment.GetLength(); i++) {
      char16_t ch = textFragment.CharAt(i);
      if (!nsCRT::IsAsciiSpace(ch) && ch != kNBSP) {
      if (!nsCRT::IsAsciiSpace(ch) && ch != HTMLEditUtils::kNBSP) {
        return Some(i);
      }
    }
+1 −3
Original line number Diff line number Diff line
@@ -75,8 +75,6 @@ using LeafNodeType = HTMLEditUtils::LeafNodeType;
using LeafNodeTypes = HTMLEditUtils::LeafNodeTypes;
using WalkTreeOption = HTMLEditUtils::WalkTreeOption;

const char16_t kNBSP = 160;

// Some utilities to handle overloading of "A" tag for link and named anchor.
static bool IsLinkTag(const nsAtom& aTagName) {
  return &aTagName == nsGkAtoms::href;
@@ -5138,7 +5136,7 @@ nsresult HTMLEditor::SetAttributeOrEquivalent(Element* aElement,
    // style attribute's value
    nsAutoString existingValue;
    aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::style, existingValue);
    existingValue.Append(' ');
    existingValue.Append(HTMLEditUtils::kSpace);
    existingValue.Append(aValue);
    if (aSuppressTransaction) {
      nsresult rv = aElement->SetAttr(kNameSpaceID_None, nsGkAtoms::style,
+9 −9
Original line number Diff line number Diff line
@@ -2584,8 +2584,9 @@ nsresult HTMLEditor::InsertWithQuotationsAsSubAction(

  // It's best to put a blank line after the quoted text so that mails
  // written without thinking won't be so ugly.
  if (!aQuotedText.IsEmpty() && (aQuotedText.Last() != char16_t('\n'))) {
    quotedStuff.Append(char16_t('\n'));
  if (!aQuotedText.IsEmpty() &&
      (aQuotedText.Last() != HTMLEditUtils::kNewLine)) {
    quotedStuff.Append(HTMLEditUtils::kNewLine);
  }

  IgnoredErrorResult ignoredError;
@@ -2679,7 +2680,7 @@ nsresult HTMLEditor::InsertTextWithQuotationsInternal(
  // there aren't any there:
#ifdef DEBUG
  nsAString::const_iterator dbgStart(hunkStart);
  if (FindCharInReadable('\r', dbgStart, strEnd)) {
  if (FindCharInReadable(HTMLEditUtils::kCarridgeReturn, dbgStart, strEnd)) {
    NS_ASSERTION(
        false,
        "Return characters in DOM! InsertTextWithQuotations may be wrong");
@@ -2692,13 +2693,13 @@ nsresult HTMLEditor::InsertTextWithQuotationsInternal(
  // We will break from inside when we run out of newlines.
  for (;;) {
    // Search for the end of this line (dom newlines, see above):
    bool found = FindCharInReadable('\n', lineStart, strEnd);
    bool found = FindCharInReadable(HTMLEditUtils::kNewLine, lineStart, strEnd);
    bool quoted = false;
    if (found) {
      // if there's another newline, lineStart now points there.
      // Loop over any consecutive newline chars:
      nsAString::const_iterator firstNewline(lineStart);
      while (*lineStart == '\n') {
      while (*lineStart == HTMLEditUtils::kNewLine) {
        ++lineStart;
      }
      quoted = (*lineStart == cite);
@@ -3427,7 +3428,6 @@ nsresult HTMLEditor::HTMLWithContextInserter::FragmentFromPasteCreator::
    NS_WARNING(
        "HTMLEditor::HTMLWithContextInserter::FragmentFromPasteCreator::"
        "RemoveNonPreWhiteSpaceOnlyTextNodesForIgnoringInvisibleWhiteSpaces() "
        " "
        "failed");
    return rv;
  }
Loading