| 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_frame_observer.h" |
| 12 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
| 13 #include "third_party/WebKit/public/web/WebNode.h" | 14 #include "third_party/WebKit/public/web/WebNode.h" |
| 14 | 15 |
| 15 namespace autofill { | 16 namespace autofill { |
| 16 | 17 |
| 17 class PageClickListener; | 18 class PageClickListener; |
| 18 | 19 |
| 19 // This class is responsible notifying the associated listener when a node is | 20 // This class is responsible notifying the associated listener when a node is |
| 20 // clicked or tapped. It also tracks whether a node was focused before the event | 21 // clicked or tapped. It also tracks whether a node was focused before the event |
| 21 // was handled. | 22 // was handled. |
| 22 // | 23 // |
| 23 // This is useful for password/form autofill where we want to trigger a | 24 // This is useful for password/form autofill where we want to trigger a |
| 24 // suggestion popup when a text input is clicked. | 25 // suggestion popup when a text input is clicked. |
| 25 // | 26 // |
| 26 // There is one PageClickTracker per AutofillAgent. | 27 // There is one PageClickTracker per AutofillAgent. |
| 27 // TODO(estade): migrate to content::RenderFrameObserver. | 28 class PageClickTracker : public content::RenderFrameObserver { |
| 28 class PageClickTracker : public content::RenderViewObserver { | |
| 29 public: | 29 public: |
| 30 // 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 |
| 31 // outlive this class. | 31 // outlive this class. |
| 32 PageClickTracker(content::RenderView* render_view, | 32 PageClickTracker(content::RenderFrame* render_frame, |
| 33 PageClickListener* listener); | 33 PageClickListener* listener); |
| 34 ~PageClickTracker() override; | 34 ~PageClickTracker() override; |
| 35 | 35 |
| 36 private: | 36 private: |
| 37 // RenderView::Observer implementation. | 37 // TODO(estade): migrate this stuff to content::RenderFrameObserver, and |
| 38 // remove this class. |
| 39 class Legacy : public content::RenderViewObserver { |
| 40 public: |
| 41 Legacy(PageClickTracker* tracker); |
| 42 |
| 43 // RenderViewObserver implementation. |
| 44 void OnDestruct() override; |
| 45 void DidHandleMouseEvent(const blink::WebMouseEvent& event) override; |
| 46 void DidHandleGestureEvent(const blink::WebGestureEvent& event) override; |
| 47 void FocusChangeComplete() override; |
| 48 |
| 49 private: |
| 50 PageClickTracker* tracker_; |
| 51 }; |
| 52 friend class Legacy; |
| 53 |
| 54 // RenderFrameObserver implementation. |
| 38 void OnDestruct() override; | 55 void OnDestruct() override; |
| 39 void DidHandleMouseEvent(const blink::WebMouseEvent& event) override; | |
| 40 void DidHandleGestureEvent(const blink::WebGestureEvent& event) override; | |
| 41 void FocusedNodeChanged(const blink::WebNode& node) override; | 56 void FocusedNodeChanged(const blink::WebNode& node) override; |
| 42 void FocusChangeComplete() override; | 57 |
| 58 // RenderViewObserver methods forwarded from Legacy. Should be |
| 59 // merged into RenderFrameObserver. |
| 60 void DidHandleMouseEvent(const blink::WebMouseEvent& event); |
| 61 void DidHandleGestureEvent(const blink::WebGestureEvent& event); |
| 62 void FocusChangeComplete(); |
| 43 | 63 |
| 44 // Called there is a tap or click at |x|, |y|. | 64 // Called there is a tap or click at |x|, |y|. |
| 45 void PotentialActivationAt(int x, int y); | 65 void PotentialActivationAt(int x, int y); |
| 46 | 66 |
| 47 // The node that was clicked. Non-null only when the animations caused by | 67 // True when the last click was on the focused node. |
| 48 // focus change are still ongoing. | 68 bool focused_node_was_last_clicked_; |
| 49 blink::WebNode clicked_node_; | |
| 50 | 69 |
| 51 // This is set to false when the focus changes, then set back to true soon | 70 // This is set to false when the focus changes, then set back to true soon |
| 52 // afterwards. This helps track whether an event happened after a node was | 71 // afterwards. This helps track whether an event happened after a node was |
| 53 // already focused, or if it caused the focus to change. | 72 // already focused, or if it caused the focus to change. |
| 54 bool was_focused_before_now_; | 73 bool was_focused_before_now_; |
| 55 | 74 |
| 56 // The listener getting the actual notifications. | 75 // The listener getting the actual notifications. |
| 57 PageClickListener* listener_; | 76 PageClickListener* listener_; |
| 58 | 77 |
| 78 Legacy legacy_; |
| 79 |
| 59 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); | 80 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); |
| 60 }; | 81 }; |
| 61 | 82 |
| 62 } // namespace autofill | 83 } // namespace autofill |
| 63 | 84 |
| 64 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ | 85 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ |
| OLD | NEW |