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 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/task.h" | 10 #include "base/task.h" |
11 #include "gfx/font.h" | 11 #include "gfx/font.h" |
12 #include "ui/base/models/simple_menu_model.h" | 12 #include "ui/base/models/simple_menu_model.h" |
13 #include "views/border.h" | 13 #include "views/border.h" |
14 #include "views/controls/textfield/native_textfield_wrapper.h" | 14 #include "views/controls/textfield/native_textfield_wrapper.h" |
15 #include "views/view.h" | 15 #include "views/view.h" |
16 | 16 |
| 17 namespace base { |
| 18 class Time; |
| 19 } |
| 20 |
17 namespace gfx { | 21 namespace gfx { |
18 class Canvas; | 22 class Canvas; |
19 } // namespace | 23 } // namespace |
20 | 24 |
21 namespace views { | 25 namespace views { |
22 | 26 |
23 class KeyEvent; | 27 class KeyEvent; |
24 class Menu2; | 28 class Menu2; |
25 class TextfieldViewsModel; | 29 class TextfieldViewsModel; |
26 | 30 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 static const char kViewClassName[]; | 105 static const char kViewClassName[]; |
102 | 106 |
103 // Returns true when | 107 // Returns true when |
104 // 1) built with GYP_DEFIENS="touchui=1" | 108 // 1) built with GYP_DEFIENS="touchui=1" |
105 // 2) enabled by SetEnableTextfieldViews(true) | 109 // 2) enabled by SetEnableTextfieldViews(true) |
106 // 3) enabled by the command line flag "--enable-textfield-view". | 110 // 3) enabled by the command line flag "--enable-textfield-view". |
107 static bool IsTextfieldViewsEnabled(); | 111 static bool IsTextfieldViewsEnabled(); |
108 // Enable/Disable TextfieldViews implementation for Textfield. | 112 // Enable/Disable TextfieldViews implementation for Textfield. |
109 static void SetEnableTextfieldViews(bool enabled); | 113 static void SetEnableTextfieldViews(bool enabled); |
110 | 114 |
| 115 enum ClickState { |
| 116 TRACKING_DOUBLE_CLICK, |
| 117 TRACKING_TRIPLE_CLICK, |
| 118 NONE, |
| 119 }; |
| 120 |
| 121 |
111 private: | 122 private: |
112 friend class NativeTextfieldViewsTest; | 123 friend class NativeTextfieldViewsTest; |
113 | 124 |
114 // A Border class to draw focus border for the text field. | 125 // A Border class to draw focus border for the text field. |
115 class TextfieldBorder : public Border { | 126 class TextfieldBorder : public Border { |
116 public: | 127 public: |
117 TextfieldBorder(); | 128 TextfieldBorder(); |
118 | 129 |
119 // Border implementation. | 130 // Border implementation. |
120 virtual void Paint(const View& view, gfx::Canvas* canvas) const; | 131 virtual void Paint(const View& view, gfx::Canvas* canvas) const; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Handle the keyevent. | 166 // Handle the keyevent. |
156 bool HandleKeyEvent(const KeyEvent& key_event); | 167 bool HandleKeyEvent(const KeyEvent& key_event); |
157 | 168 |
158 // Utility function. Gets the character corresponding to a keyevent. | 169 // Utility function. Gets the character corresponding to a keyevent. |
159 // Returns 0 if the character is not printable. | 170 // Returns 0 if the character is not printable. |
160 char16 GetPrintableChar(const KeyEvent& key_event); | 171 char16 GetPrintableChar(const KeyEvent& key_event); |
161 | 172 |
162 // Find a cusor position for given |point| in this views coordinates. | 173 // Find a cusor position for given |point| in this views coordinates. |
163 size_t FindCursorPosition(const gfx::Point& point) const; | 174 size_t FindCursorPosition(const gfx::Point& point) const; |
164 | 175 |
| 176 // Mouse event handler. Returns true if textfield needs to be repainted. |
| 177 bool HandleMousePressed(const views::MouseEvent& e); |
| 178 |
| 179 // Helper function that sets the cursor position at the location of mouse |
| 180 // event. |
| 181 void SetCursorForMouseClick(const views::MouseEvent& e); |
| 182 |
165 // Utility function to inform the parent textfield (and its controller if any) | 183 // Utility function to inform the parent textfield (and its controller if any) |
166 // that the text in the textfield has changed. | 184 // that the text in the textfield has changed. |
167 void PropagateTextChange(); | 185 void PropagateTextChange(); |
168 | 186 |
169 // Utility function to create the context menu if one does not already exist. | 187 // Utility function to create the context menu if one does not already exist. |
170 void InitContextMenuIfRequired(); | 188 void InitContextMenuIfRequired(); |
171 | 189 |
172 // The parent textfield, the owner of this object. | 190 // The parent textfield, the owner of this object. |
173 Textfield* textfield_; | 191 Textfield* textfield_; |
174 | 192 |
(...skipping 11 matching lines...) Expand all Loading... |
186 | 204 |
187 // True if the textfield is in insert mode. | 205 // True if the textfield is in insert mode. |
188 bool insert_; | 206 bool insert_; |
189 | 207 |
190 // The drawing state of cursor. True to draw. | 208 // The drawing state of cursor. True to draw. |
191 bool is_cursor_visible_; | 209 bool is_cursor_visible_; |
192 | 210 |
193 // A runnable method factory for callback to update the cursor. | 211 // A runnable method factory for callback to update the cursor. |
194 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; | 212 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; |
195 | 213 |
| 214 // Time of last LEFT mouse press. Used for tracking double/triple click. |
| 215 base::Time last_mouse_press_time_; |
| 216 |
| 217 // Position of last LEFT mouse press. Used for tracking double/triple click. |
| 218 gfx::Point last_mouse_press_location_; |
| 219 |
| 220 // State variable to track double and triple clicks. |
| 221 ClickState click_state_; |
| 222 |
196 // Context menu and its content list for the textfield. | 223 // Context menu and its content list for the textfield. |
197 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 224 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
198 scoped_ptr<Menu2> context_menu_menu_; | 225 scoped_ptr<Menu2> context_menu_menu_; |
199 | 226 |
200 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 227 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
201 }; | 228 }; |
202 | 229 |
203 } // namespace views | 230 } // namespace views |
204 | 231 |
205 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 232 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
OLD | NEW |