| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.
h" | 5 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.
h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chrome/browser/ui/browser_navigator_params.h" | 14 #include "chrome/browser/ui/browser_navigator_params.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | 16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 17 #include "chrome/grit/chromium_strings.h" | 17 #include "chrome/grit/chromium_strings.h" |
| 18 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 19 #include "components/constrained_window/constrained_window_views.h" | 19 #include "components/constrained_window/constrained_window_views.h" |
| 20 #include "components/signin/core/common/profile_management_switches.h" | 20 #include "components/signin/core/common/profile_management_switches.h" |
| 21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "google_apis/gaia/gaia_auth_util.h" | 22 #include "google_apis/gaia/gaia_auth_util.h" |
| 23 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/gfx/font.h" | 25 #include "ui/gfx/font.h" |
| 26 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
| 27 #include "ui/gfx/range/range.h" | 27 #include "ui/gfx/range/range.h" |
| 28 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
| 29 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
| 30 #include "ui/views/controls/button/md_text_button.h" |
| 30 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
| 31 #include "ui/views/controls/styled_label.h" | 32 #include "ui/views/controls/styled_label.h" |
| 32 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/box_layout.h" |
| 33 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
| 34 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
| 35 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
| 36 #include "ui/views/window/dialog_client_view.h" | 37 #include "ui/views/window/dialog_client_view.h" |
| 37 | 38 |
| 38 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( | 39 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( |
| 39 Browser* browser, | 40 Browser* browser, |
| 40 const std::string& username, | 41 const std::string& username, |
| 41 ui::ProfileSigninConfirmationDelegate* delegate) | 42 ui::ProfileSigninConfirmationDelegate* delegate) |
| 42 : browser_(browser), | 43 : browser_(browser), |
| 43 username_(username), | 44 username_(username), |
| 44 delegate_(delegate), | 45 delegate_(delegate), |
| 45 prompt_for_new_profile_(true), | 46 prompt_for_new_profile_(true) {} |
| 46 continue_signin_button_(NULL) { | |
| 47 } | |
| 48 | 47 |
| 49 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} | 48 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} |
| 50 | 49 |
| 51 // static | 50 // static |
| 52 void ProfileSigninConfirmationDialogViews::ShowDialog( | 51 void ProfileSigninConfirmationDialogViews::ShowDialog( |
| 53 Browser* browser, | 52 Browser* browser, |
| 54 Profile* profile, | 53 Profile* profile, |
| 55 const std::string& username, | 54 const std::string& username, |
| 56 ui::ProfileSigninConfirmationDelegate* delegate) { | 55 ui::ProfileSigninConfirmationDelegate* delegate) { |
| 57 // Hides the new avatar bubble if it is currently shown. The new avatar bubble | 56 // Hides the new avatar bubble if it is currently shown. The new avatar bubble |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE); | 95 IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE); |
| 97 } | 96 } |
| 98 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL); | 97 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CANCEL); |
| 99 } | 98 } |
| 100 | 99 |
| 101 int ProfileSigninConfirmationDialogViews::GetDefaultDialogButton() const { | 100 int ProfileSigninConfirmationDialogViews::GetDefaultDialogButton() const { |
| 102 return ui::DIALOG_BUTTON_NONE; | 101 return ui::DIALOG_BUTTON_NONE; |
| 103 } | 102 } |
| 104 | 103 |
| 105 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() { | 104 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() { |
| 106 if (prompt_for_new_profile_) { | 105 if (!prompt_for_new_profile_) |
| 107 const base::string16 continue_signin_text = | 106 return nullptr; |
| 108 l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE); | 107 |
| 109 continue_signin_button_ = | 108 const base::string16 continue_signin_text = |
| 110 new views::LabelButton(this, continue_signin_text); | 109 l10n_util::GetStringUTF16(IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE); |
| 111 continue_signin_button_->SetStyle(views::Button::STYLE_BUTTON); | 110 return views::MdTextButton::CreateSecondaryUiButton(this, |
| 112 } | 111 continue_signin_text); |
| 113 return continue_signin_button_; | |
| 114 } | 112 } |
| 115 | 113 |
| 116 bool ProfileSigninConfirmationDialogViews::Accept() { | 114 bool ProfileSigninConfirmationDialogViews::Accept() { |
| 117 if (delegate_) { | 115 if (delegate_) { |
| 118 if (prompt_for_new_profile_) | 116 if (prompt_for_new_profile_) |
| 119 delegate_->OnSigninWithNewProfile(); | 117 delegate_->OnSigninWithNewProfile(); |
| 120 else | 118 else |
| 121 delegate_->OnContinueSignin(); | 119 delegate_->OnContinueSignin(); |
| 122 delegate_ = NULL; | 120 delegate_ = NULL; |
| 123 } | 121 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // Create the explanation label. | 173 // Create the explanation label. |
| 176 std::vector<size_t> offsets; | 174 std::vector<size_t> offsets; |
| 177 const base::string16 learn_more_text = | 175 const base::string16 learn_more_text = |
| 178 l10n_util::GetStringUTF16( | 176 l10n_util::GetStringUTF16( |
| 179 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); | 177 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); |
| 180 const base::string16 signin_explanation_text = | 178 const base::string16 signin_explanation_text = |
| 181 l10n_util::GetStringFUTF16(prompt_for_new_profile_ ? | 179 l10n_util::GetStringFUTF16(prompt_for_new_profile_ ? |
| 182 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION_NEW_STYLE : | 180 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION_NEW_STYLE : |
| 183 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION_NEW_STYLE, | 181 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION_NEW_STYLE, |
| 184 username, learn_more_text, &offsets); | 182 username, learn_more_text, &offsets); |
| 185 explanation_label_ = new views::StyledLabel(signin_explanation_text, this); | 183 views::StyledLabel* explanation_label = |
| 186 explanation_label_->AddStyleRange( | 184 new views::StyledLabel(signin_explanation_text, this); |
| 185 explanation_label->AddStyleRange( |
| 187 gfx::Range(offsets[1], offsets[1] + learn_more_text.size()), | 186 gfx::Range(offsets[1], offsets[1] + learn_more_text.size()), |
| 188 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 187 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 189 | 188 |
| 190 // Layout the components. | 189 // Layout the components. |
| 191 views::GridLayout* dialog_layout = new views::GridLayout(this); | 190 views::GridLayout* dialog_layout = new views::GridLayout(this); |
| 192 SetLayoutManager(dialog_layout); | 191 SetLayoutManager(dialog_layout); |
| 193 | 192 |
| 194 // Use GridLayout inside the prompt bar because StyledLabel requires it. | 193 // Use GridLayout inside the prompt bar because StyledLabel requires it. |
| 195 views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar); | 194 views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar); |
| 196 prompt_bar->SetLayoutManager(prompt_layout); | 195 prompt_bar->SetLayoutManager(prompt_layout); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 // Use a new column set for the explanation label so we can add padding. | 210 // Use a new column set for the explanation label so we can add padding. |
| 212 dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin); | 211 dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin); |
| 213 views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1); | 212 views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1); |
| 214 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); | 213 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); |
| 215 explanation_columns->AddColumn( | 214 explanation_columns->AddColumn( |
| 216 views::GridLayout::FILL, views::GridLayout::FILL, 100, | 215 views::GridLayout::FILL, views::GridLayout::FILL, 100, |
| 217 views::GridLayout::USE_PREF, 0, 0); | 216 views::GridLayout::USE_PREF, 0, 0); |
| 218 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); | 217 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew); |
| 219 dialog_layout->StartRow(0, 1); | 218 dialog_layout->StartRow(0, 1); |
| 220 const int kPreferredWidth = 440; | 219 const int kPreferredWidth = 440; |
| 221 dialog_layout->AddView( | 220 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL, |
| 222 explanation_label_, 1, 1, | 221 views::GridLayout::FILL, kPreferredWidth, |
| 223 views::GridLayout::FILL, views::GridLayout::FILL, | 222 explanation_label->GetHeightForWidth(kPreferredWidth)); |
| 224 kPreferredWidth, explanation_label_->GetHeightForWidth(kPreferredWidth)); | |
| 225 } | 223 } |
| 226 | 224 |
| 227 void ProfileSigninConfirmationDialogViews::WindowClosing() { | 225 void ProfileSigninConfirmationDialogViews::WindowClosing() { |
| 228 Cancel(); | 226 Cancel(); |
| 229 } | 227 } |
| 230 | 228 |
| 231 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked( | 229 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked( |
| 232 views::StyledLabel* label, | 230 views::StyledLabel* label, |
| 233 const gfx::Range& range, | 231 const gfx::Range& range, |
| 234 int event_flags) { | 232 int event_flags) { |
| 235 chrome::NavigateParams params( | 233 chrome::NavigateParams params( |
| 236 browser_, | 234 browser_, |
| 237 GURL("https://support.google.com/chromebook/answer/1331549"), | 235 GURL("https://support.google.com/chromebook/answer/1331549"), |
| 238 ui::PAGE_TRANSITION_LINK); | 236 ui::PAGE_TRANSITION_LINK); |
| 239 params.disposition = NEW_POPUP; | 237 params.disposition = NEW_POPUP; |
| 240 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 238 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| 241 chrome::Navigate(¶ms); | 239 chrome::Navigate(¶ms); |
| 242 } | 240 } |
| 243 | 241 |
| 244 void ProfileSigninConfirmationDialogViews::ButtonPressed( | 242 void ProfileSigninConfirmationDialogViews::ButtonPressed( |
| 245 views::Button* sender, | 243 views::Button* sender, |
| 246 const ui::Event& event) { | 244 const ui::Event& event) { |
| 247 DCHECK(prompt_for_new_profile_); | 245 DCHECK(prompt_for_new_profile_); |
| 248 DCHECK_EQ(continue_signin_button_, sender); | |
| 249 if (delegate_) { | 246 if (delegate_) { |
| 250 delegate_->OnContinueSignin(); | 247 delegate_->OnContinueSignin(); |
| 251 delegate_ = NULL; | 248 delegate_ = NULL; |
| 252 } | 249 } |
| 253 GetWidget()->Close(); | 250 GetWidget()->Close(); |
| 254 } | 251 } |
| OLD | NEW |