| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_GTK_WEB_INTENT_PICKER_GTK_H_ | |
| 6 #define CHROME_BROWSER_UI_GTK_WEB_INTENT_PICKER_GTK_H_ | |
| 7 | |
| 8 #include <gtk/gtk.h> | |
| 9 | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "chrome/browser/ui/gtk/constrained_window_gtk.h" | |
| 16 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" | |
| 17 #include "chrome/browser/ui/intents/web_intent_picker.h" | |
| 18 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 #include "content/public/browser/notification_registrar.h" | |
| 21 #include "ui/base/gtk/gtk_signal.h" | |
| 22 #include "ui/base/gtk/owned_widget_gtk.h" | |
| 23 | |
| 24 namespace ui { | |
| 25 class GtkSignalRegistrar; | |
| 26 } | |
| 27 | |
| 28 class CustomDrawButton; | |
| 29 class GURL; | |
| 30 class ThrobberGtk; | |
| 31 class WebIntentPickerDelegate; | |
| 32 class WaitingDialog; | |
| 33 | |
| 34 // GTK implementation of WebIntentPicker. | |
| 35 class WebIntentPickerGtk : public WebIntentPicker, | |
| 36 public WebIntentPickerModelObserver, | |
| 37 public ConstrainedWindowGtkDelegate, | |
| 38 public content::NotificationObserver { | |
| 39 public: | |
| 40 WebIntentPickerGtk(content::WebContents* web_contents, | |
| 41 WebIntentPickerDelegate* delegate, | |
| 42 WebIntentPickerModel* model); | |
| 43 virtual ~WebIntentPickerGtk(); | |
| 44 | |
| 45 // WebIntentPicker implementation. | |
| 46 virtual void Close() OVERRIDE; | |
| 47 virtual void SetActionString(const string16& action) OVERRIDE; | |
| 48 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; | |
| 49 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; | |
| 50 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE; | |
| 51 virtual gfx::Size GetMaxInlineDispositionSize() OVERRIDE; | |
| 52 | |
| 53 // WebIntentPickerModelObserver implementation. | |
| 54 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; | |
| 55 virtual void OnFaviconChanged(WebIntentPickerModel* model, | |
| 56 size_t index) OVERRIDE; | |
| 57 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, | |
| 58 const std::string& extension_id) OVERRIDE; | |
| 59 virtual void OnInlineDisposition(const string16& title, | |
| 60 const GURL& url) OVERRIDE; | |
| 61 | |
| 62 virtual void OnPendingAsyncCompleted() OVERRIDE; | |
| 63 virtual void InvalidateDelegate() OVERRIDE; | |
| 64 | |
| 65 // ConstrainedWindowGtkDelegate implementation. | |
| 66 virtual GtkWidget* GetWidgetRoot() OVERRIDE; | |
| 67 virtual GtkWidget* GetFocusWidget() OVERRIDE; | |
| 68 virtual void DeleteDelegate() OVERRIDE; | |
| 69 virtual bool GetBackgroundColor(GdkColor* color) OVERRIDE; | |
| 70 virtual bool ShouldHaveBorderPadding() const OVERRIDE; | |
| 71 | |
| 72 // content::NotificationObserver implementation. | |
| 73 virtual void Observe(int type, | |
| 74 const content::NotificationSource& source, | |
| 75 const content::NotificationDetails& details) OVERRIDE; | |
| 76 | |
| 77 private: | |
| 78 // Callback when picker is destroyed. | |
| 79 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnDestroy); | |
| 80 // Callback when a service button is clicked. | |
| 81 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnServiceButtonClick); | |
| 82 // Callback when close button is clicked. | |
| 83 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnCloseButtonClick); | |
| 84 // Callback when suggested extension title link is clicked. | |
| 85 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnExtensionLinkClick); | |
| 86 // Callback when suggested extension install button is clicked. | |
| 87 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnExtensionInstallButtonClick); | |
| 88 // Callback when "more suggestions" link is clicked. | |
| 89 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnMoreSuggestionsLinkClick); | |
| 90 // Callback when "or choose another service" link is clicked. | |
| 91 CHROMEGTK_CALLBACK_0(WebIntentPickerGtk, void, OnChooseAnotherServiceClick); | |
| 92 // Callback when the host tab contents size changes. | |
| 93 CHROMEGTK_CALLBACK_1(WebIntentPickerGtk, void, OnHostContentsSizeAllocate, | |
| 94 GdkRectangle*); | |
| 95 | |
| 96 // Initialize the contents of the picker. After this call, contents_ will be | |
| 97 // non-NULL. | |
| 98 void InitContents(); | |
| 99 | |
| 100 // Initialize the main picker dialog. | |
| 101 void InitMainContents(); | |
| 102 | |
| 103 // Clear all contents and reset related variables. | |
| 104 void ClearContents(); | |
| 105 | |
| 106 // Reset contents to the initial picker state. | |
| 107 void ResetContents(); | |
| 108 | |
| 109 // Create the (inset relative to |box|) container for dialog elements. | |
| 110 GtkWidget* CreateSubContents(GtkWidget* box); | |
| 111 | |
| 112 // Add a close button to dialog contents | |
| 113 void AddCloseButton(GtkWidget* containingBox); | |
| 114 | |
| 115 // Add title to dialog contents | |
| 116 void AddTitle(GtkWidget* containingBox); | |
| 117 | |
| 118 // Update the installed service buttons from |model_|. | |
| 119 void UpdateInstalledServices(); | |
| 120 | |
| 121 // Update the Chrome Web Store label from |model_|. | |
| 122 void UpdateCWSLabel(); | |
| 123 | |
| 124 // Update the suggested extension table from |model_|. | |
| 125 void UpdateSuggestedExtensions(); | |
| 126 | |
| 127 // Enables/disables all service buttons and extension suggestions. | |
| 128 void SetWidgetsEnabled(bool enabled); | |
| 129 | |
| 130 // Adds a throbber to the extension at |index|. Returns the alignment widget | |
| 131 // containing the throbber. | |
| 132 GtkWidget* AddThrobberToExtensionAt(size_t index); | |
| 133 | |
| 134 // Removes the added throbber. | |
| 135 void RemoveThrobber(); | |
| 136 | |
| 137 // A weak pointer to the tab contents on which to display the picker UI. | |
| 138 content::WebContents* web_contents_; | |
| 139 | |
| 140 // A weak pointer to the WebIntentPickerDelegate to notify when the user | |
| 141 // chooses a service or cancels. | |
| 142 WebIntentPickerDelegate* delegate_; | |
| 143 | |
| 144 // A weak pointer to the picker model. | |
| 145 WebIntentPickerModel* model_; | |
| 146 | |
| 147 // A weak pointer to the widget that contains all other widgets in | |
| 148 // the picker. | |
| 149 GtkWidget* contents_; | |
| 150 | |
| 151 // A weak pointer to the header label. | |
| 152 GtkWidget* header_label_; | |
| 153 | |
| 154 // The text displayed in the header label. | |
| 155 string16 header_label_text_; | |
| 156 | |
| 157 // A weak pointer to the vbox that contains the buttons used to choose the | |
| 158 // service. | |
| 159 GtkWidget* button_vbox_; | |
| 160 | |
| 161 // A weak pointer to the Chrome Web Store header label. | |
| 162 GtkWidget* cws_label_; | |
| 163 | |
| 164 // A weak pointer to the suggested extensions vbox. | |
| 165 GtkWidget* extensions_vbox_; | |
| 166 | |
| 167 // This widget holds the header when showing an inline intent handler. | |
| 168 GtkWidget* service_hbox_; | |
| 169 | |
| 170 // A button to close the picker. | |
| 171 scoped_ptr<CustomDrawButton> close_button_; | |
| 172 | |
| 173 // The throbber to display when installing an extension. | |
| 174 scoped_ptr<ThrobberGtk> throbber_; | |
| 175 | |
| 176 scoped_ptr<WaitingDialog> waiting_dialog_; | |
| 177 | |
| 178 // A weak pointer to the constrained window. | |
| 179 ConstrainedWindowGtk* window_; | |
| 180 | |
| 181 // The WebContents being displayed in inline disposition. | |
| 182 scoped_ptr<content::WebContents> inline_disposition_web_contents_; | |
| 183 | |
| 184 // content::WebContentsDelegate for the inline disposition dialog. | |
| 185 scoped_ptr<WebIntentInlineDispositionDelegate> inline_disposition_delegate_; | |
| 186 | |
| 187 content::NotificationRegistrar registrar_; | |
| 188 | |
| 189 // Used to connect to signals fired on the host tab contents (only used while | |
| 190 // showing an inline intent handler). | |
| 191 scoped_ptr<ui::GtkSignalRegistrar> host_signals_; | |
| 192 | |
| 193 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerGtk); | |
| 194 }; | |
| 195 | |
| 196 #endif // CHROME_BROWSER_UI_GTK_WEB_INTENT_PICKER_GTK_H_ | |
| OLD | NEW |