Bumping manifests a=b2g-bump
[gecko.git] / accessible / base / TextUpdater.h
blobfcaa29d4db57067139e89308ce699f3b1a07ab40
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.
19 class TextUpdater
21 public:
22 /**
23 * Start text of the text leaf update.
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.
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.
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.
59 inline void FireInsertEvent(const nsAString& aText, uint32_t aAddlOffset,
60 nsTArray<nsRefPtr<AccEvent> >& aEvents)
62 nsRefPtr<AccEvent> event =
63 new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
64 aText, true);
65 aEvents.AppendElement(event);
68 /**
69 * Helper to create text change events for removed text.
71 inline void FireDeleteEvent(const nsAString& aText, uint32_t aAddlOffset,
72 nsTArray<nsRefPtr<AccEvent> >& aEvents)
74 nsRefPtr<AccEvent> event =
75 new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
76 aText, false);
77 aEvents.AppendElement(event);
80 /**
81 * The constant used to skip string difference calculation in case of long
82 * strings.
84 const static uint32_t kMaxStrLen = 1 << 6;
86 private:
87 DocAccessible* mDocument;
88 TextLeafAccessible* mTextLeaf;
89 HyperTextAccessible* mHyperText;
90 int32_t mTextOffset;
93 } // namespace a11y
94 } // namespace mozilla
96 #endif