Commit e4b3b7b5 authored by Darren Shen's avatar Darren Shen Committed by Commit Bot

[VK] Use display::Display instead of display_ids.

We currently refer to displays with integer display_ids. This patch
changes them to display::Display for better type safety. It also allows
us to remove some code in display_utils.

Change-Id: Ib996613eebf1b7dcb32e5b683ad33fe6c6a6d084
Reviewed-on: https://chromium-review.googlesource.com/1056932Reviewed-by: default avatarYuichiro Hanada <yhanada@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Commit-Queue: Darren Shen <shend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558914}
parent 98e5bb29
......@@ -25,13 +25,13 @@ class KeyboardUIImpl : public KeyboardUI, public AccessibilityObserver {
Shell::Get()->accessibility_controller()->RemoveObserver(this);
}
void ShowInDisplay(const int64_t display_id) override {
void ShowInDisplay(const display::Display& display) override {
keyboard::KeyboardController* controller =
keyboard::KeyboardController::GetInstance();
// Controller may not exist if keyboard has been disabled. crbug.com/749989
if (!controller)
return;
controller->ShowKeyboardInDisplay(display_id);
controller->ShowKeyboardInDisplay(display);
}
void Hide() override {
// Do nothing as this is called from ash::Shell, which also calls through
......
......@@ -11,6 +11,10 @@
#include "base/macros.h"
#include "base/observer_list.h"
namespace display {
class Display;
}
namespace ash {
class KeyboardUIObserver;
......@@ -23,7 +27,7 @@ class ASH_EXPORT KeyboardUI {
static std::unique_ptr<KeyboardUI> Create();
virtual void ShowInDisplay(const int64_t display_id) = 0;
virtual void ShowInDisplay(const display::Display& display) = 0;
virtual void Hide() = 0;
// Returns true if the keyboard is enabled.
......
......@@ -30,7 +30,7 @@ void KeyboardUIMash::Hide() {
keyboard_->Hide();
}
void KeyboardUIMash::ShowInDisplay(const int64_t display_id) {
void KeyboardUIMash::ShowInDisplay(const display::Display& display) {
// TODO(yhanada): Send display id after adding a display_id argument to
// |Keyboard::Show()| in keyboard.mojom. See crbug.com/585253.
if (keyboard_)
......
......@@ -17,6 +17,9 @@
namespace service_manager {
class Connector;
}
namespace display {
class Display;
}
namespace ash {
......@@ -32,7 +35,7 @@ class KeyboardUIMash : public KeyboardUI,
// KeyboardUI:
void Hide() override;
void ShowInDisplay(const int64_t display_id) override;
void ShowInDisplay(const display::Display& display) override;
bool IsEnabled() override;
// keyboard::mojom::KeyboardObserver:
......
......@@ -898,8 +898,7 @@ TEST_F(VirtualKeyboardRootWindowControllerTest,
ASSERT_TRUE(vk_container_in_primary->Contains(vk_window));
ASSERT_FALSE(vk_container_in_secondary->Contains(vk_window));
const int64_t secondary_display_id = secondary_display.id();
controller->ShowKeyboardInDisplay(secondary_display_id);
controller->ShowKeyboardInDisplay(secondary_display);
EXPECT_FALSE(vk_container_in_primary->Contains(vk_window));
EXPECT_TRUE(vk_container_in_secondary->Contains(vk_window));
......@@ -1109,7 +1108,7 @@ TEST_F(VirtualKeyboardRootWindowControllerTest,
// Move the keyboard into the secondary display and check that the keyboard
// doesn't cover the window on the primary screen.
keyboard_controller->ShowKeyboardInDisplay(secondary_display_id);
keyboard_controller->ShowKeyboardInDisplay(GetSecondaryDisplay());
contents_window->SetBounds(keyboard::KeyboardBoundsFromRootBounds(
secondary_root_window->bounds(), keyboard_height));
......
......@@ -70,10 +70,9 @@ void VirtualKeyboardTray::ClickedOutsideBubble() {}
bool VirtualKeyboardTray::PerformAction(const ui::Event& event) {
UserMetricsRecorder::RecordUserClickOnTray(
LoginMetricsRecorder::TrayClickTarget::kVirtualKeyboardTray);
const int64_t display_id = display::Screen::GetScreen()
->GetDisplayNearestWindow(shelf_->GetWindow())
.id();
Shell::Get()->keyboard_ui()->ShowInDisplay(display_id);
Shell::Get()->keyboard_ui()->ShowInDisplay(
display::Screen::GetScreen()->GetDisplayNearestWindow(
shelf_->GetWindow()));
// Normally, active status is set when virtual keyboard is shown/hidden,
// however, showing virtual keyboard happens asynchronously and, especially
// the first time, takes some time. We need to set active status here to
......
......@@ -19,10 +19,6 @@ namespace keyboard {
DisplayUtil::DisplayUtil() {}
int64_t DisplayUtil::GetNearestDisplayIdToWindow(aura::Window* window) const {
return GetNearestDisplayToWindow(window).id();
}
display::Display DisplayUtil::GetNearestDisplayToWindow(
aura::Window* window) const {
return display::Screen::GetScreen()->GetDisplayNearestWindow(window);
......
......@@ -15,7 +15,6 @@ class DisplayUtil {
public:
DisplayUtil();
int64_t GetNearestDisplayIdToWindow(aura::Window* window) const;
display::Display GetNearestDisplayToWindow(aura::Window* window) const;
display::Display FindAdjacentDisplayIfPointIsNearMargin(
const display::Display& current_display,
......
......@@ -312,7 +312,7 @@ void KeyboardController::SetContainerBounds(const gfx::Rect& new_bounds,
// Do not move the keyboard to another display after switch to an IME in
// a different extension.
ShowKeyboardInDisplay(
display_util_.GetNearestDisplayIdToWindow(GetContainerWindow()));
display_util_.GetNearestDisplayToWindow(GetContainerWindow()));
} else {
ShowKeyboard(false /* lock */);
}
......@@ -428,7 +428,7 @@ void KeyboardController::HideAnimationFinished() {
}
if (queued_display_change_) {
ShowKeyboardInDisplay(queued_display_change_->new_display().id());
ShowKeyboardInDisplay(queued_display_change_->new_display());
container_->SetBounds(queued_display_change_->new_bounds_in_local());
queued_display_change_ = nullptr;
}
......@@ -459,12 +459,13 @@ void KeyboardController::SetContainerBehaviorInternal(
void KeyboardController::ShowKeyboard(bool lock) {
set_keyboard_locked(lock);
ShowKeyboardInternal(display::kInvalidDisplayId);
ShowKeyboardInternal(display::Display());
}
void KeyboardController::ShowKeyboardInDisplay(int64_t display_id) {
void KeyboardController::ShowKeyboardInDisplay(
const display::Display& display) {
set_keyboard_locked(true);
ShowKeyboardInternal(display_id);
ShowKeyboardInternal(display);
}
bool KeyboardController::IsKeyboardWindowCreated() {
......@@ -575,7 +576,7 @@ void KeyboardController::ShowKeyboardIfWithinTransientBlurThreshold() {
void KeyboardController::OnShowImeIfNeeded() {
// Calling |ShowKeyboardInternal| may move the keyboard to another display.
if (IsKeyboardEnabled() && !keyboard_locked())
ShowKeyboardInternal(display::kInvalidDisplayId);
ShowKeyboardInternal(display::Display());
}
void KeyboardController::LoadKeyboardUiInBackground() {
......@@ -589,24 +590,25 @@ void KeyboardController::LoadKeyboardUiInBackground() {
// |Shell::CreateKeyboard| was called.
DCHECK(container_.get());
PopulateKeyboardContent(display::kInvalidDisplayId, false);
PopulateKeyboardContent(display::Display(), false);
}
void KeyboardController::ShowKeyboardInternal(int64_t display_id) {
void KeyboardController::ShowKeyboardInternal(const display::Display& display) {
DCHECK(container_.get());
keyboard::MarkKeyboardLoadStarted();
PopulateKeyboardContent(display_id, true);
PopulateKeyboardContent(display, true);
}
void KeyboardController::PopulateKeyboardContent(int64_t display_id,
bool show_keyboard) {
void KeyboardController::PopulateKeyboardContent(
const display::Display& display,
bool show_keyboard) {
DCHECK(show_keyboard || state_ == KeyboardControllerState::INITIAL);
TRACE_EVENT0("vk", "PopulateKeyboardContent");
if (layout_delegate_ != nullptr) {
if (display_id != display::kInvalidDisplayId)
layout_delegate_->MoveKeyboardToDisplay(display_id);
if (display.is_valid())
layout_delegate_->MoveKeyboardToDisplay(display.id());
else
layout_delegate_->MoveKeyboardToTouchableDisplay();
}
......@@ -855,7 +857,7 @@ bool KeyboardController::SetDraggableArea(const gfx::Rect& rect) {
bool KeyboardController::DisplayVirtualKeyboard() {
// Calling |ShowKeyboardInternal| may move the keyboard to another display.
if (IsKeyboardEnabled() && !keyboard_locked()) {
ShowKeyboardInternal(display::kInvalidDisplayId);
ShowKeyboardInternal(display::Display());
return true;
}
return false;
......
......@@ -132,7 +132,7 @@ class KEYBOARD_EXPORT KeyboardController
// Force the keyboard to show up in the specific display if not showing and
// lock the keyboard
void ShowKeyboardInDisplay(const int64_t display_id);
void ShowKeyboardInDisplay(const display::Display& display);
// Sets the active keyboard controller. KeyboardController takes ownership of
// the instance. Calling ResetIntance with a new instance destroys the
......@@ -242,8 +242,9 @@ class KEYBOARD_EXPORT KeyboardController
const bool contents_loaded);
// Show virtual keyboard immediately with animation.
void ShowKeyboardInternal(int64_t display_id);
void PopulateKeyboardContent(int64_t display_id, bool show_keyboard);
void ShowKeyboardInternal(const display::Display& display);
void PopulateKeyboardContent(const display::Display& display,
bool show_keyboard);
// Returns true if keyboard is scheduled to hide.
bool WillHideKeyboard() const;
......
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