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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/compiler_specific.h"
11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/strings/string16.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/sync/one_click_signin_bubble_delegate.h"
16 #include "ui/views/bubble/bubble_delegate.h"
17 #include "ui/views/controls/button/button.h"
18 #include "ui/views/controls/link_listener.h"
27 // OneClickSigninBubbleView is a view intended to be used as the content of an
28 // Bubble. It provides simple and concise feedback to the user that sync'ing
29 // has started after using the one-click singin infobar.
30 class OneClickSigninBubbleView
: public views::BubbleDelegateView
,
31 public views::LinkListener
,
32 public views::ButtonListener
{
34 // Show the one-click signin bubble if not already showing. The bubble
35 // will be placed visually beneath |anchor_view|. |start_sync| is called
37 static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type
,
38 const base::string16
& email
,
39 const base::string16
& error_message
,
40 scoped_ptr
<OneClickSigninBubbleDelegate
> delegate
,
41 views::View
* anchor_view
,
42 const BrowserWindow::StartSyncCallback
& start_sync
);
44 static bool IsShowing();
48 // Gets the global bubble view. If its not showing returns NULL. This
49 // method is meant to be called only from tests.
50 static OneClickSigninBubbleView
* view_for_testing() { return bubble_view_
; }
53 // Creates a OneClickSigninBubbleView.
54 OneClickSigninBubbleView(
55 const base::string16
& error_message
,
56 const base::string16
& email
,
57 scoped_ptr
<OneClickSigninBubbleDelegate
> delegate
,
58 views::View
* anchor_view
,
59 const BrowserWindow::StartSyncCallback
& start_sync_callback
,
62 ~OneClickSigninBubbleView() override
;
65 friend class OneClickSigninBubbleViewTest
;
67 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, BubbleOkButton
);
68 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, DialogOkButton
);
69 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, DialogUndoButton
);
70 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, BubbleAdvancedLink
);
71 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, DialogAdvancedLink
);
72 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, BubbleLearnMoreLink
);
73 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewTest
, DialogLearnMoreLink
);
75 // Overridden from views::BubbleDelegateView:
78 // Overridden from views::LinkListener:
79 void LinkClicked(views::Link
* source
, int event_flags
) override
;
81 // Overridden from views::ButtonListener:
82 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
84 // Overridden from views::View:
85 bool AcceleratorPressed(const ui::Accelerator
& accelerator
) override
;
87 // Overridden from views::WidgetDelegate:
88 void WindowClosing() override
;
89 ui::ModalType
GetModalType() const override
;
91 // Builds a popup bubble anchored under the wrench menu
92 void InitBubbleContent(views::GridLayout
* layout
);
94 // Builds a modal dialog aligned center top
95 void InitDialogContent(views::GridLayout
* layout
);
97 // Initializes the OK/Undo buttons to be used at the bottom of the bubble.
98 void InitButtons(views::GridLayout
* layout
);
99 void GetButtons(views::LabelButton
** ok_button
,
100 views::LabelButton
** undo_button
);
102 // Creates learn more link to be used at the bottom of the bubble.
103 void InitLearnMoreLink();
105 // Creates advanced link to be used at the bottom of the bubble.
106 void InitAdvancedLink();
108 // Delegate to handle clicking on links in the bubble.
109 scoped_ptr
<OneClickSigninBubbleDelegate
> delegate_
;
111 // Alternate error message to be displayed.
112 const base::string16 error_message_
;
114 // The user's email address to be used for sync.
115 const base::string16 email_
;
117 // This callback is nulled once its called, so that it is called only once.
118 // It will be called when the bubble is closed if it has not been called
119 // and nulled earlier.
120 BrowserWindow::StartSyncCallback start_sync_callback_
;
122 const bool is_sync_dialog_
;
124 // Link to sync setup advanced page.
125 views::Link
* advanced_link_
;
127 // Link to the Learn More details page
128 views::Link
* learn_more_link_
;
130 // Controls at bottom of bubble.
131 views::LabelButton
* ok_button_
;
132 views::LabelButton
* undo_button_
;
134 // Close button for the modal dialog
135 views::ImageButton
* close_button_
;
137 bool clicked_learn_more_
;
139 // The bubble, if we're showing one.
140 static OneClickSigninBubbleView
* bubble_view_
;
142 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView
);
145 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_