#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 "grit/ui_strings.h"
-#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_tree_host.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/gfx/range/range.h"
+#include "ui/wm/public/activation_client.h"
namespace content {
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_)
if (touch_selection_controller_->IsHandleDragInProgress()) {
touch_selection_controller_->SelectionChanged();
} else {
+ selection_gesture_in_process_ = false;
touch_selection_controller_->HideHandles(quick);
touch_selection_controller_.reset();
}
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();
}
bool TouchEditableImplAura::HandleInputEvent(const ui::Event* event) {
DCHECK(rwhva_);
- if (event->IsTouchEvent())
- return false;
-
if (!event->IsGestureEvent()) {
- EndTouchEditing(false);
+ // Ignore all non-gesture events. Non-gesture events that can deactivate
+ // touch editing are handled in TouchSelectionControllerImpl.
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
// tapped on selected text.
- if (selection_anchor_rect_ != selection_focus_rect_) {
+ if (gesture_event->details().tap_count() == 1 &&
+ selection_anchor_rect_ != selection_focus_rect_) {
// UnionRects only works for rects with non-zero width.
gfx::Rect anchor(selection_anchor_rect_.origin(),
gfx::Size(1, selection_anchor_rect_.height()));
}
// 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) {
- if (!rwhva_)
- return;
-
- RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
- rwhva_->GetRenderWidgetHost());
- host->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) {
}
gfx::NativeView TouchEditableImplAura::GetNativeView() const {
- return rwhva_ ? rwhva_->GetNativeView()->GetRootWindow() : NULL;
+ return rwhva_ ? rwhva_->GetNativeView()->GetToplevelWindow() : NULL;
}
void TouchEditableImplAura::ConvertPointToScreen(gfx::Point* point) {
gfx::Point point = anchor;
ConvertPointFromScreen(&point);
RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
- host->Send(new ViewMsg_ShowContextMenu(host->GetRoutingID(), point));
+ host->Send(new ViewMsg_ShowContextMenu(
+ host->GetRoutingID(), ui::MENU_SOURCE_TOUCH_EDIT_MENU, point));
EndTouchEditing(false);
}
}
void TouchEditableImplAura::ExecuteCommand(int command_id, int event_flags) {
- if (!rwhva_)
- return;
RenderWidgetHost* host = rwhva_->GetRenderWidgetHost();
+ RenderViewHost* rvh = RenderViewHost::From(host);
+ WebContents* wc = WebContents::FromRenderViewHost(rvh);
+
switch (command_id) {
case IDS_APP_CUT:
- host->Cut();
+ wc->Cut();
break;
case IDS_APP_COPY:
- host->Copy();
+ wc->Copy();
break;
case IDS_APP_PASTE:
- host->Paste();
+ wc->Paste();
break;
case IDS_APP_DELETE:
- host->Delete();
+ wc->Delete();
break;
case IDS_APP_SELECT_ALL:
- host->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;