Commit 10e8d500 authored by Jan Krcal's avatar Jan Krcal Committed by Chromium LUCI CQ

[Profile picker] Use a custom widget that defines a theme provider

This CL changes ProfilePickerView to use it's custom widget class
instead of the default one provided by DialogDelegate. This allows to
define a theme provider for the widget, based on a profile that
(sometimes) gets created throughout profile creation flow.

This is a preparatory CL for later CLs (such as CL 2569752) that will
add native views into the hierarchy that actually rely on the theme
provider.

Bug: 1126913
Change-Id: Ifed3f645a4c60035ced4b7562ab21f5d4d5b840a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2608206Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Jan Krcal <jkrcal@chromium.org>
Auto-Submit: Jan Krcal <jkrcal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841396}
parent 7d9afdd3
...@@ -134,6 +134,25 @@ GURL GetSigninURL() { ...@@ -134,6 +134,25 @@ GURL GetSigninURL() {
return signin_url; return signin_url;
} }
class ProfilePickerWidget : public views::Widget {
public:
explicit ProfilePickerWidget(ProfilePickerView* profile_picker_view)
: profile_picker_view_(profile_picker_view) {
views::Widget::InitParams params;
params.delegate = profile_picker_view_;
Init(std::move(params));
}
~ProfilePickerWidget() override = default;
// views::Widget:
const ui::ThemeProvider* GetThemeProvider() const override {
return profile_picker_view_->GetThemeProviderForProfileBeingCreated();
}
private:
ProfilePickerView* const profile_picker_view_;
};
} // namespace } // namespace
// static // static
...@@ -232,14 +251,22 @@ void ProfilePicker::SetExtendedAccountInfoTimeoutForTesting( ...@@ -232,14 +251,22 @@ void ProfilePicker::SetExtendedAccountInfoTimeoutForTesting(
} }
} }
const ui::ThemeProvider*
ProfilePickerView::GetThemeProviderForProfileBeingCreated() const {
if (!signed_in_profile_being_created_)
return nullptr;
return &ThemeService::GetThemeProviderForProfile(
signed_in_profile_being_created_);
}
ProfilePickerView::ProfilePickerView() ProfilePickerView::ProfilePickerView()
: keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW, : keep_alive_(KeepAliveOrigin::USER_MANAGER_VIEW,
KeepAliveRestartOption::DISABLED), KeepAliveRestartOption::DISABLED),
extended_account_info_timeout_(kExtendedAccountInfoTimeout) { extended_account_info_timeout_(kExtendedAccountInfoTimeout) {
// Setup the WidgetDelegate.
SetHasWindowSizeControls(true); SetHasWindowSizeControls(true);
SetButtons(ui::DIALOG_BUTTON_NONE);
SetTitle(IDS_PRODUCT_NAME); SetTitle(IDS_PRODUCT_NAME);
set_use_custom_frame(false);
ConfigureAccelerators(); ConfigureAccelerators();
// TODO(crbug.com/1063856): Add |RecordDialogCreation|. // TODO(crbug.com/1063856): Add |RecordDialogCreation|.
} }
...@@ -309,7 +336,8 @@ void ProfilePickerView::Init(ProfilePicker::EntryPoint entry_point, ...@@ -309,7 +336,8 @@ void ProfilePickerView::Init(ProfilePicker::EntryPoint entry_point,
extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
system_profile_contents_.get()); system_profile_contents_.get());
CreateDialogWidget(this, nullptr, nullptr); // The widget is owned by the native widget.
new ProfilePickerWidget(this);
#if defined(OS_WIN) #if defined(OS_WIN)
// Set the app id for the user manager to the app id of its parent. // Set the app id for the user manager to the app id of its parent.
...@@ -432,6 +460,22 @@ void ProfilePickerView::SwitchToSyncConfirmation() { ...@@ -432,6 +460,22 @@ void ProfilePickerView::SwitchToSyncConfirmation() {
sync_confirmation_ui->InitializeMessageHandlerForCreationFlow(profile_color_); sync_confirmation_ui->InitializeMessageHandlerForCreationFlow(profile_color_);
} }
void ProfilePickerView::WindowClosing() {
// Now that the window is closed, we can allow a new one to be opened.
// (WindowClosing comes in asynchronously from the call to Close() and we
// may have already opened a new instance).
if (g_profile_picker_view == this)
g_profile_picker_view = nullptr;
}
views::ClientView* ProfilePickerView::CreateClientView(views::Widget* widget) {
return new views::ClientView(widget, TransferOwnershipOfContentsView());
}
views::View* ProfilePickerView::GetContentsView() {
return this;
}
gfx::Size ProfilePickerView::CalculatePreferredSize() const { gfx::Size ProfilePickerView::CalculatePreferredSize() const {
gfx::Size preferred_size = gfx::Size(kWindowWidth, kWindowHeight); gfx::Size preferred_size = gfx::Size(kWindowWidth, kWindowHeight);
gfx::Size work_area_size = GetWidget()->GetWorkAreaBoundsInScreen().size(); gfx::Size work_area_size = GetWidget()->GetWorkAreaBoundsInScreen().size();
...@@ -443,14 +487,6 @@ gfx::Size ProfilePickerView::CalculatePreferredSize() const { ...@@ -443,14 +487,6 @@ gfx::Size ProfilePickerView::CalculatePreferredSize() const {
return preferred_size; return preferred_size;
} }
void ProfilePickerView::WindowClosing() {
// Now that the window is closed, we can allow a new one to be opened.
// (WindowClosing comes in asynchronously from the call to Close() and we
// may have already opened a new instance).
if (g_profile_picker_view == this)
g_profile_picker_view = nullptr;
}
gfx::Size ProfilePickerView::GetMinimumSize() const { gfx::Size ProfilePickerView::GetMinimumSize() const {
// On small screens, the preferred size may be smaller than the picker // On small screens, the preferred size may be smaller than the picker
// minimum size. In that case there will be scrollbars on the picker. // minimum size. In that case there will be scrollbars on the picker.
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/view.h"
#include "ui/views/widget/widget_delegate.h"
struct AccountInfo; struct AccountInfo;
class Browser; class Browser;
...@@ -31,12 +32,14 @@ class WebContents; ...@@ -31,12 +32,14 @@ class WebContents;
} // namespace content } // namespace content
// Dialog widget that contains the Desktop Profile picker webui. // Dialog widget that contains the Desktop Profile picker webui.
class ProfilePickerView : public views::DialogDelegateView, class ProfilePickerView : public views::WidgetDelegateView,
public content::WebContentsDelegate, public content::WebContentsDelegate,
public signin::IdentityManager::Observer { public signin::IdentityManager::Observer {
public: public:
using BrowserOpenedCallback = base::OnceCallback<void(Browser*)>; using BrowserOpenedCallback = base::OnceCallback<void(Browser*)>;
const ui::ThemeProvider* GetThemeProviderForProfileBeingCreated() const;
private: private:
friend class ProfilePicker; friend class ProfilePicker;
...@@ -73,11 +76,13 @@ class ProfilePickerView : public views::DialogDelegateView, ...@@ -73,11 +76,13 @@ class ProfilePickerView : public views::DialogDelegateView,
// Switches the layout to the sync confirmation screen. // Switches the layout to the sync confirmation screen.
void SwitchToSyncConfirmation(); void SwitchToSyncConfirmation();
// views::DialogDelegateView: // views::WidgetDelegate:
gfx::Size CalculatePreferredSize() const override;
void WindowClosing() override; void WindowClosing() override;
views::ClientView* CreateClientView(views::Widget* widget) override;
views::View* GetContentsView() override;
// views::View; // views::View:
gfx::Size CalculatePreferredSize() const override;
gfx::Size GetMinimumSize() const override; gfx::Size GetMinimumSize() const override;
bool AcceleratorPressed(const ui::Accelerator& accelerator) override; bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
......
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