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

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 refactoring 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 60589d229090235068af5680084ec849796437ec..7bbe8c2e9f91e50881df344d1278ba03152c93d8 100644
--- a/views/controls/textfield/native_textfield_views.cc
+++ b/views/controls/textfield/native_textfield_views.cc
@@ -59,7 +59,9 @@ 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_triple_click_(false) {
set_border(text_border_);
// Multiline is not supported.
@@ -78,7 +80,7 @@ NativeTextfieldViews::~NativeTextfieldViews() {
bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) {
textfield_->RequestFocus();
- if (e.IsLeftMouseButton()) {
+ if (e.IsLeftMouseButton() && !DetectAndHandleDoubleAndTripleClick(e)) {
size_t pos = FindCursorPosition(e.location());
if (model_->MoveCursorTo(pos, false)) {
UpdateCursorBoundsAndTextOffset();
@@ -762,6 +764,27 @@ size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const {
return left_pos;
}
+bool NativeTextfieldViews::DetectAndHandleDoubleAndTripleClick(
+ const views::MouseEvent& e) {
+ if (!e.IsOnlyLeftMouseButton())
+ return false;
oshima 2011/01/18 19:52:54 1) mouse move (with some threshold) should cancel
varunjain 2011/01/25 04:06:40 Done.
+ base::TimeDelta elapsed_time = e.GetTimeStamp() - last_mouse_press_time_;
+ last_mouse_press_time_ = e.GetTimeStamp();
+ if (elapsed_time.InMilliseconds() <= GetDoubleClickTimeMS()) {
+ if (tracking_triple_click_) {
+ model_->SelectAll();
+ } else {
+ model_->SelectWord();
+ }
+ tracking_triple_click_ = !tracking_triple_click_;
+ SchedulePaint();
+ return true;
+ } else {
+ tracking_triple_click_ = false;
+ }
+ return false;
+}
+
void NativeTextfieldViews::PropagateTextChange() {
textfield_->SyncText();
Textfield::Controller* controller = textfield_->GetController();

Powered by Google App Engine
This is Rietveld 408576698