| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/back_forward_button_gtk.h" | 5 #include "chrome/browser/gtk/back_forward_button_gtk.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/menus/menu_model.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 13 #include "chrome/browser/back_forward_menu_model.h" |
| 12 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" | |
| 14 #include "chrome/browser/gtk/gtk_theme_provider.h" | 15 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 15 #include "chrome/browser/gtk/menu_gtk.h" | 16 #include "chrome/browser/gtk/menu_gtk.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "chrome/common/gtk_util.h" | 18 #include "chrome/common/gtk_util.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 | 21 |
| 21 // The time in milliseconds between when the user clicks and the menu appears. | 22 // The time in milliseconds between when the user clicks and the menu appears. |
| 22 static const int kMenuTimerDelay = 500; | 23 static const int kMenuTimerDelay = 500; |
| 23 | 24 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 43 background = IDR_BACK_MASK; | 44 background = IDR_BACK_MASK; |
| 44 tooltip = IDS_TOOLTIP_BACK; | 45 tooltip = IDS_TOOLTIP_BACK; |
| 45 stock = GTK_STOCK_GO_BACK; | 46 stock = GTK_STOCK_GO_BACK; |
| 46 } | 47 } |
| 47 button_.reset(new CustomDrawButton( | 48 button_.reset(new CustomDrawButton( |
| 48 GtkThemeProvider::GetFrom(browser_->profile()), | 49 GtkThemeProvider::GetFrom(browser_->profile()), |
| 49 normal, active, highlight, depressed, background, stock, | 50 normal, active, highlight, depressed, background, stock, |
| 50 GTK_ICON_SIZE_SMALL_TOOLBAR)); | 51 GTK_ICON_SIZE_SMALL_TOOLBAR)); |
| 51 gtk_widget_set_tooltip_text(widget(), | 52 gtk_widget_set_tooltip_text(widget(), |
| 52 l10n_util::GetStringUTF8(tooltip).c_str()); | 53 l10n_util::GetStringUTF8(tooltip).c_str()); |
| 53 menu_model_.reset(new BackForwardMenuModelGtk(browser, | 54 menu_model_.reset( |
| 54 is_forward ? | 55 new BackForwardMenuModel(browser, |
| 55 BackForwardMenuModel::FORWARD_MENU : | 56 is_forward ? |
| 56 BackForwardMenuModel::BACKWARD_MENU, | 57 BackForwardMenuModel::FORWARD_MENU : |
| 57 this)); | 58 BackForwardMenuModel::BACKWARD_MENU)); |
| 58 | 59 |
| 59 g_signal_connect(widget(), "clicked", | 60 g_signal_connect(widget(), "clicked", |
| 60 G_CALLBACK(OnClick), this); | 61 G_CALLBACK(OnClick), this); |
| 61 g_signal_connect(widget(), "button-press-event", | 62 g_signal_connect(widget(), "button-press-event", |
| 62 G_CALLBACK(OnButtonPress), this); | 63 G_CALLBACK(OnButtonPress), this); |
| 63 gtk_widget_add_events(widget(), GDK_POINTER_MOTION_MASK); | 64 gtk_widget_add_events(widget(), GDK_POINTER_MOTION_MASK); |
| 64 g_signal_connect(widget(), "motion-notify-event", | 65 g_signal_connect(widget(), "motion-notify-event", |
| 65 G_CALLBACK(OnMouseMove), this); | 66 G_CALLBACK(OnMouseMove), this); |
| 66 | 67 |
| 67 // Popup the menu as left-aligned relative to this widget rather than the | 68 // Popup the menu as left-aligned relative to this widget rather than the |
| 68 // default of right aligned. | 69 // default of right aligned. |
| 69 g_object_set_data(G_OBJECT(widget()), "left-align-popup", | 70 g_object_set_data(G_OBJECT(widget()), "left-align-popup", |
| 70 reinterpret_cast<void*>(true)); | 71 reinterpret_cast<void*>(true)); |
| 71 | 72 |
| 72 gtk_util::SetButtonTriggersNavigation(widget()); | 73 gtk_util::SetButtonTriggersNavigation(widget()); |
| 73 } | 74 } |
| 74 | 75 |
| 75 BackForwardButtonGtk::~BackForwardButtonGtk() { | 76 BackForwardButtonGtk::~BackForwardButtonGtk() { |
| 76 } | 77 } |
| 77 | 78 |
| 78 void BackForwardButtonGtk::StoppedShowingMenu() { | 79 void BackForwardButtonGtk::StoppedShowing() { |
| 79 button_->UnsetPaintOverride(); | 80 button_->UnsetPaintOverride(); |
| 80 } | 81 } |
| 81 | 82 |
| 83 bool BackForwardButtonGtk::IsCommandEnabled(int command_id) const { |
| 84 return menu_model_->IsEnabledAt(command_id); |
| 85 } |
| 86 |
| 87 void BackForwardButtonGtk::ExecuteCommand(int command_id) { |
| 88 menu_model_->ActivatedAt(command_id); |
| 89 } |
| 90 |
| 91 bool BackForwardButtonGtk::AlwaysShowImages() const { |
| 92 return true; |
| 93 } |
| 94 |
| 82 void BackForwardButtonGtk::ShowBackForwardMenu() { | 95 void BackForwardButtonGtk::ShowBackForwardMenu() { |
| 83 menu_.reset(new MenuGtk(menu_model_.get(), true)); | 96 menu_.reset(new MenuGtk(this, menu_model_.get())); |
| 84 button_->SetPaintOverride(GTK_STATE_ACTIVE); | 97 button_->SetPaintOverride(GTK_STATE_ACTIVE); |
| 85 | 98 |
| 86 // gtk_menu_popup will ignore the first mouse button release if it matches | 99 // gtk_menu_popup will ignore the first mouse button release if it matches |
| 87 // the button type and is within a short span of the time we pass here. | 100 // the button type and is within a short span of the time we pass here. |
| 88 // Since this menu is not popped up by a button press (instead, it is popped | 101 // Since this menu is not popped up by a button press (instead, it is popped |
| 89 // up either on a timer or on a drag) this doesn't apply to us and we can | 102 // up either on a timer or on a drag) this doesn't apply to us and we can |
| 90 // pass arbitrary values. | 103 // pass arbitrary values. |
| 91 menu_->Popup(widget(), 1, gtk_get_current_event_time()); | 104 menu_->Popup(widget(), 1, gtk_get_current_event_time()); |
| 92 } | 105 } |
| 93 | 106 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 int drag_min_distance; | 145 int drag_min_distance; |
| 133 g_object_get(settings, "gtk-dnd-drag-threshold", &drag_min_distance, NULL); | 146 g_object_get(settings, "gtk-dnd-drag-threshold", &drag_min_distance, NULL); |
| 134 if (event->y - button->y_position_of_last_press_ < drag_min_distance) | 147 if (event->y - button->y_position_of_last_press_ < drag_min_distance) |
| 135 return FALSE; | 148 return FALSE; |
| 136 | 149 |
| 137 // We will show the menu now. Cancel the delayed event. | 150 // We will show the menu now. Cancel the delayed event. |
| 138 button->show_menu_factory_.RevokeAll(); | 151 button->show_menu_factory_.RevokeAll(); |
| 139 button->ShowBackForwardMenu(); | 152 button->ShowBackForwardMenu(); |
| 140 return FALSE; | 153 return FALSE; |
| 141 } | 154 } |
| 155 |
| OLD | NEW |