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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_
10 #include "base/basictypes.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"
18 class PageClickListener
;
20 // 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
24 // This is useful for password/form autofill where we want to trigger a
25 // suggestion popup when a text input is clicked.
27 // There is one PageClickTracker per AutofillAgent.
28 class PageClickTracker
: public content::RenderFrameObserver
{
30 // The |listener| will be notified when an element is clicked. It must
31 // outlive this class.
32 PageClickTracker(content::RenderFrame
* render_frame
,
33 PageClickListener
* listener
);
34 ~PageClickTracker() override
;
37 // TODO(estade): migrate this stuff to content::RenderFrameObserver, and
39 class Legacy
: public content::RenderViewObserver
{
41 Legacy(PageClickTracker
* tracker
);
43 // RenderViewObserver implementation.
44 void OnDestruct() override
;
45 void OnMouseDown(const blink::WebNode
& mouse_down_node
) override
;
46 void FocusChangeComplete() override
;
49 PageClickTracker
* tracker_
;
53 // RenderFrameObserver implementation.
54 void FocusedNodeChanged(const blink::WebNode
& node
) override
;
56 // RenderViewObserver methods forwarded from Legacy. Should be
57 // merged into RenderFrameObserver.
58 void OnMouseDown(const blink::WebNode
& mouse_down_node
);
59 void FocusChangeComplete();
60 void DoFocusChangeComplete();
62 // True when the last click was on the focused node.
63 bool focused_node_was_last_clicked_
;
65 // This is set to false when the focus changes, then set back to true soon
66 // afterwards. This helps track whether an event happened after a node was
67 // already focused, or if it caused the focus to change.
68 bool was_focused_before_now_
;
70 // The listener getting the actual notifications.
71 PageClickListener
* listener_
;
75 DISALLOW_COPY_AND_ASSIGN(PageClickTracker
);
78 } // namespace autofill
80 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_