summaryrefslogtreecommitdiffstats
path: root/views/controls/textfield
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-04 14:05:17 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-04 14:05:17 +0000
commit13a30c9d2323f978dbe37a0f21a266b8193db437 (patch)
treee54d041d37886c3eed469fb041b340bf06fb01f0 /views/controls/textfield
parent8b378365c84c12ea6c5e5c259ca38767cf51edbb (diff)
downloadchromium_src-13a30c9d2323f978dbe37a0f21a266b8193db437.zip
chromium_src-13a30c9d2323f978dbe37a0f21a266b8193db437.tar.gz
chromium_src-13a30c9d2323f978dbe37a0f21a266b8193db437.tar.bz2
Revert to non-static members for click tracking.
Revert focus to textfield, add test for focus. This is based on the CL at codereview.chromium.org/6929002 This is in response to regressions from Issue crbug.com/83991 BUG=none TEST=none Review URL: http://codereview.chromium.org/6928006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield')
-rw-r--r--views/controls/textfield/native_textfield_views.cc29
-rw-r--r--views/controls/textfield/native_textfield_views.h5
-rw-r--r--views/controls/textfield/native_textfield_views_unittest.cc7
3 files changed, 25 insertions, 16 deletions
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index 3df14d8..3170878 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -66,7 +66,10 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent)
insert_(true),
is_cursor_visible_(false),
skip_input_method_cancel_composition_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)),
+ aggregated_clicks_(0),
+ last_click_time_(base::Time::FromInternalValue(0)),
+ last_click_location_(0, 0) {
set_border(text_border_);
// Multiline is not supported.
@@ -85,27 +88,21 @@ NativeTextfieldViews::~NativeTextfieldViews() {
bool NativeTextfieldViews::OnMousePressed(const MouseEvent& event) {
OnBeforeUserAction();
- RequestFocus();
+ textfield_->RequestFocus();
if (event.IsOnlyLeftMouseButton()) {
- static size_t aggregated_clicks = 0;
- static base::Time last_click_time = base::Time::FromInternalValue(0);
- static gfx::Point last_click_location;
- static View* last_click_view = NULL;
- base::TimeDelta time_delta = event.time_stamp() - last_click_time;
- gfx::Point location_delta = event.location().Subtract(last_click_location);
+ base::TimeDelta time_delta = event.time_stamp() - last_click_time_;
+ gfx::Point location_delta = event.location().Subtract(last_click_location_);
if (time_delta.InMilliseconds() <= GetDoubleClickInterval() &&
- !ExceededDragThreshold(location_delta.x(), location_delta.y()) &&
- last_click_view == this) {
- aggregated_clicks = (aggregated_clicks + 1) % 3;
+ !ExceededDragThreshold(location_delta.x(), location_delta.y())) {
+ aggregated_clicks_ = (aggregated_clicks_ + 1) % 3;
} else {
- aggregated_clicks = 0;
+ aggregated_clicks_ = 0;
}
- last_click_time = event.time_stamp();
- last_click_location = event.location();
- last_click_view = this;
+ last_click_time_ = event.time_stamp();
+ last_click_location_ = event.location();
- switch(aggregated_clicks) {
+ switch(aggregated_clicks_) {
case 0:
MoveCursorTo(event.location(), event.IsShiftDown());
break;
diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h
index a31317d..36b12c7 100644
--- a/views/controls/textfield/native_textfield_views.h
+++ b/views/controls/textfield/native_textfield_views.h
@@ -233,6 +233,11 @@ class NativeTextfieldViews : public View,
// A runnable method factory for callback to update the cursor.
ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_;
+ // State variables used to track double and triple clicks.
+ size_t aggregated_clicks_;
+ base::Time last_click_time_;
+ gfx::Point last_click_location_;
+
// Context menu and its content list for the textfield.
scoped_ptr<ui::SimpleMenuModel> context_menu_contents_;
scoped_ptr<Menu2> context_menu_menu_;
diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc
index 4ed3407..cb35e79 100644
--- a/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/views/controls/textfield/native_textfield_views_unittest.cc
@@ -502,6 +502,13 @@ TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) {
// Request focus should still work.
textfield_->RequestFocus();
EXPECT_EQ(1, GetFocusedView()->GetID());
+
+ // Test if clicking on textfield view sets the focus to textfield_.
+ widget_->GetFocusManager()->AdvanceFocus(true);
+ EXPECT_EQ(3, GetFocusedView()->GetID());
+ MouseEvent click(ui::ET_MOUSE_PRESSED, 0, 0, ui::EF_LEFT_BUTTON_DOWN);
+ textfield_view_->OnMousePressed(click);
+ EXPECT_EQ(1, GetFocusedView()->GetID());
}
void VerifyTextfieldContextMenuContents(bool textfield_has_selection,