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
parent 2bfebfd4
...@@ -835,7 +835,9 @@ void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) { ...@@ -835,7 +835,9 @@ void RenderWidgetHostViewGtk::SetTooltipText(const std::wstring& tooltip_text) {
} }
void RenderWidgetHostViewGtk::SelectionChanged(const std::string& 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()) { if (!text.empty()) {
GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); GtkClipboard* x_clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length()); gtk_clipboard_set_text(x_clipboard, text.c_str(), text.length());
......
...@@ -88,7 +88,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView, ...@@ -88,7 +88,9 @@ class RenderWidgetHostViewGtk : public RenderWidgetHostView,
virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {} virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) {}
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE; virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text, 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 void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetBackground(const SkBitmap& background) OVERRIDE; virtual void SetBackground(const SkBitmap& background) OVERRIDE;
......
...@@ -206,7 +206,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { ...@@ -206,7 +206,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
virtual void Destroy() OVERRIDE; virtual void Destroy() OVERRIDE;
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE; virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text, 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 void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE; virtual void SetTakesFocusOnlyOnMouseDown(bool flag) OVERRIDE;
......
...@@ -644,7 +644,9 @@ void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) { ...@@ -644,7 +644,9 @@ void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) {
// which implements NSServicesRequests protocol. // which implements NSServicesRequests protocol.
// //
void RenderWidgetHostViewMac::SelectionChanged(const std::string& text, 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; selected_text_ = text;
[cocoa_view_ setSelectedRange:range.ToNSRange()]; [cocoa_view_ setSelectedRange:range.ToNSRange()];
// Updaes markedRange when there is no marked text so that retrieving // Updaes markedRange when there is no marked text so that retrieving
......
...@@ -87,7 +87,9 @@ RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host) ...@@ -87,7 +87,9 @@ RenderWidgetHostViewViews::RenderWidgetHostViewViews(RenderWidgetHost* host)
visually_deemphasized_(false), visually_deemphasized_(false),
touch_event_(), touch_event_(),
text_input_type_(ui::TEXT_INPUT_TYPE_NONE), 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); set_focusable(true);
host_->SetView(this); host_->SetView(this);
...@@ -304,9 +306,13 @@ void RenderWidgetHostViewViews::SetTooltipText(const std::wstring& tip) { ...@@ -304,9 +306,13 @@ void RenderWidgetHostViewViews::SetTooltipText(const std::wstring& tip) {
} }
void RenderWidgetHostViewViews::SelectionChanged(const std::string& text, 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 // TODO(anicolao): deal with the clipboard without GTK
NOTIMPLEMENTED(); NOTIMPLEMENTED();
if (touch_selection_controller_.get())
touch_selection_controller_->SelectionChanged(start, end);
} }
void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) { void RenderWidgetHostViewViews::ShowingContextMenu(bool showing) {
...@@ -329,6 +335,34 @@ void RenderWidgetHostViewViews::SetVisuallyDeemphasized( ...@@ -329,6 +335,34 @@ void RenderWidgetHostViewViews::SetVisuallyDeemphasized(
// TODO(anicolao) // 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 { std::string RenderWidgetHostViewViews::GetClassName() const {
return kViewClassName; return kViewClassName;
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "views/controls/native/native_view_host.h" #include "views/controls/native/native_view_host.h"
#include "views/events/event.h" #include "views/events/event.h"
#include "views/ime/text_input_client.h" #include "views/ime/text_input_client.h"
#include "views/touchui/touch_selection_controller.h"
#include "views/view.h" #include "views/view.h"
#include "webkit/glue/webcursor.h" #include "webkit/glue/webcursor.h"
...@@ -35,7 +36,7 @@ struct NativeWebKeyboardEvent; ...@@ -35,7 +36,7 @@ struct NativeWebKeyboardEvent;
// See comments in render_widget_host_view.h about this class and its members. // See comments in render_widget_host_view.h about this class and its members.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class RenderWidgetHostViewViews : public RenderWidgetHostView, class RenderWidgetHostViewViews : public RenderWidgetHostView,
public views::View, public views::TouchSelectionClientView,
public views::TextInputClient { public views::TextInputClient {
public: public:
// Internal class name. // Internal class name.
...@@ -79,7 +80,9 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, ...@@ -79,7 +80,9 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
virtual void Destroy() OVERRIDE; virtual void Destroy() OVERRIDE;
virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE; virtual void SetTooltipText(const std::wstring& tooltip_text) OVERRIDE;
virtual void SelectionChanged(const std::string& text, 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 void ShowingContextMenu(bool showing) OVERRIDE;
virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
virtual void SetBackground(const SkBitmap& background) OVERRIDE; virtual void SetBackground(const SkBitmap& background) OVERRIDE;
...@@ -98,6 +101,18 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, ...@@ -98,6 +101,18 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
#endif #endif
virtual gfx::PluginWindowHandle GetCompositingSurface() OVERRIDE; 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. // Overridden from views::View.
virtual std::string GetClassName() const OVERRIDE; virtual std::string GetClassName() const OVERRIDE;
virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE; virtual gfx::NativeCursor GetCursor(const views::MouseEvent& event) OVERRIDE;
...@@ -240,6 +255,8 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView, ...@@ -240,6 +255,8 @@ class RenderWidgetHostViewViews : public RenderWidgetHostView,
string16 tooltip_text_; string16 tooltip_text_;
scoped_ptr<views::TouchSelectionController> touch_selection_controller_;
#if defined(TOUCH_UI) #if defined(TOUCH_UI)
std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerTouch> > std::map<uint64, scoped_refptr<AcceleratedSurfaceContainerTouch> >
accelerated_surface_containers_; accelerated_surface_containers_;
......
...@@ -1002,9 +1002,11 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange( ...@@ -1002,9 +1002,11 @@ void RenderViewHost::OnMsgDidContentsPreferredSizeChange(
} }
void RenderViewHost::OnMsgSelectionChanged(const std::string& text, 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()) if (view())
view()->SelectionChanged(text, range); view()->SelectionChanged(text, range, start, end);
} }
void RenderViewHost::OnMsgRunJavaScriptMessage( void RenderViewHost::OnMsgRunJavaScriptMessage(
......
...@@ -428,7 +428,8 @@ class RenderViewHost : public RenderWidgetHost { ...@@ -428,7 +428,8 @@ class RenderViewHost : public RenderWidgetHost {
void OnMsgOpenURL(const GURL& url, const GURL& referrer, void OnMsgOpenURL(const GURL& url, const GURL& referrer,
WindowOpenDisposition disposition); WindowOpenDisposition disposition);
void OnMsgDidContentsPreferredSizeChange(const gfx::Size& new_size); 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 OnMsgPasteFromSelectionClipboard();
void OnMsgRunJavaScriptMessage(const string16& message, void OnMsgRunJavaScriptMessage(const string16& message,
const string16& default_prompt, const string16& default_prompt,
......
...@@ -179,9 +179,13 @@ class RenderWidgetHostView { ...@@ -179,9 +179,13 @@ class RenderWidgetHostView {
// the page has changed. // the page has changed.
virtual void SetTooltipText(const std::wstring& tooltip_text) = 0; 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, 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 // 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. // to suppress updates to webkit focus for the duration of the show.
......
...@@ -923,6 +923,11 @@ IPC_MESSAGE_ROUTED1(ViewMsg_Replace, ...@@ -923,6 +923,11 @@ IPC_MESSAGE_ROUTED1(ViewMsg_Replace,
IPC_MESSAGE_ROUTED0(ViewMsg_Delete) IPC_MESSAGE_ROUTED0(ViewMsg_Delete)
IPC_MESSAGE_ROUTED0(ViewMsg_SelectAll) 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 // Copies the image at location x, y to the clipboard (if there indeed is an
// image at that location). // image at that location).
IPC_MESSAGE_ROUTED2(ViewMsg_CopyImageAt, IPC_MESSAGE_ROUTED2(ViewMsg_CopyImageAt,
...@@ -1711,9 +1716,11 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_SetTooltipText, ...@@ -1711,9 +1716,11 @@ IPC_MESSAGE_ROUTED2(ViewHostMsg_SetTooltipText,
WebKit::WebTextDirection /* text direction hint */) WebKit::WebTextDirection /* text direction hint */)
// Notification that the text selection has changed. // Notification that the text selection has changed.
IPC_MESSAGE_ROUTED2(ViewHostMsg_SelectionChanged, IPC_MESSAGE_ROUTED4(ViewHostMsg_SelectionChanged,
std::string /* currently selected text */, 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 // Asks the browser to display the file chooser. The result is returned in a
// ViewHost_RunFileChooserResponse message. // ViewHost_RunFileChooserResponse message.
......
...@@ -361,7 +361,8 @@ RenderView::RenderView(RenderThreadBase* render_thread, ...@@ -361,7 +361,8 @@ RenderView::RenderView(RenderThreadBase* render_thread,
accessibility_ack_pending_(false), accessibility_ack_pending_(false),
p2p_socket_dispatcher_(NULL), p2p_socket_dispatcher_(NULL),
devtools_agent_(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; routing_id_ = routing_id;
if (opener_id != MSG_ROUTING_NONE) if (opener_id != MSG_ROUTING_NONE)
opener_id_ = opener_id; opener_id_ = opener_id;
...@@ -614,6 +615,7 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { ...@@ -614,6 +615,7 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
...@@ -979,6 +981,15 @@ void RenderView::OnSelectAll() { ...@@ -979,6 +981,15 @@ void RenderView::OnSelectAll() {
WebString::fromUTF8("SelectAll")); 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) { void RenderView::OnSetInitialFocus(bool reverse) {
if (!webview()) if (!webview())
return; return;
...@@ -1515,8 +1526,9 @@ bool RenderView::isSelectTrailingWhitespaceEnabled() { ...@@ -1515,8 +1526,9 @@ bool RenderView::isSelectTrailingWhitespaceEnabled() {
void RenderView::didChangeSelection(bool is_empty_selection) { void RenderView::didChangeSelection(bool is_empty_selection) {
#if defined(OS_POSIX) #if defined(OS_POSIX)
if (!handling_input_event_) if (!handling_input_event_ && !handling_select_range_)
return; return;
handling_select_range_ = false;
if (is_empty_selection) { if (is_empty_selection) {
last_selection_.clear(); last_selection_.clear();
...@@ -1537,7 +1549,22 @@ void RenderView::didChangeSelection(bool is_empty_selection) { ...@@ -1537,7 +1549,22 @@ void RenderView::didChangeSelection(bool is_empty_selection) {
range.set_start(location); range.set_start(location);
range.set_end(location + length); 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) #endif // defined(OS_POSIX)
} }
......
...@@ -819,6 +819,7 @@ class RenderView : public RenderWidget, ...@@ -819,6 +819,7 @@ class RenderView : public RenderWidget,
int id, int id,
bool notify_result); bool notify_result);
void OnSelectAll(); void OnSelectAll();
void OnSelectRange(const gfx::Point& start, const gfx::Point& end);
void OnSetAccessibilityFocus(int acc_obj_id); void OnSetAccessibilityFocus(int acc_obj_id);
void OnSetActive(bool active); void OnSetActive(bool active);
void OnSetAltErrorPageURL(const GURL& gurl); void OnSetAltErrorPageURL(const GURL& gurl);
...@@ -1197,6 +1198,10 @@ class RenderView : public RenderWidget, ...@@ -1197,6 +1198,10 @@ class RenderView : public RenderWidget,
// is fine. // is fine.
ObserverList<RenderViewObserver> observers_; 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 // 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 // sections rather than throwing it randomly at the end. If you're adding a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment