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 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "ui/accessibility/ax_action_data.h" | 15 #include "ui/accessibility/ax_action_data.h" |
15 #include "ui/accessibility/ax_node_data.h" | 16 #include "ui/accessibility/ax_node_data.h" |
| 17 #include "ui/aura/client/aura_constants.h" |
| 18 #include "ui/aura/window.h" |
16 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 19 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
17 #include "ui/base/cursor/cursor.h" | 20 #include "ui/base/cursor/cursor.h" |
18 #include "ui/base/default_style.h" | 21 #include "ui/base/default_style.h" |
19 #include "ui/base/dragdrop/drag_drop_types.h" | 22 #include "ui/base/dragdrop/drag_drop_types.h" |
20 #include "ui/base/ime/input_method.h" | 23 #include "ui/base/ime/input_method.h" |
21 #include "ui/base/ime/text_edit_commands.h" | 24 #include "ui/base/ime/text_edit_commands.h" |
22 #include "ui/base/material_design/material_design_controller.h" | 25 #include "ui/base/material_design/material_design_controller.h" |
23 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/base/ui_base_switches.h" |
24 #include "ui/base/ui_base_switches_util.h" | 28 #include "ui/base/ui_base_switches_util.h" |
25 #include "ui/compositor/canvas_painter.h" | 29 #include "ui/compositor/canvas_painter.h" |
26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
27 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
28 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
29 #include "ui/events/base_event_utils.h" | 33 #include "ui/events/base_event_utils.h" |
30 #include "ui/events/event.h" | 34 #include "ui/events/event.h" |
31 #include "ui/events/keycodes/keyboard_codes.h" | 35 #include "ui/events/keycodes/keyboard_codes.h" |
32 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
33 #include "ui/gfx/geometry/insets.h" | 37 #include "ui/gfx/geometry/insets.h" |
34 #include "ui/gfx/selection_bound.h" | 38 #include "ui/gfx/selection_bound.h" |
35 #include "ui/native_theme/native_theme.h" | 39 #include "ui/native_theme/native_theme.h" |
36 #include "ui/strings/grit/ui_strings.h" | 40 #include "ui/strings/grit/ui_strings.h" |
37 #include "ui/views/background.h" | 41 #include "ui/views/background.h" |
38 #include "ui/views/controls/focus_ring.h" | 42 #include "ui/views/controls/focus_ring.h" |
39 #include "ui/views/controls/focusable_border.h" | 43 #include "ui/views/controls/focusable_border.h" |
40 #include "ui/views/controls/label.h" | 44 #include "ui/views/controls/label.h" |
41 #include "ui/views/controls/menu/menu_runner.h" | 45 #include "ui/views/controls/menu/menu_runner.h" |
42 #include "ui/views/controls/native/native_view_host.h" | 46 #include "ui/views/controls/native/native_view_host.h" |
43 #include "ui/views/controls/textfield/textfield_controller.h" | 47 #include "ui/views/controls/textfield/textfield_controller.h" |
44 #include "ui/views/drag_utils.h" | 48 #include "ui/views/drag_utils.h" |
45 #include "ui/views/native_cursor.h" | 49 #include "ui/views/native_cursor.h" |
46 #include "ui/views/painter.h" | 50 #include "ui/views/painter.h" |
47 #include "ui/views/style/platform_style.h" | 51 #include "ui/views/style/platform_style.h" |
48 #include "ui/views/views_delegate.h" | 52 #include "ui/views/views_delegate.h" |
49 #include "ui/views/widget/widget.h" | 53 #include "ui/views/widget/widget.h" |
| 54 #include "ui/wm/core/coordinate_conversion.h" |
50 | 55 |
51 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
52 #include "base/win/win_util.h" | 57 #include "base/win/win_util.h" |
53 #include "ui/base/win/osk_display_manager.h" | 58 #include "ui/base/win/osk_display_manager.h" |
54 #endif | 59 #endif |
55 | 60 |
56 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 61 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
57 #include "base/strings/utf_string_conversions.h" | 62 #include "base/strings/utf_string_conversions.h" |
58 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 63 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
59 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 64 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
60 #endif | 65 #endif |
61 | 66 |
| 67 #if defined(OS_CHROMEOS) |
| 68 #include "ui/wm/core/ime_util_chromeos.h" |
| 69 #endif |
| 70 |
62 namespace views { | 71 namespace views { |
63 | 72 |
64 namespace { | 73 namespace { |
65 | 74 |
66 #if defined(OS_MACOSX) | 75 #if defined(OS_MACOSX) |
67 const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN; | 76 const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN; |
68 #else | 77 #else |
69 const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN; | 78 const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN; |
70 #endif // OS_MACOSX | 79 #endif // OS_MACOSX |
71 | 80 |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 ? ui::NativeTheme::kColorId_AlertSeverityHigh | 1011 ? ui::NativeTheme::kColorId_AlertSeverityHigh |
1003 : ui::NativeTheme::kColorId_NumColors); | 1012 : ui::NativeTheme::kColorId_NumColors); |
1004 } | 1013 } |
1005 SchedulePaint(); | 1014 SchedulePaint(); |
1006 View::OnFocus(); | 1015 View::OnFocus(); |
1007 } | 1016 } |
1008 | 1017 |
1009 void Textfield::OnBlur() { | 1018 void Textfield::OnBlur() { |
1010 gfx::RenderText* render_text = GetRenderText(); | 1019 gfx::RenderText* render_text = GetRenderText(); |
1011 render_text->set_focused(false); | 1020 render_text->set_focused(false); |
1012 if (GetInputMethod()) | 1021 if (GetInputMethod()) { |
1013 GetInputMethod()->DetachTextInputClient(this); | 1022 GetInputMethod()->DetachTextInputClient(this); |
| 1023 #if defined(OS_CHROMEOS) |
| 1024 wm::RestoreWindowBoundsOnClientFocusLost( |
| 1025 GetNativeView()->GetToplevelWindow()); |
| 1026 #endif // defined(OS_CHROMEOS) |
| 1027 } |
1014 StopBlinkingCursor(); | 1028 StopBlinkingCursor(); |
1015 cursor_view_.SetVisible(false); | 1029 cursor_view_.SetVisible(false); |
1016 | 1030 |
1017 DestroyTouchSelection(); | 1031 DestroyTouchSelection(); |
1018 | 1032 |
1019 if (use_focus_ring_) | 1033 if (use_focus_ring_) |
1020 FocusRing::Uninstall(this); | 1034 FocusRing::Uninstall(this); |
1021 SchedulePaint(); | 1035 SchedulePaint(); |
1022 View::OnBlur(); | 1036 View::OnBlur(); |
1023 } | 1037 } |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 gfx::Range range = GetRenderText()->selection(); | 1488 gfx::Range range = GetRenderText()->selection(); |
1475 DCHECK_GE(range.start(), before); | 1489 DCHECK_GE(range.start(), before); |
1476 | 1490 |
1477 range.set_start(range.start() - before); | 1491 range.set_start(range.start() - before); |
1478 range.set_end(range.end() + after); | 1492 range.set_end(range.end() + after); |
1479 gfx::Range text_range; | 1493 gfx::Range text_range; |
1480 if (GetTextRange(&text_range) && text_range.Contains(range)) | 1494 if (GetTextRange(&text_range) && text_range.Contains(range)) |
1481 DeleteRange(range); | 1495 DeleteRange(range); |
1482 } | 1496 } |
1483 | 1497 |
1484 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} | 1498 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) { |
| 1499 #if defined(OS_CHROMEOS) |
| 1500 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
| 1501 wm::EnsureWindowNotInRect(top_level_window, rect_in_screen); |
| 1502 #endif // defined(OS_CHROMEOS) |
| 1503 } |
1485 | 1504 |
1486 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { | 1505 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
1487 base::string16 result; | 1506 base::string16 result; |
1488 bool editable = !read_only(); | 1507 bool editable = !read_only(); |
1489 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; | 1508 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; |
1490 switch (command) { | 1509 switch (command) { |
1491 case ui::TextEditCommand::DELETE_BACKWARD: | 1510 case ui::TextEditCommand::DELETE_BACKWARD: |
1492 case ui::TextEditCommand::DELETE_FORWARD: | 1511 case ui::TextEditCommand::DELETE_FORWARD: |
1493 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1512 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
1494 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1513 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2094 cursor_blink_timer_.Stop(); | 2113 cursor_blink_timer_.Stop(); |
2095 } | 2114 } |
2096 | 2115 |
2097 void Textfield::OnCursorBlinkTimerFired() { | 2116 void Textfield::OnCursorBlinkTimerFired() { |
2098 DCHECK(ShouldBlinkCursor()); | 2117 DCHECK(ShouldBlinkCursor()); |
2099 cursor_view_.SetVisible(!cursor_view_.visible()); | 2118 cursor_view_.SetVisible(!cursor_view_.visible()); |
2100 UpdateCursorViewPosition(); | 2119 UpdateCursorViewPosition(); |
2101 } | 2120 } |
2102 | 2121 |
2103 } // namespace views | 2122 } // namespace views |
OLD | NEW |