summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 00:35:00 +0000
committervarunjain@chromium.org <varunjain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-06 00:35:00 +0000
commitd62f4e53307f0816dc0c0fcd6fff2e4aaf211c12 (patch)
treed78c6bd298bbfb36f293a3f0f45716cf6fe93ebc
parent2bfebfd44f06004e5a296b171e80afc017e0aa6e (diff)
downloadchromium_src-d62f4e53307f0816dc0c0fcd6fff2e4aaf211c12.zip
chromium_src-d62f4e53307f0816dc0c0fcd6fff2e4aaf211c12.tar.gz
chromium_src-d62f4e53307f0816dc0c0fcd6fff2e4aaf211c12.tar.bz2
Implement touch selection for RWHVV.
BUG=none TEST=none Review URL: http://codereview.chromium.org/7570001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95698 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_gtk.cc4
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_gtk.h4
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.h4
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_mac.mm4
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_views.cc38
-rw-r--r--chrome/browser/renderer_host/render_widget_host_view_views.h21
-rw-r--r--content/browser/renderer_host/render_view_host.cc6
-rw-r--r--content/browser/renderer_host/render_view_host.h3
-rw-r--r--content/browser/renderer_host/render_widget_host_view.h8
-rw-r--r--content/common/view_messages.h11
-rw-r--r--content/renderer/render_view.cc33
-rw-r--r--content/renderer/render_view.h5
12 files changed, 123 insertions, 18 deletions
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
index bb7f266..e3b1e13 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.cc
@@ -835,7 +835,9 @@ void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) {
}
void RenderWidgetHostViewGtk::SelectionChanged(const std::string& text,
- const ui::Range& range) {
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) {
if (!text.empty()) {
GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length());
diff --git a/chrome/browser/renderer_host/render_widget_host_view_gtk.h b/chrome/browser/renderer_host/render_widget_host_view_gtk.h
index d93b9a1..227e0811 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_gtk.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_gtk.h
@@ -88,7 +88,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView,
virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {}
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text,
- const ui::Range& range) OVERRIDE;
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) OVERRIDE;
virtual void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetBackground(const SkBitmap& background) OVERRIDE;
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.h b/chrome/browser/renderer_host/render_widget_host_view_mac.h
index 9a3daf8..7bdd77c 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.h
@@ -206,7 +206,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
virtual void Destroy() OVERRIDE;
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text,
- const ui::Range& range) OVERRIDE;
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) OVERRIDE;
virtual void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
diff --git a/chrome/browser/renderer_host/render_widget_host_view_mac.mm b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
index cb1d21f..28bbb7a 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_mac.mm
+++ b/chrome/browser/renderer_host/render_widget_host_view_mac.mm
@@ -644,7 +644,9 @@ void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) {
// which implements NSServicesRequests protocol.
//
void RenderWidgetHostViewMac::SelectionChanged(const std::string& text,
- const ui::Range& range) {
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) {
selected_text_ = text;
[cocoa_view_ setSelectedRange:range.ToNSRange()];
// Updaes markedRange when there is no marked text so that retrieving
diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.cc b/chrome/browser/renderer_host/render_widget_host_view_views.cc
index 858547c..95f5083 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_views.cc
+++ b/chrome/browser/renderer_host/render_widget_host_view_views.cc
@@ -87,7 +87,9 @@ RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host)
visually_deemphasized_(false),
touch_event_(),
text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
- has_composition_text_(false) {
+ has_composition_text_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(touch_selection_controller_(
+ views::TouchSelectionController::create(this))) {
set_focusable(true);
host_->SetView(this);
@@ -304,9 +306,13 @@ void RenderWidgetHostViewViews::SetTooltipText(const std::wstring& tip) {
}
void RenderWidgetHostViewViews::SelectionChanged(const std::string& text,
- const ui::Range& range) {
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) {
// TODO(anicolao): deal with the clipboard without GTK
NOTIMPLEMENTED();
+ if (touch_selection_controller_.get())
+ touch_selection_controller_->SelectionChanged(start, end);
}
void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) {
@@ -329,6 +335,34 @@ void RenderWidgetHostViewViews::SetVisuallyDeemphasized(
// TODO(anicolao)
}
+void RenderWidgetHostViewViews::SelectRect(const gfx::Point& start,
+ const gfx::Point& end) {
+ if (host_)
+ host_->Send(new ViewMsg_SelectRange(host_->routing_id(), start, end));
+}
+
+bool RenderWidgetHostViewViews::IsCommandIdChecked(int command_id) const {
+ // TODO(varunjain): implement this and other menu delegate methods.
+ NOTREACHED();
+ return true;
+}
+
+bool RenderWidgetHostViewViews::IsCommandIdEnabled(int command_id) const {
+ NOTREACHED();
+ return true;
+}
+
+bool RenderWidgetHostViewViews::GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) {
+ NOTREACHED();
+ return true;
+}
+
+void RenderWidgetHostViewViews::ExecuteCommand(int command_id) {
+ NOTREACHED();
+}
+
std::string RenderWidgetHostViewViews::GetClassName() const {
return kViewClassName;
}
diff --git a/chrome/browser/renderer_host/render_widget_host_view_views.h b/chrome/browser/renderer_host/render_widget_host_view_views.h
index e10694e..715c6b7 100644
--- a/chrome/browser/renderer_host/render_widget_host_view_views.h
+++ b/chrome/browser/renderer_host/render_widget_host_view_views.h
@@ -18,6 +18,7 @@
#include "views/controls/native/native_view_host.h"
#include "views/events/event.h"
#include "views/ime/text_input_client.h"
+#include "views/touchui/touch_selection_controller.h"
#include "views/view.h"
#include "webkit/glue/webcursor.h"
@@ -35,7 +36,7 @@ struct NativeWebKeyboardEvent;
// See comments in render_widget_host_view.h about this class and its members.
// -----------------------------------------------------------------------------
class RenderWidgetHostViewViews : public RenderWidgetHostView,
- public views::View,
+ public views::TouchSelectionClientView,
public views::TextInputClient {
public:
// Internal class name.
@@ -79,7 +80,9 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
virtual void Destroy() OVERRIDE;
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text,
- const ui::Range& range) OVERRIDE;
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) OVERRIDE;
virtual void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetBackground(const SkBitmap& background) OVERRIDE;
@@ -98,6 +101,18 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
#endif
virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE;
+ // Overridden from views::TouchSelectionClientView.
+ virtual void SelectRect(const gfx::Point& start,
+ const gfx::Point& end) OVERRIDE;
+
+ // Overridden from ui::SimpleMenuModel::Delegate.
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) OVERRIDE;
+ virtual void ExecuteCommand(int command_id) OVERRIDE;
+
// Overridden from views::View.
virtual std::string GetClassName() const OVERRIDE;
virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE;
@@ -240,6 +255,8 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
string16 tooltip_text_;
+ scoped_ptr<views::TouchSelectionController> touch_selection_controller_;
+
#if defined(TOUCH_UI)
std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerTouch> >
accelerated_surface_containers_;
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index 3f12fc2..2127b1b 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -1002,9 +1002,11 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange(
}
void RenderViewHost::OnMsgSelectionChanged(const std::string& text,
- const ui::Range& range) {
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) {
if (view())
- view()->SelectionChanged(text, range);
+ view()->SelectionChanged(text, range, start, end);
}
void RenderViewHost::OnMsgRunJavaScriptMessage(
diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h
index c6a8010..693e679 100644
--- a/content/browser/renderer_host/render_view_host.h
+++ b/content/browser/renderer_host/render_view_host.h
@@ -428,7 +428,8 @@ class RenderViewHost : public RenderWidgetHost {
void OnMsgOpenURL(const GURL& url, const GURL& referrer,
WindowOpenDisposition disposition);
void OnMsgDidContentsPreferredSizeChange(const gfx::Size& new_size);
- void OnMsgSelectionChanged(const std::string& text, const ui::Range& range);
+ void OnMsgSelectionChanged(const std::string& text, const ui::Range& range,
+ const gfx::Point& start, const gfx::Point& end);
void OnMsgPasteFromSelectionClipboard();
void OnMsgRunJavaScriptMessage(const string16& message,
const string16& default_prompt,
diff --git a/content/browser/renderer_host/render_widget_host_view.h b/content/browser/renderer_host/render_widget_host_view.h
index 8463cb8..cd1bc2f 100644
--- a/content/browser/renderer_host/render_widget_host_view.h
+++ b/content/browser/renderer_host/render_widget_host_view.h
@@ -179,9 +179,13 @@ class RenderWidgetHostView {
// the page has changed.
virtual void SetTooltipText(const std::wstring& tooltip_text) = 0;
- // Notifies the View that the renderer text selection has changed.
+ // Notifies the View that the renderer text selection has changed. |start|
+ // and |end| are the visual end points of the selection in the coordinate
+ // system of the render view.
virtual void SelectionChanged(const std::string& text,
- const ui::Range& range) {}
+ const ui::Range& range,
+ const gfx::Point& start,
+ const gfx::Point& end) {}
// Tells the View whether the context menu is showing. This is used on Linux
// to suppress updates to webkit focus for the duration of the show.
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index 4022238..eaf0655 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -923,6 +923,11 @@ IPC_MESSAGE_ROUTED1(ViewMsg_Replace,
IPC_MESSAGE_ROUTED0(ViewMsg_Delete)
IPC_MESSAGE_ROUTED0(ViewMsg_SelectAll)
+// Requests the renderer to select the region between two points.
+IPC_MESSAGE_ROUTED2(ViewMsg_SelectRange,
+ gfx::Point /* start */,
+ gfx::Point /* end */)
+
// Copies the image at location x, y to the clipboard (if there indeed is an
// image at that location).
IPC_MESSAGE_ROUTED2(ViewMsg_CopyImageAt,
@@ -1711,9 +1716,11 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_SetTooltipText,
WebKit::WebTextDirection /* text direction hint */)
// Notification that the text selection has changed.
-IPC_MESSAGE_ROUTED2(ViewHostMsg_SelectionChanged,
+IPC_MESSAGE_ROUTED4(ViewHostMsg_SelectionChanged,
std::string /* currently selected text */,
- ui::Range /* selection range */)
+ ui::Range /* selection range */,
+ gfx::Point,
+ gfx::Point /* visual end points of selection */)
// Asks the browser to display the file chooser. The result is returned in a
// ViewHost_RunFileChooserResponse message.
diff --git a/content/renderer/render_view.cc b/content/renderer/render_view.cc
index a0bea3c..972349f 100644
--- a/content/renderer/render_view.cc
+++ b/content/renderer/render_view.cc
@@ -361,7 +361,8 @@ RenderView::RenderView(RenderThreadBase* render_thread,
accessibility_ack_pending_(false),
p2p_socket_dispatcher_(NULL),
devtools_agent_(NULL),
- session_storage_namespace_id_(session_storage_namespace_id) {
+ session_storage_namespace_id_(session_storage_namespace_id),
+ handling_select_range_(false) {
routing_id_ = routing_id;
if (opener_id != MSG_ROUTING_NONE)
opener_id_ = opener_id;
@@ -614,6 +615,7 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
+ IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
@@ -979,6 +981,15 @@ void RenderView::OnSelectAll() {
WebString::fromUTF8("SelectAll"));
}
+void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
+ if (!webview())
+ return;
+
+ handling_select_range_ = true;
+ webview()->focusedFrame()->selectRange(start, end);
+ handling_select_range_ = false;
+}
+
void RenderView::OnSetInitialFocus(bool reverse) {
if (!webview())
return;
@@ -1515,8 +1526,9 @@ bool RenderView::isSelectTrailingWhitespaceEnabled() {
void RenderView::didChangeSelection(bool is_empty_selection) {
#if defined(OS_POSIX)
- if (!handling_input_event_)
+ if (!handling_input_event_ && !handling_select_range_)
return;
+ handling_select_range_ = false;
if (is_empty_selection) {
last_selection_.clear();
@@ -1537,7 +1549,22 @@ void RenderView::didChangeSelection(bool is_empty_selection) {
range.set_start(location);
range.set_end(location + length);
}
- Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range));
+
+ WebKit::WebPoint start, end;
+ webview()->selectionRange(start, end);
+
+ // Webkit gives an offset of 1 between start and end even if there is no
+ // selection. So we need to check against that.
+ // TODO(varunjain): remove this check once that is fixed.
+ gfx::Point p1, p2;
+ if (std::abs(start.x - end.x) > 1 || std::abs(start.y - end.y) > 1) {
+ gfx::Point scroll_offset = GetScrollOffset();
+ p1.SetPoint(start.x + scroll_offset.x(), start.y + scroll_offset.y());
+ p2.SetPoint(end.x + scroll_offset.x(), end.y + scroll_offset.y());
+ }
+ // TODO(varunjain): add other hooks for SelectionChanged.
+ Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range,
+ p1, p2));
#endif // defined(OS_POSIX)
}
diff --git a/content/renderer/render_view.h b/content/renderer/render_view.h
index 0db5615..430f054 100644
--- a/content/renderer/render_view.h
+++ b/content/renderer/render_view.h
@@ -819,6 +819,7 @@ class RenderView : public RenderWidget,
int id,
bool notify_result);
void OnSelectAll();
+ void OnSelectRange(const gfx::Point& start, const gfx::Point& end);
void OnSetAccessibilityFocus(int acc_obj_id);
void OnSetActive(bool active);
void OnSetAltErrorPageURL(const GURL& gurl);
@@ -1197,6 +1198,10 @@ class RenderView : public RenderWidget,
// is fine.
ObserverList<RenderViewObserver> observers_;
+ // Used to inform didChangeSelection() when it is called in the context
+ // of handling a ViewMsg_SelectRange IPC.
+ bool handling_select_range_;
+
// ---------------------------------------------------------------------------
// ADDING NEW DATA? Please see if it fits appropriately in one of the above
// sections rather than throwing it randomly at the end. If you're adding a