LCOV - code coverage report
Current view: directory - accessible/src/base - AccEvent.h (source / functions) Found Hit Coverage
Test: app.info Lines: 57 1 1.8 %
Date: 2012-06-02 Functions: 61 1 1.6 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Kyle Yuan (kyle.yuan@sun.com)
      24                 :  *   John Sun (john.sun@sun.com)
      25                 :  *   Alexander Surkov <surkov.alexander@gmail.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #ifndef _AccEvent_H_
      42                 : #define _AccEvent_H_
      43                 : 
      44                 : #include "nsIAccessibleEvent.h"
      45                 : 
      46                 : #include "nsAccessible.h"
      47                 : 
      48                 : class nsAccEvent;
      49                 : class nsDocAccessible;
      50                 : 
      51                 : // Constants used to point whether the event is from user input.
      52                 : enum EIsFromUserInput
      53                 : {
      54                 :   // eNoUserInput: event is not from user input
      55                 :   eNoUserInput = 0,
      56                 :   // eFromUserInput: event is from user input
      57                 :   eFromUserInput = 1,
      58                 :   // eAutoDetect: the value should be obtained from event state manager
      59                 :   eAutoDetect = -1
      60                 : };
      61                 : 
      62                 : /**
      63                 :  * Generic accessible event.
      64                 :  */
      65                 : class AccEvent
      66                 : {
      67                 : public:
      68                 : 
      69                 :   // Rule for accessible events.
      70                 :   // The rule will be applied when flushing pending events.
      71                 :   enum EEventRule {
      72                 :      // eAllowDupes : More than one event of the same type is allowed.
      73                 :      //    This event will always be emitted.
      74                 :      eAllowDupes,
      75                 : 
      76                 :      // eCoalesceFromSameSubtree : For events of the same type from the same
      77                 :      //    subtree or the same node, only the umbrella event on the ancestor
      78                 :      //    will be emitted.
      79                 :      eCoalesceFromSameSubtree,
      80                 : 
      81                 :     // eCoalesceOfSameType : For events of the same type, only the newest event
      82                 :     // will be processed.
      83                 :     eCoalesceOfSameType,
      84                 : 
      85                 :     // eCoalesceSelectionChange: coalescence of selection change events.
      86                 :     eCoalesceSelectionChange,
      87                 : 
      88                 :      // eRemoveDupes : For repeat events, only the newest event in queue
      89                 :      //    will be emitted.
      90                 :      eRemoveDupes,
      91                 : 
      92                 :      // eDoNotEmit : This event is confirmed as a duplicate, do not emit it.
      93                 :      eDoNotEmit
      94                 :   };
      95                 : 
      96                 :   // Initialize with an nsIAccessible
      97                 :   AccEvent(PRUint32 aEventType, nsAccessible* aAccessible,
      98                 :            EIsFromUserInput aIsFromUserInput = eAutoDetect,
      99                 :            EEventRule aEventRule = eRemoveDupes);
     100                 :   // Initialize with an nsIDOMNode
     101                 :   AccEvent(PRUint32 aEventType, nsINode* aNode,
     102                 :            EIsFromUserInput aIsFromUserInput = eAutoDetect,
     103                 :            EEventRule aEventRule = eRemoveDupes);
     104               0 :   virtual ~AccEvent() {}
     105                 : 
     106                 :   // AccEvent
     107               0 :   PRUint32 GetEventType() const { return mEventType; }
     108                 :   EEventRule GetEventRule() const { return mEventRule; }
     109               0 :   bool IsFromUserInput() const { return mIsFromUserInput; }
     110                 : 
     111                 :   nsAccessible *GetAccessible();
     112                 :   nsDocAccessible* GetDocAccessible();
     113                 :   nsINode* GetNode();
     114                 : 
     115                 :   /**
     116                 :    * Create and return an XPCOM object for accessible event object.
     117                 :    */
     118                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     119                 : 
     120                 :   /**
     121                 :    * Down casting.
     122                 :    */
     123                 :   enum EventGroup {
     124                 :     eGenericEvent,
     125                 :     eStateChangeEvent,
     126                 :     eTextChangeEvent,
     127                 :     eMutationEvent,
     128                 :     eHideEvent,
     129                 :     eShowEvent,
     130                 :     eCaretMoveEvent,
     131                 :     eSelectionChangeEvent,
     132                 :     eTableChangeEvent,
     133                 :     eVirtualCursorChangeEvent
     134                 :   };
     135                 : 
     136                 :   static const EventGroup kEventGroup = eGenericEvent;
     137               0 :   virtual unsigned int GetEventGroups() const
     138                 :   {
     139               0 :     return 1U << eGenericEvent;
     140                 :   }
     141                 : 
     142                 :   /**
     143                 :    * Reference counting and cycle collection.
     144                 :    */
     145               0 :   NS_INLINE_DECL_REFCOUNTING(AccEvent)
     146            1464 :   NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(AccEvent)
     147                 : 
     148                 : protected:
     149                 :   /**
     150                 :    * Get an accessible from event target node.
     151                 :    */
     152                 :   nsAccessible *GetAccessibleForNode() const;
     153                 : 
     154                 :   /**
     155                 :    * Determine whether the event is from user input by event state manager if
     156                 :    * it's not pointed explicetly.
     157                 :    */
     158                 :   void CaptureIsFromUserInput(EIsFromUserInput aIsFromUserInput);
     159                 : 
     160                 :   bool mIsFromUserInput;
     161                 :   PRUint32 mEventType;
     162                 :   EEventRule mEventRule;
     163                 :   nsRefPtr<nsAccessible> mAccessible;
     164                 :   nsCOMPtr<nsINode> mNode;
     165                 : 
     166                 :   friend class NotificationController;
     167                 : };
     168                 : 
     169                 : 
     170                 : /**
     171                 :  * Accessible state change event.
     172                 :  */
     173                 : class AccStateChangeEvent: public AccEvent
     174               0 : {
     175                 : public:
     176                 :   AccStateChangeEvent(nsAccessible* aAccessible, PRUint64 aState,
     177                 :                       bool aIsEnabled,
     178                 :                       EIsFromUserInput aIsFromUserInput = eAutoDetect);
     179                 : 
     180                 :   AccStateChangeEvent(nsINode* aNode, PRUint64 aState, bool aIsEnabled);
     181                 : 
     182                 :   AccStateChangeEvent(nsINode* aNode, PRUint64 aState);
     183                 : 
     184                 :   // AccEvent
     185                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     186                 : 
     187                 :   static const EventGroup kEventGroup = eStateChangeEvent;
     188               0 :   virtual unsigned int GetEventGroups() const
     189                 :   {
     190               0 :     return AccEvent::GetEventGroups() | (1U << eStateChangeEvent);
     191                 :   }
     192                 : 
     193                 :   // AccStateChangeEvent
     194               0 :   PRUint64 GetState() const { return mState; }
     195               0 :   bool IsStateEnabled() const { return mIsEnabled; }
     196                 : 
     197                 : private:
     198                 :   PRUint64 mState;
     199                 :   bool mIsEnabled;
     200                 : };
     201                 : 
     202                 : 
     203                 : /**
     204                 :  * Accessible text change event.
     205                 :  */
     206                 : class AccTextChangeEvent: public AccEvent
     207               0 : {
     208                 : public:
     209                 :   AccTextChangeEvent(nsAccessible* aAccessible, PRInt32 aStart,
     210                 :                      const nsAString& aModifiedText, bool aIsInserted,
     211                 :                      EIsFromUserInput aIsFromUserInput = eAutoDetect);
     212                 : 
     213                 :   // AccEvent
     214                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     215                 : 
     216                 :   static const EventGroup kEventGroup = eTextChangeEvent;
     217               0 :   virtual unsigned int GetEventGroups() const
     218                 :   {
     219               0 :     return AccEvent::GetEventGroups() | (1U << eTextChangeEvent);
     220                 :   }
     221                 : 
     222                 :   // AccTextChangeEvent
     223               0 :   PRInt32 GetStartOffset() const { return mStart; }
     224               0 :   PRUint32 GetLength() const { return mModifiedText.Length(); }
     225               0 :   bool IsTextInserted() const { return mIsInserted; }
     226               0 :   void GetModifiedText(nsAString& aModifiedText)
     227               0 :     { aModifiedText = mModifiedText; }
     228                 : 
     229                 : private:
     230                 :   PRInt32 mStart;
     231                 :   bool mIsInserted;
     232                 :   nsString mModifiedText;
     233                 : 
     234                 :   friend class NotificationController;
     235                 : };
     236                 : 
     237                 : 
     238                 : /**
     239                 :  * Base class for show and hide accessible events.
     240                 :  */
     241                 : class AccMutationEvent: public AccEvent
     242               0 : {
     243                 : public:
     244                 :   AccMutationEvent(PRUint32 aEventType, nsAccessible* aTarget,
     245                 :                    nsINode* aTargetNode);
     246                 : 
     247                 :   // Event
     248                 :   static const EventGroup kEventGroup = eMutationEvent;
     249               0 :   virtual unsigned int GetEventGroups() const
     250                 :   {
     251               0 :     return AccEvent::GetEventGroups() | (1U << eMutationEvent);
     252                 :   }
     253                 : 
     254                 :   // MutationEvent
     255               0 :   bool IsShow() const { return mEventType == nsIAccessibleEvent::EVENT_SHOW; }
     256                 :   bool IsHide() const { return mEventType == nsIAccessibleEvent::EVENT_HIDE; }
     257                 : 
     258                 : protected:
     259                 :   nsRefPtr<AccTextChangeEvent> mTextChangeEvent;
     260                 : 
     261                 :   friend class NotificationController;
     262                 : };
     263                 : 
     264                 : 
     265                 : /**
     266                 :  * Accessible hide event.
     267                 :  */
     268                 : class AccHideEvent: public AccMutationEvent
     269               0 : {
     270                 : public:
     271                 :   AccHideEvent(nsAccessible* aTarget, nsINode* aTargetNode);
     272                 : 
     273                 :   // Event
     274                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     275                 : 
     276                 :   static const EventGroup kEventGroup = eHideEvent;
     277               0 :   virtual unsigned int GetEventGroups() const
     278                 :   {
     279               0 :     return AccMutationEvent::GetEventGroups() | (1U << eHideEvent);
     280                 :   }
     281                 : 
     282                 :   // AccHideEvent
     283               0 :   nsAccessible* TargetParent() const { return mParent; }
     284               0 :   nsAccessible* TargetNextSibling() const { return mNextSibling; }
     285               0 :   nsAccessible* TargetPrevSibling() const { return mPrevSibling; }
     286                 : 
     287                 : protected:
     288                 :   nsRefPtr<nsAccessible> mParent;
     289                 :   nsRefPtr<nsAccessible> mNextSibling;
     290                 :   nsRefPtr<nsAccessible> mPrevSibling;
     291                 : 
     292                 :   friend class NotificationController;
     293                 : };
     294                 : 
     295                 : 
     296                 : /**
     297                 :  * Accessible show event.
     298                 :  */
     299                 : class AccShowEvent: public AccMutationEvent
     300               0 : {
     301                 : public:
     302                 :   AccShowEvent(nsAccessible* aTarget, nsINode* aTargetNode);
     303                 : 
     304                 :   // Event
     305                 :   static const EventGroup kEventGroup = eShowEvent;
     306               0 :   virtual unsigned int GetEventGroups() const
     307                 :   {
     308               0 :     return AccMutationEvent::GetEventGroups() | (1U << eShowEvent);
     309                 :   }
     310                 : };
     311                 : 
     312                 : 
     313                 : /**
     314                 :  * Accessible caret move event.
     315                 :  */
     316                 : class AccCaretMoveEvent: public AccEvent
     317               0 : {
     318                 : public:
     319                 :   AccCaretMoveEvent(nsAccessible* aAccessible, PRInt32 aCaretOffset);
     320                 :   AccCaretMoveEvent(nsINode* aNode);
     321                 : 
     322                 :   // AccEvent
     323                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     324                 : 
     325                 :   static const EventGroup kEventGroup = eCaretMoveEvent;
     326               0 :   virtual unsigned int GetEventGroups() const
     327                 :   {
     328               0 :     return AccEvent::GetEventGroups() | (1U << eCaretMoveEvent);
     329                 :   }
     330                 : 
     331                 :   // AccCaretMoveEvent
     332               0 :   PRInt32 GetCaretOffset() const { return mCaretOffset; }
     333                 : 
     334                 : private:
     335                 :   PRInt32 mCaretOffset;
     336                 : };
     337                 : 
     338                 : 
     339                 : /**
     340                 :  * Accessible widget selection change event.
     341                 :  */
     342                 : class AccSelChangeEvent : public AccEvent
     343                 : {
     344                 : public:
     345                 :   enum SelChangeType {
     346                 :     eSelectionAdd,
     347                 :     eSelectionRemove
     348                 :   };
     349                 : 
     350                 :   AccSelChangeEvent(nsAccessible* aWidget, nsAccessible* aItem,
     351                 :                     SelChangeType aSelChangeType);
     352                 : 
     353               0 :   virtual ~AccSelChangeEvent() { }
     354                 : 
     355                 :   // AccEvent
     356                 :   static const EventGroup kEventGroup = eSelectionChangeEvent;
     357               0 :   virtual unsigned int GetEventGroups() const
     358                 :   {
     359               0 :     return AccEvent::GetEventGroups() | (1U << eSelectionChangeEvent);
     360                 :   }
     361                 : 
     362                 :   // AccSelChangeEvent
     363               0 :   nsAccessible* Widget() const { return mWidget; }
     364                 : 
     365                 : private:
     366                 :   nsRefPtr<nsAccessible> mWidget;
     367                 :   nsRefPtr<nsAccessible> mItem;
     368                 :   SelChangeType mSelChangeType;
     369                 :   PRUint32 mPreceedingCount;
     370                 :   AccSelChangeEvent* mPackedEvent;
     371                 : 
     372                 :   friend class NotificationController;
     373                 : };
     374                 : 
     375                 : 
     376                 : /**
     377                 :  * Accessible table change event.
     378                 :  */
     379                 : class AccTableChangeEvent : public AccEvent
     380               0 : {
     381                 : public:
     382                 :   AccTableChangeEvent(nsAccessible* aAccessible, PRUint32 aEventType,
     383                 :                       PRInt32 aRowOrColIndex, PRInt32 aNumRowsOrCols);
     384                 : 
     385                 :   // AccEvent
     386                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     387                 : 
     388                 :   static const EventGroup kEventGroup = eTableChangeEvent;
     389               0 :   virtual unsigned int GetEventGroups() const
     390                 :   {
     391               0 :     return AccEvent::GetEventGroups() | (1U << eTableChangeEvent);
     392                 :   }
     393                 : 
     394                 :   // AccTableChangeEvent
     395               0 :   PRUint32 GetIndex() const { return mRowOrColIndex; }
     396               0 :   PRUint32 GetCount() const { return mNumRowsOrCols; }
     397                 : 
     398                 : private:
     399                 :   PRUint32 mRowOrColIndex;   // the start row/column after which the rows are inserted/deleted.
     400                 :   PRUint32 mNumRowsOrCols;   // the number of inserted/deleted rows/columns
     401                 : };
     402                 : 
     403                 : /**
     404                 :  * Accessible virtual cursor change event.
     405                 :  */
     406                 : class AccVCChangeEvent : public AccEvent
     407                 : {
     408                 : public:
     409                 :   AccVCChangeEvent(nsAccessible* aAccessible,
     410                 :                    nsIAccessible* aOldAccessible,
     411                 :                    PRInt32 aOldStart, PRInt32 aOldEnd);
     412                 : 
     413               0 :   virtual ~AccVCChangeEvent() { }
     414                 : 
     415                 :   // AccEvent
     416                 :   virtual already_AddRefed<nsAccEvent> CreateXPCOMObject();
     417                 : 
     418                 :   static const EventGroup kEventGroup = eVirtualCursorChangeEvent;
     419               0 :   virtual unsigned int GetEventGroups() const
     420                 :   {
     421               0 :     return AccEvent::GetEventGroups() | (1U << eVirtualCursorChangeEvent);
     422                 :   }
     423                 : 
     424                 :   // AccTableChangeEvent
     425               0 :   nsIAccessible* OldAccessible() const { return mOldAccessible; }
     426               0 :   PRInt32 OldStartOffset() const { return mOldStart; }
     427               0 :   PRInt32 OldEndOffset() const { return mOldEnd; }
     428                 : 
     429                 : private:
     430                 :   nsRefPtr<nsIAccessible> mOldAccessible;
     431                 :   PRInt32 mOldStart;
     432                 :   PRInt32 mOldEnd;
     433                 : };
     434                 : 
     435                 : /**
     436                 :  * Downcast the generic accessible event object to derived type.
     437                 :  */
     438                 : class downcast_accEvent
     439                 : {
     440                 : public:
     441               0 :   downcast_accEvent(AccEvent* e) : mRawPtr(e) { }
     442                 : 
     443                 :   template<class Destination>
     444               0 :   operator Destination*() {
     445               0 :     if (!mRawPtr)
     446               0 :       return nsnull;
     447                 : 
     448                 :     return mRawPtr->GetEventGroups() & (1U << Destination::kEventGroup) ?
     449               0 :       static_cast<Destination*>(mRawPtr) : nsnull;
     450                 :   }
     451                 : 
     452                 : private:
     453                 :   AccEvent* mRawPtr;
     454                 : };
     455                 : 
     456                 : #endif
     457                 : 

Generated by: LCOV version 1.7