Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: chrome/browser/ui/gtk/web_intent_picker_gtk.cc

Issue 9148032: [Web Intents] Refactor picker to use WebIntentPickerModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vertical layout for views Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/ui/gtk/web_intent_picker_gtk.h" 5 #include "chrome/browser/ui/gtk/web_intent_picker_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/favicon/favicon_service.h" 12 #include "chrome/browser/favicon/favicon_service.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" 16 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h"
16 #include "chrome/browser/ui/gtk/browser_window_gtk.h" 17 #include "chrome/browser/ui/gtk/browser_window_gtk.h"
17 #include "chrome/browser/ui/gtk/custom_button.h" 18 #include "chrome/browser/ui/gtk/custom_button.h"
18 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 19 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
19 #include "chrome/browser/ui/gtk/gtk_util.h" 20 #include "chrome/browser/ui/gtk/gtk_util.h"
20 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" 21 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
21 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" 22 #include "chrome/browser/ui/gtk/tab_contents_container_gtk.h"
22 #include "chrome/browser/ui/intents/web_intent_picker_controller.h" 23 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
23 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 24 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
25 #include "chrome/browser/ui/intents/web_intent_picker_model.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
25 #include "content/browser/renderer_host/render_view_host.h" 27 #include "content/browser/renderer_host/render_view_host.h"
26 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" 28 #include "content/browser/renderer_host/render_widget_host_view_gtk.h"
27 #include "content/public/browser/notification_registrar.h" 29 #include "content/public/browser/notification_registrar.h"
28 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
29 #include "content/public/browser/notification_types.h" 31 #include "content/public/browser/notification_types.h"
30 #include "content/public/browser/web_contents.h" 32 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_contents_view.h" 33 #include "content/public/browser/web_contents_view.h"
32 #include "googleurl/src/gurl.h" 34 #include "googleurl/src/gurl.h"
33 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
(...skipping 14 matching lines...) Expand all
48 // button on the right. 50 // button on the right.
49 const int kMainContentWidth = 300; 51 const int kMainContentWidth = 300;
50 52
51 // The length in pixels of the label at the bottom of the picker. Text longer 53 // The length in pixels of the label at the bottom of the picker. Text longer
52 // than this width will wrap. 54 // than this width will wrap.
53 const int kWebStoreLabelLength = 300; 55 const int kWebStoreLabelLength = 300;
54 56
55 // The pixel size of the label at the bottom of the picker. 57 // The pixel size of the label at the bottom of the picker.
56 const int kWebStoreLabelPixelSize = 11; 58 const int kWebStoreLabelPixelSize = 11;
57 59
58 // How much to scale the the buttons up from their favicon size.
59 const int kServiceButtonScale = 3;
60
61 GtkThemeService *GetThemeService(TabContentsWrapper* wrapper) { 60 GtkThemeService *GetThemeService(TabContentsWrapper* wrapper) {
62 return GtkThemeService::GetFrom(wrapper->profile()); 61 return GtkThemeService::GetFrom(wrapper->profile());
63 } 62 }
64 63
65 // Set the image of |button| to |pixbuf|, and scale the button up by 64 // Set the image of |button| to |pixbuf|, and scale the button up by
66 // |kServiceButtonScale|. 65 // |kServiceButtonScale|.
67 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) { 66 void SetServiceButtonImage(GtkWidget* button, GdkPixbuf* pixbuf) {
68 int width = gdk_pixbuf_get_width(pixbuf); 67 gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(pixbuf));
69 int height = gdk_pixbuf_get_height(pixbuf); 68 gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_LEFT);
70 gtk_button_set_image(GTK_BUTTON(button), 69 }
71 gtk_image_new_from_pixbuf(pixbuf)); 70
72 gtk_widget_set_size_request(button, 71 // This helper function removes a widget from its parent container widget.
73 width * kServiceButtonScale, 72 void RemoveAllHelper(GtkWidget* widget, gpointer data) {
74 height * kServiceButtonScale); 73 GtkWidget* parent = gtk_widget_get_parent(widget);
74 gtk_container_remove(GTK_CONTAINER(parent), widget);
75 } 75 }
76 76
77 } // namespace 77 } // namespace
78 78
79 // static 79 // static
80 WebIntentPicker* WebIntentPicker::Create(Browser* browser, 80 WebIntentPicker* WebIntentPicker::Create(Browser* browser,
81 TabContentsWrapper* wrapper, 81 TabContentsWrapper* wrapper,
82 WebIntentPickerDelegate* delegate) { 82 WebIntentPickerDelegate* delegate,
83 return new WebIntentPickerGtk(browser, wrapper, delegate); 83 WebIntentPickerModel* model) {
84 return new WebIntentPickerGtk(browser, wrapper, delegate, model);
84 } 85 }
85 86
86 WebIntentPickerGtk::WebIntentPickerGtk(Browser* browser, 87 WebIntentPickerGtk::WebIntentPickerGtk(Browser* browser,
87 TabContentsWrapper* wrapper, 88 TabContentsWrapper* wrapper,
88 WebIntentPickerDelegate* delegate) 89 WebIntentPickerDelegate* delegate,
90 WebIntentPickerModel* model)
89 : wrapper_(wrapper), 91 : wrapper_(wrapper),
90 delegate_(delegate), 92 delegate_(delegate),
93 model_(model),
91 contents_(NULL), 94 contents_(NULL),
92 button_hbox_(NULL), 95 button_vbox_(NULL),
93 bubble_(NULL), 96 bubble_(NULL),
94 browser_(browser) { 97 browser_(browser) {
95 DCHECK(delegate_ != NULL); 98 DCHECK(delegate_ != NULL);
96 DCHECK(browser); 99 DCHECK(browser);
97 DCHECK(browser->window()); 100 DCHECK(browser->window());
101
102 model_->set_observer(this);
103
98 BrowserWindowGtk* browser_window = 104 BrowserWindowGtk* browser_window =
99 BrowserWindowGtk::GetBrowserWindowForNativeWindow( 105 BrowserWindowGtk::GetBrowserWindowForNativeWindow(
100 browser->window()->GetNativeHandle()); 106 browser->window()->GetNativeHandle());
101 107
102 GtkWidget* anchor = browser_window-> 108 GtkWidget* anchor = browser_window->
103 GetToolbar()->GetLocationBarView()->location_icon_widget(); 109 GetToolbar()->GetLocationBarView()->location_icon_widget();
104 110
105 InitContents(); 111 InitContents();
106 112
107 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ? 113 BubbleGtk::ArrowLocationGtk arrow_location = base::i18n::IsRTL() ?
108 BubbleGtk::ARROW_LOCATION_TOP_RIGHT : 114 BubbleGtk::ARROW_LOCATION_TOP_RIGHT :
109 BubbleGtk::ARROW_LOCATION_TOP_LEFT; 115 BubbleGtk::ARROW_LOCATION_TOP_LEFT;
110 bubble_ = BubbleGtk::Show(anchor, 116 bubble_ = BubbleGtk::Show(anchor,
111 NULL, // |rect| 117 NULL, // |rect|
112 contents_, 118 contents_,
113 arrow_location, 119 arrow_location,
114 true, // |match_system_theme| 120 true, // |match_system_theme|
115 true, // |grab_input| 121 true, // |grab_input|
116 GetThemeService(wrapper), 122 GetThemeService(wrapper),
117 this); // |delegate| 123 this); // |delegate|
118 } 124 }
119 125
120 WebIntentPickerGtk::~WebIntentPickerGtk() { 126 WebIntentPickerGtk::~WebIntentPickerGtk() {
121 DCHECK(bubble_ == NULL) << "Should have closed window before destroying."; 127 DCHECK(bubble_ == NULL) << "Should have closed window before destroying.";
122 } 128 }
123 129
124 void WebIntentPickerGtk::SetServiceURLs(const std::vector<GURL>& urls) { 130 void WebIntentPickerGtk::OnModelChanged(WebIntentPickerModel* model) {
125 for (size_t i = 0; i < urls.size(); ++i) { 131 RemoveAllFrom(button_vbox_);
132
133 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
134
135 for (size_t i = 0; i < model->GetItemCount(); ++i) {
136 const WebIntentPickerModel::Item& item = model->GetItemAt(i);
137
126 GtkWidget* button = gtk_button_new(); 138 GtkWidget* button = gtk_button_new();
127 gtk_widget_set_tooltip_text(button, urls[i].spec().c_str()); 139
128 gtk_box_pack_start(GTK_BOX(button_hbox_), button, FALSE, FALSE, 0); 140 gtk_widget_set_tooltip_text(button, item.url.spec().c_str());
141 gtk_button_set_label(GTK_BUTTON(button), UTF16ToUTF8(item.title).c_str());
142
143 gtk_box_pack_start(GTK_BOX(button_vbox_), button, FALSE, FALSE, 0);
129 g_signal_connect(button, 144 g_signal_connect(button,
130 "clicked", 145 "clicked",
131 G_CALLBACK(OnServiceButtonClickThunk), 146 G_CALLBACK(OnServiceButtonClickThunk),
132 this); 147 this);
148
149 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON);
150 SetServiceButtonImage(button, icon_pixbuf);
133 } 151 }
134 152
135 // Add the '+' button, to use the Chrome Web Store. 153 // Add the '+' button, to use the Chrome Web Store.
136 GtkWidget* plus_button = gtk_button_new(); 154 GtkWidget* plus_button = gtk_button_new();
137 gtk_widget_set_tooltip_text( 155 gtk_widget_set_tooltip_text(
138 plus_button, 156 plus_button,
139 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_TOOLTIP).c_str()); 157 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_TOOLTIP).c_str());
140 gtk_box_pack_start(GTK_BOX(button_hbox_), plus_button, FALSE, FALSE, 0); 158 gtk_box_pack_start(GTK_BOX(button_vbox_), plus_button, FALSE, FALSE, 0);
141 159
142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
143 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_SIDETABS_NEW_TAB); 160 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_SIDETABS_NEW_TAB);
144 SetServiceButtonImage(plus_button, icon_pixbuf); 161 SetServiceButtonImage(plus_button, icon_pixbuf);
145 162
146 gtk_widget_show_all(button_hbox_); 163 gtk_widget_show_all(button_vbox_);
147 } 164 }
148 165
149 void WebIntentPickerGtk::SetServiceIcon(size_t index, const SkBitmap& icon) { 166 void WebIntentPickerGtk::OnFaviconChanged(WebIntentPickerModel* model,
150 if (icon.empty()) 167 size_t index) {
168 const WebIntentPickerModel::Item& item = model->GetItemAt(index);
169 if (item.favicon.get() == NULL)
151 return; 170 return;
152 171
153 GtkWidget* button = GetServiceButton(index); 172 GtkWidget* button = GetServiceButton(index);
154 173 GdkPixbuf* icon_pixbuf = item.favicon->ToGdkPixbuf();
155 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon);
156 SetServiceButtonImage(button, icon_pixbuf); 174 SetServiceButtonImage(button, icon_pixbuf);
157 g_object_unref(icon_pixbuf);
158 } 175 }
159 176
160 void WebIntentPickerGtk::SetDefaultServiceIcon(size_t index) { 177 void WebIntentPickerGtk::OnInlineDisposition(WebIntentPickerModel* model) {
161 GtkWidget* button = GetServiceButton(index); 178 const WebIntentPickerModel::Item& item = model->GetItemAt(
179 model->inline_disposition_index());
180 const GURL& url = item.url;
162 181
163 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 182 content::WebContents* web_contents = content::WebContents::Create(
164 GdkPixbuf* icon_pixbuf = rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON); 183 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
165 SetServiceButtonImage(button, icon_pixbuf); 184 inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents));
185 inline_disposition_delegate_.reset(new InlineDispositionDelegate);
186 web_contents->SetDelegate(inline_disposition_delegate_.get());
187 tab_contents_container_.reset(new TabContentsContainerGtk(NULL));
188 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get());
189
190 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL(
191 url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE,
192 std::string());
193
194 // Replace the bubble picker contents with the inline disposition.
195
196 RemoveAllFrom(contents_);
197
198 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
199 // TODO(gbillock): Eventually get the service icon button here.
200 // Maybe add a title or something too?
201 close_button_.reset(
202 CustomDrawButton::CloseButton(GetThemeService(wrapper_)));
203 g_signal_connect(close_button_->widget(),
204 "clicked",
205 G_CALLBACK(OnCloseButtonClickThunk),
206 this);
207 gtk_widget_set_can_focus(close_button_->widget(), FALSE);
208 GtkWidget* close_vbox = gtk_vbox_new(FALSE, 0);
209 gtk_box_pack_start(GTK_BOX(close_vbox), close_button_->widget(),
210 FALSE, FALSE, 0);
211 gtk_box_pack_end(GTK_BOX(service_hbox), close_vbox, FALSE, FALSE, 0);
212
213 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
214 gtk_box_pack_start(GTK_BOX(vbox), service_hbox, TRUE, TRUE, 0);
215
216 // The separator between the icon/title/close and the inline renderer.
217 gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, TRUE, 0);
218
219 gtk_box_pack_end(GTK_BOX(vbox), tab_contents_container_->widget(),
220 TRUE, TRUE, 0);
221
222 gtk_container_add(GTK_CONTAINER(contents_), vbox);
223
224 // TODO(gbillock): This size calculation needs more thought.
225 // Move up to WebIntentPicker?
226 gfx::Size tab_size = wrapper_->web_contents()->GetView()->GetContainerSize();
227 int width = std::max(tab_size.width()/2, kMainContentWidth);
228 int height = std::max(tab_size.height()/2, kMainContentWidth);
229 gtk_widget_set_size_request(tab_contents_container_->widget(),
230 width, height);
231 gtk_widget_show_all(contents_);
232
233 delegate_->OnInlineDispositionWebContentsCreated(web_contents);
166 } 234 }
167 235
168 void WebIntentPickerGtk::Close() { 236 void WebIntentPickerGtk::Close() {
169 bubble_->Close(); 237 bubble_->Close();
170 bubble_ = NULL;
171 if (inline_disposition_tab_contents_.get()) 238 if (inline_disposition_tab_contents_.get())
172 inline_disposition_tab_contents_->web_contents()->OnCloseStarted(); 239 inline_disposition_tab_contents_->web_contents()->OnCloseStarted();
173 } 240 }
174 241
175 void WebIntentPickerGtk::BubbleClosing(BubbleGtk* bubble, 242 void WebIntentPickerGtk::BubbleClosing(BubbleGtk* bubble,
176 bool closed_by_escape) { 243 bool closed_by_escape) {
177 delegate_->OnClosing(); 244 delegate_->OnClosing();
178 } 245 }
179 246
180 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) { 247 void WebIntentPickerGtk::OnCloseButtonClick(GtkWidget* button) {
181 delegate_->OnCancelled(); 248 delegate_->OnCancelled();
182 delegate_->OnClosing(); 249 delegate_->OnClosing();
183 } 250 }
184 251
252 void WebIntentPickerGtk::OnDestroy(GtkWidget* button) {
253 // Destroy this object when the BubbleGtk is destroyed. It can't be "delete
254 // this" because this function happens in a callback.
255 MessageLoop::current()->DeleteSoon(FROM_HERE, this);
256 model_->set_observer(NULL);
257 bubble_ = NULL;
258 }
259
185 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) { 260 void WebIntentPickerGtk::OnServiceButtonClick(GtkWidget* button) {
186 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); 261 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_));
187 gint index = g_list_index(button_list, button); 262 gint index = g_list_index(button_list, button);
188 DCHECK(index != -1); 263 DCHECK(index != -1);
189 264
190 delegate_->OnServiceChosen(static_cast<size_t>(index)); 265 const WebIntentPickerModel::Item& item = model_->GetItemAt(index);
266
267 delegate_->OnServiceChosen(static_cast<size_t>(index), item.disposition);
191 } 268 }
192 269
193 void WebIntentPickerGtk::InitContents() { 270 void WebIntentPickerGtk::InitContents() {
194 GtkThemeService* theme_service = GetThemeService(wrapper_); 271 GtkThemeService* theme_service = GetThemeService(wrapper_);
195 272
196 contents_ = gtk_hbox_new(FALSE, ui::kContentAreaSpacing); 273 contents_ = gtk_hbox_new(FALSE, ui::kContentAreaSpacing);
197 gtk_container_set_border_width(GTK_CONTAINER(contents_), 274 gtk_container_set_border_width(GTK_CONTAINER(contents_),
198 ui::kContentAreaBorder); 275 ui::kContentAreaBorder);
199 276
200 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
201 GdkPixbuf* image_pixbuf = rb.GetNativeImageNamed(IDR_PAGEINFO_INFO);
202 GtkWidget* image = gtk_image_new_from_pixbuf(image_pixbuf);
203 gtk_box_pack_start(GTK_BOX(contents_), image, FALSE, FALSE, 0);
204 gtk_misc_set_alignment(GTK_MISC(image), 0, 0);
205
206 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing); 277 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
207 278
208 GtkWidget* label = theme_service->BuildLabel( 279 GtkWidget* label = theme_service->BuildLabel(
209 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str(), 280 l10n_util::GetStringUTF8(IDS_CHOOSE_INTENT_HANDLER_MESSAGE).c_str(),
210 ui::kGdkBlack); 281 ui::kGdkBlack);
211 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); 282 gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0);
212 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); 283 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
213 284
214 gtk_widget_set_size_request(vbox, kMainContentWidth, -1); 285 gtk_widget_set_size_request(vbox, kMainContentWidth, -1);
215 286
216 button_hbox_ = gtk_hbox_new(FALSE, ui::kControlSpacing); 287 button_vbox_ = gtk_vbox_new(FALSE, ui::kControlSpacing);
217 gtk_box_pack_start(GTK_BOX(vbox), button_hbox_, TRUE, TRUE, 0); 288 gtk_box_pack_start(GTK_BOX(vbox), button_vbox_, TRUE, TRUE, 0);
218 289
219 GtkWidget* cws_label = theme_service->BuildLabel( 290 GtkWidget* cws_label = theme_service->BuildLabel(
220 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE).c_str(), 291 l10n_util::GetStringUTF8(IDS_FIND_MORE_INTENT_HANDLER_MESSAGE).c_str(),
221 ui::kGdkBlack); 292 ui::kGdkBlack);
222 gtk_box_pack_start(GTK_BOX(vbox), cws_label, TRUE, TRUE, 0); 293 gtk_box_pack_start(GTK_BOX(vbox), cws_label, TRUE, TRUE, 0);
223 gtk_misc_set_alignment(GTK_MISC(cws_label), 0, 0); 294 gtk_misc_set_alignment(GTK_MISC(cws_label), 0, 0);
224 gtk_util::SetLabelWidth(cws_label, kWebStoreLabelLength); 295 gtk_util::SetLabelWidth(cws_label, kWebStoreLabelLength);
225 gtk_util::ForceFontSizePixels(cws_label, kWebStoreLabelPixelSize); 296 gtk_util::ForceFontSizePixels(cws_label, kWebStoreLabelPixelSize);
226 297
227 gtk_box_pack_start(GTK_BOX(contents_), vbox, TRUE, TRUE, 0); 298 gtk_box_pack_start(GTK_BOX(contents_), vbox, TRUE, TRUE, 0);
228 299
229 close_button_.reset( 300 close_button_.reset(
230 CustomDrawButton::CloseButton(GetThemeService(wrapper_))); 301 CustomDrawButton::CloseButton(GetThemeService(wrapper_)));
231 g_signal_connect(close_button_->widget(), 302 g_signal_connect(close_button_->widget(),
232 "clicked", 303 "clicked",
233 G_CALLBACK(OnCloseButtonClickThunk), 304 G_CALLBACK(OnCloseButtonClickThunk),
234 this); 305 this);
235 gtk_widget_set_can_focus(close_button_->widget(), FALSE); 306 gtk_widget_set_can_focus(close_button_->widget(), FALSE);
236 307
237 GtkWidget* close_vbox = gtk_vbox_new(FALSE, 0); 308 GtkWidget* close_vbox = gtk_vbox_new(FALSE, 0);
238 gtk_box_pack_start(GTK_BOX(close_vbox), close_button_->widget(), FALSE, FALSE, 309 gtk_box_pack_start(GTK_BOX(close_vbox), close_button_->widget(), FALSE, FALSE,
239 0); 310 0);
240 gtk_box_pack_end(GTK_BOX(contents_), close_vbox, FALSE, FALSE, 0); 311 gtk_box_pack_end(GTK_BOX(contents_), close_vbox, FALSE, FALSE, 0);
241 } 312 g_signal_connect(contents_, "destroy", G_CALLBACK(&OnDestroyThunk), this);
242
243 void RemoveAllHelper(GtkWidget* widget, gpointer data) {
244 GtkWidget* parent = gtk_widget_get_parent(widget);
245 gtk_container_remove(GTK_CONTAINER(parent), widget);
246 }
247
248 WebContents* WebIntentPickerGtk::SetInlineDisposition(const GURL& url) {
249 WebContents* web_contents = WebContents::Create(
250 browser_->profile(), NULL, MSG_ROUTING_NONE, NULL, NULL);
251 inline_disposition_tab_contents_.reset(new TabContentsWrapper(web_contents));
252 inline_disposition_delegate_.reset(new InlineDispositionDelegate);
253 web_contents->SetDelegate(inline_disposition_delegate_.get());
254 tab_contents_container_.reset(new TabContentsContainerGtk(NULL));
255 tab_contents_container_->SetTab(inline_disposition_tab_contents_.get());
256
257 inline_disposition_tab_contents_->web_contents()->GetController().LoadURL(
258 url, content::Referrer(), content::PAGE_TRANSITION_START_PAGE,
259 std::string());
260
261 // Replace the bubble picker contents with the inline disposition.
262
263 gtk_container_foreach(GTK_CONTAINER(contents_), RemoveAllHelper, NULL);
264
265 GtkWidget* service_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing);
266 // TODO(gbillock): Eventually get the service icon button here.
267 // Maybe add a title or something too?
268 close_button_.reset(
269 CustomDrawButton::CloseButton(GetThemeService(wrapper_)));
270 g_signal_connect(close_button_->widget(),
271 "clicked",
272 G_CALLBACK(OnCloseButtonClickThunk),
273 this);
274 gtk_widget_set_can_focus(close_button_->widget(), FALSE);
275 GtkWidget* close_vbox = gtk_vbox_new(FALSE, 0);
276 gtk_box_pack_start(GTK_BOX(close_vbox), close_button_->widget(),
277 FALSE, FALSE, 0);
278 gtk_box_pack_end(GTK_BOX(service_hbox), close_vbox, FALSE, FALSE, 0);
279
280 GtkWidget* vbox = gtk_vbox_new(FALSE, ui::kContentAreaSpacing);
281 gtk_box_pack_start(GTK_BOX(vbox), service_hbox, TRUE, TRUE, 0);
282
283 // The separator between the icon/title/close and the inline renderer.
284 gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, TRUE, 0);
285
286 gtk_box_pack_end(GTK_BOX(vbox), tab_contents_container_->widget(),
287 TRUE, TRUE, 0);
288
289 gtk_container_add(GTK_CONTAINER(contents_), vbox);
290
291 // TODO(gbillock): This size calculation needs more thought.
292 // Move up to WebIntentPicker?
293 gfx::Size tab_size = wrapper_->web_contents()->GetView()->GetContainerSize();
294 int width = std::max(tab_size.width()/2, kMainContentWidth);
295 int height = std::max(tab_size.height()/2, kMainContentWidth);
296 gtk_widget_set_size_request(tab_contents_container_->widget(),
297 width, height);
298 gtk_widget_show_all(contents_);
299
300 return inline_disposition_tab_contents_->web_contents();
301 } 313 }
302 314
303 GtkWidget* WebIntentPickerGtk::GetServiceButton(size_t index) { 315 GtkWidget* WebIntentPickerGtk::GetServiceButton(size_t index) {
304 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_hbox_)); 316 GList* button_list = gtk_container_get_children(GTK_CONTAINER(button_vbox_));
305 GtkWidget* button = GTK_WIDGET(g_list_nth_data(button_list, index)); 317 GtkWidget* button = GTK_WIDGET(g_list_nth_data(button_list, index));
306 DCHECK(button != NULL); 318 DCHECK(button != NULL);
307 319
308 return button; 320 return button;
309 } 321 }
310 322
323 void WebIntentPickerGtk::RemoveAllFrom(GtkWidget* container) {
324 gtk_container_foreach(GTK_CONTAINER(container), RemoveAllHelper, NULL);
325 }
326
311 // WebIntentPickerGtk::InlineDispositionDelegate 327 // WebIntentPickerGtk::InlineDispositionDelegate
312 328
313 WebIntentPickerGtk::InlineDispositionDelegate::InlineDispositionDelegate() {} 329 WebIntentPickerGtk::InlineDispositionDelegate::InlineDispositionDelegate() {}
314 WebIntentPickerGtk::InlineDispositionDelegate::~InlineDispositionDelegate() {} 330 WebIntentPickerGtk::InlineDispositionDelegate::~InlineDispositionDelegate() {}
315 331
316
317 bool WebIntentPickerGtk::InlineDispositionDelegate::IsPopupOrPanel( 332 bool WebIntentPickerGtk::InlineDispositionDelegate::IsPopupOrPanel(
318 const WebContents* source) const { 333 const WebContents* source) const {
319 return true; 334 return true;
320 } 335 }
321 336
322 bool WebIntentPickerGtk::InlineDispositionDelegate:: 337 bool WebIntentPickerGtk::InlineDispositionDelegate::
323 ShouldAddNavigationToHistory( 338 ShouldAddNavigationToHistory(
324 const history::HistoryAddPageArgs& add_page_args, 339 const history::HistoryAddPageArgs& add_page_args,
325 content::NavigationType navigation_type) { 340 content::NavigationType navigation_type) {
326 return false; 341 return false;
327 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698