1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "third_party/blink/public/common/input/web_touch_event.h"
6 
7 namespace blink {
8 
Clone() const9 std::unique_ptr<WebInputEvent> WebTouchEvent::Clone() const {
10   return std::make_unique<WebTouchEvent>(*this);
11 }
12 
FlattenTransform() const13 WebTouchEvent WebTouchEvent::FlattenTransform() const {
14   WebTouchEvent transformed_event = *this;
15   for (unsigned i = 0; i < touches_length; ++i) {
16     transformed_event.touches[i] = TouchPointInRootFrame(i);
17   }
18   transformed_event.frame_translate_ = gfx::Vector2dF();
19   transformed_event.frame_scale_ = 1;
20 
21   return transformed_event;
22 }
23 
TouchPointInRootFrame(unsigned point) const24 WebTouchPoint WebTouchEvent::TouchPointInRootFrame(unsigned point) const {
25   DCHECK_LT(point, touches_length);
26   if (point >= touches_length)
27     return WebTouchPoint();
28 
29   WebTouchPoint transformed_point = touches[point];
30   transformed_point.radius_x /= frame_scale_;
31   transformed_point.radius_y /= frame_scale_;
32   transformed_point.SetPositionInWidget(
33       gfx::ScalePoint(transformed_point.PositionInWidget(), 1 / frame_scale_) +
34       frame_translate_);
35   return transformed_point;
36 }
37 
38 }  // namespace blink
39