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.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.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 for the mutli-line label. | 31 // Minimum width for the multi-line label. |
| 32 const int kMinimumDialogLabelWidth = 400; | 32 const int kMinimumDialogLabelWidth = 400; |
| 33 const int kMinimumLabelWidth = 240; | 33 const int kMinimumLabelWidth = 240; |
| 34 const int kDialogMargin = 16; | 34 const int kDialogMargin = 16; |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // The column set constants that can be used in the InitContent() function | 38 // The column set constants that can be used in the InitContent() function |
| 39 // to layout views. | 39 // to layout views. |
| 40 enum OneClickSigninBubbleColumnTypes { | 40 enum OneClickSigninBubbleColumnTypes { |
| 41 COLUMN_SET_FILL_ALIGN, | 41 COLUMN_SET_FILL_ALIGN, |
| 42 COLUMN_SET_CONTROLS, | 42 COLUMN_SET_CONTROLS, |
| 43 COLUMN_SET_TITLE_BAR | 43 COLUMN_SET_TITLE_BAR |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class OneClickSigninDialogView : public OneClickSigninBubbleView { | 46 class OneClickSigninDialogView : public OneClickSigninBubbleView { |
| 47 public: | 47 public: |
| 48 OneClickSigninDialogView( | 48 OneClickSigninDialogView( |
| 49 content::WebContents* web_content, | 49 content::WebContents* web_content, |
| 50 views::View* anchor_view, | 50 views::View* anchor_view, |
| 51 const string16& email, | 51 const string16& email, |
| 52 const BrowserWindow::StartSyncCallback& start_sync_callback); | 52 const BrowserWindow::StartSyncCallback& start_sync_callback); |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 // Overridden from views::WidgetDelegate: | 55 // Overridden from views::WidgetDelegate: |
| 56 virtual ui::ModalType GetModalType() const OVERRIDE; | 56 virtual ui::ModalType GetModalType() const OVERRIDE; |
| 57 | 57 |
| 58 // Overridden from OneClickSigninBubbleView: | 58 // Overridden from OneClickSigninBubbleView: |
| 59 virtual void InitContent(views::GridLayout* layout) OVERRIDE; | 59 virtual void InitContent(views::GridLayout* layout) OVERRIDE; |
| 60 | |
| 61 virtual void InitButtons(views::GridLayout* layout) OVERRIDE; | |
| 60 virtual void GetButtons(views::LabelButton** ok_button, | 62 virtual void GetButtons(views::LabelButton** ok_button, |
| 61 views::LabelButton** undo_button) OVERRIDE; | 63 views::LabelButton** undo_button) OVERRIDE; |
| 62 virtual views::Link* GetAdvancedLink() OVERRIDE; | 64 |
| 65 // Overridden from views::ButtonListener: | |
| 66 virtual void ButtonPressed(views::Button* sender, | |
| 67 const ui::Event& event) OVERRIDE; | |
| 63 | 68 |
| 64 // Overridden from views::LinkListener: | 69 // Overridden from views::LinkListener: |
| 65 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 70 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 66 | 71 |
| 72 // views::View method: | |
| 73 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 74 | |
| 75 // views::WidgetDelegate method: | |
| 76 virtual void WindowClosing() OVERRIDE; | |
| 77 | |
| 67 const string16 email_; | 78 const string16 email_; |
| 68 content::WebContents* web_content_; | 79 |
| 69 views::Link* learn_more_link_; | 80 // This callback is nulled once its called, so that it is called only once. |
| 81 // It will be called when the bubble is closed if it has not been called | |
| 82 // and nulled earlier. | |
| 83 BrowserWindow::StartSyncCallback start_sync_callback_; | |
| 84 | |
| 70 views::ImageButton* close_button_; | 85 views::ImageButton* close_button_; |
| 71 | 86 |
| 72 DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogView); | 87 DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogView); |
| 73 }; | 88 }; |
| 74 | 89 |
| 75 OneClickSigninDialogView::OneClickSigninDialogView( | 90 OneClickSigninDialogView::OneClickSigninDialogView( |
| 76 content::WebContents* web_content, | 91 content::WebContents* web_content, |
| 77 views::View* anchor_view, | 92 views::View* anchor_view, |
| 78 const string16& email, | 93 const string16& email, |
| 79 const BrowserWindow::StartSyncCallback& start_sync_callback) | 94 const BrowserWindow::StartSyncCallback& start_sync_callback) |
| 80 : OneClickSigninBubbleView(anchor_view, start_sync_callback), | 95 : OneClickSigninBubbleView(web_content, anchor_view, std::string()), |
| 81 email_(email), | 96 email_(email), |
| 82 web_content_(web_content), | 97 close_button_(NULL), |
| 83 learn_more_link_(NULL), | 98 start_sync_callback_(start_sync_callback) { |
| 84 close_button_(NULL) { | 99 DCHECK(!start_sync_callback_.is_null()); |
| 85 set_arrow(views::BubbleBorder::NONE); | 100 set_arrow(views::BubbleBorder::NONE); |
| 86 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); | 101 set_anchor_view_insets(gfx::Insets(0, 0, anchor_view->height() / 2, 0)); |
| 87 set_close_on_deactivate(false); | 102 set_close_on_deactivate(false); |
| 88 set_margins(gfx::Insets(kDialogMargin, kDialogMargin, kDialogMargin, | 103 set_margins(gfx::Insets(kDialogMargin, kDialogMargin, kDialogMargin, |
| 89 kDialogMargin)); | 104 kDialogMargin)); |
| 90 } | 105 } |
| 91 | 106 |
| 92 ui::ModalType OneClickSigninDialogView::GetModalType() const { | 107 ui::ModalType OneClickSigninDialogView::GetModalType() const { |
| 93 return ui::MODAL_TYPE_CHILD; | 108 return ui::MODAL_TYPE_CHILD; |
| 94 } | 109 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 115 label->SetFont(label->font().DeriveFont(3, gfx::Font::BOLD)); | 130 label->SetFont(label->font().DeriveFont(3, gfx::Font::BOLD)); |
| 116 layout->AddView(label); | 131 layout->AddView(label); |
| 117 | 132 |
| 118 close_button_ = new views::ImageButton(this); | 133 close_button_ = new views::ImageButton(this); |
| 119 close_button_->SetImage(views::ImageButton::STATE_NORMAL, | 134 close_button_->SetImage(views::ImageButton::STATE_NORMAL, |
| 120 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia()); | 135 rb.GetImageNamed(IDR_CLOSE_2).ToImageSkia()); |
| 121 close_button_->SetImage(views::ImageButton::STATE_HOVERED, | 136 close_button_->SetImage(views::ImageButton::STATE_HOVERED, |
| 122 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); | 137 rb.GetImageNamed(IDR_CLOSE_2_H).ToImageSkia()); |
| 123 close_button_->SetImage(views::ImageButton::STATE_PRESSED, | 138 close_button_->SetImage(views::ImageButton::STATE_PRESSED, |
| 124 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); | 139 rb.GetImageNamed(IDR_CLOSE_2_P).ToImageSkia()); |
| 140 | |
| 125 layout->AddView(close_button_); | 141 layout->AddView(close_button_); |
| 126 } | 142 } |
| 127 | 143 |
| 128 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 144 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 129 | 145 |
| 130 { | 146 { |
| 131 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); | 147 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); |
| 132 | 148 |
| 133 views::Label* label = new views::Label(email_.empty() ? | 149 views::Label* label = new views::Label(email_.empty() ? |
| 134 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE) : | 150 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE) : |
| 135 l10n_util::GetStringFUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE_NEW, | 151 l10n_util::GetStringFUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE_NEW, |
| 136 email_)); | 152 email_)); |
| 137 label->SetMultiLine(true); | 153 label->SetMultiLine(true); |
| 138 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 154 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 139 label->SizeToFit(kMinimumDialogLabelWidth); | 155 label->SizeToFit(kMinimumDialogLabelWidth); |
| 140 layout->AddView(label); | 156 layout->AddView(label); |
| 141 | 157 |
| 142 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); | 158 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); |
| 143 | 159 |
| 144 learn_more_link_ = new views::Link( | 160 learn_more_link_ = GetLearnMoreLink(); |
| 145 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); | |
| 146 learn_more_link_->set_listener(this); | |
| 147 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 148 layout->AddView(learn_more_link_, 1, 1, views::GridLayout::TRAILING, | 161 layout->AddView(learn_more_link_, 1, 1, views::GridLayout::TRAILING, |
| 149 views::GridLayout::CENTER); | 162 views::GridLayout::CENTER); |
| 150 } | 163 } |
| 151 | 164 |
| 152 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 165 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 153 } | 166 } |
| 154 | 167 |
| 168 void OneClickSigninDialogView::InitButtons(views::GridLayout* layout) { | |
| 169 GetButtons(&ok_button_, &undo_button_); | |
| 170 layout->AddView(ok_button_); | |
| 171 layout->AddView(undo_button_); | |
| 172 } | |
| 173 | |
| 155 void OneClickSigninDialogView::GetButtons(views::LabelButton** ok_button, | 174 void OneClickSigninDialogView::GetButtons(views::LabelButton** ok_button, |
| 156 views::LabelButton** undo_button) { | 175 views::LabelButton** undo_button) { |
| 157 *ok_button = new views::LabelButton(this, string16()); | 176 *ok_button = new views::LabelButton(this, string16()); |
| 158 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 177 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 159 | 178 |
| 160 *undo_button = new views::LabelButton(this, string16()); | 179 *undo_button = new views::LabelButton(this, string16()); |
| 161 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 180 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 162 | 181 |
| 163 // The default size of the buttons is too large. To allow them to be smaller | 182 // The default size of the buttons is too large. To allow them to be smaller |
| 164 // ignore the minimum default size. Furthermore, to make sure they are the | 183 // ignore the minimum default size. Furthermore, to make sure they are the |
| 165 // same size, SetText() is called with both strings on both buttons. | 184 // same size, SetText() is called with both strings on both buttons. |
| 166 (*ok_button)->set_min_size(gfx::Size()); | 185 (*ok_button)->set_min_size(gfx::Size()); |
| 167 (*undo_button)->set_min_size(gfx::Size()); | 186 (*undo_button)->set_min_size(gfx::Size()); |
| 168 string16 ok_label = | 187 string16 ok_label = |
| 169 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); | 188 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); |
| 170 string16 undo_label = | 189 string16 undo_label = |
| 171 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); | 190 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); |
| 172 (*ok_button)->SetText(undo_label); | 191 (*ok_button)->SetText(undo_label); |
| 173 (*ok_button)->SetText(ok_label); | 192 (*ok_button)->SetText(ok_label); |
| 174 (*undo_button)->SetText(ok_label); | 193 (*undo_button)->SetText(ok_label); |
| 175 (*undo_button)->SetText(undo_label); | 194 (*undo_button)->SetText(undo_label); |
| 176 } | 195 } |
| 177 | 196 |
| 178 views::Link* OneClickSigninDialogView::GetAdvancedLink() { | 197 void OneClickSigninDialogView::ButtonPressed(views::Button* sender, |
| 179 views::Link* advanced_link= new views::Link( | 198 const ui::Event& event) { |
| 180 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); | 199 OneClickSigninBubbleView::ButtonPressed(sender, event); |
| 181 advanced_link->set_listener(this); | 200 |
| 182 advanced_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 201 base::ResetAndReturn(&start_sync_callback_).Run((sender == ok_button_) ? |
| 183 return advanced_link; | 202 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS : |
| 203 OneClickSigninSyncStarter::UNDO_SYNC); | |
| 184 } | 204 } |
| 185 | 205 |
| 186 void OneClickSigninDialogView::LinkClicked(views::Link* source, | 206 void OneClickSigninDialogView::LinkClicked(views::Link* source, |
| 187 int event_flags) { | 207 int event_flags) { |
| 188 if (source == learn_more_link_) { | 208 if (source == learn_more_link_) { |
| 189 content::OpenURLParams params( | 209 content::OpenURLParams params( |
| 190 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), | 210 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), |
| 191 NEW_WINDOW, content::PAGE_TRANSITION_LINK, false); | 211 NEW_WINDOW, content::PAGE_TRANSITION_LINK, false); |
| 192 web_content_->OpenURL(params); | 212 web_content_->OpenURL(params); |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
This is duplicated in the base class. I wonder if
| |
| 193 return; | 213 return; |
| 194 } | 214 } |
| 195 | 215 |
| 196 OneClickSigninBubbleView::LinkClicked(source, event_flags); | 216 base::ResetAndReturn(&start_sync_callback_).Run( |
| 217 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | |
| 218 | |
| 219 OneClickSigninBubbleView::Hide(); | |
| 197 } | 220 } |
| 198 | 221 |
| 222 bool OneClickSigninDialogView::AcceleratorPressed( | |
| 223 const ui::Accelerator& accelerator) { | |
| 224 bool isAcceleratorPressed = | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
variable naming should be:
is_accelerator_pressed
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 225 OneClickSigninBubbleView::AcceleratorPressed(accelerator); | |
| 226 | |
| 227 if (accelerator.key_code() == ui::VKEY_RETURN) { | |
| 228 base::ResetAndReturn(&start_sync_callback_).Run( | |
| 229 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
| 230 } else { | |
| 231 start_sync_callback_.Reset(); | |
| 232 } | |
| 233 | |
| 234 return isAcceleratorPressed; | |
| 235 } | |
| 236 | |
| 237 void OneClickSigninDialogView::WindowClosing() { | |
| 238 OneClickSigninBubbleView::WindowClosing(); | |
| 239 | |
| 240 if (!start_sync_callback_.is_null()) { | |
| 241 base::ResetAndReturn(&start_sync_callback_).Run( | |
| 242 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
| 243 } | |
| 244 } | |
| 199 } // namespace | 245 } // namespace |
| 200 | 246 |
| 201 // OneClickSigninBubbleView ---------------------------------------------------- | 247 // OneClickSigninBubbleView ---------------------------------------------------- |
| 202 | 248 |
| 203 // static | 249 // static |
| 204 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; | 250 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; |
| 205 | 251 |
| 206 // static | 252 // static |
| 207 void OneClickSigninBubbleView::ShowBubble( | 253 void OneClickSigninBubbleView::ShowBubble( |
| 208 BrowserWindow::OneClickSigninBubbleType type, | 254 BrowserWindow::OneClickSigninBubbleType type, |
| 209 const string16& email, | 255 const string16& email, |
| 210 ToolbarView* toolbar_view, | 256 ToolbarView* toolbar_view, |
| 211 const BrowserWindow::StartSyncCallback& start_sync) { | 257 const BrowserWindow::StartSyncCallback& start_sync, |
| 258 const std::string& error_message) { | |
| 212 if (IsShowing()) | 259 if (IsShowing()) |
| 213 return; | 260 return; |
| 214 | 261 |
| 215 switch (type) { | 262 switch (type) { |
| 216 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE: | 263 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_BUBBLE: |
| 217 bubble_view_ = new OneClickSigninBubbleView(toolbar_view->app_menu(), | 264 bubble_view_ = new OneClickSigninBubbleView( |
| 218 start_sync); | 265 toolbar_view->GetWebContents(), |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
I'm concerned about storing a contents pointer as
noms (inactive)
2013/04/17 20:32:37
Added a comment that both the dialog and the bubbl
| |
| 266 toolbar_view->app_menu(), error_message); | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
ident lines 265 and 266 by 2 more.
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 219 break; | 267 break; |
| 220 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: | 268 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_MODAL_DIALOG: |
| 221 bubble_view_ = new OneClickSigninDialogView( | 269 bubble_view_ = new OneClickSigninDialogView( |
| 222 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 270 toolbar_view->GetWebContents(), toolbar_view->location_bar(), |
| 223 string16(), start_sync); | 271 string16(), start_sync); |
| 224 break; | 272 break; |
| 225 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: | 273 case BrowserWindow::ONE_CLICK_SIGNIN_BUBBLE_TYPE_SAML_MODAL_DIALOG: |
| 226 bubble_view_ = new OneClickSigninDialogView( | 274 bubble_view_ = new OneClickSigninDialogView( |
| 227 toolbar_view->GetWebContents(), toolbar_view->location_bar(), | 275 toolbar_view->GetWebContents(), toolbar_view->location_bar(), |
| 228 email, start_sync); | 276 email, start_sync); |
| 229 break; | 277 break; |
| 230 } | 278 } |
| 231 | 279 |
| 232 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); | 280 views::BubbleDelegateView::CreateBubble(bubble_view_)->Show(); |
| 233 } | 281 } |
| 234 | 282 |
| 235 // static | 283 // static |
| 236 bool OneClickSigninBubbleView::IsShowing() { | 284 bool OneClickSigninBubbleView::IsShowing() { |
| 237 return bubble_view_ != NULL; | 285 return bubble_view_ != NULL; |
| 238 } | 286 } |
| 239 | 287 |
| 240 // static | 288 // static |
| 241 void OneClickSigninBubbleView::Hide() { | 289 void OneClickSigninBubbleView::Hide() { |
| 242 if (IsShowing()) | 290 if (IsShowing()) |
| 243 bubble_view_->GetWidget()->Close(); | 291 bubble_view_->GetWidget()->Close(); |
| 244 } | 292 } |
| 245 | 293 |
| 246 OneClickSigninBubbleView::OneClickSigninBubbleView( | 294 OneClickSigninBubbleView::OneClickSigninBubbleView( |
| 295 content::WebContents* web_content, | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
indent 2 more.
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 247 views::View* anchor_view, | 296 views::View* anchor_view, |
| 248 const BrowserWindow::StartSyncCallback& start_sync_callback) | 297 const std::string& error_message) |
| 249 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 298 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 299 web_content_(web_content), | |
| 300 error_message_(error_message), | |
| 250 advanced_link_(NULL), | 301 advanced_link_(NULL), |
| 302 learn_more_link_(NULL), | |
| 251 ok_button_(NULL), | 303 ok_button_(NULL), |
| 252 undo_button_(NULL), | 304 undo_button_(NULL), |
| 253 start_sync_callback_(start_sync_callback), | |
| 254 message_loop_for_testing_(NULL) { | 305 message_loop_for_testing_(NULL) { |
| 255 DCHECK(!start_sync_callback_.is_null()); | |
| 256 } | 306 } |
| 257 | 307 |
| 258 OneClickSigninBubbleView::~OneClickSigninBubbleView() { | 308 OneClickSigninBubbleView::~OneClickSigninBubbleView() { |
| 259 } | 309 } |
| 260 | 310 |
| 261 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { | 311 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { |
| 262 views::BubbleDelegateView::AnimationEnded(animation); | 312 views::BubbleDelegateView::AnimationEnded(animation); |
| 263 if (message_loop_for_testing_) | 313 if (message_loop_for_testing_) |
| 264 message_loop_for_testing_->Quit(); | 314 message_loop_for_testing_->Quit(); |
| 265 } | 315 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 282 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 332 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 283 views::GridLayout::USE_PREF, 0, 0); | 333 views::GridLayout::USE_PREF, 0, 0); |
| 284 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | 334 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 285 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 335 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 286 views::GridLayout::USE_PREF, 0, 0); | 336 views::GridLayout::USE_PREF, 0, 0); |
| 287 | 337 |
| 288 InitContent(layout); | 338 InitContent(layout); |
| 289 | 339 |
| 290 // Add controls at the bottom. | 340 // Add controls at the bottom. |
| 291 advanced_link_= GetAdvancedLink(); | 341 advanced_link_= GetAdvancedLink(); |
| 292 GetButtons(&ok_button_, &undo_button_); | |
| 293 ok_button_->SetIsDefault(true); | |
| 294 | 342 |
| 295 layout->StartRow(0, COLUMN_SET_CONTROLS); | 343 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 296 layout->AddView(advanced_link_); | 344 layout->AddView(advanced_link_); |
| 297 layout->AddView(ok_button_); | 345 |
| 298 layout->AddView(undo_button_); | 346 InitButtons(layout); |
| 347 ok_button_->SetIsDefault(true); | |
| 299 | 348 |
| 300 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); | 349 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); |
| 301 } | 350 } |
| 302 | 351 |
| 303 void OneClickSigninBubbleView::InitContent(views::GridLayout* layout) { | 352 void OneClickSigninBubbleView::InitContent(views::GridLayout* layout) { |
| 304 // Add main text description. | 353 // Add main text description. |
| 305 views::Label* label = new views::Label( | 354 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); |
| 306 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); | 355 |
| 356 views::Label* label = !error_message_.empty() ? | |
| 357 new views::Label(UTF8ToUTF16(error_message_)) : | |
| 358 new views::Label( | |
| 359 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
indent 2 more.
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 360 | |
| 307 label->SetMultiLine(true); | 361 label->SetMultiLine(true); |
| 308 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 362 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 309 label->SizeToFit(kMinimumLabelWidth); | 363 label->SizeToFit(kMinimumLabelWidth); |
| 310 | |
| 311 layout->StartRow(0, COLUMN_SET_FILL_ALIGN); | |
| 312 layout->AddView(label); | 364 layout->AddView(label); |
| 313 | 365 |
| 314 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 366 layout->StartRow(0, COLUMN_SET_CONTROLS); |
| 367 | |
| 368 // and learn more link | |
| 369 learn_more_link_ = GetLearnMoreLink(); | |
| 370 | |
| 371 layout->AddView(learn_more_link_); | |
| 372 } | |
| 373 | |
| 374 void OneClickSigninBubbleView::InitButtons(views::GridLayout* layout) { | |
| 375 GetButtons(&ok_button_, &undo_button_); | |
| 376 layout->AddView(ok_button_); | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
I'm not sure InitButtons() needs to be virtual or
noms (inactive)
2013/04/17 20:32:37
The two InitButtons functions got merged, so this
| |
| 315 } | 377 } |
| 316 | 378 |
| 317 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, | 379 void OneClickSigninBubbleView::GetButtons(views::LabelButton** ok_button, |
| 318 views::LabelButton** undo_button) { | 380 views::LabelButton** undo_button) { |
| 319 *ok_button = new views::LabelButton(this, string16()); | 381 *ok_button = new views::LabelButton(this, string16()); |
| 320 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 382 (*ok_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 321 | 383 |
| 322 *undo_button = new views::LabelButton(this, string16()); | 384 *undo_button = new views::LabelButton(this, string16()); |
| 323 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 385 (*undo_button)->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
| 324 | 386 |
| 325 // The default size of the buttons is too large. To allow them to be smaller | 387 // The default size of the buttons is too large. To allow them to be smaller |
| 326 // ignore the minimum default size. Furthermore, to make sure they are the | 388 // ignore the minimum default size. Furthermore, to make sure they are the |
| 327 // same size, SetText() is called with both strings on both buttons. | 389 // same size, SetText() is called with both strings on both buttons. |
| 328 (*ok_button)->set_min_size(gfx::Size()); | 390 (*ok_button)->set_min_size(gfx::Size()); |
| 329 (*undo_button)->set_min_size(gfx::Size()); | 391 (*undo_button)->set_min_size(gfx::Size()); |
| 392 | |
| 330 string16 ok_label = l10n_util::GetStringUTF16(IDS_OK); | 393 string16 ok_label = l10n_util::GetStringUTF16(IDS_OK); |
| 331 string16 undo_label = l10n_util::GetStringUTF16(IDS_ONE_CLICK_BUBBLE_UNDO); | 394 string16 undo_label = |
| 395 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_UNDO_BUTTON); | |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
Just want to double check this is the correct stri
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 396 | |
| 332 (*ok_button)->SetText(undo_label); | 397 (*ok_button)->SetText(undo_label); |
| 333 (*ok_button)->SetText(ok_label); | 398 (*ok_button)->SetText(ok_label); |
| 334 (*undo_button)->SetText(ok_label); | 399 (*undo_button)->SetText(ok_label); |
| 335 (*undo_button)->SetText(undo_label); | 400 (*undo_button)->SetText(undo_label); |
| 336 } | 401 } |
| 337 | 402 |
| 338 views::Link* OneClickSigninBubbleView::GetAdvancedLink() { | 403 views::Link* OneClickSigninBubbleView::GetAdvancedLink() { |
| 339 views::Link* advanced_link= new views::Link( | 404 views::Link* advanced_link = new views::Link( |
| 340 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 405 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_ADVANCED)); |
| 341 advanced_link->set_listener(this); | 406 advanced_link->set_listener(this); |
| 342 advanced_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 407 advanced_link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 343 return advanced_link; | 408 return advanced_link; |
| 344 } | 409 } |
| 345 | 410 |
| 346 void OneClickSigninBubbleView::WindowClosing() { | 411 views::Link* OneClickSigninBubbleView::GetLearnMoreLink() { |
| 347 // We have to reset |bubble_view_| here, not in our destructor, because | 412 views::Link* learn_more_link_ = new views::Link( |
| 348 // we'll be destroyed asynchronously and the shown state will be checked | 413 l10n_util::GetStringUTF16(IDS_LEARN_MORE)); |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
indent 2 less.
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 349 // before then. | 414 learn_more_link_->set_listener(this); |
| 350 DCHECK_EQ(bubble_view_, this); | 415 learn_more_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 351 bubble_view_ = NULL; | |
| 352 | 416 |
| 353 if (!start_sync_callback_.is_null()) { | 417 return learn_more_link_; |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
Local var should not have a trailing _ in name.
H
noms (inactive)
2013/04/17 20:32:37
Made private, renamed it to InitXXXLink and remove
| |
| 354 base::ResetAndReturn(&start_sync_callback_).Run( | |
| 355 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
| 356 } | |
| 357 } | 418 } |
| 358 | 419 |
| 359 bool OneClickSigninBubbleView::AcceleratorPressed( | 420 bool OneClickSigninBubbleView::AcceleratorPressed( |
| 360 const ui::Accelerator& accelerator) { | 421 const ui::Accelerator& accelerator) { |
| 361 if (accelerator.key_code() == ui::VKEY_RETURN || | 422 if (accelerator.key_code() == ui::VKEY_RETURN || |
| 362 accelerator.key_code() == ui::VKEY_ESCAPE) { | 423 accelerator.key_code() == ui::VKEY_ESCAPE) { |
| 363 StartFade(false); | 424 OneClickSigninBubbleView::Hide(); |
|
Roger Tawa OOO till Jul 10th
2013/04/17 17:53:25
I don't think you need the class name here. Same
noms (inactive)
2013/04/17 20:32:37
Done.
| |
| 364 if (accelerator.key_code() == ui::VKEY_RETURN) { | |
| 365 base::ResetAndReturn(&start_sync_callback_).Run( | |
| 366 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
| 367 } else { | |
| 368 start_sync_callback_.Reset(); | |
| 369 } | |
| 370 | |
| 371 return true; | 425 return true; |
| 372 } | 426 } |
| 373 | 427 |
| 374 return BubbleDelegateView::AcceleratorPressed(accelerator); | 428 return BubbleDelegateView::AcceleratorPressed(accelerator); |
| 375 } | 429 } |
| 376 | 430 |
| 377 void OneClickSigninBubbleView::LinkClicked(views::Link* source, | 431 void OneClickSigninBubbleView::LinkClicked(views::Link* source, |
| 378 int event_flags) { | 432 int event_flags) { |
| 379 StartFade(false); | 433 if (source == learn_more_link_) { |
| 380 base::ResetAndReturn(&start_sync_callback_).Run( | 434 content::OpenURLParams params( |
| 381 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); | 435 GURL(chrome::kChromeSyncLearnMoreURL), content::Referrer(), |
| 436 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | |
| 437 web_content_->OpenURL(params); | |
| 438 } else if (source == advanced_link_) { | |
| 439 content::OpenURLParams params( | |
| 440 GURL(chrome::kChromeUISettingsURL), content::Referrer(), | |
| 441 CURRENT_TAB, content::PAGE_TRANSITION_LINK, false); | |
| 442 web_content_->OpenURL(params); | |
| 443 } | |
| 382 } | 444 } |
| 383 | 445 |
| 384 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, | 446 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, |
| 385 const ui::Event& event) { | 447 const ui::Event& event) { |
| 386 StartFade(false); | 448 OneClickSigninBubbleView::Hide(); |
| 387 base::ResetAndReturn(&start_sync_callback_).Run((sender == ok_button_) ? | |
| 388 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS : | |
| 389 OneClickSigninSyncStarter::UNDO_SYNC); | |
| 390 } | 449 } |
| 450 | |
| 451 void OneClickSigninBubbleView::WindowClosing() { | |
| 452 // We have to reset |bubble_view_| here, not in our destructor, because | |
| 453 // we'll be destroyed asynchronously and the shown state will be checked | |
| 454 // before then. | |
| 455 DCHECK_EQ(bubble_view_, this); | |
| 456 bubble_view_ = NULL; | |
| 457 } | |
| OLD | NEW |