Chromium Code Reviews| Index: chrome/browser/ui/views/profiles/force_signout_dialog_view.cc |
| diff --git a/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc b/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3cf8a509a691f177e8dcf90cf87db6ae3aef522a |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/profiles/force_signout_dialog_view.cc |
| @@ -0,0 +1,179 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog_view.h" |
| + |
| +#include <string> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/browser_window.h" |
| +#include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h" |
| +#include "chrome/browser/ui/views/profiles/force_signout_dialog.h" |
| +#include "chrome/grit/chromium_strings.h" |
| +#include "chrome/grit/generated_resources.h" |
| +#include "components/constrained_window/constrained_window_views.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/views/background.h" |
| +#include "ui/views/border.h" |
| +#include "ui/views/controls/styled_label.h" |
| +#include "ui/views/layout/grid_layout.h" |
| +#include "ui/views/layout/layout_constants.h" |
| +#include "ui/views/view.h" |
| +#include "ui/views/window/dialog_client_view.h" |
| + |
| +ForceSignoutDialogView::ForceSignoutDialogView(Browser* browser, |
| + ForceSignoutDialog* dialog) |
| + : dialog_(dialog) { |
| + constrained_window::CreateBrowserModalDialogViews( |
|
sky
2017/05/04 03:45:12
Can you elaborate on why you want a constrained wi
zmin
2017/05/04 23:13:52
I use constrained window as I found other modal di
|
| + this, browser->window()->GetNativeWindow()) |
| + ->Show(); |
| +} |
| + |
| +ForceSignoutDialogView::~ForceSignoutDialogView() {} |
| + |
| +bool ForceSignoutDialogView::Accept() { |
| + dialog_->OnAccept(); |
| + return true; |
| +} |
| + |
| +bool ForceSignoutDialogView::Cancel() { |
| + dialog_->OnCancel(); |
| + return true; |
| +} |
| + |
| +base::string16 ForceSignoutDialogView::GetWindowTitle() const { |
| + return dialog_->title(); |
| +} |
| + |
| +base::string16 ForceSignoutDialogView::GetDialogButtonLabel( |
| + ui::DialogButton button) const { |
| + if (button == ui::DIALOG_BUTTON_OK) |
| + return l10n_util::GetStringUTF16( |
| + IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_CONFIRM); |
| + else |
| + return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_DELAY); |
| +} |
| + |
| +int ForceSignoutDialogView::GetDialogButtons() const { |
| + if (dialog_->IsDelayAllowed()) |
| + return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| + return ui::DIALOG_BUTTON_OK; |
| +} |
| + |
| +ui::ModalType ForceSignoutDialogView::GetModalType() const { |
| + return ui::MODAL_TYPE_WINDOW; |
| +} |
| + |
| +void ForceSignoutDialogView::ViewHierarchyChanged( |
| + const ViewHierarchyChangedDetails& details) { |
|
sky
2017/05/04 03:45:12
Can this go in AddedToWidget?
zmin
2017/05/04 23:13:52
Done.
|
| + views::DialogDelegateView::ViewHierarchyChanged(details); |
| + if (!details.is_add || details.child != this) |
| + return; |
| + |
| + const SkColor kPromptBarBackgroundColor = GetSigninConfirmationPromptBarColor( |
|
sky
2017/05/04 03:45:12
kFoo style is for compile time constants. This isn
zmin
2017/05/04 23:13:52
Done.
|
| + GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha); |
| + // Create the prompt label. |
| + size_t offset; |
| + std::string email = dialog_->GetEmail(); |
| + const base::string16 domain = |
| + base::ASCIIToUTF16(gaia::ExtractDomainName(email)); |
| + const base::string16 prompt_text = |
| + l10n_util::GetStringFUTF16(IDS_ENTERPRISE_SIGNIN_ALERT, domain, &offset); |
| + views::StyledLabel* prompt_label = |
| + new views::StyledLabel(prompt_text, nullptr); |
| + prompt_label->SetDisplayedOnBackgroundColor(kPromptBarBackgroundColor); |
| + |
| + views::StyledLabel::RangeStyleInfo bold_style; |
| + bold_style.weight = gfx::Font::Weight::BOLD; |
| + prompt_label->AddStyleRange(gfx::Range(offset, offset + domain.size()), |
| + bold_style); |
| + |
| + // Create the prompt bar. |
| + views::View* prompt_bar = new views::View; |
| + prompt_bar->SetBorder(views::CreateSolidSidedBorder( |
| + 1, 0, 1, 0, |
| + ui::GetSigninConfirmationPromptBarColor( |
| + GetNativeTheme(), ui::kSigninConfirmationPromptBarBorderAlpha))); |
| + prompt_bar->set_background( |
| + views::Background::CreateSolidBackground(kPromptBarBackgroundColor)); |
| + |
| + // Create the explanation label. |
| + base::string16 signin_explanation_text; |
| + base::string16 close_warning; |
| + if (dialog_->IsDelayAllowed()) { |
| + close_warning = l10n_util::GetStringUTF16( |
| + IDS_ENTERPRISE_FORCE_SIGNOUT_ADDITIONAL_EXPLANATION); |
| + } |
| + if (email.empty()) { |
| + signin_explanation_text = l10n_util::GetStringFUTF16( |
| + IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION_WITHOUT_USER_NAME, |
| + close_warning); |
| + } else { |
| + signin_explanation_text = |
| + l10n_util::GetStringFUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION, |
| + base::ASCIIToUTF16(email), close_warning); |
| + } |
| + views::StyledLabel* explanation_label = |
| + new views::StyledLabel(signin_explanation_text, nullptr); |
| + |
| + // Layout the components. |
| + views::GridLayout* dialog_layout = new views::GridLayout(this); |
| + dialog_layout->SetInsets(views::kPanelVertMargin, 0, 0, 0); |
|
sky
2017/05/04 03:45:11
Please use the LayoutProvider constants where appr
zmin
2017/05/04 23:13:52
Done.
|
| + SetLayoutManager(dialog_layout); |
| + |
| + // Use GridLayout inside the prompt bar because StyledLabel requires it. |
| + views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar); |
| + prompt_bar->SetLayoutManager(prompt_layout); |
| + prompt_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL, |
| + views::GridLayout::CENTER, 100, |
| + views::GridLayout::USE_PREF, 0, 0); |
| + prompt_layout->StartRow(0, 0); |
| + prompt_layout->AddView(prompt_label); |
| + // Use a column set with no padding. |
| + dialog_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL, |
| + views::GridLayout::FILL, 100, |
| + views::GridLayout::USE_PREF, 0, 0); |
| + dialog_layout->StartRow(0, 0); |
| + dialog_layout->AddView(prompt_bar, 1, 1, views::GridLayout::FILL, |
| + views::GridLayout::FILL, 0, 0); |
| + |
| + // Use a new column set for the explanation label so we can add padding. |
| + dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin); |
| + views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1); |
| + explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); |
| + explanation_columns->AddColumn(views::GridLayout::FILL, |
| + views::GridLayout::FILL, 100, |
| + views::GridLayout::USE_PREF, 0, 0); |
| + explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); |
| + dialog_layout->StartRow(0, 1); |
| + const int kPreferredWidth = 440; |
| + dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL, |
| + views::GridLayout::FILL, kPreferredWidth, |
| + explanation_label->GetHeightForWidth(kPreferredWidth)); |
| +} |
| + |
| +int ForceSignoutDialogView::GetAppModalDialogButtons() const { |
| + return GetDialogButtons(); |
| +} |
| + |
| +void ForceSignoutDialogView::ShowAppModalDialog() { |
| + GetWidget()->Show(); |
| +} |
| +void ForceSignoutDialogView::ActivateAppModalDialog() { |
|
sky
2017/05/04 03:45:12
newline between functions.
zmin
2017/05/04 23:13:52
Done.
|
| + GetWidget()->Show(); |
| + GetWidget()->Activate(); |
| +} |
| +void ForceSignoutDialogView::CloseAppModalDialog() { |
| + GetWidget()->Close(); |
| +} |
| +void ForceSignoutDialogView::AcceptAppModalDialog() { |
| + GetDialogClientView()->AcceptWindow(); |
| +} |
| +void ForceSignoutDialogView::CancelAppModalDialog() { |
| + GetDialogClientView()->CancelWindow(); |
| +} |
| +bool ForceSignoutDialogView::IsShowing() const { |
| + return GetWidget()->IsVisible(); |
| +} |