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