#include "content/browser/web_contents/touch_editable_impl_aura.h"
-#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_view_aura.h"
+#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/view_messages.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
-#include "content/public/browser/web_contents.h"
#include "grit/ui_strings.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
if (!rwhva_ || !rwhva_->HasFocus())
return;
- // If touch editing handles were not visible, we bring them up only if
- // there is non-zero selection on the page. And the current event is a
- // gesture event (we dont want to show handles if the user is selecting
- // using mouse or keyboard).
- if (selection_gesture_in_process_ && !scroll_in_progress_ &&
- selection_anchor_rect_ != selection_focus_rect_)
- StartTouchEditing();
-
if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE ||
selection_anchor_rect_ != selection_focus_rect_) {
if (touch_selection_controller_)
const gfx::Rect& focus) {
selection_anchor_rect_ = anchor;
selection_focus_rect_ = focus;
+
+ // If touch editing handles were not visible, we bring them up only if
+ // there is non-zero selection on the page. And the current event is a
+ // gesture event (we dont want to show handles if the user is selecting
+ // using mouse or keyboard).
+ if (selection_gesture_in_process_ && !scroll_in_progress_ &&
+ !overscroll_in_progress_ &&
+ selection_anchor_rect_ != selection_focus_rect_) {
+ StartTouchEditing();
+ selection_gesture_in_process_ = false;
+ }
+
UpdateEditingController();
}
return false;
if (!event->IsGestureEvent()) {
+ selection_gesture_in_process_ = false;
EndTouchEditing(false);
return false;
}
static_cast<const ui::GestureEvent*>(event);
switch (event->type()) {
case ui::ET_GESTURE_TAP:
- tap_gesture_tap_count_queue_.push(gesture_event->details().tap_count());
if (gesture_event->details().tap_count() > 1)
selection_gesture_in_process_ = true;
// When the user taps, we want to show touch editing handles if user
}
// For single taps, not inside selected region, we want to show handles
// only when the tap is on an already focused textfield.
- is_tap_on_focused_textfield_ = false;
+ textfield_was_focused_on_tap_ = false;
if (gesture_event->details().tap_count() == 1 &&
text_input_type_ != ui::TEXT_INPUT_TYPE_NONE)
- is_tap_on_focused_textfield_ = true;
+ textfield_was_focused_on_tap_ = true;
break;
case ui::ET_GESTURE_LONG_PRESS:
selection_gesture_in_process_ = true;
case ui::ET_GESTURE_SCROLL_BEGIN:
// If selection handles are currently visible, we want to get them back up
// when scrolling ends. So we set |handles_hidden_due_to_scroll_| so that
- // we can re-start touch editing when we call |UpdateEditingController()|
- // on scroll end gesture.
+ // we can re-start touch editing on scroll end gesture.
scroll_in_progress_ = true;
handles_hidden_due_to_scroll_ = false;
if (touch_selection_controller_)
DCHECK(rwhva_);
if (gesture_event_type == blink::WebInputEvent::GestureTap &&
text_input_type_ != ui::TEXT_INPUT_TYPE_NONE &&
- is_tap_on_focused_textfield_) {
+ textfield_was_focused_on_tap_) {
StartTouchEditing();
- if (touch_selection_controller_)
- touch_selection_controller_->SelectionChanged();
- }
-
- if (gesture_event_type == blink::WebInputEvent::GestureLongPress)
- selection_gesture_in_process_ = false;
- if (gesture_event_type == blink::WebInputEvent::GestureTap) {
- if (tap_gesture_tap_count_queue_.front() > 1)
- selection_gesture_in_process_ = false;
- tap_gesture_tap_count_queue_.pop();
+ UpdateEditingController();
}
}
void TouchEditableImplAura::SelectRect(const gfx::Point& start,
const gfx::Point& end) {
- RenderFrameHost* focused_frame = GetFocusedFrame();
- if (!focused_frame)
- return;
-
- static_cast<RenderFrameHostImpl*>(focused_frame)->SelectRange(start, end);
+ RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
+ RenderViewHost* rvh = RenderViewHost::From(host);
+ WebContentsImpl* wc =
+ static_cast<WebContentsImpl*>(WebContents::FromRenderViewHost(rvh));
+ wc->SelectRange(start, end);
}
void TouchEditableImplAura::MoveCaretTo(const gfx::Point& point) {
}
void TouchEditableImplAura::ExecuteCommand(int command_id, int event_flags) {
- RenderFrameHost* focused_frame = GetFocusedFrame();
- if (!focused_frame)
- return;
+ RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
+ RenderViewHost* rvh = RenderViewHost::From(host);
+ WebContents* wc = WebContents::FromRenderViewHost(rvh);
+
switch (command_id) {
case IDS_APP_CUT:
- focused_frame->Cut();
+ wc->Cut();
break;
case IDS_APP_COPY:
- focused_frame->Copy();
+ wc->Copy();
break;
case IDS_APP_PASTE:
- focused_frame->Paste();
+ wc->Paste();
break;
case IDS_APP_DELETE:
- focused_frame->Delete();
+ wc->Delete();
break;
case IDS_APP_SELECT_ALL:
- focused_frame->SelectAll();
+ wc->SelectAll();
break;
default:
NOTREACHED();
EndTouchEditing(false);
}
+void TouchEditableImplAura::DestroyTouchSelection() {
+ EndTouchEditing(false);
+}
+
////////////////////////////////////////////////////////////////////////////////
// TouchEditableImplAura, private:
handles_hidden_due_to_scroll_(false),
scroll_in_progress_(false),
overscroll_in_progress_(false),
- is_tap_on_focused_textfield_(false) {
+ textfield_was_focused_on_tap_(false) {
}
void TouchEditableImplAura::Cleanup() {
}
text_input_type_ = ui::TEXT_INPUT_TYPE_NONE;
EndTouchEditing(true);
+ selection_gesture_in_process_ = false;
handles_hidden_due_to_scroll_ = false;
scroll_in_progress_ = false;
overscroll_in_progress_ = false;
}
-RenderFrameHost* TouchEditableImplAura::GetFocusedFrame() {
- if (!rwhva_)
- return NULL;
- RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
- RenderViewHost* rvh = RenderViewHost::From(host);
- WebContents* wc = WebContents::FromRenderViewHost(rvh);
- return wc->GetFocusedFrame();
-}
-
} // namespace content