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