OLD | NEW |
---|---|
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 "views/controls/textfield/native_textfield_views.h" | 5 #include "views/controls/textfield/native_textfield_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 const char NativeTextfieldViews::kViewClassName[] = | 52 const char NativeTextfieldViews::kViewClassName[] = |
53 "views/NativeTextfieldViews"; | 53 "views/NativeTextfieldViews"; |
54 | 54 |
55 NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) | 55 NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) |
56 : textfield_(parent), | 56 : textfield_(parent), |
57 model_(new TextfieldViewsModel()), | 57 model_(new TextfieldViewsModel()), |
58 text_border_(new TextfieldBorder()), | 58 text_border_(new TextfieldBorder()), |
59 text_offset_(0), | 59 text_offset_(0), |
60 insert_(true), | 60 insert_(true), |
61 is_cursor_visible_(false), | 61 is_cursor_visible_(false), |
62 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)) { | 62 ALLOW_THIS_IN_INITIALIZER_LIST(cursor_timer_(this)), |
63 last_mouse_press_time_(base::Time::FromInternalValue(0)), | |
64 tracking_triple_click_(false) { | |
63 set_border(text_border_); | 65 set_border(text_border_); |
64 | 66 |
65 // Multiline is not supported. | 67 // Multiline is not supported. |
66 DCHECK_NE(parent->style(), Textfield::STYLE_MULTILINE); | 68 DCHECK_NE(parent->style(), Textfield::STYLE_MULTILINE); |
67 // Lowercase is not supported. | 69 // Lowercase is not supported. |
68 DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE); | 70 DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE); |
69 | 71 |
70 SetContextMenuController(this); | 72 SetContextMenuController(this); |
71 } | 73 } |
72 | 74 |
73 NativeTextfieldViews::~NativeTextfieldViews() { | 75 NativeTextfieldViews::~NativeTextfieldViews() { |
74 } | 76 } |
75 | 77 |
76 //////////////////////////////////////////////////////////////////////////////// | 78 //////////////////////////////////////////////////////////////////////////////// |
77 // NativeTextfieldViews, View overrides: | 79 // NativeTextfieldViews, View overrides: |
78 | 80 |
79 bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) { | 81 bool NativeTextfieldViews::OnMousePressed(const views::MouseEvent& e) { |
80 textfield_->RequestFocus(); | 82 textfield_->RequestFocus(); |
81 if (e.IsLeftMouseButton()) { | 83 if (e.IsLeftMouseButton() && !DetectAndHandleDoubleAndTripleClick(e)) { |
82 size_t pos = FindCursorPosition(e.location()); | 84 size_t pos = FindCursorPosition(e.location()); |
83 if (model_->MoveCursorTo(pos, false)) { | 85 if (model_->MoveCursorTo(pos, false)) { |
84 UpdateCursorBoundsAndTextOffset(); | 86 UpdateCursorBoundsAndTextOffset(); |
85 SchedulePaint(); | 87 SchedulePaint(); |
86 } | 88 } |
87 } | 89 } |
88 return true; | 90 return true; |
89 } | 91 } |
90 | 92 |
91 bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& e) { | 93 bool NativeTextfieldViews::OnMouseDragged(const views::MouseEvent& e) { |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 } else if (pivot == x) { | 757 } else if (pivot == x) { |
756 return pivot_pos; | 758 return pivot_pos; |
757 } else { | 759 } else { |
758 right = pivot; | 760 right = pivot; |
759 right_pos = pivot_pos; | 761 right_pos = pivot_pos; |
760 } | 762 } |
761 } | 763 } |
762 return left_pos; | 764 return left_pos; |
763 } | 765 } |
764 | 766 |
767 bool NativeTextfieldViews::DetectAndHandleDoubleAndTripleClick( | |
768 const views::MouseEvent& e) { | |
769 if (!e.IsOnlyLeftMouseButton()) | |
770 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.
| |
771 base::TimeDelta elapsed_time = e.GetTimeStamp() - last_mouse_press_time_; | |
772 last_mouse_press_time_ = e.GetTimeStamp(); | |
773 if (elapsed_time.InMilliseconds() <= GetDoubleClickTimeMS()) { | |
774 if (tracking_triple_click_) { | |
775 model_->SelectAll(); | |
776 } else { | |
777 model_->SelectWord(); | |
778 } | |
779 tracking_triple_click_ = !tracking_triple_click_; | |
780 SchedulePaint(); | |
781 return true; | |
782 } else { | |
783 tracking_triple_click_ = false; | |
784 } | |
785 return false; | |
786 } | |
787 | |
765 void NativeTextfieldViews::PropagateTextChange() { | 788 void NativeTextfieldViews::PropagateTextChange() { |
766 textfield_->SyncText(); | 789 textfield_->SyncText(); |
767 Textfield::Controller* controller = textfield_->GetController(); | 790 Textfield::Controller* controller = textfield_->GetController(); |
768 if (controller) | 791 if (controller) |
769 controller->ContentsChanged(textfield_, GetText()); | 792 controller->ContentsChanged(textfield_, GetText()); |
770 } | 793 } |
771 | 794 |
772 void NativeTextfieldViews::InitContextMenuIfRequired() { | 795 void NativeTextfieldViews::InitContextMenuIfRequired() { |
773 if (context_menu_menu_.get()) | 796 if (context_menu_menu_.get()) |
774 return; | 797 return; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
831 } | 854 } |
832 | 855 |
833 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, | 856 void NativeTextfieldViews::TextfieldBorder::SetInsets(int top, |
834 int left, | 857 int left, |
835 int bottom, | 858 int bottom, |
836 int right) { | 859 int right) { |
837 insets_.Set(top, left, bottom, right); | 860 insets_.Set(top, left, bottom, right); |
838 } | 861 } |
839 | 862 |
840 } // namespace views | 863 } // namespace views |
OLD | NEW |