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

Unified Diff: components/autofill/content/renderer/page_click_tracker.cc

Issue 140093005: Add supports that allow Autofill to be initiated from textarea field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Condition wrap correction Created 6 years, 9 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
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 59adae197965679bb713d57b7fccdd4accc51ad6..893882652168d80f63560fcdf5ba97b9fc0e52d4 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,6 +45,18 @@ 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();
+ return element.toConst<WebTextAreaElement>();
+}
+
// 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) {
@@ -50,7 +64,8 @@ bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) {
newly_clicked_node.document().focusedElement();
if (focused_element.isNull() ||
- GetTextWebInputElement(focused_element).isNull())
+ (GetTextWebInputElement(focused_element).isNull() &&
+ GetTextWebTextAreaElement(focused_element).isNull()))
return false;
return focused_element != newly_clicked_node;
@@ -82,14 +97,18 @@ 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()->GetFocusedElement());
- listener_->InputElementClicked(input_element, was_focused_, is_focused);
+ if (!input_element.isNull())
+ listener_->FormControlElementClicked(input_element, was_focused_);
+ else if (!textarea_element.isNull())
+ listener_->FormControlElementClicked(textarea_element, was_focused_);
}
void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) {
@@ -132,7 +151,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;
@@ -142,7 +162,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

Powered by Google App Engine
This is Rietveld 408576698