widget/MouseEvents.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/MouseEvents.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,624 @@
     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_MouseEvents_h__
    1.10 +#define mozilla_MouseEvents_h__
    1.11 +
    1.12 +#include <stdint.h>
    1.13 +
    1.14 +#include "mozilla/BasicEvents.h"
    1.15 +#include "mozilla/MathAlgorithms.h"
    1.16 +#include "mozilla/dom/DataTransfer.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +#include "nsIDOMMouseEvent.h"
    1.19 +#include "nsIDOMWheelEvent.h"
    1.20 +
    1.21 +/******************************************************************************
    1.22 + * nsDragDropEventStatus
    1.23 + ******************************************************************************/
    1.24 +
    1.25 +enum nsDragDropEventStatus
    1.26 +{  
    1.27 +  // The event is a enter
    1.28 +  nsDragDropEventStatus_eDragEntered,
    1.29 +  // The event is exit
    1.30 +  nsDragDropEventStatus_eDragExited,
    1.31 +  // The event is drop
    1.32 +  nsDragDropEventStatus_eDrop
    1.33 +};
    1.34 +
    1.35 +namespace mozilla {
    1.36 +
    1.37 +namespace dom {
    1.38 +  class PBrowserParent;
    1.39 +  class PBrowserChild;
    1.40 +} // namespace dom
    1.41 +
    1.42 +/******************************************************************************
    1.43 + * mozilla::WidgetPointerHelper
    1.44 + ******************************************************************************/
    1.45 +
    1.46 +class WidgetPointerHelper
    1.47 +{
    1.48 +public:
    1.49 +  bool convertToPointer;
    1.50 +  uint32_t pointerId;
    1.51 +  uint32_t tiltX;
    1.52 +  uint32_t tiltY;
    1.53 +
    1.54 +  WidgetPointerHelper() : convertToPointer(true), pointerId(0), tiltX(0), tiltY(0) {}
    1.55 +
    1.56 +  void AssignPointerHelperData(const WidgetPointerHelper& aEvent)
    1.57 +  {
    1.58 +    convertToPointer = aEvent.convertToPointer;
    1.59 +    pointerId = aEvent.pointerId;
    1.60 +    tiltX = aEvent.tiltX;
    1.61 +    tiltY = aEvent.tiltY;
    1.62 +  }
    1.63 +};
    1.64 +
    1.65 +/******************************************************************************
    1.66 + * mozilla::WidgetMouseEventBase
    1.67 + ******************************************************************************/
    1.68 +
    1.69 +class WidgetMouseEventBase : public WidgetInputEvent
    1.70 +{
    1.71 +private:
    1.72 +  friend class dom::PBrowserParent;
    1.73 +  friend class dom::PBrowserChild;
    1.74 +
    1.75 +protected:
    1.76 +  WidgetMouseEventBase()
    1.77 +  {
    1.78 +  }
    1.79 +
    1.80 +  WidgetMouseEventBase(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
    1.81 +                       nsEventStructType aStructType) :
    1.82 +    WidgetInputEvent(aIsTrusted, aMessage, aWidget, aStructType),
    1.83 +    button(0), buttons(0), pressure(0),
    1.84 +    inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE)
    1.85 + {
    1.86 + }
    1.87 +
    1.88 +public:
    1.89 +  virtual WidgetMouseEventBase* AsMouseEventBase() MOZ_OVERRIDE { return this; }
    1.90 +
    1.91 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
    1.92 +  {
    1.93 +    MOZ_CRASH("WidgetMouseEventBase must not be most-subclass");
    1.94 +    return nullptr;
    1.95 +  }
    1.96 +
    1.97 +  /// The possible related target
    1.98 +  nsCOMPtr<nsISupports> relatedTarget;
    1.99 +
   1.100 +  enum buttonType
   1.101 +  {
   1.102 +    eLeftButton   = 0,
   1.103 +    eMiddleButton = 1,
   1.104 +    eRightButton  = 2
   1.105 +  };
   1.106 +  // Pressed button ID of mousedown or mouseup event.
   1.107 +  // This is set only when pressing a button causes the event.
   1.108 +  int16_t button;
   1.109 +
   1.110 +  enum buttonsFlag {
   1.111 +    eLeftButtonFlag   = 0x01,
   1.112 +    eRightButtonFlag  = 0x02,
   1.113 +    eMiddleButtonFlag = 0x04,
   1.114 +    // typicall, "back" button being left side of 5-button
   1.115 +    // mice, see "buttons" attribute document of DOM3 Events.
   1.116 +    e4thButtonFlag    = 0x08,
   1.117 +    // typicall, "forward" button being right side of 5-button
   1.118 +    // mice, see "buttons" attribute document of DOM3 Events.
   1.119 +    e5thButtonFlag    = 0x10
   1.120 +  };
   1.121 +
   1.122 +  // Flags of all pressed buttons at the event fired.
   1.123 +  // This is set at any mouse event, don't be confused with |button|.
   1.124 +  int16_t buttons;
   1.125 +
   1.126 +  // Finger or touch pressure of event. It ranges between 0.0 and 1.0.
   1.127 +  float pressure;
   1.128 +
   1.129 +  // Possible values at nsIDOMMouseEvent
   1.130 +  uint16_t inputSource;
   1.131 +
   1.132 +  void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent,
   1.133 +                                bool aCopyTargets)
   1.134 +  {
   1.135 +    AssignInputEventData(aEvent, aCopyTargets);
   1.136 +
   1.137 +    relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
   1.138 +    button = aEvent.button;
   1.139 +    buttons = aEvent.buttons;
   1.140 +    pressure = aEvent.pressure;
   1.141 +    inputSource = aEvent.inputSource;
   1.142 +  }
   1.143 +
   1.144 +  /**
   1.145 +   * Returns true if left click event.
   1.146 +   */
   1.147 +  bool IsLeftClickEvent() const
   1.148 +  {
   1.149 +    return message == NS_MOUSE_CLICK && button == eLeftButton;
   1.150 +  }
   1.151 +};
   1.152 +
   1.153 +/******************************************************************************
   1.154 + * mozilla::WidgetMouseEvent
   1.155 + ******************************************************************************/
   1.156 +
   1.157 +class WidgetMouseEvent : public WidgetMouseEventBase, public WidgetPointerHelper
   1.158 +{
   1.159 +private:
   1.160 +  friend class mozilla::dom::PBrowserParent;
   1.161 +  friend class mozilla::dom::PBrowserChild;
   1.162 +
   1.163 +public:
   1.164 +  enum reasonType
   1.165 +  {
   1.166 +    eReal,
   1.167 +    eSynthesized
   1.168 +  };
   1.169 +
   1.170 +  enum contextType
   1.171 +  {
   1.172 +    eNormal,
   1.173 +    eContextMenuKey
   1.174 +  };
   1.175 +
   1.176 +  enum exitType
   1.177 +  {
   1.178 +    eChild,
   1.179 +    eTopLevel
   1.180 +  };
   1.181 +
   1.182 +protected:
   1.183 +  WidgetMouseEvent()
   1.184 +  {
   1.185 +  }
   1.186 +
   1.187 +  WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
   1.188 +                   nsEventStructType aStructType, reasonType aReason) :
   1.189 +    WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aStructType),
   1.190 +    acceptActivation(false), ignoreRootScrollFrame(false),
   1.191 +    reason(aReason), context(eNormal), exit(eChild), clickCount(0)
   1.192 +  {
   1.193 +    switch (aMessage) {
   1.194 +      case NS_MOUSEENTER:
   1.195 +      case NS_MOUSELEAVE:
   1.196 +        mFlags.mBubbles = false;
   1.197 +        mFlags.mCancelable = false;
   1.198 +        break;
   1.199 +      default:
   1.200 +        break;
   1.201 +    }
   1.202 +  }
   1.203 +
   1.204 +public:
   1.205 +  virtual WidgetMouseEvent* AsMouseEvent() MOZ_OVERRIDE { return this; }
   1.206 +
   1.207 +  WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget,
   1.208 +                   reasonType aReason, contextType aContext = eNormal) :
   1.209 +    WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_EVENT),
   1.210 +    acceptActivation(false), ignoreRootScrollFrame(false),
   1.211 +    reason(aReason), context(aContext), exit(eChild), clickCount(0)
   1.212 +  {
   1.213 +    switch (aMessage) {
   1.214 +      case NS_MOUSEENTER:
   1.215 +      case NS_MOUSELEAVE:
   1.216 +        mFlags.mBubbles = false;
   1.217 +        mFlags.mCancelable = false;
   1.218 +        break;
   1.219 +      case NS_CONTEXTMENU:
   1.220 +        button = (context == eNormal) ? eRightButton : eLeftButton;
   1.221 +        break;
   1.222 +      default:
   1.223 +        break;
   1.224 +    }
   1.225 +  }
   1.226 +
   1.227 +#ifdef DEBUG
   1.228 +  virtual ~WidgetMouseEvent()
   1.229 +  {
   1.230 +    NS_WARN_IF_FALSE(message != NS_CONTEXTMENU ||
   1.231 +                     button ==
   1.232 +                       ((context == eNormal) ? eRightButton : eLeftButton),
   1.233 +                     "Wrong button set to NS_CONTEXTMENU event?");
   1.234 +  }
   1.235 +#endif
   1.236 +
   1.237 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.238 +  {
   1.239 +    MOZ_ASSERT(eventStructType == NS_MOUSE_EVENT,
   1.240 +               "Duplicate() must be overridden by sub class");
   1.241 +    // Not copying widget, it is a weak reference.
   1.242 +    WidgetMouseEvent* result =
   1.243 +      new WidgetMouseEvent(false, message, nullptr, reason, context);
   1.244 +    result->AssignMouseEventData(*this, true);
   1.245 +    result->mFlags = mFlags;
   1.246 +    return result;
   1.247 +  }
   1.248 +
   1.249 +  // Special return code for MOUSE_ACTIVATE to signal.
   1.250 +  // If the target accepts activation (1), or denies it (0).
   1.251 +  bool acceptActivation;
   1.252 +  // Whether the event should ignore scroll frame bounds during dispatch.
   1.253 +  bool ignoreRootScrollFrame;
   1.254 +
   1.255 +  reasonType reason : 4;
   1.256 +  contextType context : 4;
   1.257 +  exitType exit;
   1.258 +
   1.259 +  /// The number of mouse clicks.
   1.260 +  uint32_t clickCount;
   1.261 +
   1.262 +  void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets)
   1.263 +  {
   1.264 +    AssignMouseEventBaseData(aEvent, aCopyTargets);
   1.265 +    AssignPointerHelperData(aEvent);
   1.266 +
   1.267 +    acceptActivation = aEvent.acceptActivation;
   1.268 +    ignoreRootScrollFrame = aEvent.ignoreRootScrollFrame;
   1.269 +    clickCount = aEvent.clickCount;
   1.270 +  }
   1.271 +
   1.272 +  /**
   1.273 +   * Returns true if the event is a context menu event caused by key.
   1.274 +   */
   1.275 +  bool IsContextMenuKeyEvent() const
   1.276 +  {
   1.277 +    return message == NS_CONTEXTMENU && context == eContextMenuKey;
   1.278 +  }
   1.279 +
   1.280 +  /**
   1.281 +   * Returns true if the event is a real mouse event.  Otherwise, i.e., it's
   1.282 +   * a synthesized event by scroll or something, returns false.
   1.283 +   */
   1.284 +  bool IsReal() const
   1.285 +  {
   1.286 +    return reason == eReal;
   1.287 +  }
   1.288 +};
   1.289 +
   1.290 +/******************************************************************************
   1.291 + * mozilla::WidgetDragEvent
   1.292 + ******************************************************************************/
   1.293 +
   1.294 +class WidgetDragEvent : public WidgetMouseEvent
   1.295 +{
   1.296 +public:
   1.297 +  virtual WidgetDragEvent* AsDragEvent() MOZ_OVERRIDE { return this; }
   1.298 +
   1.299 +  WidgetDragEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
   1.300 +    WidgetMouseEvent(aIsTrusted, aMessage, aWidget, NS_DRAG_EVENT, eReal),
   1.301 +    userCancelled(false), mDefaultPreventedOnContent(false)
   1.302 +  {
   1.303 +    mFlags.mCancelable =
   1.304 +      (aMessage != NS_DRAGDROP_EXIT_SYNTH &&
   1.305 +       aMessage != NS_DRAGDROP_LEAVE_SYNTH &&
   1.306 +       aMessage != NS_DRAGDROP_END);
   1.307 +  }
   1.308 +
   1.309 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.310 +  {
   1.311 +    MOZ_ASSERT(eventStructType == NS_DRAG_EVENT,
   1.312 +               "Duplicate() must be overridden by sub class");
   1.313 +    // Not copying widget, it is a weak reference.
   1.314 +    WidgetDragEvent* result = new WidgetDragEvent(false, message, nullptr);
   1.315 +    result->AssignDragEventData(*this, true);
   1.316 +    result->mFlags = mFlags;
   1.317 +    return result;
   1.318 +  }
   1.319 +
   1.320 +  // The dragging data.
   1.321 +  nsCOMPtr<dom::DataTransfer> dataTransfer;
   1.322 +
   1.323 +  // If this is true, user has cancelled the drag operation.
   1.324 +  bool userCancelled;
   1.325 +  // If this is true, the drag event's preventDefault() is called on content.
   1.326 +  bool mDefaultPreventedOnContent;
   1.327 +
   1.328 +  // XXX Not tested by test_assign_event_data.html
   1.329 +  void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets)
   1.330 +  {
   1.331 +    AssignMouseEventData(aEvent, aCopyTargets);
   1.332 +
   1.333 +    dataTransfer = aEvent.dataTransfer;
   1.334 +    // XXX userCancelled isn't copied, is this instentionally?
   1.335 +    userCancelled = false;
   1.336 +    mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent;
   1.337 +  }
   1.338 +};
   1.339 +
   1.340 +/******************************************************************************
   1.341 + * mozilla::WidgetMouseScrollEvent
   1.342 + *
   1.343 + * This is used for legacy DOM mouse scroll events, i.e.,
   1.344 + * DOMMouseScroll and MozMousePixelScroll event.  These events are NOT hanbled
   1.345 + * by ESM even if widget dispatches them.  Use new WidgetWheelEvent instead.
   1.346 + ******************************************************************************/
   1.347 +
   1.348 +class WidgetMouseScrollEvent : public WidgetMouseEventBase
   1.349 +{
   1.350 +private:
   1.351 +  WidgetMouseScrollEvent()
   1.352 +  {
   1.353 +  }
   1.354 +
   1.355 +public:
   1.356 +  virtual WidgetMouseScrollEvent* AsMouseScrollEvent() MOZ_OVERRIDE
   1.357 +  {
   1.358 +    return this;
   1.359 +  }
   1.360 +
   1.361 +  WidgetMouseScrollEvent(bool aIsTrusted, uint32_t aMessage,
   1.362 +                         nsIWidget* aWidget) :
   1.363 +    WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_SCROLL_EVENT),
   1.364 +    delta(0), isHorizontal(false)
   1.365 +  {
   1.366 +  }
   1.367 +
   1.368 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.369 +  {
   1.370 +    MOZ_ASSERT(eventStructType == NS_MOUSE_SCROLL_EVENT,
   1.371 +               "Duplicate() must be overridden by sub class");
   1.372 +    // Not copying widget, it is a weak reference.
   1.373 +    WidgetMouseScrollEvent* result =
   1.374 +      new WidgetMouseScrollEvent(false, message, nullptr);
   1.375 +    result->AssignMouseScrollEventData(*this, true);
   1.376 +    result->mFlags = mFlags;
   1.377 +    return result;
   1.378 +  }
   1.379 +
   1.380 +  // The delta value of mouse scroll event.
   1.381 +  // If the event message is NS_MOUSE_SCROLL, the value indicates scroll amount
   1.382 +  // in lines.  However, if the value is nsIDOMUIEvent::SCROLL_PAGE_UP or
   1.383 +  // nsIDOMUIEvent::SCROLL_PAGE_DOWN, the value inducates one page scroll.
   1.384 +  // If the event message is NS_MOUSE_PIXEL_SCROLL, the value indicates scroll
   1.385 +  // amount in pixels.
   1.386 +  int32_t delta;
   1.387 +
   1.388 +  // If this is true, it may cause to scroll horizontally.
   1.389 +  // Otherwise, vertically.
   1.390 +  bool isHorizontal;
   1.391 +
   1.392 +  void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent,
   1.393 +                                  bool aCopyTargets)
   1.394 +  {
   1.395 +    AssignMouseEventBaseData(aEvent, aCopyTargets);
   1.396 +
   1.397 +    delta = aEvent.delta;
   1.398 +    isHorizontal = aEvent.isHorizontal;
   1.399 +  }
   1.400 +};
   1.401 +
   1.402 +/******************************************************************************
   1.403 + * mozilla::WidgetWheelEvent
   1.404 + ******************************************************************************/
   1.405 +
   1.406 +class WidgetWheelEvent : public WidgetMouseEventBase
   1.407 +{
   1.408 +private:
   1.409 +  friend class mozilla::dom::PBrowserParent;
   1.410 +  friend class mozilla::dom::PBrowserChild;
   1.411 +
   1.412 +  WidgetWheelEvent()
   1.413 +  {
   1.414 +  }
   1.415 +
   1.416 +public:
   1.417 +  virtual WidgetWheelEvent* AsWheelEvent() MOZ_OVERRIDE { return this; }
   1.418 +
   1.419 +  WidgetWheelEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) :
   1.420 +    WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_WHEEL_EVENT),
   1.421 +    deltaX(0.0), deltaY(0.0), deltaZ(0.0),
   1.422 +    deltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL),
   1.423 +    customizedByUserPrefs(false), isMomentum(false), isPixelOnlyDevice(false),
   1.424 +    lineOrPageDeltaX(0), lineOrPageDeltaY(0), scrollType(SCROLL_DEFAULT),
   1.425 +    overflowDeltaX(0.0), overflowDeltaY(0.0),
   1.426 +    mViewPortIsOverscrolled(false)
   1.427 +  {
   1.428 +  }
   1.429 +
   1.430 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.431 +  {
   1.432 +    MOZ_ASSERT(eventStructType == NS_WHEEL_EVENT,
   1.433 +               "Duplicate() must be overridden by sub class");
   1.434 +    // Not copying widget, it is a weak reference.
   1.435 +    WidgetWheelEvent* result = new WidgetWheelEvent(false, message, nullptr);
   1.436 +    result->AssignWheelEventData(*this, true);
   1.437 +    result->mFlags = mFlags;
   1.438 +    return result;
   1.439 +  }
   1.440 +
   1.441 +  // NOTE: deltaX, deltaY and deltaZ may be customized by
   1.442 +  //       mousewheel.*.delta_multiplier_* prefs which are applied by
   1.443 +  //       EventStateManager.  So, after widget dispatches this event,
   1.444 +  //       these delta values may have different values than before.
   1.445 +  double deltaX;
   1.446 +  double deltaY;
   1.447 +  double deltaZ;
   1.448 +
   1.449 +  // Should be one of nsIDOMWheelEvent::DOM_DELTA_*
   1.450 +  uint32_t deltaMode;
   1.451 +
   1.452 +  // Following members are for internal use only, not for DOM event.
   1.453 +
   1.454 +  // If the delta values are computed from prefs, this value is true.
   1.455 +  // Otherwise, i.e., they are computed from native events, false.
   1.456 +  bool customizedByUserPrefs;
   1.457 +
   1.458 +  // true if the event is caused by momentum.
   1.459 +  bool isMomentum;
   1.460 +
   1.461 +  // If device event handlers don't know when they should set lineOrPageDeltaX
   1.462 +  // and lineOrPageDeltaY, this is true.  Otherwise, false.
   1.463 +  // If isPixelOnlyDevice is true, ESM will generate NS_MOUSE_SCROLL events
   1.464 +  // when accumulated pixel delta values reach a line height.
   1.465 +  bool isPixelOnlyDevice;
   1.466 +
   1.467 +  // If widget sets lineOrPageDelta, EventStateManager will dispatch
   1.468 +  // NS_MOUSE_SCROLL event for compatibility.  Note that the delta value means
   1.469 +  // pages if the deltaMode is DOM_DELTA_PAGE, otherwise, lines.
   1.470 +  int32_t lineOrPageDeltaX;
   1.471 +  int32_t lineOrPageDeltaY;
   1.472 +
   1.473 +  // When the default action for an wheel event is moving history or zooming,
   1.474 +  // need to chose a delta value for doing it.
   1.475 +  int32_t GetPreferredIntDelta()
   1.476 +  {
   1.477 +    if (!lineOrPageDeltaX && !lineOrPageDeltaY) {
   1.478 +      return 0;
   1.479 +    }
   1.480 +    if (lineOrPageDeltaY && !lineOrPageDeltaX) {
   1.481 +      return lineOrPageDeltaY;
   1.482 +    }
   1.483 +    if (lineOrPageDeltaX && !lineOrPageDeltaY) {
   1.484 +      return lineOrPageDeltaX;
   1.485 +    }
   1.486 +    if ((lineOrPageDeltaX < 0 && lineOrPageDeltaY > 0) ||
   1.487 +        (lineOrPageDeltaX > 0 && lineOrPageDeltaY < 0)) {
   1.488 +      return 0; // We cannot guess the answer in this case.
   1.489 +    }
   1.490 +    return (Abs(lineOrPageDeltaX) > Abs(lineOrPageDeltaY)) ?
   1.491 +             lineOrPageDeltaX : lineOrPageDeltaY;
   1.492 +  }
   1.493 +
   1.494 +  // Scroll type
   1.495 +  // The default value is SCROLL_DEFAULT, which means EventStateManager will
   1.496 +  // select preferred scroll type automatically.
   1.497 +  enum ScrollType
   1.498 +  {
   1.499 +    SCROLL_DEFAULT,
   1.500 +    SCROLL_SYNCHRONOUSLY,
   1.501 +    SCROLL_ASYNCHRONOUSELY,
   1.502 +    SCROLL_SMOOTHLY
   1.503 +  };
   1.504 +  ScrollType scrollType;
   1.505 +
   1.506 +  // overflowed delta values for scroll, these values are set by
   1.507 +  // nsEventStateManger.  If the default action of the wheel event isn't scroll,
   1.508 +  // these values always zero.  Otherwise, remaning delta values which are
   1.509 +  // not used by scroll are set.
   1.510 +  // NOTE: deltaX, deltaY and deltaZ may be modified by EventStateManager.
   1.511 +  //       However, overflowDeltaX and overflowDeltaY indicate unused original
   1.512 +  //       delta values which are not applied the delta_multiplier prefs.
   1.513 +  //       So, if widget wanted to know the actual direction to be scrolled,
   1.514 +  //       it would need to check the deltaX and deltaY.
   1.515 +  double overflowDeltaX;
   1.516 +  double overflowDeltaY;
   1.517 +
   1.518 +  // Whether or not the parent of the currently overscrolled frame is the
   1.519 +  // ViewPort. This is false in situations when an element on the page is being
   1.520 +  // overscrolled (such as a text field), but true when the 'page' is being
   1.521 +  // overscrolled.
   1.522 +  bool mViewPortIsOverscrolled;
   1.523 +
   1.524 +  void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets)
   1.525 +  {
   1.526 +    AssignMouseEventBaseData(aEvent, aCopyTargets);
   1.527 +
   1.528 +    deltaX = aEvent.deltaX;
   1.529 +    deltaY = aEvent.deltaY;
   1.530 +    deltaZ = aEvent.deltaZ;
   1.531 +    deltaMode = aEvent.deltaMode;
   1.532 +    customizedByUserPrefs = aEvent.customizedByUserPrefs;
   1.533 +    isMomentum = aEvent.isMomentum;
   1.534 +    isPixelOnlyDevice = aEvent.isPixelOnlyDevice;
   1.535 +    lineOrPageDeltaX = aEvent.lineOrPageDeltaX;
   1.536 +    lineOrPageDeltaY = aEvent.lineOrPageDeltaY;
   1.537 +    scrollType = aEvent.scrollType;
   1.538 +    overflowDeltaX = aEvent.overflowDeltaX;
   1.539 +    overflowDeltaY = aEvent.overflowDeltaY;
   1.540 +    mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled;
   1.541 +  }
   1.542 +};
   1.543 +
   1.544 +/******************************************************************************
   1.545 + * mozilla::WidgetPointerEvent
   1.546 + ******************************************************************************/
   1.547 +
   1.548 +class WidgetPointerEvent : public WidgetMouseEvent
   1.549 +{
   1.550 +  friend class mozilla::dom::PBrowserParent;
   1.551 +  friend class mozilla::dom::PBrowserChild;
   1.552 +
   1.553 +  WidgetPointerEvent()
   1.554 +  {
   1.555 +  }
   1.556 +
   1.557 +public:
   1.558 +  virtual WidgetPointerEvent* AsPointerEvent() MOZ_OVERRIDE { return this; }
   1.559 +
   1.560 +  WidgetPointerEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget* w)
   1.561 +    : WidgetMouseEvent(aIsTrusted, aMsg, w, NS_POINTER_EVENT, eReal)
   1.562 +    , width(0)
   1.563 +    , height(0)
   1.564 +    , isPrimary(true)
   1.565 +  {
   1.566 +    UpdateFlags();
   1.567 +  }
   1.568 +
   1.569 +  WidgetPointerEvent(const WidgetMouseEvent& aEvent)
   1.570 +    : WidgetMouseEvent(aEvent)
   1.571 +    , width(0)
   1.572 +    , height(0)
   1.573 +    , isPrimary(true)
   1.574 +  {
   1.575 +    eventStructType = NS_POINTER_EVENT;
   1.576 +    UpdateFlags();
   1.577 +  }
   1.578 +
   1.579 +  void UpdateFlags()
   1.580 +  {
   1.581 +    switch (message) {
   1.582 +      case NS_POINTER_ENTER:
   1.583 +      case NS_POINTER_LEAVE:
   1.584 +        mFlags.mBubbles = false;
   1.585 +        mFlags.mCancelable = false;
   1.586 +        break;
   1.587 +      case NS_POINTER_CANCEL:
   1.588 +      case NS_POINTER_GOT_CAPTURE:
   1.589 +      case NS_POINTER_LOST_CAPTURE:
   1.590 +        mFlags.mCancelable = false;
   1.591 +        break;
   1.592 +      default:
   1.593 +        break;
   1.594 +    }
   1.595 +  }
   1.596 +
   1.597 +  virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE
   1.598 +  {
   1.599 +    MOZ_ASSERT(eventStructType == NS_POINTER_EVENT,
   1.600 +               "Duplicate() must be overridden by sub class");
   1.601 +    // Not copying widget, it is a weak reference.
   1.602 +    WidgetPointerEvent* result =
   1.603 +      new WidgetPointerEvent(false, message, nullptr);
   1.604 +    result->AssignPointerEventData(*this, true);
   1.605 +    result->mFlags = mFlags;
   1.606 +    return result;
   1.607 +  }
   1.608 +
   1.609 +  uint32_t width;
   1.610 +  uint32_t height;
   1.611 +  bool isPrimary;
   1.612 +
   1.613 +  // XXX Not tested by test_assign_event_data.html
   1.614 +  void AssignPointerEventData(const WidgetPointerEvent& aEvent,
   1.615 +                              bool aCopyTargets)
   1.616 +  {
   1.617 +    AssignMouseEventData(aEvent, aCopyTargets);
   1.618 +
   1.619 +    width = aEvent.width;
   1.620 +    height = aEvent.height;
   1.621 +    isPrimary = aEvent.isPrimary;
   1.622 +  }
   1.623 +};
   1.624 +
   1.625 +} // namespace mozilla
   1.626 +
   1.627 +#endif // mozilla_MouseEvents_h__

mercurial