accessible/src/base/TextUpdater.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_a11y_TextUpdater_h__
     7 #define mozilla_a11y_TextUpdater_h__
     9 #include "AccEvent.h"
    10 #include "HyperTextAccessible.h"
    12 namespace mozilla {
    13 namespace a11y {
    15 /**
    16  * Used to find a difference between old and new text and fire text change
    17  * events.
    18  */
    19 class TextUpdater
    20 {
    21 public:
    22   /**
    23    * Start text of the text leaf update.
    24    */
    25   static void Run(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf,
    26                   const nsAString& aNewText);
    28 private:
    29   TextUpdater(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf) :
    30     mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nullptr),
    31     mTextOffset(-1) { }
    33   ~TextUpdater()
    34     { mDocument = nullptr; mTextLeaf = nullptr; mHyperText = nullptr; }
    36   /**
    37    * Update text of the text leaf accessible, fire text change and value change
    38    * (if applicable) events for its container hypertext accessible.
    39    */
    40   void DoUpdate(const nsAString& aNewText, const nsAString& aOldText,
    41                 uint32_t aSkipStart);
    43 private:
    44   TextUpdater();
    45   TextUpdater(const TextUpdater&);
    46   TextUpdater& operator=(const TextUpdater&);
    48   /**
    49    * Fire text change events based on difference between strings.
    50    */
    51   void ComputeTextChangeEvents(const nsAString& aStr1,
    52                                const nsAString& aStr2,
    53                                uint32_t* aEntries,
    54                                nsTArray<nsRefPtr<AccEvent> >& aEvents);
    56   /**
    57    * Helper to create text change events for inserted text.
    58    */
    59   inline void FireInsertEvent(const nsAString& aText, uint32_t aAddlOffset,
    60                               nsTArray<nsRefPtr<AccEvent> >& aEvents)
    61   {
    62     nsRefPtr<AccEvent> event =
    63       new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
    64                              aText, true);
    65     aEvents.AppendElement(event);
    66   }
    68   /**
    69    * Helper to create text change events for removed text.
    70    */
    71   inline void FireDeleteEvent(const nsAString& aText, uint32_t aAddlOffset,
    72                               nsTArray<nsRefPtr<AccEvent> >& aEvents)
    73   {
    74     nsRefPtr<AccEvent> event =
    75       new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
    76                              aText, false);
    77     aEvents.AppendElement(event);
    78   }
    80   /**
    81    * The constant used to skip string difference calculation in case of long
    82    * strings.
    83    */
    84   const static uint32_t kMaxStrLen = 1 << 6;
    86 private:
    87   DocAccessible* mDocument;
    88   TextLeafAccessible* mTextLeaf;
    89   HyperTextAccessible* mHyperText;
    90   int32_t mTextOffset;
    91 };
    93 } // namespace a11y
    94 } // namespace mozilla
    96 #endif

mercurial