accessible/src/base/AccEvent.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef _AccEvent_H_
michael@0 7 #define _AccEvent_H_
michael@0 8
michael@0 9 #include "nsIAccessibleEvent.h"
michael@0 10
michael@0 11 #include "mozilla/a11y/Accessible.h"
michael@0 12
michael@0 13 namespace mozilla {
michael@0 14
michael@0 15 namespace dom {
michael@0 16 class Selection;
michael@0 17 }
michael@0 18
michael@0 19 namespace a11y {
michael@0 20
michael@0 21 class DocAccessible;
michael@0 22
michael@0 23 // Constants used to point whether the event is from user input.
michael@0 24 enum EIsFromUserInput
michael@0 25 {
michael@0 26 // eNoUserInput: event is not from user input
michael@0 27 eNoUserInput = 0,
michael@0 28 // eFromUserInput: event is from user input
michael@0 29 eFromUserInput = 1,
michael@0 30 // eAutoDetect: the value should be obtained from event state manager
michael@0 31 eAutoDetect = -1
michael@0 32 };
michael@0 33
michael@0 34 /**
michael@0 35 * Generic accessible event.
michael@0 36 */
michael@0 37 class AccEvent
michael@0 38 {
michael@0 39 public:
michael@0 40
michael@0 41 // Rule for accessible events.
michael@0 42 // The rule will be applied when flushing pending events.
michael@0 43 enum EEventRule {
michael@0 44 // eAllowDupes : More than one event of the same type is allowed.
michael@0 45 // This event will always be emitted. This flag is used for events that
michael@0 46 // don't support coalescence.
michael@0 47 eAllowDupes,
michael@0 48
michael@0 49 // eCoalesceReorder : For reorder events from the same subtree or the same
michael@0 50 // node, only the umbrella event on the ancestor will be emitted.
michael@0 51 eCoalesceReorder,
michael@0 52
michael@0 53 // eCoalesceMutationTextChange : coalesce text change events caused by
michael@0 54 // tree mutations of the same tree level.
michael@0 55 eCoalesceMutationTextChange,
michael@0 56
michael@0 57 // eCoalesceOfSameType : For events of the same type, only the newest event
michael@0 58 // will be processed.
michael@0 59 eCoalesceOfSameType,
michael@0 60
michael@0 61 // eCoalesceSelectionChange: coalescence of selection change events.
michael@0 62 eCoalesceSelectionChange,
michael@0 63
michael@0 64 // eCoalesceStateChange: coalesce state change events.
michael@0 65 eCoalesceStateChange,
michael@0 66
michael@0 67 // eCoalesceTextSelChange: coalescence of text selection change events.
michael@0 68 eCoalesceTextSelChange,
michael@0 69
michael@0 70 // eRemoveDupes : For repeat events, only the newest event in queue
michael@0 71 // will be emitted.
michael@0 72 eRemoveDupes,
michael@0 73
michael@0 74 // eDoNotEmit : This event is confirmed as a duplicate, do not emit it.
michael@0 75 eDoNotEmit
michael@0 76 };
michael@0 77
michael@0 78 // Initialize with an nsIAccessible
michael@0 79 AccEvent(uint32_t aEventType, Accessible* aAccessible,
michael@0 80 EIsFromUserInput aIsFromUserInput = eAutoDetect,
michael@0 81 EEventRule aEventRule = eRemoveDupes);
michael@0 82 virtual ~AccEvent() {}
michael@0 83
michael@0 84 // AccEvent
michael@0 85 uint32_t GetEventType() const { return mEventType; }
michael@0 86 EEventRule GetEventRule() const { return mEventRule; }
michael@0 87 bool IsFromUserInput() const { return mIsFromUserInput; }
michael@0 88 EIsFromUserInput FromUserInput() const
michael@0 89 { return static_cast<EIsFromUserInput>(mIsFromUserInput); }
michael@0 90
michael@0 91 Accessible* GetAccessible() const { return mAccessible; }
michael@0 92 DocAccessible* GetDocAccessible() const { return mAccessible->Document(); }
michael@0 93
michael@0 94 /**
michael@0 95 * Down casting.
michael@0 96 */
michael@0 97 enum EventGroup {
michael@0 98 eGenericEvent,
michael@0 99 eStateChangeEvent,
michael@0 100 eTextChangeEvent,
michael@0 101 eMutationEvent,
michael@0 102 eReorderEvent,
michael@0 103 eHideEvent,
michael@0 104 eShowEvent,
michael@0 105 eCaretMoveEvent,
michael@0 106 eTextSelChangeEvent,
michael@0 107 eSelectionChangeEvent,
michael@0 108 eTableChangeEvent,
michael@0 109 eVirtualCursorChangeEvent
michael@0 110 };
michael@0 111
michael@0 112 static const EventGroup kEventGroup = eGenericEvent;
michael@0 113 virtual unsigned int GetEventGroups() const
michael@0 114 {
michael@0 115 return 1U << eGenericEvent;
michael@0 116 }
michael@0 117
michael@0 118 /**
michael@0 119 * Reference counting and cycle collection.
michael@0 120 */
michael@0 121 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AccEvent)
michael@0 122 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(AccEvent)
michael@0 123
michael@0 124 protected:
michael@0 125 bool mIsFromUserInput;
michael@0 126 uint32_t mEventType;
michael@0 127 EEventRule mEventRule;
michael@0 128 nsRefPtr<Accessible> mAccessible;
michael@0 129
michael@0 130 friend class EventQueue;
michael@0 131 friend class AccReorderEvent;
michael@0 132 };
michael@0 133
michael@0 134
michael@0 135 /**
michael@0 136 * Accessible state change event.
michael@0 137 */
michael@0 138 class AccStateChangeEvent: public AccEvent
michael@0 139 {
michael@0 140 public:
michael@0 141 AccStateChangeEvent(Accessible* aAccessible, uint64_t aState,
michael@0 142 bool aIsEnabled,
michael@0 143 EIsFromUserInput aIsFromUserInput = eAutoDetect) :
michael@0 144 AccEvent(nsIAccessibleEvent::EVENT_STATE_CHANGE, aAccessible,
michael@0 145 aIsFromUserInput, eCoalesceStateChange),
michael@0 146 mState(aState), mIsEnabled(aIsEnabled) { }
michael@0 147
michael@0 148 AccStateChangeEvent(Accessible* aAccessible, uint64_t aState) :
michael@0 149 AccEvent(::nsIAccessibleEvent::EVENT_STATE_CHANGE, aAccessible,
michael@0 150 eAutoDetect, eCoalesceStateChange), mState(aState)
michael@0 151 { mIsEnabled = (mAccessible->State() & mState) != 0; }
michael@0 152
michael@0 153 // AccEvent
michael@0 154 static const EventGroup kEventGroup = eStateChangeEvent;
michael@0 155 virtual unsigned int GetEventGroups() const
michael@0 156 {
michael@0 157 return AccEvent::GetEventGroups() | (1U << eStateChangeEvent);
michael@0 158 }
michael@0 159
michael@0 160 // AccStateChangeEvent
michael@0 161 uint64_t GetState() const { return mState; }
michael@0 162 bool IsStateEnabled() const { return mIsEnabled; }
michael@0 163
michael@0 164 private:
michael@0 165 uint64_t mState;
michael@0 166 bool mIsEnabled;
michael@0 167
michael@0 168 friend class EventQueue;
michael@0 169 };
michael@0 170
michael@0 171
michael@0 172 /**
michael@0 173 * Accessible text change event.
michael@0 174 */
michael@0 175 class AccTextChangeEvent: public AccEvent
michael@0 176 {
michael@0 177 public:
michael@0 178 AccTextChangeEvent(Accessible* aAccessible, int32_t aStart,
michael@0 179 const nsAString& aModifiedText, bool aIsInserted,
michael@0 180 EIsFromUserInput aIsFromUserInput = eAutoDetect);
michael@0 181
michael@0 182 // AccEvent
michael@0 183 static const EventGroup kEventGroup = eTextChangeEvent;
michael@0 184 virtual unsigned int GetEventGroups() const
michael@0 185 {
michael@0 186 return AccEvent::GetEventGroups() | (1U << eTextChangeEvent);
michael@0 187 }
michael@0 188
michael@0 189 // AccTextChangeEvent
michael@0 190 int32_t GetStartOffset() const { return mStart; }
michael@0 191 uint32_t GetLength() const { return mModifiedText.Length(); }
michael@0 192 bool IsTextInserted() const { return mIsInserted; }
michael@0 193 void GetModifiedText(nsAString& aModifiedText)
michael@0 194 { aModifiedText = mModifiedText; }
michael@0 195
michael@0 196 private:
michael@0 197 int32_t mStart;
michael@0 198 bool mIsInserted;
michael@0 199 nsString mModifiedText;
michael@0 200
michael@0 201 friend class EventQueue;
michael@0 202 friend class AccReorderEvent;
michael@0 203 };
michael@0 204
michael@0 205
michael@0 206 /**
michael@0 207 * Base class for show and hide accessible events.
michael@0 208 */
michael@0 209 class AccMutationEvent: public AccEvent
michael@0 210 {
michael@0 211 public:
michael@0 212 AccMutationEvent(uint32_t aEventType, Accessible* aTarget,
michael@0 213 nsINode* aTargetNode) :
michael@0 214 AccEvent(aEventType, aTarget, eAutoDetect, eCoalesceMutationTextChange)
michael@0 215 {
michael@0 216 // Don't coalesce these since they are coalesced by reorder event. Coalesce
michael@0 217 // contained text change events.
michael@0 218 mParent = mAccessible->Parent();
michael@0 219 }
michael@0 220 virtual ~AccMutationEvent() { }
michael@0 221
michael@0 222 // Event
michael@0 223 static const EventGroup kEventGroup = eMutationEvent;
michael@0 224 virtual unsigned int GetEventGroups() const
michael@0 225 {
michael@0 226 return AccEvent::GetEventGroups() | (1U << eMutationEvent);
michael@0 227 }
michael@0 228
michael@0 229 // MutationEvent
michael@0 230 bool IsShow() const { return mEventType == nsIAccessibleEvent::EVENT_SHOW; }
michael@0 231 bool IsHide() const { return mEventType == nsIAccessibleEvent::EVENT_HIDE; }
michael@0 232
michael@0 233 protected:
michael@0 234 nsCOMPtr<nsINode> mNode;
michael@0 235 nsRefPtr<Accessible> mParent;
michael@0 236 nsRefPtr<AccTextChangeEvent> mTextChangeEvent;
michael@0 237
michael@0 238 friend class EventQueue;
michael@0 239 };
michael@0 240
michael@0 241
michael@0 242 /**
michael@0 243 * Accessible hide event.
michael@0 244 */
michael@0 245 class AccHideEvent: public AccMutationEvent
michael@0 246 {
michael@0 247 public:
michael@0 248 AccHideEvent(Accessible* aTarget, nsINode* aTargetNode);
michael@0 249
michael@0 250 // Event
michael@0 251 static const EventGroup kEventGroup = eHideEvent;
michael@0 252 virtual unsigned int GetEventGroups() const
michael@0 253 {
michael@0 254 return AccMutationEvent::GetEventGroups() | (1U << eHideEvent);
michael@0 255 }
michael@0 256
michael@0 257 // AccHideEvent
michael@0 258 Accessible* TargetParent() const { return mParent; }
michael@0 259 Accessible* TargetNextSibling() const { return mNextSibling; }
michael@0 260 Accessible* TargetPrevSibling() const { return mPrevSibling; }
michael@0 261
michael@0 262 protected:
michael@0 263 nsRefPtr<Accessible> mNextSibling;
michael@0 264 nsRefPtr<Accessible> mPrevSibling;
michael@0 265
michael@0 266 friend class EventQueue;
michael@0 267 };
michael@0 268
michael@0 269
michael@0 270 /**
michael@0 271 * Accessible show event.
michael@0 272 */
michael@0 273 class AccShowEvent: public AccMutationEvent
michael@0 274 {
michael@0 275 public:
michael@0 276 AccShowEvent(Accessible* aTarget, nsINode* aTargetNode);
michael@0 277
michael@0 278 // Event
michael@0 279 static const EventGroup kEventGroup = eShowEvent;
michael@0 280 virtual unsigned int GetEventGroups() const
michael@0 281 {
michael@0 282 return AccMutationEvent::GetEventGroups() | (1U << eShowEvent);
michael@0 283 }
michael@0 284 };
michael@0 285
michael@0 286
michael@0 287 /**
michael@0 288 * Class for reorder accessible event. Takes care about
michael@0 289 */
michael@0 290 class AccReorderEvent : public AccEvent
michael@0 291 {
michael@0 292 public:
michael@0 293 AccReorderEvent(Accessible* aTarget) :
michael@0 294 AccEvent(::nsIAccessibleEvent::EVENT_REORDER, aTarget,
michael@0 295 eAutoDetect, eCoalesceReorder) { }
michael@0 296 virtual ~AccReorderEvent() { }
michael@0 297
michael@0 298 // Event
michael@0 299 static const EventGroup kEventGroup = eReorderEvent;
michael@0 300 virtual unsigned int GetEventGroups() const
michael@0 301 {
michael@0 302 return AccEvent::GetEventGroups() | (1U << eReorderEvent);
michael@0 303 }
michael@0 304
michael@0 305 /**
michael@0 306 * Get connected with mutation event.
michael@0 307 */
michael@0 308 void AddSubMutationEvent(AccMutationEvent* aEvent)
michael@0 309 { mDependentEvents.AppendElement(aEvent); }
michael@0 310
michael@0 311 /**
michael@0 312 * Do not emit the reorder event and its connected mutation events.
michael@0 313 */
michael@0 314 void DoNotEmitAll()
michael@0 315 {
michael@0 316 mEventRule = AccEvent::eDoNotEmit;
michael@0 317 uint32_t eventsCount = mDependentEvents.Length();
michael@0 318 for (uint32_t idx = 0; idx < eventsCount; idx++)
michael@0 319 mDependentEvents[idx]->mEventRule = AccEvent::eDoNotEmit;
michael@0 320 }
michael@0 321
michael@0 322 /**
michael@0 323 * Return true if the given accessible is a target of connected mutation
michael@0 324 * event.
michael@0 325 */
michael@0 326 uint32_t IsShowHideEventTarget(const Accessible* aTarget) const;
michael@0 327
michael@0 328 protected:
michael@0 329 /**
michael@0 330 * Show and hide events causing this reorder event.
michael@0 331 */
michael@0 332 nsTArray<AccMutationEvent*> mDependentEvents;
michael@0 333
michael@0 334 friend class EventQueue;
michael@0 335 };
michael@0 336
michael@0 337
michael@0 338 /**
michael@0 339 * Accessible caret move event.
michael@0 340 */
michael@0 341 class AccCaretMoveEvent: public AccEvent
michael@0 342 {
michael@0 343 public:
michael@0 344 AccCaretMoveEvent(Accessible* aAccessible, int32_t aCaretOffset,
michael@0 345 EIsFromUserInput aIsFromUserInput = eAutoDetect) :
michael@0 346 AccEvent(::nsIAccessibleEvent::EVENT_TEXT_CARET_MOVED, aAccessible,
michael@0 347 aIsFromUserInput),
michael@0 348 mCaretOffset(aCaretOffset) { }
michael@0 349 virtual ~AccCaretMoveEvent() { }
michael@0 350
michael@0 351 // AccEvent
michael@0 352 static const EventGroup kEventGroup = eCaretMoveEvent;
michael@0 353 virtual unsigned int GetEventGroups() const
michael@0 354 {
michael@0 355 return AccEvent::GetEventGroups() | (1U << eCaretMoveEvent);
michael@0 356 }
michael@0 357
michael@0 358 // AccCaretMoveEvent
michael@0 359 int32_t GetCaretOffset() const { return mCaretOffset; }
michael@0 360
michael@0 361 private:
michael@0 362 int32_t mCaretOffset;
michael@0 363 };
michael@0 364
michael@0 365
michael@0 366 /**
michael@0 367 * Accessible text selection change event.
michael@0 368 */
michael@0 369 class AccTextSelChangeEvent : public AccEvent
michael@0 370 {
michael@0 371 public:
michael@0 372 AccTextSelChangeEvent(HyperTextAccessible* aTarget,
michael@0 373 dom::Selection* aSelection,
michael@0 374 int32_t aReason);
michael@0 375 virtual ~AccTextSelChangeEvent();
michael@0 376
michael@0 377 // AccEvent
michael@0 378 static const EventGroup kEventGroup = eTextSelChangeEvent;
michael@0 379 virtual unsigned int GetEventGroups() const
michael@0 380 {
michael@0 381 return AccEvent::GetEventGroups() | (1U << eTextSelChangeEvent);
michael@0 382 }
michael@0 383
michael@0 384 // AccTextSelChangeEvent
michael@0 385
michael@0 386 /**
michael@0 387 * Return true if the text selection change wasn't caused by pure caret move.
michael@0 388 */
michael@0 389 bool IsCaretMoveOnly() const;
michael@0 390
michael@0 391 private:
michael@0 392 nsRefPtr<dom::Selection> mSel;
michael@0 393 int32_t mReason;
michael@0 394
michael@0 395 friend class EventQueue;
michael@0 396 friend class SelectionManager;
michael@0 397 };
michael@0 398
michael@0 399
michael@0 400 /**
michael@0 401 * Accessible widget selection change event.
michael@0 402 */
michael@0 403 class AccSelChangeEvent : public AccEvent
michael@0 404 {
michael@0 405 public:
michael@0 406 enum SelChangeType {
michael@0 407 eSelectionAdd,
michael@0 408 eSelectionRemove
michael@0 409 };
michael@0 410
michael@0 411 AccSelChangeEvent(Accessible* aWidget, Accessible* aItem,
michael@0 412 SelChangeType aSelChangeType);
michael@0 413
michael@0 414 virtual ~AccSelChangeEvent() { }
michael@0 415
michael@0 416 // AccEvent
michael@0 417 static const EventGroup kEventGroup = eSelectionChangeEvent;
michael@0 418 virtual unsigned int GetEventGroups() const
michael@0 419 {
michael@0 420 return AccEvent::GetEventGroups() | (1U << eSelectionChangeEvent);
michael@0 421 }
michael@0 422
michael@0 423 // AccSelChangeEvent
michael@0 424 Accessible* Widget() const { return mWidget; }
michael@0 425
michael@0 426 private:
michael@0 427 nsRefPtr<Accessible> mWidget;
michael@0 428 nsRefPtr<Accessible> mItem;
michael@0 429 SelChangeType mSelChangeType;
michael@0 430 uint32_t mPreceedingCount;
michael@0 431 AccSelChangeEvent* mPackedEvent;
michael@0 432
michael@0 433 friend class EventQueue;
michael@0 434 };
michael@0 435
michael@0 436
michael@0 437 /**
michael@0 438 * Accessible table change event.
michael@0 439 */
michael@0 440 class AccTableChangeEvent : public AccEvent
michael@0 441 {
michael@0 442 public:
michael@0 443 AccTableChangeEvent(Accessible* aAccessible, uint32_t aEventType,
michael@0 444 int32_t aRowOrColIndex, int32_t aNumRowsOrCols);
michael@0 445
michael@0 446 // AccEvent
michael@0 447 static const EventGroup kEventGroup = eTableChangeEvent;
michael@0 448 virtual unsigned int GetEventGroups() const
michael@0 449 {
michael@0 450 return AccEvent::GetEventGroups() | (1U << eTableChangeEvent);
michael@0 451 }
michael@0 452
michael@0 453 // AccTableChangeEvent
michael@0 454 uint32_t GetIndex() const { return mRowOrColIndex; }
michael@0 455 uint32_t GetCount() const { return mNumRowsOrCols; }
michael@0 456
michael@0 457 private:
michael@0 458 uint32_t mRowOrColIndex; // the start row/column after which the rows are inserted/deleted.
michael@0 459 uint32_t mNumRowsOrCols; // the number of inserted/deleted rows/columns
michael@0 460 };
michael@0 461
michael@0 462 /**
michael@0 463 * Accessible virtual cursor change event.
michael@0 464 */
michael@0 465 class AccVCChangeEvent : public AccEvent
michael@0 466 {
michael@0 467 public:
michael@0 468 AccVCChangeEvent(Accessible* aAccessible,
michael@0 469 nsIAccessible* aOldAccessible,
michael@0 470 int32_t aOldStart, int32_t aOldEnd,
michael@0 471 int16_t aReason);
michael@0 472
michael@0 473 virtual ~AccVCChangeEvent() { }
michael@0 474
michael@0 475 // AccEvent
michael@0 476 static const EventGroup kEventGroup = eVirtualCursorChangeEvent;
michael@0 477 virtual unsigned int GetEventGroups() const
michael@0 478 {
michael@0 479 return AccEvent::GetEventGroups() | (1U << eVirtualCursorChangeEvent);
michael@0 480 }
michael@0 481
michael@0 482 // AccTableChangeEvent
michael@0 483 nsIAccessible* OldAccessible() const { return mOldAccessible; }
michael@0 484 int32_t OldStartOffset() const { return mOldStart; }
michael@0 485 int32_t OldEndOffset() const { return mOldEnd; }
michael@0 486 int32_t Reason() const { return mReason; }
michael@0 487
michael@0 488 private:
michael@0 489 nsRefPtr<nsIAccessible> mOldAccessible;
michael@0 490 int32_t mOldStart;
michael@0 491 int32_t mOldEnd;
michael@0 492 int16_t mReason;
michael@0 493 };
michael@0 494
michael@0 495 /**
michael@0 496 * Downcast the generic accessible event object to derived type.
michael@0 497 */
michael@0 498 class downcast_accEvent
michael@0 499 {
michael@0 500 public:
michael@0 501 downcast_accEvent(AccEvent* e) : mRawPtr(e) { }
michael@0 502
michael@0 503 template<class Destination>
michael@0 504 operator Destination*() {
michael@0 505 if (!mRawPtr)
michael@0 506 return nullptr;
michael@0 507
michael@0 508 return mRawPtr->GetEventGroups() & (1U << Destination::kEventGroup) ?
michael@0 509 static_cast<Destination*>(mRawPtr) : nullptr;
michael@0 510 }
michael@0 511
michael@0 512 private:
michael@0 513 AccEvent* mRawPtr;
michael@0 514 };
michael@0 515
michael@0 516 /**
michael@0 517 * Return a new xpcom accessible event for the given internal one.
michael@0 518 */
michael@0 519 already_AddRefed<nsIAccessibleEvent>
michael@0 520 MakeXPCEvent(AccEvent* aEvent);
michael@0 521
michael@0 522 } // namespace a11y
michael@0 523 } // namespace mozilla
michael@0 524
michael@0 525 #endif
michael@0 526

mercurial