| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 111 private: | 115 private: |
| 112 friend class NativeTextfieldViewsTest; | 116 friend class NativeTextfieldViewsTest; |
| 113 | 117 |
| 118 enum ClickAction { |
| 119 SELECT_WORD, |
| 120 SELECT_ALL, |
| 121 CURSOR_SELECT, |
| 122 NONE, |
| 123 }; |
| 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; |
| 121 virtual void GetInsets(gfx::Insets* insets) const; | 132 virtual void GetInsets(gfx::Insets* insets) const; |
| 122 | 133 |
| 123 // Sets the insets of the border. | 134 // Sets the insets of the border. |
| (...skipping 31 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 // Double or tripple click handler. Returns true if a double/triple click is |
| 177 // detected and handled. |
| 178 bool DetectAndHandleDoubleAndTripleClick(const views::MouseEvent& e); |
| 179 |
| 180 // Helper function determines whether a mouse event is a double/triple click. |
| 181 ClickAction GetClickAction(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 // True if a click has occured and we are waiting for a double click. |
| 221 bool tracking_double_click_; |
| 222 |
| 223 // True if a double click has occured and we are waiting for a triple click. |
| 224 bool tracking_triple_click_; |
| 225 |
| 196 // Context menu and its content list for the textfield. | 226 // Context menu and its content list for the textfield. |
| 197 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 227 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
| 198 scoped_ptr<Menu2> context_menu_menu_; | 228 scoped_ptr<Menu2> context_menu_menu_; |
| 199 | 229 |
| 200 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 230 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
| 201 }; | 231 }; |
| 202 | 232 |
| 203 } // namespace views | 233 } // namespace views |
| 204 | 234 |
| 205 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 235 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
| OLD | NEW |