| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_TEXTFIELD_H_ | 5 #ifndef VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 6 #define VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "views/view.h" | 24 #include "views/view.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
| 26 | 26 |
| 27 #ifdef UNIT_TEST | 27 #ifdef UNIT_TEST |
| 28 #include "gfx/native_widget_types.h" | 28 #include "gfx/native_widget_types.h" |
| 29 #include "views/controls/textfield/native_textfield_wrapper.h" | 29 #include "views/controls/textfield/native_textfield_wrapper.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 namespace views { | 32 namespace views { |
| 33 | 33 |
| 34 class KeyEvent; |
| 35 |
| 34 class NativeTextfieldWrapper; | 36 class NativeTextfieldWrapper; |
| 35 | 37 |
| 36 // This class implements a ChromeView that wraps a native text (edit) field. | 38 // This class implements a ChromeView that wraps a native text (edit) field. |
| 37 class Textfield : public View { | 39 class Textfield : public View { |
| 38 public: | 40 public: |
| 39 // The button's class name. | 41 // The button's class name. |
| 40 static const char kViewClassName[]; | 42 static const char kViewClassName[]; |
| 41 | 43 |
| 42 // Keystroke provides a platform-dependent way to send keystroke events. | |
| 43 // Cross-platform code can use IsKeystrokeEnter/Escape to check for these | |
| 44 // two common key events. | |
| 45 // TODO(brettw) this should be cleaned up to be more cross-platform. | |
| 46 class Keystroke { | |
| 47 public: | |
| 48 #if defined(OS_WIN) | |
| 49 const Keystroke(unsigned int m, | |
| 50 wchar_t k, | |
| 51 int r, | |
| 52 unsigned int f) | |
| 53 : message_(m), | |
| 54 key_(k), | |
| 55 repeat_count_(r), | |
| 56 flags_(f) { | |
| 57 } | |
| 58 unsigned int message() const { return message_; } | |
| 59 wchar_t key() const { return key_; } | |
| 60 int repeat_count() const { return repeat_count_; } | |
| 61 unsigned int flags() const { return flags_; } | |
| 62 #else | |
| 63 explicit Keystroke(const KeyEvent* event) | |
| 64 : event_(event) { | |
| 65 } | |
| 66 const KeyEvent& key_event() const { return *event_;}; | |
| 67 const GdkEventKey* event() const { return event_->native_event(); } | |
| 68 #endif | |
| 69 app::KeyboardCode GetKeyboardCode() const; | |
| 70 bool IsControlHeld() const; | |
| 71 bool IsShiftHeld() const; | |
| 72 | |
| 73 private: | |
| 74 #if defined(OS_WIN) | |
| 75 unsigned int message_; | |
| 76 wchar_t key_; | |
| 77 int repeat_count_; | |
| 78 unsigned int flags_; | |
| 79 #else | |
| 80 const KeyEvent* event_; | |
| 81 #endif | |
| 82 | |
| 83 DISALLOW_COPY_AND_ASSIGN(Keystroke); | |
| 84 }; | |
| 85 | |
| 86 // This defines the callback interface for other code to be notified of | 44 // This defines the callback interface for other code to be notified of |
| 87 // changes in the state of a text field. | 45 // changes in the state of a text field. |
| 88 class Controller { | 46 class Controller { |
| 89 public: | 47 public: |
| 90 // This method is called whenever the text in the field changes. | 48 // This method is called whenever the text in the field changes. |
| 91 virtual void ContentsChanged(Textfield* sender, | 49 virtual void ContentsChanged(Textfield* sender, |
| 92 const string16& new_contents) = 0; | 50 const string16& new_contents) = 0; |
| 93 | 51 |
| 94 // This method is called to get notified about keystrokes in the edit. | 52 // This method is called to get notified about keystrokes in the edit. |
| 95 // This method returns true if the message was handled and should not be | 53 // This method returns true if the message was handled and should not be |
| 96 // processed further. If it returns false the processing continues. | 54 // processed further. If it returns false the processing continues. |
| 97 virtual bool HandleKeystroke(Textfield* sender, | 55 virtual bool HandleKeyEvent(Textfield* sender, |
| 98 const Textfield::Keystroke& keystroke) = 0; | 56 const KeyEvent& key_event) = 0; |
| 99 }; | 57 }; |
| 100 | 58 |
| 101 enum StyleFlags { | 59 enum StyleFlags { |
| 102 STYLE_DEFAULT = 0, | 60 STYLE_DEFAULT = 0, |
| 103 STYLE_PASSWORD = 1<<0, | 61 STYLE_PASSWORD = 1<<0, |
| 104 STYLE_MULTILINE = 1<<1, | 62 STYLE_MULTILINE = 1<<1, |
| 105 STYLE_LOWERCASE = 1<<2 | 63 STYLE_LOWERCASE = 1<<2 |
| 106 }; | 64 }; |
| 107 | 65 |
| 108 Textfield(); | 66 Textfield(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 | 273 |
| 316 // Text to display when empty. | 274 // Text to display when empty. |
| 317 string16 text_to_display_when_empty_; | 275 string16 text_to_display_when_empty_; |
| 318 | 276 |
| 319 DISALLOW_COPY_AND_ASSIGN(Textfield); | 277 DISALLOW_COPY_AND_ASSIGN(Textfield); |
| 320 }; | 278 }; |
| 321 | 279 |
| 322 } // namespace views | 280 } // namespace views |
| 323 | 281 |
| 324 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 282 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
| OLD | NEW |