2011-02-08 07:48:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-02-08 07:48:41 +03:00
|
|
|
|
2012-06-11 02:18:27 +04:00
|
|
|
#ifndef mozilla_a11y_TextUpdater_h__
|
|
|
|
#define mozilla_a11y_TextUpdater_h__
|
2011-02-08 07:48:41 +03:00
|
|
|
|
|
|
|
#include "AccEvent.h"
|
2012-05-31 12:04:41 +04:00
|
|
|
#include "HyperTextAccessible.h"
|
2011-02-08 07:48:41 +03:00
|
|
|
|
2012-06-11 02:18:27 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2011-02-08 07:48:41 +03:00
|
|
|
/**
|
|
|
|
* Used to find a difference between old and new text and fire text change
|
|
|
|
* events.
|
|
|
|
*/
|
|
|
|
class TextUpdater
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Start text of the text leaf update.
|
|
|
|
*/
|
2012-06-11 02:18:27 +04:00
|
|
|
static void Run(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf,
|
2011-02-08 07:48:41 +03:00
|
|
|
const nsAString& aNewText);
|
|
|
|
|
|
|
|
private:
|
2012-06-11 02:18:27 +04:00
|
|
|
TextUpdater(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf) :
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nullptr),
|
2011-02-08 07:48:41 +03:00
|
|
|
mTextOffset(-1) { }
|
|
|
|
|
|
|
|
~TextUpdater()
|
2012-07-30 18:20:58 +04:00
|
|
|
{ mDocument = nullptr; mTextLeaf = nullptr; mHyperText = nullptr; }
|
2011-02-08 07:48:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update text of the text leaf accessible, fire text change and value change
|
|
|
|
* (if applicable) events for its container hypertext accessible.
|
|
|
|
*/
|
|
|
|
void DoUpdate(const nsAString& aNewText, const nsAString& aOldText,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aSkipStart);
|
2011-02-08 07:48:41 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
TextUpdater();
|
|
|
|
TextUpdater(const TextUpdater&);
|
|
|
|
TextUpdater& operator=(const TextUpdater&);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fire text change events based on difference between strings.
|
|
|
|
*/
|
|
|
|
void ComputeTextChangeEvents(const nsAString& aStr1,
|
|
|
|
const nsAString& aStr2,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t* aEntries,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<AccEvent> >& aEvents);
|
2011-02-08 07:48:41 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to create text change events for inserted text.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void FireInsertEvent(const nsAString& aText, uint32_t aAddlOffset,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<AccEvent> >& aEvents)
|
2011-02-08 07:48:41 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> event =
|
2011-02-08 07:48:41 +03:00
|
|
|
new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
|
2011-10-17 18:59:28 +04:00
|
|
|
aText, true);
|
2011-02-08 07:48:41 +03:00
|
|
|
aEvents.AppendElement(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to create text change events for removed text.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
inline void FireDeleteEvent(const nsAString& aText, uint32_t aAddlOffset,
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<AccEvent> >& aEvents)
|
2011-02-08 07:48:41 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AccEvent> event =
|
2011-02-08 07:48:41 +03:00
|
|
|
new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
|
2011-10-17 18:59:28 +04:00
|
|
|
aText, false);
|
2011-02-08 07:48:41 +03:00
|
|
|
aEvents.AppendElement(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-04 07:57:08 +04:00
|
|
|
* The constant used to skip string difference calculation in case of long
|
|
|
|
* strings.
|
2011-02-08 07:48:41 +03:00
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
const static uint32_t kMaxStrLen = 1 << 6;
|
2011-02-08 07:48:41 +03:00
|
|
|
|
|
|
|
private:
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible* mDocument;
|
2012-06-11 02:18:27 +04:00
|
|
|
TextLeafAccessible* mTextLeaf;
|
2012-05-31 12:04:41 +04:00
|
|
|
HyperTextAccessible* mHyperText;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mTextOffset;
|
2011-02-08 07:48:41 +03:00
|
|
|
};
|
|
|
|
|
2012-06-11 02:18:27 +04:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-02-08 07:48:41 +03:00
|
|
|
#endif
|