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

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

Issue 165233003: Replace WebDocument::focusedNode to focusedElement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nits Created 6 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "content/renderer/render_view_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 1542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 1553
1554 target_url_status_ = TARGET_NONE; 1554 target_url_status_ = TARGET_NONE;
1555 } 1555 }
1556 1556
1557 void RenderViewImpl::OnCopy() { 1557 void RenderViewImpl::OnCopy() {
1558 if (!webview()) 1558 if (!webview())
1559 return; 1559 return;
1560 1560
1561 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1561 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1562 WebNode current_node = context_menu_node_.isNull() ? 1562 WebNode current_node = context_menu_node_.isNull() ?
1563 GetFocusedNode() : context_menu_node_; 1563 GetFocusedElement() : context_menu_node_;
1564 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"), 1564 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Copy"),
1565 current_node); 1565 current_node);
1566 } 1566 }
1567 1567
1568 void RenderViewImpl::OnCut() { 1568 void RenderViewImpl::OnCut() {
1569 if (!webview()) 1569 if (!webview())
1570 return; 1570 return;
1571 1571
1572 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1572 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1573 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"), 1573 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Cut"),
1574 GetFocusedNode()); 1574 GetFocusedElement());
1575 } 1575 }
1576 1576
1577 void RenderViewImpl::OnDelete() { 1577 void RenderViewImpl::OnDelete() {
1578 if (!webview()) 1578 if (!webview())
1579 return; 1579 return;
1580 1580
1581 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"), 1581 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Delete"),
1582 GetFocusedNode()); 1582 GetFocusedElement());
1583 } 1583 }
1584 1584
1585 void RenderViewImpl::OnExecuteEditCommand(const std::string& name, 1585 void RenderViewImpl::OnExecuteEditCommand(const std::string& name,
1586 const std::string& value) { 1586 const std::string& value) {
1587 if (!webview() || !webview()->focusedFrame()) 1587 if (!webview() || !webview()->focusedFrame())
1588 return; 1588 return;
1589 1589
1590 webview()->focusedFrame()->executeCommand( 1590 webview()->focusedFrame()->executeCommand(
1591 WebString::fromUTF8(name), WebString::fromUTF8(value)); 1591 WebString::fromUTF8(name), WebString::fromUTF8(value));
1592 } 1592 }
1593 1593
1594 void RenderViewImpl::OnMoveCaret(const gfx::Point& point) { 1594 void RenderViewImpl::OnMoveCaret(const gfx::Point& point) {
1595 if (!webview()) 1595 if (!webview())
1596 return; 1596 return;
1597 1597
1598 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_)); 1598 Send(new ViewHostMsg_MoveCaret_ACK(routing_id_));
1599 1599
1600 webview()->focusedFrame()->moveCaretSelection(point); 1600 webview()->focusedFrame()->moveCaretSelection(point);
1601 } 1601 }
1602 1602
1603 void RenderViewImpl::OnPaste() { 1603 void RenderViewImpl::OnPaste() {
1604 if (!webview()) 1604 if (!webview())
1605 return; 1605 return;
1606 1606
1607 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1607 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1608 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"), 1608 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Paste"),
1609 GetFocusedNode()); 1609 GetFocusedElement());
1610 } 1610 }
1611 1611
1612 void RenderViewImpl::OnPasteAndMatchStyle() { 1612 void RenderViewImpl::OnPasteAndMatchStyle() {
1613 if (!webview()) 1613 if (!webview())
1614 return; 1614 return;
1615 1615
1616 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1616 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1617 webview()->focusedFrame()->executeCommand( 1617 webview()->focusedFrame()->executeCommand(
1618 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedNode()); 1618 WebString::fromUTF8("PasteAndMatchStyle"), GetFocusedElement());
1619 } 1619 }
1620 1620
1621 void RenderViewImpl::OnRedo() { 1621 void RenderViewImpl::OnRedo() {
1622 if (!webview()) 1622 if (!webview())
1623 return; 1623 return;
1624 1624
1625 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"), 1625 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Redo"),
1626 GetFocusedNode()); 1626 GetFocusedElement());
1627 } 1627 }
1628 1628
1629 void RenderViewImpl::OnReplace(const base::string16& text) { 1629 void RenderViewImpl::OnReplace(const base::string16& text) {
1630 if (!webview()) 1630 if (!webview())
1631 return; 1631 return;
1632 1632
1633 WebFrame* frame = webview()->focusedFrame(); 1633 WebFrame* frame = webview()->focusedFrame();
1634 if (!frame->hasSelection()) 1634 if (!frame->hasSelection())
1635 frame->selectWordAroundCaret(); 1635 frame->selectWordAroundCaret();
1636 1636
1637 frame->replaceSelection(text); 1637 frame->replaceSelection(text);
1638 } 1638 }
1639 1639
1640 void RenderViewImpl::OnReplaceMisspelling(const base::string16& text) { 1640 void RenderViewImpl::OnReplaceMisspelling(const base::string16& text) {
1641 if (!webview()) 1641 if (!webview())
1642 return; 1642 return;
1643 1643
1644 WebFrame* frame = webview()->focusedFrame(); 1644 WebFrame* frame = webview()->focusedFrame();
1645 if (!frame->hasSelection()) 1645 if (!frame->hasSelection())
1646 return; 1646 return;
1647 1647
1648 frame->replaceMisspelledRange(text); 1648 frame->replaceMisspelledRange(text);
1649 } 1649 }
1650 1650
1651 void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect( 1651 void RenderViewImpl::OnScrollFocusedEditableNodeIntoRect(
1652 const gfx::Rect& rect) { 1652 const gfx::Rect& rect) {
1653 blink::WebNode node = GetFocusedNode(); 1653 blink::WebElement element = GetFocusedElement();
1654 if (!node.isNull()) { 1654 if (!element.isNull()) {
1655 if (IsEditableNode(node)) { 1655 if (IsEditableNode(element)) {
1656 webview()->saveScrollAndScaleState(); 1656 webview()->saveScrollAndScaleState();
1657 webview()->scrollFocusedNodeIntoRect(rect); 1657 webview()->scrollFocusedNodeIntoRect(rect);
1658 } 1658 }
1659 } 1659 }
1660 } 1660 }
1661 1661
1662 void RenderViewImpl::OnSelectAll() { 1662 void RenderViewImpl::OnSelectAll() {
1663 if (!webview()) 1663 if (!webview())
1664 return; 1664 return;
1665 1665
1666 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1666 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1667 webview()->focusedFrame()->executeCommand( 1667 webview()->focusedFrame()->executeCommand(
1668 WebString::fromUTF8("SelectAll"), GetFocusedNode()); 1668 WebString::fromUTF8("SelectAll"), GetFocusedElement());
1669 } 1669 }
1670 1670
1671 void RenderViewImpl::OnSelectRange(const gfx::Point& start, 1671 void RenderViewImpl::OnSelectRange(const gfx::Point& start,
1672 const gfx::Point& end) { 1672 const gfx::Point& end) {
1673 if (!webview()) 1673 if (!webview())
1674 return; 1674 return;
1675 1675
1676 Send(new ViewHostMsg_SelectRange_ACK(routing_id_)); 1676 Send(new ViewHostMsg_SelectRange_ACK(routing_id_));
1677 1677
1678 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1678 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1679 webview()->focusedFrame()->selectRange(start, end); 1679 webview()->focusedFrame()->selectRange(start, end);
1680 } 1680 }
1681 1681
1682 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent( 1682 void RenderViewImpl::OnSetEditCommandsForNextKeyEvent(
1683 const EditCommands& edit_commands) { 1683 const EditCommands& edit_commands) {
1684 edit_commands_ = edit_commands; 1684 edit_commands_ = edit_commands;
1685 } 1685 }
1686 1686
1687 void RenderViewImpl::OnUndo() { 1687 void RenderViewImpl::OnUndo() {
1688 if (!webview()) 1688 if (!webview())
1689 return; 1689 return;
1690 1690
1691 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"), 1691 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Undo"),
1692 GetFocusedNode()); 1692 GetFocusedElement());
1693 } 1693 }
1694 1694
1695 void RenderViewImpl::OnUnselect() { 1695 void RenderViewImpl::OnUnselect() {
1696 if (!webview()) 1696 if (!webview())
1697 return; 1697 return;
1698 1698
1699 base::AutoReset<bool> handling_select_range(&handling_select_range_, true); 1699 base::AutoReset<bool> handling_select_range(&handling_select_range_, true);
1700 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), 1700 webview()->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
1701 GetFocusedNode()); 1701 GetFocusedElement());
1702 } 1702 }
1703 1703
1704 #if defined(OS_MACOSX) 1704 #if defined(OS_MACOSX)
1705 void RenderViewImpl::OnCopyToFindPboard() { 1705 void RenderViewImpl::OnCopyToFindPboard() {
1706 if (!webview()) 1706 if (!webview())
1707 return; 1707 return;
1708 1708
1709 // Since the find pasteboard supports only plain text, this can be simpler 1709 // Since the find pasteboard supports only plain text, this can be simpler
1710 // than the |OnCopy()| case. 1710 // than the |OnCopy()| case.
1711 WebFrame* frame = webview()->focusedFrame(); 1711 WebFrame* frame = webview()->focusedFrame();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 return; 1781 return;
1782 if (in_live_resize) 1782 if (in_live_resize)
1783 webview()->willStartLiveResize(); 1783 webview()->willStartLiveResize();
1784 else 1784 else
1785 webview()->willEndLiveResize(); 1785 webview()->willEndLiveResize();
1786 } 1786 }
1787 #endif 1787 #endif
1788 1788
1789 #if defined(OS_ANDROID) 1789 #if defined(OS_ANDROID)
1790 void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() { 1790 void RenderViewImpl::OnUndoScrollFocusedEditableNodeIntoRect() {
1791 const WebNode node = GetFocusedNode(); 1791 const WebElement element = GetFocusedElement();
1792 if (!node.isNull() && IsEditableNode(node)) 1792 if (!element.isNull() && IsEditableNode(element))
1793 webview()->restoreScrollAndScaleState(); 1793 webview()->restoreScrollAndScaleState();
1794 } 1794 }
1795 1795
1796 void RenderViewImpl::OnPauseVideo() { 1796 void RenderViewImpl::OnPauseVideo() {
1797 // Inform RendererMediaPlayerManager to release all video player resources. 1797 // Inform RendererMediaPlayerManager to release all video player resources.
1798 // If something is in progress the resource will not be freed, it will 1798 // If something is in progress the resource will not be freed, it will
1799 // only be freed once the tab is destroyed or if the user navigates away 1799 // only be freed once the tab is destroyed or if the user navigates away
1800 // via WebMediaPlayerAndroid::Destroy. 1800 // via WebMediaPlayerAndroid::Destroy.
1801 media_player_manager_->ReleaseVideoResources(); 1801 media_player_manager_->ReleaseVideoResources();
1802 } 1802 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2276 EditCommands::iterator it = edit_commands_.begin(); 2276 EditCommands::iterator it = edit_commands_.begin();
2277 EditCommands::iterator end = edit_commands_.end(); 2277 EditCommands::iterator end = edit_commands_.end();
2278 2278
2279 bool did_execute_command = false; 2279 bool did_execute_command = false;
2280 for (; it != end; ++it) { 2280 for (; it != end; ++it) {
2281 // In gtk and cocoa, it's possible to bind multiple edit commands to one 2281 // In gtk and cocoa, it's possible to bind multiple edit commands to one
2282 // key (but it's the exception). Once one edit command is not executed, it 2282 // key (but it's the exception). Once one edit command is not executed, it
2283 // seems safest to not execute the rest. 2283 // seems safest to not execute the rest.
2284 if (!frame->executeCommand(WebString::fromUTF8(it->name), 2284 if (!frame->executeCommand(WebString::fromUTF8(it->name),
2285 WebString::fromUTF8(it->value), 2285 WebString::fromUTF8(it->value),
2286 GetFocusedNode())) 2286 GetFocusedElement()))
2287 break; 2287 break;
2288 did_execute_command = true; 2288 did_execute_command = true;
2289 } 2289 }
2290 2290
2291 return did_execute_command; 2291 return did_execute_command;
2292 } 2292 }
2293 2293
2294 blink::WebColorChooser* RenderViewImpl::createColorChooser( 2294 blink::WebColorChooser* RenderViewImpl::createColorChooser(
2295 blink::WebColorChooserClient* client, 2295 blink::WebColorChooserClient* client,
2296 const blink::WebColor& initial_color, 2296 const blink::WebColor& initial_color,
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
3722 } 3722 }
3723 3723
3724 void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) { 3724 void RenderViewImpl::SetWebkitPreferences(const WebPreferences& preferences) {
3725 OnUpdateWebPreferences(preferences); 3725 OnUpdateWebPreferences(preferences);
3726 } 3726 }
3727 3727
3728 blink::WebView* RenderViewImpl::GetWebView() { 3728 blink::WebView* RenderViewImpl::GetWebView() {
3729 return webview(); 3729 return webview();
3730 } 3730 }
3731 3731
3732 blink::WebNode RenderViewImpl::GetFocusedNode() const { 3732 blink::WebElement RenderViewImpl::GetFocusedElement() const {
3733 if (!webview()) 3733 if (!webview())
3734 return WebNode(); 3734 return WebElement();
3735 WebFrame* focused_frame = webview()->focusedFrame(); 3735 WebFrame* focused_frame = webview()->focusedFrame();
3736 if (focused_frame) { 3736 if (focused_frame) {
3737 WebDocument doc = focused_frame->document(); 3737 WebDocument doc = focused_frame->document();
3738 if (!doc.isNull()) 3738 if (!doc.isNull())
3739 return doc.focusedNode(); 3739 return doc.focusedElement();
3740 } 3740 }
3741 3741
3742 return WebNode(); 3742 return WebElement();
3743 } 3743 }
3744 3744
3745 blink::WebNode RenderViewImpl::GetContextMenuNode() const { 3745 blink::WebNode RenderViewImpl::GetContextMenuNode() const {
3746 return context_menu_node_; 3746 return context_menu_node_;
3747 } 3747 }
3748 3748
3749 bool RenderViewImpl::IsEditableNode(const WebNode& node) const { 3749 bool RenderViewImpl::IsEditableNode(const WebNode& node) const {
3750 if (node.isNull()) 3750 if (node.isNull())
3751 return false; 3751 return false;
3752 3752
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
3966 // increment the current match ordinal; we need to re-generate it. 3966 // increment the current match ordinal; we need to re-generate it.
3967 WebRange current_selection = focused_frame->selectionRange(); 3967 WebRange current_selection = focused_frame->selectionRange();
3968 3968
3969 do { 3969 do {
3970 result = search_frame->find( 3970 result = search_frame->find(
3971 request_id, search_text, options, wrap_within_frame, &selection_rect); 3971 request_id, search_text, options, wrap_within_frame, &selection_rect);
3972 3972
3973 if (!result) { 3973 if (!result) {
3974 // don't leave text selected as you move to the next frame. 3974 // don't leave text selected as you move to the next frame.
3975 search_frame->executeCommand(WebString::fromUTF8("Unselect"), 3975 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
3976 GetFocusedNode()); 3976 GetFocusedElement());
3977 3977
3978 // Find the next frame, but skip the invisible ones. 3978 // Find the next frame, but skip the invisible ones.
3979 do { 3979 do {
3980 // What is the next frame to search? (we might be going backwards). Note 3980 // What is the next frame to search? (we might be going backwards). Note
3981 // that we specify wrap=true so that search_frame never becomes NULL. 3981 // that we specify wrap=true so that search_frame never becomes NULL.
3982 search_frame = options.forward ? 3982 search_frame = options.forward ?
3983 search_frame->traverseNext(true) : 3983 search_frame->traverseNext(true) :
3984 search_frame->traversePrevious(true); 3984 search_frame->traversePrevious(true);
3985 } while (!search_frame->hasVisibleContent() && 3985 } while (!search_frame->hasVisibleContent() &&
3986 search_frame != focused_frame); 3986 search_frame != focused_frame);
3987 3987
3988 // Make sure selection doesn't affect the search operation in new frame. 3988 // Make sure selection doesn't affect the search operation in new frame.
3989 search_frame->executeCommand(WebString::fromUTF8("Unselect"), 3989 search_frame->executeCommand(WebString::fromUTF8("Unselect"),
3990 GetFocusedNode()); 3990 GetFocusedElement());
3991 3991
3992 // If we have multiple frames and we have wrapped back around to the 3992 // If we have multiple frames and we have wrapped back around to the
3993 // focused frame, we need to search it once more allowing wrap within 3993 // focused frame, we need to search it once more allowing wrap within
3994 // the frame, otherwise it will report 'no match' if the focused frame has 3994 // the frame, otherwise it will report 'no match' if the focused frame has
3995 // reported matches, but no frames after the focused_frame contain a 3995 // reported matches, but no frames after the focused_frame contain a
3996 // match for the search word(s). 3996 // match for the search word(s).
3997 if (multi_frame && search_frame == focused_frame) { 3997 if (multi_frame && search_frame == focused_frame) {
3998 result = search_frame->find( 3998 result = search_frame->find(
3999 request_id, search_text, options, true, // Force wrapping. 3999 request_id, search_text, options, true, // Force wrapping.
4000 &selection_rect); 4000 &selection_rect);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4055 4055
4056 WebDocument doc = view->mainFrame()->document(); 4056 WebDocument doc = view->mainFrame()->document();
4057 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) { 4057 if (doc.isPluginDocument() && GetWebPluginFromPluginDocument()) {
4058 GetWebPluginFromPluginDocument()->stopFind(); 4058 GetWebPluginFromPluginDocument()->stopFind();
4059 return; 4059 return;
4060 } 4060 }
4061 4061
4062 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION; 4062 bool clear_selection = action == STOP_FIND_ACTION_CLEAR_SELECTION;
4063 if (clear_selection) { 4063 if (clear_selection) {
4064 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"), 4064 view->focusedFrame()->executeCommand(WebString::fromUTF8("Unselect"),
4065 GetFocusedNode()); 4065 GetFocusedElement());
4066 } 4066 }
4067 4067
4068 WebFrame* frame = view->mainFrame(); 4068 WebFrame* frame = view->mainFrame();
4069 while (frame) { 4069 while (frame) {
4070 frame->stopFinding(clear_selection); 4070 frame->stopFinding(clear_selection);
4071 frame = frame->traverseNext(false); 4071 frame = frame->traverseNext(false);
4072 } 4072 }
4073 4073
4074 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) { 4074 if (action == STOP_FIND_ACTION_ACTIVATE_SELECTION) {
4075 WebFrame* focused_frame = view->focusedFrame(); 4075 WebFrame* focused_frame = view->focusedFrame();
4076 if (focused_frame) { 4076 if (focused_frame) {
4077 WebDocument doc = focused_frame->document(); 4077 WebDocument doc = focused_frame->document();
4078 if (!doc.isNull()) { 4078 if (!doc.isNull()) {
4079 WebNode node = doc.focusedNode(); 4079 WebElement element = doc.focusedElement();
4080 if (!node.isNull()) 4080 if (!element.isNull())
4081 node.simulateClick(); 4081 element.simulateClick();
4082 } 4082 }
4083 } 4083 }
4084 } 4084 }
4085 } 4085 }
4086 4086
4087 #if defined(OS_ANDROID) 4087 #if defined(OS_ANDROID)
4088 void RenderViewImpl::OnActivateNearestFindResult(int request_id, 4088 void RenderViewImpl::OnActivateNearestFindResult(int request_id,
4089 float x, float y) { 4089 float x, float y) {
4090 if (!webview()) 4090 if (!webview())
4091 return; 4091 return;
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after
5751 for (size_t i = 0; i < icon_urls.size(); i++) { 5751 for (size_t i = 0; i < icon_urls.size(); i++) {
5752 WebURL url = icon_urls[i].iconURL(); 5752 WebURL url = icon_urls[i].iconURL();
5753 if (!url.isEmpty()) 5753 if (!url.isEmpty())
5754 urls.push_back(FaviconURL(url, 5754 urls.push_back(FaviconURL(url,
5755 ToFaviconType(icon_urls[i].iconType()))); 5755 ToFaviconType(icon_urls[i].iconType())));
5756 } 5756 }
5757 SendUpdateFaviconURL(urls); 5757 SendUpdateFaviconURL(urls);
5758 } 5758 }
5759 5759
5760 } // namespace content 5760 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698