15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright 2008, The Android Open Source Project
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  * Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  * Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/dom/Touch.h"
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "core/frame/FrameView.h"
31d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)#include "core/frame/LocalFrame.h"
325d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)#include "platform/geometry/FloatPoint.h"
335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
34c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
365d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)static FloatPoint contentsOffset(LocalFrame* frame)
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!frame)
395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        return FloatPoint();
405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    FrameView* frameView = frame->view();
415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!frameView)
425d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)        return FloatPoint();
435d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    float scale = 1.0f / frame->pageZoomFactor();
445d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    return FloatPoint(frameView->scrollPosition()).scaledBy(scale);
455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
475d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)Touch::Touch(LocalFrame* frame, EventTarget* target, unsigned identifier, const FloatPoint& screenPos, const FloatPoint& pagePos, const FloatSize& radius, float rotationAngle, float force)
485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    : m_target(target)
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_identifier(identifier)
505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_clientPos(pagePos - contentsOffset(frame))
515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_screenPos(screenPos)
525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_pagePos(pagePos)
535d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_radius(radius)
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_rotationAngle(rotationAngle)
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    , m_force(force)
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
57c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    float scaleFactor = frame ? frame->pageZoomFactor() : 1.0f;
585d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    m_absoluteLocation = roundedLayoutPoint(pagePos.scaledBy(scaleFactor));
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
615d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)Touch::Touch(EventTarget* target, unsigned identifier, const FloatPoint& clientPos, const FloatPoint& screenPos, const FloatPoint& pagePos, const FloatSize& radius, float rotationAngle, float force, LayoutPoint absoluteLocation)
62926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    : m_target(target)
63926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_identifier(identifier)
645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_clientPos(clientPos)
655d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_screenPos(screenPos)
665d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_pagePos(pagePos)
675d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    , m_radius(radius)
68926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_rotationAngle(rotationAngle)
69926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_force(force)
70926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_absoluteLocation(absoluteLocation)
71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
73926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
74d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)PassRefPtrWillBeRawPtr<Touch> Touch::cloneWithNewTarget(EventTarget* eventTarget) const
75926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)    return adoptRefWillBeNoop(new Touch(eventTarget, m_identifier, m_clientPos, m_screenPos, m_pagePos, m_radius, m_rotationAngle, m_force, m_absoluteLocation));
77926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
78926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
79f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)void Touch::trace(Visitor* visitor)
80f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles){
81f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    visitor->trace(m_target);
82f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)}
83f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
84c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
85