Commit 7a8fab11 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

ash: modernize Views use in InSessionAuthDialog

This change:
1) Removes AuthDialogWidgetDelegate in favor of setters on the base
   WidgetDelegate class
2) Removes InSessionAuthDialog::contents_view_ in favor of storing
   the auth methods (which are the only thing it is used for) directly
   as a const member var
3) Simplifies construction of the auth dialog widget
4) Removes a couple of redundant calls to set bounds on the Widget

(4) deserves more explanation:
Before this change, CreateAuthDialogWidget() set the Widget's initial
bounds to kDefaultSize centered within the primary display, then
InSessionAuthDialog set the bounds again to change the height to the
contents view's preferred height. The first bounds set should be
unnecessary because system modals (which this is) are centered in the
screen. The second bounds set should also be unnecessary because a
widget's default size is its contents view's size. Therefore, what
this code actually accomplishes is to set the width of the widget to
340. This value is at odds with AuthDialogContentsView's actual
preferred width, which I believe is 512.

After this change, the widget's bounds are not set, nor is its size;
it is allowed to size itself to the size of its contents view, as
widgets normally do. This will make the InSessionAuthDialog large
enough to display its entire contents view, which may cause a visual
change.

Bug: 1075649
Change-Id: Ib7e972dba773ea3bf887d774fab328cbb306faad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441963Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813831}
parent f11dcca4
......@@ -18,55 +18,37 @@ namespace {
// The initial height does nothing except determining the vertical position of
// the dialog, since the dialog is centered with the initial height.
constexpr gfx::Size kDefaultSize(340, 490);
constexpr int kCornerRadius = 12;
class AuthDialogWidgetDelegate : public views::WidgetDelegate {
public:
AuthDialogWidgetDelegate() {
SetOwnedByWidget(true);
SetModalType(ui::MODAL_TYPE_SYSTEM);
}
AuthDialogWidgetDelegate(const AuthDialogWidgetDelegate&) = delete;
AuthDialogWidgetDelegate& operator=(const AuthDialogWidgetDelegate&) = delete;
~AuthDialogWidgetDelegate() override = default;
// views::WidgetDelegate:
views::View* GetInitiallyFocusedView() override {
return GetWidget()->GetContentsView();
}
};
std::unique_ptr<views::Widget> CreateAuthDialogWidget(aura::Window* parent) {
std::unique_ptr<views::Widget> CreateAuthDialogWidget(
std::unique_ptr<views::View> contents_view) {
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = new AuthDialogWidgetDelegate();
params.delegate = new views::WidgetDelegate();
params.show_state = ui::SHOW_STATE_NORMAL;
params.parent = parent;
params.parent = nullptr;
params.name = "AuthDialogWidget";
params.shadow_type = views::Widget::InitParams::ShadowType::kDrop;
params.shadow_elevation = 3;
gfx::Rect bounds = display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
bounds.ClampToCenteredSize(kDefaultSize);
params.bounds = bounds;
params.delegate->SetInitiallyFocusedView(contents_view.get());
params.delegate->SetModalType(ui::MODAL_TYPE_SYSTEM);
params.delegate->SetOwnedByWidget(true);
std::unique_ptr<views::Widget> widget = std::make_unique<views::Widget>();
widget->Init(std::move(params));
widget->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE);
widget->SetContentsView(std::move(contents_view));
return widget;
}
} // namespace
InSessionAuthDialog::InSessionAuthDialog(uint32_t auth_methods) {
widget_ = CreateAuthDialogWidget(nullptr);
contents_view_ = widget_->SetContentsView(
InSessionAuthDialog::InSessionAuthDialog(uint32_t auth_methods)
: auth_methods_(auth_methods) {
widget_ = CreateAuthDialogWidget(
std::make_unique<AuthDialogContentsView>(auth_methods));
gfx::Rect bound = widget_->GetWindowBoundsInScreen();
// Calculate initial height based on which child views are shown.
bound.set_height(contents_view_->GetPreferredSize().height());
widget_->SetBounds(bound);
aura::Window* window = widget_->GetNativeWindow();
rounded_corner_decorator_ = std::make_unique<RoundedCornerDecorator>(
......@@ -78,8 +60,7 @@ InSessionAuthDialog::InSessionAuthDialog(uint32_t auth_methods) {
InSessionAuthDialog::~InSessionAuthDialog() = default;
uint32_t InSessionAuthDialog::GetAuthMethods() const {
DCHECK(contents_view_);
return contents_view_->auth_methods();
return auth_methods_;
}
} // namespace ash
......@@ -15,7 +15,6 @@ class Widget;
namespace ash {
class AuthDialogContentsView;
class RoundedCornerDecorator;
// InSessionAuthDialog gets instantiated on every request to show
......@@ -41,7 +40,7 @@ class InSessionAuthDialog {
// Pointer to the contents view. Used to query and update the set of available
// auth methods.
AuthDialogContentsView* contents_view_ = nullptr;
const uint32_t auth_methods_;
std::unique_ptr<RoundedCornerDecorator> rounded_corner_decorator_;
};
......
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