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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 | 69 |
68 PageClickTracker::~PageClickTracker() { | 70 PageClickTracker::~PageClickTracker() { |
69 // Note that even though RenderView calls FrameDetached when notified that | 71 // Note that even though RenderView calls FrameDetached when notified that |
70 // a frame was closed, it might not always get that notification from WebKit | 72 // a frame was closed, it might not always get that notification from WebKit |
71 // for all frames. | 73 // for all frames. |
72 // By the time we get here, the frame could have been destroyed so we cannot | 74 // By the time we get here, the frame could have been destroyed so we cannot |
73 // unregister listeners in frames remaining in tracked_frames_ as they might | 75 // unregister listeners in frames remaining in tracked_frames_ as they might |
74 // be invalid. | 76 // be invalid. |
75 } | 77 } |
76 | 78 |
77 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { | 79 void PageClickTracker::DidHandleMouseOrGestureEvent( |
78 if (event.type != WebInputEvent::MouseDown || | 80 const WebInputEvent& event, |
79 last_node_clicked_.isNull()) { | 81 WebInputEvent::Type expected_type, |
82 autofill::InputEventSource source) { | |
Ilya Sherman
2013/06/06 20:35:08
nit: No need for the "autofill::" prefix, as this
| |
83 if (event.type != expected_type || last_node_clicked_.isNull()) { | |
80 return; | 84 return; |
81 } | 85 } |
Ilya Sherman
2013/06/06 20:35:08
nit: No need for curlies
| |
82 | 86 |
83 // We are only interested in text field clicks. | 87 // We are only interested in text field clicks and taps. |
84 const WebInputElement input_element = | 88 const WebInputElement input_element = |
85 GetTextWebInputElement(last_node_clicked_); | 89 GetTextWebInputElement(last_node_clicked_); |
86 if (input_element.isNull()) | 90 if (input_element.isNull()) |
87 return; | 91 return; |
88 | 92 |
89 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); | 93 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); |
90 listener_->InputElementClicked(input_element, was_focused_, is_focused); | 94 listener_->InputElementClicked(input_element, |
95 was_focused_, | |
96 is_focused, | |
97 source); | |
98 } | |
99 | |
100 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { | |
101 DidHandleMouseOrGestureEvent(event, WebInputEvent::MouseDown, MOUSE_CLICK); | |
102 } | |
103 | |
104 void PageClickTracker::DidHandleGestureEvent(const WebGestureEvent& event) { | |
105 DidHandleMouseOrGestureEvent(event, WebInputEvent::GestureTap, TAP_GESTURE); | |
91 } | 106 } |
92 | 107 |
93 void PageClickTracker::DidFinishDocumentLoad(WebKit::WebFrame* frame) { | 108 void PageClickTracker::DidFinishDocumentLoad(WebKit::WebFrame* frame) { |
94 tracked_frames_.push_back(frame); | 109 tracked_frames_.push_back(frame); |
95 frame->document().addEventListener("mousedown", this, false); | 110 frame->document().addEventListener("mousedown", this, false); |
96 } | 111 } |
97 | 112 |
98 void PageClickTracker::FrameDetached(WebKit::WebFrame* frame) { | 113 void PageClickTracker::FrameDetached(WebKit::WebFrame* frame) { |
99 std::vector<WebKit::WebFrame*>::iterator iter = | 114 std::vector<WebKit::WebFrame*>::iterator iter = |
100 std::find(tracked_frames_.begin(), tracked_frames_.end(), frame); | 115 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_); | 152 was_focused_ = (node.document().focusedNode() == last_node_clicked_); |
138 } | 153 } |
139 | 154 |
140 void PageClickTracker::HandleTextFieldMaybeLosingFocus( | 155 void PageClickTracker::HandleTextFieldMaybeLosingFocus( |
141 const WebNode& newly_clicked_node) { | 156 const WebNode& newly_clicked_node) { |
142 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) | 157 if (DidSelectedTextFieldLoseFocus(newly_clicked_node)) |
143 listener_->InputElementLostFocus(); | 158 listener_->InputElementLostFocus(); |
144 } | 159 } |
145 | 160 |
146 } // namespace autofill | 161 } // namespace autofill |
OLD | NEW |