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

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view_gtk.cc

Issue 507022: Fix issue 11258: Linux: gracefully handle small browser window... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years 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
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/chrome_browser.gypi » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/tab_contents/tab_contents_view_gtk.h" 5 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
6 6
7 #include <gdk/gdk.h> 7 #include <gdk/gdk.h>
8 #include <gdk/gdkkeysyms.h> 8 #include <gdk/gdkkeysyms.h>
9 #include <gtk/gtk.h> 9 #include <gtk/gtk.h>
10 10
11 #include "app/gtk_dnd_util.h" 11 #include "app/gtk_dnd_util.h"
12 #include "base/gfx/point.h" 12 #include "base/gfx/point.h"
13 #include "base/gfx/rect.h" 13 #include "base/gfx/rect.h"
14 #include "base/gfx/size.h" 14 #include "base/gfx/size.h"
15 #include "base/pickle.h" 15 #include "base/pickle.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "chrome/browser/download/download_shelf.h" 18 #include "chrome/browser/download/download_shelf.h"
19 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" 19 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h"
20 #include "chrome/browser/gtk/browser_window_gtk.h" 20 #include "chrome/browser/gtk/browser_window_gtk.h"
21 #include "chrome/browser/gtk/constrained_window_gtk.h" 21 #include "chrome/browser/gtk/constrained_window_gtk.h"
22 #include "chrome/browser/gtk/gtk_expanded_container.h"
22 #include "chrome/browser/gtk/gtk_floating_container.h" 23 #include "chrome/browser/gtk/gtk_floating_container.h"
23 #include "chrome/browser/gtk/gtk_theme_provider.h" 24 #include "chrome/browser/gtk/gtk_theme_provider.h"
24 #include "chrome/browser/gtk/sad_tab_gtk.h" 25 #include "chrome/browser/gtk/sad_tab_gtk.h"
25 #include "chrome/browser/gtk/tab_contents_drag_source.h" 26 #include "chrome/browser/gtk/tab_contents_drag_source.h"
26 #include "chrome/browser/renderer_host/render_view_host.h" 27 #include "chrome/browser/renderer_host/render_view_host.h"
27 #include "chrome/browser/renderer_host/render_view_host_factory.h" 28 #include "chrome/browser/renderer_host/render_view_host_factory.h"
28 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" 29 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
29 #include "chrome/browser/tab_contents/interstitial_page.h" 30 #include "chrome/browser/tab_contents/interstitial_page.h"
30 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h" 31 #include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
31 #include "chrome/browser/tab_contents/tab_contents.h" 32 #include "chrome/browser/tab_contents/tab_contents.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return TRUE; 94 return TRUE;
94 } else if (event->direction == GDK_SCROLL_UP) { 95 } else if (event->direction == GDK_SCROLL_UP) {
95 tab_contents->delegate()->ContentsZoomChange(true); 96 tab_contents->delegate()->ContentsZoomChange(true);
96 return TRUE; 97 return TRUE;
97 } 98 }
98 } 99 }
99 100
100 return FALSE; 101 return FALSE;
101 } 102 }
102 103
103 // Used with gtk_container_foreach to change the sizes of the children of
104 // |fixed_|.
105 void SetSizeRequest(GtkWidget* widget, gpointer userdata) {
106 gfx::Size* size = static_cast<gfx::Size*>(userdata);
107 if (widget->allocation.width != size->width() ||
108 widget->allocation.height != size->height()) {
109 gtk_widget_set_size_request(widget, size->width(), size->height());
110 }
111 }
112
113 } // namespace 104 } // namespace
114 105
115 // static 106 // static
116 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 107 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
117 return new TabContentsViewGtk(tab_contents); 108 return new TabContentsViewGtk(tab_contents);
118 } 109 }
119 110
120 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) 111 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
121 : TabContentsView(tab_contents), 112 : TabContentsView(tab_contents),
122 floating_(gtk_floating_container_new()), 113 floating_(gtk_floating_container_new()),
123 fixed_(gtk_fixed_new()), 114 expanded_(gtk_expanded_container_new()),
124 popup_view_(NULL) { 115 popup_view_(NULL) {
125 gtk_widget_set_name(fixed_, "chrome-tab-contents-view"); 116 gtk_widget_set_name(expanded_, "chrome-tab-contents-view");
126 g_signal_connect(fixed_, "size-allocate", 117 g_signal_connect(expanded_, "size-allocate",
127 G_CALLBACK(OnSizeAllocate), this); 118 G_CALLBACK(OnSizeAllocate), this);
119 g_signal_connect(expanded_, "child-size-request",
120 G_CALLBACK(OnChildSizeRequest), this);
128 g_signal_connect(floating_.get(), "set-floating-position", 121 g_signal_connect(floating_.get(), "set-floating-position",
129 G_CALLBACK(OnSetFloatingPosition), this); 122 G_CALLBACK(OnSetFloatingPosition), this);
130 123
131 gtk_container_add(GTK_CONTAINER(floating_.get()), fixed_); 124 gtk_container_add(GTK_CONTAINER(floating_.get()), expanded_);
132 gtk_widget_show(fixed_); 125 gtk_widget_show(expanded_);
133 gtk_widget_show(floating_.get()); 126 gtk_widget_show(floating_.get());
134 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, 127 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
135 Source<TabContents>(tab_contents)); 128 Source<TabContents>(tab_contents));
136 drag_source_.reset(new TabContentsDragSource(this)); 129 drag_source_.reset(new TabContentsDragSource(this));
137 } 130 }
138 131
139 TabContentsViewGtk::~TabContentsViewGtk() { 132 TabContentsViewGtk::~TabContentsViewGtk() {
140 floating_.Destroy(); 133 floating_.Destroy();
141 } 134 }
142 135
(...skipping 29 matching lines...) Expand all
172 constrained_window); 165 constrained_window);
173 DCHECK(item != constrained_windows_.end()); 166 DCHECK(item != constrained_windows_.end());
174 167
175 gtk_container_remove(GTK_CONTAINER(floating_.get()), 168 gtk_container_remove(GTK_CONTAINER(floating_.get()),
176 constrained_window->widget()); 169 constrained_window->widget());
177 constrained_windows_.erase(item); 170 constrained_windows_.erase(item);
178 } 171 }
179 172
180 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) { 173 void TabContentsViewGtk::CreateView(const gfx::Size& initial_size) {
181 requested_size_ = initial_size; 174 requested_size_ = initial_size;
182 gtk_widget_set_size_request(fixed_, requested_size_.width(),
183 requested_size_.height());
184 } 175 }
185 176
186 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget( 177 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget(
187 RenderWidgetHost* render_widget_host) { 178 RenderWidgetHost* render_widget_host) {
188 if (render_widget_host->view()) { 179 if (render_widget_host->view()) {
189 // During testing, the view will already be set up in most cases to the 180 // During testing, the view will already be set up in most cases to the
190 // test view, so we don't want to clobber it with a real one. To verify that 181 // test view, so we don't want to clobber it with a real one. To verify that
191 // this actually is happening (and somebody isn't accidentally creating the 182 // this actually is happening (and somebody isn't accidentally creating the
192 // view twice), we check for the RVH Factory, which will be set when we're 183 // view twice), we check for the RVH Factory, which will be set when we're
193 // making special ones (which go along with the special views). 184 // making special ones (which go along with the special views).
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 return window ? GTK_WINDOW(window) : NULL; 225 return window ? GTK_WINDOW(window) : NULL;
235 } 226 }
236 227
237 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { 228 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const {
238 // This is used for positioning the download shelf arrow animation, 229 // This is used for positioning the download shelf arrow animation,
239 // as well as sizing some other widgets in Windows. In GTK the size is 230 // as well as sizing some other widgets in Windows. In GTK the size is
240 // managed for us, so it appears to be only used for the download shelf 231 // managed for us, so it appears to be only used for the download shelf
241 // animation. 232 // animation.
242 int x = 0; 233 int x = 0;
243 int y = 0; 234 int y = 0;
244 if (fixed_->window) 235 if (expanded_->window)
245 gdk_window_get_origin(fixed_->window, &x, &y); 236 gdk_window_get_origin(expanded_->window, &x, &y);
246 out->SetRect(x + fixed_->allocation.x, y + fixed_->allocation.y, 237 out->SetRect(x + expanded_->allocation.x, y + expanded_->allocation.y,
247 requested_size_.width(), requested_size_.height()); 238 requested_size_.width(), requested_size_.height());
248 } 239 }
249 240
250 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) { 241 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) {
251 // Set the window name to include the page title so it's easier to spot 242 // Set the window name to include the page title so it's easier to spot
252 // when debugging (e.g. via xwininfo -tree). 243 // when debugging (e.g. via xwininfo -tree).
253 gfx::NativeView content_view = GetContentNativeView(); 244 gfx::NativeView content_view = GetContentNativeView();
254 if (content_view && content_view->window) 245 if (content_view && content_view->window)
255 gdk_window_set_title(content_view->window, WideToUTF8(title).c_str()); 246 gdk_window_set_title(content_view->window, WideToUTF8(title).c_str());
256 } 247 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 WebDragOperationsMask ops) { 344 WebDragOperationsMask ops) {
354 DCHECK(GetContentNativeView()); 345 DCHECK(GetContentNativeView());
355 346
356 drag_source_->StartDragging(drop_data, &last_mouse_down_); 347 drag_source_->StartDragging(drop_data, &last_mouse_down_);
357 // TODO(snej): Make use of the WebDragOperationsMask somehow 348 // TODO(snej): Make use of the WebDragOperationsMask somehow
358 } 349 }
359 350
360 // ----------------------------------------------------------------------------- 351 // -----------------------------------------------------------------------------
361 352
362 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) { 353 void TabContentsViewGtk::InsertIntoContentArea(GtkWidget* widget) {
363 gtk_fixed_put(GTK_FIXED(fixed_), widget, 0, 0); 354 gtk_container_add(GTK_CONTAINER(expanded_), widget);
364 } 355 }
365 356
366 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget, 357 gboolean TabContentsViewGtk::OnMouseDown(GtkWidget* widget,
367 GdkEventButton* event, TabContentsViewGtk* view) { 358 GdkEventButton* event, TabContentsViewGtk* view) {
368 view->last_mouse_down_ = *event; 359 view->last_mouse_down_ = *event;
369 return FALSE; 360 return FALSE;
370 } 361 }
371 362
372 gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, 363 void TabContentsViewGtk::OnChildSizeRequest(GtkWidget* widget,
373 GtkAllocation* allocation, 364 GtkWidget* child,
365 GtkRequisition* requisition,
374 TabContentsViewGtk* view) { 366 TabContentsViewGtk* view) {
367 if (view->tab_contents()->delegate()) {
368 requisition->height +=
369 view->tab_contents()->delegate()->GetExtraRenderViewHeight();
370 }
371 }
372
373 void TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget,
374 GtkAllocation* allocation,
375 TabContentsViewGtk* view) {
375 int width = allocation->width; 376 int width = allocation->width;
376 int height = allocation->height; 377 int height = allocation->height;
377 // |delegate()| can be NULL here during browser teardown. 378 // |delegate()| can be NULL here during browser teardown.
378 if (view->tab_contents()->delegate()) 379 if (view->tab_contents()->delegate())
379 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); 380 height += view->tab_contents()->delegate()->GetExtraRenderViewHeight();
380 gfx::Size size(width, height); 381 gfx::Size size(width, height);
381 view->requested_size_ = size; 382 view->requested_size_ = size;
382 gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size);
383 383
384 // We manually tell our RWHV to resize the renderer content. This avoids 384 // We manually tell our RWHV to resize the renderer content. This avoids
385 // spurious resizes from GTK+. 385 // spurious resizes from GTK+.
386 if (view->tab_contents()->render_widget_host_view()) 386 if (view->tab_contents()->render_widget_host_view())
387 view->tab_contents()->render_widget_host_view()->SetSize(size); 387 view->tab_contents()->render_widget_host_view()->SetSize(size);
388 if (view->tab_contents()->interstitial_page()) 388 if (view->tab_contents()->interstitial_page())
389 view->tab_contents()->interstitial_page()->SetSize(size); 389 view->tab_contents()->interstitial_page()->SetSize(size);
390
391 return FALSE;
392 } 390 }
393 391
394 // static 392 // static
395 void TabContentsViewGtk::OnSetFloatingPosition( 393 void TabContentsViewGtk::OnSetFloatingPosition(
396 GtkFloatingContainer* floating_container, GtkAllocation* allocation, 394 GtkFloatingContainer* floating_container, GtkAllocation* allocation,
397 TabContentsViewGtk* tab_contents_view) { 395 TabContentsViewGtk* tab_contents_view) {
398 if (tab_contents_view->popup_view_) { 396 if (tab_contents_view->popup_view_) {
399 GtkWidget* widget = tab_contents_view->popup_view_->widget(); 397 GtkWidget* widget = tab_contents_view->popup_view_->widget();
400 398
401 // Look at the size request of the status bubble and tell the 399 // Look at the size request of the status bubble and tell the
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 441 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
444 widget, "x", &value); 442 widget, "x", &value);
445 443
446 int child_y = std::max(half_view_height - (requisition.height / 2), 0); 444 int child_y = std::max(half_view_height - (requisition.height / 2), 0);
447 g_value_set_int(&value, child_y); 445 g_value_set_int(&value, child_y);
448 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 446 gtk_container_child_set_property(GTK_CONTAINER(floating_container),
449 widget, "y", &value); 447 widget, "y", &value);
450 g_value_unset(&value); 448 g_value_unset(&value);
451 } 449 }
452 } 450 }
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_gtk.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698