OLD | NEW |
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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 PANGO_SCALE * size_pixels); | 409 PANGO_SCALE * size_pixels); |
410 gtk_widget_modify_font(widget, font_desc); | 410 gtk_widget_modify_font(widget, font_desc); |
411 pango_font_description_free(font_desc); | 411 pango_font_description_free(font_desc); |
412 } | 412 } |
413 | 413 |
414 void UndoForceFontSize(GtkWidget* widget) { | 414 void UndoForceFontSize(GtkWidget* widget) { |
415 gtk_widget_modify_font(widget, NULL); | 415 gtk_widget_modify_font(widget, NULL); |
416 } | 416 } |
417 | 417 |
418 gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { | 418 gfx::Point GetWidgetScreenPosition(GtkWidget* widget) { |
419 if (!widget->window) { | 419 GdkWindow* window = gtk_widget_get_window(widget); |
| 420 |
| 421 if (!window) { |
420 NOTREACHED() << "Must only be called on realized widgets."; | 422 NOTREACHED() << "Must only be called on realized widgets."; |
421 return gfx::Point(0, 0); | 423 return gfx::Point(0, 0); |
422 } | 424 } |
423 | 425 |
424 gint x, y; | 426 gint x, y; |
425 gdk_window_get_origin(widget->window, &x, &y); | 427 gdk_window_get_origin(window, &x, &y); |
426 | 428 |
427 if (GTK_WIDGET_NO_WINDOW(widget)) { | 429 if (!gtk_widget_get_has_window(widget)) { |
428 x += widget->allocation.x; | 430 GtkAllocation allocation; |
429 y += widget->allocation.y; | 431 gtk_widget_get_allocation(widget, &allocation); |
| 432 x += allocation.x; |
| 433 y += allocation.y; |
430 } | 434 } |
431 | 435 |
432 return gfx::Point(x, y); | 436 return gfx::Point(x, y); |
433 } | 437 } |
434 | 438 |
435 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { | 439 gfx::Rect GetWidgetScreenBounds(GtkWidget* widget) { |
436 gfx::Point position = GetWidgetScreenPosition(widget); | 440 gfx::Point position = GetWidgetScreenPosition(widget); |
| 441 |
| 442 GtkAllocation allocation; |
| 443 gtk_widget_get_allocation(widget, &allocation); |
| 444 |
437 return gfx::Rect(position.x(), position.y(), | 445 return gfx::Rect(position.x(), position.y(), |
438 widget->allocation.width, widget->allocation.height); | 446 allocation.width, allocation.height); |
439 } | 447 } |
440 | 448 |
441 gfx::Size GetWidgetSize(GtkWidget* widget) { | 449 gfx::Size GetWidgetSize(GtkWidget* widget) { |
442 GtkRequisition size; | 450 GtkRequisition size; |
443 gtk_widget_size_request(widget, &size); | 451 gtk_widget_size_request(widget, &size); |
444 return gfx::Size(size.width, size.height); | 452 return gfx::Size(size.width, size.height); |
445 } | 453 } |
446 | 454 |
447 void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) { | 455 void ConvertWidgetPointToScreen(GtkWidget* widget, gfx::Point* p) { |
448 DCHECK(widget); | 456 DCHECK(widget); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 G_CALLBACK(OnMouseButtonReleased), userdata); | 508 G_CALLBACK(OnMouseButtonReleased), userdata); |
501 } | 509 } |
502 | 510 |
503 void SetButtonTriggersNavigation(GtkWidget* button) { | 511 void SetButtonTriggersNavigation(GtkWidget* button) { |
504 SetButtonClickableByMouseButtons(button, true, true, false); | 512 SetButtonClickableByMouseButtons(button, true, true, false); |
505 } | 513 } |
506 | 514 |
507 int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds) { | 515 int MirroredLeftPointForRect(GtkWidget* widget, const gfx::Rect& bounds) { |
508 if (!base::i18n::IsRTL()) | 516 if (!base::i18n::IsRTL()) |
509 return bounds.x(); | 517 return bounds.x(); |
510 return widget->allocation.width - bounds.x() - bounds.width(); | 518 |
| 519 GtkAllocation allocation; |
| 520 gtk_widget_get_allocation(widget, &allocation); |
| 521 return allocation.width - bounds.x() - bounds.width(); |
511 } | 522 } |
512 | 523 |
513 int MirroredRightPointForRect(GtkWidget* widget, const gfx::Rect& bounds) { | 524 int MirroredRightPointForRect(GtkWidget* widget, const gfx::Rect& bounds) { |
514 if (!base::i18n::IsRTL()) | 525 if (!base::i18n::IsRTL()) |
515 return bounds.right(); | 526 return bounds.right(); |
516 return widget->allocation.width - bounds.x(); | 527 |
| 528 GtkAllocation allocation; |
| 529 gtk_widget_get_allocation(widget, &allocation); |
| 530 return allocation.width - bounds.x(); |
517 } | 531 } |
518 | 532 |
519 int MirroredXCoordinate(GtkWidget* widget, int x) { | 533 int MirroredXCoordinate(GtkWidget* widget, int x) { |
520 if (base::i18n::IsRTL()) | 534 if (base::i18n::IsRTL()) { |
521 return widget->allocation.width - x; | 535 GtkAllocation allocation; |
| 536 gtk_widget_get_allocation(widget, &allocation); |
| 537 return allocation.width - x; |
| 538 } |
522 return x; | 539 return x; |
523 } | 540 } |
524 | 541 |
525 bool WidgetContainsCursor(GtkWidget* widget) { | 542 bool WidgetContainsCursor(GtkWidget* widget) { |
526 gint x = 0; | 543 gint x = 0; |
527 gint y = 0; | 544 gint y = 0; |
528 gtk_widget_get_pointer(widget, &x, &y); | 545 gtk_widget_get_pointer(widget, &x, &y); |
529 return WidgetBounds(widget).Contains(x, y); | 546 return WidgetBounds(widget).Contains(x, y); |
530 } | 547 } |
531 | 548 |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 826 |
810 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); | 827 GtkWidget* toplevel = gtk_widget_get_toplevel(widget); |
811 DCHECK(toplevel); | 828 DCHECK(toplevel); |
812 DCHECK(gtk_widget_get_realized(toplevel)); | 829 DCHECK(gtk_widget_get_realized(toplevel)); |
813 | 830 |
814 gint x = 0, y = 0; | 831 gint x = 0, y = 0; |
815 gtk_widget_translate_coordinates(widget, | 832 gtk_widget_translate_coordinates(widget, |
816 toplevel, | 833 toplevel, |
817 0, 0, | 834 0, 0, |
818 &x, &y); | 835 &x, &y); |
819 return gfx::Rect(x, y, widget->allocation.width, widget->allocation.height); | 836 |
| 837 GtkAllocation allocation; |
| 838 gtk_widget_get_allocation(widget, &allocation); |
| 839 return gfx::Rect(x, y, allocation.width, allocation.height); |
820 } | 840 } |
821 | 841 |
822 void SuppressDefaultPainting(GtkWidget* container) { | 842 void SuppressDefaultPainting(GtkWidget* container) { |
823 g_signal_connect(container, "expose-event", | 843 g_signal_connect(container, "expose-event", |
824 G_CALLBACK(PaintNoBackground), NULL); | 844 G_CALLBACK(PaintNoBackground), NULL); |
825 } | 845 } |
826 | 846 |
827 WindowOpenDisposition DispositionForCurrentButtonPressEvent() { | 847 WindowOpenDisposition DispositionForCurrentButtonPressEvent() { |
828 GdkEvent* event = gtk_get_current_event(); | 848 GdkEvent* event = gtk_get_current_event(); |
829 if (!event) { | 849 if (!event) { |
(...skipping 29 matching lines...) Expand all Loading... |
859 | 879 |
860 gtk_grab_add(widget); | 880 gtk_grab_add(widget); |
861 return true; | 881 return true; |
862 } | 882 } |
863 | 883 |
864 gfx::Rect WidgetBounds(GtkWidget* widget) { | 884 gfx::Rect WidgetBounds(GtkWidget* widget) { |
865 // To quote the gtk docs: | 885 // To quote the gtk docs: |
866 // | 886 // |
867 // Widget coordinates are a bit odd; for historical reasons, they are | 887 // Widget coordinates are a bit odd; for historical reasons, they are |
868 // defined as widget->window coordinates for widgets that are not | 888 // defined as widget->window coordinates for widgets that are not |
869 // GTK_NO_WINDOW widgets, and are relative to widget->allocation.x, | 889 // GTK_NO_WINDOW widgets, and are relative to allocation.x, allocation.y |
870 // widget->allocation.y for widgets that are GTK_NO_WINDOW widgets. | 890 // for widgets that are GTK_NO_WINDOW widgets. |
871 // | 891 // |
872 // So the base is always (0,0). | 892 // So the base is always (0,0). |
873 return gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height); | 893 GtkAllocation allocation; |
| 894 gtk_widget_get_allocation(widget, &allocation); |
| 895 return gfx::Rect(0, 0, allocation.width, allocation.height); |
874 } | 896 } |
875 | 897 |
876 void SetWMLastUserActionTime(GtkWindow* window) { | 898 void SetWMLastUserActionTime(GtkWindow* window) { |
877 gdk_x11_window_set_user_time(gtk_widget_get_window(GTK_WIDGET(window)), | 899 gdk_x11_window_set_user_time(gtk_widget_get_window(GTK_WIDGET(window)), |
878 XTimeNow()); | 900 XTimeNow()); |
879 } | 901 } |
880 | 902 |
881 guint32 XTimeNow() { | 903 guint32 XTimeNow() { |
882 struct timespec ts; | 904 struct timespec ts; |
883 clock_gettime(CLOCK_MONOTONIC, &ts); | 905 clock_gettime(CLOCK_MONOTONIC, &ts); |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 | 1188 |
1167 void DoCopy(BrowserWindow* window) { | 1189 void DoCopy(BrowserWindow* window) { |
1168 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); | 1190 DoCutCopyPaste(window, &RenderViewHost::Copy, "copy-clipboard"); |
1169 } | 1191 } |
1170 | 1192 |
1171 void DoPaste(BrowserWindow* window) { | 1193 void DoPaste(BrowserWindow* window) { |
1172 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); | 1194 DoCutCopyPaste(window, &RenderViewHost::Paste, "paste-clipboard"); |
1173 } | 1195 } |
1174 | 1196 |
1175 } // namespace gtk_util | 1197 } // namespace gtk_util |
OLD | NEW |