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

Update ShelfLayoutManager KeyboardControllerObserver methods

The floating keyboard should not cause the shelf to disappear. Although
the regular full-width keyboard should.

This CL does 3 things:
- Uses the keyboard's occluding bounds rather than visual bounds. This
  describes the area that is not accessible due to the keyboard
  covering it. This will be empty bounds in the case of a floating
  keyboard.
- Uses keyboard availability event rather than checking if bounds are
  empty to determine if the keyboard is available.
- Uses the is_locked attribute on the state descriptor object rather
  than checking the GetInstance()'s value directly. There are too many
  places where code is querying the static instance directly for the
  keyboard's current lock state and so we'd like to...lock those down.

Bug: 786290
Change-Id: I8aba795b7228a14d00a8aaf218d4f56fb1006091
Reviewed-on: https://chromium-review.googlesource.com/816483Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Commit-Queue: Blake O'Hare <blakeo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523998}
parent 86c84346
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ui/app_list/presenter/app_list.h" #include "ui/app_list/presenter/app_list.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/keyboard/keyboard_controller_observer.h"
namespace ash { namespace ash {
...@@ -289,6 +290,19 @@ StatusAreaWidget* Shelf::GetStatusAreaWidget() const { ...@@ -289,6 +290,19 @@ StatusAreaWidget* Shelf::GetStatusAreaWidget() const {
} }
void Shelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { void Shelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) {
keyboard::KeyboardStateDescriptor state;
state.is_available = !bounds.IsEmpty();
state.is_locked = false;
state.visual_bounds = bounds;
state.occluded_bounds = bounds;
state.displaced_bounds = gfx::Rect();
shelf_layout_manager_->OnKeyboardAvailabilityChanging(state.is_available);
shelf_layout_manager_->OnKeyboardVisibleBoundsChanging(state.visual_bounds);
shelf_layout_manager_->OnKeyboardWorkspaceOccludedBoundsChanging(
state.occluded_bounds);
shelf_layout_manager_->OnKeyboardWorkspaceDisplacingBoundsChanging(
state.displaced_bounds);
shelf_layout_manager_->OnKeyboardAppearanceChanging(state);
shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); shelf_layout_manager_->OnKeyboardBoundsChanging(bounds);
} }
......
...@@ -448,23 +448,21 @@ void ShelfLayoutManager::OnWindowActivated(ActivationReason reason, ...@@ -448,23 +448,21 @@ void ShelfLayoutManager::OnWindowActivated(ActivationReason reason,
UpdateAutoHideStateNow(); UpdateAutoHideStateNow();
} }
void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { void ShelfLayoutManager::OnKeyboardAppearanceChanging(
bool keyboard_is_about_to_hide = false; const keyboard::KeyboardStateDescriptor& state) {
if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) // If in locked mode, change the work area.
keyboard_is_about_to_hide = true; bool change_work_area = state.is_locked;
// If in non-sticky mode, do not change the work area. keyboard_bounds_ = state.occluded_bounds;
bool change_work_area =
keyboard::KeyboardController::GetInstance() &&
keyboard::KeyboardController::GetInstance()->keyboard_locked();
keyboard_bounds_ = new_bounds;
LayoutShelfAndUpdateBounds(change_work_area); LayoutShelfAndUpdateBounds(change_work_area);
}
void ShelfLayoutManager::OnKeyboardAvailabilityChanging(
const bool is_available) {
// On login screen if keyboard has been just hidden, update bounds just once // On login screen if keyboard has been just hidden, update bounds just once
// but ignore target_bounds.work_area_insets since shelf overlaps with login // but ignore target_bounds.work_area_insets since shelf overlaps with login
// window. // window.
if (Shell::Get()->session_controller()->IsUserSessionBlocked() && if (Shell::Get()->session_controller()->IsUserSessionBlocked() &&
keyboard_is_about_to_hide) { !is_available) {
Shell::Get()->SetDisplayWorkAreaInsets(shelf_widget_->GetNativeWindow(), Shell::Get()->SetDisplayWorkAreaInsets(shelf_widget_->GetNativeWindow(),
gfx::Insets()); gfx::Insets());
} }
......
...@@ -159,7 +159,9 @@ class ASH_EXPORT ShelfLayoutManager ...@@ -159,7 +159,9 @@ class ASH_EXPORT ShelfLayoutManager
aura::Window* lost_active) override; aura::Window* lost_active) override;
// Overridden from keyboard::KeyboardControllerObserver: // Overridden from keyboard::KeyboardControllerObserver:
void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override; void OnKeyboardAppearanceChanging(
const keyboard::KeyboardStateDescriptor& state) override;
void OnKeyboardAvailabilityChanging(const bool is_available) override;
void OnKeyboardClosed() override; void OnKeyboardClosed() override;
// Overridden from LockStateObserver: // Overridden from LockStateObserver:
......
...@@ -2113,6 +2113,19 @@ class ShelfLayoutManagerKeyboardTest : public AshTestBase { ...@@ -2113,6 +2113,19 @@ class ShelfLayoutManagerKeyboardTest : public AshTestBase {
work_area.width(), work_area.height() / 2); work_area.width(), work_area.height() / 2);
} }
void NotifyKeyboardChanging(ShelfLayoutManager* layout_manager,
bool is_locked,
const gfx::Rect& bounds) {
keyboard::KeyboardStateDescriptor state;
state.visual_bounds = bounds;
state.occluded_bounds = bounds;
state.displaced_bounds = is_locked ? bounds : gfx::Rect();
state.is_locked = is_locked;
state.is_available = !bounds.IsEmpty();
layout_manager->OnKeyboardAvailabilityChanging(state.is_available);
layout_manager->OnKeyboardAppearanceChanging(state);
}
const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; } const gfx::Rect& keyboard_bounds() const { return keyboard_bounds_; }
private: private:
...@@ -2130,7 +2143,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ShelfNotMoveOnKeyboardOpen) { ...@@ -2130,7 +2143,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ShelfNotMoveOnKeyboardOpen) {
keyboard::KeyboardController::GetInstance(); keyboard::KeyboardController::GetInstance();
// Open keyboard in non-sticky mode. // Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false); kb_controller->ShowKeyboard(false);
layout_manager->OnKeyboardBoundsChanging(keyboard_bounds()); NotifyKeyboardChanging(layout_manager, false, keyboard_bounds());
layout_manager->LayoutShelf(); layout_manager->LayoutShelf();
// Shelf position should not be changed. // Shelf position should not be changed.
...@@ -2150,7 +2163,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ...@@ -2150,7 +2163,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest,
// Open keyboard in non-sticky mode. // Open keyboard in non-sticky mode.
kb_controller->ShowKeyboard(false); kb_controller->ShowKeyboard(false);
layout_manager->OnKeyboardBoundsChanging(keyboard_bounds()); NotifyKeyboardChanging(layout_manager, false, keyboard_bounds());
layout_manager->LayoutShelf(); layout_manager->LayoutShelf();
// Work area should not be changed. // Work area should not be changed.
...@@ -2159,7 +2172,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ...@@ -2159,7 +2172,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest,
kb_controller->HideKeyboard( kb_controller->HideKeyboard(
keyboard::KeyboardController::HIDE_REASON_AUTOMATIC); keyboard::KeyboardController::HIDE_REASON_AUTOMATIC);
layout_manager->OnKeyboardBoundsChanging(gfx::Rect()); NotifyKeyboardChanging(layout_manager, false, gfx::Rect());
layout_manager->LayoutShelf(); layout_manager->LayoutShelf();
EXPECT_EQ(orig_work_area, EXPECT_EQ(orig_work_area,
display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); display::Screen::GetScreen()->GetPrimaryDisplay().work_area());
...@@ -2176,7 +2189,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ShelfShouldChangeWorkAreaInStickyMode) { ...@@ -2176,7 +2189,7 @@ TEST_F(ShelfLayoutManagerKeyboardTest, ShelfShouldChangeWorkAreaInStickyMode) {
// Open keyboard in sticky mode. // Open keyboard in sticky mode.
kb_controller->ShowKeyboard(true); kb_controller->ShowKeyboard(true);
layout_manager->OnKeyboardBoundsChanging(keyboard_bounds()); NotifyKeyboardChanging(layout_manager, true, keyboard_bounds());
layout_manager->LayoutShelf(); layout_manager->LayoutShelf();
// Work area should be changed. // Work area should be changed.
......
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