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

Unified Diff: views/controls/textfield/native_textfield_views.cc

Issue 6267002: Implement double/triple click functionality in views textfield. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: minor changes Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: views/controls/textfield/native_textfield_views.cc
diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc
index a4324be2f68fd7a6998ee266a2e65178d1bd14ab..d70ea3231ab65e6c0c10343dc1301189266b567a 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -59,7 +59,10 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent)
text_offset_(0),
insert_(true),
is_cursor_visible_(false),
- ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)) {
+ ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)),
+ last_mouse_press_time_(base::Time::FromInternalValue(0)),
+ tracking_double_click_(false),
+ tracking_triple_click_(false) {
set_border(text_border_);
// Multiline is not supported.
@@ -78,7 +81,9 @@ NativeTextfieldViews::~NativeTextfieldViews() {
bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) {
textfield_->RequestFocus();
- if (e.IsLeftMouseButton()) {
+ if (DetectAndHandleDoubleAndTripleClick(e)) {
+ SchedulePaint();
+ } else if (e.IsLeftMouseButton()) {
size_t pos = FindCursorPosition(e.location());
if (model_->MoveCursorTo(pos, false)) {
oshima 2011/01/25 19:31:59 It's probably better to move this logic to GetClic
varunjain 2011/01/25 20:10:40 Done.
UpdateCursorBoundsAndTextOffset();
@@ -784,6 +789,57 @@ size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const {
return left_pos;
}
+bool NativeTextfieldViews::DetectAndHandleDoubleAndTripleClick(
+ const views::MouseEvent& e) {
+ switch(GetClickAction(e)) {
+ case SELECT_WORD:
+ model_->SelectWord();
+ return true;
+ case SELECT_ALL:
+ model_->SelectAll();
+ return true;
+ case CURSOR_SELECT:
+ tracking_double_click_ = true;
+ return false;
+ default:
+ return false;
+ }
+}
+
+NativeTextfieldViews::ClickAction NativeTextfieldViews::GetClickAction(
+ const views::MouseEvent& e) {
+ base::TimeDelta time_delta = e.GetTimeStamp() - last_mouse_press_time_;
+ gfx::Point location_delta = e.location().Subtract(last_mouse_press_location_);
+ last_mouse_press_time_ = e.GetTimeStamp();
+ last_mouse_press_location_ = e.location();
+ if (e.IsOnlyLeftMouseButton()) {
+ if (!ExceededDragThreshold(location_delta.x(), location_delta.y())
+ && time_delta.InMilliseconds() <= GetDoubleClickTimeMS()) {
+ // Multiple mouse press detected. Check for double or triple.
+ if (tracking_double_click_) {
oshima 2011/01/25 19:31:59 can't we make this simple state machine rather tha
varunjain 2011/01/25 20:10:40 Done.
+ tracking_double_click_ = false;
+ tracking_triple_click_ = true;
+ return SELECT_WORD;
+ } else if (tracking_triple_click_) {
+ tracking_double_click_ = false;
+ tracking_triple_click_ = false;
+ return SELECT_ALL;
+ } else {
+ // The 4th click should be treated as a single click.
+ tracking_double_click_ = true;
+ tracking_triple_click_ = false;
+ return CURSOR_SELECT;
+ }
+ } else {
+ // Single mouse press.
+ tracking_double_click_ = true;
+ tracking_triple_click_ = false;
+ return CURSOR_SELECT;
+ }
+ }
+ return NONE;
+}
+
void NativeTextfieldViews::PropagateTextChange() {
textfield_->SyncText();
Textfield::Controller* controller = textfield_->GetController();

Powered by Google App Engine
This is Rietveld 408576698