summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/page_click_tracker.h
diff options
context:
space:
mode:
authorjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-05 04:38:06 +0000
committerjcivelli@chromium.org <jcivelli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-05 04:38:06 +0000
commit6a8ddba5ea1e8972c2954b138aeb14d77a548a3c (patch)
tree4c1a21857eca96cea8a8743a28209041de389699 /chrome/renderer/page_click_tracker.h
parente333e8d07ee32668fc132a21c13cdf674443d1e9 (diff)
downloadchromium_src-6a8ddba5ea1e8972c2954b138aeb14d77a548a3c.zip
chromium_src-6a8ddba5ea1e8972c2954b138aeb14d77a548a3c.tar.gz
chromium_src-6a8ddba5ea1e8972c2954b138aeb14d77a548a3c.tar.bz2
Adding a class to track when a node in a page gets clicked.
This is going to be used by the password/form autofill to trigger the suggestion popup, as part of the effort in moving that code out of WebKit. BUG=None TEST=Run unit-tests. Review URL: http://codereview.chromium.org/3090007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/page_click_tracker.h')
-rw-r--r--chrome/renderer/page_click_tracker.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/renderer/page_click_tracker.h b/chrome/renderer/page_click_tracker.h
new file mode 100644
index 0000000..492237c
--- /dev/null
+++ b/chrome/renderer/page_click_tracker.h
@@ -0,0 +1,87 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
+#define CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
+
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/observer_list.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebDOMEventListener.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
+
+class PageClickListener;
+class RenderView;
+
+namespace WebKit {
+class WebFrame;
+class WebDOMEvent;
+class WebMouseEvent;
+}
+
+// This class is responsible for tracking clicks on elements in web pages and
+// notifiying the associated listener when a node is clicked.
+// Compared to a simple WebDOMEventListener, it offers the added capability of
+// notifying the listeners of whether the clicked node was already focused
+// before it was clicked.
+//
+// This is useful for password/form autofill where we want to trigger a
+// suggestion popup when a text input is clicked.
+// It only notifies of WebInputElement that are text inputs being clicked, but
+// could easily be changed to report click on any type of WebNode.
+//
+// There is one PageClickTracker per RenderView.
+
+class PageClickTracker : public WebKit::WebDOMEventListener {
+ public:
+ explicit PageClickTracker(RenderView* render_view);
+ virtual ~PageClickTracker();
+
+ // Starts reporting node clicks for |frame| on the listener previously
+ // specified with SetListener().
+ void StartTrackingFrame(WebKit::WebFrame* frame);
+
+ // Stops reporting node clicks for |frame|. |frame_detached| should be true
+ // if the frame has already been detached.
+ void StopTrackingFrame(WebKit::WebFrame* frame, bool frame_detached);
+
+ // Called after the mouse event |event| has been processed by WebKit.
+ void DidHandleMouseEvent(const WebKit::WebMouseEvent& event);
+
+ // Adds/removes a listener for getting notification when an element is
+ // clicked. Note that the order of insertion is important as a listener when
+ // notified can decide to stop the propagation of the event (so that listeners
+ // inserted after don't get the notification).
+ void AddListener(PageClickListener* listener);
+ void RemoveListener(PageClickListener* listener);
+
+ private:
+ // WebKit::WebDOMEventListener implementation.
+ virtual void handleEvent(const WebKit::WebDOMEvent& event);
+
+ // Returns the currently focused node in the associated render view.
+ // That node may be null.
+ WebKit::WebNode GetFocusedNode();
+
+ // The last node that was clicked and had focus.
+ WebKit::WebNode last_node_clicked_;
+
+ // The render view we are associated with.
+ RenderView* render_view_;
+
+ // Whether the last clicked node had focused before it was clicked.
+ bool was_focused_;
+
+ // The frames we are listening to for mouse events.
+ typedef std::vector<WebKit::WebFrame*> FrameList;
+ FrameList tracked_frames_;
+
+ // The listener getting the actual notifications.
+ ObserverList<PageClickListener> listeners_;
+
+ DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
+};
+
+#endif // CHROME_RENDERER_PAGE_CLICK_TRACKER_H_