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

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

Issue 8890027: GTK: Remove most calls to widget->window and replace with accessor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 9 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
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.h ('k') | chrome/browser/ui/panels/panel_browser_window_gtk.cc » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/gtk_util.h" 5 #include "chrome/browser/ui/gtk/gtk_util.h"
6 6
7 #include <cairo/cairo.h> 7 #include <cairo/cairo.h>
8 8
9 #include <cstdarg> 9 #include <cstdarg>
10 10
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 GtkRequisition requisition; 339 GtkRequisition requisition;
340 gtk_widget_size_request(GTK_WIDGET(window), &requisition); 340 gtk_widget_size_request(GTK_WIDGET(window), &requisition);
341 gtk_widget_set_size_request( 341 gtk_widget_set_size_request(
342 GTK_WIDGET(window), 342 GTK_WIDGET(window),
343 width == -1 ? -1 : std::max(width, requisition.width), 343 width == -1 ? -1 : std::max(width, requisition.width),
344 height == -1 ? -1 : std::max(height, requisition.height)); 344 height == -1 ? -1 : std::max(height, requisition.height));
345 } 345 }
346 gtk_window_set_resizable(window, resizable ? TRUE : FALSE); 346 gtk_window_set_resizable(window, resizable ? TRUE : FALSE);
347 } 347 }
348 348
349 void CenterOverWindow(GtkWindow* window, GtkWindow* parent) {
Elliot Glaysher 2011/12/08 19:24:54 Function is never used. Instead of porting the Gdk
350 gfx::Rect frame_bounds = gtk_util::GetWidgetScreenBounds(GTK_WIDGET(parent));
351 gfx::Point origin = frame_bounds.origin();
352 gfx::Size size = gtk_util::GetWidgetSize(GTK_WIDGET(window));
353 origin.Offset(
354 (frame_bounds.width() - size.width()) / 2,
355 (frame_bounds.height() - size.height()) / 2);
356
357 // Prevent moving window out of monitor bounds.
358 GdkScreen* screen = gtk_window_get_screen(parent);
359 if (screen) {
360 // It would be better to check against workarea for given monitor
361 // but getting workarea for particular monitor is tricky.
362 gint monitor = gdk_screen_get_monitor_at_window(screen,
363 GTK_WIDGET(parent)->window);
364 GdkRectangle rect;
365 gdk_screen_get_monitor_geometry(screen, monitor, &rect);
366
367 // Check the right bottom corner.
368 if (origin.x() > rect.x + rect.width - size.width())
369 origin.set_x(rect.x + rect.width - size.width());
370 if (origin.y() > rect.y + rect.height - size.height())
371 origin.set_y(rect.y + rect.height - size.height());
372
373 // Check the left top corner.
374 if (origin.x() < rect.x)
375 origin.set_x(rect.x);
376 if (origin.y() < rect.y)
377 origin.set_y(rect.y);
378 }
379
380 gtk_window_move(window, origin.x(), origin.y());
381
382 // Move to user expected desktop if window is already visible.
383 if (GTK_WIDGET(window)->window) {
384 ui::ChangeWindowDesktop(
385 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window)),
386 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(parent)));
387 }
388 }
389
390 void MakeAppModalWindowGroup() { 349 void MakeAppModalWindowGroup() {
391 // Older versions of GTK+ don't give us gtk_window_group_list() which is what 350 // Older versions of GTK+ don't give us gtk_window_group_list() which is what
392 // we need to add current non-browser modal dialogs to the list. If 351 // we need to add current non-browser modal dialogs to the list. If
393 // we have 2.14+ we can do things the correct way. 352 // we have 2.14+ we can do things the correct way.
394 GtkWindowGroup* window_group = gtk_window_group_new(); 353 GtkWindowGroup* window_group = gtk_window_group_new();
395 for (BrowserList::const_iterator it = BrowserList::begin(); 354 for (BrowserList::const_iterator it = BrowserList::begin();
396 it != BrowserList::end(); ++it) { 355 it != BrowserList::end(); ++it) {
397 // List all windows in this current group 356 // List all windows in this current group
398 GtkWindowGroup* old_group = 357 GtkWindowGroup* old_group =
399 gtk_window_get_group((*it)->window()->GetNativeHandle()); 358 gtk_window_get_group((*it)->window()->GetNativeHandle());
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 // Widget coordinates are a bit odd; for historical reasons, they are 866 // Widget coordinates are a bit odd; for historical reasons, they are
908 // defined as widget->window coordinates for widgets that are not 867 // defined as widget->window coordinates for widgets that are not
909 // GTK_NO_WINDOW widgets, and are relative to widget->allocation.x, 868 // GTK_NO_WINDOW widgets, and are relative to widget->allocation.x,
910 // widget->allocation.y for widgets that are GTK_NO_WINDOW widgets. 869 // widget->allocation.y for widgets that are GTK_NO_WINDOW widgets.
911 // 870 //
912 // So the base is always (0,0). 871 // So the base is always (0,0).
913 return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height); 872 return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height);
914 } 873 }
915 874
916 void SetWMLastUserActionTime(GtkWindow* window) { 875 void SetWMLastUserActionTime(GtkWindow* window) {
917 gdk_x11_window_set_user_time(GTK_WIDGET(window)->window, XTimeNow()); 876 gdk_x11_window_set_user_time(gtk_widget_get_window(GTK_WIDGET(window)),
877 XTimeNow());
918 } 878 }
919 879
920 guint32 XTimeNow() { 880 guint32 XTimeNow() {
921 struct timespec ts; 881 struct timespec ts;
922 clock_gettime(CLOCK_MONOTONIC, &ts); 882 clock_gettime(CLOCK_MONOTONIC, &ts);
923 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000; 883 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
924 } 884 }
925 885
926 bool URLFromPrimarySelection(Profile* profile, GURL* url) { 886 bool URLFromPrimarySelection(Profile* profile, GURL* url) {
927 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY); 887 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 1165
1206 void DoCopy(BrowserWindow* window) { 1166 void DoCopy(BrowserWindow* window) {
1207 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); 1167 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard");
1208 } 1168 }
1209 1169
1210 void DoPaste(BrowserWindow* window) { 1170 void DoPaste(BrowserWindow* window) {
1211 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); 1171 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard");
1212 } 1172 }
1213 1173
1214 } // namespace gtk_util 1174 } // namespace gtk_util
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/gtk_util.h ('k') | chrome/browser/ui/panels/panel_browser_window_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698