Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(177)

Side by Side Diff: chrome/browser/ui/views/sync/one_click_signin_bubble_view.cc

Issue 10332185: Update behavior of one-click infobar to remove modal dialog, add "undo". (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 8 #include "base/logging.h"
8 #include "base/message_loop.h" 9 #include "base/message_loop.h"
9 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "ui/base/keycodes/keyboard_codes.h" 15 #include "ui/base/keycodes/keyboard_codes.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/controls/button/text_button.h" 18 #include "ui/views/controls/button/text_button.h"
18 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
19 #include "ui/views/controls/link.h" 20 #include "ui/views/controls/link.h"
20 #include "ui/views/events/event.h" 21 #include "ui/views/events/event.h"
21 #include "ui/views/layout/grid_layout.h" 22 #include "ui/views/layout/grid_layout.h"
22 #include "ui/views/layout/layout_constants.h" 23 #include "ui/views/layout/layout_constants.h"
23 24
24 // Minimum width for the fields - they will push out the size of the bubble if 25 // Minimum width for the mutli-line label.
25 // necessary. This should be big enough so that the field pushes the right side 26 const int kMinimumLabelWidth = 240;
26 // of the bubble far enough so that the edit button's left edge is to the right 27
27 // of the field's left edge.
28 const int kMinimumFieldSize = 240;
29 28
30 // BookmarkBubbleView --------------------------------------------------------- 29 // BookmarkBubbleView ---------------------------------------------------------
31 30
32 // static 31 // static
33 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; 32 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL;
34 33
35 // static 34 // static
36 void OneClickSigninBubbleView::ShowBubble( 35 void OneClickSigninBubbleView::ShowBubble(
37 views::View* anchor_view, 36 views::View* anchor_view,
38 const base::Closure& learn_more_callback, 37 const BrowserWindow::StartSyncCallback& start_sync) {
39 const base::Closure& advanced_callback) {
40 if (IsShowing()) 38 if (IsShowing())
41 return; 39 return;
42 40
43 bubble_view_ = 41 bubble_view_ =
44 new OneClickSigninBubbleView(anchor_view, learn_more_callback, 42 new OneClickSigninBubbleView(anchor_view, start_sync);
45 advanced_callback);
46 views::BubbleDelegateView::CreateBubble(bubble_view_); 43 views::BubbleDelegateView::CreateBubble(bubble_view_);
47 bubble_view_->Show(); 44 bubble_view_->Show();
48 } 45 }
49 46
50 // static 47 // static
51 bool OneClickSigninBubbleView::IsShowing() { 48 bool OneClickSigninBubbleView::IsShowing() {
52 return bubble_view_ != NULL; 49 return bubble_view_ != NULL;
53 } 50 }
54 51
55 // static 52 // static
56 void OneClickSigninBubbleView::Hide() { 53 void OneClickSigninBubbleView::Hide() {
57 if (IsShowing()) 54 if (IsShowing())
58 bubble_view_->GetWidget()->Close(); 55 bubble_view_->GetWidget()->Close();
59 } 56 }
60 57
61 OneClickSigninBubbleView::OneClickSigninBubbleView( 58 OneClickSigninBubbleView::OneClickSigninBubbleView(
62 views::View* anchor_view, 59 views::View* anchor_view,
63 const base::Closure& learn_more_callback, 60 const BrowserWindow::StartSyncCallback& start_sync_callback)
64 const base::Closure& advanced_callback)
65 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 61 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
66 learn_more_link_(NULL),
67 advanced_link_(NULL), 62 advanced_link_(NULL),
68 close_button_(NULL), 63 ok_button_(NULL),
69 learn_more_callback_(learn_more_callback), 64 undo_button_(NULL),
70 advanced_callback_(advanced_callback), 65 start_sync_callback_(start_sync_callback),
71 message_loop_for_testing_(NULL) { 66 message_loop_for_testing_(NULL) {
72 DCHECK(!learn_more_callback_.is_null()); 67 DCHECK(!start_sync_callback_.is_null());
73 DCHECK(!advanced_callback_.is_null());
74 } 68 }
75 69
76 OneClickSigninBubbleView::~OneClickSigninBubbleView() { 70 OneClickSigninBubbleView::~OneClickSigninBubbleView() {
77 } 71 }
78 72
79 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { 73 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) {
80 views::BubbleDelegateView::AnimationEnded(animation); 74 views::BubbleDelegateView::AnimationEnded(animation);
81 if (message_loop_for_testing_) 75 if (message_loop_for_testing_)
82 message_loop_for_testing_->Quit(); 76 message_loop_for_testing_->Quit();
83 } 77 }
84 78
85 void OneClickSigninBubbleView::Init() { 79 void OneClickSigninBubbleView::Init() {
86 views::GridLayout* layout = new views::GridLayout(this); 80 views::GridLayout* layout = new views::GridLayout(this);
87 SetLayoutManager(layout); 81 SetLayoutManager(layout);
88 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8)); 82 set_border(views::Border::CreateEmptyBorder(8, 8, 8, 8));
89 83
90 enum { 84 enum {
91 kColumnSetFillAlign, 85 kColumnSetFillAlign,
92 kColumnSetControls 86 kColumnSetControls
93 }; 87 };
94 88
95 // Column set for descriptive text and link. 89 // Column set for descriptive text and link.
96 views::ColumnSet* cs = layout->AddColumnSet(kColumnSetFillAlign); 90 views::ColumnSet* cs = layout->AddColumnSet(kColumnSetFillAlign);
97 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0, 91 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0,
98 views::GridLayout::USE_PREF, 0, kMinimumFieldSize); 92 views::GridLayout::USE_PREF, 0, kMinimumLabelWidth);
99 93
100 cs = layout->AddColumnSet(kColumnSetControls); 94 cs = layout->AddColumnSet(kColumnSetControls);
101 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, 95 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
102 views::GridLayout::USE_PREF, 0, 0); 96 views::GridLayout::USE_PREF, 0, 0);
103 cs->AddPaddingColumn(1, 0); 97 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
98 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0,
99 views::GridLayout::USE_PREF, 0, 0);
100 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
104 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, 101 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0,
105 views::GridLayout::USE_PREF, 0, 0); 102 views::GridLayout::USE_PREF, 0, 0);
106 103
107 // Add main text description. 104 // Add main text description.
108 views::Label* label = new views::Label( 105 views::Label* label = new views::Label(
109 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, 106 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE));
110 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)));
111 label->SetMultiLine(true); 107 label->SetMultiLine(true);
112 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 108 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
113 label->SizeToFit(kMinimumFieldSize); 109 label->SizeToFit(kMinimumLabelWidth);
114 110
115 layout->StartRow(0, kColumnSetFillAlign); 111 layout->StartRow(0, kColumnSetFillAlign);
116 layout->AddView(label); 112 layout->AddView(label);
117 113
118 // Add link for user to learn more about sync. 114 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing);
119 learn_more_link_= new views::Link(
120 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_LEARN_MORE));
121 learn_more_link_->set_listener(this);
122 learn_more_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
123
124 layout->StartRow(0, kColumnSetFillAlign);
125 layout->AddView(learn_more_link_);
126
127 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
128 115
129 // Add link for user to do advanced config of sync. 116 // Add link for user to do advanced config of sync.
130 advanced_link_= new views::Link( 117 advanced_link_= new views::Link(
131 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); 118 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED));
132 advanced_link_->set_listener(this); 119 advanced_link_->set_listener(this);
133 advanced_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 120 advanced_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
134 121
135 // Add controls at the bottom. 122 // Add controls at the bottom.
136 close_button_ = new views::NativeTextButton( 123 ok_button_ = new views::NativeTextButton(this);
137 this, l10n_util::GetStringUTF16(IDS_OK)); 124 ok_button_->SetIsDefault(true);
138 close_button_->SetIsDefault(true); 125
126 undo_button_ = new views::NativeTextButton(this);
127
128 // The default size of the buttons is too large. To allow them to be smaller
129 // ignore the minimum default size. Furthermore, to make sure they are the
130 // same size, SetText() is called with both strings on both buttons.
131 ok_button_->set_ignore_minimum_size(false);
Peter Kasting 2012/05/25 16:58:06 I think these are being "ignored" because you're c
Roger Tawa OOO till Jul 10th 2012/05/25 18:49:51 duh. I misinterpreted the meaning.
132 undo_button_->set_ignore_minimum_size(false);
133 string16 ok_label = l10n_util::GetStringUTF16(IDS_OK);
134 string16 undo_label = l10n_util::GetStringUTF16(IDS_ONE_CLICK_BUBBLE_UNDO);
135 ok_button_->SetText(undo_label);
136 ok_button_->SetText(ok_label);
137 undo_button_->SetText(ok_label);
138 undo_button_->SetText(undo_label);
139 139
140 layout->StartRow(0, kColumnSetControls); 140 layout->StartRow(0, kColumnSetControls);
141 layout->AddView(advanced_link_); 141 layout->AddView(advanced_link_);
142 layout->AddView(close_button_); 142 layout->AddView(ok_button_);
143 layout->AddView(undo_button_);
143 144
144 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); 145 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0));
145 } 146 }
146 147
147 void OneClickSigninBubbleView::WindowClosing() { 148 void OneClickSigninBubbleView::WindowClosing() {
148 // We have to reset |bubble_view_| here, not in our destructor, because 149 // We have to reset |bubble_view_| here, not in our destructor, because
149 // we'll be destroyed asynchronously and the shown state will be checked 150 // we'll be destroyed asynchronously and the shown state will be checked
150 // before then. 151 // before then.
151 DCHECK(bubble_view_ == this); 152 DCHECK(bubble_view_ == this);
152 bubble_view_ = NULL; 153 bubble_view_ = NULL;
153 } 154
155 if (!start_sync_callback_.is_null()) {
156 base::ResetAndReturn(&start_sync_callback_).Run(
157 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
158 }
159 }
154 160
155 bool OneClickSigninBubbleView::AcceleratorPressed( 161 bool OneClickSigninBubbleView::AcceleratorPressed(
156 const ui::Accelerator& accelerator) { 162 const ui::Accelerator& accelerator) {
157 if (accelerator.key_code() == ui::VKEY_RETURN || 163 if (accelerator.key_code() == ui::VKEY_RETURN ||
158 accelerator.key_code() == ui::VKEY_ESCAPE) { 164 accelerator.key_code() == ui::VKEY_ESCAPE) {
159 StartFade(false); 165 StartFade(false);
166 if (accelerator.key_code() == ui::VKEY_RETURN) {
167 base::ResetAndReturn(&start_sync_callback_).Run(
168 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
169 } else {
170 start_sync_callback_.Reset();
171 }
172
160 return true; 173 return true;
161 } 174 }
162 175
163 return BubbleDelegateView::AcceleratorPressed(accelerator); 176 return BubbleDelegateView::AcceleratorPressed(accelerator);
164 } 177 }
165 178
166 void OneClickSigninBubbleView::LinkClicked(views::Link* source, 179 void OneClickSigninBubbleView::LinkClicked(views::Link* source,
167 int event_flags) { 180 int event_flags) {
168 StartFade(false); 181 StartFade(false);
169 182 base::ResetAndReturn(&start_sync_callback_).Run(
170 if (source == learn_more_link_) 183 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST);
171 learn_more_callback_.Run();
172 else
173 advanced_callback_.Run();
174 } 184 }
175 185
176 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, 186 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender,
177 const views::Event& event) { 187 const views::Event& event) {
178 DCHECK_EQ(close_button_, sender);
179 StartFade(false); 188 StartFade(false);
189 if (ok_button_ == sender) {
190 base::ResetAndReturn(&start_sync_callback_).Run(
191 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS);
192 } else {
193 start_sync_callback_.Reset();
194 }
180 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698