Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/one_click_signin_bubble_view.h" | 5 #include "chrome/browser/ui/views/sync/one_click_signin_bubble_view.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "ui/events/keycodes/keyboard_codes.h" | 21 #include "ui/events/keycodes/keyboard_codes.h" |
| 22 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
| 23 #include "ui/views/controls/button/label_button.h" | 23 #include "ui/views/controls/button/label_button.h" |
| 24 #include "ui/views/controls/image_view.h" | 24 #include "ui/views/controls/image_view.h" |
| 25 #include "ui/views/controls/label.h" | 25 #include "ui/views/controls/label.h" |
| 26 #include "ui/views/controls/link.h" | 26 #include "ui/views/controls/link.h" |
| 27 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
| 28 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
| 29 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 30 | 30 |
| 31 // Minimum width of the the bubble. | |
| 32 const int kMinBubbleWidth = 310; | |
| 33 | |
| 31 // Minimum width for the multi-line label. | 34 // Minimum width for the multi-line label. |
| 32 const int kMinimumDialogLabelWidth = 400; | 35 const int kMinimumDialogLabelWidth = 400; |
|
noms (inactive)
2014/01/06 22:22:23
What's the difference between kMinBubbleWidth and
Oren Blasberg
2014/01/07 00:12:20
The bubble and dialog modes of the view aren't nec
Oren Blasberg
2014/01/08 21:44:00
As discussed offline I've moved the layout->set_mi
| |
| 33 const int kMinimumLabelWidth = 240; | 36 const int kMinimumLabelWidth = 240; |
| 37 const int kBubbleMargin = 20; | |
|
noms (inactive)
2014/01/06 22:22:23
You don't need to redefine this, you can just use
Oren Blasberg
2014/01/07 00:12:20
Done.
| |
| 34 const int kDialogMargin = 16; | 38 const int kDialogMargin = 16; |
| 35 | 39 |
| 36 namespace { | 40 namespace { |
| 37 | 41 |
| 38 // The column set constants that can be used in the InitContent() function | 42 // The column set constants that can be used in the InitContent() function |
| 39 // to layout views. | 43 // to layout views. |
| 40 enum OneClickSigninBubbleColumnTypes { | 44 enum OneClickSigninBubbleColumnTypes { |
| 41 COLUMN_SET_FILL_ALIGN, | 45 COLUMN_SET_FILL_ALIGN, |
| 42 COLUMN_SET_CONTROLS, | 46 COLUMN_SET_CONTROLS, |
| 43 COLUMN_SET_TITLE_BAR | 47 COLUMN_SET_TITLE_BAR |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 ok_button_(NULL), | 112 ok_button_(NULL), |
| 109 undo_button_(NULL), | 113 undo_button_(NULL), |
| 110 close_button_(NULL), | 114 close_button_(NULL), |
| 111 clicked_learn_more_(false), | 115 clicked_learn_more_(false), |
| 112 message_loop_for_testing_(NULL) { | 116 message_loop_for_testing_(NULL) { |
| 113 if (is_sync_dialog_) { | 117 if (is_sync_dialog_) { |
| 114 DCHECK(!start_sync_callback_.is_null()); | 118 DCHECK(!start_sync_callback_.is_null()); |
| 115 set_arrow(views::BubbleBorder::NONE); | 119 set_arrow(views::BubbleBorder::NONE); |
| 116 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); | 120 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); |
| 117 set_close_on_deactivate(false); | 121 set_close_on_deactivate(false); |
| 118 set_margins(gfx::Insets(kDialogMargin, kDialogMargin, kDialogMargin, | |
| 119 kDialogMargin)); | |
| 120 } | 122 } |
| 123 int margin = is_sync_dialog_ ? kDialogMargin : kBubbleMargin; | |
| 124 set_margins(gfx::Insets(margin, margin, margin, margin)); | |
| 121 } | 125 } |
| 122 | 126 |
| 123 OneClickSigninBubbleView::~OneClickSigninBubbleView() { | 127 OneClickSigninBubbleView::~OneClickSigninBubbleView() { |
| 124 } | 128 } |
| 125 | 129 |
| 126 ui::ModalType OneClickSigninBubbleView::GetModalType() const { | 130 ui::ModalType OneClickSigninBubbleView::GetModalType() const { |
| 127 return is_sync_dialog_? ui::MODAL_TYPE_CHILD : ui::MODAL_TYPE_NONE; | 131 return is_sync_dialog_? ui::MODAL_TYPE_CHILD : ui::MODAL_TYPE_NONE; |
| 128 } | 132 } |
| 129 | 133 |
| 130 void OneClickSigninBubbleView::AnimationEnded(const gfx::Animation* animation) { | 134 void OneClickSigninBubbleView::AnimationEnded(const gfx::Animation* animation) { |
| 131 views::BubbleDelegateView::AnimationEnded(animation); | 135 views::BubbleDelegateView::AnimationEnded(animation); |
| 132 if (message_loop_for_testing_) | 136 if (message_loop_for_testing_) |
| 133 message_loop_for_testing_->Quit(); | 137 message_loop_for_testing_->Quit(); |
| 134 } | 138 } |
| 135 | 139 |
| 136 void OneClickSigninBubbleView::Init() { | 140 void OneClickSigninBubbleView::Init() { |
| 137 views::GridLayout* layout = new views::GridLayout(this); | 141 views::GridLayout* layout = new views::GridLayout(this); |
| 138 SetLayoutManager(layout); | 142 SetLayoutManager(layout); |
| 143 layout->set_minimum_size(gfx::Size(kMinBubbleWidth, 0)); | |
| 139 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8)); | 144 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8)); |
| 140 | 145 |
| 141 // Column set for descriptive text and link. | 146 // Column set for descriptive text and link. |
| 142 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_FILL_ALIGN); | 147 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_FILL_ALIGN); |
| 143 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | 148 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 144 views::GridLayout::USE_PREF, 0, 0); | 149 views::GridLayout::USE_PREF, 0, 0); |
| 145 | 150 |
| 146 // Column set for buttons at bottom of bubble. | 151 // Column set for buttons at bottom of bubble. |
| 147 cs = layout->AddColumnSet(COLUMN_SET_CONTROLS); | 152 cs = layout->AddColumnSet(COLUMN_SET_CONTROLS); |
| 148 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 153 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
| 149 views::GridLayout::USE_PREF, 0, 0); | 154 views::GridLayout::USE_PREF, 0, 0); |
| 150 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 155 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 151 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 156 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 152 views::GridLayout::USE_PREF, 0, 0); | 157 views::GridLayout::USE_PREF, 0, 0); |
| 153 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
| 154 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 158 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 155 views::GridLayout::USE_PREF, 0, 0); | 159 views::GridLayout::USE_PREF, 0, 0); |
| 156 | 160 |
| 157 is_sync_dialog_ ? InitDialogContent(layout) : InitBubbleContent(layout); | 161 is_sync_dialog_ ? InitDialogContent(layout) : InitBubbleContent(layout); |
| 158 | 162 |
| 159 // Add controls at the bottom. | 163 // Add controls at the bottom. |
| 160 // Don't display the advanced link for the error bubble. | 164 // Don't display the advanced link for the error bubble. |
| 161 if (is_sync_dialog_ || error_message_.empty()) { | 165 if (is_sync_dialog_ || error_message_.empty()) { |
| 162 InitAdvancedLink(); | 166 InitAdvancedLink(); |
| 163 layout->StartRow(0, COLUMN_SET_CONTROLS); | 167 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 164 layout->AddView(advanced_link_); | 168 layout->AddView(advanced_link_); |
| 165 } | 169 } |
| 166 | 170 |
| 167 InitButtons(layout); | 171 InitButtons(layout); |
| 168 ok_button_->SetIsDefault(true); | 172 ok_button_->SetIsDefault(true); |
| 169 | 173 |
| 170 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); | 174 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); |
| 171 } | 175 } |
| 172 | 176 |
| 173 void OneClickSigninBubbleView::InitBubbleContent(views::GridLayout* layout) { | 177 void OneClickSigninBubbleView::InitBubbleContent(views::GridLayout* layout) { |
| 178 // Add title message. | |
| 179 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_TITLE_BAR); | |
| 180 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, | |
| 181 views::GridLayout::USE_PREF, 0, 0); | |
| 182 { | |
| 183 layout->StartRow(0, COLUMN_SET_TITLE_BAR); | |
| 184 | |
| 185 views::Label* label = new views::Label( | |
| 186 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE_NEW)); | |
| 187 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 188 label->SetFont(label->font().DeriveFont(3)); | |
| 189 layout->AddView(label); | |
| 190 } | |
| 191 | |
| 192 layout->AddPaddingRow(0, views::kUnrelatedControlLargeVerticalSpacing); | |
| 193 | |
| 174 // Add main text description. | 194 // Add main text description. |
| 175 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); | 195 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); |
| 176 | 196 |
| 177 views::Label* label = !error_message_.empty() ? | 197 views::Label* label = !error_message_.empty() ? |
| 178 new views::Label(error_message_) : | 198 new views::Label(error_message_) : |
| 179 new views::Label( | 199 new views::Label( |
| 180 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); | 200 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); |
| 181 | 201 |
| 182 label->SetMultiLine(true); | 202 label->SetMultiLine(true); |
| 183 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 203 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 184 label->SizeToFit(kMinimumLabelWidth); | 204 label->SizeToFit(kMinimumLabelWidth); |
| 185 layout->AddView(label); | 205 layout->AddView(label); |
| 186 | 206 |
| 207 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
| 208 | |
| 187 layout->StartRow(0, COLUMN_SET_CONTROLS); | 209 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 188 | 210 |
| 189 InitLearnMoreLink(); | 211 InitLearnMoreLink(); |
| 190 layout->AddView(learn_more_link_); | 212 layout->AddView(learn_more_link_); |
| 191 } | 213 } |
| 192 | 214 |
| 193 void OneClickSigninBubbleView::InitDialogContent(views::GridLayout* layout) { | 215 void OneClickSigninBubbleView::InitDialogContent(views::GridLayout* layout) { |
| 194 OneClickSigninHelper::LogConfirmHistogramValue( | 216 OneClickSigninHelper::LogConfirmHistogramValue( |
| 195 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); | 217 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); |
| 196 | 218 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 | 279 |
| 258 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, | 280 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, |
| 259 views::LabelButton** undo_button) { | 281 views::LabelButton** undo_button) { |
| 260 *ok_button = new views::LabelButton(this, base::string16()); | 282 *ok_button = new views::LabelButton(this, base::string16()); |
| 261 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 283 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 262 | 284 |
| 263 // The default size of the buttons is too large. To allow them to be smaller | 285 // The default size of the buttons is too large. To allow them to be smaller |
| 264 // ignore the minimum default size., | 286 // ignore the minimum default size., |
| 265 (*ok_button)->set_min_size(gfx::Size()); | 287 (*ok_button)->set_min_size(gfx::Size()); |
| 266 | 288 |
| 267 base::string16 ok_label; | 289 base::string16 ok_label = |
| 290 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); | |
| 268 | 291 |
| 269 if (is_sync_dialog_) { | 292 if (is_sync_dialog_) { |
| 270 *undo_button = new views::LabelButton(this, base::string16()); | 293 *undo_button = new views::LabelButton(this, base::string16()); |
| 271 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 294 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 272 (*undo_button)->set_min_size(gfx::Size()); | 295 (*undo_button)->set_min_size(gfx::Size()); |
| 273 | 296 |
| 274 ok_label = l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); | |
| 275 base::string16 undo_label = | 297 base::string16 undo_label = |
| 276 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); | 298 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); |
| 277 | 299 |
| 278 // To make sure they are the same size, SetText() is called | 300 // To make sure they are the same size, SetText() is called |
| 279 // with both strings on both buttons. | 301 // with both strings on both buttons. |
| 280 (*ok_button)->SetText(undo_label); | 302 (*ok_button)->SetText(undo_label); |
| 281 (*ok_button)->SetText(ok_label); | 303 (*ok_button)->SetText(ok_label); |
| 282 (*undo_button)->SetText(ok_label); | 304 (*undo_button)->SetText(ok_label); |
| 283 (*undo_button)->SetText(undo_label); | 305 (*undo_button)->SetText(undo_label); |
| 284 } else { | 306 } else { |
| 285 ok_label = l10n_util::GetStringUTF16(IDS_OK); | |
| 286 (*ok_button)->SetText(ok_label); | 307 (*ok_button)->SetText(ok_label); |
|
noms (inactive)
2014/01/06 22:22:23
You can move this (and above) to right under the o
Oren Blasberg
2014/01/07 00:12:20
Ah. Duh. Thanks. :)
Oren Blasberg
2014/01/07 00:12:20
Done.
| |
| 287 } | 308 } |
| 288 } | 309 } |
| 289 | 310 |
| 290 void OneClickSigninBubbleView::InitAdvancedLink() { | 311 void OneClickSigninBubbleView::InitAdvancedLink() { |
| 291 advanced_link_ = new views::Link( | 312 advanced_link_ = new views::Link( |
| 292 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); | 313 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); |
| 293 | 314 |
| 294 advanced_link_->set_listener(this); | 315 advanced_link_->set_listener(this); |
| 295 advanced_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 316 advanced_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 296 } | 317 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 // we'll be destroyed asynchronously and the shown state will be checked | 419 // we'll be destroyed asynchronously and the shown state will be checked |
| 399 // before then. | 420 // before then. |
| 400 DCHECK_EQ(bubble_view_, this); | 421 DCHECK_EQ(bubble_view_, this); |
| 401 bubble_view_ = NULL; | 422 bubble_view_ = NULL; |
| 402 | 423 |
| 403 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { | 424 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { |
| 404 base::ResetAndReturn(&start_sync_callback_).Run( | 425 base::ResetAndReturn(&start_sync_callback_).Run( |
| 405 OneClickSigninSyncStarter::UNDO_SYNC); | 426 OneClickSigninSyncStarter::UNDO_SYNC); |
| 406 } | 427 } |
| 407 } | 428 } |
| OLD | NEW |