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

Unified Diff: chrome/renderer/page_click_tracker.cc

Issue 7064012: In PageClickTracker, only store last clicked node if it's significant. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/page_click_tracker.cc
===================================================================
--- chrome/renderer/page_click_tracker.cc (revision 86185)
+++ chrome/renderer/page_click_tracker.cc (working copy)
@@ -27,6 +27,33 @@
using WebKit::WebString;
using WebKit::WebView;
+namespace {
+
+// Returns whether |node| is a text input element.
Jay Civelli 2011/05/24 04:47:25 I wonder if we need this method. May be GetTextWeb
dpanpong 2011/05/24 17:10:26 I like that much better. Done.
+bool IsTextWebInputElement(const WebNode& node) {
+ if (!node.isElementNode())
dpanpong 2011/05/24 01:21:40 The logic in this function moved from DidHandleMou
+ return false;
+ const WebElement element = node.toConst<WebElement>();
+ if (!element.isFormControlElement())
+ return false;
+ const WebFormControlElement control =
+ element.toConst<WebFormControlElement>();
+ if (control.formControlType() != WebString::fromUTF8("text"))
+ return false;
+ return true;
+}
+
+// Casts |node| to a WebInputElement.
+// |node| must be a web input element.
+const WebInputElement GetTextWebInputElement(const WebNode& node) {
+ const WebElement element = node.toConst<WebElement>();
+ const WebFormControlElement control =
+ element.toConst<WebFormControlElement>();
+ return element.toConst<WebInputElement>();
+}
+
+} // namespace
+
PageClickTracker::PageClickTracker(RenderView* render_view)
: RenderViewObserver(render_view),
was_focused_(false) {
@@ -48,17 +75,11 @@
}
// We are only interested in text field clicks.
- if (!last_node_clicked_.isElementNode())
+ if (!IsTextWebInputElement(last_node_clicked_))
return;
- const WebElement& element = last_node_clicked_.toConst<WebElement>();
- if (!element.isFormControlElement())
- return;
- const WebFormControlElement& control =
- element.toConst<WebFormControlElement>();
- if (control.formControlType() != WebString::fromUTF8("text"))
- return;
- const WebInputElement& input_element = element.toConst<WebInputElement>();
+ const WebInputElement input_element =
+ GetTextWebInputElement(last_node_clicked_);
bool is_focused = (last_node_clicked_ == GetFocusedNode());
ObserverListBase<PageClickListener>::Iterator it(listeners_);
@@ -125,7 +146,12 @@
// Remember which node has focus before the click is processed.
// We'll get a notification once the mouse event has been processed
// (DidHandleMouseEvent), we'll notify the listener at that point.
- last_node_clicked_ = mouse_event.target();
+ WebNode node = mouse_event.target();
+ // We are only interested in text field clicks.
+ if (!IsTextWebInputElement(node))
+ return;
+
+ last_node_clicked_ = node;
was_focused_ = (GetFocusedNode() == last_node_clicked_);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698