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 |
62 #if defined(USE_X11) | 67 #if defined(USE_X11) |
63 #include "ui/base/x/x11_util_internal.h" // nogncheck | 68 #include "ui/base/x/x11_util_internal.h" // nogncheck |
64 #endif | 69 #endif |
65 | 70 |
| 71 #if defined(OS_CHROMEOS) |
| 72 #include "ui/wm/core/ime_util_chromeos.h" |
| 73 #endif |
| 74 |
66 namespace views { | 75 namespace views { |
67 | 76 |
68 namespace { | 77 namespace { |
69 | 78 |
70 #if defined(OS_MACOSX) | 79 #if defined(OS_MACOSX) |
71 const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN; | 80 const ui::EventFlags kPlatformModifier = ui::EF_COMMAND_DOWN; |
72 #else | 81 #else |
73 const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN; | 82 const ui::EventFlags kPlatformModifier = ui::EF_CONTROL_DOWN; |
74 #endif // OS_MACOSX | 83 #endif // OS_MACOSX |
75 | 84 |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 ? ui::NativeTheme::kColorId_AlertSeverityHigh | 1015 ? ui::NativeTheme::kColorId_AlertSeverityHigh |
1007 : ui::NativeTheme::kColorId_NumColors); | 1016 : ui::NativeTheme::kColorId_NumColors); |
1008 } | 1017 } |
1009 SchedulePaint(); | 1018 SchedulePaint(); |
1010 View::OnFocus(); | 1019 View::OnFocus(); |
1011 } | 1020 } |
1012 | 1021 |
1013 void Textfield::OnBlur() { | 1022 void Textfield::OnBlur() { |
1014 gfx::RenderText* render_text = GetRenderText(); | 1023 gfx::RenderText* render_text = GetRenderText(); |
1015 render_text->set_focused(false); | 1024 render_text->set_focused(false); |
1016 if (GetInputMethod()) | 1025 if (GetInputMethod()) { |
1017 GetInputMethod()->DetachTextInputClient(this); | 1026 GetInputMethod()->DetachTextInputClient(this); |
| 1027 #if defined(OS_CHROMEOS) |
| 1028 wm::RestoreWindowBoundsOnClientFocusLost( |
| 1029 GetNativeView()->GetToplevelWindow()); |
| 1030 #endif // defined(OS_CHROMEOS) |
| 1031 } |
1018 StopBlinkingCursor(); | 1032 StopBlinkingCursor(); |
1019 cursor_view_.SetVisible(false); | 1033 cursor_view_.SetVisible(false); |
1020 | 1034 |
1021 DestroyTouchSelection(); | 1035 DestroyTouchSelection(); |
1022 | 1036 |
1023 if (use_focus_ring_) | 1037 if (use_focus_ring_) |
1024 FocusRing::Uninstall(this); | 1038 FocusRing::Uninstall(this); |
1025 SchedulePaint(); | 1039 SchedulePaint(); |
1026 View::OnBlur(); | 1040 View::OnBlur(); |
1027 } | 1041 } |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 gfx::Range range = GetRenderText()->selection(); | 1492 gfx::Range range = GetRenderText()->selection(); |
1479 DCHECK_GE(range.start(), before); | 1493 DCHECK_GE(range.start(), before); |
1480 | 1494 |
1481 range.set_start(range.start() - before); | 1495 range.set_start(range.start() - before); |
1482 range.set_end(range.end() + after); | 1496 range.set_end(range.end() + after); |
1483 gfx::Range text_range; | 1497 gfx::Range text_range; |
1484 if (GetTextRange(&text_range) && text_range.Contains(range)) | 1498 if (GetTextRange(&text_range) && text_range.Contains(range)) |
1485 DeleteRange(range); | 1499 DeleteRange(range); |
1486 } | 1500 } |
1487 | 1501 |
1488 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} | 1502 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) { |
| 1503 #if defined(OS_CHROMEOS) |
| 1504 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
| 1505 wm::EnsureWindowNotInRect(top_level_window, rect_in_screen); |
| 1506 #endif // defined(OS_CHROMEOS) |
| 1507 } |
1489 | 1508 |
1490 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { | 1509 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
1491 base::string16 result; | 1510 base::string16 result; |
1492 bool editable = !read_only(); | 1511 bool editable = !read_only(); |
1493 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; | 1512 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; |
1494 switch (command) { | 1513 switch (command) { |
1495 case ui::TextEditCommand::DELETE_BACKWARD: | 1514 case ui::TextEditCommand::DELETE_BACKWARD: |
1496 case ui::TextEditCommand::DELETE_FORWARD: | 1515 case ui::TextEditCommand::DELETE_FORWARD: |
1497 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1516 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
1498 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1517 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 cursor_blink_timer_.Stop(); | 2117 cursor_blink_timer_.Stop(); |
2099 } | 2118 } |
2100 | 2119 |
2101 void Textfield::OnCursorBlinkTimerFired() { | 2120 void Textfield::OnCursorBlinkTimerFired() { |
2102 DCHECK(ShouldBlinkCursor()); | 2121 DCHECK(ShouldBlinkCursor()); |
2103 cursor_view_.SetVisible(!cursor_view_.visible()); | 2122 cursor_view_.SetVisible(!cursor_view_.visible()); |
2104 UpdateCursorViewPosition(); | 2123 UpdateCursorViewPosition(); |
2105 } | 2124 } |
2106 | 2125 |
2107 } // namespace views | 2126 } // namespace views |
OLD | NEW |