touch_editable_impl_aura.h revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
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  // Overridden from RenderWidgetHostViewAura::TouchEditingClient.
41  virtual void StartTouchEditing() OVERRIDE;
42  virtual void EndTouchEditing() OVERRIDE;
43  virtual void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
44                                          const gfx::Rect& focus) OVERRIDE;
45  virtual void OnTextInputTypeChanged(ui::TextInputType type) OVERRIDE;
46  virtual bool HandleInputEvent(const ui::Event* event) OVERRIDE;
47  virtual void GestureEventAck(int gesture_event_type) OVERRIDE;
48  virtual void OnViewDestroyed() OVERRIDE;
49
50  // Overridden from ui::TouchEditable:
51  virtual void SelectRect(const gfx::Point& start,
52                          const gfx::Point& end) OVERRIDE;
53  virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE;
54  virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE;
55  virtual gfx::Rect GetBounds() OVERRIDE;
56  virtual gfx::NativeView GetNativeView() OVERRIDE;
57  virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE;
58  virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE;
59  virtual bool DrawsHandles() OVERRIDE;
60  virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE;
61  virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
62  virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
63  virtual bool GetAcceleratorForCommandId(
64      int command_id,
65      ui::Accelerator* accelerator) OVERRIDE;
66  virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
67
68 protected:
69  TouchEditableImplAura();
70
71 private:
72  friend class TouchEditableImplAuraTest;
73
74  void Cleanup();
75
76  // Rectangles for the selection anchor and focus.
77  gfx::Rect selection_anchor_rect_;
78  gfx::Rect selection_focus_rect_;
79
80  // The current text input type.
81  ui::TextInputType text_input_type_;
82
83  RenderWidgetHostViewAura* rwhva_;
84  scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
85
86  // True if |rwhva_| is currently handling a gesture that could result in a
87  // change in selection.
88  bool selection_gesture_in_process_;
89
90  bool handles_hidden_due_to_scroll_;
91
92  DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
93};
94
95}  // namespace content
96
97#endif  // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
98