1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INPUT_TOUCH_H_ 27 #define THIRD_PARTY_BLINK_RENDERER_CORE_INPUT_TOUCH_H_ 28 29 #include "third_party/blink/renderer/core/core_export.h" 30 #include "third_party/blink/renderer/core/dom/document.h" 31 #include "third_party/blink/renderer/core/dom/events/event_target.h" 32 #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" 33 #include "third_party/blink/renderer/platform/geometry/float_point.h" 34 #include "third_party/blink/renderer/platform/geometry/float_size.h" 35 #include "third_party/blink/renderer/platform/geometry/layout_point.h" 36 #include "third_party/blink/renderer/platform/heap/handle.h" 37 38 namespace blink { 39 40 class LocalFrame; 41 class TouchInit; 42 43 class CORE_EXPORT Touch final : public ScriptWrappable { 44 DEFINE_WRAPPERTYPEINFO(); 45 46 public: Create(LocalFrame * frame,EventTarget * target,int identifier,const FloatPoint & screen_pos,const FloatPoint & page_pos,const FloatSize & radius,float rotation_angle,float force,String region)47 static Touch* Create(LocalFrame* frame, 48 EventTarget* target, 49 int identifier, 50 const FloatPoint& screen_pos, 51 const FloatPoint& page_pos, 52 const FloatSize& radius, 53 float rotation_angle, 54 float force, 55 String region) { 56 return MakeGarbageCollected<Touch>(frame, target, identifier, screen_pos, 57 page_pos, radius, rotation_angle, force, 58 region); 59 } 60 Create(const Document & document,const TouchInit * initializer)61 static Touch* Create(const Document& document, const TouchInit* initializer) { 62 return MakeGarbageCollected<Touch>(document.GetFrame(), initializer); 63 } 64 65 Touch(LocalFrame*, 66 EventTarget*, 67 int identifier, 68 const FloatPoint& screen_pos, 69 const FloatPoint& page_pos, 70 const FloatSize& radius, 71 float rotation_angle, 72 float force, 73 String region); 74 75 Touch(EventTarget*, 76 int identifier, 77 const FloatPoint& client_pos, 78 const FloatPoint& screen_pos, 79 const FloatPoint& page_pos, 80 const FloatSize& radius, 81 float rotation_angle, 82 float force, 83 String region, 84 LayoutPoint absolute_location); 85 86 Touch(LocalFrame*, const TouchInit*); 87 88 // DOM Touch implementation target()89 EventTarget* target() const { return target_.Get(); } identifier()90 int identifier() const { return identifier_; } clientX()91 double clientX() const { return client_pos_.X(); } clientY()92 double clientY() const { return client_pos_.Y(); } screenX()93 double screenX() const { return screen_pos_.X(); } screenY()94 double screenY() const { return screen_pos_.Y(); } pageX()95 double pageX() const { return page_pos_.X(); } pageY()96 double pageY() const { return page_pos_.Y(); } radiusX()97 float radiusX() const { return radius_.Width(); } radiusY()98 float radiusY() const { return radius_.Height(); } rotationAngle()99 float rotationAngle() const { return rotation_angle_; } force()100 float force() const { return force_; } region()101 const String& region() const { return region_; } 102 103 // Blink-internal methods AbsoluteLocation()104 const LayoutPoint& AbsoluteLocation() const { return absolute_location_; } ScreenLocation()105 const FloatPoint& ScreenLocation() const { return screen_pos_; } 106 Touch* CloneWithNewTarget(EventTarget*) const; 107 108 void Trace(Visitor*) const override; 109 110 private: 111 Member<EventTarget> target_; 112 int identifier_; 113 // Position relative to the viewport in CSS px. 114 FloatPoint client_pos_; 115 // Position relative to the screen in DIPs. 116 FloatPoint screen_pos_; 117 // Position relative to the page in CSS px. 118 FloatPoint page_pos_; 119 // Radius in CSS px. 120 FloatSize radius_; 121 float rotation_angle_; 122 float force_; 123 String region_; 124 // FIXME(rbyers): Shouldn't we be able to migrate callers to relying on 125 // screenPos, pagePos or clientPos? absoluteLocation appears to be the same as 126 // pagePos but without browser scale applied. 127 LayoutPoint absolute_location_; 128 }; 129 130 } // namespace blink 131 132 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_INPUT_TOUCH_H_ 133