Commit a92a8095 authored by Blake O'Hare's avatar Blake O'Hare Committed by Commit Bot

Fix some floating keyboard assumptions that there is only one display

Moving the floating keyboard on a secondary monitor did not work well.
The keyboard movement would be bounded to certain nonsensical ranges
that would correspond to the primary display.

Bug: 828701
Change-Id: Ic910ee48d4cfa17b37334b7d9c719090da502414
Reviewed-on: https://chromium-review.googlesource.com/994632
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547999}
parent 0ce3313c
......@@ -39,10 +39,11 @@ class KEYBOARD_EXPORT ContainerBehavior {
// Used by the layout manager to intercept any bounds setting request to
// adjust the request to different bounds, if necessary. This method gets
// called at any time during the keyboard's life cycle.
// called at any time during the keyboard's life cycle. The bounds are in
// global screen coordinates.
virtual const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) = 0;
const gfx::Rect& requested_bounds_in_screen_coords) = 0;
// Used to set the bounds to the default location. This is generally called
// during initialization, but may also be have identical behavior to
......
......@@ -115,20 +115,20 @@ gfx::Rect ContainerFloatingBehavior::ContainKeyboardToScreenBounds(
int bottom = keyboard_bounds.bottom();
// Prevent keyboard from appearing off screen or overlapping with the edge.
if (left < 0) {
left = 0;
right = keyboard_bounds.width();
if (left < display_bounds.x()) {
left = display_bounds.x();
right = left + keyboard_bounds.width();
}
if (right >= display_bounds.width()) {
right = display_bounds.width();
if (right >= display_bounds.right()) {
right = display_bounds.right();
left = right - keyboard_bounds.width();
}
if (top < 0) {
top = 0;
bottom = keyboard_bounds.height();
if (top < display_bounds.y()) {
top = display_bounds.y();
bottom = top + keyboard_bounds.height();
}
if (bottom >= display_bounds.height()) {
bottom = display_bounds.height();
if (bottom >= display_bounds.bottom()) {
bottom = display_bounds.bottom();
top = bottom - keyboard_bounds.height();
}
......@@ -162,7 +162,11 @@ gfx::Point ContainerFloatingBehavior::GetPositionForShowingKeyboard(
// Make sure that this location is valid according to the current size of the
// screen.
gfx::Rect keyboard_bounds = gfx::Rect(top_left_offset, keyboard_size);
gfx::Rect keyboard_bounds =
gfx::Rect(top_left_offset.x() + display_bounds.x(),
top_left_offset.y() + display_bounds.y(), keyboard_size.width(),
keyboard_size.height());
gfx::Rect valid_keyboard_bounds =
ContainKeyboardToScreenBounds(keyboard_bounds, display_bounds);
......
......@@ -43,7 +43,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior {
void InitializeShowAnimationStartingState(aura::Window* container) override;
const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) override;
const gfx::Rect& requested_bounds_in_screen_coords) override;
bool IsOverscrollAllowed() const override;
bool IsDragHandle(const gfx::Vector2d& offset,
const gfx::Size& keyboard_size) const override;
......
......@@ -48,6 +48,13 @@ TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequest) {
workspace.height() - keyboard_height, keyboard_width,
keyboard_height),
result);
// Try to move the keyboard to the center of the primary display while it's
// in a secondary display.
gfx::Rect secondary_display(1000, -200, 1200, 800);
result = floating_behavior.AdjustSetBoundsRequest(secondary_display, center);
// It gets clipped to the far left of this display
ASSERT_EQ(gfx::Rect(1000, 100, keyboard_width, keyboard_height), result);
}
TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequestVariousSides) {
......
......@@ -58,19 +58,19 @@ void ContainerFullWidthBehavior::InitializeShowAnimationStartingState(
const gfx::Rect ContainerFullWidthBehavior::AdjustSetBoundsRequest(
const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) {
const gfx::Rect& requested_bounds_in_screen_coords) {
gfx::Rect new_bounds;
// Honors only the height of the request bounds
const int keyboard_height = requested_bounds.height();
const int keyboard_height = requested_bounds_in_screen_coords.height();
new_bounds.set_y(display_bounds.height() - keyboard_height);
new_bounds.set_y(display_bounds.bottom() - keyboard_height);
new_bounds.set_height(keyboard_height);
// If shelf is positioned on the left side of screen, x is not 0. In
// FULL_WIDTH mode, the virtual keyboard should always align with the left
// edge of the screen. So manually set x to 0 here.
new_bounds.set_x(0);
// edge of the screen. So manually set x to the left side of the screen.
new_bounds.set_x(display_bounds.x());
new_bounds.set_width(display_bounds.width());
return new_bounds;
......
......@@ -35,7 +35,7 @@ class KEYBOARD_EXPORT ContainerFullWidthBehavior : public ContainerBehavior {
void InitializeShowAnimationStartingState(aura::Window* container) override;
const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) override;
const gfx::Rect& requested_bounds_in_screen_coords) override;
bool IsOverscrollAllowed() const override;
bool IsDragHandle(const gfx::Vector2d& offset,
const gfx::Size& keyboard_size) const override;
......
......@@ -18,20 +18,22 @@ class ContainerFullWidthBehaviorTest : public testing::Test {
TEST(ContainerFullWidthBehaviorTest, AdjustSetBoundsRequest) {
ContainerFullWidthBehavior full_width_behavior(nullptr);
gfx::Rect workspace(0, 0, 300, 200);
// workspace is not always necessarily positioned at the origin (e.g.
// secondary display).
gfx::Rect workspace(20, -30, 300, 200);
gfx::Rect requested_bounds(0, 0, 10, 10);
gfx::Rect result;
// Ignore width. Stretch the bounds across the bottom of the screen.
result =
full_width_behavior.AdjustSetBoundsRequest(workspace, requested_bounds);
ASSERT_EQ(gfx::Rect(0, 190, 300, 10), result);
ASSERT_EQ(gfx::Rect(20, 160, 300, 10), result);
// Even if the coordinates are non-zero, ignore them. Only use height.
requested_bounds = gfx::Rect(30, 80, 20, 100);
result =
full_width_behavior.AdjustSetBoundsRequest(workspace, requested_bounds);
ASSERT_EQ(gfx::Rect(0, 100, 300, 100), result);
ASSERT_EQ(gfx::Rect(20, 70, 300, 100), result);
}
} // namespace keyboard
......@@ -14,7 +14,12 @@ namespace keyboard {
DisplayUtil::DisplayUtil() {}
int64_t DisplayUtil::GetNearestDisplayIdToWindow(aura::Window* window) const {
return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id();
return GetNearestDisplayToWindow(window).id();
}
display::Display DisplayUtil::GetNearestDisplayToWindow(
aura::Window* window) const {
return display::Screen::GetScreen()->GetDisplayNearestWindow(window);
}
} // namespace keyboard
......@@ -6,6 +6,7 @@
#define UI_KEYBOARD_DISPLAY_UTIL_H_
#include "ui/aura/window.h"
#include "ui/display/display.h"
namespace keyboard {
......@@ -15,6 +16,7 @@ class DisplayUtil {
DisplayUtil();
int64_t GetNearestDisplayIdToWindow(aura::Window* window) const;
display::Display GetNearestDisplayToWindow(aura::Window* window) const;
};
} // namespace keyboard
......
......@@ -5,6 +5,7 @@
#include "ui/keyboard/keyboard_layout_manager.h"
#include "ui/compositor/layer_animator.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
......@@ -36,20 +37,29 @@ void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
// resized and covers the container window. Note the contents' bound is only
// set in OnWindowResized.
const aura::Window* root_window =
aura::Window* root_window =
controller_->GetContainerWindow()->GetRootWindow();
// If the keyboard has been deactivated, this reference will be null.
if (!root_window)
return;
const gfx::Rect new_bounds = controller_->AdjustSetBoundsRequest(
root_window->bounds(), requested_bounds);
DisplayUtil display_util;
const display::Display& display =
display_util.GetNearestDisplayToWindow(root_window);
const gfx::Vector2d display_offset =
display.bounds().origin().OffsetFromOrigin();
const gfx::Rect new_bounds =
controller_->AdjustSetBoundsRequest(display.bounds(),
requested_bounds + display_offset) -
display_offset;
// Containar bounds should only be reset when the contents window bounds
// actually change. Otherwise it interrupts the initial animation of showing
// the keyboard. Described in crbug.com/356753.
gfx::Rect old_bounds = contents_window_->GetTargetBounds();
aura::Window::ConvertRectToTarget(contents_window_, root_window, &old_bounds);
if (new_bounds == old_bounds)
return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment