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