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..56a40d88651710d9819efa0223d9199cd2cbed35 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,32 @@ 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 WebFormControlElement& controlElement = |
+ element.toConst<WebFormControlElement>(); |
+ if (!autofill::IsTextAreaElement(controlElement)) |
+ return WebTextAreaElement(); |
+ const WebTextAreaElement text_area = |
+ controlElement.toConst<WebTextAreaElement>(); |
+ return text_area; |
+} |
+ |
// 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 +102,20 @@ 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_->InputElementClicked(input_element, was_focused_, is_focused); |
+ if (!textarea_element.isNull()) |
+ listener_->TextAreaElementClicked(textarea_element, |
+ was_focused_, is_focused); |
} |
void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) { |
@@ -130,7 +158,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 +169,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 |