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_); |
} |