michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_TextUpdater_h__ michael@0: #define mozilla_a11y_TextUpdater_h__ michael@0: michael@0: #include "AccEvent.h" michael@0: #include "HyperTextAccessible.h" michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: /** michael@0: * Used to find a difference between old and new text and fire text change michael@0: * events. michael@0: */ michael@0: class TextUpdater michael@0: { michael@0: public: michael@0: /** michael@0: * Start text of the text leaf update. michael@0: */ michael@0: static void Run(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf, michael@0: const nsAString& aNewText); michael@0: michael@0: private: michael@0: TextUpdater(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf) : michael@0: mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nullptr), michael@0: mTextOffset(-1) { } michael@0: michael@0: ~TextUpdater() michael@0: { mDocument = nullptr; mTextLeaf = nullptr; mHyperText = nullptr; } michael@0: michael@0: /** michael@0: * Update text of the text leaf accessible, fire text change and value change michael@0: * (if applicable) events for its container hypertext accessible. michael@0: */ michael@0: void DoUpdate(const nsAString& aNewText, const nsAString& aOldText, michael@0: uint32_t aSkipStart); michael@0: michael@0: private: michael@0: TextUpdater(); michael@0: TextUpdater(const TextUpdater&); michael@0: TextUpdater& operator=(const TextUpdater&); michael@0: michael@0: /** michael@0: * Fire text change events based on difference between strings. michael@0: */ michael@0: void ComputeTextChangeEvents(const nsAString& aStr1, michael@0: const nsAString& aStr2, michael@0: uint32_t* aEntries, michael@0: nsTArray >& aEvents); michael@0: michael@0: /** michael@0: * Helper to create text change events for inserted text. michael@0: */ michael@0: inline void FireInsertEvent(const nsAString& aText, uint32_t aAddlOffset, michael@0: nsTArray >& aEvents) michael@0: { michael@0: nsRefPtr event = michael@0: new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset, michael@0: aText, true); michael@0: aEvents.AppendElement(event); michael@0: } michael@0: michael@0: /** michael@0: * Helper to create text change events for removed text. michael@0: */ michael@0: inline void FireDeleteEvent(const nsAString& aText, uint32_t aAddlOffset, michael@0: nsTArray >& aEvents) michael@0: { michael@0: nsRefPtr event = michael@0: new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset, michael@0: aText, false); michael@0: aEvents.AppendElement(event); michael@0: } michael@0: michael@0: /** michael@0: * The constant used to skip string difference calculation in case of long michael@0: * strings. michael@0: */ michael@0: const static uint32_t kMaxStrLen = 1 << 6; michael@0: michael@0: private: michael@0: DocAccessible* mDocument; michael@0: TextLeafAccessible* mTextLeaf; michael@0: HyperTextAccessible* mHyperText; michael@0: int32_t mTextOffset; michael@0: }; michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif