| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 1677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 pending_context_menus_.Lookup(custom_context.request_id); | 1688 pending_context_menus_.Lookup(custom_context.request_id); |
| 1689 if (client) | 1689 if (client) |
| 1690 client->OnMenuAction(custom_context.request_id, action); | 1690 client->OnMenuAction(custom_context.request_id, action); |
| 1691 } else { | 1691 } else { |
| 1692 // Internal request, forward to WebKit. | 1692 // Internal request, forward to WebKit. |
| 1693 render_view_->webview()->performCustomContextMenuAction(action); | 1693 render_view_->webview()->performCustomContextMenuAction(action); |
| 1694 } | 1694 } |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 void RenderFrameImpl::OnUndo() { | 1697 void RenderFrameImpl::OnUndo() { |
| 1698 frame_->executeCommand(WebString::fromUTF8("Undo"), GetFocusedElement()); | 1698 frame_->executeCommand(WebString::fromUTF8("Undo")); |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 void RenderFrameImpl::OnRedo() { | 1701 void RenderFrameImpl::OnRedo() { |
| 1702 frame_->executeCommand(WebString::fromUTF8("Redo"), GetFocusedElement()); | 1702 frame_->executeCommand(WebString::fromUTF8("Redo")); |
| 1703 } | 1703 } |
| 1704 | 1704 |
| 1705 void RenderFrameImpl::OnCut() { | 1705 void RenderFrameImpl::OnCut() { |
| 1706 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1706 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1707 frame_->executeCommand(WebString::fromUTF8("Cut"), GetFocusedElement()); | 1707 frame_->executeCommand(WebString::fromUTF8("Cut")); |
| 1708 } | 1708 } |
| 1709 | 1709 |
| 1710 void RenderFrameImpl::OnCopy() { | 1710 void RenderFrameImpl::OnCopy() { |
| 1711 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1711 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1712 WebNode current_node = frame_->contextMenuNode(); | 1712 frame_->executeCommand(WebString::fromUTF8("Copy")); |
| 1713 frame_->executeCommand(WebString::fromUTF8("Copy"), current_node.isNull() | |
| 1714 ? GetFocusedElement() | |
| 1715 : current_node); | |
| 1716 } | 1713 } |
| 1717 | 1714 |
| 1718 void RenderFrameImpl::OnPaste() { | 1715 void RenderFrameImpl::OnPaste() { |
| 1719 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1716 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1720 base::AutoReset<bool> handling_paste(&is_pasting_, true); | 1717 base::AutoReset<bool> handling_paste(&is_pasting_, true); |
| 1721 frame_->executeCommand(WebString::fromUTF8("Paste"), GetFocusedElement()); | 1718 frame_->executeCommand(WebString::fromUTF8("Paste")); |
| 1722 } | 1719 } |
| 1723 | 1720 |
| 1724 void RenderFrameImpl::OnPasteAndMatchStyle() { | 1721 void RenderFrameImpl::OnPasteAndMatchStyle() { |
| 1725 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1722 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1726 frame_->executeCommand( | 1723 frame_->executeCommand(WebString::fromUTF8("PasteAndMatchStyle")); |
| 1727 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedElement()); | |
| 1728 } | 1724 } |
| 1729 | 1725 |
| 1730 #if defined(OS_MACOSX) | 1726 #if defined(OS_MACOSX) |
| 1731 void RenderFrameImpl::OnCopyToFindPboard() { | 1727 void RenderFrameImpl::OnCopyToFindPboard() { |
| 1732 // Since the find pasteboard supports only plain text, this can be simpler | 1728 // Since the find pasteboard supports only plain text, this can be simpler |
| 1733 // than the |OnCopy()| case. | 1729 // than the |OnCopy()| case. |
| 1734 if (frame_->hasSelection()) { | 1730 if (frame_->hasSelection()) { |
| 1735 base::string16 selection = frame_->selectionAsText(); | 1731 base::string16 selection = frame_->selectionAsText(); |
| 1736 RenderThread::Get()->Send( | 1732 RenderThread::Get()->Send( |
| 1737 new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); | 1733 new ClipboardHostMsg_FindPboardWriteStringAsync(selection)); |
| 1738 } | 1734 } |
| 1739 } | 1735 } |
| 1740 #endif | 1736 #endif |
| 1741 | 1737 |
| 1742 void RenderFrameImpl::OnDelete() { | 1738 void RenderFrameImpl::OnDelete() { |
| 1743 frame_->executeCommand(WebString::fromUTF8("Delete"), GetFocusedElement()); | 1739 frame_->executeCommand(WebString::fromUTF8("Delete")); |
| 1744 } | 1740 } |
| 1745 | 1741 |
| 1746 void RenderFrameImpl::OnSelectAll() { | 1742 void RenderFrameImpl::OnSelectAll() { |
| 1747 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1743 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1748 frame_->executeCommand(WebString::fromUTF8("SelectAll"), GetFocusedElement()); | 1744 frame_->executeCommand(WebString::fromUTF8("SelectAll")); |
| 1749 } | 1745 } |
| 1750 | 1746 |
| 1751 void RenderFrameImpl::OnSelectRange(const gfx::Point& base, | 1747 void RenderFrameImpl::OnSelectRange(const gfx::Point& base, |
| 1752 const gfx::Point& extent) { | 1748 const gfx::Point& extent) { |
| 1753 // This IPC is dispatched by RenderWidgetHost, so use its routing id. | 1749 // This IPC is dispatched by RenderWidgetHost, so use its routing id. |
| 1754 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id())); | 1750 Send(new InputHostMsg_SelectRange_ACK(GetRenderWidget()->routing_id())); |
| 1755 | 1751 |
| 1756 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1752 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1757 frame_->selectRange(render_view_->ConvertWindowPointToViewport(base), | 1753 frame_->selectRange(render_view_->ConvertWindowPointToViewport(base), |
| 1758 render_view_->ConvertWindowPointToViewport(extent)); | 1754 render_view_->ConvertWindowPointToViewport(extent)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1777 // the document. | 1773 // the document. |
| 1778 start += start_adjust; | 1774 start += start_adjust; |
| 1779 length += end_adjust - start_adjust; | 1775 length += end_adjust - start_adjust; |
| 1780 | 1776 |
| 1781 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1777 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1782 frame_->selectRange(WebRange::fromDocumentRange(frame_, start, length)); | 1778 frame_->selectRange(WebRange::fromDocumentRange(frame_, start, length)); |
| 1783 } | 1779 } |
| 1784 | 1780 |
| 1785 void RenderFrameImpl::OnUnselect() { | 1781 void RenderFrameImpl::OnUnselect() { |
| 1786 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1782 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1787 frame_->executeCommand(WebString::fromUTF8("Unselect"), GetFocusedElement()); | 1783 frame_->executeCommand(WebString::fromUTF8("Unselect")); |
| 1788 } | 1784 } |
| 1789 | 1785 |
| 1790 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { | 1786 void RenderFrameImpl::OnMoveRangeSelectionExtent(const gfx::Point& point) { |
| 1791 // This IPC is dispatched by RenderWidgetHost, so use its routing id. | 1787 // This IPC is dispatched by RenderWidgetHost, so use its routing id. |
| 1792 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( | 1788 Send(new InputHostMsg_MoveRangeSelectionExtent_ACK( |
| 1793 GetRenderWidget()->routing_id())); | 1789 GetRenderWidget()->routing_id())); |
| 1794 | 1790 |
| 1795 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); | 1791 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); |
| 1796 frame_->moveRangeSelectionExtent( | 1792 frame_->moveRangeSelectionExtent( |
| 1797 render_view_->ConvertWindowPointToViewport(point)); | 1793 render_view_->ConvertWindowPointToViewport(point)); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 void RenderFrameImpl::OnSetCompositionFromExistingText( | 1966 void RenderFrameImpl::OnSetCompositionFromExistingText( |
| 1971 int start, int end, | 1967 int start, int end, |
| 1972 const std::vector<blink::WebCompositionUnderline>& underlines) { | 1968 const std::vector<blink::WebCompositionUnderline>& underlines) { |
| 1973 if (!GetRenderWidget()->ShouldHandleImeEvent()) | 1969 if (!GetRenderWidget()->ShouldHandleImeEvent()) |
| 1974 return; | 1970 return; |
| 1975 ImeEventGuard guard(GetRenderWidget()); | 1971 ImeEventGuard guard(GetRenderWidget()); |
| 1976 frame_->setCompositionFromExistingText(start, end, underlines); | 1972 frame_->setCompositionFromExistingText(start, end, underlines); |
| 1977 } | 1973 } |
| 1978 | 1974 |
| 1979 void RenderFrameImpl::OnExecuteNoValueEditCommand(const std::string& name) { | 1975 void RenderFrameImpl::OnExecuteNoValueEditCommand(const std::string& name) { |
| 1980 frame_->executeCommand(WebString::fromUTF8(name), GetFocusedElement()); | 1976 frame_->executeCommand(WebString::fromUTF8(name)); |
| 1981 } | 1977 } |
| 1982 | 1978 |
| 1983 void RenderFrameImpl::OnExtendSelectionAndDelete(int before, int after) { | 1979 void RenderFrameImpl::OnExtendSelectionAndDelete(int before, int after) { |
| 1984 if (!GetRenderWidget()->ShouldHandleImeEvent()) | 1980 if (!GetRenderWidget()->ShouldHandleImeEvent()) |
| 1985 return; | 1981 return; |
| 1986 | 1982 |
| 1987 ImeEventGuard guard(GetRenderWidget()); | 1983 ImeEventGuard guard(GetRenderWidget()); |
| 1988 frame_->extendSelectionAndDelete(before, after); | 1984 frame_->extendSelectionAndDelete(before, after); |
| 1989 } | 1985 } |
| 1990 | 1986 |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2233 | 2229 |
| 2234 int RenderFrameImpl::GetRoutingID() { | 2230 int RenderFrameImpl::GetRoutingID() { |
| 2235 return routing_id_; | 2231 return routing_id_; |
| 2236 } | 2232 } |
| 2237 | 2233 |
| 2238 blink::WebLocalFrame* RenderFrameImpl::GetWebFrame() { | 2234 blink::WebLocalFrame* RenderFrameImpl::GetWebFrame() { |
| 2239 DCHECK(frame_); | 2235 DCHECK(frame_); |
| 2240 return frame_; | 2236 return frame_; |
| 2241 } | 2237 } |
| 2242 | 2238 |
| 2243 WebElement RenderFrameImpl::GetFocusedElement() const { | |
| 2244 WebDocument doc = frame_->document(); | |
| 2245 if (!doc.isNull()) | |
| 2246 return doc.focusedElement(); | |
| 2247 | |
| 2248 return WebElement(); | |
| 2249 } | |
| 2250 | |
| 2251 WebPreferences& RenderFrameImpl::GetWebkitPreferences() { | 2239 WebPreferences& RenderFrameImpl::GetWebkitPreferences() { |
| 2252 return render_view_->GetWebkitPreferences(); | 2240 return render_view_->GetWebkitPreferences(); |
| 2253 } | 2241 } |
| 2254 | 2242 |
| 2255 int RenderFrameImpl::ShowContextMenu(ContextMenuClient* client, | 2243 int RenderFrameImpl::ShowContextMenu(ContextMenuClient* client, |
| 2256 const ContextMenuParams& params) { | 2244 const ContextMenuParams& params) { |
| 2257 DCHECK(client); // A null client means "internal" when we issue callbacks. | 2245 DCHECK(client); // A null client means "internal" when we issue callbacks. |
| 2258 ContextMenuParams our_params(params); | 2246 ContextMenuParams our_params(params); |
| 2259 | 2247 |
| 2260 blink::WebRect position_in_window(params.x, params.y, 0, 0); | 2248 blink::WebRect position_in_window(params.x, params.y, 0, 0); |
| (...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5038 // increment the current match ordinal; we need to re-generate it. | 5026 // increment the current match ordinal; we need to re-generate it. |
| 5039 WebRange current_selection = focused_frame->selectionRange(); | 5027 WebRange current_selection = focused_frame->selectionRange(); |
| 5040 | 5028 |
| 5041 do { | 5029 do { |
| 5042 result = | 5030 result = |
| 5043 search_frame->find(request_id, search_text, options, wrap_within_frame, | 5031 search_frame->find(request_id, search_text, options, wrap_within_frame, |
| 5044 &selection_rect, &active_now); | 5032 &selection_rect, &active_now); |
| 5045 | 5033 |
| 5046 if (!result) { | 5034 if (!result) { |
| 5047 // Don't leave text selected as you move to the next frame. | 5035 // Don't leave text selected as you move to the next frame. |
| 5048 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5036 search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
| 5049 GetFocusedElement()); | |
| 5050 | 5037 |
| 5051 // Find the next frame, but skip the invisible ones. | 5038 // Find the next frame, but skip the invisible ones. |
| 5052 do { | 5039 do { |
| 5053 // What is the next frame to search (we might be going backwards)? Note | 5040 // What is the next frame to search (we might be going backwards)? Note |
| 5054 // that we specify wrap=true so that search_frame never becomes NULL. | 5041 // that we specify wrap=true so that search_frame never becomes NULL. |
| 5055 search_frame = options.forward | 5042 search_frame = options.forward |
| 5056 ? search_frame->traverseNextLocal(true) | 5043 ? search_frame->traverseNextLocal(true) |
| 5057 : search_frame->traversePreviousLocal(true); | 5044 : search_frame->traversePreviousLocal(true); |
| 5058 } while (!search_frame->hasVisibleContent() && | 5045 } while (!search_frame->hasVisibleContent() && |
| 5059 search_frame != focused_frame); | 5046 search_frame != focused_frame); |
| 5060 | 5047 |
| 5061 // Make sure selection doesn't affect the search operation in new frame. | 5048 // Make sure selection doesn't affect the search operation in new frame. |
| 5062 search_frame->executeCommand(WebString::fromUTF8("Unselect"), | 5049 search_frame->executeCommand(WebString::fromUTF8("Unselect")); |
| 5063 GetFocusedElement()); | |
| 5064 | 5050 |
| 5065 // If we have multiple frames and we have wrapped back around to the | 5051 // If we have multiple frames and we have wrapped back around to the |
| 5066 // focused frame, we need to search it once more allowing wrap within | 5052 // focused frame, we need to search it once more allowing wrap within |
| 5067 // the frame, otherwise it will report 'no match' if the focused frame has | 5053 // the frame, otherwise it will report 'no match' if the focused frame has |
| 5068 // reported matches, but no frames after the focused_frame contain a | 5054 // reported matches, but no frames after the focused_frame contain a |
| 5069 // match for the search word(s). | 5055 // match for the search word(s). |
| 5070 if (multi_frame && search_frame == focused_frame) { | 5056 if (multi_frame && search_frame == focused_frame) { |
| 5071 result = search_frame->find(request_id, search_text, options, | 5057 result = search_frame->find(request_id, search_text, options, |
| 5072 true, // Force wrapping. | 5058 true, // Force wrapping. |
| 5073 &selection_rect, &active_now); | 5059 &selection_rect, &active_now); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5132 return; | 5118 return; |
| 5133 | 5119 |
| 5134 blink::WebPlugin* plugin = GetWebPluginForFind(); | 5120 blink::WebPlugin* plugin = GetWebPluginForFind(); |
| 5135 if (plugin) { | 5121 if (plugin) { |
| 5136 plugin->stopFind(); | 5122 plugin->stopFind(); |
| 5137 return; | 5123 return; |
| 5138 } | 5124 } |
| 5139 | 5125 |
| 5140 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; | 5126 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; |
| 5141 if (clear_selection) { | 5127 if (clear_selection) { |
| 5142 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), | 5128 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect")); |
| 5143 GetFocusedElement()); | |
| 5144 } | 5129 } |
| 5145 | 5130 |
| 5146 WebLocalFrame* frame = GetWebFrame(); | 5131 WebLocalFrame* frame = GetWebFrame(); |
| 5147 while (frame) { | 5132 while (frame) { |
| 5148 frame->stopFinding(clear_selection); | 5133 frame->stopFinding(clear_selection); |
| 5149 frame = frame->traverseNextLocal(false); | 5134 frame = frame->traverseNextLocal(false); |
| 5150 } | 5135 } |
| 5151 | 5136 |
| 5152 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { | 5137 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { |
| 5153 WebFrame* focused_frame = view->focusedFrame(); | 5138 WebFrame* focused_frame = view->focusedFrame(); |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6136 // event target. Potentially a Pepper plugin will receive the event. | 6121 // event target. Potentially a Pepper plugin will receive the event. |
| 6137 // In order to tell whether a plugin gets the last mouse event and which it | 6122 // In order to tell whether a plugin gets the last mouse event and which it |
| 6138 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6123 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6139 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6124 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6140 // |pepper_last_mouse_event_target_|. | 6125 // |pepper_last_mouse_event_target_|. |
| 6141 pepper_last_mouse_event_target_ = nullptr; | 6126 pepper_last_mouse_event_target_ = nullptr; |
| 6142 #endif | 6127 #endif |
| 6143 } | 6128 } |
| 6144 | 6129 |
| 6145 } // namespace content | 6130 } // namespace content |
| OLD | NEW |