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

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

Issue 2259033003: New accessibility virtual keyboard behavior in non-sticky mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 4 years, 4 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/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "ui/accessibility/ax_view_state.h" 13 #include "ui/accessibility/ax_view_state.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/window.h"
13 #include "ui/base/clipboard/scoped_clipboard_writer.h" 16 #include "ui/base/clipboard/scoped_clipboard_writer.h"
14 #include "ui/base/cursor/cursor.h" 17 #include "ui/base/cursor/cursor.h"
15 #include "ui/base/default_style.h" 18 #include "ui/base/default_style.h"
16 #include "ui/base/dragdrop/drag_drop_types.h" 19 #include "ui/base/dragdrop/drag_drop_types.h"
17 #include "ui/base/dragdrop/drag_utils.h" 20 #include "ui/base/dragdrop/drag_utils.h"
18 #include "ui/base/ime/input_method.h" 21 #include "ui/base/ime/input_method.h"
19 #include "ui/base/ime/text_edit_commands.h" 22 #include "ui/base/ime/text_edit_commands.h"
20 #include "ui/base/material_design/material_design_controller.h" 23 #include "ui/base/material_design/material_design_controller.h"
21 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/ui_base_switches.h"
22 #include "ui/base/ui_base_switches_util.h" 26 #include "ui/base/ui_base_switches_util.h"
23 #include "ui/compositor/canvas_painter.h" 27 #include "ui/compositor/canvas_painter.h"
24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 28 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
25 #include "ui/display/display.h" 29 #include "ui/display/display.h"
26 #include "ui/display/screen.h" 30 #include "ui/display/screen.h"
27 #include "ui/events/base_event_utils.h" 31 #include "ui/events/base_event_utils.h"
28 #include "ui/events/event.h" 32 #include "ui/events/event.h"
29 #include "ui/events/keycodes/keyboard_codes.h" 33 #include "ui/events/keycodes/keyboard_codes.h"
30 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/geometry/insets.h" 35 #include "ui/gfx/geometry/insets.h"
(...skipping 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 gfx::Range range = GetRenderText()->selection(); 1439 gfx::Range range = GetRenderText()->selection();
1436 DCHECK_GE(range.start(), before); 1440 DCHECK_GE(range.start(), before);
1437 1441
1438 range.set_start(range.start() - before); 1442 range.set_start(range.start() - before);
1439 range.set_end(range.end() + after); 1443 range.set_end(range.end() + after);
1440 gfx::Range text_range; 1444 gfx::Range text_range;
1441 if (GetTextRange(&text_range) && text_range.Contains(range)) 1445 if (GetTextRange(&text_range) && text_range.Contains(range))
1442 DeleteRange(range); 1446 DeleteRange(range);
1443 } 1447 }
1444 1448
1445 void Textfield::EnsureCaretInRect(const gfx::Rect& rect) {} 1449 void Textfield::EnsureCaretInRect(const gfx::Rect& rect) {
1450 #if defined(OS_CHROMEOS)
1451 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1452 ::switches::kUseNewVirtualKeyboardBehavior))
1453 return;
1454
1455 // Only windows in primary display should be moved by virtual keyboard.
1456 display::Screen* screen = display::Screen::GetScreen();
1457 if (screen->GetPrimaryDisplay().id() !=
1458 screen->GetDisplayNearestWindow(GetNativeView()).id())
1459 return;
1460
1461 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
1462 if (rect != screen->GetPrimaryDisplay().bounds()) {
1463 // Calculate vertical window shift.
1464 gfx::Rect window_bounds = top_level_window->GetBoundsInRootWindow();
1465 int vertical_displacement =
1466 std::max(0, window_bounds.bottom() - rect.bottom());
1467 int shift = std::min(vertical_displacement, window_bounds.y());
1468
1469 // Set restore bounds and move window.
1470 if (shift > 0) {
1471 gfx::Point origin(window_bounds.x(), window_bounds.y() - shift);
1472 top_level_window->SetProperty(
1473 aura::client::kVirtualKeyboardRestoreBoundsKey,
1474 new gfx::Rect(window_bounds));
1475 top_level_window->SetBounds(gfx::Rect(origin, window_bounds.size()));
1476 }
1477 } else {
1478 // Restore if necessary
1479 OnClientFocusLost();
1480 }
1481 #endif
1482 }
1483
1484 void Textfield::OnClientFocusLost() {
1485 #if defined(OS_CHROMEOS)
1486 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
1487 ::switches::kUseNewVirtualKeyboardBehavior))
1488 return;
1489
1490 // Only windows in primary display should be moved by virtual keyboard.
1491 display::Screen* screen = display::Screen::GetScreen();
1492 if (screen->GetPrimaryDisplay().id() !=
1493 screen->GetDisplayNearestWindow(GetNativeView()).id())
1494 return;
1495
1496 // Get restore bounds of window.
1497 aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
1498 gfx::Rect* vk_restore_bounds = top_level_window->GetProperty(
1499 aura::client::kVirtualKeyboardRestoreBoundsKey);
1500
1501 if (vk_restore_bounds) {
1502 // Restore window.
1503 top_level_window->SetBounds(*vk_restore_bounds);
1504 top_level_window->ClearProperty(
1505 aura::client::kVirtualKeyboardRestoreBoundsKey);
1506 }
1507 #endif
1508 }
1446 1509
1447 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const { 1510 bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
1448 base::string16 result; 1511 base::string16 result;
1449 bool editable = !read_only(); 1512 bool editable = !read_only();
1450 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD; 1513 bool readable = text_input_type_ != ui::TEXT_INPUT_TYPE_PASSWORD;
1451 switch (command) { 1514 switch (command) {
1452 case ui::TextEditCommand::DELETE_BACKWARD: 1515 case ui::TextEditCommand::DELETE_BACKWARD:
1453 case ui::TextEditCommand::DELETE_FORWARD: 1516 case ui::TextEditCommand::DELETE_FORWARD:
1454 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE: 1517 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_LINE:
1455 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH: 1518 case ui::TextEditCommand::DELETE_TO_BEGINNING_OF_PARAGRAPH:
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 RequestFocus(); 2088 RequestFocus();
2026 model_->MoveCursorTo(mouse); 2089 model_->MoveCursorTo(mouse);
2027 if (!selection_clipboard_text.empty()) { 2090 if (!selection_clipboard_text.empty()) {
2028 model_->InsertText(selection_clipboard_text); 2091 model_->InsertText(selection_clipboard_text);
2029 UpdateAfterChange(true, true); 2092 UpdateAfterChange(true, true);
2030 } 2093 }
2031 OnAfterUserAction(); 2094 OnAfterUserAction();
2032 } 2095 }
2033 2096
2034 } // namespace views 2097 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | ui/views/controls/textfield/textfield_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698