OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
8 #if defined (OS_LINUX) | |
9 #include <gdk/gdk.h> | |
10 #endif | |
11 | |
8 #include "app/gfx/font.h" | 12 #include "app/gfx/font.h" |
9 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/keyboard_codes.h" | |
10 #include "base/string16.h" | 15 #include "base/string16.h" |
11 #include "views/view.h" | 16 #include "views/view.h" |
12 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
13 | 18 |
14 #ifdef UNIT_TEST | 19 #ifdef UNIT_TEST |
15 #include "base/gfx/native_widget_types.h" | 20 #include "base/gfx/native_widget_types.h" |
16 #include "views/controls/textfield/native_textfield_wrapper.h" | 21 #include "views/controls/textfield/native_textfield_wrapper.h" |
17 #endif | 22 #endif |
18 | 23 |
19 namespace views { | 24 namespace views { |
20 | 25 |
21 class NativeTextfieldWrapper; | 26 class NativeTextfieldWrapper; |
22 | 27 |
23 // This class implements a ChromeView that wraps a native text (edit) field. | 28 // This class implements a ChromeView that wraps a native text (edit) field. |
24 class Textfield : public View { | 29 class Textfield : public View { |
25 public: | 30 public: |
26 // The button's class name. | 31 // The button's class name. |
27 static const char kViewClassName[]; | 32 static const char kViewClassName[]; |
28 | 33 |
29 // Keystroke provides a platform-dependent way to send keystroke events. | 34 // Keystroke provides a platform-dependent way to send keystroke events. |
30 // Cross-platform code can use IsKeystrokeEnter/Escape to check for these | 35 // Cross-platform code can use IsKeystrokeEnter/Escape to check for these |
31 // two common key events. | 36 // two common key events. |
32 // TODO(brettw) this should be cleaned up to be more cross-platform. | 37 // TODO(brettw) this should be cleaned up to be more cross-platform. |
38 class Keystroke { | |
39 public: | |
33 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
34 struct Keystroke { | |
35 Keystroke(unsigned int m, | 41 Keystroke(unsigned int m, |
36 wchar_t k, | 42 wchar_t k, |
37 int r, | 43 int r, |
38 unsigned int f) | 44 unsigned int f) |
39 : message(m), | 45 : message_(m), |
40 key(k), | 46 key_(k), |
41 repeat_count(r), | 47 repeat_count_(r), |
42 flags(f) { | 48 flags_(f) { |
43 } | 49 } |
50 unsigned int message() const { return message_; } | |
51 wchar_t key() const { return key_; } | |
52 int repeat_count() const { return repeat_count_; } | |
53 unsigned int flags() const { return flags_; } | |
54 #else | |
55 explicit Keystroke(GdkEventKey* event) | |
56 : event_(*event) { | |
57 } | |
58 const GdkEventKey* event() const { return &event_; } | |
59 #endif | |
60 base::KeyboardCode GetKeyboardCode() const; | |
61 bool IsControlHeld() const; | |
62 bool IsShiftHeld() const; | |
44 | 63 |
45 unsigned int message; | 64 private: |
46 wchar_t key; | 65 #if defined(OS_WIN) |
47 int repeat_count; | 66 unsigned int message_; |
48 unsigned int flags; | 67 wchar_t key_; |
68 int repeat_count_; | |
69 unsigned int flags_; | |
70 #else | |
71 GdkEventKey event_; | |
72 #endif | |
sky
2009/09/09 22:49:41
DISALLOW_COPY_AND_ASSIGN
| |
49 }; | 73 }; |
50 #else | |
51 struct Keystroke { | |
52 // TODO(brettw) figure out what this should be on GTK. | |
53 }; | |
54 #endif | |
55 | 74 |
56 // This defines the callback interface for other code to be notified of | 75 // This defines the callback interface for other code to be notified of |
57 // changes in the state of a text field. | 76 // changes in the state of a text field. |
58 class Controller { | 77 class Controller { |
59 public: | 78 public: |
60 // This method is called whenever the text in the field changes. | 79 // This method is called whenever the text in the field changes. |
61 virtual void ContentsChanged(Textfield* sender, | 80 virtual void ContentsChanged(Textfield* sender, |
62 const string16& new_contents) = 0; | 81 const string16& new_contents) = 0; |
63 | 82 |
64 // This method is called to get notified about keystrokes in the edit. | 83 // This method is called to get notified about keystrokes in the edit. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 | 169 |
151 // Calculates the insets for the text field. | 170 // Calculates the insets for the text field. |
152 void CalculateInsets(gfx::Insets* insets); | 171 void CalculateInsets(gfx::Insets* insets); |
153 | 172 |
154 // Invoked by the edit control when the value changes. This method set | 173 // Invoked by the edit control when the value changes. This method set |
155 // the text_ member variable to the value contained in edit control. | 174 // the text_ member variable to the value contained in edit control. |
156 // This is important because the edit control can be replaced if it has | 175 // This is important because the edit control can be replaced if it has |
157 // been deleted during a window close. | 176 // been deleted during a window close. |
158 void SyncText(); | 177 void SyncText(); |
159 | 178 |
160 // Provides a cross-platform way of checking whether a keystroke is one of | |
161 // these common keys. Most code only checks keystrokes against these two keys, | |
162 // so the caller can be cross-platform by implementing the platform-specific | |
163 // parts in here. | |
164 // TODO(brettw) we should use a more cross-platform representation of | |
165 // keyboard events so these are not necessary. | |
166 static bool IsKeystrokeEnter(const Keystroke& key); | |
167 static bool IsKeystrokeEscape(const Keystroke& key); | |
168 | |
169 #ifdef UNIT_TEST | 179 #ifdef UNIT_TEST |
170 gfx::NativeView GetTestingHandle() const { | 180 gfx::NativeView GetTestingHandle() const { |
171 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; | 181 return native_wrapper_ ? native_wrapper_->GetTestingHandle() : NULL; |
172 } | 182 } |
173 #endif | 183 #endif |
174 | 184 |
175 // Overridden from View: | 185 // Overridden from View: |
176 virtual void Layout(); | 186 virtual void Layout(); |
177 virtual gfx::Size GetPreferredSize(); | 187 virtual gfx::Size GetPreferredSize(); |
178 virtual bool IsFocusable() const; | 188 virtual bool IsFocusable() const; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 // TODO(beng): remove this once NativeTextfieldWin subclasses | 240 // TODO(beng): remove this once NativeTextfieldWin subclasses |
231 // NativeControlWin. | 241 // NativeControlWin. |
232 bool initialized_; | 242 bool initialized_; |
233 | 243 |
234 DISALLOW_COPY_AND_ASSIGN(Textfield); | 244 DISALLOW_COPY_AND_ASSIGN(Textfield); |
235 }; | 245 }; |
236 | 246 |
237 } // namespace views | 247 } // namespace views |
238 | 248 |
239 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ | 249 #endif // VIEWS_CONTROLS_TEXTFIELD_TEXTFIELD_H_ |
OLD | NEW |