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 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 gfx::Range range = GetRenderText()->selection(); | 1480 gfx::Range range = GetRenderText()->selection(); |
1475 DCHECK_GE(range.start(), before); | 1481 DCHECK_GE(range.start(), before); |
1476 | 1482 |
1477 range.set_start(range.start() - before); | 1483 range.set_start(range.start() - before); |
1478 range.set_end(range.end() + after); | 1484 range.set_end(range.end() + after); |
1479 gfx::Range text_range; | 1485 gfx::Range text_range; |
1480 if (GetTextRange(&text_range) && text_range.Contains(range)) | 1486 if (GetTextRange(&text_range) && text_range.Contains(range)) |
1481 DeleteRange(range); | 1487 DeleteRange(range); |
1482 } | 1488 } |
1483 | 1489 |
1484 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} | 1490 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) { |
| 1491 #if defined(OS_CHROMEOS) |
| 1492 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1493 ::switches::kUseNewVirtualKeyboardBehavior)) |
| 1494 return; |
| 1495 |
| 1496 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
| 1497 gfx::Rect original_window_bounds = top_level_window->GetBoundsInScreen(); |
| 1498 if (top_level_window->GetProperty( |
| 1499 aura::client::kVirtualKeyboardRestoreBoundsKey)) { |
| 1500 original_window_bounds = *top_level_window->GetProperty( |
| 1501 aura::client::kVirtualKeyboardRestoreBoundsKey); |
| 1502 } |
| 1503 |
| 1504 gfx::Rect hidden_window_bounds_in_screen = |
| 1505 gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| 1506 if (hidden_window_bounds_in_screen.IsEmpty()) { |
| 1507 // The window isn't covered by the keyboard, restore the window position if |
| 1508 // necessary. |
| 1509 OnClientFocusLost(); |
| 1510 return; |
| 1511 } |
| 1512 |
| 1513 if (wm::MoveWindowToEnsureCaretNotInRect(top_level_window, rect_in_screen)) { |
| 1514 // Recalculate hidden_window_bounds_in_screen after moving up the window |
| 1515 original_window_bounds = top_level_window->GetBoundsInScreen(); |
| 1516 hidden_window_bounds_in_screen = |
| 1517 gfx::IntersectRects(rect_in_screen, original_window_bounds); |
| 1518 } else { |
| 1519 // No need to move the window or need to restore the window position. |
| 1520 OnClientFocusLost(); |
| 1521 } |
| 1522 #endif // defined(OS_CHROMEOS) |
| 1523 } |
| 1524 |
| 1525 void Textfield::OnClientFocusLost() { |
| 1526 #if defined(OS_CHROMEOS) |
| 1527 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1528 ::switches::kUseNewVirtualKeyboardBehavior)) |
| 1529 return; |
| 1530 |
| 1531 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow(); |
| 1532 DCHECK(top_level_window); |
| 1533 wm::RestoreWindowBoundsOnClientFocusLost(top_level_window); |
| 1534 #endif // defined(OS_CHROMEOS) |
| 1535 } |
1485 | 1536 |
1486 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { | 1537 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { |
1487 base::string16 result; | 1538 base::string16 result; |
1488 bool editable = !read_only(); | 1539 bool editable = !read_only(); |
1489 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; | 1540 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; |
1490 switch (command) { | 1541 switch (command) { |
1491 case ui::TextEditCommand::DELETE_BACKWARD: | 1542 case ui::TextEditCommand::DELETE_BACKWARD: |
1492 case ui::TextEditCommand::DELETE_FORWARD: | 1543 case ui::TextEditCommand::DELETE_FORWARD: |
1493 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: | 1544 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: |
1494 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: | 1545 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2095 cursor_blink_timer_.Stop(); | 2146 cursor_blink_timer_.Stop(); |
2096 } | 2147 } |
2097 | 2148 |
2098 void Textfield::OnCursorBlinkTimerFired() { | 2149 void Textfield::OnCursorBlinkTimerFired() { |
2099 DCHECK(ShouldBlinkCursor()); | 2150 DCHECK(ShouldBlinkCursor()); |
2100 cursor_view_.SetVisible(!cursor_view_.visible()); | 2151 cursor_view_.SetVisible(!cursor_view_.visible()); |
2101 UpdateCursorViewPosition(); | 2152 UpdateCursorViewPosition(); |
2102 } | 2153 } |
2103 | 2154 |
2104 } // namespace views | 2155 } // namespace views |
OLD | NEW |