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 #include "views/controls/textfield/textfield.h" | 5 #include "views/controls/textfield/textfield.h" |
6 | 6 |
| 7 #if defined(OS_LINUX) |
| 8 #include <gdk/gdkkeysyms.h> |
| 9 #endif |
| 10 |
7 #include "app/gfx/insets.h" | 11 #include "app/gfx/insets.h" |
8 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
9 #include "app/win_util.h" | 13 #include "app/win_util.h" |
10 #endif | 14 #endif |
| 15 |
11 #include "base/string_util.h" | 16 #include "base/string_util.h" |
12 #include "views/controls/textfield/native_textfield_wrapper.h" | 17 #include "views/controls/textfield/native_textfield_wrapper.h" |
13 #include "views/widget/widget.h" | 18 #include "views/widget/widget.h" |
14 | 19 |
15 #if defined(OS_WIN) | 20 #if defined(OS_WIN) |
16 // TODO(beng): this should be removed when the OS_WIN hack from | 21 // TODO(beng): this should be removed when the OS_WIN hack from |
17 // ViewHierarchyChanged is removed. | 22 // ViewHierarchyChanged is removed. |
18 #include "views/controls/textfield/native_textfield_win.h" | 23 #include "views/controls/textfield/native_textfield_win.h" |
19 #endif | 24 #endif |
20 | 25 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 165 |
161 // This appears to be the insets used by Windows. | 166 // This appears to be the insets used by Windows. |
162 insets->Set(3, 3, 3, 3); | 167 insets->Set(3, 3, 3, 3); |
163 } | 168 } |
164 | 169 |
165 void Textfield::SyncText() { | 170 void Textfield::SyncText() { |
166 if (native_wrapper_) | 171 if (native_wrapper_) |
167 text_ = native_wrapper_->GetText(); | 172 text_ = native_wrapper_->GetText(); |
168 } | 173 } |
169 | 174 |
170 // static | |
171 bool Textfield::IsKeystrokeEnter(const Keystroke& key) { | |
172 #if defined(OS_WIN) | |
173 return key.key == VK_RETURN; | |
174 #else | |
175 // TODO(port): figure out VK_constants | |
176 NOTIMPLEMENTED(); | |
177 return false; | |
178 #endif | |
179 } | |
180 | |
181 // static | |
182 bool Textfield::IsKeystrokeEscape(const Keystroke& key) { | |
183 #if defined(OS_WIN) | |
184 return key.key == VK_ESCAPE; | |
185 #else | |
186 // TODO(port): figure out VK_constants | |
187 NOTIMPLEMENTED(); | |
188 return false; | |
189 #endif | |
190 } | |
191 | |
192 //////////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////////// |
193 // Textfield, View overrides: | 176 // Textfield, View overrides: |
194 | 177 |
195 void Textfield::Layout() { | 178 void Textfield::Layout() { |
196 if (native_wrapper_) { | 179 if (native_wrapper_) { |
197 native_wrapper_->GetView()->SetBounds(GetLocalBounds(true)); | 180 native_wrapper_->GetView()->SetBounds(GetLocalBounds(true)); |
198 native_wrapper_->GetView()->Layout(); | 181 native_wrapper_->GetView()->Layout(); |
199 } | 182 } |
200 } | 183 } |
201 | 184 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 native_wrapper->UpdateText(); | 272 native_wrapper->UpdateText(); |
290 native_wrapper->UpdateBackgroundColor(); | 273 native_wrapper->UpdateBackgroundColor(); |
291 native_wrapper->UpdateReadOnly(); | 274 native_wrapper->UpdateReadOnly(); |
292 native_wrapper->UpdateFont(); | 275 native_wrapper->UpdateFont(); |
293 native_wrapper->UpdateEnabled(); | 276 native_wrapper->UpdateEnabled(); |
294 native_wrapper->UpdateBorder(); | 277 native_wrapper->UpdateBorder(); |
295 | 278 |
296 return native_wrapper; | 279 return native_wrapper; |
297 } | 280 } |
298 | 281 |
| 282 base::KeyboardCode Textfield::Keystroke::GetKeyboardCode() const { |
| 283 #if defined(OS_WIN) |
| 284 return static_cast<base::KeyboardCode>(key_)); |
| 285 #else |
| 286 return static_cast<base::KeyboardCode>(event_.keyval); |
| 287 #endif |
| 288 } |
| 289 |
| 290 #if defined(OS_WIN) |
| 291 bool Textfield::Keystroke::IsControlHeld() const { |
| 292 return GetKeyState(VK_CONTROL) >= 0; |
| 293 } |
| 294 |
| 295 bool Textfield::Keystroke::IsShiftHeld() const { |
| 296 return GetKeyState(VK_SHIFT) >= 0; |
| 297 } |
| 298 #else |
| 299 bool Textfield::Keystroke::IsControlHeld() const { |
| 300 return (event_.state & gtk_accelerator_get_default_mod_mask()) == |
| 301 GDK_CONTROL_MASK; |
| 302 } |
| 303 |
| 304 bool Textfield::Keystroke::IsShiftHeld() const { |
| 305 return (event_.state & gtk_accelerator_get_default_mod_mask()) == |
| 306 GDK_SHIFT_MASK; |
| 307 } |
| 308 #endif |
| 309 |
299 } // namespace views | 310 } // namespace views |
OLD | NEW |