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/logging.h" |
7 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
8 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/views/window.h" | 11 #include "chrome/browser/ui/views/window.h" |
11 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
12 #include "content/public/common/page_transition_types.h" | |
13 #include "grit/chromium_strings.h" | 13 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
15 #include "ui/base/keycodes/keyboard_codes.h" | 15 #include "ui/base/keycodes/keyboard_codes.h" |
16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/views/controls/button/text_button.h" | 18 #include "ui/views/controls/button/text_button.h" |
19 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
20 #include "ui/views/controls/link.h" | 20 #include "ui/views/controls/link.h" |
21 #include "ui/views/events/event.h" | 21 #include "ui/views/events/event.h" |
22 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
23 #include "ui/views/layout/layout_constants.h" | 23 #include "ui/views/layout/layout_constants.h" |
24 | 24 |
25 // 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 |
26 // 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 |
27 // 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 |
28 // of the field's left edge. | 28 // of the field's left edge. |
29 const int kMinimumFieldSize = 240; | 29 const int kMinimumFieldSize = 240; |
30 | 30 |
31 // BookmarkBubbleView --------------------------------------------------------- | 31 // BookmarkBubbleView --------------------------------------------------------- |
32 | 32 |
33 // static | 33 // static |
34 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; | 34 OneClickSigninBubbleView* OneClickSigninBubbleView::bubble_view_ = NULL; |
35 | 35 |
36 // static | 36 // static |
37 void OneClickSigninBubbleView::ShowBubble(views::View* anchor_view, | 37 void OneClickSigninBubbleView::ShowBubble( |
38 Browser* browser) { | 38 views::View* anchor_view, |
| 39 const base::Closure& learn_more_callback, |
| 40 const base::Closure& advanced_callback) { |
39 if (IsShowing()) | 41 if (IsShowing()) |
40 return; | 42 return; |
41 | 43 |
42 bubble_view_ = new OneClickSigninBubbleView(anchor_view, browser); | 44 bubble_view_ = |
| 45 new OneClickSigninBubbleView(anchor_view, learn_more_callback, |
| 46 advanced_callback); |
43 browser::CreateViewsBubble(bubble_view_); | 47 browser::CreateViewsBubble(bubble_view_); |
44 bubble_view_->Show(); | 48 bubble_view_->Show(); |
45 } | 49 } |
46 | 50 |
47 // static | 51 // static |
48 bool OneClickSigninBubbleView::IsShowing() { | 52 bool OneClickSigninBubbleView::IsShowing() { |
49 return bubble_view_ != NULL; | 53 return bubble_view_ != NULL; |
50 } | 54 } |
51 | 55 |
52 // static | 56 // static |
53 void OneClickSigninBubbleView::Hide() { | 57 void OneClickSigninBubbleView::Hide() { |
54 if (IsShowing()) | 58 if (IsShowing()) |
55 bubble_view_->GetWidget()->Close(); | 59 bubble_view_->GetWidget()->Close(); |
56 } | 60 } |
57 | 61 |
58 OneClickSigninBubbleView::OneClickSigninBubbleView(views::View* anchor_view, | 62 OneClickSigninBubbleView::OneClickSigninBubbleView( |
59 Browser* browser) | 63 views::View* anchor_view, |
| 64 const base::Closure& learn_more_callback, |
| 65 const base::Closure& advanced_callback) |
60 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 66 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
61 learn_more_link_(NULL), | 67 learn_more_link_(NULL), |
62 advanced_link_(NULL), | 68 advanced_link_(NULL), |
63 close_button_(NULL), | 69 close_button_(NULL), |
64 browser_(browser), | 70 learn_more_callback_(learn_more_callback), |
| 71 advanced_callback_(advanced_callback), |
65 message_loop_for_testing_(NULL) { | 72 message_loop_for_testing_(NULL) { |
66 DCHECK(browser_); | 73 DCHECK(!learn_more_callback_.is_null()); |
| 74 DCHECK(!advanced_callback_.is_null()); |
67 } | 75 } |
68 | 76 |
69 OneClickSigninBubbleView::~OneClickSigninBubbleView() { | 77 OneClickSigninBubbleView::~OneClickSigninBubbleView() { |
70 } | 78 } |
71 | 79 |
72 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { | 80 void OneClickSigninBubbleView::AnimationEnded(const ui::Animation* animation) { |
73 views::BubbleDelegateView::AnimationEnded(animation); | 81 views::BubbleDelegateView::AnimationEnded(animation); |
74 if (message_loop_for_testing_) | 82 if (message_loop_for_testing_) |
75 message_loop_for_testing_->Quit(); | 83 message_loop_for_testing_->Quit(); |
76 } | 84 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 return true; | 161 return true; |
154 } | 162 } |
155 | 163 |
156 return BubbleDelegateView::AcceleratorPressed(accelerator); | 164 return BubbleDelegateView::AcceleratorPressed(accelerator); |
157 } | 165 } |
158 | 166 |
159 void OneClickSigninBubbleView::LinkClicked(views::Link* source, | 167 void OneClickSigninBubbleView::LinkClicked(views::Link* source, |
160 int event_flags) { | 168 int event_flags) { |
161 StartFade(false); | 169 StartFade(false); |
162 | 170 |
163 GURL url; | 171 if (source == learn_more_link_) |
164 if (source == learn_more_link_) { | 172 learn_more_callback_.Run(); |
165 url = GURL(chrome::kSyncLearnMoreURL); | 173 else |
166 } else { | 174 advanced_callback_.Run(); |
167 url = GURL(std::string(chrome::kChromeUISettingsURL) + | |
168 chrome::kSyncSetupSubPage); | |
169 } | |
170 browser_->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_AUTO_BOOKMARK); | |
171 } | 175 } |
172 | 176 |
173 void OneClickSigninBubbleView::ButtonPressed( | 177 void OneClickSigninBubbleView::ButtonPressed( |
174 views::Button* sender, const views::Event& event) { | 178 views::Button* sender, const views::Event& event) { |
175 DCHECK_EQ(sender, close_button_); | 179 DCHECK_EQ(sender, close_button_); |
176 StartFade(false); | 180 StartFade(false); |
177 } | 181 } |
OLD | NEW |