| 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 "ui/base/models/simple_menu_model.h" | 11 #include "ui/base/models/simple_menu_model.h" |
| 12 #include "ui/gfx/font.h" | 12 #include "ui/gfx/font.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/controls/textfield/textfield_views_model.h" |
| 16 #include "views/ime/text_input_client.h" |
| 15 #include "views/view.h" | 17 #include "views/view.h" |
| 16 | 18 |
| 17 namespace base { | 19 namespace base { |
| 18 class Time; | 20 class Time; |
| 19 } | 21 } |
| 20 | 22 |
| 21 namespace gfx { | 23 namespace gfx { |
| 22 class Canvas; | 24 class Canvas; |
| 23 } | 25 } |
| 24 | 26 |
| 25 namespace views { | 27 namespace views { |
| 26 | 28 |
| 27 class KeyEvent; | 29 class KeyEvent; |
| 28 class Menu2; | 30 class Menu2; |
| 29 class TextfieldViewsModel; | |
| 30 | 31 |
| 31 // A views/skia only implementation of NativeTextfieldWrapper. | 32 // A views/skia only implementation of NativeTextfieldWrapper. |
| 32 // No platform specific code is used. | 33 // No platform specific code is used. |
| 33 // Following features are not yet supported. | 34 // Following features are not yet supported. |
| 34 // * BIDI | 35 // * BIDI |
| 35 // * IME/i18n support. | 36 // * IME/i18n support. |
| 36 // * X selection (only if we want to support). | 37 // * X selection (only if we want to support). |
| 37 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in | 38 // * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in |
| 38 // chromeos, so we may not need them) | 39 // chromeos, so we may not need them) |
| 39 // * Double click to select word, and triple click to select all. | 40 // * Double click to select word, and triple click to select all. |
| 40 // * Undo/Redo | 41 // * Undo/Redo |
| 41 class NativeTextfieldViews : public views::View, | 42 class NativeTextfieldViews : public views::View, |
| 42 public views::ContextMenuController, | 43 public views::ContextMenuController, |
| 43 public NativeTextfieldWrapper, | 44 public NativeTextfieldWrapper, |
| 44 public ui::SimpleMenuModel::Delegate { | 45 public ui::SimpleMenuModel::Delegate, |
| 46 public TextInputClient, |
| 47 public TextfieldViewsModel::Delegate { |
| 45 public: | 48 public: |
| 46 explicit NativeTextfieldViews(Textfield* parent); | 49 explicit NativeTextfieldViews(Textfield* parent); |
| 47 ~NativeTextfieldViews(); | 50 ~NativeTextfieldViews(); |
| 48 | 51 |
| 49 // views::View overrides: | 52 // views::View overrides: |
| 50 virtual bool OnMousePressed(const views::MouseEvent& e) OVERRIDE; | 53 virtual bool OnMousePressed(const views::MouseEvent& e) OVERRIDE; |
| 51 virtual bool OnMouseDragged(const views::MouseEvent& e) OVERRIDE; | 54 virtual bool OnMouseDragged(const views::MouseEvent& e) OVERRIDE; |
| 52 virtual void OnMouseReleased(const views::MouseEvent& e, | 55 virtual void OnMouseReleased(const views::MouseEvent& e, |
| 53 bool canceled) OVERRIDE; | 56 bool canceled) OVERRIDE; |
| 54 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; | 57 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 85 virtual View* GetView() OVERRIDE; | 88 virtual View* GetView() OVERRIDE; |
| 86 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; | 89 virtual gfx::NativeView GetTestingHandle() const OVERRIDE; |
| 87 virtual bool IsIMEComposing() const OVERRIDE; | 90 virtual bool IsIMEComposing() const OVERRIDE; |
| 88 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; | 91 virtual void GetSelectedRange(ui::Range* range) const OVERRIDE; |
| 89 virtual void SelectRange(const ui::Range& range) OVERRIDE; | 92 virtual void SelectRange(const ui::Range& range) OVERRIDE; |
| 90 virtual size_t GetCursorPosition() const OVERRIDE; | 93 virtual size_t GetCursorPosition() const OVERRIDE; |
| 91 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; | 94 virtual bool HandleKeyPressed(const views::KeyEvent& e) OVERRIDE; |
| 92 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; | 95 virtual bool HandleKeyReleased(const views::KeyEvent& e) OVERRIDE; |
| 93 virtual void HandleFocus() OVERRIDE; | 96 virtual void HandleFocus() OVERRIDE; |
| 94 virtual void HandleBlur() OVERRIDE; | 97 virtual void HandleBlur() OVERRIDE; |
| 98 virtual TextInputClient* GetTextInputClient() OVERRIDE; |
| 95 | 99 |
| 96 // ui::SimpleMenuModel::Delegate overrides | 100 // ui::SimpleMenuModel::Delegate overrides |
| 97 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; | 101 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 98 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; | 102 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 99 virtual bool GetAcceleratorForCommandId( | 103 virtual bool GetAcceleratorForCommandId( |
| 100 int command_id, | 104 int command_id, |
| 101 ui::Accelerator* accelerator) OVERRIDE; | 105 ui::Accelerator* accelerator) OVERRIDE; |
| 102 virtual void ExecuteCommand(int command_id) OVERRIDE; | 106 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 103 | 107 |
| 104 // class name of internal | 108 // class name of internal |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 has_focus_ = has_focus; | 146 has_focus_ = has_focus; |
| 143 } | 147 } |
| 144 | 148 |
| 145 private: | 149 private: |
| 146 bool has_focus_; | 150 bool has_focus_; |
| 147 gfx::Insets insets_; | 151 gfx::Insets insets_; |
| 148 | 152 |
| 149 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); | 153 DISALLOW_COPY_AND_ASSIGN(TextfieldBorder); |
| 150 }; | 154 }; |
| 151 | 155 |
| 156 // Overridden from TextInputClient: |
| 157 virtual void SetComposition(const ui::Composition& composition) OVERRIDE; |
| 158 virtual void ConfirmComposition() OVERRIDE; |
| 159 virtual void ClearComposition() OVERRIDE; |
| 160 virtual void InsertText(const string16& text) OVERRIDE; |
| 161 virtual void InsertChar(char16 ch, int flags) OVERRIDE; |
| 162 virtual ui::TextInputType GetTextInputType() OVERRIDE; |
| 163 virtual gfx::Rect GetCaretBounds() OVERRIDE; |
| 164 virtual bool HasComposition() OVERRIDE; |
| 165 virtual bool GetTextRange(ui::Range* range) OVERRIDE; |
| 166 virtual bool GetCompositionRange(ui::Range* range) OVERRIDE; |
| 167 virtual bool GetSelectionRange(ui::Range* range) OVERRIDE; |
| 168 virtual bool SetSelectionRange(const ui::Range& range) OVERRIDE; |
| 169 virtual bool DeleteRange(const ui::Range& range) OVERRIDE; |
| 170 virtual bool GetTextFromRange( |
| 171 const ui::Range& range, |
| 172 const base::Callback<void(string16)>& callback) OVERRIDE; |
| 173 virtual void OnInputMethodChanged() OVERRIDE; |
| 174 virtual bool ChangeTextDirectionAndLayoutAlignment( |
| 175 base::i18n::TextDirection direction) OVERRIDE; |
| 176 |
| 177 // Overridden from TextfieldViewsModel::Delegate: |
| 178 virtual void OnCompositionConfirmedOrCleared() OVERRIDE; |
| 179 |
| 152 // Returns the Textfield's font. | 180 // Returns the Textfield's font. |
| 153 const gfx::Font& GetFont() const; | 181 const gfx::Font& GetFont() const; |
| 154 | 182 |
| 155 // Returns the Textfield's text color. | 183 // Returns the Textfield's text color. |
| 156 SkColor GetTextColor() const; | 184 SkColor GetTextColor() const; |
| 157 | 185 |
| 158 // A callback function to periodically update the cursor state. | 186 // A callback function to periodically update the cursor state. |
| 159 void UpdateCursor(); | 187 void UpdateCursor(); |
| 160 | 188 |
| 161 // Repaint the cursor. | 189 // Repaint the cursor. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 183 // that the text in the textfield has changed. | 211 // that the text in the textfield has changed. |
| 184 void PropagateTextChange(); | 212 void PropagateTextChange(); |
| 185 | 213 |
| 186 // Does necessary updates when the text and/or the position of the cursor | 214 // Does necessary updates when the text and/or the position of the cursor |
| 187 // changed. | 215 // changed. |
| 188 void UpdateAfterChange(bool text_changed, bool cursor_changed); | 216 void UpdateAfterChange(bool text_changed, bool cursor_changed); |
| 189 | 217 |
| 190 // Utility function to create the context menu if one does not already exist. | 218 // Utility function to create the context menu if one does not already exist. |
| 191 void InitContextMenuIfRequired(); | 219 void InitContextMenuIfRequired(); |
| 192 | 220 |
| 221 // Convenience method to call InputMethod::OnTextInputTypeChanged(); |
| 222 void OnTextInputTypeChanged(); |
| 223 |
| 224 // Convenience method to call InputMethod::OnCaretBoundsChanged(); |
| 225 void OnCaretBoundsChanged(); |
| 226 |
| 227 // Convenience method to call InputMethod::CancelComposition(); |
| 228 void CancelComposition(); |
| 229 |
| 193 // Convenience method to call TextfieldController::OnBeforeUserAction(); | 230 // Convenience method to call TextfieldController::OnBeforeUserAction(); |
| 194 void OnBeforeUserAction(); | 231 void OnBeforeUserAction(); |
| 195 | 232 |
| 196 // Convenience method to call TextfieldController::OnAfterUserAction(); | 233 // Convenience method to call TextfieldController::OnAfterUserAction(); |
| 197 void OnAfterUserAction(); | 234 void OnAfterUserAction(); |
| 198 | 235 |
| 199 // Checks if a char is valid to be inserted into the textfield. | 236 // Checks if a char is valid to be inserted into the textfield. |
| 200 static bool IsValidChar(char16 ch, int flags); | 237 static bool IsValidChar(char16 ch, int flags); |
| 201 | 238 |
| 202 // The parent textfield, the owner of this object. | 239 // The parent textfield, the owner of this object. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 213 | 250 |
| 214 // Cursor's bounds in the textfield's coordinates. | 251 // Cursor's bounds in the textfield's coordinates. |
| 215 gfx::Rect cursor_bounds_; | 252 gfx::Rect cursor_bounds_; |
| 216 | 253 |
| 217 // True if the textfield is in insert mode. | 254 // True if the textfield is in insert mode. |
| 218 bool insert_; | 255 bool insert_; |
| 219 | 256 |
| 220 // The drawing state of cursor. True to draw. | 257 // The drawing state of cursor. True to draw. |
| 221 bool is_cursor_visible_; | 258 bool is_cursor_visible_; |
| 222 | 259 |
| 260 // True if CancelComposition() should not be called. |
| 261 bool skip_cancel_composition_; |
| 262 |
| 223 // A runnable method factory for callback to update the cursor. | 263 // A runnable method factory for callback to update the cursor. |
| 224 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; | 264 ScopedRunnableMethodFactory<NativeTextfieldViews> cursor_timer_; |
| 225 | 265 |
| 226 // Time of last LEFT mouse press. Used for tracking double/triple click. | 266 // Time of last LEFT mouse press. Used for tracking double/triple click. |
| 227 base::Time last_mouse_press_time_; | 267 base::Time last_mouse_press_time_; |
| 228 | 268 |
| 229 // Position of last LEFT mouse press. Used for tracking double/triple click. | 269 // Position of last LEFT mouse press. Used for tracking double/triple click. |
| 230 gfx::Point last_mouse_press_location_; | 270 gfx::Point last_mouse_press_location_; |
| 231 | 271 |
| 232 // State variable to track double and triple clicks. | 272 // State variable to track double and triple clicks. |
| 233 ClickState click_state_; | 273 ClickState click_state_; |
| 234 | 274 |
| 235 // Context menu and its content list for the textfield. | 275 // Context menu and its content list for the textfield. |
| 236 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; | 276 scoped_ptr<ui::SimpleMenuModel> context_menu_contents_; |
| 237 scoped_ptr<Menu2> context_menu_menu_; | 277 scoped_ptr<Menu2> context_menu_menu_; |
| 238 | 278 |
| 239 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); | 279 DISALLOW_COPY_AND_ASSIGN(NativeTextfieldViews); |
| 240 }; | 280 }; |
| 241 | 281 |
| 242 } // namespace views | 282 } // namespace views |
| 243 | 283 |
| 244 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ | 284 #endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_VIEWS_H_ |
| OLD | NEW |