Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 mozilla_MouseEvents_h__ |
michael@0 | 7 | #define mozilla_MouseEvents_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> |
michael@0 | 10 | |
michael@0 | 11 | #include "mozilla/BasicEvents.h" |
michael@0 | 12 | #include "mozilla/MathAlgorithms.h" |
michael@0 | 13 | #include "mozilla/dom/DataTransfer.h" |
michael@0 | 14 | #include "nsCOMPtr.h" |
michael@0 | 15 | #include "nsIDOMMouseEvent.h" |
michael@0 | 16 | #include "nsIDOMWheelEvent.h" |
michael@0 | 17 | |
michael@0 | 18 | /****************************************************************************** |
michael@0 | 19 | * nsDragDropEventStatus |
michael@0 | 20 | ******************************************************************************/ |
michael@0 | 21 | |
michael@0 | 22 | enum nsDragDropEventStatus |
michael@0 | 23 | { |
michael@0 | 24 | // The event is a enter |
michael@0 | 25 | nsDragDropEventStatus_eDragEntered, |
michael@0 | 26 | // The event is exit |
michael@0 | 27 | nsDragDropEventStatus_eDragExited, |
michael@0 | 28 | // The event is drop |
michael@0 | 29 | nsDragDropEventStatus_eDrop |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | namespace mozilla { |
michael@0 | 33 | |
michael@0 | 34 | namespace dom { |
michael@0 | 35 | class PBrowserParent; |
michael@0 | 36 | class PBrowserChild; |
michael@0 | 37 | } // namespace dom |
michael@0 | 38 | |
michael@0 | 39 | /****************************************************************************** |
michael@0 | 40 | * mozilla::WidgetPointerHelper |
michael@0 | 41 | ******************************************************************************/ |
michael@0 | 42 | |
michael@0 | 43 | class WidgetPointerHelper |
michael@0 | 44 | { |
michael@0 | 45 | public: |
michael@0 | 46 | bool convertToPointer; |
michael@0 | 47 | uint32_t pointerId; |
michael@0 | 48 | uint32_t tiltX; |
michael@0 | 49 | uint32_t tiltY; |
michael@0 | 50 | |
michael@0 | 51 | WidgetPointerHelper() : convertToPointer(true), pointerId(0), tiltX(0), tiltY(0) {} |
michael@0 | 52 | |
michael@0 | 53 | void AssignPointerHelperData(const WidgetPointerHelper& aEvent) |
michael@0 | 54 | { |
michael@0 | 55 | convertToPointer = aEvent.convertToPointer; |
michael@0 | 56 | pointerId = aEvent.pointerId; |
michael@0 | 57 | tiltX = aEvent.tiltX; |
michael@0 | 58 | tiltY = aEvent.tiltY; |
michael@0 | 59 | } |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | /****************************************************************************** |
michael@0 | 63 | * mozilla::WidgetMouseEventBase |
michael@0 | 64 | ******************************************************************************/ |
michael@0 | 65 | |
michael@0 | 66 | class WidgetMouseEventBase : public WidgetInputEvent |
michael@0 | 67 | { |
michael@0 | 68 | private: |
michael@0 | 69 | friend class dom::PBrowserParent; |
michael@0 | 70 | friend class dom::PBrowserChild; |
michael@0 | 71 | |
michael@0 | 72 | protected: |
michael@0 | 73 | WidgetMouseEventBase() |
michael@0 | 74 | { |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | WidgetMouseEventBase(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
michael@0 | 78 | nsEventStructType aStructType) : |
michael@0 | 79 | WidgetInputEvent(aIsTrusted, aMessage, aWidget, aStructType), |
michael@0 | 80 | button(0), buttons(0), pressure(0), |
michael@0 | 81 | inputSource(nsIDOMMouseEvent::MOZ_SOURCE_MOUSE) |
michael@0 | 82 | { |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | public: |
michael@0 | 86 | virtual WidgetMouseEventBase* AsMouseEventBase() MOZ_OVERRIDE { return this; } |
michael@0 | 87 | |
michael@0 | 88 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 89 | { |
michael@0 | 90 | MOZ_CRASH("WidgetMouseEventBase must not be most-subclass"); |
michael@0 | 91 | return nullptr; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /// The possible related target |
michael@0 | 95 | nsCOMPtr<nsISupports> relatedTarget; |
michael@0 | 96 | |
michael@0 | 97 | enum buttonType |
michael@0 | 98 | { |
michael@0 | 99 | eLeftButton = 0, |
michael@0 | 100 | eMiddleButton = 1, |
michael@0 | 101 | eRightButton = 2 |
michael@0 | 102 | }; |
michael@0 | 103 | // Pressed button ID of mousedown or mouseup event. |
michael@0 | 104 | // This is set only when pressing a button causes the event. |
michael@0 | 105 | int16_t button; |
michael@0 | 106 | |
michael@0 | 107 | enum buttonsFlag { |
michael@0 | 108 | eLeftButtonFlag = 0x01, |
michael@0 | 109 | eRightButtonFlag = 0x02, |
michael@0 | 110 | eMiddleButtonFlag = 0x04, |
michael@0 | 111 | // typicall, "back" button being left side of 5-button |
michael@0 | 112 | // mice, see "buttons" attribute document of DOM3 Events. |
michael@0 | 113 | e4thButtonFlag = 0x08, |
michael@0 | 114 | // typicall, "forward" button being right side of 5-button |
michael@0 | 115 | // mice, see "buttons" attribute document of DOM3 Events. |
michael@0 | 116 | e5thButtonFlag = 0x10 |
michael@0 | 117 | }; |
michael@0 | 118 | |
michael@0 | 119 | // Flags of all pressed buttons at the event fired. |
michael@0 | 120 | // This is set at any mouse event, don't be confused with |button|. |
michael@0 | 121 | int16_t buttons; |
michael@0 | 122 | |
michael@0 | 123 | // Finger or touch pressure of event. It ranges between 0.0 and 1.0. |
michael@0 | 124 | float pressure; |
michael@0 | 125 | |
michael@0 | 126 | // Possible values at nsIDOMMouseEvent |
michael@0 | 127 | uint16_t inputSource; |
michael@0 | 128 | |
michael@0 | 129 | void AssignMouseEventBaseData(const WidgetMouseEventBase& aEvent, |
michael@0 | 130 | bool aCopyTargets) |
michael@0 | 131 | { |
michael@0 | 132 | AssignInputEventData(aEvent, aCopyTargets); |
michael@0 | 133 | |
michael@0 | 134 | relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr; |
michael@0 | 135 | button = aEvent.button; |
michael@0 | 136 | buttons = aEvent.buttons; |
michael@0 | 137 | pressure = aEvent.pressure; |
michael@0 | 138 | inputSource = aEvent.inputSource; |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | /** |
michael@0 | 142 | * Returns true if left click event. |
michael@0 | 143 | */ |
michael@0 | 144 | bool IsLeftClickEvent() const |
michael@0 | 145 | { |
michael@0 | 146 | return message == NS_MOUSE_CLICK && button == eLeftButton; |
michael@0 | 147 | } |
michael@0 | 148 | }; |
michael@0 | 149 | |
michael@0 | 150 | /****************************************************************************** |
michael@0 | 151 | * mozilla::WidgetMouseEvent |
michael@0 | 152 | ******************************************************************************/ |
michael@0 | 153 | |
michael@0 | 154 | class WidgetMouseEvent : public WidgetMouseEventBase, public WidgetPointerHelper |
michael@0 | 155 | { |
michael@0 | 156 | private: |
michael@0 | 157 | friend class mozilla::dom::PBrowserParent; |
michael@0 | 158 | friend class mozilla::dom::PBrowserChild; |
michael@0 | 159 | |
michael@0 | 160 | public: |
michael@0 | 161 | enum reasonType |
michael@0 | 162 | { |
michael@0 | 163 | eReal, |
michael@0 | 164 | eSynthesized |
michael@0 | 165 | }; |
michael@0 | 166 | |
michael@0 | 167 | enum contextType |
michael@0 | 168 | { |
michael@0 | 169 | eNormal, |
michael@0 | 170 | eContextMenuKey |
michael@0 | 171 | }; |
michael@0 | 172 | |
michael@0 | 173 | enum exitType |
michael@0 | 174 | { |
michael@0 | 175 | eChild, |
michael@0 | 176 | eTopLevel |
michael@0 | 177 | }; |
michael@0 | 178 | |
michael@0 | 179 | protected: |
michael@0 | 180 | WidgetMouseEvent() |
michael@0 | 181 | { |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
michael@0 | 185 | nsEventStructType aStructType, reasonType aReason) : |
michael@0 | 186 | WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, aStructType), |
michael@0 | 187 | acceptActivation(false), ignoreRootScrollFrame(false), |
michael@0 | 188 | reason(aReason), context(eNormal), exit(eChild), clickCount(0) |
michael@0 | 189 | { |
michael@0 | 190 | switch (aMessage) { |
michael@0 | 191 | case NS_MOUSEENTER: |
michael@0 | 192 | case NS_MOUSELEAVE: |
michael@0 | 193 | mFlags.mBubbles = false; |
michael@0 | 194 | mFlags.mCancelable = false; |
michael@0 | 195 | break; |
michael@0 | 196 | default: |
michael@0 | 197 | break; |
michael@0 | 198 | } |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | public: |
michael@0 | 202 | virtual WidgetMouseEvent* AsMouseEvent() MOZ_OVERRIDE { return this; } |
michael@0 | 203 | |
michael@0 | 204 | WidgetMouseEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget, |
michael@0 | 205 | reasonType aReason, contextType aContext = eNormal) : |
michael@0 | 206 | WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_EVENT), |
michael@0 | 207 | acceptActivation(false), ignoreRootScrollFrame(false), |
michael@0 | 208 | reason(aReason), context(aContext), exit(eChild), clickCount(0) |
michael@0 | 209 | { |
michael@0 | 210 | switch (aMessage) { |
michael@0 | 211 | case NS_MOUSEENTER: |
michael@0 | 212 | case NS_MOUSELEAVE: |
michael@0 | 213 | mFlags.mBubbles = false; |
michael@0 | 214 | mFlags.mCancelable = false; |
michael@0 | 215 | break; |
michael@0 | 216 | case NS_CONTEXTMENU: |
michael@0 | 217 | button = (context == eNormal) ? eRightButton : eLeftButton; |
michael@0 | 218 | break; |
michael@0 | 219 | default: |
michael@0 | 220 | break; |
michael@0 | 221 | } |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | #ifdef DEBUG |
michael@0 | 225 | virtual ~WidgetMouseEvent() |
michael@0 | 226 | { |
michael@0 | 227 | NS_WARN_IF_FALSE(message != NS_CONTEXTMENU || |
michael@0 | 228 | button == |
michael@0 | 229 | ((context == eNormal) ? eRightButton : eLeftButton), |
michael@0 | 230 | "Wrong button set to NS_CONTEXTMENU event?"); |
michael@0 | 231 | } |
michael@0 | 232 | #endif |
michael@0 | 233 | |
michael@0 | 234 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 235 | { |
michael@0 | 236 | MOZ_ASSERT(eventStructType == NS_MOUSE_EVENT, |
michael@0 | 237 | "Duplicate() must be overridden by sub class"); |
michael@0 | 238 | // Not copying widget, it is a weak reference. |
michael@0 | 239 | WidgetMouseEvent* result = |
michael@0 | 240 | new WidgetMouseEvent(false, message, nullptr, reason, context); |
michael@0 | 241 | result->AssignMouseEventData(*this, true); |
michael@0 | 242 | result->mFlags = mFlags; |
michael@0 | 243 | return result; |
michael@0 | 244 | } |
michael@0 | 245 | |
michael@0 | 246 | // Special return code for MOUSE_ACTIVATE to signal. |
michael@0 | 247 | // If the target accepts activation (1), or denies it (0). |
michael@0 | 248 | bool acceptActivation; |
michael@0 | 249 | // Whether the event should ignore scroll frame bounds during dispatch. |
michael@0 | 250 | bool ignoreRootScrollFrame; |
michael@0 | 251 | |
michael@0 | 252 | reasonType reason : 4; |
michael@0 | 253 | contextType context : 4; |
michael@0 | 254 | exitType exit; |
michael@0 | 255 | |
michael@0 | 256 | /// The number of mouse clicks. |
michael@0 | 257 | uint32_t clickCount; |
michael@0 | 258 | |
michael@0 | 259 | void AssignMouseEventData(const WidgetMouseEvent& aEvent, bool aCopyTargets) |
michael@0 | 260 | { |
michael@0 | 261 | AssignMouseEventBaseData(aEvent, aCopyTargets); |
michael@0 | 262 | AssignPointerHelperData(aEvent); |
michael@0 | 263 | |
michael@0 | 264 | acceptActivation = aEvent.acceptActivation; |
michael@0 | 265 | ignoreRootScrollFrame = aEvent.ignoreRootScrollFrame; |
michael@0 | 266 | clickCount = aEvent.clickCount; |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | /** |
michael@0 | 270 | * Returns true if the event is a context menu event caused by key. |
michael@0 | 271 | */ |
michael@0 | 272 | bool IsContextMenuKeyEvent() const |
michael@0 | 273 | { |
michael@0 | 274 | return message == NS_CONTEXTMENU && context == eContextMenuKey; |
michael@0 | 275 | } |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Returns true if the event is a real mouse event. Otherwise, i.e., it's |
michael@0 | 279 | * a synthesized event by scroll or something, returns false. |
michael@0 | 280 | */ |
michael@0 | 281 | bool IsReal() const |
michael@0 | 282 | { |
michael@0 | 283 | return reason == eReal; |
michael@0 | 284 | } |
michael@0 | 285 | }; |
michael@0 | 286 | |
michael@0 | 287 | /****************************************************************************** |
michael@0 | 288 | * mozilla::WidgetDragEvent |
michael@0 | 289 | ******************************************************************************/ |
michael@0 | 290 | |
michael@0 | 291 | class WidgetDragEvent : public WidgetMouseEvent |
michael@0 | 292 | { |
michael@0 | 293 | public: |
michael@0 | 294 | virtual WidgetDragEvent* AsDragEvent() MOZ_OVERRIDE { return this; } |
michael@0 | 295 | |
michael@0 | 296 | WidgetDragEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : |
michael@0 | 297 | WidgetMouseEvent(aIsTrusted, aMessage, aWidget, NS_DRAG_EVENT, eReal), |
michael@0 | 298 | userCancelled(false), mDefaultPreventedOnContent(false) |
michael@0 | 299 | { |
michael@0 | 300 | mFlags.mCancelable = |
michael@0 | 301 | (aMessage != NS_DRAGDROP_EXIT_SYNTH && |
michael@0 | 302 | aMessage != NS_DRAGDROP_LEAVE_SYNTH && |
michael@0 | 303 | aMessage != NS_DRAGDROP_END); |
michael@0 | 304 | } |
michael@0 | 305 | |
michael@0 | 306 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 307 | { |
michael@0 | 308 | MOZ_ASSERT(eventStructType == NS_DRAG_EVENT, |
michael@0 | 309 | "Duplicate() must be overridden by sub class"); |
michael@0 | 310 | // Not copying widget, it is a weak reference. |
michael@0 | 311 | WidgetDragEvent* result = new WidgetDragEvent(false, message, nullptr); |
michael@0 | 312 | result->AssignDragEventData(*this, true); |
michael@0 | 313 | result->mFlags = mFlags; |
michael@0 | 314 | return result; |
michael@0 | 315 | } |
michael@0 | 316 | |
michael@0 | 317 | // The dragging data. |
michael@0 | 318 | nsCOMPtr<dom::DataTransfer> dataTransfer; |
michael@0 | 319 | |
michael@0 | 320 | // If this is true, user has cancelled the drag operation. |
michael@0 | 321 | bool userCancelled; |
michael@0 | 322 | // If this is true, the drag event's preventDefault() is called on content. |
michael@0 | 323 | bool mDefaultPreventedOnContent; |
michael@0 | 324 | |
michael@0 | 325 | // XXX Not tested by test_assign_event_data.html |
michael@0 | 326 | void AssignDragEventData(const WidgetDragEvent& aEvent, bool aCopyTargets) |
michael@0 | 327 | { |
michael@0 | 328 | AssignMouseEventData(aEvent, aCopyTargets); |
michael@0 | 329 | |
michael@0 | 330 | dataTransfer = aEvent.dataTransfer; |
michael@0 | 331 | // XXX userCancelled isn't copied, is this instentionally? |
michael@0 | 332 | userCancelled = false; |
michael@0 | 333 | mDefaultPreventedOnContent = aEvent.mDefaultPreventedOnContent; |
michael@0 | 334 | } |
michael@0 | 335 | }; |
michael@0 | 336 | |
michael@0 | 337 | /****************************************************************************** |
michael@0 | 338 | * mozilla::WidgetMouseScrollEvent |
michael@0 | 339 | * |
michael@0 | 340 | * This is used for legacy DOM mouse scroll events, i.e., |
michael@0 | 341 | * DOMMouseScroll and MozMousePixelScroll event. These events are NOT hanbled |
michael@0 | 342 | * by ESM even if widget dispatches them. Use new WidgetWheelEvent instead. |
michael@0 | 343 | ******************************************************************************/ |
michael@0 | 344 | |
michael@0 | 345 | class WidgetMouseScrollEvent : public WidgetMouseEventBase |
michael@0 | 346 | { |
michael@0 | 347 | private: |
michael@0 | 348 | WidgetMouseScrollEvent() |
michael@0 | 349 | { |
michael@0 | 350 | } |
michael@0 | 351 | |
michael@0 | 352 | public: |
michael@0 | 353 | virtual WidgetMouseScrollEvent* AsMouseScrollEvent() MOZ_OVERRIDE |
michael@0 | 354 | { |
michael@0 | 355 | return this; |
michael@0 | 356 | } |
michael@0 | 357 | |
michael@0 | 358 | WidgetMouseScrollEvent(bool aIsTrusted, uint32_t aMessage, |
michael@0 | 359 | nsIWidget* aWidget) : |
michael@0 | 360 | WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_MOUSE_SCROLL_EVENT), |
michael@0 | 361 | delta(0), isHorizontal(false) |
michael@0 | 362 | { |
michael@0 | 363 | } |
michael@0 | 364 | |
michael@0 | 365 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 366 | { |
michael@0 | 367 | MOZ_ASSERT(eventStructType == NS_MOUSE_SCROLL_EVENT, |
michael@0 | 368 | "Duplicate() must be overridden by sub class"); |
michael@0 | 369 | // Not copying widget, it is a weak reference. |
michael@0 | 370 | WidgetMouseScrollEvent* result = |
michael@0 | 371 | new WidgetMouseScrollEvent(false, message, nullptr); |
michael@0 | 372 | result->AssignMouseScrollEventData(*this, true); |
michael@0 | 373 | result->mFlags = mFlags; |
michael@0 | 374 | return result; |
michael@0 | 375 | } |
michael@0 | 376 | |
michael@0 | 377 | // The delta value of mouse scroll event. |
michael@0 | 378 | // If the event message is NS_MOUSE_SCROLL, the value indicates scroll amount |
michael@0 | 379 | // in lines. However, if the value is nsIDOMUIEvent::SCROLL_PAGE_UP or |
michael@0 | 380 | // nsIDOMUIEvent::SCROLL_PAGE_DOWN, the value inducates one page scroll. |
michael@0 | 381 | // If the event message is NS_MOUSE_PIXEL_SCROLL, the value indicates scroll |
michael@0 | 382 | // amount in pixels. |
michael@0 | 383 | int32_t delta; |
michael@0 | 384 | |
michael@0 | 385 | // If this is true, it may cause to scroll horizontally. |
michael@0 | 386 | // Otherwise, vertically. |
michael@0 | 387 | bool isHorizontal; |
michael@0 | 388 | |
michael@0 | 389 | void AssignMouseScrollEventData(const WidgetMouseScrollEvent& aEvent, |
michael@0 | 390 | bool aCopyTargets) |
michael@0 | 391 | { |
michael@0 | 392 | AssignMouseEventBaseData(aEvent, aCopyTargets); |
michael@0 | 393 | |
michael@0 | 394 | delta = aEvent.delta; |
michael@0 | 395 | isHorizontal = aEvent.isHorizontal; |
michael@0 | 396 | } |
michael@0 | 397 | }; |
michael@0 | 398 | |
michael@0 | 399 | /****************************************************************************** |
michael@0 | 400 | * mozilla::WidgetWheelEvent |
michael@0 | 401 | ******************************************************************************/ |
michael@0 | 402 | |
michael@0 | 403 | class WidgetWheelEvent : public WidgetMouseEventBase |
michael@0 | 404 | { |
michael@0 | 405 | private: |
michael@0 | 406 | friend class mozilla::dom::PBrowserParent; |
michael@0 | 407 | friend class mozilla::dom::PBrowserChild; |
michael@0 | 408 | |
michael@0 | 409 | WidgetWheelEvent() |
michael@0 | 410 | { |
michael@0 | 411 | } |
michael@0 | 412 | |
michael@0 | 413 | public: |
michael@0 | 414 | virtual WidgetWheelEvent* AsWheelEvent() MOZ_OVERRIDE { return this; } |
michael@0 | 415 | |
michael@0 | 416 | WidgetWheelEvent(bool aIsTrusted, uint32_t aMessage, nsIWidget* aWidget) : |
michael@0 | 417 | WidgetMouseEventBase(aIsTrusted, aMessage, aWidget, NS_WHEEL_EVENT), |
michael@0 | 418 | deltaX(0.0), deltaY(0.0), deltaZ(0.0), |
michael@0 | 419 | deltaMode(nsIDOMWheelEvent::DOM_DELTA_PIXEL), |
michael@0 | 420 | customizedByUserPrefs(false), isMomentum(false), isPixelOnlyDevice(false), |
michael@0 | 421 | lineOrPageDeltaX(0), lineOrPageDeltaY(0), scrollType(SCROLL_DEFAULT), |
michael@0 | 422 | overflowDeltaX(0.0), overflowDeltaY(0.0), |
michael@0 | 423 | mViewPortIsOverscrolled(false) |
michael@0 | 424 | { |
michael@0 | 425 | } |
michael@0 | 426 | |
michael@0 | 427 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 428 | { |
michael@0 | 429 | MOZ_ASSERT(eventStructType == NS_WHEEL_EVENT, |
michael@0 | 430 | "Duplicate() must be overridden by sub class"); |
michael@0 | 431 | // Not copying widget, it is a weak reference. |
michael@0 | 432 | WidgetWheelEvent* result = new WidgetWheelEvent(false, message, nullptr); |
michael@0 | 433 | result->AssignWheelEventData(*this, true); |
michael@0 | 434 | result->mFlags = mFlags; |
michael@0 | 435 | return result; |
michael@0 | 436 | } |
michael@0 | 437 | |
michael@0 | 438 | // NOTE: deltaX, deltaY and deltaZ may be customized by |
michael@0 | 439 | // mousewheel.*.delta_multiplier_* prefs which are applied by |
michael@0 | 440 | // EventStateManager. So, after widget dispatches this event, |
michael@0 | 441 | // these delta values may have different values than before. |
michael@0 | 442 | double deltaX; |
michael@0 | 443 | double deltaY; |
michael@0 | 444 | double deltaZ; |
michael@0 | 445 | |
michael@0 | 446 | // Should be one of nsIDOMWheelEvent::DOM_DELTA_* |
michael@0 | 447 | uint32_t deltaMode; |
michael@0 | 448 | |
michael@0 | 449 | // Following members are for internal use only, not for DOM event. |
michael@0 | 450 | |
michael@0 | 451 | // If the delta values are computed from prefs, this value is true. |
michael@0 | 452 | // Otherwise, i.e., they are computed from native events, false. |
michael@0 | 453 | bool customizedByUserPrefs; |
michael@0 | 454 | |
michael@0 | 455 | // true if the event is caused by momentum. |
michael@0 | 456 | bool isMomentum; |
michael@0 | 457 | |
michael@0 | 458 | // If device event handlers don't know when they should set lineOrPageDeltaX |
michael@0 | 459 | // and lineOrPageDeltaY, this is true. Otherwise, false. |
michael@0 | 460 | // If isPixelOnlyDevice is true, ESM will generate NS_MOUSE_SCROLL events |
michael@0 | 461 | // when accumulated pixel delta values reach a line height. |
michael@0 | 462 | bool isPixelOnlyDevice; |
michael@0 | 463 | |
michael@0 | 464 | // If widget sets lineOrPageDelta, EventStateManager will dispatch |
michael@0 | 465 | // NS_MOUSE_SCROLL event for compatibility. Note that the delta value means |
michael@0 | 466 | // pages if the deltaMode is DOM_DELTA_PAGE, otherwise, lines. |
michael@0 | 467 | int32_t lineOrPageDeltaX; |
michael@0 | 468 | int32_t lineOrPageDeltaY; |
michael@0 | 469 | |
michael@0 | 470 | // When the default action for an wheel event is moving history or zooming, |
michael@0 | 471 | // need to chose a delta value for doing it. |
michael@0 | 472 | int32_t GetPreferredIntDelta() |
michael@0 | 473 | { |
michael@0 | 474 | if (!lineOrPageDeltaX && !lineOrPageDeltaY) { |
michael@0 | 475 | return 0; |
michael@0 | 476 | } |
michael@0 | 477 | if (lineOrPageDeltaY && !lineOrPageDeltaX) { |
michael@0 | 478 | return lineOrPageDeltaY; |
michael@0 | 479 | } |
michael@0 | 480 | if (lineOrPageDeltaX && !lineOrPageDeltaY) { |
michael@0 | 481 | return lineOrPageDeltaX; |
michael@0 | 482 | } |
michael@0 | 483 | if ((lineOrPageDeltaX < 0 && lineOrPageDeltaY > 0) || |
michael@0 | 484 | (lineOrPageDeltaX > 0 && lineOrPageDeltaY < 0)) { |
michael@0 | 485 | return 0; // We cannot guess the answer in this case. |
michael@0 | 486 | } |
michael@0 | 487 | return (Abs(lineOrPageDeltaX) > Abs(lineOrPageDeltaY)) ? |
michael@0 | 488 | lineOrPageDeltaX : lineOrPageDeltaY; |
michael@0 | 489 | } |
michael@0 | 490 | |
michael@0 | 491 | // Scroll type |
michael@0 | 492 | // The default value is SCROLL_DEFAULT, which means EventStateManager will |
michael@0 | 493 | // select preferred scroll type automatically. |
michael@0 | 494 | enum ScrollType |
michael@0 | 495 | { |
michael@0 | 496 | SCROLL_DEFAULT, |
michael@0 | 497 | SCROLL_SYNCHRONOUSLY, |
michael@0 | 498 | SCROLL_ASYNCHRONOUSELY, |
michael@0 | 499 | SCROLL_SMOOTHLY |
michael@0 | 500 | }; |
michael@0 | 501 | ScrollType scrollType; |
michael@0 | 502 | |
michael@0 | 503 | // overflowed delta values for scroll, these values are set by |
michael@0 | 504 | // nsEventStateManger. If the default action of the wheel event isn't scroll, |
michael@0 | 505 | // these values always zero. Otherwise, remaning delta values which are |
michael@0 | 506 | // not used by scroll are set. |
michael@0 | 507 | // NOTE: deltaX, deltaY and deltaZ may be modified by EventStateManager. |
michael@0 | 508 | // However, overflowDeltaX and overflowDeltaY indicate unused original |
michael@0 | 509 | // delta values which are not applied the delta_multiplier prefs. |
michael@0 | 510 | // So, if widget wanted to know the actual direction to be scrolled, |
michael@0 | 511 | // it would need to check the deltaX and deltaY. |
michael@0 | 512 | double overflowDeltaX; |
michael@0 | 513 | double overflowDeltaY; |
michael@0 | 514 | |
michael@0 | 515 | // Whether or not the parent of the currently overscrolled frame is the |
michael@0 | 516 | // ViewPort. This is false in situations when an element on the page is being |
michael@0 | 517 | // overscrolled (such as a text field), but true when the 'page' is being |
michael@0 | 518 | // overscrolled. |
michael@0 | 519 | bool mViewPortIsOverscrolled; |
michael@0 | 520 | |
michael@0 | 521 | void AssignWheelEventData(const WidgetWheelEvent& aEvent, bool aCopyTargets) |
michael@0 | 522 | { |
michael@0 | 523 | AssignMouseEventBaseData(aEvent, aCopyTargets); |
michael@0 | 524 | |
michael@0 | 525 | deltaX = aEvent.deltaX; |
michael@0 | 526 | deltaY = aEvent.deltaY; |
michael@0 | 527 | deltaZ = aEvent.deltaZ; |
michael@0 | 528 | deltaMode = aEvent.deltaMode; |
michael@0 | 529 | customizedByUserPrefs = aEvent.customizedByUserPrefs; |
michael@0 | 530 | isMomentum = aEvent.isMomentum; |
michael@0 | 531 | isPixelOnlyDevice = aEvent.isPixelOnlyDevice; |
michael@0 | 532 | lineOrPageDeltaX = aEvent.lineOrPageDeltaX; |
michael@0 | 533 | lineOrPageDeltaY = aEvent.lineOrPageDeltaY; |
michael@0 | 534 | scrollType = aEvent.scrollType; |
michael@0 | 535 | overflowDeltaX = aEvent.overflowDeltaX; |
michael@0 | 536 | overflowDeltaY = aEvent.overflowDeltaY; |
michael@0 | 537 | mViewPortIsOverscrolled = aEvent.mViewPortIsOverscrolled; |
michael@0 | 538 | } |
michael@0 | 539 | }; |
michael@0 | 540 | |
michael@0 | 541 | /****************************************************************************** |
michael@0 | 542 | * mozilla::WidgetPointerEvent |
michael@0 | 543 | ******************************************************************************/ |
michael@0 | 544 | |
michael@0 | 545 | class WidgetPointerEvent : public WidgetMouseEvent |
michael@0 | 546 | { |
michael@0 | 547 | friend class mozilla::dom::PBrowserParent; |
michael@0 | 548 | friend class mozilla::dom::PBrowserChild; |
michael@0 | 549 | |
michael@0 | 550 | WidgetPointerEvent() |
michael@0 | 551 | { |
michael@0 | 552 | } |
michael@0 | 553 | |
michael@0 | 554 | public: |
michael@0 | 555 | virtual WidgetPointerEvent* AsPointerEvent() MOZ_OVERRIDE { return this; } |
michael@0 | 556 | |
michael@0 | 557 | WidgetPointerEvent(bool aIsTrusted, uint32_t aMsg, nsIWidget* w) |
michael@0 | 558 | : WidgetMouseEvent(aIsTrusted, aMsg, w, NS_POINTER_EVENT, eReal) |
michael@0 | 559 | , width(0) |
michael@0 | 560 | , height(0) |
michael@0 | 561 | , isPrimary(true) |
michael@0 | 562 | { |
michael@0 | 563 | UpdateFlags(); |
michael@0 | 564 | } |
michael@0 | 565 | |
michael@0 | 566 | WidgetPointerEvent(const WidgetMouseEvent& aEvent) |
michael@0 | 567 | : WidgetMouseEvent(aEvent) |
michael@0 | 568 | , width(0) |
michael@0 | 569 | , height(0) |
michael@0 | 570 | , isPrimary(true) |
michael@0 | 571 | { |
michael@0 | 572 | eventStructType = NS_POINTER_EVENT; |
michael@0 | 573 | UpdateFlags(); |
michael@0 | 574 | } |
michael@0 | 575 | |
michael@0 | 576 | void UpdateFlags() |
michael@0 | 577 | { |
michael@0 | 578 | switch (message) { |
michael@0 | 579 | case NS_POINTER_ENTER: |
michael@0 | 580 | case NS_POINTER_LEAVE: |
michael@0 | 581 | mFlags.mBubbles = false; |
michael@0 | 582 | mFlags.mCancelable = false; |
michael@0 | 583 | break; |
michael@0 | 584 | case NS_POINTER_CANCEL: |
michael@0 | 585 | case NS_POINTER_GOT_CAPTURE: |
michael@0 | 586 | case NS_POINTER_LOST_CAPTURE: |
michael@0 | 587 | mFlags.mCancelable = false; |
michael@0 | 588 | break; |
michael@0 | 589 | default: |
michael@0 | 590 | break; |
michael@0 | 591 | } |
michael@0 | 592 | } |
michael@0 | 593 | |
michael@0 | 594 | virtual WidgetEvent* Duplicate() const MOZ_OVERRIDE |
michael@0 | 595 | { |
michael@0 | 596 | MOZ_ASSERT(eventStructType == NS_POINTER_EVENT, |
michael@0 | 597 | "Duplicate() must be overridden by sub class"); |
michael@0 | 598 | // Not copying widget, it is a weak reference. |
michael@0 | 599 | WidgetPointerEvent* result = |
michael@0 | 600 | new WidgetPointerEvent(false, message, nullptr); |
michael@0 | 601 | result->AssignPointerEventData(*this, true); |
michael@0 | 602 | result->mFlags = mFlags; |
michael@0 | 603 | return result; |
michael@0 | 604 | } |
michael@0 | 605 | |
michael@0 | 606 | uint32_t width; |
michael@0 | 607 | uint32_t height; |
michael@0 | 608 | bool isPrimary; |
michael@0 | 609 | |
michael@0 | 610 | // XXX Not tested by test_assign_event_data.html |
michael@0 | 611 | void AssignPointerEventData(const WidgetPointerEvent& aEvent, |
michael@0 | 612 | bool aCopyTargets) |
michael@0 | 613 | { |
michael@0 | 614 | AssignMouseEventData(aEvent, aCopyTargets); |
michael@0 | 615 | |
michael@0 | 616 | width = aEvent.width; |
michael@0 | 617 | height = aEvent.height; |
michael@0 | 618 | isPrimary = aEvent.isPrimary; |
michael@0 | 619 | } |
michael@0 | 620 | }; |
michael@0 | 621 | |
michael@0 | 622 | } // namespace mozilla |
michael@0 | 623 | |
michael@0 | 624 | #endif // mozilla_MouseEvents_h__ |