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/dragdrop/drag_utils.h" | 23 #include "ui/base/dragdrop/drag_utils.h" |
21 #include "ui/base/ime/input_method.h" | 24 #include "ui/base/ime/input_method.h" |
22 #include "ui/base/ime/text_edit_commands.h" | 25 #include "ui/base/ime/text_edit_commands.h" |
23 #include "ui/base/material_design/material_design_controller.h" | 26 #include "ui/base/material_design/material_design_controller.h" |
24 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/base/ui_base_switches.h" | |
25 #include "ui/base/ui_base_switches_util.h" | 29 #include "ui/base/ui_base_switches_util.h" |
26 #include "ui/compositor/canvas_painter.h" | 30 #include "ui/compositor/canvas_painter.h" |
27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 31 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
28 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
29 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
30 #include "ui/events/base_event_utils.h" | 34 #include "ui/events/base_event_utils.h" |
31 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
32 #include "ui/events/keycodes/keyboard_codes.h" | 36 #include "ui/events/keycodes/keyboard_codes.h" |
33 #include "ui/gfx/canvas.h" | 37 #include "ui/gfx/canvas.h" |
34 #include "ui/gfx/geometry/insets.h" | 38 #include "ui/gfx/geometry/insets.h" |
35 #include "ui/gfx/selection_bound.h" | 39 #include "ui/gfx/selection_bound.h" |
36 #include "ui/native_theme/native_theme.h" | 40 #include "ui/native_theme/native_theme.h" |
37 #include "ui/strings/grit/ui_strings.h" | 41 #include "ui/strings/grit/ui_strings.h" |
38 #include "ui/views/background.h" | 42 #include "ui/views/background.h" |
39 #include "ui/views/controls/focus_ring.h" | 43 #include "ui/views/controls/focus_ring.h" |
40 #include "ui/views/controls/focusable_border.h" | 44 #include "ui/views/controls/focusable_border.h" |
41 #include "ui/views/controls/label.h" | 45 #include "ui/views/controls/label.h" |
42 #include "ui/views/controls/menu/menu_runner.h" | 46 #include "ui/views/controls/menu/menu_runner.h" |
43 #include "ui/views/controls/native/native_view_host.h" | 47 #include "ui/views/controls/native/native_view_host.h" |
44 #include "ui/views/controls/textfield/textfield_controller.h" | 48 #include "ui/views/controls/textfield/textfield_controller.h" |
45 #include "ui/views/drag_utils.h" | 49 #include "ui/views/drag_utils.h" |
46 #include "ui/views/native_cursor.h" | 50 #include "ui/views/native_cursor.h" |
47 #include "ui/views/painter.h" | 51 #include "ui/views/painter.h" |
48 #include "ui/views/style/platform_style.h" | 52 #include "ui/views/style/platform_style.h" |
49 #include "ui/views/views_delegate.h" | 53 #include "ui/views/views_delegate.h" |
50 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
55 #include "ui/wm/core/coordinate_conversion.h" | |
56 #include "ui/wm/core/ime_util.h" | |
51 | 57 |
52 #if defined(OS_WIN) | 58 #if defined(OS_WIN) |
53 #include "base/win/win_util.h" | 59 #include "base/win/win_util.h" |
54 #include "ui/base/win/osk_display_manager.h" | 60 #include "ui/base/win/osk_display_manager.h" |
55 #endif | 61 #endif |
56 | 62 |
57 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 63 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
58 #include "base/strings/utf_string_conversions.h" | 64 #include "base/strings/utf_string_conversions.h" |
59 #include "ui/base/ime/linux/text_edit_command_auralinux.h" | 65 #include "ui/base/ime/linux/text_edit_command_auralinux.h" |
60 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 66 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 ? ui::NativeTheme::kColorId_AlertSeverityHigh | 1009 ? ui::NativeTheme::kColorId_AlertSeverityHigh |
1004 : ui::NativeTheme::kColorId_NumColors); | 1010 : ui::NativeTheme::kColorId_NumColors); |
1005 } | 1011 } |
1006 SchedulePaint(); | 1012 SchedulePaint(); |
1007 View::OnFocus(); | 1013 View::OnFocus(); |
1008 } | 1014 } |
1009 | 1015 |
1010 void Textfield::OnBlur() { | 1016 void Textfield::OnBlur() { |
1011 gfx::RenderText* render_text = GetRenderText(); | 1017 gfx::RenderText* render_text = GetRenderText(); |
1012 render_text->set_focused(false); | 1018 render_text->set_focused(false); |
1013 if (GetInputMethod()) | 1019 if (GetInputMethod()) { |
1014 GetInputMethod()->DetachTextInputClient(this); | 1020 GetInputMethod()->DetachTextInputClient(this); |
1021 #if defined(OS_CHROMEOS) | |
1022 wm::RestoreWindowBoundsOnClientFocusLost( | |
1023 GetNativeView()->GetToplevelWindow()); | |
1024 #endif // defined(OS_CHROMEOS) | |
1025 } | |
1015 StopBlinkingCursor(); | 1026 StopBlinkingCursor(); |
1016 cursor_view_.SetVisible(false); | 1027 cursor_view_.SetVisible(false); |
1017 | 1028 |
1018 DestroyTouchSelection(); | 1029 DestroyTouchSelection(); |
1019 | 1030 |
1020 if (use_focus_ring_) | 1031 if (use_focus_ring_) |
1021 FocusRing::Uninstall(this); | 1032 FocusRing::Uninstall(this); |
1022 SchedulePaint(); | 1033 SchedulePaint(); |
1023 View::OnBlur(); | 1034 View::OnBlur(); |
1024 } | 1035 } |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1477 gfx::Range range = GetRenderText()->selection(); | 1488 gfx::Range range = GetRenderText()->selection(); |
1478 DCHECK_GE(range.start(), before); | 1489 DCHECK_GE(range.start(), before); |
1479 | 1490 |
1480 range.set_start(range.start() - before); | 1491 range.set_start(range.start() - before); |
1481 range.set_end(range.end() + after); | 1492 range.set_end(range.end() + after); |
1482 gfx::Range text_range; | 1493 gfx::Range text_range; |
1483 if (GetTextRange(&text_range) && text_range.Contains(range)) | 1494 if (GetTextRange(&text_range) && text_range.Contains(range)) |
1484 DeleteRange(range); | 1495 DeleteRange(range); |
1485 } | 1496 } |
1486 | 1497 |
1487 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} | 1498 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) { |
1499 #if defined(OS_CHROMEOS) | |
1500 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
1501 ::switches::kUseNewVirtualKeyboardBehavior)) | |
1502 return; | |
1503 | |
1504 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); | |
1505 gfx::Rect original_window_bounds = top_level_window->GetBoundsInScreen(); | |
1506 if (top_level_window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey)) { | |
1507 original_window_bounds = | |
1508 *top_level_window->GetProperty(wm::kVirtualKeyboardRestoreBoundsKey); | |
1509 } | |
1510 | |
1511 gfx::Rect hidden_window_bounds_in_screen = | |
1512 gfx::IntersectRects(rect_in_screen, original_window_bounds); | |
1513 if (hidden_window_bounds_in_screen.IsEmpty()) { | |
1514 // The window isn't covered by the keyboard, restore the window position if | |
1515 // necessary. | |
1516 wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); | |
1517 return; | |
1518 } | |
1519 | |
1520 if (wm::MoveWindowToEnsureCaretNotInRect(top_level_window, rect_in_screen)) { | |
1521 // Recalculate hidden_window_bounds_in_screen after moving up the window | |
1522 original_window_bounds = top_level_window->GetBoundsInScreen(); | |
1523 hidden_window_bounds_in_screen = | |
1524 gfx::IntersectRects(rect_in_screen, original_window_bounds); | |
oshima
2017/04/17 13:24:22
These code aren't necessary (if you want to keep t
yhanada
2017/04/26 11:29:45
Done.
| |
1525 } else { | |
1526 // No need to move the window or need to restore the window position. | |
1527 wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); | |
1528 } | |
1529 #endif // defined(OS_CHROMEOS) | |
oshima
2017/04/17 13:24:22
The fundamental logic must be same as one in RWHVA
yhanada
2017/04/26 11:29:45
I moved the logic to ime_util. Done.
| |
1530 } | |
1488 | 1531 |
1489 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { | 1532 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
1490 base::string16 result; | 1533 base::string16 result; |
1491 bool editable = !read_only(); | 1534 bool editable = !read_only(); |
1492 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; | 1535 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; |
1493 switch (command) { | 1536 switch (command) { |
1494 case ui::TextEditCommand::DELETE_BACKWARD: | 1537 case ui::TextEditCommand::DELETE_BACKWARD: |
1495 case ui::TextEditCommand::DELETE_FORWARD: | 1538 case ui::TextEditCommand::DELETE_FORWARD: |
1496 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1539 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
1497 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1540 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2098 cursor_blink_timer_.Stop(); | 2141 cursor_blink_timer_.Stop(); |
2099 } | 2142 } |
2100 | 2143 |
2101 void Textfield::OnCursorBlinkTimerFired() { | 2144 void Textfield::OnCursorBlinkTimerFired() { |
2102 DCHECK(ShouldBlinkCursor()); | 2145 DCHECK(ShouldBlinkCursor()); |
2103 cursor_view_.SetVisible(!cursor_view_.visible()); | 2146 cursor_view_.SetVisible(!cursor_view_.visible()); |
2104 UpdateCursorViewPosition(); | 2147 UpdateCursorViewPosition(); |
2105 } | 2148 } |
2106 | 2149 |
2107 } // namespace views | 2150 } // namespace views |
OLD | NEW |