Commit 772e38b0 authored by dpanpong@google.com's avatar dpanpong@google.com

In PageClickTracker:

As soon as we start to handle an event, filter against the type of
nodes we care about (only text fields), rather than waiting to filter
in DidHandleMouseEvent().

Otherwise, PageClickTracker could hold a reference to the node until the
next mouse event, potentially keeping the node alive for longer than
necessary.

Review URL: http://codereview.chromium.org/7064012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86759 0039d316-1c4b-4281-b951-d872f2087c98
parent ae70b1aa
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -27,6 +27,26 @@ using WebKit::WebNode; ...@@ -27,6 +27,26 @@ using WebKit::WebNode;
using WebKit::WebString; using WebKit::WebString;
using WebKit::WebView; using WebKit::WebView;
namespace {
// Casts |node| to a WebInputElement.
// Returns an empty (isNull()) WebInputElement if |node| is not a text
// WebInputElement.
const WebInputElement GetTextWebInputElement(const WebNode& node) {
if (!node.isElementNode())
return WebInputElement();
const WebElement element = node.toConst<WebElement>();
if (!element.isFormControlElement())
return WebInputElement();
const WebFormControlElement control =
element.toConst<WebFormControlElement>();
if (control.formControlType() != WebString::fromUTF8("text"))
return WebInputElement();
return element.toConst<WebInputElement>();
}
} // namespace
PageClickTracker::PageClickTracker(RenderView* render_view) PageClickTracker::PageClickTracker(RenderView* render_view)
: RenderViewObserver(render_view), : RenderViewObserver(render_view),
was_focused_(false) { was_focused_(false) {
...@@ -48,18 +68,11 @@ void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) { ...@@ -48,18 +68,11 @@ void PageClickTracker::DidHandleMouseEvent(const WebMouseEvent& event) {
} }
// We are only interested in text field clicks. // We are only interested in text field clicks.
if (!last_node_clicked_.isElementNode()) const WebInputElement input_element =
return; GetTextWebInputElement(last_node_clicked_);
const WebElement& element = last_node_clicked_.toConst<WebElement>(); if (input_element.isNull())
if (!element.isFormControlElement())
return;
const WebFormControlElement& control =
element.toConst<WebFormControlElement>();
if (control.formControlType() != WebString::fromUTF8("text"))
return; return;
const WebInputElement& input_element = element.toConst<WebInputElement>();
bool is_focused = (last_node_clicked_ == GetFocusedNode()); bool is_focused = (last_node_clicked_ == GetFocusedNode());
ObserverListBase<PageClickListener>::Iterator it(listeners_); ObserverListBase<PageClickListener>::Iterator it(listeners_);
PageClickListener* listener; PageClickListener* listener;
...@@ -125,7 +138,12 @@ void PageClickTracker::handleEvent(const WebDOMEvent& event) { ...@@ -125,7 +138,12 @@ void PageClickTracker::handleEvent(const WebDOMEvent& event) {
// Remember which node has focus before the click is processed. // Remember which node has focus before the click is processed.
// We'll get a notification once the mouse event has been processed // We'll get a notification once the mouse event has been processed
// (DidHandleMouseEvent), we'll notify the listener at that point. // (DidHandleMouseEvent), we'll notify the listener at that point.
last_node_clicked_ = mouse_event.target(); WebNode node = mouse_event.target();
// We are only interested in text field clicks.
if (GetTextWebInputElement(node).isNull())
return;
last_node_clicked_ = node;
was_focused_ = (GetFocusedNode() == last_node_clicked_); was_focused_ = (GetFocusedNode() == last_node_clicked_);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment