OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/page_click_tracker.h" | 5 #include "components/autofill/renderer/page_click_tracker.h" |
6 | 6 |
7 #include "components/autofill/renderer/form_autofill_util.h" | 7 #include "components/autofill/renderer/form_autofill_util.h" |
8 #include "components/autofill/renderer/page_click_listener.h" | 8 #include "components/autofill/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/Source/WebKit/chromium/public/WebDOMMouseEvent.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMouseEvent.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
17 | 17 |
18 using WebKit::WebDOMEvent; | 18 using WebKit::WebDOMEvent; |
19 using WebKit::WebDOMMouseEvent; | 19 using WebKit::WebDOMMouseEvent; |
20 using WebKit::WebElement; | 20 using WebKit::WebElement; |
21 using WebKit::WebFormControlElement; | 21 using WebKit::WebFormControlElement; |
22 using WebKit::WebFrame; | 22 using WebKit::WebFrame; |
23 using WebKit::WebGestureEvent; | |
23 using WebKit::WebInputElement; | 24 using WebKit::WebInputElement; |
24 using WebKit::WebInputEvent; | 25 using WebKit::WebInputEvent; |
25 using WebKit::WebMouseEvent; | 26 using WebKit::WebMouseEvent; |
27 using WebKit::WebTouchEvent; | |
26 using WebKit::WebNode; | 28 using WebKit::WebNode; |
27 using WebKit::WebString; | 29 using WebKit::WebString; |
28 using WebKit::WebView; | 30 using WebKit::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()) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
80 return; | 82 return; |
81 } | 83 } |
82 | 84 |
83 // We are only interested in text field clicks. | 85 // We are only interested in text field clicks. |
84 const WebInputElement input_element = | 86 const WebInputElement input_element = |
85 GetTextWebInputElement(last_node_clicked_); | 87 GetTextWebInputElement(last_node_clicked_); |
86 if (input_element.isNull()) | 88 if (input_element.isNull()) |
87 return; | 89 return; |
88 | 90 |
89 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); | 91 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); |
90 listener_->InputElementClicked(input_element, was_focused_, is_focused); | 92 listener_->InputElementClicked(input_element, |
93 was_focused_, | |
94 is_focused, | |
95 MOUSE_CLICK); | |
96 } | |
97 | |
98 void PageClickTracker::DidHandleGestureEvent( | |
99 const WebKit::WebGestureEvent& event) { | |
100 if (event.type != WebInputEvent::GestureTap) | |
101 return; | |
102 | |
103 if (last_node_clicked_.isNull()) | |
104 return; | |
105 | |
106 // We are only interested in text field clicks. | |
107 const WebInputElement input_element = | |
108 GetTextWebInputElement(last_node_clicked_); | |
109 if (input_element.isNull()) | |
110 return; | |
111 | |
112 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); | |
113 listener_->InputElementClicked(input_element, | |
114 was_focused_, | |
115 is_focused, | |
116 TAP_GESTURE); | |
Ilya Sherman
2013/06/06 09:25:35
Please refactor the code so that the common parts
nyquist
2013/06/07 22:51:10
Done in the other CL.
| |
91 } | 117 } |
92 | 118 |
93 void PageClickTracker::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 119 void PageClickTracker::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
94 tracked_frames_.push_back(frame); | 120 tracked_frames_.push_back(frame); |
95 frame->document().addEventListener("mousedown", this, false); | 121 frame->document().addEventListener("mousedown", this, false); |
96 } | 122 } |
97 | 123 |
98 void PageClickTracker::FrameDetached(WebKit::WebFrame* frame) { | 124 void PageClickTracker::FrameDetached(WebKit::WebFrame* frame) { |
99 std::vector<WebKit::WebFrame*>::iterator iter = | 125 std::vector<WebKit::WebFrame*>::iterator iter = |
100 std::find(tracked_frames_.begin(), tracked_frames_.end(), frame); | 126 std::find(tracked_frames_.begin(), tracked_frames_.end(), frame); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 was_focused_ = (node.document().focusedNode() == last_node_clicked_); | 163 was_focused_ = (node.document().focusedNode() == last_node_clicked_); |
138 } | 164 } |
139 | 165 |
140 void PageClickTracker::HandleTextFieldMaybeLosingFocus( | 166 void PageClickTracker::HandleTextFieldMaybeLosingFocus( |
141 const WebNode& newly_clicked_node) { | 167 const WebNode& newly_clicked_node) { |
142 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) | 168 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) |
143 listener_->InputElementLostFocus(); | 169 listener_->InputElementLostFocus(); |
144 } | 170 } |
145 | 171 |
146 } // namespace autofill | 172 } // namespace autofill |
OLD | NEW |