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 virtual ~OneClickSigninBubbleView();
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:
76 virtual void Init() OVERRIDE
;
78 // Overridden from views::LinkListener:
79 virtual void LinkClicked(views::Link
* source
, int event_flags
) OVERRIDE
;
81 // Overridden from views::ButtonListener:
82 virtual void ButtonPressed(views::Button
* sender
,
83 const ui::Event
& event
) OVERRIDE
;
85 // Overridden from views::View:
86 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
88 // Overridden from views::WidgetDelegate:
89 virtual void WindowClosing() OVERRIDE
;
90 virtual ui::ModalType
GetModalType() const OVERRIDE
;
92 // Builds a popup bubble anchored under the wrench menu
93 void InitBubbleContent(views::GridLayout
* layout
);
95 // Builds a modal dialog aligned center top
96 void InitDialogContent(views::GridLayout
* layout
);
98 // Initializes the OK/Undo buttons to be used at the bottom of the bubble.
99 void InitButtons(views::GridLayout
* layout
);
100 void GetButtons(views::LabelButton
** ok_button
,
101 views::LabelButton
** undo_button
);
103 // Creates learn more link to be used at the bottom of the bubble.
104 void InitLearnMoreLink();
106 // Creates advanced link to be used at the bottom of the bubble.
107 void InitAdvancedLink();
109 // Delegate to handle clicking on links in the bubble.
110 scoped_ptr
<OneClickSigninBubbleDelegate
> delegate_
;
112 // Alternate error message to be displayed.
113 const base::string16 error_message_
;
115 // The user's email address to be used for sync.
116 const base::string16 email_
;
118 // This callback is nulled once its called, so that it is called only once.
119 // It will be called when the bubble is closed if it has not been called
120 // and nulled earlier.
121 BrowserWindow::StartSyncCallback start_sync_callback_
;
123 const bool is_sync_dialog_
;
125 // Link to sync setup advanced page.
126 views::Link
* advanced_link_
;
128 // Link to the Learn More details page
129 views::Link
* learn_more_link_
;
131 // Controls at bottom of bubble.
132 views::LabelButton
* ok_button_
;
133 views::LabelButton
* undo_button_
;
135 // Close button for the modal dialog
136 views::ImageButton
* close_button_
;
138 bool clicked_learn_more_
;
140 // The bubble, if we're showing one.
141 static OneClickSigninBubbleView
* bubble_view_
;
143 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView
);
146 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_