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.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_
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"
24 class TouchEditableImplAuraTest;
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) {
31 ~TouchEditableImplAura() override;
33 static TouchEditableImplAura* Create();
35 void AttachToView(RenderWidgetHostViewAura* view);
37 // Updates the |touch_selection_controller_| or ends touch editing session
38 // depending on the current selection and cursor state.
39 void UpdateEditingController();
41 void OverscrollStarted();
42 void OverscrollCompleted();
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;
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;
73 TouchEditableImplAura();
76 friend class TouchEditableImplAuraTest;
78 // A convenience function that is called after scroll/fling/overscroll ends to
79 // re-activate touch selection if necessary.
84 // Rectangles for the selection anchor and focus.
85 gfx::Rect selection_anchor_rect_;
86 gfx::Rect selection_focus_rect_;
88 // The current text input type.
89 ui::TextInputType text_input_type_;
91 RenderWidgetHostViewAura* rwhva_;
92 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
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_;
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_;
102 // Keeps track of number of scrolls/flings/overscrolls in progress.
103 int scrolls_in_progress_;
105 // Used to track if a textfield was focused when the current tap gesture
107 bool textfield_was_focused_on_tap_;
109 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
112 } // namespace content
114 #endif // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_