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

Side by Side Diff: content/shell/shell_gtk.cc

Issue 14496004: Gtk content shell: make the window shrinkable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address issue raised by jochen: nit. please spell out "elms" Created 7 years, 7 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
« no previous file with comments | « content/shell/shell.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/shell/shell.h" 5 #include "content/shell/shell.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (headless_) 94 if (headless_)
95 return; 95 return;
96 96
97 if (loading) 97 if (loading)
98 gtk_spinner_start(GTK_SPINNER(spinner_)); 98 gtk_spinner_start(GTK_SPINNER(spinner_));
99 else 99 else
100 gtk_spinner_stop(GTK_SPINNER(spinner_)); 100 gtk_spinner_stop(GTK_SPINNER(spinner_));
101 } 101 }
102 102
103 void Shell::PlatformCreateWindow(int width, int height) { 103 void Shell::PlatformCreateWindow(int width, int height) {
104 SizeTo(width, height); 104 ui_elements_height_ = 0;
105 105 if (headless_) {
106 if (headless_) 106 SizeTo(width, height);
107 return; 107 return;
108 }
108 109
109 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); 110 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
110 gtk_window_set_title(window_, "Content Shell"); 111 gtk_window_set_title(window_, "Content Shell");
111 g_signal_connect(G_OBJECT(window_), "destroy", 112 g_signal_connect(G_OBJECT(window_), "destroy",
112 G_CALLBACK(OnWindowDestroyedThunk), this); 113 G_CALLBACK(OnWindowDestroyedThunk), this);
113 114
114 vbox_ = gtk_vbox_new(FALSE, 0); 115 vbox_ = gtk_vbox_new(FALSE, 0);
115 116
116 // Create the menu bar. 117 // Create the menu bar.
117 GtkWidget* menu_bar = CreateMenuBar(this); 118 GtkWidget* menu_bar = CreateMenuBar(this);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 gtk_widget_set_size_request(spinner_, 20, 20); 195 gtk_widget_set_size_request(spinner_, 20, 20);
195 gtk_container_add(GTK_CONTAINER(spinner_alignment), spinner_); 196 gtk_container_add(GTK_CONTAINER(spinner_alignment), spinner_);
196 197
197 spinner_item_ = gtk_tool_item_new(); 198 spinner_item_ = gtk_tool_item_new();
198 gtk_container_add(GTK_CONTAINER(spinner_item_), spinner_alignment); 199 gtk_container_add(GTK_CONTAINER(spinner_item_), spinner_alignment);
199 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), spinner_item_, -1 /* append */); 200 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), spinner_item_, -1 /* append */);
200 201
201 gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0); 202 gtk_box_pack_start(GTK_BOX(vbox_), toolbar, FALSE, FALSE, 0);
202 203
203 gtk_container_add(GTK_CONTAINER(window_), vbox_); 204 gtk_container_add(GTK_CONTAINER(window_), vbox_);
205
206 // Trigger layout of the UI elements, so that we can measure their
207 // heights. The width and height passed to this method are meant for the web
208 // contents view, not the top-level window. Since Gtk only seems to provide a
209 // suitable resizing function for top-level windows, we need to know how to
210 // convert from web contents view size to top-level window size.
211 gtk_widget_show_all(GTK_WIDGET(vbox_));
212
213 // Measure the heights of the UI elements, now that they have been laid out.
214 GtkRequisition elm_size;
215 gtk_widget_size_request(menu_bar, &elm_size);
216 ui_elements_height_ += elm_size.height;
217 gtk_widget_size_request(toolbar, &elm_size);
218 ui_elements_height_ += elm_size.height;
219
220 // We're ready to set an initial window size.
221 SizeTo(width, height);
222
223 // Finally, show the window.
204 gtk_widget_show_all(GTK_WIDGET(window_)); 224 gtk_widget_show_all(GTK_WIDGET(window_));
205 } 225 }
206 226
207 void Shell::PlatformSetContents() { 227 void Shell::PlatformSetContents() {
208 if (headless_) 228 if (headless_)
209 return; 229 return;
210 230
211 WebContentsView* content_view = web_contents_->GetView(); 231 WebContentsView* content_view = web_contents_->GetView();
212 gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView()); 232 gtk_container_add(GTK_CONTAINER(vbox_), content_view->GetNativeView());
213 } 233 }
214 234
215 void Shell::SizeTo(int width, int height) { 235 void Shell::SizeTo(int width, int height) {
216 content_width_ = width; 236 content_width_ = width;
217 content_height_ = height; 237 content_height_ = height;
218 if (web_contents_) { 238
239 // Prefer setting the top level window's size (if we have one), rather than
240 // setting the inner widget's minimum size (so that the user can shrink the
241 // window if she wants).
242 if (window_) {
243 gtk_window_resize(window_, width, height + ui_elements_height_);
244 } else if (web_contents_) {
219 gtk_widget_set_size_request(web_contents_->GetView()->GetNativeView(), 245 gtk_widget_set_size_request(web_contents_->GetView()->GetNativeView(),
220 width, height); 246 width, height);
221 } 247 }
222 } 248 }
223 249
224 void Shell::PlatformResizeSubViews() { 250 void Shell::PlatformResizeSubViews() {
225 SizeTo(content_width_, content_height_); 251 SizeTo(content_width_, content_height_);
226 } 252 }
227 253
228 void Shell::Close() { 254 void Shell::Close() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 330
305 void Shell::PlatformSetTitle(const string16& title) { 331 void Shell::PlatformSetTitle(const string16& title) {
306 if (headless_) 332 if (headless_)
307 return; 333 return;
308 334
309 std::string title_utf8 = UTF16ToUTF8(title); 335 std::string title_utf8 = UTF16ToUTF8(title);
310 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str()); 336 gtk_window_set_title(GTK_WINDOW(window_), title_utf8.c_str());
311 } 337 }
312 338
313 } // namespace content 339 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/shell.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698