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 "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/app/chrome_dll_resource.h" | 11 #include "chrome/app/chrome_dll_resource.h" |
12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
13 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" | 13 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" |
14 #include "chrome/browser/gtk/menu_gtk.h" | 14 #include "chrome/browser/gtk/menu_gtk.h" |
15 #include "chrome/common/gtk_util.h" | 15 #include "chrome/common/gtk_util.h" |
16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 | 18 |
19 // The time in milliseconds between when the user clicks and the menu appears. | 19 // The time in milliseconds between when the user clicks and the menu appears. |
20 static const int kMenuTimerDelay = 500; | 20 static const int kMenuTimerDelay = 500; |
21 | 21 |
22 BackForwardButtonGtk::BackForwardButtonGtk(Browser* browser, bool is_forward) | 22 BackForwardButtonGtk::BackForwardButtonGtk(Browser* browser, bool is_forward) |
23 : browser_(browser), | 23 : browser_(browser), |
24 is_forward_(is_forward), | 24 is_forward_(is_forward), |
25 last_release_event_flags_(0), | 25 last_release_event_flags_(0), |
26 show_menu_factory_(this) { | 26 show_menu_factory_(this) { |
27 int normal, active, highlight, depressed, tooltip; | 27 int normal, active, highlight, depressed, tooltip; |
| 28 const char* stock; |
28 if (is_forward) { | 29 if (is_forward) { |
29 normal = IDR_FORWARD; | 30 normal = IDR_FORWARD; |
30 active = IDR_FORWARD_P; | 31 active = IDR_FORWARD_P; |
31 highlight = IDR_FORWARD_H; | 32 highlight = IDR_FORWARD_H; |
32 depressed = IDR_FORWARD_D; | 33 depressed = IDR_FORWARD_D; |
33 tooltip = IDS_TOOLTIP_FORWARD; | 34 tooltip = IDS_TOOLTIP_FORWARD; |
| 35 stock = GTK_STOCK_GO_FORWARD; |
34 } else { | 36 } else { |
35 normal = IDR_BACK; | 37 normal = IDR_BACK; |
36 active = IDR_BACK_P; | 38 active = IDR_BACK_P; |
37 highlight = IDR_BACK_H; | 39 highlight = IDR_BACK_H; |
38 depressed = IDR_BACK_D; | 40 depressed = IDR_BACK_D; |
39 tooltip = IDS_TOOLTIP_BACK; | 41 tooltip = IDS_TOOLTIP_BACK; |
| 42 stock = GTK_STOCK_GO_BACK; |
40 } | 43 } |
41 button_.reset(new CustomDrawButton(normal, active, highlight, depressed)); | 44 button_.reset(new CustomDrawButton(normal, active, highlight, depressed, |
| 45 stock)); |
42 gtk_widget_set_tooltip_text(widget(), | 46 gtk_widget_set_tooltip_text(widget(), |
43 l10n_util::GetStringUTF8(tooltip).c_str()); | 47 l10n_util::GetStringUTF8(tooltip).c_str()); |
44 menu_model_.reset(new BackForwardMenuModelGtk(browser, | 48 menu_model_.reset(new BackForwardMenuModelGtk(browser, |
45 is_forward ? | 49 is_forward ? |
46 BackForwardMenuModel::FORWARD_MENU : | 50 BackForwardMenuModel::FORWARD_MENU : |
47 BackForwardMenuModel::BACKWARD_MENU, | 51 BackForwardMenuModel::BACKWARD_MENU, |
48 this)); | 52 this)); |
49 | 53 |
50 g_signal_connect(widget(), "clicked", | 54 g_signal_connect(widget(), "clicked", |
51 G_CALLBACK(OnClick), this); | 55 G_CALLBACK(OnClick), this); |
(...skipping 13 matching lines...) Expand all Loading... |
65 gtk_util::SetButtonTriggersNavigation(widget()); | 69 gtk_util::SetButtonTriggersNavigation(widget()); |
66 } | 70 } |
67 | 71 |
68 BackForwardButtonGtk::~BackForwardButtonGtk() { | 72 BackForwardButtonGtk::~BackForwardButtonGtk() { |
69 } | 73 } |
70 | 74 |
71 void BackForwardButtonGtk::StoppedShowingMenu() { | 75 void BackForwardButtonGtk::StoppedShowingMenu() { |
72 button_->UnsetPaintOverride(); | 76 button_->UnsetPaintOverride(); |
73 } | 77 } |
74 | 78 |
| 79 void BackForwardButtonGtk::SetUseSystemTheme(bool use_gtk) { |
| 80 button_->SetUseSystemTheme(use_gtk); |
| 81 } |
| 82 |
75 void BackForwardButtonGtk::ShowBackForwardMenu() { | 83 void BackForwardButtonGtk::ShowBackForwardMenu() { |
76 menu_.reset(new MenuGtk(menu_model_.get(), true)); | 84 menu_.reset(new MenuGtk(menu_model_.get(), true)); |
77 button_->SetPaintOverride(GTK_STATE_ACTIVE); | 85 button_->SetPaintOverride(GTK_STATE_ACTIVE); |
78 | 86 |
79 // gtk_menu_popup will ignore the first mouse button release if it matches | 87 // gtk_menu_popup will ignore the first mouse button release if it matches |
80 // the button type and is within a short span of the time we pass here. | 88 // the button type and is within a short span of the time we pass here. |
81 // Since this menu is not popped up by a button press (instead, it is popped | 89 // Since this menu is not popped up by a button press (instead, it is popped |
82 // up either on a timer or on a drag) this doesn't apply to us and we can | 90 // up either on a timer or on a drag) this doesn't apply to us and we can |
83 // pass arbitrary values. | 91 // pass arbitrary values. |
84 menu_->Popup(widget(), 1, gtk_get_current_event_time()); | 92 menu_->Popup(widget(), 1, gtk_get_current_event_time()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 int drag_min_distance; | 142 int drag_min_distance; |
135 g_object_get(settings, "gtk-dnd-drag-threshold", &drag_min_distance, NULL); | 143 g_object_get(settings, "gtk-dnd-drag-threshold", &drag_min_distance, NULL); |
136 if (event->y - button->y_position_of_last_press_ < drag_min_distance) | 144 if (event->y - button->y_position_of_last_press_ < drag_min_distance) |
137 return FALSE; | 145 return FALSE; |
138 | 146 |
139 // We will show the menu now. Cancel the delayed event. | 147 // We will show the menu now. Cancel the delayed event. |
140 button->show_menu_factory_.RevokeAll(); | 148 button->show_menu_factory_.RevokeAll(); |
141 button->ShowBackForwardMenu(); | 149 button->ShowBackForwardMenu(); |
142 return FALSE; | 150 return FALSE; |
143 } | 151 } |
OLD | NEW |