OLD | NEW |
---|---|
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 Loading... | |
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 selection_ack_pending_(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 Loading... | |
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_SelectRect, OnSelectRect) | |
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 Loading... | |
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::OnSelectRect(const gfx::Point& start, const gfx::Point& end) { | |
darin (slow to review)
2011/08/04 18:15:57
I wonder... since the IPC is called SelectRect, sh
varunjain
2011/08/04 19:25:22
mostly because the selected region may not be a re
| |
984 if (!webview()) | |
985 return; | |
986 | |
987 selection_ack_pending_ = true; | |
988 webview()->focusedFrame()->selectRange(start, end); | |
989 selection_ack_pending_ = 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 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1506 bool RenderView::isSelectTrailingWhitespaceEnabled() { | 1517 bool RenderView::isSelectTrailingWhitespaceEnabled() { |
1507 #if defined(OS_WIN) | 1518 #if defined(OS_WIN) |
1508 return true; | 1519 return true; |
1509 #else | 1520 #else |
1510 return false; | 1521 return false; |
1511 #endif | 1522 #endif |
1512 } | 1523 } |
1513 | 1524 |
1514 void RenderView::didChangeSelection(bool is_empty_selection) { | 1525 void RenderView::didChangeSelection(bool is_empty_selection) { |
1515 #if defined(OS_POSIX) | 1526 #if defined(OS_POSIX) |
1516 if (!handling_input_event_) | 1527 if (!handling_input_event_ && !selection_ack_pending_) |
1517 return; | 1528 return; |
1529 selection_ack_pending_ = false; | |
darin (slow to review)
2011/08/04 18:15:57
this seems like the wrong name for this member var
varunjain
2011/08/04 19:25:22
Done
| |
1518 | 1530 |
1519 if (is_empty_selection) { | 1531 if (is_empty_selection) { |
1520 last_selection_.clear(); | 1532 last_selection_.clear(); |
1521 } else { | 1533 } else { |
1522 // Sometimes we get repeated didChangeSelection calls from webkit when | 1534 // Sometimes we get repeated didChangeSelection calls from webkit when |
1523 // the selection hasn't actually changed. We don't want to report these | 1535 // the selection hasn't actually changed. We don't want to report these |
1524 // because it will cause us to continually claim the X clipboard. | 1536 // because it will cause us to continually claim the X clipboard. |
1525 WebFrame* frame = webview()->focusedFrame(); | 1537 WebFrame* frame = webview()->focusedFrame(); |
1526 const std::string& this_selection = frame->selectionAsText().utf8(); | 1538 const std::string& this_selection = frame->selectionAsText().utf8(); |
1527 if (this_selection == last_selection_) | 1539 if (this_selection == last_selection_) |
1528 return; | 1540 return; |
1529 last_selection_ = this_selection; | 1541 last_selection_ = this_selection; |
1530 } | 1542 } |
1531 | 1543 |
1532 ui::Range range(ui::Range::InvalidRange()); | 1544 ui::Range range(ui::Range::InvalidRange()); |
1533 size_t location, length; | 1545 size_t location, length; |
1534 if (webview()->caretOrSelectionRange(&location, &length)) { | 1546 if (webview()->caretOrSelectionRange(&location, &length)) { |
1535 range.set_start(location); | 1547 range.set_start(location); |
1536 range.set_end(location + length); | 1548 range.set_end(location + length); |
1537 } | 1549 } |
1538 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range)); | 1550 |
1551 WebKit::WebPoint start, end; | |
1552 webview()->selectionRange(start, end); | |
1553 | |
1554 // Webkit gives an offset of 1 between start and end even if there is no | |
1555 // selection. So we need to check against that. | |
1556 // TODO(varunjain): remove this check once that is fixed. | |
darin (slow to review)
2011/08/04 18:15:57
instead of adding this hack here, wouldn't it be b
varunjain
2011/08/04 19:25:22
I need to first check with clang team as they were
| |
1557 gfx::Point p1, p2; | |
1558 if (std::abs(start.x - end.x) > 1 || std::abs(start.y - end.y) > 1) { | |
1559 gfx::Point scroll_offset = GetScrollOffset(); | |
darin (slow to review)
2011/08/04 18:15:57
it seems like you are trying to correct for scroll
varunjain
2011/08/04 19:25:22
selectionRange API may need to be revised. I inten
| |
1560 p1.SetPoint(start.x + scroll_offset.x(), start.y + scroll_offset.y()); | |
1561 p2.SetPoint(end.x + scroll_offset.x(), end.y + scroll_offset.y()); | |
1562 } | |
1563 // TODO(varunjain): add other hooks for SelectionChanged. | |
1564 Send(new ViewHostMsg_SelectionChanged(routing_id_, last_selection_, range, | |
1565 p1, p2)); | |
darin (slow to review)
2011/08/04 18:15:57
nit: please indent "p1, p2));" so that p1 starts a
varunjain
2011/08/04 19:25:22
Done.
| |
1539 #endif // defined(OS_POSIX) | 1566 #endif // defined(OS_POSIX) |
1540 } | 1567 } |
1541 | 1568 |
1542 void RenderView::didExecuteCommand(const WebString& command_name) { | 1569 void RenderView::didExecuteCommand(const WebString& command_name) { |
1543 const std::string& name = UTF16ToUTF8(command_name); | 1570 const std::string& name = UTF16ToUTF8(command_name); |
1544 if (StartsWithASCII(name, "Move", true) || | 1571 if (StartsWithASCII(name, "Move", true) || |
1545 StartsWithASCII(name, "Insert", true) || | 1572 StartsWithASCII(name, "Insert", true) || |
1546 StartsWithASCII(name, "Delete", true)) | 1573 StartsWithASCII(name, "Delete", true)) |
1547 return; | 1574 return; |
1548 RenderThread::current()->Send( | 1575 RenderThread::current()->Send( |
(...skipping 2883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4432 } | 4459 } |
4433 #endif | 4460 #endif |
4434 | 4461 |
4435 void RenderView::OnContextMenuClosed( | 4462 void RenderView::OnContextMenuClosed( |
4436 const webkit_glue::CustomContextMenuContext& custom_context) { | 4463 const webkit_glue::CustomContextMenuContext& custom_context) { |
4437 if (custom_context.is_pepper_menu) | 4464 if (custom_context.is_pepper_menu) |
4438 pepper_delegate_.OnContextMenuClosed(custom_context); | 4465 pepper_delegate_.OnContextMenuClosed(custom_context); |
4439 else | 4466 else |
4440 context_menu_node_.reset(); | 4467 context_menu_node_.reset(); |
4441 } | 4468 } |
OLD | NEW |