michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/MouseScrollEvent.h" michael@0: #include "mozilla/MouseEvents.h" michael@0: #include "prtime.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: MouseScrollEvent::MouseScrollEvent(EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetMouseScrollEvent* aEvent) michael@0: : MouseEvent(aOwner, aPresContext, michael@0: aEvent ? aEvent : new WidgetMouseScrollEvent(false, 0, nullptr)) michael@0: { michael@0: if (aEvent) { michael@0: mEventIsInternal = false; michael@0: } else { michael@0: mEventIsInternal = true; michael@0: mEvent->time = PR_Now(); michael@0: mEvent->refPoint.x = mEvent->refPoint.y = 0; michael@0: static_cast(mEvent)->inputSource = michael@0: nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN; michael@0: } michael@0: michael@0: mDetail = mEvent->AsMouseScrollEvent()->delta; michael@0: } michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(MouseScrollEvent, MouseEvent) michael@0: NS_IMPL_RELEASE_INHERITED(MouseScrollEvent, MouseEvent) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN(MouseScrollEvent) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMMouseScrollEvent) michael@0: NS_INTERFACE_MAP_END_INHERITING(MouseEvent) michael@0: michael@0: NS_IMETHODIMP michael@0: MouseScrollEvent::InitMouseScrollEvent(const nsAString& aType, michael@0: bool aCanBubble, michael@0: bool aCancelable, michael@0: nsIDOMWindow* aView, michael@0: int32_t aDetail, michael@0: int32_t aScreenX, michael@0: int32_t aScreenY, michael@0: int32_t aClientX, michael@0: int32_t aClientY, michael@0: bool aCtrlKey, michael@0: bool aAltKey, michael@0: bool aShiftKey, michael@0: bool aMetaKey, michael@0: uint16_t aButton, michael@0: nsIDOMEventTarget* aRelatedTarget, michael@0: int32_t aAxis) michael@0: { michael@0: nsresult rv = michael@0: MouseEvent::InitMouseEvent(aType, aCanBubble, aCancelable, aView, aDetail, michael@0: aScreenX, aScreenY, aClientX, aClientY, michael@0: aCtrlKey, aAltKey, aShiftKey, aMetaKey, aButton, michael@0: aRelatedTarget); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: mEvent->AsMouseScrollEvent()->isHorizontal = (aAxis == HORIZONTAL_AXIS); michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: MouseScrollEvent::GetAxis(int32_t* aResult) michael@0: { michael@0: NS_ENSURE_ARG_POINTER(aResult); michael@0: *aResult = Axis(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: int32_t michael@0: MouseScrollEvent::Axis() michael@0: { michael@0: return mEvent->AsMouseScrollEvent()->isHorizontal ? michael@0: static_cast(HORIZONTAL_AXIS) : michael@0: static_cast(VERTICAL_AXIS); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: using namespace mozilla; michael@0: using namespace dom; michael@0: michael@0: nsresult michael@0: NS_NewDOMMouseScrollEvent(nsIDOMEvent** aInstancePtrResult, michael@0: EventTarget* aOwner, michael@0: nsPresContext* aPresContext, michael@0: WidgetMouseScrollEvent* aEvent) michael@0: { michael@0: MouseScrollEvent* it = new MouseScrollEvent(aOwner, aPresContext, aEvent); michael@0: NS_ADDREF(it); michael@0: *aInstancePtrResult = static_cast(it); michael@0: return NS_OK; michael@0: }