| 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 #ifndef CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ | 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_ | 6 #define CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/views/toolbar_view.h" |
| 14 #include "ui/views/bubble/bubble_delegate.h" | 15 #include "ui/views/bubble/bubble_delegate.h" |
| 15 #include "ui/views/controls/button/button.h" | 16 #include "ui/views/controls/button/button.h" |
| 16 #include "ui/views/controls/link_listener.h" | 17 #include "ui/views/controls/link_listener.h" |
| 17 | 18 |
| 18 class MessageLoop; | 19 class MessageLoop; |
| 19 | 20 |
| 20 namespace views { | 21 namespace views { |
| 22 class GridLayout; |
| 21 class TextButton; | 23 class TextButton; |
| 22 } | 24 } |
| 23 | 25 |
| 24 // OneClickSigninBubbleView is a view intended to be used as the content of an | 26 // OneClickSigninBubbleView is a view intended to be used as the content of an |
| 25 // Bubble. It provides simple and concise feedback to the user that sync'ing | 27 // Bubble. It provides simple and concise feedback to the user that sync'ing |
| 26 // has started after using the one-click singin infobar. | 28 // has started after using the one-click singin infobar. |
| 27 class OneClickSigninBubbleView : public views::BubbleDelegateView, | 29 class OneClickSigninBubbleView : public views::BubbleDelegateView, |
| 28 public views::LinkListener, | 30 public views::LinkListener, |
| 29 public views::ButtonListener { | 31 public views::ButtonListener { |
| 30 public: | 32 public: |
| 31 // Show the one-click signin bubble if not already showing. The bubble | 33 // Show the one-click signin bubble if not already showing. The bubble |
| 32 // will be placed visually beneath |anchor_view|. |start_sync| is called | 34 // will be placed visually beneath |anchor_view|. |start_sync| is called |
| 33 // to start sync. | 35 // to start sync. |
| 34 static void ShowBubble(views::View* anchor_view, | 36 static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type, |
| 37 ToolbarView* toolbar_view, |
| 35 const BrowserWindow::StartSyncCallback& start_sync); | 38 const BrowserWindow::StartSyncCallback& start_sync); |
| 36 | 39 |
| 37 static bool IsShowing(); | 40 static bool IsShowing(); |
| 38 | 41 |
| 39 static void Hide(); | 42 static void Hide(); |
| 40 | 43 |
| 41 // Gets the global bubble view. If its not showing returns NULL. This | 44 // Gets the global bubble view. If its not showing returns NULL. This |
| 42 // method is meant to be called only from tests. | 45 // method is meant to be called only from tests. |
| 43 static OneClickSigninBubbleView* view_for_testing() { return bubble_view_; } | 46 static OneClickSigninBubbleView* view_for_testing() { return bubble_view_; } |
| 44 | 47 |
| 45 private: | 48 protected: |
| 46 friend class OneClickSigninBubbleViewBrowserTest; | |
| 47 | |
| 48 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, OkButton); | |
| 49 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, UndoButton); | |
| 50 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, AdvancedLink); | |
| 51 | |
| 52 // Creates a OneClickSigninBubbleView. | 49 // Creates a OneClickSigninBubbleView. |
| 53 OneClickSigninBubbleView( | 50 OneClickSigninBubbleView( |
| 54 views::View* anchor_view, | 51 views::View* anchor_view, |
| 55 const BrowserWindow::StartSyncCallback& start_sync_callback); | 52 const BrowserWindow::StartSyncCallback& start_sync_callback); |
| 56 | 53 |
| 57 virtual ~OneClickSigninBubbleView(); | 54 virtual ~OneClickSigninBubbleView(); |
| 58 | 55 |
| 59 // views::BubbleDelegateView methods: | |
| 60 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | |
| 61 virtual void Init() OVERRIDE; | |
| 62 | |
| 63 // views::WidgetDelegate method: | |
| 64 virtual void WindowClosing() OVERRIDE; | |
| 65 | |
| 66 // views::View method: | |
| 67 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | |
| 68 | |
| 69 // Overridden from views::LinkListener: | 56 // Overridden from views::LinkListener: |
| 70 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 57 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 71 | 58 |
| 72 // Overridden from views::ButtonListener: | 59 // Overridden from views::ButtonListener: |
| 73 virtual void ButtonPressed(views::Button* sender, | 60 virtual void ButtonPressed(views::Button* sender, |
| 74 const ui::Event& event) OVERRIDE; | 61 const ui::Event& event) OVERRIDE; |
| 75 | 62 |
| 63 private: |
| 64 friend class OneClickSigninBubbleViewBrowserTest; |
| 65 |
| 66 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, OkButton); |
| 67 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, UndoButton); |
| 68 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, AdvancedLink); |
| 69 |
| 70 // views::BubbleDelegateView methods: |
| 71 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 72 virtual void Init() OVERRIDE; |
| 73 |
| 74 // Method to build the main part of the bubble. Derived classes should |
| 75 // reimplement this function. |
| 76 virtual void InitContent(views::GridLayout* layout); |
| 77 |
| 78 // Creates OK and Undo buttons to be used at the bottom of the bubble. |
| 79 // Derived classes can reimplement to have buttons with different labels, |
| 80 // colours, or sizes. The caller of this function owns the returned buttons. |
| 81 virtual void GetButtons(views::TextButton** ok_button, |
| 82 views::TextButton** undo_button); |
| 83 |
| 84 // views::WidgetDelegate method: |
| 85 virtual void WindowClosing() OVERRIDE; |
| 86 |
| 87 // views::View method: |
| 88 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 89 |
| 76 // The bubble, if we're showing one. | 90 // The bubble, if we're showing one. |
| 77 static OneClickSigninBubbleView* bubble_view_; | 91 static OneClickSigninBubbleView* bubble_view_; |
| 78 | 92 |
| 79 // Link to sync setup advanced page. | 93 // Link to sync setup advanced page. |
| 80 views::Link* advanced_link_; | 94 views::Link* advanced_link_; |
| 81 | 95 |
| 82 // Controls at bottom of bubble. | 96 // Controls at bottom of bubble. |
| 83 views::TextButton* ok_button_; | 97 views::TextButton* ok_button_; |
| 84 views::TextButton* undo_button_; | 98 views::TextButton* undo_button_; |
| 85 | 99 |
| 86 // This callback is nulled once its called, so that it is called only once. | 100 // This callback is nulled once its called, so that it is called only once. |
| 87 // It will be called when the bubble is closed if it has not been called | 101 // It will be called when the bubble is closed if it has not been called |
| 88 // and nulled earlier. | 102 // and nulled earlier. |
| 89 BrowserWindow::StartSyncCallback start_sync_callback_; | 103 BrowserWindow::StartSyncCallback start_sync_callback_; |
| 90 | 104 |
| 91 // A message loop used only with unit tests. | 105 // A message loop used only with unit tests. |
| 92 MessageLoop* message_loop_for_testing_; | 106 MessageLoop* message_loop_for_testing_; |
| 93 | 107 |
| 94 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView); | 108 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView); |
| 95 }; | 109 }; |
| 96 | 110 |
| 97 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ | 111 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ |
| OLD | NEW |