• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_
7 
8 #include <vector>
9 
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"
14 
15 namespace autofill {
16 
17 class PageClickListener;
18 
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.
24 //
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.
29 //
30 // There is one PageClickTracker per RenderView.
31 class PageClickTracker : public content::RenderViewObserver,
32                          public blink::WebDOMEventListener {
33  public:
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();
39 
40  private:
41   // RenderView::Observer implementation.
42   virtual void DidFinishDocumentLoad(blink::WebFrame* frame) OVERRIDE;
43   virtual void FrameDetached(blink::WebFrame* frame) OVERRIDE;
44   virtual void DidHandleMouseEvent(const blink::WebMouseEvent& event) OVERRIDE;
45 
46   // blink::WebDOMEventListener implementation.
47   virtual void handleEvent(const blink::WebDOMEvent& event);
48 
49   // Checks to see if a text field is losing focus and inform listeners if
50   // it is.
51   void HandleTextFieldMaybeLosingFocus(
52       const blink::WebNode& newly_clicked_node);
53 
54   // The last node that was clicked and had focus.
55   blink::WebNode last_node_clicked_;
56 
57   // Whether the last clicked node had focused before it was clicked.
58   bool was_focused_;
59 
60   // The frames we are listening to for mouse events.
61   std::vector<blink::WebFrame*> tracked_frames_;
62 
63   // The listener getting the actual notifications.
64   PageClickListener* listener_;
65 
66   DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
67 };
68 
69 }  // namespace autofill
70 
71 #endif  // COMPONENTS_AUTOFILL_CONTENT_RENDERER_PAGE_CLICK_TRACKER_H_
72