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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/content/renderer/page_click_tracker.h" 5 #include "components/autofill/content/renderer/page_click_tracker.h"
6 6
7 #include "components/autofill/content/renderer/form_autofill_util.h" 7 #include "components/autofill/content/renderer/form_autofill_util.h"
8 #include "components/autofill/content/renderer/page_click_listener.h" 8 #include "components/autofill/content/renderer/page_click_listener.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/public/platform/WebString.h" 10 #include "third_party/WebKit/public/platform/WebString.h"
11 #include "third_party/WebKit/public/web/WebDOMMouseEvent.h" 11 #include "third_party/WebKit/public/web/WebDOMMouseEvent.h"
12 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebFrame.h" 13 #include "third_party/WebKit/public/web/WebFrame.h"
14 #include "third_party/WebKit/public/web/WebInputElement.h" 14 #include "third_party/WebKit/public/web/WebInputElement.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h" 15 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
16 #include "third_party/WebKit/public/web/WebView.h" 17 #include "third_party/WebKit/public/web/WebView.h"
17 18
18 using blink::WebDOMEvent; 19 using blink::WebDOMEvent;
19 using blink::WebDOMMouseEvent; 20 using blink::WebDOMMouseEvent;
20 using blink::WebElement; 21 using blink::WebElement;
21 using blink::WebFormControlElement; 22 using blink::WebFormControlElement;
22 using blink::WebFrame; 23 using blink::WebFrame;
23 using blink::WebInputElement; 24 using blink::WebInputElement;
24 using blink::WebInputEvent; 25 using blink::WebInputEvent;
25 using blink::WebMouseEvent; 26 using blink::WebMouseEvent;
26 using blink::WebNode; 27 using blink::WebNode;
27 using blink::WebString; 28 using blink::WebString;
29 using blink::WebTextAreaElement;
28 using blink::WebView; 30 using blink::WebView;
29 31
30 namespace { 32 namespace {
31 33
32 // Casts |node| to a WebInputElement. 34 // Casts |node| to a WebInputElement.
33 // Returns an empty (isNull()) WebInputElement if |node| is not a text field. 35 // Returns an empty (isNull()) WebInputElement if |node| is not a text field.
34 const WebInputElement GetTextWebInputElement(const WebNode& node) { 36 const WebInputElement GetTextWebInputElement(const WebNode& node) {
35 if (!node.isElementNode()) 37 if (!node.isElementNode())
36 return WebInputElement(); 38 return WebInputElement();
37 const WebElement element = node.toConst<WebElement>(); 39 const WebElement element = node.toConst<WebElement>();
38 if (!element.hasTagName("input")) 40 if (!element.hasTagName("input"))
39 return WebInputElement(); 41 return WebInputElement();
40 const WebInputElement* input = blink::toWebInputElement(&element); 42 const WebInputElement* input = blink::toWebInputElement(&element);
41 if (!autofill::IsTextInput(input)) 43 if (!autofill::IsTextInput(input))
42 return WebInputElement(); 44 return WebInputElement();
43 return *input; 45 return *input;
44 } 46 }
45 47
48 // Casts |node| to a WebTextAreaElement.
49 // Returns an empty (isNull()) WebTextAreaElement if |node| is not a
50 // textarea field.
51 const WebTextAreaElement GetTextWebTextAreaElement(const WebNode& node) {
52 if (!node.isElementNode())
53 return WebTextAreaElement();
54 const WebElement element = node.toConst<WebElement>();
55 if (!element.hasTagName("textarea"))
56 return WebTextAreaElement();
57 return element.toConst<WebTextAreaElement>();
58 }
59
46 // Checks to see if a text field was the previously selected node and is now 60 // Checks to see if a text field was the previously selected node and is now
47 // losing its focus. 61 // losing its focus.
48 bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) { 62 bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) {
49 blink::WebElement focused_element = 63 blink::WebElement focused_element =
50 newly_clicked_node.document().focusedElement(); 64 newly_clicked_node.document().focusedElement();
51 65
52 if (focused_element.isNull() || 66 if (focused_element.isNull() ||
53 GetTextWebInputElement(focused_element).isNull()) 67 (GetTextWebInputElement(focused_element).isNull() &&
68 GetTextWebTextAreaElement(focused_element).isNull()))
54 return false; 69 return false;
55 70
56 return focused_element != newly_clicked_node; 71 return focused_element != newly_clicked_node;
57 } 72 }
58 73
59 } // namespace 74 } // namespace
60 75
61 namespace autofill { 76 namespace autofill {
62 77
63 PageClickTracker::PageClickTracker(content::RenderView* render_view, 78 PageClickTracker::PageClickTracker(content::RenderView* render_view,
(...skipping 11 matching lines...) Expand all
75 // unregister listeners in frames remaining in tracked_frames_ as they might 90 // unregister listeners in frames remaining in tracked_frames_ as they might
76 // be invalid. 91 // be invalid.
77 } 92 }
78 93
79 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { 94 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) {
80 if (event.type != WebInputEvent::MouseDown || 95 if (event.type != WebInputEvent::MouseDown ||
81 last_node_clicked_.isNull()) { 96 last_node_clicked_.isNull()) {
82 return; 97 return;
83 } 98 }
84 99
85 // We are only interested in text field clicks. 100 // We are only interested in text field and textarea field clicks.
86 const WebInputElement input_element = 101 const WebInputElement input_element =
87 GetTextWebInputElement(last_node_clicked_); 102 GetTextWebInputElement(last_node_clicked_);
88 if (input_element.isNull()) 103 const WebTextAreaElement textarea_element =
104 GetTextWebTextAreaElement(last_node_clicked_);
105 if (input_element.isNull() && textarea_element.isNull())
89 return; 106 return;
90 107
91 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedElement()); 108 if (!input_element.isNull())
92 listener_->InputElementClicked(input_element, was_focused_, is_focused); 109 listener_->FormControlElementClicked(input_element, was_focused_);
110 else if (!textarea_element.isNull())
111 listener_->FormControlElementClicked(textarea_element, was_focused_);
93 } 112 }
94 113
95 void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) { 114 void PageClickTracker::DidFinishDocumentLoad(blink::WebFrame* frame) {
96 tracked_frames_.push_back(frame); 115 tracked_frames_.push_back(frame);
97 frame->document().addEventListener("mousedown", this, false); 116 frame->document().addEventListener("mousedown", this, false);
98 } 117 }
99 118
100 void PageClickTracker::FrameDetached(blink::WebFrame* frame) { 119 void PageClickTracker::FrameDetached(blink::WebFrame* frame) {
101 std::vector<blink::WebFrame*>::iterator iter = 120 std::vector<blink::WebFrame*>::iterator iter =
102 std::find(tracked_frames_.begin(), tracked_frames_.end(), frame); 121 std::find(tracked_frames_.begin(), tracked_frames_.end(), frame);
(...skipping 22 matching lines...) Expand all
125 // (DidHandleMouseEvent), we'll notify the listener at that point. 144 // (DidHandleMouseEvent), we'll notify the listener at that point.
126 WebNode node = mouse_event.target(); 145 WebNode node = mouse_event.target();
127 if (node.isNull()) 146 if (node.isNull())
128 // Node may be null if the target was an SVG instance element from a <use> 147 // Node may be null if the target was an SVG instance element from a <use>
129 // tree and the tree has been rebuilt due to an earlier event. 148 // tree and the tree has been rebuilt due to an earlier event.
130 return; 149 return;
131 150
132 HandleTextFieldMaybeLosingFocus(node); 151 HandleTextFieldMaybeLosingFocus(node);
133 152
134 // We are only interested in text field clicks. 153 // We are only interested in text field clicks.
135 if (GetTextWebInputElement(node).isNull()) 154 if (GetTextWebInputElement(node).isNull() &&
155 GetTextWebTextAreaElement(node).isNull())
136 return; 156 return;
137 157
138 last_node_clicked_ = node; 158 last_node_clicked_ = node;
139 was_focused_ = (node.document().focusedElement() == last_node_clicked_); 159 was_focused_ = (node.document().focusedElement() == last_node_clicked_);
140 } 160 }
141 161
142 void PageClickTracker::HandleTextFieldMaybeLosingFocus( 162 void PageClickTracker::HandleTextFieldMaybeLosingFocus(
143 const WebNode& newly_clicked_node) { 163 const WebNode& newly_clicked_node) {
144 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) 164 if (DidSelectedTextFieldLoseFocus(newly_clicked_node))
145 listener_->InputElementLostFocus(); 165 listener_->FormControlElementLostFocus();
146 } 166 }
147 167
148 } // namespace autofill 168 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698