summaryrefslogtreecommitdiff
path: root/chromium/content/browser/web_contents/touch_editable_impl_aura.h
blob: 7f1ea845512e949f017ca3598c5a45c3279eefbc (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2013 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.

#ifndef CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
#define CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_

#include <deque>
#include <map>

#include "content/browser/renderer_host/render_widget_host_view_aura.h"
#include "ui/aura/window_observer.h"
#include "ui/base/touch/touch_editing_controller.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"

namespace ui {
class Accelerator;
}

namespace content {
class TouchEditableImplAuraTest;

// Aura specific implementation of ui::TouchEditable for a RenderWidgetHostView.
class CONTENT_EXPORT TouchEditableImplAura
    : public ui::TouchEditable,
      public NON_EXPORTED_BASE(RenderWidgetHostViewAura::TouchEditingClient) {
 public:
  virtual ~TouchEditableImplAura();

  static TouchEditableImplAura* Create();

  void AttachToView(RenderWidgetHostViewAura* view);

  // Updates the |touch_selection_controller_| or ends touch editing session
  // depending on the current selection and cursor state.
  void UpdateEditingController();

  void OverscrollStarted();
  void OverscrollCompleted();

  // Overridden from RenderWidgetHostViewAura::TouchEditingClient.
  virtual void StartTouchEditing() OVERRIDE;
  virtual void EndTouchEditing() OVERRIDE;
  virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
                                          const gfx::Rect& focus) OVERRIDE;
  virtual void OnTextInputTypeChanged(ui::TextInputType type) OVERRIDE;
  virtual bool HandleInputEvent(const ui::Event* event) OVERRIDE;
  virtual void GestureEventAck(int gesture_event_type) OVERRIDE;
  virtual void OnViewDestroyed() OVERRIDE;

  // Overridden from ui::TouchEditable:
  virtual void SelectRect(const gfx::Point& start,
                          const gfx::Point& end) OVERRIDE;
  virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE;
  virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE;
  virtual gfx::Rect GetBounds() OVERRIDE;
  virtual gfx::NativeView GetNativeView() OVERRIDE;
  virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE;
  virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE;
  virtual bool DrawsHandles() OVERRIDE;
  virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE;
  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
  virtual bool GetAcceleratorForCommandId(
      int command_id,
      ui::Accelerator* accelerator) OVERRIDE;
  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;

 protected:
  TouchEditableImplAura();

 private:
  friend class TouchEditableImplAuraTest;

  void Cleanup();

  // Rectangles for the selection anchor and focus.
  gfx::Rect selection_anchor_rect_;
  gfx::Rect selection_focus_rect_;

  // The current text input type.
  ui::TextInputType text_input_type_;

  RenderWidgetHostViewAura* rwhva_;
  scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;

  // True if |rwhva_| is currently handling a gesture that could result in a
  // change in selection (long press, double tap or triple tap).
  bool selection_gesture_in_process_;

  // Set to true if handles are hidden when user is scrolling. Used to determine
  // whether to re-show handles after a scrolling session.
  bool handles_hidden_due_to_scroll_;

  // Keeps track of when the user is scrolling.
  bool scroll_in_progress_;

  // Set to true when the page starts an overscroll.
  bool overscroll_in_progress_;

  // Used to track if the current tap gesture is on a focused textfield.
  bool is_tap_on_focused_textfield_;

  // When we receive ack for a ET_GESTURE_TAP, we do not know if the ack is for
  // a tap or a double tap (we only get the event type in the ack). So we have
  // this queue to keep track of the the tap count so that we can distinguish
  // between double and single tap when we get the ack.
  std::queue<int> tap_gesture_tap_count_queue_;

  DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
};

}  // namespace content

#endif  // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_