Chromium Code Reviews| Index: components/autofill/content/renderer/page_click_tracker.cc |
| diff --git a/components/autofill/content/renderer/page_click_tracker.cc b/components/autofill/content/renderer/page_click_tracker.cc |
| index 9e2f649f023a15a00f2f7c6b42e5231b8242d565..bc6ac8eaf2d7eb4985fb43f3c9d42c6a770e6483 100644 |
| --- a/components/autofill/content/renderer/page_click_tracker.cc |
| +++ b/components/autofill/content/renderer/page_click_tracker.cc |
| @@ -13,6 +13,7 @@ |
| #include "third_party/WebKit/public/web/WebFrame.h" |
| #include "third_party/WebKit/public/web/WebInputElement.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| +#include "third_party/WebKit/public/web/WebTextAreaElement.h" |
| #include "third_party/WebKit/public/web/WebView.h" |
| using blink::WebDOMEvent; |
| @@ -25,6 +26,7 @@ using blink::WebInputEvent; |
| using blink::WebMouseEvent; |
| using blink::WebNode; |
| using blink::WebString; |
| +using blink::WebTextAreaElement; |
| using blink::WebView; |
| namespace { |
| @@ -43,12 +45,28 @@ const WebInputElement GetTextWebInputElement(const WebNode& node) { |
| return *input; |
| } |
| +// Casts |node| to a WebTextAreaElement. |
| +// Returns an empty (isNull()) WebTextAreaElement if |node| is not a |
| +// textarea field. |
| +const WebTextAreaElement GetTextWebTextAreaElement(const WebNode& node) { |
| + if (!node.isElementNode()) |
| + return WebTextAreaElement(); |
| + const WebElement element = node.toConst<WebElement>(); |
| + if (!element.hasTagName("textarea")) |
| + return WebTextAreaElement(); |
| + const WebTextAreaElement text_area = |
| + element.toConst<WebTextAreaElement>(); |
| + return text_area; |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Lines 57 through 59 can be shortened to just
ziran.sun
2014/02/26 18:11:50
Done.
|
| +} |
| + |
| // Checks to see if a text field was the previously selected node and is now |
| // losing its focus. |
| bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) { |
| blink::WebNode focused_node = newly_clicked_node.document().focusedNode(); |
| - if (focused_node.isNull() || GetTextWebInputElement(focused_node).isNull()) |
| + if (focused_node.isNull() || |
| + (GetTextWebInputElement(focused_node).isNull() && |
| + GetTextWebTextAreaElement(focused_node).isNull())) |
| return false; |
| return focused_node != newly_clicked_node; |
| @@ -80,14 +98,21 @@ void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { |
| return; |
| } |
| - // We are only interested in text field clicks. |
| + // We are only interested in text field and textarea field clicks. |
| const WebInputElement input_element = |
| GetTextWebInputElement(last_node_clicked_); |
| - if (input_element.isNull()) |
| + const WebTextAreaElement textarea_element = |
| + GetTextWebTextAreaElement(last_node_clicked_); |
| + if (input_element.isNull() && textarea_element.isNull()) |
| return; |
| - bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); |
| - listener_->InputElementClicked(input_element, was_focused_, is_focused); |
| + if (!input_element.isNull()) { |
| + listener_->FormControlElementClicked(input_element, |
| + was_focused_); |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Doesn't look like this line needs to wrap any
ziran.sun
2014/02/26 18:11:50
Done.
|
| + } else if (!textarea_element.isNull()) { |
| + listener_->FormControlElementClicked(textarea_element, |
| + was_focused_); |
|
Ilya Sherman
2014/02/26 00:12:07
nit: Doesn't look like this line needs to wrap any
ziran.sun
2014/02/26 18:11:50
Done.
|
| + } |
| } |
| void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) { |
| @@ -130,7 +155,8 @@ void PageClickTracker::handleEvent(const WebDOMEvent& event) { |
| HandleTextFieldMaybeLosingFocus(node); |
| // We are only interested in text field clicks. |
| - if (GetTextWebInputElement(node).isNull()) |
| + if (GetTextWebInputElement(node).isNull() && |
| + GetTextWebTextAreaElement(node).isNull()) |
| return; |
| last_node_clicked_ = node; |
| @@ -140,7 +166,7 @@ void PageClickTracker::handleEvent(const WebDOMEvent& event) { |
| void PageClickTracker::HandleTextFieldMaybeLosingFocus( |
| const WebNode& newly_clicked_node) { |
| if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) |
| - listener_->InputElementLostFocus(); |
| + listener_->FormControlElementLostFocus(); |
| } |
| } // namespace autofill |