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__
10 #include "HyperTextAccessible.h"
16 * Used to find a difference between old and new text and fire text change
22 * Start text of the text leaf update.
24 static void Run(DocAccessible
* aDocument
, TextLeafAccessible
* aTextLeaf
,
25 const nsAString
& aNewText
);
28 TextUpdater(DocAccessible
* aDocument
, TextLeafAccessible
* aTextLeaf
)
29 : mDocument(aDocument
),
41 * Update text of the text leaf accessible, fire text change and value change
42 * (if applicable) events for its container hypertext accessible.
44 void DoUpdate(const nsAString
& aNewText
, const nsAString
& aOldText
,
49 TextUpdater(const TextUpdater
&);
50 TextUpdater
& operator=(const TextUpdater
&);
53 * Fire text change events based on difference between strings.
55 void ComputeTextChangeEvents(const nsAString
& aStr1
, const nsAString
& aStr2
,
57 nsTArray
<RefPtr
<AccEvent
> >& aEvents
);
60 * Helper to create text change events for inserted text.
62 inline void FireInsertEvent(const nsAString
& aText
, uint32_t aAddlOffset
,
63 nsTArray
<RefPtr
<AccEvent
> >& aEvents
) {
64 RefPtr
<AccEvent
> event
= new AccTextChangeEvent(
65 mHyperText
, mTextOffset
+ aAddlOffset
, aText
, true);
66 aEvents
.AppendElement(event
);
70 * Helper to create text change events for removed text.
72 inline void FireDeleteEvent(const nsAString
& aText
, uint32_t aAddlOffset
,
73 nsTArray
<RefPtr
<AccEvent
> >& aEvents
) {
74 RefPtr
<AccEvent
> event
= new AccTextChangeEvent(
75 mHyperText
, mTextOffset
+ aAddlOffset
, aText
, false);
76 aEvents
.AppendElement(event
);
80 * The constant used to skip string difference calculation in case of long
83 const static uint32_t kMaxStrLen
= 1 << 6;
86 DocAccessible
* mDocument
;
87 TextLeafAccessible
* mTextLeaf
;
88 HyperTextAccessible
* mHyperText
;
93 } // namespace mozilla