| 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/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" | |
| 13 #include "content/public/renderer/render_view_observer.h" | |
| 14 #include "third_party/WebKit/public/web/WebNode.h" | 12 #include "third_party/WebKit/public/web/WebNode.h" |
| 15 | 13 |
| 14 namespace content { |
| 15 class RenderFrame; |
| 16 } |
| 17 |
| 16 namespace autofill { | 18 namespace autofill { |
| 17 | 19 |
| 18 class PageClickListener; | 20 class PageClickListener; |
| 19 | 21 |
| 20 // This class is responsible notifying the associated listener when a node is | 22 // This class is responsible notifying the associated listener when a node is |
| 21 // clicked or tapped. It also tracks whether a node was focused before the event | 23 // clicked or tapped. It also tracks whether a node was focused before the event |
| 22 // was handled. | 24 // was handled. |
| 23 // | 25 // |
| 24 // This is useful for password/form autofill where we want to trigger a | 26 // This is useful for password/form autofill where we want to trigger a |
| 25 // suggestion popup when a text input is clicked. | 27 // suggestion popup when a text input is clicked. |
| 26 // | 28 // |
| 27 // There is one PageClickTracker per AutofillAgent. | 29 // There is one PageClickTracker per AutofillAgent. |
| 28 class PageClickTracker : public content::RenderFrameObserver { | 30 class PageClickTracker { |
| 29 public: | 31 public: |
| 30 // The |listener| will be notified when an element is clicked. It must | 32 // The |listener| will be notified when an element is clicked. It must |
| 31 // outlive this class. | 33 // outlive this class. |
| 32 PageClickTracker(content::RenderFrame* render_frame, | 34 PageClickTracker(content::RenderFrame* render_frame, |
| 33 PageClickListener* listener); | 35 PageClickListener* listener); |
| 34 ~PageClickTracker() override; | 36 ~PageClickTracker(); |
| 37 |
| 38 void FocusedNodeChanged(const blink::WebNode& node); |
| 39 void DidCompleteFocusChangeInFrame(); |
| 40 void DidReceiveLeftMouseDownOrGestureTapInNode(const blink::WebNode& node); |
| 41 |
| 42 content::RenderFrame* render_frame() const { return render_frame_; } |
| 35 | 43 |
| 36 private: | 44 private: |
| 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 OnMouseDown(const blink::WebNode& mouse_down_node) override; | |
| 46 void FocusChangeComplete() override; | |
| 47 | |
| 48 private: | |
| 49 PageClickTracker* tracker_; | |
| 50 }; | |
| 51 friend class Legacy; | |
| 52 | |
| 53 // RenderFrameObserver implementation. | |
| 54 void FocusedNodeChanged(const blink::WebNode& node) override; | |
| 55 void OnDestruct() override; | |
| 56 | |
| 57 // RenderViewObserver methods forwarded from Legacy. Should be | |
| 58 // merged into RenderFrameObserver. | |
| 59 void OnMouseDown(const blink::WebNode& mouse_down_node); | |
| 60 void FocusChangeComplete(); | |
| 61 void DoFocusChangeComplete(); | 45 void DoFocusChangeComplete(); |
| 62 | 46 |
| 63 // True when the last click was on the focused node. | 47 // True when the last click was on the focused node. |
| 64 bool focused_node_was_last_clicked_; | 48 bool focused_node_was_last_clicked_; |
| 65 | 49 |
| 66 // This is set to false when the focus changes, then set back to true soon | 50 // This is set to false when the focus changes, then set back to true soon |
| 67 // afterwards. This helps track whether an event happened after a node was | 51 // afterwards. This helps track whether an event happened after a node was |
| 68 // already focused, or if it caused the focus to change. | 52 // already focused, or if it caused the focus to change. |
| 69 bool was_focused_before_now_; | 53 bool was_focused_before_now_; |
| 70 | 54 |
| 71 // The listener getting the actual notifications. | 55 // The listener getting the actual notifications. |
| 72 PageClickListener* listener_; | 56 PageClickListener* listener_; |
| 73 | 57 |
| 74 Legacy legacy_; | 58 content::RenderFrame* const render_frame_; |
| 75 | 59 |
| 76 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); | 60 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); |
| 77 }; | 61 }; |
| 78 | 62 |
| 79 } // namespace autofill | 63 } // namespace autofill |
| 80 | 64 |
| 81 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ | 65 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_ |
| OLD | NEW |