summaryrefslogtreecommitdiffstats
path: root/views/touchui/gesture_manager.cc
blob: 24424694d8d96bbc96ee05e02bdefc4f9510ec04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "views/touchui/gesture_manager.h"
#ifndef NDEBUG
#include <iostream>
#endif

#include "base/logging.h"
#include "views/events/event.h"
#include "views/view.h"

namespace views {

GestureManager::~GestureManager() {
}

GestureManager* GestureManager::GetInstance() {
  return Singleton<GestureManager>::get();
}

bool GestureManager::ProcessTouchEventForGesture(const TouchEvent& event,
                                                 View* source,
                                                 View::TouchStatus status) {
  if (status != View::TOUCH_STATUS_UNKNOWN)
    return false;  // The event was consumed by a touch sequence.

  // TODO(rjkroege): A realistic version of the GestureManager will
  // appear in a subsequent CL. This interim version permits verifying that the
  // event distribution code works by turning all touch inputs into
  // mouse approximations.

  // TODO(sad): Clean this up.
  // This is currently only called where |source| is a RootView. Now, RootView
  // expects the mouse-events in the widget's coordinate system, and not in the
  // RV's coordinate system. But |event| is in the RV's coordinate system. So it
  // is necessary to construct the synthetic event in the widget's coordinate
  // system.
  gfx::Point location = event.location();
  View::ConvertPointToWidget(source, &location);

  if (event.type() == ui::ET_TOUCH_PRESSED) {
    DVLOG(1) << "GestureManager::ProcessTouchEventForGesture: TouchPressed";
    MouseEvent mouse_event(ui::ET_MOUSE_PRESSED, location.x(), location.y(),
                           event.flags());
    source->OnMousePressed(mouse_event);
    return true;
  }

  if (event.type() == ui::ET_TOUCH_RELEASED) {
    DVLOG(1) << "GestureManager::ProcessTouchEventForGesture: TouchReleased";
    MouseEvent mouse_event(ui::ET_MOUSE_RELEASED, location.x(), location.y(),
                           event.flags());
    source->OnMouseReleased(mouse_event, false);
    return true;
  }

  if (event.type() == ui::ET_TOUCH_MOVED) {
    DVLOG(1) << "GestureManager::ProcessTouchEventForGesture: TouchMotion";
    MouseEvent mouse_event(ui::ET_MOUSE_DRAGGED, location.x(), location.y(),
                           event.flags());
    source->OnMouseDragged(mouse_event);
    return true;
  }

  DVLOG(1) << "GestureManager::ProcessTouchEventForGesture: unhandled event";
  return false;
}

GestureManager::GestureManager() {
}

}  // namespace views