Fixed service side implementation of glTexStorage2DEXT to only initialize the number of
[chromium-blink-merge.git] / chrome / renderer / page_click_tracker.h
blob360082a78dfd939808d021e39254e9bd6b5678d4
1 // Copyright (c) 2011 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 CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
6 #define CHROME_RENDERER_PAGE_CLICK_TRACKER_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "content/public/renderer/render_view_observer.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEventListener.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
16 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 {
33 public:
34 explicit PageClickTracker(content::RenderView* render_view);
35 virtual ~PageClickTracker();
37 // 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);
44 private:
45 // RenderView::Observer implementation.
46 virtual void DidFinishDocumentLoad(WebKit::WebFrame* frame) OVERRIDE;
47 virtual void FrameDetached(WebKit::WebFrame* frame) OVERRIDE;
48 virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event) OVERRIDE;
50 // WebKit::WebDOMEventListener implementation.
51 virtual void handleEvent(const WebKit::WebDOMEvent& event);
53 // 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);
58 // The last node that was clicked and had focus.
59 WebKit::WebNode last_node_clicked_;
61 // Whether the last clicked node had focused before it was clicked.
62 bool was_focused_;
64 // The frames we are listening to for mouse events.
65 typedef std::vector<WebKit::WebFrame*> FrameList;
66 FrameList tracked_frames_;
68 // The listener getting the actual notifications.
69 ObserverList<PageClickListener> listeners_;
71 DISALLOW_COPY_AND_ASSIGN(PageClickTracker);
74 #endif // CHROME_RENDERER_PAGE_CLICK_TRACKER_H_