2011-02-07 20:48:41 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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-07 20:48:41 -08:00
|
|
|
|
2012-06-10 15:18:27 -07:00
|
|
|
#ifndef mozilla_a11y_TextUpdater_h__
|
|
|
|
#define mozilla_a11y_TextUpdater_h__
|
2011-02-07 20:48:41 -08:00
|
|
|
|
|
|
|
#include "AccEvent.h"
|
2012-05-31 01:04:41 -07:00
|
|
|
#include "HyperTextAccessible.h"
|
2011-02-07 20:48:41 -08:00
|
|
|
|
2012-06-10 15:18:27 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2011-02-07 20:48:41 -08: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-10 15:18:27 -07:00
|
|
|
static void Run(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf,
|
2011-02-07 20:48:41 -08:00
|
|
|
const nsAString& aNewText);
|
|
|
|
|
|
|
|
private:
|
2012-06-10 15:18:27 -07:00
|
|
|
TextUpdater(DocAccessible* aDocument, TextLeafAccessible* aTextLeaf) :
|
2012-07-30 07:20:58 -07:00
|
|
|
mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nullptr),
|
2011-02-07 20:48:41 -08:00
|
|
|
mTextOffset(-1) { }
|
|
|
|
|
|
|
|
~TextUpdater()
|
2012-07-30 07:20:58 -07:00
|
|
|
{ mDocument = nullptr; mTextLeaf = nullptr; mHyperText = nullptr; }
|
2011-02-07 20:48:41 -08: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 08:56:38 -07:00
|
|
|
uint32_t aSkipStart);
|
2011-02-07 20:48:41 -08: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 08:56:38 -07:00
|
|
|
uint32_t* aEntries,
|
2011-02-07 20:48:41 -08:00
|
|
|
nsTArray<nsRefPtr<AccEvent> >& aEvents);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to create text change events for inserted text.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
inline void FireInsertEvent(const nsAString& aText, uint32_t aAddlOffset,
|
2011-02-07 20:48:41 -08:00
|
|
|
nsTArray<nsRefPtr<AccEvent> >& aEvents)
|
|
|
|
{
|
|
|
|
nsRefPtr<AccEvent> event =
|
|
|
|
new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
|
2011-10-17 07:59:28 -07:00
|
|
|
aText, true);
|
2011-02-07 20:48:41 -08:00
|
|
|
aEvents.AppendElement(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper to create text change events for removed text.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
inline void FireDeleteEvent(const nsAString& aText, uint32_t aAddlOffset,
|
2011-02-07 20:48:41 -08:00
|
|
|
nsTArray<nsRefPtr<AccEvent> >& aEvents)
|
|
|
|
{
|
|
|
|
nsRefPtr<AccEvent> event =
|
|
|
|
new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
|
2011-10-17 07:59:28 -07:00
|
|
|
aText, false);
|
2011-02-07 20:48:41 -08:00
|
|
|
aEvents.AppendElement(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-03 20:57:08 -07:00
|
|
|
* The constant used to skip string difference calculation in case of long
|
|
|
|
* strings.
|
2011-02-07 20:48:41 -08:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
const static uint32_t kMaxStrLen = 1 << 6;
|
2011-02-07 20:48:41 -08:00
|
|
|
|
|
|
|
private:
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* mDocument;
|
2012-06-10 15:18:27 -07:00
|
|
|
TextLeafAccessible* mTextLeaf;
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible* mHyperText;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mTextOffset;
|
2011-02-07 20:48:41 -08:00
|
|
|
};
|
|
|
|
|
2012-06-10 15:18:27 -07:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2011-02-07 20:48:41 -08:00
|
|
|
#endif
|