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 { ...@@ -39,10 +39,11 @@ class KEYBOARD_EXPORT ContainerBehavior {
// Used by the layout manager to intercept any bounds setting request to // Used by the layout manager to intercept any bounds setting request to
// adjust the request to different bounds, if necessary. This method gets // 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( virtual const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds, 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 // Used to set the bounds to the default location. This is generally called
// during initialization, but may also be have identical behavior to // during initialization, but may also be have identical behavior to
......
...@@ -115,20 +115,20 @@ gfx::Rect ContainerFloatingBehavior::ContainKeyboardToScreenBounds( ...@@ -115,20 +115,20 @@ gfx::Rect ContainerFloatingBehavior::ContainKeyboardToScreenBounds(
int bottom = keyboard_bounds.bottom(); int bottom = keyboard_bounds.bottom();
// Prevent keyboard from appearing off screen or overlapping with the edge. // Prevent keyboard from appearing off screen or overlapping with the edge.
if (left < 0) { if (left < display_bounds.x()) {
left = 0; left = display_bounds.x();
right = keyboard_bounds.width(); right = left + keyboard_bounds.width();
} }
if (right >= display_bounds.width()) { if (right >= display_bounds.right()) {
right = display_bounds.width(); right = display_bounds.right();
left = right - keyboard_bounds.width(); left = right - keyboard_bounds.width();
} }
if (top < 0) { if (top < display_bounds.y()) {
top = 0; top = display_bounds.y();
bottom = keyboard_bounds.height(); bottom = top + keyboard_bounds.height();
} }
if (bottom >= display_bounds.height()) { if (bottom >= display_bounds.bottom()) {
bottom = display_bounds.height(); bottom = display_bounds.bottom();
top = bottom - keyboard_bounds.height(); top = bottom - keyboard_bounds.height();
} }
...@@ -162,7 +162,11 @@ gfx::Point ContainerFloatingBehavior::GetPositionForShowingKeyboard( ...@@ -162,7 +162,11 @@ gfx::Point ContainerFloatingBehavior::GetPositionForShowingKeyboard(
// Make sure that this location is valid according to the current size of the // Make sure that this location is valid according to the current size of the
// screen. // 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 = gfx::Rect valid_keyboard_bounds =
ContainKeyboardToScreenBounds(keyboard_bounds, display_bounds); ContainKeyboardToScreenBounds(keyboard_bounds, display_bounds);
......
...@@ -43,7 +43,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior { ...@@ -43,7 +43,7 @@ class KEYBOARD_EXPORT ContainerFloatingBehavior : public ContainerBehavior {
void InitializeShowAnimationStartingState(aura::Window* container) override; void InitializeShowAnimationStartingState(aura::Window* container) override;
const gfx::Rect AdjustSetBoundsRequest( const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds, 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 IsOverscrollAllowed() const override;
bool IsDragHandle(const gfx::Vector2d& offset, bool IsDragHandle(const gfx::Vector2d& offset,
const gfx::Size& keyboard_size) const override; const gfx::Size& keyboard_size) const override;
......
...@@ -48,6 +48,13 @@ TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequest) { ...@@ -48,6 +48,13 @@ TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequest) {
workspace.height() - keyboard_height, keyboard_width, workspace.height() - keyboard_height, keyboard_width,
keyboard_height), keyboard_height),
result); 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) { TEST(ContainerFloatingBehaviorTest, AdjustSetBoundsRequestVariousSides) {
......
...@@ -58,19 +58,19 @@ void ContainerFullWidthBehavior::InitializeShowAnimationStartingState( ...@@ -58,19 +58,19 @@ void ContainerFullWidthBehavior::InitializeShowAnimationStartingState(
const gfx::Rect ContainerFullWidthBehavior::AdjustSetBoundsRequest( const gfx::Rect ContainerFullWidthBehavior::AdjustSetBoundsRequest(
const gfx::Rect& display_bounds, const gfx::Rect& display_bounds,
const gfx::Rect& requested_bounds) { const gfx::Rect& requested_bounds_in_screen_coords) {
gfx::Rect new_bounds; gfx::Rect new_bounds;
// Honors only the height of the request 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); new_bounds.set_height(keyboard_height);
// If shelf is positioned on the left side of screen, x is not 0. In // 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 // FULL_WIDTH mode, the virtual keyboard should always align with the left
// edge of the screen. So manually set x to 0 here. // edge of the screen. So manually set x to the left side of the screen.
new_bounds.set_x(0); new_bounds.set_x(display_bounds.x());
new_bounds.set_width(display_bounds.width()); new_bounds.set_width(display_bounds.width());
return new_bounds; return new_bounds;
......
...@@ -35,7 +35,7 @@ class KEYBOARD_EXPORT ContainerFullWidthBehavior : public ContainerBehavior { ...@@ -35,7 +35,7 @@ class KEYBOARD_EXPORT ContainerFullWidthBehavior : public ContainerBehavior {
void InitializeShowAnimationStartingState(aura::Window* container) override; void InitializeShowAnimationStartingState(aura::Window* container) override;
const gfx::Rect AdjustSetBoundsRequest( const gfx::Rect AdjustSetBoundsRequest(
const gfx::Rect& display_bounds, 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 IsOverscrollAllowed() const override;
bool IsDragHandle(const gfx::Vector2d& offset, bool IsDragHandle(const gfx::Vector2d& offset,
const gfx::Size& keyboard_size) const override; const gfx::Size& keyboard_size) const override;
......
...@@ -18,20 +18,22 @@ class ContainerFullWidthBehaviorTest : public testing::Test { ...@@ -18,20 +18,22 @@ class ContainerFullWidthBehaviorTest : public testing::Test {
TEST(ContainerFullWidthBehaviorTest, AdjustSetBoundsRequest) { TEST(ContainerFullWidthBehaviorTest, AdjustSetBoundsRequest) {
ContainerFullWidthBehavior full_width_behavior(nullptr); 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 requested_bounds(0, 0, 10, 10);
gfx::Rect result; gfx::Rect result;
// Ignore width. Stretch the bounds across the bottom of the screen. // Ignore width. Stretch the bounds across the bottom of the screen.
result = result =
full_width_behavior.AdjustSetBoundsRequest(workspace, requested_bounds); 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. // Even if the coordinates are non-zero, ignore them. Only use height.
requested_bounds = gfx::Rect(30, 80, 20, 100); requested_bounds = gfx::Rect(30, 80, 20, 100);
result = result =
full_width_behavior.AdjustSetBoundsRequest(workspace, requested_bounds); 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 } // namespace keyboard
...@@ -14,7 +14,12 @@ namespace keyboard { ...@@ -14,7 +14,12 @@ namespace keyboard {
DisplayUtil::DisplayUtil() {} DisplayUtil::DisplayUtil() {}
int64_t DisplayUtil::GetNearestDisplayIdToWindow(aura::Window* window) const { 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 } // namespace keyboard
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define UI_KEYBOARD_DISPLAY_UTIL_H_ #define UI_KEYBOARD_DISPLAY_UTIL_H_
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/display/display.h"
namespace keyboard { namespace keyboard {
...@@ -15,6 +16,7 @@ class DisplayUtil { ...@@ -15,6 +16,7 @@ class DisplayUtil {
DisplayUtil(); DisplayUtil();
int64_t GetNearestDisplayIdToWindow(aura::Window* window) const; int64_t GetNearestDisplayIdToWindow(aura::Window* window) const;
display::Display GetNearestDisplayToWindow(aura::Window* window) const;
}; };
} // namespace keyboard } // namespace keyboard
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ui/keyboard/keyboard_layout_manager.h" #include "ui/keyboard/keyboard_layout_manager.h"
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
#include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/keyboard/keyboard_controller.h" #include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h" #include "ui/keyboard/keyboard_util.h"
...@@ -36,20 +37,29 @@ void KeyboardLayoutManager::SetChildBounds(aura::Window* child, ...@@ -36,20 +37,29 @@ void KeyboardLayoutManager::SetChildBounds(aura::Window* child,
// resized and covers the container window. Note the contents' bound is only // resized and covers the container window. Note the contents' bound is only
// set in OnWindowResized. // set in OnWindowResized.
const aura::Window* root_window = aura::Window* root_window =
controller_->GetContainerWindow()->GetRootWindow(); controller_->GetContainerWindow()->GetRootWindow();
// If the keyboard has been deactivated, this reference will be null. // If the keyboard has been deactivated, this reference will be null.
if (!root_window) if (!root_window)
return; return;
const gfx::Rect new_bounds = controller_->AdjustSetBoundsRequest( DisplayUtil display_util;
root_window->bounds(), requested_bounds); 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 // Containar bounds should only be reset when the contents window bounds
// actually change. Otherwise it interrupts the initial animation of showing // actually change. Otherwise it interrupts the initial animation of showing
// the keyboard. Described in crbug.com/356753. // the keyboard. Described in crbug.com/356753.
gfx::Rect old_bounds = contents_window_->GetTargetBounds(); gfx::Rect old_bounds = contents_window_->GetTargetBounds();
aura::Window::ConvertRectToTarget(contents_window_, root_window, &old_bounds); aura::Window::ConvertRectToTarget(contents_window_, root_window, &old_bounds);
if (new_bounds == old_bounds) if (new_bounds == old_bounds)
return; 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