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 "content/public/renderer/render_view_observer.h"
12 #include "third_party/WebKit/public/web/WebDOMEventListener.h"
13 #include "third_party/WebKit/public/web/WebNode.h"
17 class PageClickListener;
19 // This class is responsible for tracking clicks on elements in web pages and
20 // notifiying the associated listener when a node is clicked.
21 // Compared to a simple WebDOMEventListener, it offers the added capability of
22 // notifying the listeners of whether the clicked node was already focused
23 // before it was clicked.
25 // This is useful for password/form autofill where we want to trigger a
26 // suggestion popup when a text input is clicked.
27 // It only notifies of WebInputElement that are text inputs being clicked, but
28 // could easily be changed to report click on any type of WebNode.
30 // There is one PageClickTracker per RenderView.
31 class PageClickTracker : public content::RenderViewObserver,
32 public WebKit::WebDOMEventListener {
34 // The |listener| will be notified when an element is clicked. It must
35 // outlive this class.
36 PageClickTracker(content::RenderView* render_view,
37 PageClickListener* listener);
38 virtual ~PageClickTracker();
41 // RenderView::Observer implementation.
42 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE;
43 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE;
44 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) OVERRIDE;
46 // WebKit::WebDOMEventListener implementation.
47 virtual void handleEvent(const WebKit::WebDOMEvent& event);
49 // Checks to see if a text field is losing focus and inform listeners if
51 void HandleTextFieldMaybeLosingFocus(
52 const WebKit::WebNode& newly_clicked_node);
54 // The last node that was clicked and had focus.
55 WebKit::WebNode last_node_clicked_;
57 // Whether the last clicked node had focused before it was clicked.
60 // The frames we are listening to for mouse events.
61 std::vector<WebKit::WebFrame*> tracked_frames_;
63 // The listener getting the actual notifications.
64 PageClickListener* listener_;
66 DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
69 } // namespace autofill
71 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_