vk: Fix visual_bounds_in_screen to actually return screen bounds.

visual_bounds_in_screen used to return root bounds, not screen bounds.
Changing this will change the behavior in touch exploration manager.

Behavior for the pip positioner is not changed as it already accounts
for the incorrect visual_bounds_in_screen.

Bug: 943446
Change-Id: Ib9fe1363846aee43eaa6c5775d272586bd7f2878
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1567134
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Reviewed-by: Eliot Courtney <edcourtney@chromium.org>
Cr-Commit-Position: refs/heads/master@{#655123}
diff --git a/ash/accessibility/touch_exploration_manager.cc b/ash/accessibility/touch_exploration_manager.cc
index c3d9ba7..3d735fc2 100644
--- a/ash/accessibility/touch_exploration_manager.cc
+++ b/ash/accessibility/touch_exploration_manager.cc
@@ -239,7 +239,7 @@
     auto* keyboard_controller = keyboard::KeyboardController::Get();
     if (keyboard_controller->IsEnabled()) {
       touch_exploration_controller_->SetLiftActivationBounds(
-          keyboard_controller->visual_bounds_in_screen());
+          keyboard_controller->GetVisualBoundsInScreen());
     }
   } else {
     touch_exploration_controller_.reset();
diff --git a/ash/keyboard/ash_keyboard_controller_unittest.cc b/ash/keyboard/ash_keyboard_controller_unittest.cc
index 073a8de..4d4cb80 100644
--- a/ash/keyboard/ash_keyboard_controller_unittest.cc
+++ b/ash/keyboard/ash_keyboard_controller_unittest.cc
@@ -20,8 +20,10 @@
 #include "services/service_manager/public/cpp/connector.h"
 #include "testing/gtest/include/gtest/gtest.h"
 #include "ui/aura/window.h"
+#include "ui/display/manager/display_manager.h"
 #include "ui/keyboard/container_behavior.h"
 #include "ui/keyboard/keyboard_controller.h"
+#include "ui/keyboard/test/keyboard_test_util.h"
 
 using keyboard::mojom::KeyboardConfig;
 using keyboard::mojom::KeyboardConfigPtr;
@@ -473,4 +475,21 @@
   EXPECT_EQ(2, test_observer()->destroyed_count());
 }
 
+TEST_F(AshKeyboardControllerTest, VisualBoundsInMultipleDisplays) {
+  UpdateDisplay("800x600,800x600");
+
+  test_client()->SetEnableFlag(KeyboardEnableFlag::kExtensionEnabled);
+
+  // Show the keyboard in the second display.
+  keyboard_controller()->ShowKeyboardInDisplay(
+      Shell::Get()->display_manager()->GetSecondaryDisplay());
+  ASSERT_TRUE(keyboard::WaitUntilShown());
+
+  gfx::Rect root_bounds = keyboard_controller()->visual_bounds_in_root();
+  EXPECT_EQ(0, root_bounds.x());
+
+  gfx::Rect screen_bounds = keyboard_controller()->GetVisualBoundsInScreen();
+  EXPECT_EQ(800, screen_bounds.x());
+}
+
 }  // namespace ash
diff --git a/ash/keyboard/virtual_keyboard_unittest.cc b/ash/keyboard/virtual_keyboard_unittest.cc
index 7230635b..59fe05e 100644
--- a/ash/keyboard/virtual_keyboard_unittest.cc
+++ b/ash/keyboard/virtual_keyboard_unittest.cc
@@ -59,7 +59,7 @@
   // event passes through the keyboard window to the background window.
   ui::test::EventGenerator generator(root_window);
   const gfx::Point origin =
-      keyboard_controller->visual_bounds_in_screen().origin();
+      keyboard_controller->GetVisualBoundsInScreen().origin();
 
   // (0, 0) is inside the first hit rect, so the event is handled by the window
   // and is not received by the background window.
diff --git a/ash/magnifier/magnification_controller_unittest.cc b/ash/magnifier/magnification_controller_unittest.cc
index 421cf780..fc24f76e 100644
--- a/ash/magnifier/magnification_controller_unittest.cc
+++ b/ash/magnifier/magnification_controller_unittest.cc
@@ -991,7 +991,7 @@
   gfx::Rect viewport_outside_keyboard_bounds = GetViewport();
   viewport_outside_keyboard_bounds.set_height(
       viewport_outside_keyboard_bounds.height() -
-      keyboard_controller->visual_bounds_in_screen().height() /
+      keyboard_controller->GetVisualBoundsInScreen().height() /
           GetMagnificationController()->GetScale());
 
   gfx::Rect caret_bounds = text_input_helper_.GetCaretBounds();
diff --git a/ash/wm/collision_detection/collision_detection_utils.cc b/ash/wm/collision_detection/collision_detection_utils.cc
index 90e9cab0..7eb3aaaf 100644
--- a/ash/wm/collision_detection/collision_detection_utils.cc
+++ b/ash/wm/collision_detection/collision_detection_utils.cc
@@ -108,13 +108,11 @@
       keyboard_controller->GetActiveContainerType() ==
           keyboard::mojom::ContainerType::kFloating &&
       keyboard_controller->GetRootWindow() == root_window &&
-      !keyboard_controller->visual_bounds_in_screen().IsEmpty() &&
+      !keyboard_controller->GetVisualBoundsInScreen().IsEmpty() &&
       !ShouldIgnoreWindowForCollision(keyboard_controller->GetKeyboardWindow(),
                                       priority)) {
-    // TODO(shend): visual_bounds_in_screen should return the bounds in screen
-    // coordinates. See crbug.com/943446.
     rects.push_back(ComputeCollisionRectFromBounds(
-        keyboard_controller->visual_bounds_in_screen(),
+        keyboard_controller->visual_bounds_in_root(),
         /*parent=*/root_window));
   }
 
@@ -324,4 +322,4 @@
   return moved_bounds;
 }
 
-}  // namespace ash
\ No newline at end of file
+}  // namespace ash
diff --git a/ash/wm/lock_action_handler_layout_manager_unittest.cc b/ash/wm/lock_action_handler_layout_manager_unittest.cc
index 5ed0f1d..d47f89e 100644
--- a/ash/wm/lock_action_handler_layout_manager_unittest.cc
+++ b/ash/wm/lock_action_handler_layout_manager_unittest.cc
@@ -304,8 +304,8 @@
   ShowKeyboard(true);
 
   gfx::Rect keyboard_bounds =
-      keyboard::KeyboardController::Get()->visual_bounds_in_screen();
-  // Sanity check that the keyboard intersects woth original window bounds - if
+      keyboard::KeyboardController::Get()->GetVisualBoundsInScreen();
+  // Sanity check that the keyboard intersects with original window bounds - if
   // this is not true, the window bounds would remain unchanged.
   ASSERT_TRUE(keyboard_bounds.Intersects(initial_bounds));
 
diff --git a/ash/wm/lock_layout_manager_unittest.cc b/ash/wm/lock_layout_manager_unittest.cc
index 97982e8..c2e4032 100644
--- a/ash/wm/lock_layout_manager_unittest.cc
+++ b/ash/wm/lock_layout_manager_unittest.cc
@@ -235,7 +235,7 @@
       keyboard::mojom::KeyboardOverscrollBehavior::kEnabled);
   ShowKeyboard(true);
   EXPECT_EQ(screen_bounds.ToString(), window->GetBoundsInScreen().ToString());
-  gfx::Rect keyboard_bounds = keyboard->visual_bounds_in_screen();
+  gfx::Rect keyboard_bounds = keyboard->GetVisualBoundsInScreen();
   EXPECT_NE(keyboard_bounds, gfx::Rect());
   ShowKeyboard(false);
 
diff --git a/ui/keyboard/keyboard_controller.cc b/ui/keyboard/keyboard_controller.cc
index ad85247..156e25d 100644
--- a/ui/keyboard/keyboard_controller.cc
+++ b/ui/keyboard/keyboard_controller.cc
@@ -46,6 +46,7 @@
 #include "ui/keyboard/shaped_window_targeter.h"
 #include "ui/ozone/public/input_controller.h"
 #include "ui/ozone/public/ozone_platform.h"
+#include "ui/wm/core/coordinate_conversion.h"
 #include "ui/wm/core/window_animations.h"
 
 namespace keyboard {
@@ -369,7 +370,7 @@
   return ui_ ? ui_->GetKeyboardWindow() : nullptr;
 }
 
-aura::Window* KeyboardController::GetRootWindow() {
+aura::Window* KeyboardController::GetRootWindow() const {
   return parent_container_ ? parent_container_->GetRootWindow() : nullptr;
 }
 
@@ -754,9 +755,10 @@
   ShowKeyboardInternal(layout_delegate_->GetContainerForDisplay(display));
 }
 
-const gfx::Rect& KeyboardController::visual_bounds_in_screen() const {
-  // TODO(https://crbug.com/943446): Convert root window bounds to screen.
-  return visual_bounds_in_root_;
+gfx::Rect KeyboardController::GetVisualBoundsInScreen() const {
+  gfx::Rect visual_bounds_in_screen = visual_bounds_in_root_;
+  ::wm::ConvertRectToScreen(GetRootWindow(), &visual_bounds_in_screen);
+  return visual_bounds_in_screen;
 }
 
 void KeyboardController::LoadKeyboardWindowInBackground() {
diff --git a/ui/keyboard/keyboard_controller.h b/ui/keyboard/keyboard_controller.h
index 612c9ee..315d1ca 100644
--- a/ui/keyboard/keyboard_controller.h
+++ b/ui/keyboard/keyboard_controller.h
@@ -102,7 +102,7 @@
 
   // Returns the root window that this keyboard controller is attached to, or
   // null if the keyboard has not been attached to any root window.
-  aura::Window* GetRootWindow();
+  aura::Window* GetRootWindow() const;
 
   // Move the keyboard window to a different parent container. |parent| must not
   // be null.
@@ -175,9 +175,15 @@
   // lock the keyboard
   void ShowKeyboardInDisplay(const display::Display& display);
 
+  // Returns the bounds in root window for the visible portion of the keyboard.
+  // An empty rectangle will get returned when the keyboard is hidden.
+  const gfx::Rect& visual_bounds_in_root() const {
+    return visual_bounds_in_root_;
+  }
+
   // Returns the bounds in screen for the visible portion of the keyboard. An
   // empty rectangle will get returned when the keyboard is hidden.
-  const gfx::Rect& visual_bounds_in_screen() const;
+  gfx::Rect GetVisualBoundsInScreen() const;
 
   // Returns the current bounds that affect the workspace layout. If the
   // keyboard is not shown or if the keyboard mode should not affect the usable