1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// 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 TouchEditableImplAuraTest;
25
26// Aura specific implementation of ui::TouchEditable for a RenderWidgetHostView.
27class CONTENT_EXPORT TouchEditableImplAura
28    : public ui::TouchEditable,
29      public NON_EXPORTED_BASE(RenderWidgetHostViewAura::TouchEditingClient) {
30 public:
31  virtual ~TouchEditableImplAura();
32
33  static TouchEditableImplAura* Create();
34
35  void AttachToView(RenderWidgetHostViewAura* view);
36
37  // Updates the |touch_selection_controller_| or ends touch editing session
38  // depending on the current selection and cursor state.
39  void UpdateEditingController();
40
41  void OverscrollStarted();
42  void OverscrollCompleted();
43
44  // Overridden from RenderWidgetHostViewAura::TouchEditingClient.
45  virtual void StartTouchEditing() OVERRIDE;
46  virtual void EndTouchEditing(bool quick) OVERRIDE;
47  virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
48                                          const gfx::Rect& focus) OVERRIDE;
49  virtual void OnTextInputTypeChanged(ui::TextInputType type) OVERRIDE;
50  virtual bool HandleInputEvent(const ui::Event* event) OVERRIDE;
51  virtual void GestureEventAck(int gesture_event_type) OVERRIDE;
52  virtual void DidStopFlinging() 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  virtual void DestroyTouchSelection() OVERRIDE;
73
74 protected:
75  TouchEditableImplAura();
76
77 private:
78  friend class TouchEditableImplAuraTest;
79
80  // A convenience function that is called after scroll/fling/overscroll ends to
81  // re-activate touch selection if necessary.
82  void ScrollEnded();
83
84  void Cleanup();
85
86  // Rectangles for the selection anchor and focus.
87  gfx::Rect selection_anchor_rect_;
88  gfx::Rect selection_focus_rect_;
89
90  // The current text input type.
91  ui::TextInputType text_input_type_;
92
93  RenderWidgetHostViewAura* rwhva_;
94  scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
95
96  // True if |rwhva_| is currently handling a gesture that could result in a
97  // change in selection (long press, double tap or triple tap).
98  bool selection_gesture_in_process_;
99
100  // Set to true if handles are hidden when user is scrolling. Used to determine
101  // whether to re-show handles after a scrolling session.
102  bool handles_hidden_due_to_scroll_;
103
104  // Keeps track of number of scrolls/flings/overscrolls in progress.
105  int scrolls_in_progress_;
106
107  // Used to track if a textfield was focused when the current tap gesture
108  // happened.
109  bool textfield_was_focused_on_tap_;
110
111  DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
112};
113
114}  // namespace content
115
116#endif  // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
117