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
23 * Start text of the text leaf update.
25 static void Run(DocAccessible
* aDocument
, TextLeafAccessible
* aTextLeaf
,
26 const nsAString
& aNewText
);
29 TextUpdater(DocAccessible
* aDocument
, TextLeafAccessible
* aTextLeaf
) :
30 mDocument(aDocument
), mTextLeaf(aTextLeaf
), mHyperText(nullptr),
34 { mDocument
= nullptr; mTextLeaf
= nullptr; mHyperText
= nullptr; }
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
,
45 TextUpdater(const TextUpdater
&);
46 TextUpdater
& operator=(const TextUpdater
&);
49 * Fire text change events based on difference between strings.
51 void ComputeTextChangeEvents(const nsAString
& aStr1
,
52 const nsAString
& aStr2
,
54 nsTArray
<nsRefPtr
<AccEvent
> >& aEvents
);
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
,
65 aEvents
.AppendElement(event
);
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
,
77 aEvents
.AppendElement(event
);
81 * The constant used to skip string difference calculation in case of long
84 const static uint32_t kMaxStrLen
= 1 << 6;
87 DocAccessible
* mDocument
;
88 TextLeafAccessible
* mTextLeaf
;
89 HyperTextAccessible
* mHyperText
;
94 } // namespace mozilla