Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: address the comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
51 56
52 #if defined(OS_WIN) 57 #if defined(OS_WIN)
53 #include "base/win/win_util.h" 58 #include "base/win/win_util.h"
54 #include "ui/base/win/osk_display_manager.h" 59 #include "ui/base/win/osk_display_manager.h"
55 #endif 60 #endif
56 61
57 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 62 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
58 #include "base/strings/utf_string_conversions.h" 63 #include "base/strings/utf_string_conversions.h"
59 #include "ui/base/ime/linux/text_edit_command_auralinux.h" 64 #include "ui/base/ime/linux/text_edit_command_auralinux.h"
60 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" 65 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
(...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 gfx::Range range = GetRenderText()->selection(); 1438 gfx::Range range = GetRenderText()->selection();
1434 DCHECK_GE(range.start(), before); 1439 DCHECK_GE(range.start(), before);
1435 1440
1436 range.set_start(range.start() - before); 1441 range.set_start(range.start() - before);
1437 range.set_end(range.end() + after); 1442 range.set_end(range.end() + after);
1438 gfx::Range text_range; 1443 gfx::Range text_range;
1439 if (GetTextRange(&text_range) && text_range.Contains(range)) 1444 if (GetTextRange(&text_range) && text_range.Contains(range))
1440 DeleteRange(range); 1445 DeleteRange(range);
1441 } 1446 }
1442 1447
1443 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect) {} 1448 void Textfield::EnsureCaretNotInRect(const gfx::Rect& rect_in_screen) {
1449 #if defined(OS_CHROMEOS)
1450 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1451 ::switches::kUseNewVirtualKeyboardBehavior))
1452 return;
1453
1454 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
1455 if (!top_level_window->GetProperty(
1456 aura::client::kVirtualKeyboardRestoreBoundsKey)) {
1457 top_level_window->SetProperty(
1458 aura::client::kVirtualKeyboardRestoreBoundsKey,
1459 new gfx::Rect(top_level_window->GetBoundsInScreen()));
1460 }
1461
1462 const gfx::Rect original_window_bounds = *top_level_window->GetProperty(
1463 aura::client::kVirtualKeyboardRestoreBoundsKey);
1464 const gfx::Rect hiding_area_in_screen(
1465 gfx::IntersectRects(rect_in_screen, original_window_bounds));
1466
1467 if (hiding_area_in_screen.IsEmpty()) {
1468 // The window isn't covered by the keyboad, restore the window position if
1469 // necessary
1470 OnClientFocusLost();
1471 return;
1472 }
1473
1474 // Calculate vertical window shift.
1475 const int vertical_displacement = std::max(0, hiding_area_in_screen.height());
1476 const int shift = std::min(vertical_displacement,
1477 top_level_window->GetBoundsInRootWindow().y());
1478
1479 // Set restore bounds and move window.
1480 if (shift > 0) {
1481 top_level_window->SetProperty(
1482 aura::client::kVirtualKeyboardRestoreBoundsKey,
1483 new gfx::Rect(original_window_bounds));
1484
1485 gfx::Point new_origin_in_root_window_space(
1486 original_window_bounds.x(), original_window_bounds.y() - shift);
1487 wm::ConvertPointFromScreen(top_level_window,
1488 &new_origin_in_root_window_space);
1489
1490 gfx::Rect new_window_bounds_in_root_window_space(
1491 new_origin_in_root_window_space, original_window_bounds.size());
1492 top_level_window->SetBounds(new_window_bounds_in_root_window_space);
1493 } else {
1494 // No need to move the window or need to restore the window position.
1495 OnClientFocusLost();
1496 }
1497 #endif // defined(OS_CHROMEOS)
1498 }
1499
1500 void Textfield::OnClientFocusLost() {
1501 #if defined(OS_CHROMEOS)
1502 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1503 ::switches::kUseNewVirtualKeyboardBehavior))
1504 return;
1505
1506 // Get restore bounds of window.
1507 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
1508 gfx::Rect* vk_restore_bounds = top_level_window->GetProperty(
1509 aura::client::kVirtualKeyboardRestoreBoundsKey);
1510
1511 if (vk_restore_bounds) {
1512 // Restore window.
1513 top_level_window->SetBounds(*vk_restore_bounds);
1514 top_level_window->ClearProperty(
1515 aura::client::kVirtualKeyboardRestoreBoundsKey);
1516 }
1517 #endif // defined(OS_CHROMEOS)
1518 }
1444 1519
1445 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { 1520 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
1446 base::string16 result; 1521 base::string16 result;
1447 bool editable = !read_only(); 1522 bool editable = !read_only();
1448 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; 1523 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD;
1449 switch (command) { 1524 switch (command) {
1450 case ui::TextEditCommand::DELETE_BACKWARD: 1525 case ui::TextEditCommand::DELETE_BACKWARD:
1451 case ui::TextEditCommand::DELETE_FORWARD: 1526 case ui::TextEditCommand::DELETE_FORWARD:
1452 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: 1527 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
1453 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: 1528 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 } 2128 }
2054 2129
2055 void Textfield::OnCursorBlinkTimerFired() { 2130 void Textfield::OnCursorBlinkTimerFired() {
2056 DCHECK(ShouldBlinkCursor()); 2131 DCHECK(ShouldBlinkCursor());
2057 gfx::RenderText* render_text = GetRenderText(); 2132 gfx::RenderText* render_text = GetRenderText();
2058 render_text->set_cursor_visible(!render_text->cursor_visible()); 2133 render_text->set_cursor_visible(!render_text->cursor_visible());
2059 RepaintCursor(); 2134 RepaintCursor();
2060 } 2135 }
2061 2136
2062 } // namespace views 2137 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698