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 virtual ~TouchEditableImplAura();
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 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;
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(
70 ui::Accelerator* accelerator) OVERRIDE;
71 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
72 virtual void DestroyTouchSelection() OVERRIDE;
75 TouchEditableImplAura();
78 friend class TouchEditableImplAuraTest;
80 // A convenience function that is called after scroll/fling/overscroll ends to
81 // re-activate touch selection if necessary.
86 // Rectangles for the selection anchor and focus.
87 gfx::Rect selection_anchor_rect_;
88 gfx::Rect selection_focus_rect_;
90 // The current text input type.
91 ui::TextInputType text_input_type_;
93 RenderWidgetHostViewAura* rwhva_;
94 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_;
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_;
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_;
104 // Keeps track of number of scrolls/flings/overscrolls in progress.
105 int scrolls_in_progress_;
107 // Used to track if a textfield was focused when the current tap gesture
109 bool textfield_was_focused_on_tap_;
111 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura);
114 } // namespace content
116 #endif // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_