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 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/public/renderer/render_view_observer.h" | 12 #include "content/public/renderer/render_view_observer.h" |
13 #include "third_party/WebKit/public/web/WebNode.h" | 13 #include "third_party/WebKit/public/web/WebNode.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 | 16 |
17 class PageClickListener; | 17 class PageClickListener; |
18 | 18 |
19 // This class is responsible notifiying the associated listener when a node is | 19 // This class is responsible notifiying the associated listener when a node is |
20 // clicked or tapped. It also tracks whether a node was focused before the event | 20 // clicked or tapped. It also tracks whether a node was focused before the event |
21 // was handled. | 21 // was handled. |
22 // | 22 // |
23 // This is useful for password/form autofill where we want to trigger a | 23 // This is useful for password/form autofill where we want to trigger a |
24 // suggestion popup when a text input is clicked. | 24 // suggestion popup when a text input is clicked. |
25 // | 25 // |
26 // There is one PageClickTracker per RenderView. | 26 // There is one PageClickTracker per AutofillAgent. |
| 27 // TODO(estade): migrate to content::RenderFrameObserver. |
27 class PageClickTracker : public content::RenderViewObserver { | 28 class PageClickTracker : public content::RenderViewObserver { |
28 public: | 29 public: |
29 // The |listener| will be notified when an element is clicked. It must | 30 // The |listener| will be notified when an element is clicked. It must |
30 // outlive this class. | 31 // outlive this class. |
31 PageClickTracker(content::RenderView* render_view, | 32 PageClickTracker(content::RenderView* render_view, |
32 PageClickListener* listener); | 33 PageClickListener* listener); |
33 ~PageClickTracker() override; | 34 ~PageClickTracker() override; |
34 | 35 |
35 private: | 36 private: |
36 // RenderView::Observer implementation. | 37 // RenderView::Observer implementation. |
| 38 void OnDestruct() override; |
37 void DidHandleMouseEvent(const blink::WebMouseEvent& event) override; | 39 void DidHandleMouseEvent(const blink::WebMouseEvent& event) override; |
38 void DidHandleGestureEvent(const blink::WebGestureEvent& event) override; | 40 void DidHandleGestureEvent(const blink::WebGestureEvent& event) override; |
39 void FocusedNodeChanged(const blink::WebNode& node) override; | 41 void FocusedNodeChanged(const blink::WebNode& node) override; |
40 | 42 |
41 // Called there is a tap or click at |x|, |y|. | 43 // Called there is a tap or click at |x|, |y|. |
42 void PotentialActivationAt(int x, int y); | 44 void PotentialActivationAt(int x, int y); |
43 | 45 |
44 // Sets |was_focused_before_now_| to true. | 46 // Sets |was_focused_before_now_| to true. |
45 void SetWasFocused(); | 47 void SetWasFocused(); |
46 | 48 |
47 // This is set to false when the focus changes, then set back to true soon | 49 // This is set to false when the focus changes, then set back to true soon |
48 // afterwards. This helps track whether an event happened after a node was | 50 // afterwards. This helps track whether an event happened after a node was |
49 // already focused, or if it caused the focus to change. | 51 // already focused, or if it caused the focus to change. |
50 bool was_focused_before_now_; | 52 bool was_focused_before_now_; |
51 | 53 |
52 // The listener getting the actual notifications. | 54 // The listener getting the actual notifications. |
53 PageClickListener* listener_; | 55 PageClickListener* listener_; |
54 | 56 |
55 base::WeakPtrFactory<PageClickTracker> weak_ptr_factory_; | 57 base::WeakPtrFactory<PageClickTracker> weak_ptr_factory_; |
56 | 58 |
57 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); | 59 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); |
58 }; | 60 }; |
59 | 61 |
60 } // namespace autofill | 62 } // namespace autofill |
61 | 63 |
62 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ | 64 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ |
OLD | NEW |