touch_editable_impl_aura.h revision 58537e28ecd584eab876aee8be7156509866d23a
1// Copyright (c) 2013 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#ifndef CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
6#define CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
7
8#include <deque>
9#include <map>
10
11#include "content/browser/renderer_host/render_widget_host_view_aura.h"
12#include "ui/aura/window_observer.h"
13#include "ui/base/touch/touch_editing_controller.h"
14#include "ui/gfx/native_widget_types.h"
15#include "ui/gfx/point.h"
16#include "ui/gfx/rect.h"
17
18namespace ui {
19class Accelerator;
20}
21
22namespace content {
23class TouchEditableImplAuraTest;
24
25// Aura specific implementation of ui::TouchEditable for a RenderWidgetHostView.
26class CONTENT_EXPORT TouchEditableImplAura
27    : public ui::TouchEditable,
28      public NON_EXPORTED_BASE(RenderWidgetHostViewAura::TouchEditingClient) {
29 public:
30  virtual ~TouchEditableImplAura();
31
32  static TouchEditableImplAura* Create();
33
34  void AttachToView(RenderWidgetHostViewAura* view);
35
36  // Updates the |touch_selection_controller_| or ends touch editing session
37  // depending on the current selection and cursor state.
38  void UpdateEditingController();
39
40  void OverscrollStarted();
41  void OverscrollCompleted();
42
43  // Overridden from RenderWidgetHostViewAura::TouchEditingClient.
44  virtual void StartTouchEditing() OVERRIDE;
45  virtual void EndTouchEditing() OVERRIDE;
46  virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
47                                          const gfx::Rect& focus) OVERRIDE;
48  virtual void OnTextInputTypeChanged(ui::TextInputType type) OVERRIDE;
49  virtual bool HandleInputEvent(const ui::Event* event) OVERRIDE;
50  virtual void GestureEventAck(int gesture_event_type) OVERRIDE;
51  virtual void OnViewDestroyed() OVERRIDE;
52
53  // Overridden from ui::TouchEditable:
54  virtual void SelectRect(const gfx::Point& start,
55                          const gfx::Point& end) OVERRIDE;
56  virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE;
57  virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE;
58  virtual gfx::Rect GetBounds() OVERRIDE;
59  virtual gfx::NativeView GetNativeView() OVERRIDE;
60  virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE;
61  virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE;
62  virtual bool DrawsHandles() OVERRIDE;
63  virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE;
64  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
65  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
66  virtual bool GetAcceleratorForCommandId(
67      int command_id,
68      ui::Accelerator* accelerator) OVERRIDE;
69  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
70
71 protected:
72  TouchEditableImplAura();
73
74 private:
75  friend class TouchEditableImplAuraTest;
76
77  void Cleanup();
78
79  // Rectangles for the selection anchor and focus.
80  gfx::Rect selection_anchor_rect_;
81  gfx::Rect selection_focus_rect_;
82
83  // The current text input type.
84  ui::TextInputType text_input_type_;
85
86  RenderWidgetHostViewAura* rwhva_;
87  scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
88
89  // True if |rwhva_| is currently handling a gesture that could result in a
90  // change in selection (long press, double tap or triple tap).
91  bool selection_gesture_in_process_;
92
93  // Set to true if handles are hidden when user is scrolling. Used to determine
94  // whether to re-show handles after a scrolling session.
95  bool handles_hidden_due_to_scroll_;
96
97  // Keeps track of when the user is scrolling.
98  bool scroll_in_progress_;
99
100  // Set to true when the page starts an overscroll.
101  bool overscroll_in_progress_;
102
103  // Used to track if the current tap gesture is on a focused textfield.
104  bool is_tap_on_focused_textfield_;
105
106  // When we receive ack for a ET_GESTURE_TAP, we do not know if the ack is for
107  // a tap or a double tap (we only get the event type in the ack). So we have
108  // this queue to keep track of the the tap count so that we can distinguish
109  // between double and single tap when we get the ack.
110  std::queue<int> tap_gesture_tap_count_queue_;
111
112  DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
113};
114
115}  // namespace content
116
117#endif  // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
118