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

Side by Side Diff: components/autofill/content/renderer/page_click_tracker.cc

Issue 715733002: [Android] Show autofill popup after animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 11 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 "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "components/autofill/content/renderer/form_autofill_util.h" 7 #include "components/autofill/content/renderer/form_autofill_util.h"
10 #include "components/autofill/content/renderer/page_click_listener.h" 8 #include "components/autofill/content/renderer/page_click_listener.h"
11 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/web/WebDOMMouseEvent.h"
14 #include "third_party/WebKit/public/web/WebDocument.h" 10 #include "third_party/WebKit/public/web/WebDocument.h"
15 #include "third_party/WebKit/public/web/WebInputElement.h" 11 #include "third_party/WebKit/public/web/WebInputElement.h"
16 #include "third_party/WebKit/public/web/WebInputEvent.h" 12 #include "third_party/WebKit/public/web/WebInputEvent.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 13 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 #include "third_party/WebKit/public/web/WebTextAreaElement.h" 14 #include "third_party/WebKit/public/web/WebTextAreaElement.h"
19 #include "third_party/WebKit/public/web/WebView.h" 15 #include "third_party/WebKit/public/web/WebView.h"
20 16
21 using blink::WebDOMEvent;
22 using blink::WebDOMMouseEvent;
23 using blink::WebElement; 17 using blink::WebElement;
24 using blink::WebFormControlElement;
25 using blink::WebFrame;
26 using blink::WebGestureEvent; 18 using blink::WebGestureEvent;
27 using blink::WebInputElement; 19 using blink::WebInputElement;
28 using blink::WebInputEvent; 20 using blink::WebInputEvent;
29 using blink::WebMouseEvent; 21 using blink::WebMouseEvent;
30 using blink::WebNode; 22 using blink::WebNode;
31 using blink::WebString;
32 using blink::WebTextAreaElement; 23 using blink::WebTextAreaElement;
33 using blink::WebView;
34 24
35 namespace { 25 namespace {
36 26
37 // Casts |node| to a WebInputElement. 27 // Casts |node| to a WebInputElement.
38 // Returns an empty (isNull()) WebInputElement if |node| is not a text field. 28 // Returns an empty (isNull()) WebInputElement if |node| is not a text field.
39 const WebInputElement GetTextWebInputElement(const WebNode& node) { 29 const WebInputElement GetTextWebInputElement(const WebNode& node) {
40 if (!node.isElementNode()) 30 if (!node.isElementNode())
41 return WebInputElement(); 31 return WebInputElement();
42 const WebElement element = node.toConst<WebElement>(); 32 const WebElement element = node.toConst<WebElement>();
43 if (!element.hasHTMLTagName("input")) 33 if (!element.hasHTMLTagName("input"))
(...skipping 17 matching lines...) Expand all
61 } 51 }
62 52
63 } // namespace 53 } // namespace
64 54
65 namespace autofill { 55 namespace autofill {
66 56
67 PageClickTracker::PageClickTracker(content::RenderView* render_view, 57 PageClickTracker::PageClickTracker(content::RenderView* render_view,
68 PageClickListener* listener) 58 PageClickListener* listener)
69 : content::RenderViewObserver(render_view), 59 : content::RenderViewObserver(render_view),
70 was_focused_before_now_(false), 60 was_focused_before_now_(false),
71 listener_(listener), 61 listener_(listener) {
72 weak_ptr_factory_(this) {
73 } 62 }
74 63
75 PageClickTracker::~PageClickTracker() { 64 PageClickTracker::~PageClickTracker() {
76 } 65 }
77 66
78 void PageClickTracker::OnDestruct() { 67 void PageClickTracker::OnDestruct() {
79 // No-op. Don't delete |this|. 68 // No-op. Don't delete |this|.
80 } 69 }
81 70
82 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { 71 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) {
83 if (event.type != WebInputEvent::MouseDown || 72 if (event.type != WebInputEvent::MouseDown ||
84 event.button != WebMouseEvent::ButtonLeft) { 73 event.button != WebMouseEvent::ButtonLeft) {
85 return; 74 return;
86 } 75 }
87 76
88 PotentialActivationAt(event.x, event.y); 77 PotentialActivationAt(event.x, event.y);
89 } 78 }
90 79
91 void PageClickTracker::DidHandleGestureEvent( 80 void PageClickTracker::DidHandleGestureEvent(const WebGestureEvent& event) {
92 const blink::WebGestureEvent& event) { 81 if (event.type != WebGestureEvent::GestureTap)
93 if (event.type != blink::WebGestureEvent::GestureTap)
94 return; 82 return;
95 83
96 PotentialActivationAt(event.x, event.y); 84 PotentialActivationAt(event.x, event.y);
97 } 85 }
98 86
99 void PageClickTracker::FocusedNodeChanged(const blink::WebNode& node) { 87 void PageClickTracker::FocusedNodeChanged(const WebNode& node) {
100 was_focused_before_now_ = false; 88 was_focused_before_now_ = false;
101 // If the focus change was a result of handling a click or tap, we'll soon get 89 }
102 // an associated event. Reset |was_focused_before_now_| to true only after the 90
103 // message loop unwinds. 91 void PageClickTracker::FocusChangeComplete() {
104 base::MessageLoop::current()->PostTask( 92 if (!clicked_node_.isNull()) {
105 FROM_HERE, 93 const WebInputElement input_element = GetTextWebInputElement(clicked_node_);
106 base::Bind(&PageClickTracker::SetWasFocused, 94 if (!input_element.isNull()) {
107 weak_ptr_factory_.GetWeakPtr())); 95 listener_->FormControlElementClicked(input_element,
96 was_focused_before_now_);
97 } else {
98 const WebTextAreaElement textarea_element =
99 GetWebTextAreaElement(clicked_node_);
100 if (!textarea_element.isNull()) {
101 listener_->FormControlElementClicked(textarea_element,
102 was_focused_before_now_);
103 }
104 }
105 }
106
107 clicked_node_.reset();
108 was_focused_before_now_ = true;
108 } 109 }
109 110
110 void PageClickTracker::PotentialActivationAt(int x, int y) { 111 void PageClickTracker::PotentialActivationAt(int x, int y) {
111 blink::WebNode focused_node = render_view()->GetFocusedElement(); 112 WebElement focused_element = render_view()->GetFocusedElement();
112 if (focused_node.isNull()) 113 if (focused_element.isNull())
113 return; 114 return;
114 115
115 if (!render_view()->NodeContainsPoint(focused_node, gfx::Point(x, y))) 116 if (!GetScaledBoundingBox(render_view()->GetWebView()->pageScaleFactor(),
116 return; 117 &focused_element).Contains(x, y)) {
117
118 const WebInputElement input_element = GetTextWebInputElement(focused_node);
119 if (!input_element.isNull()) {
120 listener_->FormControlElementClicked(input_element,
121 was_focused_before_now_);
122 return; 118 return;
123 } 119 }
124 120
125 const WebTextAreaElement textarea_element = 121 clicked_node_ = focused_element;
126 GetWebTextAreaElement(focused_node);
127 if (!textarea_element.isNull()) {
128 listener_->FormControlElementClicked(textarea_element,
129 was_focused_before_now_);
130 }
131 }
132
133 void PageClickTracker::SetWasFocused() {
134 was_focused_before_now_ = true;
135 } 122 }
136 123
137 } // namespace autofill 124 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/page_click_tracker.h ('k') | content/browser/renderer_host/compositor_impl_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698