LCOV - code coverage report
Current view: top level - dom/events - PointerEvent.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 83 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :  * Portions Copyright 2013 Microsoft Open Technologies, Inc. */
       8             : 
       9             : #include "mozilla/dom/PointerEvent.h"
      10             : #include "mozilla/MouseEvents.h"
      11             : #include "prtime.h"
      12             : 
      13             : namespace mozilla {
      14             : namespace dom {
      15             : 
      16           0 : PointerEvent::PointerEvent(EventTarget* aOwner,
      17             :                            nsPresContext* aPresContext,
      18           0 :                            WidgetPointerEvent* aEvent)
      19             :   : MouseEvent(aOwner, aPresContext,
      20             :                aEvent ? aEvent :
      21           0 :                         new WidgetPointerEvent(false, eVoidEvent, nullptr))
      22             : {
      23           0 :   NS_ASSERTION(mEvent->mClass == ePointerEventClass,
      24             :                "event type mismatch ePointerEventClass");
      25             : 
      26           0 :   WidgetMouseEvent* mouseEvent = mEvent->AsMouseEvent();
      27           0 :   if (aEvent) {
      28           0 :     mEventIsInternal = false;
      29             :   } else {
      30           0 :     mEventIsInternal = true;
      31           0 :     mEvent->mTime = PR_Now();
      32           0 :     mEvent->mRefPoint = LayoutDeviceIntPoint(0, 0);
      33           0 :     mouseEvent->inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
      34             :   }
      35             :   // 5.2 Pointer Event types, for all pointer events, |detail| attribute SHOULD
      36             :   // be 0.
      37           0 :   mDetail = 0;
      38           0 : }
      39             : 
      40             : static uint16_t
      41           0 : ConvertStringToPointerType(const nsAString& aPointerTypeArg)
      42             : {
      43           0 :   if (aPointerTypeArg.EqualsLiteral("mouse")) {
      44           0 :     return nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
      45             :   }
      46           0 :   if (aPointerTypeArg.EqualsLiteral("pen")) {
      47           0 :     return nsIDOMMouseEvent::MOZ_SOURCE_PEN;
      48             :   }
      49           0 :   if (aPointerTypeArg.EqualsLiteral("touch")) {
      50           0 :     return nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
      51             :   }
      52             : 
      53           0 :   return nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
      54             : }
      55             : 
      56             : void
      57           0 : ConvertPointerTypeToString(uint16_t aPointerTypeSrc, nsAString& aPointerTypeDest)
      58             : {
      59           0 :   switch (aPointerTypeSrc) {
      60             :     case nsIDOMMouseEvent::MOZ_SOURCE_MOUSE:
      61           0 :       aPointerTypeDest.AssignLiteral("mouse");
      62           0 :       break;
      63             :     case nsIDOMMouseEvent::MOZ_SOURCE_PEN:
      64           0 :       aPointerTypeDest.AssignLiteral("pen");
      65           0 :       break;
      66             :     case nsIDOMMouseEvent::MOZ_SOURCE_TOUCH:
      67           0 :       aPointerTypeDest.AssignLiteral("touch");
      68           0 :       break;
      69             :     default:
      70           0 :       aPointerTypeDest.Truncate();
      71           0 :       break;
      72             :   }
      73           0 : }
      74             : 
      75             : // static
      76             : already_AddRefed<PointerEvent>
      77           0 : PointerEvent::Constructor(EventTarget* aOwner,
      78             :                           const nsAString& aType,
      79             :                           const PointerEventInit& aParam)
      80             : {
      81           0 :   RefPtr<PointerEvent> e = new PointerEvent(aOwner, nullptr, nullptr);
      82           0 :   bool trusted = e->Init(aOwner);
      83             : 
      84           0 :   e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
      85           0 :                     aParam.mView, aParam.mDetail, aParam.mScreenX,
      86           0 :                     aParam.mScreenY, aParam.mClientX, aParam.mClientY,
      87           0 :                     false, false, false, false, aParam.mButton,
      88           0 :                     aParam.mRelatedTarget);
      89           0 :   e->InitializeExtraMouseEventDictionaryMembers(aParam);
      90             : 
      91           0 :   WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
      92           0 :   widgetEvent->pointerId = aParam.mPointerId;
      93           0 :   widgetEvent->mWidth = aParam.mWidth;
      94           0 :   widgetEvent->mHeight = aParam.mHeight;
      95           0 :   widgetEvent->pressure = aParam.mPressure;
      96           0 :   widgetEvent->tangentialPressure = aParam.mTangentialPressure;
      97           0 :   widgetEvent->tiltX = aParam.mTiltX;
      98           0 :   widgetEvent->tiltY = aParam.mTiltY;
      99           0 :   widgetEvent->twist = aParam.mTwist;
     100           0 :   widgetEvent->inputSource = ConvertStringToPointerType(aParam.mPointerType);
     101           0 :   widgetEvent->mIsPrimary = aParam.mIsPrimary;
     102           0 :   widgetEvent->buttons = aParam.mButtons;
     103             : 
     104           0 :   e->SetTrusted(trusted);
     105           0 :   e->SetComposed(aParam.mComposed);
     106           0 :   return e.forget();
     107             : }
     108             : 
     109             : // static
     110             : already_AddRefed<PointerEvent>
     111           0 : PointerEvent::Constructor(const GlobalObject& aGlobal,
     112             :                           const nsAString& aType,
     113             :                           const PointerEventInit& aParam,
     114             :                           ErrorResult& aRv)
     115             : {
     116           0 :   nsCOMPtr<EventTarget> owner = do_QueryInterface(aGlobal.GetAsSupports());
     117           0 :   return Constructor(owner, aType, aParam);
     118             : }
     119             : 
     120             : void
     121           0 : PointerEvent::GetPointerType(nsAString& aPointerType)
     122             : {
     123           0 :   ConvertPointerTypeToString(mEvent->AsPointerEvent()->inputSource, aPointerType);
     124           0 : }
     125             : 
     126             : int32_t
     127           0 : PointerEvent::PointerId()
     128             : {
     129           0 :   return mEvent->AsPointerEvent()->pointerId;
     130             : }
     131             : 
     132             : int32_t
     133           0 : PointerEvent::Width()
     134             : {
     135           0 :   return mEvent->AsPointerEvent()->mWidth;
     136             : }
     137             : 
     138             : int32_t
     139           0 : PointerEvent::Height()
     140             : {
     141           0 :   return mEvent->AsPointerEvent()->mHeight;
     142             : }
     143             : 
     144             : float
     145           0 : PointerEvent::Pressure()
     146             : {
     147           0 :   return mEvent->AsPointerEvent()->pressure;
     148             : }
     149             : 
     150             : float
     151           0 : PointerEvent::TangentialPressure()
     152             : {
     153           0 :   return mEvent->AsPointerEvent()->tangentialPressure;
     154             : }
     155             : 
     156             : int32_t
     157           0 : PointerEvent::TiltX()
     158             : {
     159           0 :   return mEvent->AsPointerEvent()->tiltX;
     160             : }
     161             : 
     162             : int32_t
     163           0 : PointerEvent::TiltY()
     164             : {
     165           0 :   return mEvent->AsPointerEvent()->tiltY;
     166             : }
     167             : 
     168             : int32_t
     169           0 : PointerEvent::Twist()
     170             : {
     171           0 :   return mEvent->AsPointerEvent()->twist;
     172             : }
     173             : 
     174             : bool
     175           0 : PointerEvent::IsPrimary()
     176             : {
     177           0 :   return mEvent->AsPointerEvent()->mIsPrimary;
     178             : }
     179             : 
     180             : } // namespace dom
     181             : } // namespace mozilla
     182             : 
     183             : using namespace mozilla;
     184             : using namespace mozilla::dom;
     185             : 
     186             : already_AddRefed<PointerEvent>
     187           0 : NS_NewDOMPointerEvent(EventTarget* aOwner,
     188             :                       nsPresContext* aPresContext,
     189             :                       WidgetPointerEvent *aEvent)
     190             : {
     191           0 :   RefPtr<PointerEvent> it = new PointerEvent(aOwner, aPresContext, aEvent);
     192           0 :   return it.forget();
     193             : }

Generated by: LCOV version 1.13