cros: re-center oobe ui dialog when keyboard visibility changed

Bug: 841074
Change-Id: I1862d72f637a8044b1051aeac22a4f72c6872036
Reviewed-on: https://chromium-review.googlesource.com/1150635
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578091}
diff --git a/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.cc b/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.cc
index 4a49016..1f842c4 100644
--- a/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.cc
+++ b/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.cc
@@ -19,6 +19,7 @@
 #include "content/public/browser/web_contents.h"
 #include "ui/aura/window.h"
 #include "ui/base/accelerators/accelerator.h"
+#include "ui/base/ui_base_features.h"
 #include "ui/display/display.h"
 #include "ui/display/screen.h"
 #include "ui/views/controls/webview/web_dialog_view.h"
@@ -41,9 +42,18 @@
     : controller_(controller),
       size_(gfx::Size(kGaiaDialogWidth, kGaiaDialogHeight)),
       display_observer_(this),
-      tablet_mode_observer_(this) {
+      tablet_mode_observer_(this),
+      keyboard_observer_(this) {
   display_observer_.Add(display::Screen::GetScreen());
   tablet_mode_observer_.Add(TabletModeClient::Get());
+  // TODO(mash): Support virtual keyboard under MASH. There is no
+  // KeyboardController in the browser process under MASH.
+  if (features::IsAshInBrowserProcess()) {
+    keyboard_observer_.Add(keyboard::KeyboardController::Get());
+  } else {
+    NOTIMPLEMENTED();
+  }
+
   accel_map_[ui::Accelerator(
       ui::VKEY_S, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)] = kAppLaunchBailout;
   accel_map_[ui::Accelerator(ui::VKEY_ESCAPE, 0)] = kCancel;
@@ -268,4 +278,11 @@
   return true;
 }
 
+void OobeUIDialogDelegate::OnKeyboardVisibilityStateChanged(bool is_visible) {
+  if (!dialog_widget_)
+    return;
+
+  UpdateSizeAndPosition(size_.width(), size_.height());
+}
+
 }  // namespace chromeos
diff --git a/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h b/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h
index f45bad5..e76af93 100644
--- a/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h
+++ b/chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h
@@ -16,6 +16,7 @@
 #include "chrome/browser/ui/chrome_web_modal_dialog_manager_delegate.h"
 #include "components/web_modal/web_contents_modal_dialog_host.h"
 #include "ui/display/display_observer.h"
+#include "ui/keyboard/keyboard_controller_observer.h"
 #include "ui/web_dialogs/web_dialog_delegate.h"
 
 class TabletModeClient;
@@ -53,7 +54,8 @@
                              public TabletModeClientObserver,
                              public ui::WebDialogDelegate,
                              public ChromeWebModalDialogManagerDelegate,
-                             public web_modal::WebContentsModalDialogHost {
+                             public web_modal::WebContentsModalDialogHost,
+                             public keyboard::KeyboardControllerObserver {
  public:
   explicit OobeUIDialogDelegate(base::WeakPtr<LoginDisplayHostMojo> controller);
   ~OobeUIDialogDelegate() override;
@@ -112,6 +114,9 @@
   std::vector<ui::Accelerator> GetAccelerators() override;
   bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
 
+  // keyboard::KeyboardControllerObserver:
+  void OnKeyboardVisibilityStateChanged(bool is_visible) override;
+
   base::WeakPtr<LoginDisplayHostMojo> controller_;
 
   // This is owned by the underlying native widget.
@@ -124,6 +129,8 @@
   ScopedObserver<display::Screen, display::DisplayObserver> display_observer_;
   ScopedObserver<TabletModeClient, TabletModeClientObserver>
       tablet_mode_observer_;
+  ScopedObserver<keyboard::KeyboardController, KeyboardControllerObserver>
+      keyboard_observer_;
 
   std::map<ui::Accelerator, std::string> accel_map_;