| 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; |
| 33 const int kMinimumLabelWidth = 240; | 36 const int kMinimumLabelWidth = 240; |
| 34 const int kDialogMargin = 16; | 37 const int kDialogMargin = 16; |
| 35 | 38 |
| 36 namespace { | 39 namespace { |
| 37 | 40 |
| 38 // The column set constants that can be used in the InitContent() function | 41 // The column set constants that can be used in the InitContent() function |
| 39 // to layout views. | 42 // to layout views. |
| 40 enum OneClickSigninBubbleColumnTypes { | 43 enum OneClickSigninBubbleColumnTypes { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ok_button_(NULL), | 111 ok_button_(NULL), |
| 109 undo_button_(NULL), | 112 undo_button_(NULL), |
| 110 close_button_(NULL), | 113 close_button_(NULL), |
| 111 clicked_learn_more_(false), | 114 clicked_learn_more_(false), |
| 112 message_loop_for_testing_(NULL) { | 115 message_loop_for_testing_(NULL) { |
| 113 if (is_sync_dialog_) { | 116 if (is_sync_dialog_) { |
| 114 DCHECK(!start_sync_callback_.is_null()); | 117 DCHECK(!start_sync_callback_.is_null()); |
| 115 set_arrow(views::BubbleBorder::NONE); | 118 set_arrow(views::BubbleBorder::NONE); |
| 116 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); | 119 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); |
| 117 set_close_on_deactivate(false); | 120 set_close_on_deactivate(false); |
| 118 set_margins(gfx::Insets(kDialogMargin, kDialogMargin, kDialogMargin, | |
| 119 kDialogMargin)); | |
| 120 } | 121 } |
| 122 int margin = is_sync_dialog_ ? kDialogMargin : views::kButtonVEdgeMarginNew; |
| 123 set_margins(gfx::Insets(margin, margin, margin, margin)); |
| 121 } | 124 } |
| 122 | 125 |
| 123 OneClickSigninBubbleView::~OneClickSigninBubbleView() { | 126 OneClickSigninBubbleView::~OneClickSigninBubbleView() { |
| 124 } | 127 } |
| 125 | 128 |
| 126 ui::ModalType OneClickSigninBubbleView::GetModalType() const { | 129 ui::ModalType OneClickSigninBubbleView::GetModalType() const { |
| 127 return is_sync_dialog_? ui::MODAL_TYPE_CHILD : ui::MODAL_TYPE_NONE; | 130 return is_sync_dialog_? ui::MODAL_TYPE_CHILD : ui::MODAL_TYPE_NONE; |
| 128 } | 131 } |
| 129 | 132 |
| 130 void OneClickSigninBubbleView::AnimationEnded(const gfx::Animation* animation) { | 133 void OneClickSigninBubbleView::AnimationEnded(const gfx::Animation* animation) { |
| 131 views::BubbleDelegateView::AnimationEnded(animation); | 134 views::BubbleDelegateView::AnimationEnded(animation); |
| 132 if (message_loop_for_testing_) | 135 if (message_loop_for_testing_) |
| 133 message_loop_for_testing_->Quit(); | 136 message_loop_for_testing_->Quit(); |
| 134 } | 137 } |
| 135 | 138 |
| 136 void OneClickSigninBubbleView::Init() { | 139 void OneClickSigninBubbleView::Init() { |
| 137 views::GridLayout* layout = new views::GridLayout(this); | 140 views::GridLayout* layout = new views::GridLayout(this); |
| 138 SetLayoutManager(layout); | 141 SetLayoutManager(layout); |
| 142 |
| 139 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8)); | 143 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8)); |
| 140 | 144 |
| 141 // Column set for descriptive text and link. | 145 // Column set for descriptive text and link. |
| 142 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_FILL_ALIGN); | 146 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_FILL_ALIGN); |
| 143 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | 147 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
| 144 views::GridLayout::USE_PREF, 0, 0); | 148 views::GridLayout::USE_PREF, 0, 0); |
| 145 | 149 |
| 146 // Column set for buttons at bottom of bubble. | 150 // Column set for buttons at bottom of bubble. |
| 147 cs = layout->AddColumnSet(COLUMN_SET_CONTROLS); | 151 cs = layout->AddColumnSet(COLUMN_SET_CONTROLS); |
| 148 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 152 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
| 149 views::GridLayout::USE_PREF, 0, 0); | 153 views::GridLayout::USE_PREF, 0, 0); |
| 150 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 154 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 151 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 155 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 152 views::GridLayout::USE_PREF, 0, 0); | 156 views::GridLayout::USE_PREF, 0, 0); |
| 153 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
| 154 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 157 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 155 views::GridLayout::USE_PREF, 0, 0); | 158 views::GridLayout::USE_PREF, 0, 0); |
| 156 | 159 |
| 157 is_sync_dialog_ ? InitDialogContent(layout) : InitBubbleContent(layout); | 160 is_sync_dialog_ ? InitDialogContent(layout) : InitBubbleContent(layout); |
| 158 | 161 |
| 159 // Add controls at the bottom. | 162 // Add controls at the bottom. |
| 160 // Don't display the advanced link for the error bubble. | 163 // Don't display the advanced link for the error bubble. |
| 161 if (is_sync_dialog_ || error_message_.empty()) { | 164 if (is_sync_dialog_ || error_message_.empty()) { |
| 162 InitAdvancedLink(); | 165 InitAdvancedLink(); |
| 163 layout->StartRow(0, COLUMN_SET_CONTROLS); | 166 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 164 layout->AddView(advanced_link_); | 167 layout->AddView(advanced_link_); |
| 165 } | 168 } |
| 166 | 169 |
| 167 InitButtons(layout); | 170 InitButtons(layout); |
| 168 ok_button_->SetIsDefault(true); | 171 ok_button_->SetIsDefault(true); |
| 169 | 172 |
| 170 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); | 173 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void OneClickSigninBubbleView::InitBubbleContent(views::GridLayout* layout) { | 176 void OneClickSigninBubbleView::InitBubbleContent(views::GridLayout* layout) { |
| 177 layout->set_minimum_size(gfx::Size(kMinBubbleWidth, 0)); |
| 178 |
| 179 // Add title message. |
| 180 views::ColumnSet* cs = layout->AddColumnSet(COLUMN_SET_TITLE_BAR); |
| 181 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, |
| 182 views::GridLayout::USE_PREF, 0, 0); |
| 183 { |
| 184 layout->StartRow(0, COLUMN_SET_TITLE_BAR); |
| 185 |
| 186 views::Label* label = new views::Label( |
| 187 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE_NEW)); |
| 188 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 189 label->SetFont(label->font().DeriveFont(3)); |
| 190 layout->AddView(label); |
| 191 } |
| 192 |
| 193 layout->AddPaddingRow(0, views::kUnrelatedControlLargeVerticalSpacing); |
| 194 |
| 174 // Add main text description. | 195 // Add main text description. |
| 175 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); | 196 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); |
| 176 | 197 |
| 177 views::Label* label = !error_message_.empty() ? | 198 views::Label* label = !error_message_.empty() ? |
| 178 new views::Label(error_message_) : | 199 new views::Label(error_message_) : |
| 179 new views::Label( | 200 new views::Label( |
| 180 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); | 201 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); |
| 181 | 202 |
| 182 label->SetMultiLine(true); | 203 label->SetMultiLine(true); |
| 183 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 204 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 184 label->SizeToFit(kMinimumLabelWidth); | 205 label->SizeToFit(kMinimumLabelWidth); |
| 185 layout->AddView(label); | 206 layout->AddView(label); |
| 186 | 207 |
| 208 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 209 |
| 187 layout->StartRow(0, COLUMN_SET_CONTROLS); | 210 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 188 | 211 |
| 189 InitLearnMoreLink(); | 212 InitLearnMoreLink(); |
| 190 layout->AddView(learn_more_link_); | 213 layout->AddView(learn_more_link_); |
| 191 } | 214 } |
| 192 | 215 |
| 193 void OneClickSigninBubbleView::InitDialogContent(views::GridLayout* layout) { | 216 void OneClickSigninBubbleView::InitDialogContent(views::GridLayout* layout) { |
| 194 OneClickSigninHelper::LogConfirmHistogramValue( | 217 OneClickSigninHelper::LogConfirmHistogramValue( |
| 195 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); | 218 one_click_signin::HISTOGRAM_CONFIRM_SHOWN); |
| 196 | 219 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 void OneClickSigninBubbleView::InitButtons(views::GridLayout* layout) { | 273 void OneClickSigninBubbleView::InitButtons(views::GridLayout* layout) { |
| 251 GetButtons(&ok_button_, &undo_button_); | 274 GetButtons(&ok_button_, &undo_button_); |
| 252 layout->AddView(ok_button_); | 275 layout->AddView(ok_button_); |
| 253 | 276 |
| 254 if (is_sync_dialog_) | 277 if (is_sync_dialog_) |
| 255 layout->AddView(undo_button_); | 278 layout->AddView(undo_button_); |
| 256 } | 279 } |
| 257 | 280 |
| 258 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, | 281 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, |
| 259 views::LabelButton** undo_button) { | 282 views::LabelButton** undo_button) { |
| 260 *ok_button = new views::LabelButton(this, base::string16()); | 283 base::string16 ok_label = |
| 284 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); |
| 285 |
| 286 *ok_button = new views::LabelButton(this, ok_label); |
| 261 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 287 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 262 | 288 |
| 263 // The default size of the buttons is too large. To allow them to be smaller | 289 // The default size of the buttons is too large. To allow them to be smaller |
| 264 // ignore the minimum default size., | 290 // ignore the minimum default size., |
| 265 (*ok_button)->set_min_size(gfx::Size()); | 291 (*ok_button)->set_min_size(gfx::Size()); |
| 266 | 292 |
| 267 base::string16 ok_label; | |
| 268 | |
| 269 if (is_sync_dialog_) { | 293 if (is_sync_dialog_) { |
| 270 *undo_button = new views::LabelButton(this, base::string16()); | 294 *undo_button = new views::LabelButton(this, base::string16()); |
| 271 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 295 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 272 (*undo_button)->set_min_size(gfx::Size()); | 296 (*undo_button)->set_min_size(gfx::Size()); |
| 273 | 297 |
| 274 ok_label = l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); | |
| 275 base::string16 undo_label = | 298 base::string16 undo_label = |
| 276 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); | 299 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); |
| 277 | |
| 278 // To make sure they are the same size, SetText() is called | |
| 279 // with both strings on both buttons. | |
| 280 (*ok_button)->SetText(undo_label); | |
| 281 (*ok_button)->SetText(ok_label); | |
| 282 (*undo_button)->SetText(ok_label); | |
| 283 (*undo_button)->SetText(undo_label); | 300 (*undo_button)->SetText(undo_label); |
| 284 } else { | |
| 285 ok_label = l10n_util::GetStringUTF16(IDS_OK); | |
| 286 (*ok_button)->SetText(ok_label); | |
| 287 } | 301 } |
| 288 } | 302 } |
| 289 | 303 |
| 290 void OneClickSigninBubbleView::InitAdvancedLink() { | 304 void OneClickSigninBubbleView::InitAdvancedLink() { |
| 291 advanced_link_ = new views::Link( | 305 advanced_link_ = new views::Link( |
| 292 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); | 306 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); |
| 293 | 307 |
| 294 advanced_link_->set_listener(this); | 308 advanced_link_->set_listener(this); |
| 295 advanced_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 309 advanced_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 296 } | 310 } |
| (...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 | 412 // we'll be destroyed asynchronously and the shown state will be checked |
| 399 // before then. | 413 // before then. |
| 400 DCHECK_EQ(bubble_view_, this); | 414 DCHECK_EQ(bubble_view_, this); |
| 401 bubble_view_ = NULL; | 415 bubble_view_ = NULL; |
| 402 | 416 |
| 403 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { | 417 if (is_sync_dialog_ && !start_sync_callback_.is_null()) { |
| 404 base::ResetAndReturn(&start_sync_callback_).Run( | 418 base::ResetAndReturn(&start_sync_callback_).Run( |
| 405 OneClickSigninSyncStarter::UNDO_SYNC); | 419 OneClickSigninSyncStarter::UNDO_SYNC); |
| 406 } | 420 } |
| 407 } | 421 } |
| OLD | NEW |