Backed out changeset a66043ecf949 (bug 1346535) for build bustages
authorDorel Luca <dluca@mozilla.com>
Sat, 17 Mar 2018 00:08:00 +0200
changeset 408587 5ea69407408936dc79877a460fd9eaa1ef03b7b3
parent 408586 231448afb53d8997b569a42f682adb79042bab1a
child 408588 6a865ed8750b193075948ee444e0745552db9409
push id100984
push userdluca@mozilla.com
push dateFri, 16 Mar 2018 22:08:29 +0000
treeherdermozilla-inbound@5ea694074089 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1346535
milestone61.0a1
backs outa66043ecf949b365d7a3c09423fb0f4ea137668f
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset a66043ecf949 (bug 1346535) for build bustages
accessible/atk/DOMtoATK.cpp
accessible/atk/DOMtoATK.h
accessible/atk/moz.build
accessible/atk/nsMaiInterfaceText.cpp
xpcom/string/nsUTF8Utils.h
deleted file mode 100644
--- a/accessible/atk/DOMtoATK.cpp
+++ /dev/null
@@ -1,158 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* 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 "DOMtoATK.h"
-#include "nsUTF8Utils.h"
-
-using namespace mozilla;
-using namespace mozilla::a11y;
-
-namespace mozilla::a11y::DOMtoATK {
-
-void
-AddBOMs(nsACString& aDest, const nsACString& aSource)
-{
-  uint32_t destlength = 0;
-
-  // First compute how much room we will need.
-  for (uint32_t srci = 0; srci < aSource.Length(); ) {
-    int bytes = UTF8traits::bytes(aSource[srci]);
-    if (bytes >= 4) {
-      // Non-BMP character, will add a BOM after it.
-      destlength += 3;
-    }
-    // Skip whole character encoding.
-    srci += bytes;
-    destlength += bytes;
-  }
-
-  uint32_t desti = 0; // Index within aDest.
-
-  // Add BOMs after non-BMP characters.
-  aDest.SetLength(destlength);
-  for (uint32_t srci = 0; srci < aSource.Length(); ) {
-    uint32_t bytes = UTF8traits::bytes(aSource[srci]);
-
-    MOZ_ASSERT(bytes <= aSource.Length() - srci, "We should have the whole sequence");
-
-    // Copy whole sequence.
-    aDest.Replace(desti, bytes, Substring(aSource, srci, bytes));
-    desti += bytes;
-    srci += bytes;
-
-    if (bytes >= 4) {
-      // More than 4 bytes in UTF-8 encoding exactly means more than 16 encoded
-      // bits.  This is thus a non-BMP character which needed a surrogate
-      // pair to get encoded in UTF-16, add a BOM after it.
-
-      // And add a BOM after it.
-      aDest.Replace(desti, 3, "\xEF\xBB\xBF");
-      desti += 3;
-    }
-  }
-  MOZ_ASSERT(desti == destlength, "Incoherency between computed length"
-                                  "and actually translated length");
-}
-
-void
-ATKStringConverterHelper::AdjustOffsets(gint* aStartOffset, gint* aEndOffset,
-                                        gint count)
-{
-  MOZ_ASSERT(!mAdjusted, "DOMtoATK::ATKStringConverterHelper::AdjustOffsets needs to be called only once");
-
-  if (*aStartOffset > 0) {
-    (*aStartOffset)--;
-    mStartShifted = true;
-  }
-
-  if (*aEndOffset != -1 && *aEndOffset < count) {
-    (*aEndOffset)++;
-    mEndShifted = true;
-  }
-
-#ifdef DEBUG
-  mAdjusted = true;
-#endif
-}
-
-gchar*
-ATKStringConverterHelper::FinishUTF16toUTF8(nsCString& aStr)
-{
-  int skip = 0;
-
-  if (mStartShifted) {
-    // AdjustOffsets added a leading character.
-
-    MOZ_ASSERT(aStr.Length() > 0, "There should be a leading character");
-    MOZ_ASSERT(static_cast<int>(aStr.Length()) >= UTF8traits::bytes(aStr.CharAt(0)),
-               "The leading character should be complete");
-
-    // drop first character
-    skip = UTF8traits::bytes(aStr.CharAt(0));
-  }
-
-  if (mEndShifted) {
-    // AdjustOffsets added a trailing character.
-
-    MOZ_ASSERT(aStr.Length() > 0, "There should be a trailing character");
-
-    int trail = -1;
-    // Find beginning of last character.
-    for (trail = aStr.Length() - 1; trail >= 0; trail--) {
-      if (!UTF8traits::isInSeq(aStr.CharAt(trail))) {
-        break;
-      }
-    }
-    MOZ_ASSERT(trail >= 0,
-               "There should be at least a whole trailing character");
-    MOZ_ASSERT(trail + UTF8traits::bytes(aStr.CharAt(trail)) == static_cast<int>(aStr.Length()),
-               "The trailing character should be complete");
-
-    // Drop the last character.
-    aStr.Truncate(trail);
-  }
-
-  // copy and return, libspi will free it
-  return g_strdup(aStr.get() + skip);
-}
-
-gchar*
-ATKStringConverterHelper::ConvertAdjusted(const nsAString& aStr)
-{
-  MOZ_ASSERT(mAdjusted, "DOMtoATK::ATKStringConverterHelper::AdjustOffsets needs to be called before ATKStringConverterHelper::ConvertAdjusted");
-
-  NS_ConvertUTF16toUTF8 cautoStr(aStr);
-  if (!cautoStr.get()) {
-    return nullptr;
-  }
-
-  nsAutoCString cautoStrBOMs;
-  AddBOMs(cautoStrBOMs, cautoStr);
-  return FinishUTF16toUTF8(cautoStrBOMs);
-}
-
-gchar*
-Convert(const nsAString& aStr)
-{
-  NS_ConvertUTF16toUTF8 cautoStr(aStr);
-  if (!cautoStr.get()) {
-    return nullptr;
-  }
-
-  nsAutoCString cautoStrBOMs;
-  AddBOMs(cautoStrBOMs, cautoStr);
-  return g_strdup(cautoStrBOMs.get());
-}
-
-void
-ConvertTexttoAsterisks(nsAString& aString)
-{
-  for (uint32_t i = 0; i < aString.Length(); i++) {
-    aString.ReplaceLiteral(i, 1, u"*");
-  }
-}
-
-}
deleted file mode 100644
--- a/accessible/atk/DOMtoATK.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* 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 "AccessibleWrap.h"
-#include "nsString.h"
-#include "nsMai.h"
-
-/**
- * ATK offsets are counted in unicode codepoints, while DOM offsets are counted
- * in UTF-16 code units.  That makes a difference for non-BMP characters,
- * which need two UTF-16 code units to be represented (a pair of surrogates),
- * while they are just one unicode character.
- *
- * To keep synchronization between ATK offsets (unicode codepoints) and DOM
- * offsets (UTF-16 code units), after translation from UTF-16 to UTF-8 we add a
- * BOM after each non-BMP character (which would otherwise use 2 UTF-16
- * code units for only 1 unicode codepoint).
- *
- * BOMs (Byte Order Marks, U+FEFF, also known as ZERO WIDTH NO-BREAK SPACE, but
- * that usage is deprecated) normally only appear at the beginning of unicode
- * files, but their occurrence within text (notably after cut&paste) is not
- * uncommon, and are thus considered as non-text.
- *
- * Since the selection requested through ATK may not contain both surrogates
- * at the ends of the selection, we need to fetch one UTF-16 code point more
- * on both side, and get rid of it before returning the string to ATK. The
- * ATKStringConverterHelper class maintains this, NewATKString should be used
- * to call it properly.
- *
- * In the end,
- * - if the start is between the high and low surrogates, the UTF-8 result
- * includes a BOM from it but not the character
- * - if the end is between the high and low surrogates, the UTF-8 result
- * includes the character but *not* the BOM
- * - all non-BMP characters that are fully in the string are in the UTF-8 result
- * as character followed by BOM
- */
-namespace mozilla {
-namespace a11y {
-
-namespace DOMtoATK
-{
-
-  /**
-   * Converts a string of accessible text into ATK gchar* string (by adding
-   * BOMs). This can be used when offsets do not need to be adjusted because
-   * ends of the string can not fall between surrogates.
-   */
-  gchar* Convert(const nsAString& aStr);
-
-  /**
-   * Add a BOM after each non-BMP character.
-   */
-  void AddBOMs(nsACString& aDest, const nsACString& aSource);
-
-  /**
-   * Replace all characters with asterisks (e.g. for password fields).
-   */
-  void ConvertTexttoAsterisks(nsAString& aString);
-
-  /**
-   * Parameterize conversion.
-   */
-  enum class AtkStringConvertFlags : uint32_t {
-    None                   = 0,
-    ConvertTextToAsterisks = 1 << 0,
-  };
-
-  MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(AtkStringConvertFlags)
-
-  class ATKStringConverterHelper {
-  public:
-    ATKStringConverterHelper(void) :
-#ifdef DEBUG
-      mAdjusted (false),
-#endif
-      mStartShifted (false),
-      mEndShifted (false) { }
-
-    /**
-     * In order to properly get non-BMP values, offsets need to be changed
-     * to get one character more on each end, so that ConvertUTF16toUTF8 can
-     * convert surrogates even if the originally requested offsets fall between
-     * them.
-     */
-    void AdjustOffsets(gint* aStartOffset, gint* aEndOffset, gint count);
-
-    /**
-     * Converts a string of accessible text with adjusted offsets into ATK
-     * gchar* string (by adding BOMs).  Note, AdjustOffsets has to be called
-     * before getting the text passed to this.
-     */
-    gchar* ConvertAdjusted(const nsAString& aStr);
-
-  private:
-    /**
-     * Remove the additional characters requested by PrepareUTF16toUTF8.
-     */
-    gchar* FinishUTF16toUTF8(nsCString& aStr);
-
-#ifdef DEBUG
-    bool mAdjusted;
-#endif
-    bool mStartShifted;
-    bool mEndShifted;
-  };
-
-  /**
-   * Get text from aAccessible, using ATKStringConverterHelper to properly
-   * introduce appropriate BOMs.
-   */
-  template <class AccessibleOrProxy>
-  gchar* NewATKString(AccessibleOrProxy* aAccessible,
-                      gint aStartOffset, gint aEndOffset,
-                      AtkStringConvertFlags aFlags)
-  {
-    gint startOffset = aStartOffset, endOffset = aEndOffset;
-    ATKStringConverterHelper converter;
-    converter.AdjustOffsets(&startOffset, &endOffset,
-                            gint(aAccessible->CharacterCount()));
-    nsAutoString str;
-    aAccessible->TextSubstring(startOffset, endOffset, str);
-    if (aFlags & AtkStringConvertFlags::ConvertTextToAsterisks)
-      ConvertTexttoAsterisks(str);
-    return converter.ConvertAdjusted(str);
-  }
-
-  /**
-   * Get a character from aAccessible, fetching more data as appropriate to
-   * properly get non-BMP characters or a BOM as appropriate.
-   */
-  template <class AccessibleCharAt>
-  gunichar ATKCharacter(AccessibleCharAt* aAccessible, gint aOffset)
-  {
-    // char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib.
-    gunichar character = static_cast<gunichar>(aAccessible->CharAt(aOffset));
-
-    if (NS_IS_LOW_SURROGATE(character)) {
-      // Trailing surrogate, return BOM instead.
-      return 0xFEFF;
-    }
-
-    if (NS_IS_HIGH_SURROGATE(character)) {
-      // Heading surrogate, get the trailing surrogate and combine them.
-      gunichar characterLow = static_cast<gunichar>(aAccessible->CharAt(aOffset + 1));
-
-      if (!NS_IS_LOW_SURROGATE(characterLow)) {
-        // It should have been a trailing surrogate... Flag the error.
-        return 0xFFFD;
-      }
-      return SURROGATE_TO_UCS4(character, characterLow);
-    }
-
-    return character;
-  }
-
-}
-
-} // namespace a11y
-} // namespace mozilla
--- a/accessible/atk/moz.build
+++ b/accessible/atk/moz.build
@@ -9,17 +9,16 @@ EXPORTS.mozilla.a11y += [
     'HyperTextAccessibleWrap.h',
 ]
 
 SOURCES += [
     'AccessibleWrap.cpp',
     'ApplicationAccessibleWrap.cpp',
     'AtkSocketAccessible.cpp',
     'DocAccessibleWrap.cpp',
-    'DOMtoATK.cpp',
     'nsMaiHyperlink.cpp',
     'nsMaiInterfaceAction.cpp',
     'nsMaiInterfaceComponent.cpp',
     'nsMaiInterfaceDocument.cpp',
     'nsMaiInterfaceEditableText.cpp',
     'nsMaiInterfaceHyperlinkImpl.cpp',
     'nsMaiInterfaceHypertext.cpp',
     'nsMaiInterfaceImage.cpp',
--- a/accessible/atk/nsMaiInterfaceText.cpp
+++ b/accessible/atk/nsMaiInterfaceText.cpp
@@ -9,22 +9,19 @@
 #include "Accessible-inl.h"
 #include "HyperTextAccessible-inl.h"
 #include "nsMai.h"
 #include "ProxyAccessible.h"
 
 #include "nsIAccessibleTypes.h"
 #include "nsIPersistentProperties2.h"
 #include "nsISimpleEnumerator.h"
-#include "nsUTF8Utils.h"
 
 #include "mozilla/Likely.h"
 
-#include "DOMtoATK.h"
-
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 static const char* sAtkTextAttrNames[ATK_TEXT_ATTR_LAST_DEFINED];
 
 void
 ConvertTextAttributeToAtkAttribute(const nsACString& aName,
                                    const nsAString& aValue,
@@ -126,43 +123,44 @@ ConvertToAtkTextAttributeSet(nsIPersiste
   return objAttributeSet;
 }
 
 static void
 ConvertTexttoAsterisks(AccessibleWrap* accWrap, nsAString& aString)
 {
   // convert each char to "*" when it's "password text"
   if (accWrap->NativeRole() == roles::PASSWORD_TEXT) {
-    DOMtoATK::ConvertTexttoAsterisks(aString);
+    for (uint32_t i = 0; i < aString.Length(); i++)
+      aString.ReplaceLiteral(i, 1, u"*");
   }
 }
 
 extern "C" {
 
 static gchar*
 getTextCB(AtkText *aText, gint aStartOffset, gint aEndOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   nsAutoString autoStr;
   if (accWrap) {
     HyperTextAccessible* text = accWrap->AsHyperText();
-    if (!text || !text->IsTextRole() || text->IsDefunct())
+    if (!text || !text->IsTextRole())
       return nullptr;
 
-    return DOMtoATK::NewATKString(text, aStartOffset, aEndOffset,
-         accWrap->NativeRole() == roles::PASSWORD_TEXT ?
-           DOMtoATK::AtkStringConvertFlags::ConvertTextToAsterisks :
-           DOMtoATK::AtkStringConvertFlags::None);
+    text->TextSubstring(aStartOffset, aEndOffset, autoStr);
 
+    ConvertTexttoAsterisks(accWrap, autoStr);
   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
-    return DOMtoATK::NewATKString(proxy, aStartOffset, aEndOffset,
-         DOMtoATK::AtkStringConvertFlags::None);
+    proxy->TextSubstring(aStartOffset, aEndOffset, autoStr);
   }
 
-  return nullptr;
+  NS_ConvertUTF16toUTF8 cautoStr(autoStr);
+
+  //copy and return, libspi will free it.
+  return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
 
 static gchar*
 getTextAfterOffsetCB(AtkText *aText, gint aOffset,
                      AtkTextBoundary aBoundaryType,
                      gint *aStartOffset, gint *aEndOffset)
 {
     nsAutoString autoStr;
@@ -178,18 +176,18 @@ getTextAfterOffsetCB(AtkText *aText, gin
   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
     proxy->GetTextAfterOffset(aOffset, aBoundaryType, autoStr, &startOffset,
                               &endOffset);
   }
 
   *aStartOffset = startOffset;
   *aEndOffset = endOffset;
 
-  // libspi will free it.
-  return DOMtoATK::Convert(autoStr);
+  NS_ConvertUTF16toUTF8 cautoStr(autoStr);
+  return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
 
 static gchar*
 getTextAtOffsetCB(AtkText *aText, gint aOffset,
                   AtkTextBoundary aBoundaryType,
                   gint *aStartOffset, gint *aEndOffset)
 {
   nsAutoString autoStr;
@@ -205,34 +203,36 @@ getTextAtOffsetCB(AtkText *aText, gint a
   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
     proxy->GetTextAtOffset(aOffset, aBoundaryType, autoStr, &startOffset,
                            &endOffset);
   }
 
   *aStartOffset = startOffset;
   *aEndOffset = endOffset;
 
-  // libspi will free it.
-  return DOMtoATK::Convert(autoStr);
+  NS_ConvertUTF16toUTF8 cautoStr(autoStr);
+  return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
 
 static gunichar
 getCharacterAtOffsetCB(AtkText* aText, gint aOffset)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (accWrap) {
     HyperTextAccessible* text = accWrap->AsHyperText();
     if (!text || !text->IsTextRole()) {
       return 0;
     }
-    return DOMtoATK::ATKCharacter(text, aOffset);
+
+    // char16_t is unsigned short in Mozilla, gnuichar is guint32 in glib.
+    return static_cast<gunichar>(text->CharAt(aOffset));
   }
 
   if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
-    return DOMtoATK::ATKCharacter(proxy, aOffset);
+    return static_cast<gunichar>(proxy->CharAt(aOffset));
   }
 
   return 0;
 }
 
 static gchar*
 getTextBeforeOffsetCB(AtkText *aText, gint aOffset,
                       AtkTextBoundary aBoundaryType,
@@ -252,18 +252,18 @@ getTextBeforeOffsetCB(AtkText *aText, gi
   } else if (ProxyAccessible* proxy = GetProxy(ATK_OBJECT(aText))) {
     proxy->GetTextBeforeOffset(aOffset, aBoundaryType, autoStr, &startOffset,
                                &endOffset);
   }
 
   *aStartOffset = startOffset;
   *aEndOffset = endOffset;
 
-  // libspi will free it.
-  return DOMtoATK::Convert(autoStr);
+  NS_ConvertUTF16toUTF8 cautoStr(autoStr);
+  return (cautoStr.get()) ? g_strdup(cautoStr.get()) : nullptr;
 }
 
 static gint
 getCaretOffsetCB(AtkText *aText)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aText));
   if (accWrap) {
     HyperTextAccessible* text = accWrap->AsHyperText();
--- a/xpcom/string/nsUTF8Utils.h
+++ b/xpcom/string/nsUTF8Utils.h
@@ -51,40 +51,16 @@ public:
   static bool is5byte(char aChar)
   {
     return (aChar & 0xFC) == 0xF8;
   }
   static bool is6byte(char aChar)
   {
     return (aChar & 0xFE) == 0xFC;
   }
-  // return the number of bytes in a sequence beginning with aChar
-  static int bytes(char aChar)
-  {
-    if (isASCII(aChar)) {
-      return 1;
-    }
-    if (is2byte(aChar)) {
-      return 2;
-    }
-    if (is3byte(aChar)) {
-      return 3;
-    }
-    if (is4byte(aChar)) {
-      return 4;
-    }
-    if (is5byte(aChar)) {
-      return 5;
-    }
-    if (is6byte(aChar)) {
-      return 6;
-    }
-    MOZ_ASSERT_UNREACHABLE("should not be used for in-sequence characters");
-    return 1;
-  }
 };
 
 /**
  * Extract the next UCS-4 character from the buffer and return it.  The
  * pointer passed in is advanced to the start of the next character in the
  * buffer.  If non-null, the parameters err and overlong are filled in to
  * indicate that the character was represented by an overlong sequence, or
  * that an error occurred.