| 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/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 } | 576 } |
| 577 | 577 |
| 578 void BrowserActionsToolbarGtk::HidePopup() { | 578 void BrowserActionsToolbarGtk::HidePopup() { |
| 579 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); | 579 ExtensionPopupGtk* popup = ExtensionPopupGtk::get_current_extension_popup(); |
| 580 if (popup) | 580 if (popup) |
| 581 popup->DestroyPopup(); | 581 popup->DestroyPopup(); |
| 582 } | 582 } |
| 583 | 583 |
| 584 void BrowserActionsToolbarGtk::AnimateToShowNIcons(int count) { | 584 void BrowserActionsToolbarGtk::AnimateToShowNIcons(int count) { |
| 585 desired_width_ = WidthForIconCount(count); | 585 desired_width_ = WidthForIconCount(count); |
| 586 start_width_ = button_hbox_->allocation.width; | 586 |
| 587 GtkAllocation allocation; |
| 588 gtk_widget_get_allocation(button_hbox_.get(), &allocation); |
| 589 start_width_ = allocation.width; |
| 590 |
| 587 resize_animation_.Reset(); | 591 resize_animation_.Reset(); |
| 588 resize_animation_.Show(); | 592 resize_animation_.Show(); |
| 589 } | 593 } |
| 590 | 594 |
| 591 void BrowserActionsToolbarGtk::BrowserActionAdded(const Extension* extension, | 595 void BrowserActionsToolbarGtk::BrowserActionAdded(const Extension* extension, |
| 592 int index) { | 596 int index) { |
| 593 overflow_menu_.reset(); | 597 overflow_menu_.reset(); |
| 594 | 598 |
| 595 CreateButtonForExtension(extension, index); | 599 CreateButtonForExtension(extension, index); |
| 596 | 600 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 } | 759 } |
| 756 } | 760 } |
| 757 | 761 |
| 758 gboolean BrowserActionsToolbarGtk::OnDragMotion(GtkWidget* widget, | 762 gboolean BrowserActionsToolbarGtk::OnDragMotion(GtkWidget* widget, |
| 759 GdkDragContext* drag_context, | 763 GdkDragContext* drag_context, |
| 760 gint x, gint y, guint time) { | 764 gint x, gint y, guint time) { |
| 761 // Only handle drags we initiated. | 765 // Only handle drags we initiated. |
| 762 if (!drag_button_) | 766 if (!drag_button_) |
| 763 return FALSE; | 767 return FALSE; |
| 764 | 768 |
| 765 if (base::i18n::IsRTL()) | 769 if (base::i18n::IsRTL()) { |
| 766 x = widget->allocation.width - x; | 770 GtkAllocation allocation; |
| 771 gtk_widget_get_allocation(widget, &allocation); |
| 772 x = allocation.width - x; |
| 773 } |
| 774 |
| 767 drop_index_ = x < kButtonWidth ? 0 : x / (kButtonWidth + kButtonPadding); | 775 drop_index_ = x < kButtonWidth ? 0 : x / (kButtonWidth + kButtonPadding); |
| 768 | 776 |
| 769 // We will go ahead and reorder the child in order to provide visual feedback | 777 // We will go ahead and reorder the child in order to provide visual feedback |
| 770 // to the user. We don't inform the model that it has moved until the drag | 778 // to the user. We don't inform the model that it has moved until the drag |
| 771 // ends. | 779 // ends. |
| 772 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), drag_button_->widget(), | 780 gtk_box_reorder_child(GTK_BOX(button_hbox_.get()), drag_button_->widget(), |
| 773 drop_index_); | 781 drop_index_); |
| 774 | 782 |
| 775 gdk_drag_status(drag_context, GDK_ACTION_MOVE, time); | 783 gdk_drag_status(drag_context, GDK_ACTION_MOVE, time); |
| 776 return TRUE; | 784 return TRUE; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 822 weak_factory_.GetWeakPtr())); | 830 weak_factory_.GetWeakPtr())); |
| 823 } | 831 } |
| 824 | 832 |
| 825 gboolean BrowserActionsToolbarGtk::OnGripperMotionNotify( | 833 gboolean BrowserActionsToolbarGtk::OnGripperMotionNotify( |
| 826 GtkWidget* widget, GdkEventMotion* event) { | 834 GtkWidget* widget, GdkEventMotion* event) { |
| 827 if (!(event->state & GDK_BUTTON1_MASK)) | 835 if (!(event->state & GDK_BUTTON1_MASK)) |
| 828 return FALSE; | 836 return FALSE; |
| 829 | 837 |
| 830 // Calculate how much the user dragged the gripper and subtract that off the | 838 // Calculate how much the user dragged the gripper and subtract that off the |
| 831 // button container's width. | 839 // button container's width. |
| 832 int distance_dragged = base::i18n::IsRTL() ? | 840 int distance_dragged; |
| 833 -event->x : | 841 if (base::i18n::IsRTL()) { |
| 834 event->x - widget->allocation.width; | 842 distance_dragged = -event->x; |
| 835 gint new_width = button_hbox_->allocation.width - distance_dragged; | 843 } else { |
| 844 GtkAllocation widget_allocation; |
| 845 gtk_widget_get_allocation(widget, &widget_allocation); |
| 846 distance_dragged = event->x - widget_allocation.width; |
| 847 } |
| 848 |
| 849 GtkAllocation button_hbox_allocation; |
| 850 gtk_widget_get_allocation(button_hbox_.get(), &button_hbox_allocation); |
| 851 gint new_width = button_hbox_allocation.width - distance_dragged; |
| 836 SetButtonHBoxWidth(new_width); | 852 SetButtonHBoxWidth(new_width); |
| 837 | 853 |
| 838 return FALSE; | 854 return FALSE; |
| 839 } | 855 } |
| 840 | 856 |
| 841 gboolean BrowserActionsToolbarGtk::OnGripperExpose(GtkWidget* gripper, | 857 gboolean BrowserActionsToolbarGtk::OnGripperExpose(GtkWidget* gripper, |
| 842 GdkEventExpose* expose) { | 858 GdkEventExpose* expose) { |
| 843 return TRUE; | 859 return TRUE; |
| 844 } | 860 } |
| 845 | 861 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 857 | 873 |
| 858 gboolean BrowserActionsToolbarGtk::OnGripperLeaveNotify( | 874 gboolean BrowserActionsToolbarGtk::OnGripperLeaveNotify( |
| 859 GtkWidget* gripper, GdkEventCrossing* event) { | 875 GtkWidget* gripper, GdkEventCrossing* event) { |
| 860 if (!(event->state & GDK_BUTTON1_MASK)) | 876 if (!(event->state & GDK_BUTTON1_MASK)) |
| 861 gdk_window_set_cursor(gtk_widget_get_window(gripper), NULL); | 877 gdk_window_set_cursor(gtk_widget_get_window(gripper), NULL); |
| 862 return FALSE; | 878 return FALSE; |
| 863 } | 879 } |
| 864 | 880 |
| 865 gboolean BrowserActionsToolbarGtk::OnGripperButtonRelease( | 881 gboolean BrowserActionsToolbarGtk::OnGripperButtonRelease( |
| 866 GtkWidget* gripper, GdkEventButton* event) { | 882 GtkWidget* gripper, GdkEventButton* event) { |
| 867 gfx::Rect gripper_rect(0, 0, | 883 GtkAllocation allocation; |
| 868 gripper->allocation.width, gripper->allocation.height); | 884 gtk_widget_get_allocation(gripper, &allocation); |
| 885 gfx::Rect gripper_rect(0, 0, allocation.width, allocation.height); |
| 886 |
| 869 gfx::Point release_point(event->x, event->y); | 887 gfx::Point release_point(event->x, event->y); |
| 870 if (!gripper_rect.Contains(release_point)) | 888 if (!gripper_rect.Contains(release_point)) |
| 871 gdk_window_set_cursor(gtk_widget_get_window(gripper), NULL); | 889 gdk_window_set_cursor(gtk_widget_get_window(gripper), NULL); |
| 872 | 890 |
| 873 // After the user resizes the toolbar, we want to smartly resize it to be | 891 // After the user resizes the toolbar, we want to smartly resize it to be |
| 874 // the perfect size to fit the buttons. | 892 // the perfect size to fit the buttons. |
| 875 int visible_icon_count = | 893 int visible_icon_count = |
| 876 gtk_chrome_shrinkable_hbox_get_visible_child_count( | 894 gtk_chrome_shrinkable_hbox_get_visible_child_count( |
| 877 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 895 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
| 878 AnimateToShowNIcons(visible_icon_count); | 896 AnimateToShowNIcons(visible_icon_count); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 | 972 |
| 955 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 973 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
| 956 event->time); | 974 event->time); |
| 957 return TRUE; | 975 return TRUE; |
| 958 } | 976 } |
| 959 | 977 |
| 960 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 978 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
| 961 if (!resize_animation_.is_animating()) | 979 if (!resize_animation_.is_animating()) |
| 962 UpdateChevronVisibility(); | 980 UpdateChevronVisibility(); |
| 963 } | 981 } |
| OLD | NEW |