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

Side by Side Diff: content/renderer/render_view.cc

Issue 7570001: Implement touch selection for RWHVV. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: synced and modified according to comments Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/render_view.h" 5 #include "content/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 target_url_status_(TARGET_NONE), 353 target_url_status_(TARGET_NONE),
354 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), 354 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
355 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), 355 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
356 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), 356 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
357 geolocation_dispatcher_(NULL), 357 geolocation_dispatcher_(NULL),
358 speech_input_dispatcher_(NULL), 358 speech_input_dispatcher_(NULL),
359 device_orientation_dispatcher_(NULL), 359 device_orientation_dispatcher_(NULL),
360 accessibility_ack_pending_(false), 360 accessibility_ack_pending_(false),
361 p2p_socket_dispatcher_(NULL), 361 p2p_socket_dispatcher_(NULL),
362 devtools_agent_(NULL), 362 devtools_agent_(NULL),
363 session_storage_namespace_id_(session_storage_namespace_id) { 363 session_storage_namespace_id_(session_storage_namespace_id),
364 handling_select_rect_(false) {
364 routing_id_ = routing_id; 365 routing_id_ = routing_id;
365 if (opener_id != MSG_ROUTING_NONE) 366 if (opener_id != MSG_ROUTING_NONE)
366 opener_id_ = opener_id; 367 opener_id_ = opener_id;
367 368
368 webwidget_ = WebView::create(this); 369 webwidget_ = WebView::create(this);
369 370
370 if (counter) { 371 if (counter) {
371 shared_popup_counter_ = counter; 372 shared_popup_counter_ = counter;
372 shared_popup_counter_->data++; 373 shared_popup_counter_->data++;
373 decrement_shared_popup_at_destruction_ = true; 374 decrement_shared_popup_at_destruction_ = true;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) 607 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
607 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) 608 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
608 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) 609 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
609 #if defined(OS_MACOSX) 610 #if defined(OS_MACOSX)
610 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) 611 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
611 #endif 612 #endif
612 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) 613 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
613 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) 614 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
614 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) 615 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
615 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) 616 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
617 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
616 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) 618 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
617 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) 619 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
618 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) 620 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
619 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 621 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
620 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) 622 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
621 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 623 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
622 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) 624 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
623 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, 625 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
624 OnSetZoomLevelForLoadingURL) 626 OnSetZoomLevelForLoadingURL)
625 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 627 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 973 }
972 974
973 void RenderView::OnSelectAll() { 975 void RenderView::OnSelectAll() {
974 if (!webview()) 976 if (!webview())
975 return; 977 return;
976 978
977 webview()->focusedFrame()->executeCommand( 979 webview()->focusedFrame()->executeCommand(
978 WebString::fromUTF8("SelectAll")); 980 WebString::fromUTF8("SelectAll"));
979 } 981 }
980 982
983 void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
984 if (!webview())
985 return;
986
987 handling_select_rect_ = true;
988 webview()->focusedFrame()->selectRange(start, end);
989 handling_select_rect_ = false;
990 }
991
981 void RenderView::OnSetInitialFocus(bool reverse) { 992 void RenderView::OnSetInitialFocus(bool reverse) {
982 if (!webview()) 993 if (!webview())
983 return; 994 return;
984 webview()->setInitialFocus(reverse); 995 webview()->setInitialFocus(reverse);
985 } 996 }
986 997
987 #if defined(OS_MACOSX) 998 #if defined(OS_MACOSX)
988 void RenderView::OnSetInLiveResize(bool in_live_resize) { 999 void RenderView::OnSetInLiveResize(bool in_live_resize) {
989 if (!webview()) 1000 if (!webview())
990 return; 1001 return;
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 bool RenderView::isSelectTrailingWhitespaceEnabled() { 1518 bool RenderView::isSelectTrailingWhitespaceEnabled() {
1508 #if defined(OS_WIN) 1519 #if defined(OS_WIN)
1509 return true; 1520 return true;
1510 #else 1521 #else
1511 return false; 1522 return false;
1512 #endif 1523 #endif
1513 } 1524 }
1514 1525
1515 void RenderView::didChangeSelection(bool is_empty_selection) { 1526 void RenderView::didChangeSelection(bool is_empty_selection) {
1516 #if defined(OS_POSIX) 1527 #if defined(OS_POSIX)
1517 if (!handling_input_event_) 1528 if (!handling_input_event_ && !handling_select_rect_)
1518 return; 1529 return;
1530 handling_select_rect_ = false;
1519 1531
1520 if (is_empty_selection) { 1532 if (is_empty_selection) {
1521 last_selection_.clear(); 1533 last_selection_.clear();
1522 } else { 1534 } else {
1523 // Sometimes we get repeated didChangeSelection calls from webkit when 1535 // Sometimes we get repeated didChangeSelection calls from webkit when
1524 // the selection hasn't actually changed. We don't want to report these 1536 // the selection hasn't actually changed. We don't want to report these
1525 // because it will cause us to continually claim the X clipboard. 1537 // because it will cause us to continually claim the X clipboard.
1526 WebFrame* frame = webview()->focusedFrame(); 1538 WebFrame* frame = webview()->focusedFrame();
1527 const std::string& this_selection = frame->selectionAsText().utf8(); 1539 const std::string& this_selection = frame->selectionAsText().utf8();
1528 if (this_selection == last_selection_) 1540 if (this_selection == last_selection_)
1529 return; 1541 return;
1530 last_selection_ = this_selection; 1542 last_selection_ = this_selection;
1531 } 1543 }
1532 1544
1533 ui::Range range(ui::Range::InvalidRange()); 1545 ui::Range range(ui::Range::InvalidRange());
1534 size_t location, length; 1546 size_t location, length;
1535 if (webview()->caretOrSelectionRange(&location, &length)) { 1547 if (webview()->caretOrSelectionRange(&location, &length)) {
1536 range.set_start(location); 1548 range.set_start(location);
1537 range.set_end(location + length); 1549 range.set_end(location + length);
1538 } 1550 }
1539 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range)); 1551
1552 WebKit::WebPoint start, end;
1553 webview()->selectionRange(start, end);
1554
1555 // Webkit gives an offset of 1 between start and end even if there is no
1556 // selection. So we need to check against that.
1557 // TODO(varunjain): remove this check once that is fixed.
1558 gfx::Point p1, p2;
1559 if (std::abs(start.x - end.x) > 1 || std::abs(start.y - end.y) > 1) {
1560 gfx::Point scroll_offset = GetScrollOffset();
1561 p1.SetPoint(start.x + scroll_offset.x(), start.y + scroll_offset.y());
1562 p2.SetPoint(end.x + scroll_offset.x(), end.y + scroll_offset.y());
1563 }
1564 // TODO(varunjain): add other hooks for SelectionChanged.
darin (slow to review) 2011/08/05 03:51:16 nit: this comment is quite tantalizing and leaves
varunjain 2011/08/05 15:57:30 by other hooks, I meant make selection handles wor
1565 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range,
1566 p1, p2));
1540 #endif // defined(OS_POSIX) 1567 #endif // defined(OS_POSIX)
1541 } 1568 }
1542 1569
1543 void RenderView::didExecuteCommand(const WebString& command_name) { 1570 void RenderView::didExecuteCommand(const WebString& command_name) {
1544 const std::string& name = UTF16ToUTF8(command_name); 1571 const std::string& name = UTF16ToUTF8(command_name);
1545 if (StartsWithASCII(name, "Move", true) || 1572 if (StartsWithASCII(name, "Move", true) ||
1546 StartsWithASCII(name, "Insert", true) || 1573 StartsWithASCII(name, "Insert", true) ||
1547 StartsWithASCII(name, "Delete", true)) 1574 StartsWithASCII(name, "Delete", true))
1548 return; 1575 return;
1549 RenderThread::current()->Send( 1576 RenderThread::current()->Send(
(...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after
4433 } 4460 }
4434 #endif 4461 #endif
4435 4462
4436 void RenderView::OnContextMenuClosed( 4463 void RenderView::OnContextMenuClosed(
4437 const webkit_glue::CustomContextMenuContext& custom_context) { 4464 const webkit_glue::CustomContextMenuContext& custom_context) {
4438 if (custom_context.is_pepper_menu) 4465 if (custom_context.is_pepper_menu)
4439 pepper_delegate_.OnContextMenuClosed(custom_context); 4466 pepper_delegate_.OnContextMenuClosed(custom_context);
4440 else 4467 else
4441 context_menu_node_.reset(); 4468 context_menu_node_.reset();
4442 } 4469 }
OLDNEW
« content/renderer/render_view.h ('K') | « content/renderer/render_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698