| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "ui/base/accessibility/accessible_view_state.h" | 12 #include "ui/base/accessibility/accessible_view_state.h" |
| 13 #include "ui/base/event.h" |
| 13 #include "ui/base/ime/text_input_type.h" | 14 #include "ui/base/ime/text_input_type.h" |
| 14 #include "ui/base/keycodes/keyboard_codes.h" | 15 #include "ui/base/keycodes/keyboard_codes.h" |
| 15 #include "ui/base/range/range.h" | 16 #include "ui/base/range/range.h" |
| 16 #include "ui/base/ui_base_switches.h" | 17 #include "ui/base/ui_base_switches.h" |
| 17 #include "ui/gfx/insets.h" | 18 #include "ui/gfx/insets.h" |
| 18 #include "ui/gfx/selection_model.h" | 19 #include "ui/gfx/selection_model.h" |
| 19 #include "ui/views/controls/native/native_view_host.h" | 20 #include "ui/views/controls/native/native_view_host.h" |
| 20 #include "ui/views/controls/textfield/native_textfield_views.h" | 21 #include "ui/views/controls/textfield/native_textfield_views.h" |
| 21 #include "ui/views/controls/textfield/native_textfield_wrapper.h" | 22 #include "ui/views/controls/textfield/native_textfield_wrapper.h" |
| 22 #include "ui/views/controls/textfield/textfield_controller.h" | 23 #include "ui/views/controls/textfield/textfield_controller.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() : | 367 const int font_height = native_wrapper_ ? native_wrapper_->GetFontHeight() : |
| 367 font_.GetHeight(); | 368 font_.GetHeight(); |
| 368 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + | 369 return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + |
| 369 insets.width(), font_height + insets.height()); | 370 insets.width(), font_height + insets.height()); |
| 370 } | 371 } |
| 371 | 372 |
| 372 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { | 373 void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 373 SelectAll(false); | 374 SelectAll(false); |
| 374 } | 375 } |
| 375 | 376 |
| 376 bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) { | 377 bool Textfield::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { |
| 377 // TODO(hamaji): Figure out which keyboard combinations we need to add here, | 378 // TODO(hamaji): Figure out which keyboard combinations we need to add here, |
| 378 // similar to LocationBarView::SkipDefaultKeyEventProcessing. | 379 // similar to LocationBarView::SkipDefaultKeyEventProcessing. |
| 379 ui::KeyboardCode key = e.key_code(); | 380 ui::KeyboardCode key = e.key_code(); |
| 380 if (key == ui::VKEY_BACK) | 381 if (key == ui::VKEY_BACK) |
| 381 return true; // We'll handle BackSpace ourselves. | 382 return true; // We'll handle BackSpace ourselves. |
| 382 | 383 |
| 383 #if defined(USE_AURA) | 384 #if defined(USE_AURA) |
| 384 NOTIMPLEMENTED(); | 385 NOTIMPLEMENTED(); |
| 385 #elif defined(OS_WIN) | 386 #elif defined(OS_WIN) |
| 386 // We don't translate accelerators for ALT + NumPad digit on Windows, they are | 387 // We don't translate accelerators for ALT + NumPad digit on Windows, they are |
| 387 // used for entering special characters. We do translate alt-home. | 388 // used for entering special characters. We do translate alt-home. |
| 388 if (e.IsAltDown() && (key != ui::VKEY_HOME) && | 389 if (e.IsAltDown() && (key != ui::VKEY_HOME) && |
| 389 NativeTextfieldWin::IsNumPadDigit(key, | 390 NativeTextfieldWin::IsNumPadDigit(key, |
| 390 (e.flags() & ui::EF_EXTENDED) != 0)) | 391 (e.flags() & ui::EF_EXTENDED) != 0)) |
| 391 return true; | 392 return true; |
| 392 #endif | 393 #endif |
| 393 return false; | 394 return false; |
| 394 } | 395 } |
| 395 | 396 |
| 396 void Textfield::OnPaintFocusBorder(gfx::Canvas* canvas) { | 397 void Textfield::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 397 if (NativeViewHost::kRenderNativeControlFocus) | 398 if (NativeViewHost::kRenderNativeControlFocus) |
| 398 View::OnPaintFocusBorder(canvas); | 399 View::OnPaintFocusBorder(canvas); |
| 399 } | 400 } |
| 400 | 401 |
| 401 bool Textfield::OnKeyPressed(const views::KeyEvent& e) { | 402 bool Textfield::OnKeyPressed(const ui::KeyEvent& e) { |
| 402 return native_wrapper_ && native_wrapper_->HandleKeyPressed(e); | 403 return native_wrapper_ && native_wrapper_->HandleKeyPressed(e); |
| 403 } | 404 } |
| 404 | 405 |
| 405 bool Textfield::OnKeyReleased(const views::KeyEvent& e) { | 406 bool Textfield::OnKeyReleased(const ui::KeyEvent& e) { |
| 406 return native_wrapper_ && native_wrapper_->HandleKeyReleased(e); | 407 return native_wrapper_ && native_wrapper_->HandleKeyReleased(e); |
| 407 } | 408 } |
| 408 | 409 |
| 409 void Textfield::OnFocus() { | 410 void Textfield::OnFocus() { |
| 410 if (native_wrapper_) | 411 if (native_wrapper_) |
| 411 native_wrapper_->HandleFocus(); | 412 native_wrapper_->HandleFocus(); |
| 412 | 413 |
| 413 // Forward the focus to the wrapper if it exists. | 414 // Forward the focus to the wrapper if it exists. |
| 414 if (!native_wrapper_ || !native_wrapper_->SetFocus()) { | 415 if (!native_wrapper_ || !native_wrapper_->SetFocus()) { |
| 415 // If there is no wrapper or the wrapper didn't take focus, call | 416 // If there is no wrapper or the wrapper didn't take focus, call |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 486 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
| 486 Textfield* field) { | 487 Textfield* field) { |
| 487 #if defined(OS_WIN) && !defined(USE_AURA) | 488 #if defined(OS_WIN) && !defined(USE_AURA) |
| 488 if (!UseNativeTextfieldViews()) | 489 if (!UseNativeTextfieldViews()) |
| 489 return new NativeTextfieldWin(field); | 490 return new NativeTextfieldWin(field); |
| 490 #endif | 491 #endif |
| 491 return new NativeTextfieldViews(field); | 492 return new NativeTextfieldViews(field); |
| 492 } | 493 } |
| 493 | 494 |
| 494 } // namespace views | 495 } // namespace views |
| OLD | NEW |