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

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

Issue 7064012: In PageClickTracker, only store last clicked node if it's significant. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 9 years, 7 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 | « no previous file | no next file » | 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 #include "chrome/renderer/page_click_tracker.h" 5 #include "chrome/renderer/page_click_tracker.h"
6 6
7 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 #include "chrome/renderer/page_click_listener.h" 8 #include "chrome/renderer/page_click_listener.h"
9 #include "content/common/view_messages.h" 9 #include "content/common/view_messages.h"
10 #include "content/renderer/render_view.h" 10 #include "content/renderer/render_view.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMouseEvent.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMouseEvent.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
17 17
18 using WebKit::WebDOMEvent; 18 using WebKit::WebDOMEvent;
19 using WebKit::WebDOMMouseEvent; 19 using WebKit::WebDOMMouseEvent;
20 using WebKit::WebElement; 20 using WebKit::WebElement;
21 using WebKit::WebFormControlElement; 21 using WebKit::WebFormControlElement;
22 using WebKit::WebFrame; 22 using WebKit::WebFrame;
23 using WebKit::WebInputElement; 23 using WebKit::WebInputElement;
24 using WebKit::WebInputEvent; 24 using WebKit::WebInputEvent;
25 using WebKit::WebMouseEvent; 25 using WebKit::WebMouseEvent;
26 using WebKit::WebNode; 26 using WebKit::WebNode;
27 using WebKit::WebString; 27 using WebKit::WebString;
28 using WebKit::WebView; 28 using WebKit::WebView;
29 29
30 namespace {
31
32 // Returns whether |node| is a text input element.
Jay Civelli 2011/05/24 04:47:25 I wonder if we need this method. May be GetTextWeb
dpanpong 2011/05/24 17:10:26 I like that much better. Done.
33 bool IsTextWebInputElement(const WebNode& node) {
34 if (!node.isElementNode())
dpanpong 2011/05/24 01:21:40 The logic in this function moved from DidHandleMou
35 return false;
36 const WebElement element = node.toConst<WebElement>();
37 if (!element.isFormControlElement())
38 return false;
39 const WebFormControlElement control =
40 element.toConst<WebFormControlElement>();
41 if (control.formControlType() != WebString::fromUTF8("text"))
42 return false;
43 return true;
44 }
45
46 // Casts |node| to a WebInputElement.
47 // |node| must be a web input element.
48 const WebInputElement GetTextWebInputElement(const WebNode& node) {
49 const WebElement element = node.toConst<WebElement>();
50 const WebFormControlElement control =
51 element.toConst<WebFormControlElement>();
52 return element.toConst<WebInputElement>();
53 }
54
55 } // namespace
56
30 PageClickTracker::PageClickTracker(RenderView* render_view) 57 PageClickTracker::PageClickTracker(RenderView* render_view)
31 : RenderViewObserver(render_view), 58 : RenderViewObserver(render_view),
32 was_focused_(false) { 59 was_focused_(false) {
33 } 60 }
34 61
35 PageClickTracker::~PageClickTracker() { 62 PageClickTracker::~PageClickTracker() {
36 // Note that even though RenderView calls FrameDetached when notified that 63 // Note that even though RenderView calls FrameDetached when notified that
37 // a frame was closed, it might not always get that notification from WebKit 64 // a frame was closed, it might not always get that notification from WebKit
38 // for all frames. 65 // for all frames.
39 // By the time we get here, the frame could have been destroyed so we cannot 66 // By the time we get here, the frame could have been destroyed so we cannot
40 // unregister listeners in frames remaining in tracked_frames_ as they might 67 // unregister listeners in frames remaining in tracked_frames_ as they might
41 // be invalid. 68 // be invalid.
42 } 69 }
43 70
44 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { 71 void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) {
45 if (event.type != WebInputEvent::MouseDown || 72 if (event.type != WebInputEvent::MouseDown ||
46 last_node_clicked_.isNull()) { 73 last_node_clicked_.isNull()) {
47 return; 74 return;
48 } 75 }
49 76
50 // We are only interested in text field clicks. 77 // We are only interested in text field clicks.
51 if (!last_node_clicked_.isElementNode()) 78 if (!IsTextWebInputElement(last_node_clicked_))
52 return;
53 const WebElement& element = last_node_clicked_.toConst<WebElement>();
54 if (!element.isFormControlElement())
55 return;
56 const WebFormControlElement& control =
57 element.toConst<WebFormControlElement>();
58 if (control.formControlType() != WebString::fromUTF8("text"))
59 return; 79 return;
60 80
61 const WebInputElement& input_element = element.toConst<WebInputElement>(); 81 const WebInputElement input_element =
82 GetTextWebInputElement(last_node_clicked_);
62 83
63 bool is_focused = (last_node_clicked_ == GetFocusedNode()); 84 bool is_focused = (last_node_clicked_ == GetFocusedNode());
64 ObserverListBase<PageClickListener>::Iterator it(listeners_); 85 ObserverListBase<PageClickListener>::Iterator it(listeners_);
65 PageClickListener* listener; 86 PageClickListener* listener;
66 while ((listener = it.GetNext()) != NULL) { 87 while ((listener = it.GetNext()) != NULL) {
67 if (listener->InputElementClicked(input_element, was_focused_, is_focused)) 88 if (listener->InputElementClicked(input_element, was_focused_, is_focused))
68 break; 89 break;
69 } 90 }
70 91
71 last_node_clicked_.reset(); 92 last_node_clicked_.reset();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 return; 139 return;
119 140
120 const WebDOMMouseEvent mouse_event = event.toConst<WebDOMMouseEvent>(); 141 const WebDOMMouseEvent mouse_event = event.toConst<WebDOMMouseEvent>();
121 DCHECK(mouse_event.buttonDown()); 142 DCHECK(mouse_event.buttonDown());
122 if (mouse_event.button() != 0) 143 if (mouse_event.button() != 0)
123 return; // We are only interested in left clicks. 144 return; // We are only interested in left clicks.
124 145
125 // Remember which node has focus before the click is processed. 146 // Remember which node has focus before the click is processed.
126 // We'll get a notification once the mouse event has been processed 147 // We'll get a notification once the mouse event has been processed
127 // (DidHandleMouseEvent), we'll notify the listener at that point. 148 // (DidHandleMouseEvent), we'll notify the listener at that point.
128 last_node_clicked_ = mouse_event.target(); 149 WebNode node = mouse_event.target();
150 // We are only interested in text field clicks.
151 if (!IsTextWebInputElement(node))
152 return;
153
154 last_node_clicked_ = node;
129 was_focused_ = (GetFocusedNode() == last_node_clicked_); 155 was_focused_ = (GetFocusedNode() == last_node_clicked_);
130 } 156 }
131 157
132 WebNode PageClickTracker::GetFocusedNode() { 158 WebNode PageClickTracker::GetFocusedNode() {
133 WebView* web_view = render_view()->webview(); 159 WebView* web_view = render_view()->webview();
134 if (!web_view) 160 if (!web_view)
135 return WebNode(); 161 return WebNode();
136 162
137 WebFrame* web_frame = web_view->focusedFrame(); 163 WebFrame* web_frame = web_view->focusedFrame();
138 if (!web_frame) 164 if (!web_frame)
139 return WebNode(); 165 return WebNode();
140 166
141 return web_frame->document().focusedNode(); 167 return web_frame->document().focusedNode();
142 } 168 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698