Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(185)

Side by Side Diff: chrome/renderer/page_click_tracker.h

Issue 6151011: Introduce RenderView::Observer interface so that RenderView doesn't have to k... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/notification_provider.cc ('k') | chrome/renderer/page_click_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_RENDERER_PAGE_CLICK_TRACKER_H_ 5 #ifndef CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
6 #define CHROME_RENDERER_PAGE_CLICK_TRACKER_H_ 6 #define CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "chrome/renderer/render_view_observer.h"
12 #include "third_party/WebKit/WebKit/chromium/public/WebDOMEventListener.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebDOMEventListener.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
14 15
15 class PageClickListener; 16 class PageClickListener;
16 class RenderView;
17 17
18 namespace WebKit {
19 class WebFrame;
20 class WebDOMEvent;
21 class WebMouseEvent;
22 }
23 18
24 // This class is responsible for tracking clicks on elements in web pages and 19 // This class is responsible for tracking clicks on elements in web pages and
25 // notifiying the associated listener when a node is clicked. 20 // notifiying the associated listener when a node is clicked.
26 // Compared to a simple WebDOMEventListener, it offers the added capability of 21 // Compared to a simple WebDOMEventListener, it offers the added capability of
27 // notifying the listeners of whether the clicked node was already focused 22 // notifying the listeners of whether the clicked node was already focused
28 // before it was clicked. 23 // before it was clicked.
29 // 24 //
30 // This is useful for password/form autofill where we want to trigger a 25 // This is useful for password/form autofill where we want to trigger a
31 // suggestion popup when a text input is clicked. 26 // suggestion popup when a text input is clicked.
32 // It only notifies of WebInputElement that are text inputs being clicked, but 27 // It only notifies of WebInputElement that are text inputs being clicked, but
33 // could easily be changed to report click on any type of WebNode. 28 // could easily be changed to report click on any type of WebNode.
34 // 29 //
35 // There is one PageClickTracker per RenderView. 30 // There is one PageClickTracker per RenderView.
36 31 class PageClickTracker : public RenderViewObserver,
37 class PageClickTracker : public WebKit::WebDOMEventListener { 32 public WebKit::WebDOMEventListener {
38 public: 33 public:
39 explicit PageClickTracker(RenderView* render_view); 34 explicit PageClickTracker(RenderView* render_view);
40 virtual ~PageClickTracker(); 35 virtual ~PageClickTracker();
41 36
42 // Starts reporting node clicks for |frame| on the listener previously
43 // specified with SetListener().
44 void StartTrackingFrame(WebKit::WebFrame* frame);
45
46 // Stops reporting node clicks for |frame|. |frame_detached| should be true
47 // if the frame has already been detached.
48 void StopTrackingFrame(WebKit::WebFrame* frame, bool frame_detached);
49
50 // Called after the mouse event |event| has been processed by WebKit.
51 void DidHandleMouseEvent(const WebKit::WebMouseEvent& event);
52
53 // Adds/removes a listener for getting notification when an element is 37 // Adds/removes a listener for getting notification when an element is
54 // clicked. Note that the order of insertion is important as a listener when 38 // clicked. Note that the order of insertion is important as a listener when
55 // notified can decide to stop the propagation of the event (so that listeners 39 // notified can decide to stop the propagation of the event (so that listeners
56 // inserted after don't get the notification). 40 // inserted after don't get the notification).
57 void AddListener(PageClickListener* listener); 41 void AddListener(PageClickListener* listener);
58 void RemoveListener(PageClickListener* listener); 42 void RemoveListener(PageClickListener* listener);
59 43
60 private: 44 private:
45 // RenderView::Observer implementation.
46 virtual bool OnMessageReceived(const IPC::Message& message);
47 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame);
48 virtual void FrameDetached(WebKit::WebFrame* frame);
49
61 // WebKit::WebDOMEventListener implementation. 50 // WebKit::WebDOMEventListener implementation.
62 virtual void handleEvent(const WebKit::WebDOMEvent& event); 51 virtual void handleEvent(const WebKit::WebDOMEvent& event);
63 52
53 // Called after the mouse event |event| has been processed by WebKit.
54 void DidHandleMouseEvent(const WebKit::WebMouseEvent& event);
55
64 // Returns the currently focused node in the associated render view. 56 // Returns the currently focused node in the associated render view.
65 // That node may be null. 57 // That node may be null.
66 WebKit::WebNode GetFocusedNode(); 58 WebKit::WebNode GetFocusedNode();
67 59
68 // The last node that was clicked and had focus. 60 // The last node that was clicked and had focus.
69 WebKit::WebNode last_node_clicked_; 61 WebKit::WebNode last_node_clicked_;
70 62
71 // The render view we are associated with.
72 RenderView* render_view_;
73
74 // Whether the last clicked node had focused before it was clicked. 63 // Whether the last clicked node had focused before it was clicked.
75 bool was_focused_; 64 bool was_focused_;
76 65
77 // The frames we are listening to for mouse events. 66 // The frames we are listening to for mouse events.
78 typedef std::vector<WebKit::WebFrame*> FrameList; 67 typedef std::vector<WebKit::WebFrame*> FrameList;
79 FrameList tracked_frames_; 68 FrameList tracked_frames_;
80 69
81 // The listener getting the actual notifications. 70 // The listener getting the actual notifications.
82 ObserverList<PageClickListener> listeners_; 71 ObserverList<PageClickListener> listeners_;
83 72
84 DISALLOW_COPY_AND_ASSIGN(PageClickTracker); 73 DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
85 }; 74 };
86 75
87 #endif // CHROME_RENDERER_PAGE_CLICK_TRACKER_H_ 76 #endif // CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
OLDNEW
« no previous file with comments | « chrome/renderer/notification_provider.cc ('k') | chrome/renderer/page_click_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698