tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MouseEvent.h (9335B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_MouseEvent_h_
      8 #define mozilla_dom_MouseEvent_h_
      9 
     10 #include "mozilla/EventForwards.h"
     11 #include "mozilla/dom/BindingDeclarations.h"
     12 #include "mozilla/dom/MouseEventBinding.h"
     13 #include "mozilla/dom/UIEvent.h"
     14 
     15 namespace mozilla::dom {
     16 
     17 class MouseEvent : public UIEvent {
     18 public:
     19  MouseEvent(EventTarget* aOwner, nsPresContext* aPresContext,
     20             WidgetMouseEventBase* aEvent);
     21 
     22  NS_INLINE_DECL_REFCOUNTING_INHERITED(MouseEvent, UIEvent)
     23 
     24  virtual JSObject* WrapObjectInternal(
     25      JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override {
     26    return MouseEvent_Binding::Wrap(aCx, this, aGivenProto);
     27  }
     28 
     29  virtual MouseEvent* AsMouseEvent() override { return this; }
     30 
     31  MOZ_CAN_RUN_SCRIPT_BOUNDARY void DuplicatePrivateData() override;
     32 
     33  // Web IDL binding methods
     34  virtual uint32_t Which(CallerType aCallerType) override {
     35    return Button() + 1;
     36  }
     37 
     38  already_AddRefed<nsIScreen> GetScreen();
     39 
     40  /**
     41   * Return screenX and screenY values for this event in CSS pixels.
     42   * If current setting allows to expose fractional coordinates for the event,
     43   * this returns the fractional values as-is.  Otherwise, this returns
     44   * integer values with rounding the computed values.  Note that if this
     45   * event is untrusted one and should not expose fractional values, the
     46   * initialized values are floored before computing the values as defined by
     47   * Pointer Events spec.
     48   */
     49  CSSDoublePoint ScreenPoint(CallerType) const;
     50  double ScreenX(CallerType aCallerType) const {
     51    return ScreenPoint(aCallerType).x;
     52  }
     53  double ScreenY(CallerType aCallerType) const {
     54    return ScreenPoint(aCallerType).y;
     55  }
     56  LayoutDeviceIntPoint ScreenPointLayoutDevicePix() const;
     57  DesktopIntPoint ScreenPointDesktopPix() const;
     58 
     59  /**
     60   * Return pageX and pageY values for this event in CSS pixels which are
     61   * client point + scroll position of the root scrollable frame.
     62   * If current setting allows to expose fractional coordinates for the event,
     63   * this returns the fractional values as-is.  Otherwise, this returns
     64   * integer values with rounding the computed values.  Note that if this
     65   * event is untrusted one and should not expose fractional values, the
     66   * initialized values are floored before computing the values as defined by
     67   * Pointer Events spec.
     68   */
     69  CSSDoublePoint PagePoint() const;
     70  double PageX() const { return PagePoint().x; }
     71  double PageY() const { return PagePoint().y; }
     72 
     73  /**
     74   * Return clientX and clientY values for this event in CSS pixels.
     75   * If current setting allows to expose fractional coordinates for the event,
     76   * this returns the fractional values as-is.  Otherwise, this returns
     77   * integer values with rounding the computed values.  Note that if this
     78   * event is untrusted one and should not expose fractional values, the
     79   * initialized values are floored before computing the values as defined by
     80   * Pointer Events spec.
     81   */
     82  CSSDoublePoint ClientPoint() const;
     83  double ClientX() const { return ClientPoint().x; }
     84  double ClientY() const { return ClientPoint().y; }
     85 
     86  /**
     87   * Return offsetX and offsetY values for this event in CSS pixels which are
     88   * offset in the target element.
     89   * If current setting allows to expose fractional coordinates for the event,
     90   * this returns the fractional values as-is.  Otherwise, this returns
     91   * integer values with rounding the computed values.  Note that if this
     92   * event is untrusted one and should not expose fractional values, the
     93   * initialized values are floored before computing the values as defined by
     94   * Pointer Events spec.
     95   *
     96   * Note that this may flush the pending layout.
     97   */
     98  MOZ_CAN_RUN_SCRIPT_BOUNDARY CSSDoublePoint OffsetPoint() const;
     99  double OffsetX() const { return OffsetPoint().x; }
    100  double OffsetY() const { return OffsetPoint().y; }
    101 
    102  bool CtrlKey();
    103  bool ShiftKey();
    104  bool AltKey();
    105  bool MetaKey();
    106  int16_t Button();
    107  uint16_t Buttons() const;
    108  already_AddRefed<EventTarget> GetRelatedTarget();
    109  void InitMouseEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
    110                      nsGlobalWindowInner* aView, int32_t aDetail,
    111                      int32_t aScreenX, int32_t aScreenY, int32_t aClientX,
    112                      int32_t aClientY, bool aCtrlKey, bool aAltKey,
    113                      bool aShiftKey, bool aMetaKey, uint16_t aButton,
    114                      EventTarget* aRelatedTarget) {
    115    InitMouseEventInternal(aType, aCanBubble, aCancelable, aView, aDetail,
    116                           aScreenX, aScreenY, aClientX, aClientY, aCtrlKey,
    117                           aAltKey, aShiftKey, aMetaKey, aButton,
    118                           aRelatedTarget);
    119  }
    120 
    121  void InitializeExtraMouseEventDictionaryMembers(const MouseEventInit& aParam);
    122 
    123  bool GetModifierState(const nsAString& aKeyArg) {
    124    return GetModifierStateInternal(aKeyArg);
    125  }
    126  static already_AddRefed<MouseEvent> Constructor(const GlobalObject& aGlobal,
    127                                                  const nsAString& aType,
    128                                                  const MouseEventInit& aParam);
    129  int32_t MovementX() { return GetMovementPoint().x; }
    130  int32_t MovementY() { return GetMovementPoint().y; }
    131  float MozPressure(CallerType) const;
    132  uint16_t InputSource(CallerType) const;
    133  void InitNSMouseEvent(const nsAString& aType, bool aCanBubble,
    134                        bool aCancelable, nsGlobalWindowInner* aView,
    135                        int32_t aDetail, int32_t aScreenX, int32_t aScreenY,
    136                        int32_t aClientX, int32_t aClientY, bool aCtrlKey,
    137                        bool aAltKey, bool aShiftKey, bool aMetaKey,
    138                        uint16_t aButton, EventTarget* aRelatedTarget,
    139                        float aPressure, uint16_t aInputSource);
    140  void PreventClickEvent();
    141  bool ClickEventPrevented();
    142  already_AddRefed<Event> GetTriggerEvent() const;
    143 
    144 protected:
    145  ~MouseEvent() = default;
    146 
    147  nsIntPoint GetMovementPoint() const;
    148 
    149  void InitMouseEventInternal(const nsAString& aType, bool aCanBubble,
    150                              bool aCancelable, nsGlobalWindowInner* aView,
    151                              int32_t aDetail, double aScreenX, double aScreenY,
    152                              double aClientX, double aClientY, bool aCtrlKey,
    153                              bool aAltKey, bool aShiftKey, bool aMetaKey,
    154                              uint16_t aButton, EventTarget* aRelatedTarget);
    155 
    156  void InitMouseEventInternal(const nsAString& aType, bool aCanBubble,
    157                              bool aCancelable, nsGlobalWindowInner* aView,
    158                              int32_t aDetail, double aScreenX, double aScreenY,
    159                              double aClientX, double aClientY, int16_t aButton,
    160                              EventTarget* aRelatedTarget,
    161                              const nsAString& aModifiersList);
    162 
    163  // mWidgetOrScreenRelativePoint stores the reference point of the event within
    164  // the double coordinates until ending of the propagation.  If this is a
    165  // trusted event, the values are copied from mEvent->mRefPoint whose type is
    166  // LayoutDeviceIntPoint which should be the relative point in the widget.
    167  // Therefore, the values are always integer.  However, once the propagation
    168  // ends, this starts storing the screen point because mEvent->mWidget is
    169  // cleared by Event::DuplicatePrivateData() and we won't be able to compute
    170  // screen point from its relative point without the widget.
    171  // On the other hand, if this is an untrusted event, this stores a screen
    172  // point since there is no widget.  And the values may be fractional values if
    173  // and only if the event should expose fractional coordinates.  Otherwise,
    174  // this is floored values for the backward compatibility.
    175  LayoutDeviceDoublePoint mWidgetOrScreenRelativePoint;
    176 
    177  // If this is a trusted event and after dispatching this, mDefaultClientPoint
    178  // stores the clientX and clientY values at duplicating the data.
    179  // If this is an untrusted event, mDefaultClientPoint stores the clientX and
    180  // clientY inputs.  If this event should expose fractional coordinates, the
    181  // values are set as-is.  Otherwise, this stores floored input values for
    182  // the backward compatibility.
    183  CSSDoublePoint mDefaultClientPoint;
    184 
    185  // If this is a trusted event and after dispatching this, mPagePoint stores
    186  // the pageX and pageY values at duplicating the data.
    187  // If this is an untrusted event, mPagePoint stores the pageX and pageY
    188  // inputs. If this event should expose fractional coordinates, the values are
    189  // set as-is.  Otherwise, this stores floored input values for the backward
    190  // compatibility.
    191  CSSDoublePoint mPagePoint;
    192 
    193  nsIntPoint mMovementPoint;
    194  bool mUseFractionalCoords = false;
    195 };
    196 
    197 }  // namespace mozilla::dom
    198 
    199 already_AddRefed<mozilla::dom::MouseEvent> NS_NewDOMMouseEvent(
    200    mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext,
    201    mozilla::WidgetMouseEvent* aEvent);
    202 
    203 #endif  // mozilla_dom_MouseEvent_h_