| 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/menu_gtk.h" | 5 #include "chrome/browser/ui/gtk/menu_gtk.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonImage), button); | 89 g_signal_connect(menu, "show", G_CALLBACK(OnSubmenuShowButtonImage), button); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Popup menus may get squished if they open up too close to the bottom of the | 92 // Popup menus may get squished if they open up too close to the bottom of the |
| 93 // screen. This function takes the size of the screen, the size of the menu, | 93 // screen. This function takes the size of the screen, the size of the menu, |
| 94 // an optional widget, the Y position of the mouse click, and adjusts the popup | 94 // an optional widget, the Y position of the mouse click, and adjusts the popup |
| 95 // menu's Y position to make it fit if it's possible to do so. | 95 // menu's Y position to make it fit if it's possible to do so. |
| 96 // Returns the new Y position of the popup menu. | 96 // Returns the new Y position of the popup menu. |
| 97 int CalculateMenuYPosition(const GdkRectangle* screen_rect, | 97 int CalculateMenuYPosition(const GdkRectangle* screen_rect, |
| 98 const GtkRequisition* menu_req, | 98 const GtkRequisition* menu_req, |
| 99 const GtkWidget* widget, const int y) { | 99 GtkWidget* widget, const int y) { |
| 100 CHECK(screen_rect); | 100 CHECK(screen_rect); |
| 101 CHECK(menu_req); | 101 CHECK(menu_req); |
| 102 // If the menu would run off the bottom of the screen, and there is enough | 102 // If the menu would run off the bottom of the screen, and there is enough |
| 103 // screen space upwards to accommodate the menu, then pop upwards. If there | 103 // screen space upwards to accommodate the menu, then pop upwards. If there |
| 104 // is a widget, then also move the anchor point to the top of the widget | 104 // is a widget, then also move the anchor point to the top of the widget |
| 105 // rather than the bottom. | 105 // rather than the bottom. |
| 106 const int screen_top = screen_rect->y; | 106 const int screen_top = screen_rect->y; |
| 107 const int screen_bottom = screen_rect->y + screen_rect->height; | 107 const int screen_bottom = screen_rect->y + screen_rect->height; |
| 108 const int menu_bottom = y + menu_req->height; | 108 const int menu_bottom = y + menu_req->height; |
| 109 int alternate_y = y - menu_req->height; | 109 int alternate_y = y - menu_req->height; |
| 110 if (widget) | 110 if (widget) { |
| 111 alternate_y -= widget->allocation.height; | 111 GtkAllocation allocation; |
| 112 gtk_widget_get_allocation(widget, &allocation); |
| 113 alternate_y -= allocation.height; |
| 114 } |
| 112 if (menu_bottom >= screen_bottom && alternate_y >= screen_top) | 115 if (menu_bottom >= screen_bottom && alternate_y >= screen_top) |
| 113 return alternate_y; | 116 return alternate_y; |
| 114 return y; | 117 return y; |
| 115 } | 118 } |
| 116 | 119 |
| 117 } // namespace | 120 } // namespace |
| 118 | 121 |
| 119 GtkWidget* MenuGtk::Delegate::GetDefaultImageForCommandId(int command_id) { | 122 GtkWidget* MenuGtk::Delegate::GetDefaultImageForCommandId(int command_id) { |
| 120 const char* stock; | 123 const char* stock; |
| 121 switch (command_id) { | 124 switch (command_id) { |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 gtk_widget_size_request(GTK_WIDGET(menu), &menu_req); | 691 gtk_widget_size_request(GTK_WIDGET(menu), &menu_req); |
| 689 | 692 |
| 690 gdk_window_get_origin(widget->window, x, y); | 693 gdk_window_get_origin(widget->window, x, y); |
| 691 GdkScreen *screen = gtk_widget_get_screen(widget); | 694 GdkScreen *screen = gtk_widget_get_screen(widget); |
| 692 gint monitor = gdk_screen_get_monitor_at_point(screen, *x, *y); | 695 gint monitor = gdk_screen_get_monitor_at_point(screen, *x, *y); |
| 693 | 696 |
| 694 GdkRectangle screen_rect; | 697 GdkRectangle screen_rect; |
| 695 gdk_screen_get_monitor_geometry(screen, monitor, | 698 gdk_screen_get_monitor_geometry(screen, monitor, |
| 696 &screen_rect); | 699 &screen_rect); |
| 697 | 700 |
| 698 if (GTK_WIDGET_NO_WINDOW(widget)) { | 701 GtkAllocation allocation; |
| 699 *x += widget->allocation.x; | 702 gtk_widget_get_allocation(widget, &allocation); |
| 700 *y += widget->allocation.y; | 703 |
| 704 if (!gtk_widget_get_has_window(widget)) { |
| 705 *x += allocation.x; |
| 706 *y += allocation.y; |
| 701 } | 707 } |
| 702 *y += widget->allocation.height; | 708 *y += allocation.height; |
| 703 | 709 |
| 704 bool start_align = | 710 bool start_align = |
| 705 !!g_object_get_data(G_OBJECT(widget), "left-align-popup"); | 711 !!g_object_get_data(G_OBJECT(widget), "left-align-popup"); |
| 706 if (base::i18n::IsRTL()) | 712 if (base::i18n::IsRTL()) |
| 707 start_align = !start_align; | 713 start_align = !start_align; |
| 708 | 714 |
| 709 if (!start_align) | 715 if (!start_align) |
| 710 *x += widget->allocation.width - menu_req.width; | 716 *x += allocation.width - menu_req.width; |
| 711 | 717 |
| 712 *y = CalculateMenuYPosition(&screen_rect, &menu_req, widget, *y); | 718 *y = CalculateMenuYPosition(&screen_rect, &menu_req, widget, *y); |
| 713 | 719 |
| 714 *push_in = FALSE; | 720 *push_in = FALSE; |
| 715 } | 721 } |
| 716 | 722 |
| 717 // static | 723 // static |
| 718 void MenuGtk::PointMenuPositionFunc(GtkMenu* menu, | 724 void MenuGtk::PointMenuPositionFunc(GtkMenu* menu, |
| 719 int* x, | 725 int* x, |
| 720 int* y, | 726 int* y, |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 gtk_widget_hide(widget); | 912 gtk_widget_hide(widget); |
| 907 } | 913 } |
| 908 | 914 |
| 909 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 915 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
| 910 if (submenu) { | 916 if (submenu) { |
| 911 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 917 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
| 912 userdata); | 918 userdata); |
| 913 } | 919 } |
| 914 } | 920 } |
| 915 } | 921 } |
| OLD | NEW |