Commit 3c83d2f6 authored by Sarah Hu's avatar Sarah Hu Committed by Commit Bot

Always position the gaia dialog in the center of the screen.

We should re-position the dialog when tablet mode is changed, and when
display metrics is changed.

Bug: 841074, 837005
Change-Id: I11299070a947e2fc4f4f494d2bbac4c94c27746e
Reviewed-on: https://chromium-review.googlesource.com/1110487Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569404}
parent 74ddb9c6
......@@ -254,7 +254,7 @@ void LoginDisplayHostMojo::UpdateGaiaDialogVisibility(
void LoginDisplayHostMojo::UpdateGaiaDialogSize(int width, int height) {
if (dialog_)
dialog_->SetSize(width, height);
dialog_->UpdateSizeAndPosition(width, height);
}
const user_manager::UserList LoginDisplayHostMojo::GetUsers() {
......
......@@ -9,6 +9,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
#include "chrome/browser/ui/ash/ash_util.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/webui/chrome_web_contents_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
#include "content/public/browser/web_contents.h"
......@@ -31,7 +32,12 @@ constexpr int kGaiaDialogWidth = 768;
OobeUIDialogDelegate::OobeUIDialogDelegate(
base::WeakPtr<LoginDisplayHostMojo> controller)
: controller_(controller),
size_(gfx::Size(kGaiaDialogWidth, kGaiaDialogHeight)) {}
size_(gfx::Size(kGaiaDialogWidth, kGaiaDialogHeight)),
display_observer_(this),
tablet_mode_observer_(this) {
display_observer_.Add(display::Screen::GetScreen());
tablet_mode_observer_.Add(TabletModeClient::Get());
}
OobeUIDialogDelegate::~OobeUIDialogDelegate() {
if (controller_)
......@@ -71,7 +77,7 @@ void OobeUIDialogDelegate::Show(bool closable_by_esc) {
void OobeUIDialogDelegate::ShowFullScreen() {
const gfx::Size& size =
display::Screen::GetScreen()->GetPrimaryDisplay().size();
SetSize(size.width(), size.height());
UpdateSizeAndPosition(size.width(), size.height());
Show(false /*closable_by_esc*/);
}
......@@ -85,10 +91,7 @@ void OobeUIDialogDelegate::Close() {
dialog_widget_->Close();
}
void OobeUIDialogDelegate::SetSize(int width, int height) {
if (size_ == gfx::Size(width, height))
return;
void OobeUIDialogDelegate::UpdateSizeAndPosition(int width, int height) {
size_.SetSize(width, height);
if (!dialog_widget_)
return;
......@@ -118,6 +121,26 @@ gfx::NativeWindow OobeUIDialogDelegate::GetNativeWindow() const {
return dialog_widget_ ? dialog_widget_->GetNativeWindow() : nullptr;
}
void OobeUIDialogDelegate::OnDisplayMetricsChanged(
const display::Display& display,
uint32_t changed_metrics) {
if (!dialog_widget_)
return;
const display::Display this_display =
display::Screen::GetScreen()->GetDisplayNearestWindow(
dialog_widget_->GetNativeWindow());
if (this_display.id() == display.id())
UpdateSizeAndPosition(size_.width(), size_.height());
}
void OobeUIDialogDelegate::OnTabletModeToggled(bool enabled) {
if (!dialog_widget_)
return;
UpdateSizeAndPosition(size_.width(), size_.height());
}
ui::ModalType OobeUIDialogDelegate::GetDialogModalType() const {
return ui::MODAL_TYPE_SYSTEM;
}
......
......@@ -9,13 +9,22 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/ash/tablet_mode_client_observer.h"
#include "ui/display/display_observer.h"
#include "ui/web_dialogs/web_dialog_delegate.h"
class TabletModeClient;
namespace content {
class WebContents;
}
namespace display {
class Screen;
}
namespace ui {
class Accelerator;
}
......@@ -37,7 +46,9 @@ class OobeUI;
// |
// V
// clientView---->Widget's view hierarchy
class OobeUIDialogDelegate : public ui::WebDialogDelegate {
class OobeUIDialogDelegate : public display::DisplayObserver,
public TabletModeClientObserver,
public ui::WebDialogDelegate {
public:
explicit OobeUIDialogDelegate(base::WeakPtr<LoginDisplayHostMojo> controller);
~OobeUIDialogDelegate() override;
......@@ -61,11 +72,17 @@ class OobeUIDialogDelegate : public ui::WebDialogDelegate {
content::WebContents* GetWebContents();
void SetSize(int width, int height);
void UpdateSizeAndPosition(int width, int height);
OobeUI* GetOobeUI() const;
gfx::NativeWindow GetNativeWindow() const;
private:
// display::DisplayObserver:
void OnDisplayMetricsChanged(const display::Display& display,
uint32_t changed_metrics) override;
// TabletModeClientObserver:
void OnTabletModeToggled(bool enabled) override;
// ui::WebDialogDelegate:
ui::ModalType GetDialogModalType() const override;
base::string16 GetDialogTitle() const override;
......@@ -93,6 +110,10 @@ class OobeUIDialogDelegate : public ui::WebDialogDelegate {
gfx::Size size_;
bool closable_by_esc_ = true;
ScopedObserver<display::Screen, display::DisplayObserver> display_observer_;
ScopedObserver<TabletModeClient, TabletModeClientObserver>
tablet_mode_observer_;
DISALLOW_COPY_AND_ASSIGN(OobeUIDialogDelegate);
};
......
......@@ -786,7 +786,9 @@ cr.define('cr.ui.login', function() {
if (this.showingViewsLogin) {
chrome.send('updateGaiaDialogSize', [width, height]);
$('scroll-container').classList.toggle('disable-scroll', true);
$('scroll-container').scrollTop = $('inner-container').offsetTop;
$('inner-container').classList.toggle('disable-scroll', true);
$('inner-container').style.top =
cr.ui.toCssPx($('scroll-container').scrollTop);
}
},
......
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