blob: 360082a78dfd939808d021e39254e9bd6b5678d4 [file] [log] [blame]
[email protected]65ec8db2011-11-04 14:50:441// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]6a8ddba52010-09-05 04:38:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
6#define CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "base/observer_list.h"
[email protected]3a034ebb2011-10-03 19:19:4412#include "content/public/renderer/render_view_observer.h"
[email protected]8bd0fe62011-01-17 06:44:3713#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEventListener.h"
14#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
[email protected]6a8ddba52010-09-05 04:38:0615
16class PageClickListener;
[email protected]6a8ddba52010-09-05 04:38:0617
[email protected]6a8ddba52010-09-05 04:38:0618
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.
[email protected]3a034ebb2011-10-03 19:19:4431class PageClickTracker : public content::RenderViewObserver,
[email protected]676126f72011-01-15 00:03:5132 public WebKit::WebDOMEventListener {
[email protected]6a8ddba52010-09-05 04:38:0633 public:
[email protected]a2ef54c2011-10-10 16:20:3134 explicit PageClickTracker(content::RenderView* render_view);
[email protected]6a8ddba52010-09-05 04:38:0635 virtual ~PageClickTracker();
36
[email protected]6a8ddba52010-09-05 04:38:0637 // Adds/removes a listener for getting notification when an element is
38 // clicked. Note that the order of insertion is important as a listener when
39 // notified can decide to stop the propagation of the event (so that listeners
40 // inserted after don't get the notification).
41 void AddListener(PageClickListener* listener);
42 void RemoveListener(PageClickListener* listener);
43
44 private:
[email protected]676126f72011-01-15 00:03:5145 // RenderView::Observer implementation.
[email protected]77fc9b92011-10-15 16:20:3746 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE;
47 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE;
48 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) OVERRIDE;
[email protected]676126f72011-01-15 00:03:5149
[email protected]6a8ddba52010-09-05 04:38:0650 // WebKit::WebDOMEventListener implementation.
51 virtual void handleEvent(const WebKit::WebDOMEvent& event);
52
[email protected]65ec8db2011-11-04 14:50:4453 // Checks to see if a text field is losing focus and inform listeners if
54 // it is.
55 void HandleTextFieldMaybeLosingFocus(
56 const WebKit::WebNode& newly_clicked_node);
57
[email protected]6a8ddba52010-09-05 04:38:0658 // The last node that was clicked and had focus.
59 WebKit::WebNode last_node_clicked_;
60
[email protected]6a8ddba52010-09-05 04:38:0661 // Whether the last clicked node had focused before it was clicked.
62 bool was_focused_;
63
64 // The frames we are listening to for mouse events.
65 typedef std::vector<WebKit::WebFrame*> FrameList;
66 FrameList tracked_frames_;
67
68 // The listener getting the actual notifications.
69 ObserverList<PageClickListener> listeners_;
70
71 DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
72};
73
74#endif // CHROME_RENDERER_PAGE_CLICK_TRACKER_H_