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

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

Issue 8351009: Updating PageClickTracker to Notify listeners When Text Input Loses Focus. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Making browser_tests work on all platforms Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
(...skipping 26 matching lines...) Expand all
37 const WebElement element = node.toConst<WebElement>(); 37 const WebElement element = node.toConst<WebElement>();
38 if (!element.isFormControlElement()) 38 if (!element.isFormControlElement())
39 return WebInputElement(); 39 return WebInputElement();
40 const WebFormControlElement control = 40 const WebFormControlElement control =
41 element.toConst<WebFormControlElement>(); 41 element.toConst<WebFormControlElement>();
42 if (control.formControlType() != WebString::fromUTF8("text")) 42 if (control.formControlType() != WebString::fromUTF8("text"))
43 return WebInputElement(); 43 return WebInputElement();
44 return element.toConst<WebInputElement>(); 44 return element.toConst<WebInputElement>();
45 } 45 }
46 46
47 // Checks to see if a text field was the previously selected node and is now
48 // losing its focus.
49 bool DidSelectedTextFieldLoseFocus(const WebNode& newly_clicked_node) {
50 WebKit::WebNode focused_node = newly_clicked_node.document().focusedNode();
51
52 if (focused_node.isNull() || GetTextWebInputElement(focused_node).isNull())
53 return false;
54
55 return focused_node != newly_clicked_node;
56 }
57
47 } // namespace 58 } // namespace
48 59
49 PageClickTracker::PageClickTracker(content::RenderView* render_view) 60 PageClickTracker::PageClickTracker(content::RenderView* render_view)
50 : content::RenderViewObserver(render_view), 61 : content::RenderViewObserver(render_view),
51 was_focused_(false) { 62 was_focused_(false) {
52 } 63 }
53 64
54 PageClickTracker::~PageClickTracker() { 65 PageClickTracker::~PageClickTracker() {
55 // Note that even though RenderView calls FrameDetached when notified that 66 // Note that even though RenderView calls FrameDetached when notified that
56 // a frame was closed, it might not always get that notification from WebKit 67 // a frame was closed, it might not always get that notification from WebKit
(...skipping 15 matching lines...) Expand all
72 if (input_element.isNull()) 83 if (input_element.isNull())
73 return; 84 return;
74 85
75 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode()); 86 bool is_focused = (last_node_clicked_ == render_view()->GetFocusedNode());
76 ObserverListBase<PageClickListener>::Iterator it(listeners_); 87 ObserverListBase<PageClickListener>::Iterator it(listeners_);
77 PageClickListener* listener; 88 PageClickListener* listener;
78 while ((listener = it.GetNext()) != NULL) { 89 while ((listener = it.GetNext()) != NULL) {
79 if (listener->InputElementClicked(input_element, was_focused_, is_focused)) 90 if (listener->InputElementClicked(input_element, was_focused_, is_focused))
80 break; 91 break;
81 } 92 }
82
83 last_node_clicked_.reset();
84 } 93 }
85 94
86 void PageClickTracker::AddListener(PageClickListener* listener) { 95 void PageClickTracker::AddListener(PageClickListener* listener) {
87 listeners_.AddObserver(listener); 96 listeners_.AddObserver(listener);
88 } 97 }
89 98
90 void PageClickTracker::RemoveListener(PageClickListener* listener) { 99 void PageClickTracker::RemoveListener(PageClickListener* listener) {
91 listeners_.RemoveObserver(listener); 100 listeners_.RemoveObserver(listener);
92 } 101 }
93 102
(...skipping 22 matching lines...) Expand all
116 125
117 const WebDOMMouseEvent mouse_event = event.toConst<WebDOMMouseEvent>(); 126 const WebDOMMouseEvent mouse_event = event.toConst<WebDOMMouseEvent>();
118 DCHECK(mouse_event.buttonDown()); 127 DCHECK(mouse_event.buttonDown());
119 if (mouse_event.button() != 0) 128 if (mouse_event.button() != 0)
120 return; // We are only interested in left clicks. 129 return; // We are only interested in left clicks.
121 130
122 // Remember which node has focus before the click is processed. 131 // Remember which node has focus before the click is processed.
123 // We'll get a notification once the mouse event has been processed 132 // We'll get a notification once the mouse event has been processed
124 // (DidHandleMouseEvent), we'll notify the listener at that point. 133 // (DidHandleMouseEvent), we'll notify the listener at that point.
125 WebNode node = mouse_event.target(); 134 WebNode node = mouse_event.target();
135
136 HandleTextFieldMaybeLosingFocus(node);
137
126 // We are only interested in text field clicks. 138 // We are only interested in text field clicks.
127 if (GetTextWebInputElement(node).isNull()) 139 if (GetTextWebInputElement(node).isNull())
128 return; 140 return;
129 141
130 last_node_clicked_ = node; 142 last_node_clicked_ = node;
131 was_focused_ = (render_view()->GetFocusedNode() == last_node_clicked_); 143 was_focused_ = (node.document().focusedNode() == last_node_clicked_);
132 } 144 }
145
146 void PageClickTracker::HandleTextFieldMaybeLosingFocus(
147 const WebNode& newly_clicked_node) {
148 if (!DidSelectedTextFieldLoseFocus(newly_clicked_node))
149 return;
150
151 ObserverListBase<PageClickListener>::Iterator it(listeners_);
152 PageClickListener* listener;
153 while ((listener = it.GetNext()) != NULL) {
154 if (listener->InputElementLostFocus())
155 break;
156 }
157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698