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_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
6 | 6 |
7 #include <X11/XF86keysym.h> | 7 #include <X11/XF86keysym.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 // BrowserToolbarGtk, public --------------------------------------------------- | 84 // BrowserToolbarGtk, public --------------------------------------------------- |
85 | 85 |
86 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) | 86 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) |
87 : toolbar_(NULL), | 87 : toolbar_(NULL), |
88 location_bar_(new LocationBarViewGtk(browser)), | 88 location_bar_(new LocationBarViewGtk(browser)), |
89 model_(browser->toolbar_model()), | 89 model_(browser->toolbar_model()), |
90 wrench_menu_model_(this, browser), | 90 wrench_menu_model_(this, browser), |
91 browser_(browser), | 91 browser_(browser), |
92 window_(window), | 92 window_(window) { |
93 profile_(NULL) { | |
94 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 93 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
95 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 94 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
96 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 95 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
97 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); | 96 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); |
98 | 97 |
99 registrar_.Add(this, | 98 registrar_.Add(this, |
100 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 99 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
101 NotificationService::AllSources()); | 100 NotificationService::AllSources()); |
102 } | 101 } |
103 | 102 |
104 BrowserToolbarGtk::~BrowserToolbarGtk() { | 103 BrowserToolbarGtk::~BrowserToolbarGtk() { |
105 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); | 104 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); |
106 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); | 105 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); |
107 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); | 106 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); |
108 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); | 107 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); |
109 | 108 |
110 offscreen_entry_.Destroy(); | 109 offscreen_entry_.Destroy(); |
111 | 110 |
112 wrench_menu_.reset(); | 111 wrench_menu_.reset(); |
113 } | 112 } |
114 | 113 |
115 void BrowserToolbarGtk::Init(Profile* profile, | 114 void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { |
116 GtkWindow* top_level_window) { | 115 Profile* profile = browser_->profile(); |
117 // Make sure to tell the location bar the profile before calling its Init. | |
118 SetProfile(profile); | |
119 | |
120 theme_service_ = GtkThemeService::GetFrom(profile); | 116 theme_service_ = GtkThemeService::GetFrom(profile); |
121 registrar_.Add(this, | 117 registrar_.Add(this, |
122 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 118 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
123 Source<ThemeService>(theme_service_)); | 119 Source<ThemeService>(theme_service_)); |
124 | 120 |
125 offscreen_entry_.Own(gtk_entry_new()); | 121 offscreen_entry_.Own(gtk_entry_new()); |
126 | 122 |
127 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 123 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
128 home_page_.Init(prefs::kHomePage, profile->GetPrefs(), this); | 124 home_page_.Init(prefs::kHomePage, profile->GetPrefs(), this); |
129 home_page_is_new_tab_page_.Init(prefs::kHomePageIsNewTabPage, | 125 home_page_is_new_tab_page_.Init(prefs::kHomePageIsNewTabPage, |
(...skipping 28 matching lines...) Expand all Loading... |
158 G_CALLBACK(OnButtonClickThunk), this); | 154 G_CALLBACK(OnButtonClickThunk), this); |
159 gtk_size_group_add_widget(size_group, forward_->widget()); | 155 gtk_size_group_add_widget(size_group, forward_->widget()); |
160 gtk_box_pack_start(GTK_BOX(toolbar_left_), forward_->widget(), FALSE, | 156 gtk_box_pack_start(GTK_BOX(toolbar_left_), forward_->widget(), FALSE, |
161 FALSE, 0); | 157 FALSE, 0); |
162 | 158 |
163 reload_.reset(new ReloadButtonGtk(location_bar_.get(), browser_)); | 159 reload_.reset(new ReloadButtonGtk(location_bar_.get(), browser_)); |
164 gtk_size_group_add_widget(size_group, reload_->widget()); | 160 gtk_size_group_add_widget(size_group, reload_->widget()); |
165 gtk_box_pack_start(GTK_BOX(toolbar_left_), reload_->widget(), FALSE, FALSE, | 161 gtk_box_pack_start(GTK_BOX(toolbar_left_), reload_->widget(), FALSE, FALSE, |
166 0); | 162 0); |
167 | 163 |
168 home_.reset(new CustomDrawButton(GtkThemeService::GetFrom(profile_), | 164 home_.reset(new CustomDrawButton(theme_service_, IDR_HOME, IDR_HOME_P, |
169 IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, GTK_STOCK_HOME, | 165 IDR_HOME_H, 0, GTK_STOCK_HOME, GTK_ICON_SIZE_SMALL_TOOLBAR)); |
170 GTK_ICON_SIZE_SMALL_TOOLBAR)); | |
171 gtk_widget_set_tooltip_text(home_->widget(), | 166 gtk_widget_set_tooltip_text(home_->widget(), |
172 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME).c_str()); | 167 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME).c_str()); |
173 g_signal_connect(home_->widget(), "clicked", | 168 g_signal_connect(home_->widget(), "clicked", |
174 G_CALLBACK(OnButtonClickThunk), this); | 169 G_CALLBACK(OnButtonClickThunk), this); |
175 gtk_size_group_add_widget(size_group, home_->widget()); | 170 gtk_size_group_add_widget(size_group, home_->widget()); |
176 gtk_box_pack_start(GTK_BOX(toolbar_left_), home_->widget(), FALSE, FALSE, | 171 gtk_box_pack_start(GTK_BOX(toolbar_left_), home_->widget(), FALSE, FALSE, |
177 kToolbarWidgetSpacing); | 172 kToolbarWidgetSpacing); |
178 gtk_util::SetButtonTriggersNavigation(home_->widget()); | 173 gtk_util::SetButtonTriggersNavigation(home_->widget()); |
179 | 174 |
180 gtk_box_pack_start(GTK_BOX(toolbar_), toolbar_left_, FALSE, FALSE, | 175 gtk_box_pack_start(GTK_BOX(toolbar_), toolbar_left_, FALSE, FALSE, |
(...skipping 12 matching lines...) Expand all Loading... |
193 ShouldOnlyShowLocation() ? 1 : 0); | 188 ShouldOnlyShowLocation() ? 1 : 0); |
194 | 189 |
195 if (!ShouldOnlyShowLocation()) { | 190 if (!ShouldOnlyShowLocation()) { |
196 actions_toolbar_.reset(new BrowserActionsToolbarGtk(browser_)); | 191 actions_toolbar_.reset(new BrowserActionsToolbarGtk(browser_)); |
197 gtk_box_pack_start(GTK_BOX(toolbar_), actions_toolbar_->widget(), | 192 gtk_box_pack_start(GTK_BOX(toolbar_), actions_toolbar_->widget(), |
198 FALSE, FALSE, 0); | 193 FALSE, FALSE, 0); |
199 } | 194 } |
200 | 195 |
201 wrench_menu_image_ = gtk_image_new_from_pixbuf( | 196 wrench_menu_image_ = gtk_image_new_from_pixbuf( |
202 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); | 197 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); |
203 wrench_menu_button_.reset(new CustomDrawButton( | 198 wrench_menu_button_.reset(new CustomDrawButton(theme_service_, IDR_TOOLS, |
204 GtkThemeService::GetFrom(profile_), | 199 IDR_TOOLS_P, IDR_TOOLS_H, 0, wrench_menu_image_)); |
205 IDR_TOOLS, IDR_TOOLS_P, IDR_TOOLS_H, 0, | |
206 wrench_menu_image_)); | |
207 GtkWidget* wrench_button = wrench_menu_button_->widget(); | 200 GtkWidget* wrench_button = wrench_menu_button_->widget(); |
208 | 201 |
209 gtk_widget_set_tooltip_text( | 202 gtk_widget_set_tooltip_text( |
210 wrench_button, | 203 wrench_button, |
211 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, | 204 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, |
212 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); | 205 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); |
213 g_signal_connect(wrench_button, "button-press-event", | 206 g_signal_connect(wrench_button, "button-press-event", |
214 G_CALLBACK(OnMenuButtonPressEventThunk), this); | 207 G_CALLBACK(OnMenuButtonPressEventThunk), this); |
215 gtk_widget_set_can_focus(wrench_button, FALSE); | 208 gtk_widget_set_can_focus(wrench_button, FALSE); |
216 | 209 |
217 // Put the wrench button in a box so that we can paint the update notification | 210 // Put the wrench button in a box so that we can paint the update notification |
218 // over it. | 211 // over it. |
219 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); | 212 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); |
220 g_signal_connect_after(wrench_box, "expose-event", | 213 g_signal_connect_after(wrench_box, "expose-event", |
221 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); | 214 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); |
222 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); | 215 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); |
223 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); | 216 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); |
224 | 217 |
225 wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_)); | 218 wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_)); |
226 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 219 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, |
227 Source<HostZoomMap>(browser_->profile()->GetHostZoomMap())); | 220 Source<HostZoomMap>(profile->GetHostZoomMap())); |
228 | 221 |
229 if (ShouldOnlyShowLocation()) { | 222 if (ShouldOnlyShowLocation()) { |
230 gtk_widget_show(event_box_); | 223 gtk_widget_show(event_box_); |
231 gtk_widget_show(alignment_); | 224 gtk_widget_show(alignment_); |
232 gtk_widget_show(toolbar_); | 225 gtk_widget_show(toolbar_); |
233 gtk_widget_show_all(location_hbox_); | 226 gtk_widget_show_all(location_hbox_); |
234 gtk_widget_hide(reload_->widget()); | 227 gtk_widget_hide(reload_->widget()); |
235 } else { | 228 } else { |
236 gtk_widget_show_all(event_box_); | 229 gtk_widget_show_all(event_box_); |
237 if (actions_toolbar_->button_count() == 0) | 230 if (actions_toolbar_->button_count() == 0) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 // If our zoom level changed, we need to tell the menu to update its state, | 385 // If our zoom level changed, we need to tell the menu to update its state, |
393 // since the menu could still be open. | 386 // since the menu could still be open. |
394 wrench_menu_->UpdateMenu(); | 387 wrench_menu_->UpdateMenu(); |
395 } else { | 388 } else { |
396 NOTREACHED(); | 389 NOTREACHED(); |
397 } | 390 } |
398 } | 391 } |
399 | 392 |
400 // BrowserToolbarGtk, public --------------------------------------------------- | 393 // BrowserToolbarGtk, public --------------------------------------------------- |
401 | 394 |
402 void BrowserToolbarGtk::SetProfile(Profile* profile) { | |
403 if (profile == profile_) | |
404 return; | |
405 | |
406 profile_ = profile; | |
407 location_bar_->SetProfile(profile); | |
408 } | |
409 | |
410 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, | 395 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, |
411 bool should_restore_state) { | 396 bool should_restore_state) { |
412 location_bar_->Update(should_restore_state ? contents : NULL); | 397 location_bar_->Update(should_restore_state ? contents : NULL); |
413 | 398 |
414 if (actions_toolbar_.get()) | 399 if (actions_toolbar_.get()) |
415 actions_toolbar_->Update(); | 400 actions_toolbar_->Update(); |
416 } | 401 } |
417 | 402 |
418 // BrowserToolbarGtk, private -------------------------------------------------- | 403 // BrowserToolbarGtk, private -------------------------------------------------- |
419 | 404 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 int x_offset = base::i18n::IsRTL() ? 0 : | 633 int x_offset = base::i18n::IsRTL() ? 0 : |
649 sender->allocation.width - badge->width(); | 634 sender->allocation.width - badge->width(); |
650 int y_offset = 0; | 635 int y_offset = 0; |
651 canvas.DrawBitmapInt( | 636 canvas.DrawBitmapInt( |
652 *badge, | 637 *badge, |
653 sender->allocation.x + x_offset, | 638 sender->allocation.x + x_offset, |
654 sender->allocation.y + y_offset); | 639 sender->allocation.y + y_offset); |
655 | 640 |
656 return FALSE; | 641 return FALSE; |
657 } | 642 } |
OLD | NEW |