2013-03-07 16:16:10 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_a11y_SelectionManager_h__
|
|
|
|
#define mozilla_a11y_SelectionManager_h__
|
|
|
|
|
2013-03-23 05:59:48 +04:00
|
|
|
#include "nsIFrame.h"
|
2013-03-07 16:16:10 +04:00
|
|
|
#include "nsISelectionListener.h"
|
|
|
|
|
|
|
|
class nsIPresShell;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace a11y {
|
|
|
|
|
2013-10-26 18:58:53 +04:00
|
|
|
class AccEvent;
|
2014-05-01 19:45:40 +04:00
|
|
|
class HyperTextAccessible;
|
2013-03-07 16:16:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This special accessibility class is for the caret and selection management.
|
|
|
|
* There is only 1 visible caret per top level window. However, there may be
|
|
|
|
* several visible selections.
|
|
|
|
*
|
|
|
|
* The important selections are the one owned by each document, and the one in
|
|
|
|
* the currently focused control.
|
|
|
|
*
|
|
|
|
* On Windows this class is used to move an invisible system caret that
|
|
|
|
* shadows the Mozilla caret. Windows will also automatically map this to
|
|
|
|
* the MSAA caret accessible object (via OBJID_CARET) (as opposed to the root
|
|
|
|
* accessible tree for a window which is retrieved with OBJID_CLIENT).
|
|
|
|
*
|
|
|
|
* For ATK and IAccessible2, this class is used to fire caret move and
|
|
|
|
* selection change events.
|
|
|
|
*/
|
|
|
|
|
2014-02-12 05:18:31 +04:00
|
|
|
struct SelData;
|
|
|
|
|
2013-03-07 16:16:10 +04:00
|
|
|
class SelectionManager : public nsISelectionListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports
|
|
|
|
// implemented by derived nsAccessibilityService
|
|
|
|
|
|
|
|
// nsISelectionListener
|
|
|
|
NS_DECL_NSISELECTIONLISTENER
|
|
|
|
|
|
|
|
// SelectionManager
|
2013-10-26 18:58:53 +04:00
|
|
|
void Shutdown() { ClearControlSelectionListener(); }
|
2013-03-07 16:16:10 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to selection events on the focused control.
|
|
|
|
*
|
|
|
|
* Note: only one control's selection events are listened to at a time. This
|
|
|
|
* will remove the previous control's selection listener.
|
|
|
|
*/
|
|
|
|
void SetControlSelectionListener(dom::Element* aFocusedElm);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop listening to selection events on the control.
|
|
|
|
*/
|
|
|
|
void ClearControlSelectionListener();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Listen to selection events on the document.
|
|
|
|
*/
|
|
|
|
void AddDocSelectionListener(nsIPresShell* aPresShell);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop listening to selection events for a given document
|
|
|
|
*/
|
|
|
|
void RemoveDocSelectionListener(nsIPresShell* aShell);
|
|
|
|
|
|
|
|
/**
|
2013-10-26 18:58:53 +04:00
|
|
|
* Process delayed event, results in caret move and text selection change
|
|
|
|
* events.
|
2013-03-07 16:16:10 +04:00
|
|
|
*/
|
2013-10-26 18:58:53 +04:00
|
|
|
void ProcessTextSelChangeEvent(AccEvent* aEvent);
|
2013-03-07 16:16:10 +04:00
|
|
|
|
2014-05-01 19:45:40 +04:00
|
|
|
/**
|
|
|
|
* Gets the current caret offset/hypertext accessible pair. If there is no
|
|
|
|
* current pair, then returns -1 for the offset and a nullptr for the
|
|
|
|
* accessible.
|
|
|
|
*/
|
|
|
|
inline HyperTextAccessible* AccessibleWithCaret(int32_t* aCaret)
|
|
|
|
{
|
|
|
|
if (aCaret)
|
|
|
|
*aCaret = mCaretOffset;
|
|
|
|
|
|
|
|
return mAccWithCaret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update caret offset when it doesn't go through a caret move event.
|
|
|
|
*/
|
|
|
|
inline void UpdateCaretOffset(HyperTextAccessible* aItem, int32_t aOffset)
|
|
|
|
{
|
|
|
|
mAccWithCaret = aItem;
|
|
|
|
mCaretOffset = aOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ResetCaretOffset()
|
|
|
|
{
|
|
|
|
mCaretOffset = -1;
|
|
|
|
mAccWithCaret = nullptr;
|
|
|
|
}
|
|
|
|
|
2013-03-07 16:16:10 +04:00
|
|
|
protected:
|
2014-05-01 19:45:40 +04:00
|
|
|
|
|
|
|
SelectionManager();
|
|
|
|
|
2013-03-07 16:16:10 +04:00
|
|
|
/**
|
|
|
|
* Process DOM selection change. Fire selection and caret move events.
|
|
|
|
*/
|
2014-02-12 05:18:31 +04:00
|
|
|
void ProcessSelectionChanged(SelData* aSelData);
|
2013-03-07 16:16:10 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Currently focused control.
|
2017-03-01 20:03:14 +03:00
|
|
|
WeakFrame mCurrCtrlFrame;
|
2014-05-01 19:45:40 +04:00
|
|
|
int32_t mCaretOffset;
|
|
|
|
HyperTextAccessible* mAccWithCaret;
|
2013-03-07 16:16:10 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|