Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / web_contents / touch_editable_impl_aura.h
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
19 namespace ui {
20 class Accelerator;
21 }
22
23 namespace content {
24 class TouchEditableImplAuraTest;
25
26 // Aura specific implementation of ui::TouchEditable for a RenderWidgetHostView.
27 class CONTENT_EXPORT TouchEditableImplAura
28     : public ui::TouchEditable,
29       public NON_EXPORTED_BASE(RenderWidgetHostViewAura::TouchEditingClient) {
30  public:
31   ~TouchEditableImplAura() override;
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   void StartTouchEditing() override;
46   void EndTouchEditing(bool quick) override;
47   void OnSelectionOrCursorChanged(const gfx::Rect& anchor,
48                                   const gfx::Rect& focus) override;
49   void OnTextInputTypeChanged(ui::TextInputType type) override;
50   bool HandleInputEvent(const ui::Event* event) override;
51   void GestureEventAck(int gesture_event_type) override;
52   void DidStopFlinging() override;
53   void OnViewDestroyed() override;
54
55   // Overridden from ui::TouchEditable:
56   void SelectRect(const gfx::Point& start, const gfx::Point& end) override;
57   void MoveCaretTo(const gfx::Point& point) override;
58   void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) override;
59   gfx::Rect GetBounds() override;
60   gfx::NativeView GetNativeView() const override;
61   void ConvertPointToScreen(gfx::Point* point) override;
62   void ConvertPointFromScreen(gfx::Point* point) override;
63   bool DrawsHandles() override;
64   void OpenContextMenu(const gfx::Point& anchor) override;
65   bool IsCommandIdChecked(int command_id) const override;
66   bool IsCommandIdEnabled(int command_id) const override;
67   bool GetAcceleratorForCommandId(int command_id,
68                                   ui::Accelerator* accelerator) override;
69   void ExecuteCommand(int command_id, int event_flags) override;
70   void DestroyTouchSelection() override;
71
72  protected:
73   TouchEditableImplAura();
74
75  private:
76   friend class TouchEditableImplAuraTest;
77
78   // A convenience function that is called after scroll/fling/overscroll ends to
79   // re-activate touch selection if necessary.
80   void ScrollEnded();
81
82   void Cleanup();
83
84   // Rectangles for the selection anchor and focus.
85   gfx::Rect selection_anchor_rect_;
86   gfx::Rect selection_focus_rect_;
87
88   // The current text input type.
89   ui::TextInputType text_input_type_;
90
91   RenderWidgetHostViewAura* rwhva_;
92   scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
93
94   // True if |rwhva_| is currently handling a gesture that could result in a
95   // change in selection (long press, double tap or triple tap).
96   bool selection_gesture_in_process_;
97
98   // Set to true if handles are hidden when user is scrolling. Used to determine
99   // whether to re-show handles after a scrolling session.
100   bool handles_hidden_due_to_scroll_;
101
102   // Keeps track of number of scrolls/flings/overscrolls in progress.
103   int scrolls_in_progress_;
104
105   // Used to track if a textfield was focused when the current tap gesture
106   // happened.
107   bool textfield_was_focused_on_tap_;
108
109   DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
110 };
111
112 }  // namespace content
113
114 #endif  // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_