| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 // has started after using the one-click singin infobar. | 30 // has started after using the one-click singin infobar. |
| 31 class OneClickSigninBubbleView : public views::BubbleDelegateView, | 31 class OneClickSigninBubbleView : public views::BubbleDelegateView, |
| 32 public views::LinkListener, | 32 public views::LinkListener, |
| 33 public views::ButtonListener { | 33 public views::ButtonListener { |
| 34 public: | 34 public: |
| 35 // Show the one-click signin bubble if not already showing. The bubble | 35 // Show the one-click signin bubble if not already showing. The bubble |
| 36 // will be placed visually beneath |anchor_view|. |start_sync| is called | 36 // will be placed visually beneath |anchor_view|. |start_sync| is called |
| 37 // to start sync. | 37 // to start sync. |
| 38 static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type, | 38 static void ShowBubble(BrowserWindow::OneClickSigninBubbleType type, |
| 39 const string16& email, | 39 const string16& email, |
| 40 const string16& error_message, |
| 40 ToolbarView* toolbar_view, | 41 ToolbarView* toolbar_view, |
| 41 const BrowserWindow::StartSyncCallback& start_sync); | 42 const BrowserWindow::StartSyncCallback& start_sync); |
| 42 | 43 |
| 43 static bool IsShowing(); | 44 static bool IsShowing(); |
| 44 | 45 |
| 45 static void Hide(); | 46 static void Hide(); |
| 46 | 47 |
| 47 // Gets the global bubble view. If its not showing returns NULL. This | 48 // Gets the global bubble view. If its not showing returns NULL. This |
| 48 // method is meant to be called only from tests. | 49 // method is meant to be called only from tests. |
| 49 static OneClickSigninBubbleView* view_for_testing() { return bubble_view_; } | 50 static OneClickSigninBubbleView* view_for_testing() { return bubble_view_; } |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 // Creates a OneClickSigninBubbleView. | 53 // Creates a OneClickSigninBubbleView. |
| 53 OneClickSigninBubbleView( | 54 OneClickSigninBubbleView( |
| 55 content::WebContents* web_contents, |
| 54 views::View* anchor_view, | 56 views::View* anchor_view, |
| 55 const BrowserWindow::StartSyncCallback& start_sync_callback); | 57 const string16& error_message, |
| 58 const string16& email, |
| 59 const BrowserWindow::StartSyncCallback& start_sync_callback, |
| 60 bool is_sync_dialog); |
| 56 | 61 |
| 57 virtual ~OneClickSigninBubbleView(); | 62 virtual ~OneClickSigninBubbleView(); |
| 58 | 63 |
| 64 private: |
| 65 friend class OneClickSigninBubbleViewBrowserTest; |
| 66 |
| 67 FRIEND_TEST_ALL_PREFIXES( |
| 68 OneClickSigninBubbleViewBrowserTest, BubbleOkButton); |
| 69 FRIEND_TEST_ALL_PREFIXES( |
| 70 OneClickSigninBubbleViewBrowserTest, DialogOkButton); |
| 71 FRIEND_TEST_ALL_PREFIXES( |
| 72 OneClickSigninBubbleViewBrowserTest, DialogUndoButton); |
| 73 FRIEND_TEST_ALL_PREFIXES( |
| 74 OneClickSigninBubbleViewBrowserTest, BubbleAdvancedLink); |
| 75 FRIEND_TEST_ALL_PREFIXES( |
| 76 OneClickSigninBubbleViewBrowserTest, DialogAdvancedLink); |
| 77 FRIEND_TEST_ALL_PREFIXES( |
| 78 OneClickSigninBubbleViewBrowserTest, BubbleLearnMoreLink); |
| 79 FRIEND_TEST_ALL_PREFIXES( |
| 80 OneClickSigninBubbleViewBrowserTest, DialogLearnMoreLink); |
| 81 |
| 82 // Overridden from views::BubbleDelegateView: |
| 83 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; |
| 84 virtual void Init() OVERRIDE; |
| 85 |
| 59 // Overridden from views::LinkListener: | 86 // Overridden from views::LinkListener: |
| 60 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 87 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 61 | 88 |
| 62 // Overridden from views::ButtonListener: | 89 // Overridden from views::ButtonListener: |
| 63 virtual void ButtonPressed(views::Button* sender, | 90 virtual void ButtonPressed(views::Button* sender, |
| 64 const ui::Event& event) OVERRIDE; | 91 const ui::Event& event) OVERRIDE; |
| 65 | 92 |
| 66 // views::View method: | 93 // Overridden from views::View: |
| 67 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; | 94 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| 68 | 95 |
| 69 views::Link* GetAdvancedLink(); | 96 // Overridden from views::WidgetDelegate: |
| 70 views::Button* GetOkButton(); | 97 virtual void WindowClosing() OVERRIDE; |
| 71 views::Button* GetUndoButton(); | 98 virtual ui::ModalType GetModalType() const OVERRIDE; |
| 72 | 99 |
| 73 private: | 100 // Builds a popup bubble anchored under the wrench menu |
| 74 friend class OneClickSigninBubbleViewBrowserTest; | 101 void InitBubbleContent(views::GridLayout* layout); |
| 75 | 102 |
| 76 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, OkButton); | 103 // Builds a modal dialog aligned center top |
| 77 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, UndoButton); | 104 void InitDialogContent(views::GridLayout* layout); |
| 78 FRIEND_TEST_ALL_PREFIXES(OneClickSigninBubbleViewBrowserTest, AdvancedLink); | |
| 79 | 105 |
| 80 // views::BubbleDelegateView methods: | 106 // Initializes the OK/Undo buttons to be used at the bottom of the bubble. |
| 81 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 107 void InitButtons(views::GridLayout* layout); |
| 82 virtual void Init() OVERRIDE; | 108 void GetButtons(views::LabelButton** ok_button, |
| 83 | |
| 84 // Method to build the main part of the bubble. Derived classes should | |
| 85 // reimplement this function. | |
| 86 virtual void InitContent(views::GridLayout* layout); | |
| 87 | |
| 88 // Creates OK and Undo buttons to be used at the bottom of the bubble. | |
| 89 // Derived classes can reimplement to have buttons with different labels, | |
| 90 // colours, or sizes. The caller of this function owns the returned buttons. | |
| 91 virtual void GetButtons(views::LabelButton** ok_button, | |
| 92 views::LabelButton** undo_button); | 109 views::LabelButton** undo_button); |
| 93 | 110 |
| 111 // Creates learn more link to be used at the bottom of the bubble. |
| 112 void InitLearnMoreLink(); |
| 113 |
| 94 // Creates advanced link to be used at the bottom of the bubble. | 114 // Creates advanced link to be used at the bottom of the bubble. |
| 95 // Derived classes can reimplement. The caller of this function owns the | 115 void InitAdvancedLink(); |
| 96 // returned link. | |
| 97 virtual views::Link* CreateAdvancedLink(); | |
| 98 | 116 |
| 99 // views::WidgetDelegate method: | 117 // The bubble/dialog will always outlive the web_content, so this is ok |
| 100 virtual void WindowClosing() OVERRIDE; | 118 content::WebContents* web_contents_; |
| 101 | 119 |
| 102 // The bubble, if we're showing one. | 120 // Alternate error message to be displayed |
| 103 static OneClickSigninBubbleView* bubble_view_; | 121 const string16 error_message_; |
| 104 | 122 |
| 105 // Link to sync setup advanced page. | 123 const string16 email_; |
| 106 views::Link* advanced_link_; | |
| 107 | |
| 108 // Controls at bottom of bubble. | |
| 109 views::LabelButton* ok_button_; | |
| 110 views::LabelButton* undo_button_; | |
| 111 | 124 |
| 112 // This callback is nulled once its called, so that it is called only once. | 125 // This callback is nulled once its called, so that it is called only once. |
| 113 // It will be called when the bubble is closed if it has not been called | 126 // It will be called when the bubble is closed if it has not been called |
| 114 // and nulled earlier. | 127 // and nulled earlier. |
| 115 BrowserWindow::StartSyncCallback start_sync_callback_; | 128 BrowserWindow::StartSyncCallback start_sync_callback_; |
| 116 | 129 |
| 130 const bool is_sync_dialog_; |
| 131 |
| 132 // Link to sync setup advanced page. |
| 133 views::Link* advanced_link_; |
| 134 |
| 135 // Link to the Learn More details page |
| 136 views::Link* learn_more_link_; |
| 137 |
| 138 // Controls at bottom of bubble. |
| 139 views::LabelButton* ok_button_; |
| 140 views::LabelButton* undo_button_; |
| 141 |
| 142 // Close button for the modal dialog |
| 143 views::ImageButton* close_button_; |
| 144 |
| 145 bool clicked_learn_more_; |
| 146 |
| 117 // A message loop used only with unit tests. | 147 // A message loop used only with unit tests. |
| 118 base::MessageLoop* message_loop_for_testing_; | 148 base::MessageLoop* message_loop_for_testing_; |
| 119 | 149 |
| 150 // The bubble, if we're showing one. |
| 151 static OneClickSigninBubbleView* bubble_view_; |
| 152 |
| 120 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView); | 153 DISALLOW_COPY_AND_ASSIGN(OneClickSigninBubbleView); |
| 121 }; | 154 }; |
| 122 | 155 |
| 123 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ | 156 #endif // CHROME_BROWSER_UI_VIEWS_SYNC_ONE_CLICK_SIGNIN_BUBBLE_VIEW_H_ |
| OLD | NEW |