touch_editable_impl_aura.h revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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 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 OnViewDestroyed() OVERRIDE; 53 54 // Overridden from ui::TouchEditable: 55 virtual void SelectRect(const gfx::Point& start, 56 const gfx::Point& end) OVERRIDE; 57 virtual void MoveCaretTo(const gfx::Point& point) OVERRIDE; 58 virtual void GetSelectionEndPoints(gfx::Rect* p1, gfx::Rect* p2) OVERRIDE; 59 virtual gfx::Rect GetBounds() OVERRIDE; 60 virtual gfx::NativeView GetNativeView() const OVERRIDE; 61 virtual void ConvertPointToScreen(gfx::Point* point) OVERRIDE; 62 virtual void ConvertPointFromScreen(gfx::Point* point) OVERRIDE; 63 virtual bool DrawsHandles() OVERRIDE; 64 virtual void OpenContextMenu(const gfx::Point& anchor) OVERRIDE; 65 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 66 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 67 virtual bool GetAcceleratorForCommandId( 68 int command_id, 69 ui::Accelerator* accelerator) OVERRIDE; 70 virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE; 71 72 protected: 73 TouchEditableImplAura(); 74 75 private: 76 friend class TouchEditableImplAuraTest; 77 78 void Cleanup(); 79 80 // Rectangles for the selection anchor and focus. 81 gfx::Rect selection_anchor_rect_; 82 gfx::Rect selection_focus_rect_; 83 84 // The current text input type. 85 ui::TextInputType text_input_type_; 86 87 RenderWidgetHostViewAura* rwhva_; 88 scoped_ptr<ui::TouchSelectionController> touch_selection_controller_; 89 90 // True if |rwhva_| is currently handling a gesture that could result in a 91 // change in selection (long press, double tap or triple tap). 92 bool selection_gesture_in_process_; 93 94 // Set to true if handles are hidden when user is scrolling. Used to determine 95 // whether to re-show handles after a scrolling session. 96 bool handles_hidden_due_to_scroll_; 97 98 // Keeps track of when the user is scrolling. 99 bool scroll_in_progress_; 100 101 // Set to true when the page starts an overscroll. 102 bool overscroll_in_progress_; 103 104 // Used to track if the current tap gesture is on a focused textfield. 105 bool is_tap_on_focused_textfield_; 106 107 // When we receive ack for a ET_GESTURE_TAP, we do not know if the ack is for 108 // a tap or a double tap (we only get the event type in the ack). So we have 109 // this queue to keep track of the the tap count so that we can distinguish 110 // between double and single tap when we get the ack. 111 std::queue<int> tap_gesture_tap_count_queue_; 112 113 DISALLOW_COPY_AND_ASSIGN(TouchEditableImplAura); 114}; 115 116} // namespace content 117 118#endif // CONTENT_BROWSER_WEB_CONTENTS_TOUCH_EDITABLE_IMPL_AURA_H_ 119