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

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

Issue 7528009: This is the exact same CL as in http://codereview.chromium.org/7570001 . (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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
« no previous file with comments | « content/renderer/render_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 target_url_status_(TARGET_NONE), 354 target_url_status_(TARGET_NONE),
355 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), 355 ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)),
356 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)), 356 ALLOW_THIS_IN_INITIALIZER_LIST(accessibility_method_factory_(this)),
357 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)), 357 ALLOW_THIS_IN_INITIALIZER_LIST(cookie_jar_(this)),
358 geolocation_dispatcher_(NULL), 358 geolocation_dispatcher_(NULL),
359 speech_input_dispatcher_(NULL), 359 speech_input_dispatcher_(NULL),
360 device_orientation_dispatcher_(NULL), 360 device_orientation_dispatcher_(NULL),
361 accessibility_ack_pending_(false), 361 accessibility_ack_pending_(false),
362 p2p_socket_dispatcher_(NULL), 362 p2p_socket_dispatcher_(NULL),
363 devtools_agent_(NULL), 363 devtools_agent_(NULL),
364 session_storage_namespace_id_(session_storage_namespace_id) { 364 session_storage_namespace_id_(session_storage_namespace_id),
365 handling_select_range_(false) {
365 routing_id_ = routing_id; 366 routing_id_ = routing_id;
366 if (opener_id != MSG_ROUTING_NONE) 367 if (opener_id != MSG_ROUTING_NONE)
367 opener_id_ = opener_id; 368 opener_id_ = opener_id;
368 369
369 webwidget_ = WebView::create(this); 370 webwidget_ = WebView::create(this);
370 371
371 if (counter) { 372 if (counter) {
372 shared_popup_counter_ = counter; 373 shared_popup_counter_ = counter;
373 shared_popup_counter_->data++; 374 shared_popup_counter_->data++;
374 decrement_shared_popup_at_destruction_ = true; 375 decrement_shared_popup_at_destruction_ = true;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo) 608 IPC_MESSAGE_HANDLER(ViewMsg_Redo, OnRedo)
608 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut) 609 IPC_MESSAGE_HANDLER(ViewMsg_Cut, OnCut)
609 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy) 610 IPC_MESSAGE_HANDLER(ViewMsg_Copy, OnCopy)
610 #if defined(OS_MACOSX) 611 #if defined(OS_MACOSX)
611 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard) 612 IPC_MESSAGE_HANDLER(ViewMsg_CopyToFindPboard, OnCopyToFindPboard)
612 #endif 613 #endif
613 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste) 614 IPC_MESSAGE_HANDLER(ViewMsg_Paste, OnPaste)
614 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace) 615 IPC_MESSAGE_HANDLER(ViewMsg_Replace, OnReplace)
615 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete) 616 IPC_MESSAGE_HANDLER(ViewMsg_Delete, OnDelete)
616 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll) 617 IPC_MESSAGE_HANDLER(ViewMsg_SelectAll, OnSelectAll)
618 IPC_MESSAGE_HANDLER(ViewMsg_SelectRange, OnSelectRange)
617 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt) 619 IPC_MESSAGE_HANDLER(ViewMsg_CopyImageAt, OnCopyImageAt)
618 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand) 620 IPC_MESSAGE_HANDLER(ViewMsg_ExecuteEditCommand, OnExecuteEditCommand)
619 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind) 621 IPC_MESSAGE_HANDLER(ViewMsg_Find, OnFind)
620 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding) 622 IPC_MESSAGE_HANDLER(ViewMsg_StopFinding, OnStopFinding)
621 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck) 623 IPC_MESSAGE_HANDLER(ViewMsg_FindReplyACK, OnFindReplyAck)
622 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom) 624 IPC_MESSAGE_HANDLER(ViewMsg_Zoom, OnZoom)
623 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel) 625 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevel, OnSetZoomLevel)
624 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL, 626 IPC_MESSAGE_HANDLER(ViewMsg_SetZoomLevelForLoadingURL,
625 OnSetZoomLevelForLoadingURL) 627 OnSetZoomLevelForLoadingURL)
626 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding) 628 IPC_MESSAGE_HANDLER(ViewMsg_SetPageEncoding, OnSetPageEncoding)
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 } 974 }
973 975
974 void RenderView::OnSelectAll() { 976 void RenderView::OnSelectAll() {
975 if (!webview()) 977 if (!webview())
976 return; 978 return;
977 979
978 webview()->focusedFrame()->executeCommand( 980 webview()->focusedFrame()->executeCommand(
979 WebString::fromUTF8("SelectAll")); 981 WebString::fromUTF8("SelectAll"));
980 } 982 }
981 983
984 void RenderView::OnSelectRange(const gfx::Point& start, const gfx::Point& end) {
985 if (!webview())
986 return;
987
988 handling_select_range_ = true;
989 webview()->focusedFrame()->selectRange(start, end);
990 handling_select_range_ = false;
991 }
992
982 void RenderView::OnSetInitialFocus(bool reverse) { 993 void RenderView::OnSetInitialFocus(bool reverse) {
983 if (!webview()) 994 if (!webview())
984 return; 995 return;
985 webview()->setInitialFocus(reverse); 996 webview()->setInitialFocus(reverse);
986 } 997 }
987 998
988 #if defined(OS_MACOSX) 999 #if defined(OS_MACOSX)
989 void RenderView::OnSetInLiveResize(bool in_live_resize) { 1000 void RenderView::OnSetInLiveResize(bool in_live_resize) {
990 if (!webview()) 1001 if (!webview())
991 return; 1002 return;
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 bool RenderView::isSelectTrailingWhitespaceEnabled() { 1519 bool RenderView::isSelectTrailingWhitespaceEnabled() {
1509 #if defined(OS_WIN) 1520 #if defined(OS_WIN)
1510 return true; 1521 return true;
1511 #else 1522 #else
1512 return false; 1523 return false;
1513 #endif 1524 #endif
1514 } 1525 }
1515 1526
1516 void RenderView::didChangeSelection(bool is_empty_selection) { 1527 void RenderView::didChangeSelection(bool is_empty_selection) {
1517 #if defined(OS_POSIX) 1528 #if defined(OS_POSIX)
1518 if (!handling_input_event_) 1529 if (!handling_input_event_ && !handling_select_range_)
1519 return; 1530 return;
1531 handling_select_range_ = false;
1520 1532
1521 if (is_empty_selection) { 1533 if (is_empty_selection) {
1522 last_selection_.clear(); 1534 last_selection_.clear();
1523 } else { 1535 } else {
1524 // Sometimes we get repeated didChangeSelection calls from webkit when 1536 // Sometimes we get repeated didChangeSelection calls from webkit when
1525 // the selection hasn't actually changed. We don't want to report these 1537 // the selection hasn't actually changed. We don't want to report these
1526 // because it will cause us to continually claim the X clipboard. 1538 // because it will cause us to continually claim the X clipboard.
1527 WebFrame* frame = webview()->focusedFrame(); 1539 WebFrame* frame = webview()->focusedFrame();
1528 const std::string& this_selection = frame->selectionAsText().utf8(); 1540 const std::string& this_selection = frame->selectionAsText().utf8();
1529 if (this_selection == last_selection_) 1541 if (this_selection == last_selection_)
1530 return; 1542 return;
1531 last_selection_ = this_selection; 1543 last_selection_ = this_selection;
1532 } 1544 }
1533 1545
1534 ui::Range range(ui::Range::InvalidRange()); 1546 ui::Range range(ui::Range::InvalidRange());
1535 size_t location, length; 1547 size_t location, length;
1536 if (webview()->caretOrSelectionRange(&location, &length)) { 1548 if (webview()->caretOrSelectionRange(&location, &length)) {
1537 range.set_start(location); 1549 range.set_start(location);
1538 range.set_end(location + length); 1550 range.set_end(location + length);
1539 } 1551 }
1540 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range)); 1552
1553 WebKit::WebPoint start, end;
1554 webview()->selectionRange(start, end);
1555
1556 // Webkit gives an offset of 1 between start and end even if there is no
1557 // selection. So we need to check against that.
1558 // TODO(varunjain): remove this check once that is fixed.
1559 gfx::Point p1, p2;
1560 if (std::abs(start.x - end.x) > 1 || std::abs(start.y - end.y) > 1) {
1561 gfx::Point scroll_offset = GetScrollOffset();
1562 p1.SetPoint(start.x + scroll_offset.x(), start.y + scroll_offset.y());
1563 p2.SetPoint(end.x + scroll_offset.x(), end.y + scroll_offset.y());
1564 }
1565 // TODO(varunjain): add other hooks for SelectionChanged.
1566 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range,
1567 p1, p2));
1541 #endif // defined(OS_POSIX) 1568 #endif // defined(OS_POSIX)
1542 } 1569 }
1543 1570
1544 void RenderView::didExecuteCommand(const WebString& command_name) { 1571 void RenderView::didExecuteCommand(const WebString& command_name) {
1545 const std::string& name = UTF16ToUTF8(command_name); 1572 const std::string& name = UTF16ToUTF8(command_name);
1546 if (StartsWithASCII(name, "Move", true) || 1573 if (StartsWithASCII(name, "Move", true) ||
1547 StartsWithASCII(name, "Insert", true) || 1574 StartsWithASCII(name, "Insert", true) ||
1548 StartsWithASCII(name, "Delete", true)) 1575 StartsWithASCII(name, "Delete", true))
1549 return; 1576 return;
1550 RenderThread::current()->Send( 1577 RenderThread::current()->Send(
(...skipping 2884 matching lines...) Expand 10 before | Expand all | Expand 10 after
4435 } 4462 }
4436 #endif 4463 #endif
4437 4464
4438 void RenderView::OnContextMenuClosed( 4465 void RenderView::OnContextMenuClosed(
4439 const webkit_glue::CustomContextMenuContext& custom_context) { 4466 const webkit_glue::CustomContextMenuContext& custom_context) {
4440 if (custom_context.is_pepper_menu) 4467 if (custom_context.is_pepper_menu)
4441 pepper_delegate_.OnContextMenuClosed(custom_context); 4468 pepper_delegate_.OnContextMenuClosed(custom_context);
4442 else 4469 else
4443 context_menu_node_.reset(); 4470 context_menu_node_.reset();
4444 } 4471 }
OLDNEW
« no previous file with comments | « content/renderer/render_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698