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/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 fields - they will push out the size of the bubble if |
25 // necessary. This should be big enough so that the field pushes the right side | 26 // necessary. This should be big enough so that the field pushes the right side |
26 // of the bubble far enough so that the edit button's left edge is to the right | 27 // of the bubble far enough so that the edit button's left edge is to the right |
27 // of the field's left edge. | 28 // of the field's left edge. |
28 const int kMinimumFieldSize = 240; | 29 const int kMinimumFieldSize = 240; |
29 | 30 |
31 // Button width. The default width of NativeTextButtons is too large for this | |
32 // bubble. | |
33 const int kButtonWidth = 64; | |
Peter Kasting
2012/05/24 22:25:18
Hardcoding this makes me really nervous for both l
Roger Tawa OOO till Jul 10th
2012/05/25 16:04:08
set_ignore_minimum_size() seems to be ignored, but
| |
34 | |
35 | |
30 // BookmarkBubbleView --------------------------------------------------------- | 36 // BookmarkBubbleView --------------------------------------------------------- |
31 | 37 |
32 // static | 38 // static |
33 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; | 39 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; |
34 | 40 |
35 // static | 41 // static |
36 void OneClickSigninBubbleView::ShowBubble( | 42 void OneClickSigninBubbleView::ShowBubble( |
37 views::View* anchor_view, | 43 views::View* anchor_view, |
38 const base::Closure& learn_more_callback, | 44 const BrowserWindow::StartSyncCallback& start_sync) { |
39 const base::Closure& advanced_callback) { | |
40 if (IsShowing()) | 45 if (IsShowing()) |
41 return; | 46 return; |
42 | 47 |
43 bubble_view_ = | 48 bubble_view_ = |
44 new OneClickSigninBubbleView(anchor_view, learn_more_callback, | 49 new OneClickSigninBubbleView(anchor_view, start_sync); |
45 advanced_callback); | |
46 views::BubbleDelegateView::CreateBubble(bubble_view_); | 50 views::BubbleDelegateView::CreateBubble(bubble_view_); |
47 bubble_view_->Show(); | 51 bubble_view_->Show(); |
48 } | 52 } |
49 | 53 |
50 // static | 54 // static |
51 bool OneClickSigninBubbleView::IsShowing() { | 55 bool OneClickSigninBubbleView::IsShowing() { |
52 return bubble_view_ != NULL; | 56 return bubble_view_ != NULL; |
53 } | 57 } |
54 | 58 |
55 // static | 59 // static |
56 void OneClickSigninBubbleView::Hide() { | 60 void OneClickSigninBubbleView::Hide() { |
57 if (IsShowing()) | 61 if (IsShowing()) |
58 bubble_view_->GetWidget()->Close(); | 62 bubble_view_->GetWidget()->Close(); |
59 } | 63 } |
60 | 64 |
61 OneClickSigninBubbleView::OneClickSigninBubbleView( | 65 OneClickSigninBubbleView::OneClickSigninBubbleView( |
62 views::View* anchor_view, | 66 views::View* anchor_view, |
63 const base::Closure& learn_more_callback, | 67 const BrowserWindow::StartSyncCallback& start_sync_callback) |
64 const base::Closure& advanced_callback) | |
65 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 68 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
66 learn_more_link_(NULL), | |
67 advanced_link_(NULL), | 69 advanced_link_(NULL), |
68 close_button_(NULL), | 70 ok_button_(NULL), |
69 learn_more_callback_(learn_more_callback), | 71 undo_button_(NULL), |
70 advanced_callback_(advanced_callback), | 72 start_sync_callback_(start_sync_callback), |
71 message_loop_for_testing_(NULL) { | 73 message_loop_for_testing_(NULL) { |
72 DCHECK(!learn_more_callback_.is_null()); | 74 DCHECK(!start_sync_callback_.is_null()); |
73 DCHECK(!advanced_callback_.is_null()); | |
74 } | 75 } |
75 | 76 |
76 OneClickSigninBubbleView::~OneClickSigninBubbleView() { | 77 OneClickSigninBubbleView::~OneClickSigninBubbleView() { |
77 } | 78 } |
78 | 79 |
79 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { | 80 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { |
80 views::BubbleDelegateView::AnimationEnded(animation); | 81 views::BubbleDelegateView::AnimationEnded(animation); |
81 if (message_loop_for_testing_) | 82 if (message_loop_for_testing_) |
82 message_loop_for_testing_->Quit(); | 83 message_loop_for_testing_->Quit(); |
83 } | 84 } |
(...skipping 11 matching lines...) Expand all Loading... | |
95 // Column set for descriptive text and link. | 96 // Column set for descriptive text and link. |
96 views::ColumnSet* cs = layout->AddColumnSet(kColumnSetFillAlign); | 97 views::ColumnSet* cs = layout->AddColumnSet(kColumnSetFillAlign); |
97 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0, | 98 cs->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 0, |
98 views::GridLayout::USE_PREF, 0, kMinimumFieldSize); | 99 views::GridLayout::USE_PREF, 0, kMinimumFieldSize); |
99 | 100 |
100 cs = layout->AddColumnSet(kColumnSetControls); | 101 cs = layout->AddColumnSet(kColumnSetControls); |
101 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | 102 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, |
102 views::GridLayout::USE_PREF, 0, 0); | 103 views::GridLayout::USE_PREF, 0, 0); |
103 cs->AddPaddingColumn(1, 0); | 104 cs->AddPaddingColumn(1, 0); |
104 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 105 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
105 views::GridLayout::USE_PREF, 0, 0); | 106 views::GridLayout::FIXED, kButtonWidth, 0); |
107 cs->AddPaddingColumn(0, 5); | |
108 cs->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | |
109 views::GridLayout::FIXED, kButtonWidth, 0); | |
106 | 110 |
107 // Add main text description. | 111 // Add main text description. |
108 views::Label* label = new views::Label( | 112 views::Label* label = new views::Label( |
109 l10n_util::GetStringFUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_MESSAGE, | 113 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_BUBBLE_MESSAGE)); |
110 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | |
111 label->SetMultiLine(true); | 114 label->SetMultiLine(true); |
112 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 115 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
113 label->SizeToFit(kMinimumFieldSize); | 116 label->SizeToFit(kMinimumFieldSize); |
114 | 117 |
115 layout->StartRow(0, kColumnSetFillAlign); | 118 layout->StartRow(0, kColumnSetFillAlign); |
116 layout->AddView(label); | 119 layout->AddView(label); |
117 | 120 |
118 // Add link for user to learn more about sync. | 121 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); |
Peter Kasting
2012/05/24 22:25:18
This doesn't seem like the right value. This is f
Roger Tawa OOO till Jul 10th
2012/05/25 16:04:08
Seems like the right one to me. Which value do yo
Peter Kasting
2012/05/25 16:58:06
This is for a case like:
BLAH_FOO option:
[
Roger Tawa OOO till Jul 10th
2012/05/25 18:49:51
Done.
| |
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 | 122 |
129 // Add link for user to do advanced config of sync. | 123 // Add link for user to do advanced config of sync. |
130 advanced_link_= new views::Link( | 124 advanced_link_= new views::Link( |
131 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 125 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
132 advanced_link_->set_listener(this); | 126 advanced_link_->set_listener(this); |
133 advanced_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 127 advanced_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
134 | 128 |
135 // Add controls at the bottom. | 129 // Add controls at the bottom. |
136 close_button_ = new views::NativeTextButton( | 130 ok_button_ = new views::NativeTextButton( |
137 this, l10n_util::GetStringUTF16(IDS_OK)); | 131 this, l10n_util::GetStringUTF16(IDS_OK)); |
138 close_button_->SetIsDefault(true); | 132 ok_button_->SetIsDefault(true); |
133 | |
134 undo_button_ = new views::NativeTextButton( | |
135 this, l10n_util::GetStringUTF16(IDS_ONE_CLICK_BUBBLE_UNDO)); | |
139 | 136 |
140 layout->StartRow(0, kColumnSetControls); | 137 layout->StartRow(0, kColumnSetControls); |
141 layout->AddView(advanced_link_); | 138 layout->AddView(advanced_link_); |
142 layout->AddView(close_button_); | 139 layout->AddView(ok_button_); |
140 layout->AddView(undo_button_); | |
143 | 141 |
144 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); | 142 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, 0)); |
145 } | 143 } |
146 | 144 |
147 void OneClickSigninBubbleView::WindowClosing() { | 145 void OneClickSigninBubbleView::WindowClosing() { |
148 // We have to reset |bubble_view_| here, not in our destructor, because | 146 // 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 | 147 // we'll be destroyed asynchronously and the shown state will be checked |
150 // before then. | 148 // before then. |
151 DCHECK(bubble_view_ == this); | 149 DCHECK(bubble_view_ == this); |
152 bubble_view_ = NULL; | 150 bubble_view_ = NULL; |
153 } | 151 |
152 if (!start_sync_callback_.is_null()) | |
Peter Kasting
2012/05/24 22:25:18
Nit: Need {}
Roger Tawa OOO till Jul 10th
2012/05/25 16:04:08
Done.
| |
153 base::ResetAndReturn(&start_sync_callback_).Run( | |
154 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
155 } | |
154 | 156 |
155 bool OneClickSigninBubbleView::AcceleratorPressed( | 157 bool OneClickSigninBubbleView::AcceleratorPressed( |
156 const ui::Accelerator& accelerator) { | 158 const ui::Accelerator& accelerator) { |
157 if (accelerator.key_code() == ui::VKEY_RETURN || | 159 if (accelerator.key_code() == ui::VKEY_RETURN || |
158 accelerator.key_code() == ui::VKEY_ESCAPE) { | 160 accelerator.key_code() == ui::VKEY_ESCAPE) { |
159 StartFade(false); | 161 StartFade(false); |
162 if (accelerator.key_code() == ui::VKEY_RETURN) { | |
163 base::ResetAndReturn(&start_sync_callback_).Run( | |
164 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
165 } else { | |
166 start_sync_callback_.Reset(); | |
167 } | |
168 | |
160 return true; | 169 return true; |
161 } | 170 } |
162 | 171 |
163 return BubbleDelegateView::AcceleratorPressed(accelerator); | 172 return BubbleDelegateView::AcceleratorPressed(accelerator); |
164 } | 173 } |
165 | 174 |
166 void OneClickSigninBubbleView::LinkClicked(views::Link* source, | 175 void OneClickSigninBubbleView::LinkClicked(views::Link* source, |
167 int event_flags) { | 176 int event_flags) { |
168 StartFade(false); | 177 StartFade(false); |
169 | 178 base::ResetAndReturn(&start_sync_callback_).Run( |
170 if (source == learn_more_link_) | 179 OneClickSigninSyncStarter::CONFIGURE_SYNC_FIRST); |
171 learn_more_callback_.Run(); | |
172 else | |
173 advanced_callback_.Run(); | |
174 } | 180 } |
175 | 181 |
176 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, | 182 void OneClickSigninBubbleView::ButtonPressed(views::Button* sender, |
177 const views::Event& event) { | 183 const views::Event& event) { |
178 DCHECK_EQ(close_button_, sender); | |
179 StartFade(false); | 184 StartFade(false); |
185 if (ok_button_ == sender) { | |
186 base::ResetAndReturn(&start_sync_callback_).Run( | |
187 OneClickSigninSyncStarter::SYNC_WITH_DEFAULT_SETTINGS); | |
188 } else { | |
189 start_sync_callback_.Reset(); | |
190 } | |
180 } | 191 } |
OLD | NEW |