Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: content/renderer/render_frame_impl.cc

Issue 1205033005: Adds selection expansion support for Contextual Search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed java tests Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/render_frame_impl.cc
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 7005fdd66b83c004a1b45dac7c53f7973f5d4082..16c575a1098eb3fc3b622a1daafc285df21f148e 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -1013,6 +1013,8 @@ bool RenderFrameImpl::OnMessageReceived(const IPC::Message& msg) {
IPC_MESSAGE_HANDLER(InputMsg_Delete, OnDelete)
IPC_MESSAGE_HANDLER(InputMsg_SelectAll, OnSelectAll)
IPC_MESSAGE_HANDLER(InputMsg_SelectRange, OnSelectRange)
+ IPC_MESSAGE_HANDLER(InputMsg_AdjustSelectionByCharacterOffset,
+ OnAdjustSelectionByCharacterOffset)
IPC_MESSAGE_HANDLER(InputMsg_Unselect, OnUnselect)
IPC_MESSAGE_HANDLER(InputMsg_MoveRangeSelectionExtent,
OnMoveRangeSelectionExtent)
@@ -1326,6 +1328,29 @@ void RenderFrameImpl::OnSelectRange(const gfx::Point& base,
frame_->selectRange(base, extent);
}
+void RenderFrameImpl::OnAdjustSelectionByCharacterOffset(int start_adjust,
+ int end_adjust) {
+ size_t start, length;
+ if (!GetRenderWidget()->webwidget()->caretOrSelectionRange(
+ &start, &length)) {
+ return;
+ }
+
+ // Sanity checks to disallow empty and out of range selections.
+ if (start_adjust - end_adjust > static_cast<int>(length)
+ || static_cast<int>(start) + start_adjust < 0) {
+ return;
+ }
+
+ // A negative adjust amount moves the selection towards the beginning of
+ // the document, a positive amount moves the selection towards the end of
+ // the document.
+ start += start_adjust;
+ length += end_adjust - start_adjust;
+
+ frame_->selectRange(WebRange::fromDocumentRange(frame_, start, length));
+}
+
void RenderFrameImpl::OnUnselect() {
base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
frame_->executeCommand(WebString::fromUTF8("Unselect"), GetFocusedElement());
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698