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