widget/MiscEvents.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_MiscEvents_h__
     7 #define mozilla_MiscEvents_h__
     9 #include <stdint.h>
    11 #include "mozilla/BasicEvents.h"
    12 #include "nsCOMPtr.h"
    13 #include "nsIAtom.h"
    14 #include "nsITransferable.h"
    16 namespace mozilla {
    18 /******************************************************************************
    19  * mozilla::WidgetContentCommandEvent
    20  ******************************************************************************/
    22 class WidgetContentCommandEvent : public WidgetGUIEvent
    23 {
    24 public:
    25   virtual WidgetContentCommandEvent* AsContentCommandEvent() MOZ_OVERRIDE
    26   {
    27     return this;
    28   }
    30   WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage,
    31                             nsIWidget* aWidget,
    32                             bool aOnlyEnabledCheck = false) :
    33     WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_CONTENT_COMMAND_EVENT),
    34     mOnlyEnabledCheck(aOnlyEnabledCheck), mSucceeded(false), mIsEnabled(false)
    35   {
    36   }
    38   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
    39   {
    40     // This event isn't an internal event of any DOM event.
    41     NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
    42       "WidgetQueryContentEvent needs to support Duplicate()");
    43     MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
    44     return nullptr;
    45   }
    47   // NS_CONTENT_COMMAND_PASTE_TRANSFERABLE
    48   nsCOMPtr<nsITransferable> mTransferable; // [in]
    50   // NS_CONTENT_COMMAND_SCROLL
    51   // for mScroll.mUnit
    52   enum
    53   {
    54     eCmdScrollUnit_Line,
    55     eCmdScrollUnit_Page,
    56     eCmdScrollUnit_Whole
    57   };
    59   struct ScrollInfo
    60   {
    61     ScrollInfo() :
    62       mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
    63     {
    64     }
    66     int32_t mAmount;    // [in]
    67     uint8_t mUnit;      // [in]
    68     bool mIsHorizontal; // [in]
    69   } mScroll;
    71   bool mOnlyEnabledCheck; // [in]
    73   bool mSucceeded; // [out]
    74   bool mIsEnabled; // [out]
    76   void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
    77                                      bool aCopyTargets)
    78   {
    79     AssignGUIEventData(aEvent, aCopyTargets);
    81     mScroll = aEvent.mScroll;
    82     mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
    83     mSucceeded = aEvent.mSucceeded;
    84     mIsEnabled = aEvent.mIsEnabled;
    85   }
    86 };
    88 /******************************************************************************
    89  * mozilla::WidgetCommandEvent
    90  *
    91  * This sends a command to chrome.  If you want to request what is performed
    92  * in focused content, you should use WidgetContentCommandEvent instead.
    93  *
    94  * XXX Should be |WidgetChromeCommandEvent|?
    95  ******************************************************************************/
    97 class WidgetCommandEvent : public WidgetGUIEvent
    98 {
    99 public:
   100   virtual WidgetCommandEvent* AsCommandEvent() MOZ_OVERRIDE { return this; }
   102   WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
   103                      nsIAtom* aCommand, nsIWidget* aWidget) :
   104     WidgetGUIEvent(aIsTrusted, NS_USER_DEFINED_EVENT, aWidget,
   105                    NS_COMMAND_EVENT),
   106     command(aCommand)
   107   {
   108     userType = aEventType;
   109   }
   111   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   112   {
   113     MOZ_ASSERT(eventStructType == NS_COMMAND_EVENT,
   114                "Duplicate() must be overridden by sub class");
   115     // Not copying widget, it is a weak reference.
   116     WidgetCommandEvent* result =
   117       new WidgetCommandEvent(false, userType, command, nullptr);
   118     result->AssignCommandEventData(*this, true);
   119     result->mFlags = mFlags;
   120     return result;
   121   }
   123   nsCOMPtr<nsIAtom> command;
   125   // XXX Not tested by test_assign_event_data.html
   126   void AssignCommandEventData(const WidgetCommandEvent& aEvent,
   127                               bool aCopyTargets)
   128   {
   129     AssignGUIEventData(aEvent, aCopyTargets);
   131     // command must have been initialized with the constructor.
   132   }
   133 };
   135 /******************************************************************************
   136  * mozilla::WidgetPluginEvent
   137  *
   138  * This event delivers only a native event to focused plugin.
   139  ******************************************************************************/
   141 class WidgetPluginEvent : public WidgetGUIEvent
   142 {
   143 public:
   144   virtual WidgetPluginEvent* AsPluginEvent() MOZ_OVERRIDE { return this; }
   146   WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
   147     WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_PLUGIN_EVENT),
   148     retargetToFocusedDocument(false)
   149   {
   150   }
   152   virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   153   {
   154     // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
   155     //       So, this event needs to support Duplicate().
   156     MOZ_ASSERT(eventStructType == NS_PLUGIN_EVENT,
   157                "Duplicate() must be overridden by sub class");
   158     // Not copying widget, it is a weak reference.
   159     WidgetPluginEvent* result = new WidgetPluginEvent(false, message, nullptr);
   160     result->AssignPluginEventData(*this, true);
   161     result->mFlags = mFlags;
   162     return result;
   163   }
   165   // If true, this event needs to be retargeted to focused document.
   166   // Otherwise, never retargeted. Defaults to false.
   167   bool retargetToFocusedDocument;
   169   void AssignPluginEventData(const WidgetPluginEvent& aEvent,
   170                              bool aCopyTargets)
   171   {
   172     AssignGUIEventData(aEvent, aCopyTargets);
   174     retargetToFocusedDocument = aEvent.retargetToFocusedDocument;
   175   }
   176 };
   178 } // namespace mozilla
   180 #endif // mozilla_MiscEvents_h__

mercurial