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

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,26 @@
using WebKit::WebString;
using WebKit::WebView;
+namespace {
+
+// Casts |node| to a WebInputElement.
+// Returns an empty (isNull()) WebInputElement if |node| is not a text
+// WebInputElement.
+const WebInputElement GetTextWebInputElement(const WebNode& node) {
+ if (!node.isElementNode())
+ return WebInputElement();
+ const WebElement element = node.toConst<WebElement>();
+ if (!element.isFormControlElement())
+ return WebInputElement();
+ const WebFormControlElement control =
+ element.toConst<WebFormControlElement>();
+ if (control.formControlType() != WebString::fromUTF8("text"))
+ return WebInputElement();
+ return element.toConst<WebInputElement>();
+}
+
+} // namespace
+
PageClickTracker::PageClickTracker(RenderView* render_view)
: RenderViewObserver(render_view),
was_focused_(false) {
@@ -48,18 +68,11 @@
}
// We are only interested in text field clicks.
- if (!last_node_clicked_.isElementNode())
+ const WebInputElement input_element =
+ GetTextWebInputElement(last_node_clicked_);
+ if (input_element.isNull())
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>();
-
bool is_focused = (last_node_clicked_ == GetFocusedNode());
ObserverListBase<PageClickListener>::Iterator it(listeners_);
PageClickListener* listener;
@@ -125,7 +138,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 (GetTextWebInputElement(node).isNull())
+ 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