OLD | NEW |
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" |
(...skipping 19 matching lines...) Expand all Loading... |
30 using blink::WebView; | 30 using blink::WebView; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Casts |node| to a WebInputElement. | 34 // Casts |node| to a WebInputElement. |
35 // 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. |
36 const WebInputElement GetTextWebInputElement(const WebNode& node) { | 36 const WebInputElement GetTextWebInputElement(const WebNode& node) { |
37 if (!node.isElementNode()) | 37 if (!node.isElementNode()) |
38 return WebInputElement(); | 38 return WebInputElement(); |
39 const WebElement element = node.toConst<WebElement>(); | 39 const WebElement element = node.toConst<WebElement>(); |
40 if (!element.hasTagName("input")) | 40 if (!element.hasHTMLTagName("input")) |
41 return WebInputElement(); | 41 return WebInputElement(); |
42 const WebInputElement* input = blink::toWebInputElement(&element); | 42 const WebInputElement* input = blink::toWebInputElement(&element); |
43 if (!autofill::IsTextInput(input)) | 43 if (!autofill::IsTextInput(input)) |
44 return WebInputElement(); | 44 return WebInputElement(); |
45 return *input; | 45 return *input; |
46 } | 46 } |
47 | 47 |
48 // Casts |node| to a WebTextAreaElement. | 48 // Casts |node| to a WebTextAreaElement. |
49 // Returns an empty (isNull()) WebTextAreaElement if |node| is not a | 49 // Returns an empty (isNull()) WebTextAreaElement if |node| is not a |
50 // textarea field. | 50 // textarea field. |
51 const WebTextAreaElement GetTextWebTextAreaElement(const WebNode& node) { | 51 const WebTextAreaElement GetWebTextAreaElement(const WebNode& node) { |
52 if (!node.isElementNode()) | 52 if (!node.isElementNode()) |
53 return WebTextAreaElement(); | 53 return WebTextAreaElement(); |
54 const WebElement element = node.toConst<WebElement>(); | 54 const WebElement element = node.toConst<WebElement>(); |
55 if (!element.hasTagName("textarea")) | 55 if (!element.hasHTMLTagName("textarea")) |
56 return WebTextAreaElement(); | 56 return WebTextAreaElement(); |
57 return element.toConst<WebTextAreaElement>(); | 57 return element.toConst<WebTextAreaElement>(); |
58 } | 58 } |
59 | 59 |
60 // 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 |
61 // losing its focus. | 61 // losing its focus. |
62 bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) { | 62 bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) { |
63 blink::WebElement focused_element = | 63 blink::WebElement focused_element = |
64 newly_clicked_node.document().focusedElement(); | 64 newly_clicked_node.document().focusedElement(); |
65 | 65 |
66 if (focused_element.isNull() || | 66 if (focused_element.isNull() || |
67 (GetTextWebInputElement(focused_element).isNull() && | 67 (GetTextWebInputElement(focused_element).isNull() && |
68 GetTextWebTextAreaElement(focused_element).isNull())) | 68 GetWebTextAreaElement(focused_element).isNull())) |
69 return false; | 69 return false; |
70 | 70 |
71 return focused_element != newly_clicked_node; | 71 return focused_element != newly_clicked_node; |
72 } | 72 } |
73 | 73 |
74 } // namespace | 74 } // namespace |
75 | 75 |
76 namespace autofill { | 76 namespace autofill { |
77 | 77 |
78 PageClickTracker::PageClickTracker(content::RenderView* render_view, | 78 PageClickTracker::PageClickTracker(content::RenderView* render_view, |
(...skipping 15 matching lines...) Expand all Loading... |
94 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { | 94 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { |
95 if (event.type != WebInputEvent::MouseDown || | 95 if (event.type != WebInputEvent::MouseDown || |
96 last_node_clicked_.isNull()) { | 96 last_node_clicked_.isNull()) { |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
100 // We are only interested in text field and textarea field clicks. | 100 // We are only interested in text field and textarea field clicks. |
101 const WebInputElement input_element = | 101 const WebInputElement input_element = |
102 GetTextWebInputElement(last_node_clicked_); | 102 GetTextWebInputElement(last_node_clicked_); |
103 const WebTextAreaElement textarea_element = | 103 const WebTextAreaElement textarea_element = |
104 GetTextWebTextAreaElement(last_node_clicked_); | 104 GetWebTextAreaElement(last_node_clicked_); |
105 if (input_element.isNull() && textarea_element.isNull()) | 105 if (input_element.isNull() && textarea_element.isNull()) |
106 return; | 106 return; |
107 | 107 |
108 if (!input_element.isNull()) | 108 if (!input_element.isNull()) |
109 listener_->FormControlElementClicked(input_element, was_focused_); | 109 listener_->FormControlElementClicked(input_element, was_focused_); |
110 else if (!textarea_element.isNull()) | 110 else if (!textarea_element.isNull()) |
111 listener_->FormControlElementClicked(textarea_element, was_focused_); | 111 listener_->FormControlElementClicked(textarea_element, was_focused_); |
112 } | 112 } |
113 | 113 |
114 void PageClickTracker::DidFinishDocumentLoad(blink::WebLocalFrame* frame) { | 114 void PageClickTracker::DidFinishDocumentLoad(blink::WebLocalFrame* frame) { |
(...skipping 30 matching lines...) Expand all Loading... |
145 WebNode node = mouse_event.target(); | 145 WebNode node = mouse_event.target(); |
146 if (node.isNull()) | 146 if (node.isNull()) |
147 // 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> |
148 // 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. |
149 return; | 149 return; |
150 | 150 |
151 HandleTextFieldMaybeLosingFocus(node); | 151 HandleTextFieldMaybeLosingFocus(node); |
152 | 152 |
153 // We are only interested in text field clicks. | 153 // We are only interested in text field clicks. |
154 if (GetTextWebInputElement(node).isNull() && | 154 if (GetTextWebInputElement(node).isNull() && |
155 GetTextWebTextAreaElement(node).isNull()) | 155 GetWebTextAreaElement(node).isNull()) |
156 return; | 156 return; |
157 | 157 |
158 last_node_clicked_ = node; | 158 last_node_clicked_ = node; |
159 was_focused_ = (node.document().focusedElement() == last_node_clicked_); | 159 was_focused_ = (node.document().focusedElement() == last_node_clicked_); |
160 } | 160 } |
161 | 161 |
162 void PageClickTracker::HandleTextFieldMaybeLosingFocus( | 162 void PageClickTracker::HandleTextFieldMaybeLosingFocus( |
163 const WebNode& newly_clicked_node) { | 163 const WebNode& newly_clicked_node) { |
164 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) | 164 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) |
165 listener_->FormControlElementLostFocus(); | 165 listener_->FormControlElementLostFocus(); |
166 } | 166 } |
167 | 167 |
168 } // namespace autofill | 168 } // namespace autofill |
OLD | NEW |