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

Unified Diff: ui/views/controls/textfield/textfield.cc

Issue 2553603002: New accessibility virtual keyboard behavior in non-sticky mode. (Closed)
Patch Set: reupload Created 4 years 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/textfield/textfield.cc
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 3fbf7dfcdc1ec04a36a1d3ff63afdc2870ada3ae..9c747247b881a0bd12a4b3bd07dc5119acc08265 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -7,11 +7,14 @@
#include <string>
#include <utility>
+#include "base/command_line.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_action_data.h"
#include "ui/accessibility/ax_node_data.h"
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/window.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/default_style.h"
@@ -21,6 +24,7 @@
#include "ui/base/ime/text_edit_commands.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_switches_util.h"
#include "ui/compositor/canvas_painter.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
@@ -1440,7 +1444,67 @@ void Textfield::ExtendSelectionAndDelete(size_t before, size_t after) {
DeleteRange(range);
}
-void Textfield::EnsureCaretOutOfRect(const gfx::Rect& rect) {}
+void Textfield::EnsureCaretOutOfRect(const gfx::Rect& rect) {
+#if defined(OS_CHROMEOS)
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kUseNewVirtualKeyboardBehavior))
+ return;
+
+ const gfx::Rect hiding_area_in_this_window(
+ gfx::IntersectRects(rect, GetNativeView()->GetBoundsInScreen()));
+ if (hiding_area_in_this_window.IsEmpty()) {
+ // The window isn't covered by the keyboad, restore the window position if
+ // necessary
+ OnClientFocusLost();
+ return;
+ }
+
+ aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
+ // Calculate vertical window shift.
+ gfx::Rect visible_area_in_this_window(gfx::SubtractRects(
+ GetNativeView()->GetBoundsInScreen(), hiding_area_in_this_window));
+ const int vertical_displacement =
+ std::max(0, top_level_window->GetBoundsInScreen().bottom() -
+ visible_area_in_this_window.bottom());
+ const gfx::Rect window_bounds = top_level_window->GetBoundsInRootWindow();
+ const int shift = std::min(vertical_displacement, window_bounds.y());
+
+ // Set restore bounds and move window.
+ if (shift > 0) {
+ gfx::Point origin(window_bounds.x(), window_bounds.y() - shift);
+ top_level_window->SetProperty(
+ aura::client::kVirtualKeyboardRestoreBoundsKey,
+ new gfx::Rect(window_bounds));
+ top_level_window->SetBounds(gfx::Rect(origin, window_bounds.size()));
+ }
+#endif // defined(OS_CHROMEOS)
+}
+
+void Textfield::OnClientFocusLost() {
+#if defined(OS_CHROMEOS)
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ ::switches::kUseNewVirtualKeyboardBehavior))
+ return;
+
+ // Only windows in primary display should be moved by virtual keyboard.
+ display::Screen* screen = display::Screen::GetScreen();
+ if (screen->GetPrimaryDisplay().id() !=
+ screen->GetDisplayNearestWindow(GetNativeView()).id())
+ return;
+
+ // Get restore bounds of window.
+ aura::Window* top_level_window = GetNativeView()->GetToplevelWindow();
+ gfx::Rect* vk_restore_bounds = top_level_window->GetProperty(
+ aura::client::kVirtualKeyboardRestoreBoundsKey);
+
+ if (vk_restore_bounds) {
+ // Restore window.
+ top_level_window->SetBounds(*vk_restore_bounds);
+ top_level_window->ClearProperty(
+ aura::client::kVirtualKeyboardRestoreBoundsKey);
+ }
+#endif // defined(OS_CHROMEOS)
+}
bool Textfield::IsTextEditCommandEnabled(ui::TextEditCommand command) const {
base::string16 result;

Powered by Google App Engine
This is Rietveld 408576698