widget/MiscEvents.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/MiscEvents.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,180 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_MiscEvents_h__
    1.10 +#define mozilla_MiscEvents_h__
    1.11 +
    1.12 +#include <stdint.h>
    1.13 +
    1.14 +#include "mozilla/BasicEvents.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsIAtom.h"
    1.17 +#include "nsITransferable.h"
    1.18 +
    1.19 +namespace mozilla {
    1.20 +
    1.21 +/******************************************************************************
    1.22 + * mozilla::WidgetContentCommandEvent
    1.23 + ******************************************************************************/
    1.24 +
    1.25 +class WidgetContentCommandEvent : public WidgetGUIEvent
    1.26 +{
    1.27 +public:
    1.28 +  virtual WidgetContentCommandEvent* AsContentCommandEvent() MOZ_OVERRIDE
    1.29 +  {
    1.30 +    return this;
    1.31 +  }
    1.32 +
    1.33 +  WidgetContentCommandEvent(bool aIsTrusted, uint32_t aMessage,
    1.34 +                            nsIWidget* aWidget,
    1.35 +                            bool aOnlyEnabledCheck = false) :
    1.36 +    WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_CONTENT_COMMAND_EVENT),
    1.37 +    mOnlyEnabledCheck(aOnlyEnabledCheck), mSucceeded(false), mIsEnabled(false)
    1.38 +  {
    1.39 +  }
    1.40 +
    1.41 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
    1.42 +  {
    1.43 +    // This event isn't an internal event of any DOM event.
    1.44 +    NS_ASSERTION(!IsAllowedToDispatchDOMEvent(),
    1.45 +      "WidgetQueryContentEvent needs to support Duplicate()");
    1.46 +    MOZ_CRASH("WidgetQueryContentEvent doesn't support Duplicate()");
    1.47 +    return nullptr;
    1.48 +  }
    1.49 +
    1.50 +  // NS_CONTENT_COMMAND_PASTE_TRANSFERABLE
    1.51 +  nsCOMPtr<nsITransferable> mTransferable; // [in]
    1.52 +
    1.53 +  // NS_CONTENT_COMMAND_SCROLL
    1.54 +  // for mScroll.mUnit
    1.55 +  enum
    1.56 +  {
    1.57 +    eCmdScrollUnit_Line,
    1.58 +    eCmdScrollUnit_Page,
    1.59 +    eCmdScrollUnit_Whole
    1.60 +  };
    1.61 +
    1.62 +  struct ScrollInfo
    1.63 +  {
    1.64 +    ScrollInfo() :
    1.65 +      mAmount(0), mUnit(eCmdScrollUnit_Line), mIsHorizontal(false)
    1.66 +    {
    1.67 +    }
    1.68 +
    1.69 +    int32_t mAmount;    // [in]
    1.70 +    uint8_t mUnit;      // [in]
    1.71 +    bool mIsHorizontal; // [in]
    1.72 +  } mScroll;
    1.73 +
    1.74 +  bool mOnlyEnabledCheck; // [in]
    1.75 +
    1.76 +  bool mSucceeded; // [out]
    1.77 +  bool mIsEnabled; // [out]
    1.78 +
    1.79 +  void AssignContentCommandEventData(const WidgetContentCommandEvent& aEvent,
    1.80 +                                     bool aCopyTargets)
    1.81 +  {
    1.82 +    AssignGUIEventData(aEvent, aCopyTargets);
    1.83 +
    1.84 +    mScroll = aEvent.mScroll;
    1.85 +    mOnlyEnabledCheck = aEvent.mOnlyEnabledCheck;
    1.86 +    mSucceeded = aEvent.mSucceeded;
    1.87 +    mIsEnabled = aEvent.mIsEnabled;
    1.88 +  }
    1.89 +};
    1.90 +
    1.91 +/******************************************************************************
    1.92 + * mozilla::WidgetCommandEvent
    1.93 + *
    1.94 + * This sends a command to chrome.  If you want to request what is performed
    1.95 + * in focused content, you should use WidgetContentCommandEvent instead.
    1.96 + *
    1.97 + * XXX Should be |WidgetChromeCommandEvent|?
    1.98 + ******************************************************************************/
    1.99 +
   1.100 +class WidgetCommandEvent : public WidgetGUIEvent
   1.101 +{
   1.102 +public:
   1.103 +  virtual WidgetCommandEvent* AsCommandEvent() MOZ_OVERRIDE { return this; }
   1.104 +
   1.105 +  WidgetCommandEvent(bool aIsTrusted, nsIAtom* aEventType,
   1.106 +                     nsIAtom* aCommand, nsIWidget* aWidget) :
   1.107 +    WidgetGUIEvent(aIsTrusted, NS_USER_DEFINED_EVENT, aWidget,
   1.108 +                   NS_COMMAND_EVENT),
   1.109 +    command(aCommand)
   1.110 +  {
   1.111 +    userType = aEventType;
   1.112 +  }
   1.113 +
   1.114 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.115 +  {
   1.116 +    MOZ_ASSERT(eventStructType == NS_COMMAND_EVENT,
   1.117 +               "Duplicate() must be overridden by sub class");
   1.118 +    // Not copying widget, it is a weak reference.
   1.119 +    WidgetCommandEvent* result =
   1.120 +      new WidgetCommandEvent(false, userType, command, nullptr);
   1.121 +    result->AssignCommandEventData(*this, true);
   1.122 +    result->mFlags = mFlags;
   1.123 +    return result;
   1.124 +  }
   1.125 +
   1.126 +  nsCOMPtr<nsIAtom> command;
   1.127 +
   1.128 +  // XXX Not tested by test_assign_event_data.html
   1.129 +  void AssignCommandEventData(const WidgetCommandEvent& aEvent,
   1.130 +                              bool aCopyTargets)
   1.131 +  {
   1.132 +    AssignGUIEventData(aEvent, aCopyTargets);
   1.133 +
   1.134 +    // command must have been initialized with the constructor.
   1.135 +  }
   1.136 +};
   1.137 +
   1.138 +/******************************************************************************
   1.139 + * mozilla::WidgetPluginEvent
   1.140 + *
   1.141 + * This event delivers only a native event to focused plugin.
   1.142 + ******************************************************************************/
   1.143 +
   1.144 +class WidgetPluginEvent : public WidgetGUIEvent
   1.145 +{
   1.146 +public:
   1.147 +  virtual WidgetPluginEvent* AsPluginEvent() MOZ_OVERRIDE { return this; }
   1.148 +
   1.149 +  WidgetPluginEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
   1.150 +    WidgetGUIEvent(aIsTrusted, aMessage, aWidget, NS_PLUGIN_EVENT),
   1.151 +    retargetToFocusedDocument(false)
   1.152 +  {
   1.153 +  }
   1.154 +
   1.155 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.156 +  {
   1.157 +    // NOTE: PluginEvent has to be dispatched to nsIFrame::HandleEvent().
   1.158 +    //       So, this event needs to support Duplicate().
   1.159 +    MOZ_ASSERT(eventStructType == NS_PLUGIN_EVENT,
   1.160 +               "Duplicate() must be overridden by sub class");
   1.161 +    // Not copying widget, it is a weak reference.
   1.162 +    WidgetPluginEvent* result = new WidgetPluginEvent(false, message, nullptr);
   1.163 +    result->AssignPluginEventData(*this, true);
   1.164 +    result->mFlags = mFlags;
   1.165 +    return result;
   1.166 +  }
   1.167 +
   1.168 +  // If true, this event needs to be retargeted to focused document.
   1.169 +  // Otherwise, never retargeted. Defaults to false.
   1.170 +  bool retargetToFocusedDocument;
   1.171 +
   1.172 +  void AssignPluginEventData(const WidgetPluginEvent& aEvent,
   1.173 +                             bool aCopyTargets)
   1.174 +  {
   1.175 +    AssignGUIEventData(aEvent, aCopyTargets);
   1.176 +
   1.177 +    retargetToFocusedDocument = aEvent.retargetToFocusedDocument;
   1.178 +  }
   1.179 +};
   1.180 +
   1.181 +} // namespace mozilla
   1.182 +
   1.183 +#endif // mozilla_MiscEvents_h__

mercurial