OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/browser_actions_toolbar_gtk.h" | 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 model_(NULL), | 343 model_(NULL), |
344 hbox_(gtk_hbox_new(FALSE, 0)), | 344 hbox_(gtk_hbox_new(FALSE, 0)), |
345 button_hbox_(gtk_chrome_shrinkable_hbox_new(TRUE, FALSE, kButtonPadding)), | 345 button_hbox_(gtk_chrome_shrinkable_hbox_new(TRUE, FALSE, kButtonPadding)), |
346 overflow_button_(browser->profile()), | 346 overflow_button_(browser->profile()), |
347 separator_(theme_provider_->CreateToolbarSeparator()), | 347 separator_(theme_provider_->CreateToolbarSeparator()), |
348 drag_button_(NULL), | 348 drag_button_(NULL), |
349 drop_index_(-1), | 349 drop_index_(-1), |
350 resize_animation_(this), | 350 resize_animation_(this), |
351 desired_width_(0), | 351 desired_width_(0), |
352 start_width_(0), | 352 start_width_(0), |
353 draw_gripper_(false), | |
354 method_factory_(this) { | 353 method_factory_(this) { |
355 ExtensionsService* extension_service = profile_->GetExtensionsService(); | 354 ExtensionsService* extension_service = profile_->GetExtensionsService(); |
356 // The |extension_service| can be NULL in Incognito. | 355 // The |extension_service| can be NULL in Incognito. |
357 if (!extension_service) | 356 if (!extension_service) |
358 return; | 357 return; |
359 | 358 |
360 GtkWidget* gripper = gtk_button_new(); | 359 GtkWidget* gripper = gtk_button_new(); |
361 GTK_WIDGET_UNSET_FLAGS(gripper, GTK_CAN_FOCUS); | 360 GTK_WIDGET_UNSET_FLAGS(gripper, GTK_CAN_FOCUS); |
362 gtk_widget_add_events(gripper, GDK_POINTER_MOTION_MASK); | 361 gtk_widget_add_events(gripper, GDK_POINTER_MOTION_MASK); |
363 signals_.Connect(gripper, "motion-notify-event", | 362 signals_.Connect(gripper, "motion-notify-event", |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 -event->x : | 746 -event->x : |
748 event->x - widget->allocation.width; | 747 event->x - widget->allocation.width; |
749 gint new_width = button_hbox_->allocation.width - distance_dragged; | 748 gint new_width = button_hbox_->allocation.width - distance_dragged; |
750 SetButtonHBoxWidth(new_width); | 749 SetButtonHBoxWidth(new_width); |
751 | 750 |
752 return FALSE; | 751 return FALSE; |
753 } | 752 } |
754 | 753 |
755 gboolean BrowserActionsToolbarGtk::OnGripperExpose(GtkWidget* gripper, | 754 gboolean BrowserActionsToolbarGtk::OnGripperExpose(GtkWidget* gripper, |
756 GdkEventExpose* expose) { | 755 GdkEventExpose* expose) { |
757 if (!draw_gripper_) | |
758 return TRUE; | |
759 | |
760 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(expose->window)); | |
761 | |
762 CairoCachedSurface* surface = theme_provider_->GetSurfaceNamed( | |
763 IDR_RESIZE_GRIPPER, gripper); | |
764 gfx::Point center = gfx::Rect(gripper->allocation).CenterPoint(); | |
765 center.Offset(-surface->Width() / 2, -surface->Height() / 2); | |
766 surface->SetSource(cr, center.x(), center.y()); | |
767 gdk_cairo_rectangle(cr, &expose->area); | |
768 cairo_fill(cr); | |
769 | |
770 cairo_destroy(cr); | |
771 | |
772 return TRUE; | 756 return TRUE; |
773 } | 757 } |
774 | 758 |
775 // These three signal handlers (EnterNotify, LeaveNotify, and ButtonRelease) | 759 // These three signal handlers (EnterNotify, LeaveNotify, and ButtonRelease) |
776 // are used to give the gripper the resize cursor. Since it doesn't have its | 760 // are used to give the gripper the resize cursor. Since it doesn't have its |
777 // own window, we have to set the cursor whenever the pointer moves into the | 761 // own window, we have to set the cursor whenever the pointer moves into the |
778 // button or leaves the button, and be sure to leave it on when the user is | 762 // button or leaves the button, and be sure to leave it on when the user is |
779 // dragging. | 763 // dragging. |
780 gboolean BrowserActionsToolbarGtk::OnGripperEnterNotify( | 764 gboolean BrowserActionsToolbarGtk::OnGripperEnterNotify( |
781 GtkWidget* gripper, GdkEventCrossing* event) { | 765 GtkWidget* gripper, GdkEventCrossing* event) { |
782 gdk_window_set_cursor(gripper->window, | 766 gdk_window_set_cursor(gripper->window, |
783 gtk_util::GetCursor(GDK_SB_H_DOUBLE_ARROW)); | 767 gtk_util::GetCursor(GDK_SB_H_DOUBLE_ARROW)); |
784 draw_gripper_ = true; | |
785 | |
786 return FALSE; | 768 return FALSE; |
787 } | 769 } |
788 | 770 |
789 gboolean BrowserActionsToolbarGtk::OnGripperLeaveNotify( | 771 gboolean BrowserActionsToolbarGtk::OnGripperLeaveNotify( |
790 GtkWidget* gripper, GdkEventCrossing* event) { | 772 GtkWidget* gripper, GdkEventCrossing* event) { |
791 if (!(event->state & GDK_BUTTON1_MASK)) { | 773 if (!(event->state & GDK_BUTTON1_MASK)) |
792 gdk_window_set_cursor(gripper->window, NULL); | 774 gdk_window_set_cursor(gripper->window, NULL); |
793 draw_gripper_ = false; | |
794 } | |
795 | |
796 return FALSE; | 775 return FALSE; |
797 } | 776 } |
798 | 777 |
799 gboolean BrowserActionsToolbarGtk::OnGripperButtonRelease( | 778 gboolean BrowserActionsToolbarGtk::OnGripperButtonRelease( |
800 GtkWidget* gripper, GdkEventButton* event) { | 779 GtkWidget* gripper, GdkEventButton* event) { |
801 gfx::Rect gripper_rect(0, 0, | 780 gfx::Rect gripper_rect(0, 0, |
802 gripper->allocation.width, gripper->allocation.height); | 781 gripper->allocation.width, gripper->allocation.height); |
803 gfx::Point release_point(event->x, event->y); | 782 gfx::Point release_point(event->x, event->y); |
804 if (!gripper_rect.Contains(release_point)) { | 783 if (!gripper_rect.Contains(release_point)) |
805 gdk_window_set_cursor(gripper->window, NULL); | 784 gdk_window_set_cursor(gripper->window, NULL); |
806 draw_gripper_ = false; | |
807 gtk_widget_queue_draw(gripper); | |
808 } | |
809 | 785 |
810 // After the user resizes the toolbar, we want to smartly resize it to be | 786 // After the user resizes the toolbar, we want to smartly resize it to be |
811 // the perfect size to fit the buttons. | 787 // the perfect size to fit the buttons. |
812 int visible_icon_count = | 788 int visible_icon_count = |
813 gtk_chrome_shrinkable_hbox_get_visible_child_count( | 789 gtk_chrome_shrinkable_hbox_get_visible_child_count( |
814 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); | 790 GTK_CHROME_SHRINKABLE_HBOX(button_hbox_.get())); |
815 AnimateToShowNIcons(visible_icon_count); | 791 AnimateToShowNIcons(visible_icon_count); |
816 model_->SetVisibleIconCount(visible_icon_count); | 792 model_->SetVisibleIconCount(visible_icon_count); |
817 | 793 |
818 return FALSE; | 794 return FALSE; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 863 } |
888 | 864 |
889 it->second.get()->GetContextMenu()->PopupAsContext(event->time); | 865 it->second.get()->GetContextMenu()->PopupAsContext(event->time); |
890 return TRUE; | 866 return TRUE; |
891 } | 867 } |
892 | 868 |
893 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 869 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
894 if (!resize_animation_.is_animating()) | 870 if (!resize_animation_.is_animating()) |
895 UpdateChevronVisibility(); | 871 UpdateChevronVisibility(); |
896 } | 872 } |
OLD | NEW |