OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <X11/XF86keysym.h> | 9 #include <X11/XF86keysym.h> |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } // namespace | 92 } // namespace |
93 | 93 |
94 // BrowserToolbarGtk, public --------------------------------------------------- | 94 // BrowserToolbarGtk, public --------------------------------------------------- |
95 | 95 |
96 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) | 96 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) |
97 : toolbar_(NULL), | 97 : toolbar_(NULL), |
98 location_bar_(new LocationBarViewGtk(browser)), | 98 location_bar_(new LocationBarViewGtk(browser)), |
99 model_(browser->toolbar_model()), | 99 model_(browser->toolbar_model()), |
100 is_wrench_menu_model_valid_(true), | 100 is_wrench_menu_model_valid_(true), |
101 browser_(browser), | 101 browser_(browser), |
102 window_(window) { | 102 window_(window), |
| 103 zoom_callback_(base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged, |
| 104 base::Unretained(this))) { |
103 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, false, false)); | 105 wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, false, false)); |
104 | 106 |
105 chrome::AddCommandObserver(browser_, IDC_BACK, this); | 107 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
106 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); | 108 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
107 chrome::AddCommandObserver(browser_, IDC_HOME, this); | 109 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
108 chrome::AddCommandObserver(browser_, IDC_BOOKMARK_PAGE, this); | 110 chrome::AddCommandObserver(browser_, IDC_BOOKMARK_PAGE, this); |
109 | 111 |
110 registrar_.Add(this, | 112 registrar_.Add(this, |
111 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, | 113 chrome::NOTIFICATION_UPGRADE_RECOMMENDED, |
112 content::NotificationService::AllSources()); | 114 content::NotificationService::AllSources()); |
113 registrar_.Add(this, | 115 registrar_.Add(this, |
114 chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, | 116 chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED, |
115 content::Source<Profile>(browser_->profile())); | 117 content::Source<Profile>(browser_->profile())); |
116 } | 118 } |
117 | 119 |
118 BrowserToolbarGtk::~BrowserToolbarGtk() { | 120 BrowserToolbarGtk::~BrowserToolbarGtk() { |
119 chrome::RemoveCommandObserver(browser_, IDC_BACK, this); | 121 chrome::RemoveCommandObserver(browser_, IDC_BACK, this); |
120 chrome::RemoveCommandObserver(browser_, IDC_FORWARD, this); | 122 chrome::RemoveCommandObserver(browser_, IDC_FORWARD, this); |
121 chrome::RemoveCommandObserver(browser_, IDC_HOME, this); | 123 chrome::RemoveCommandObserver(browser_, IDC_HOME, this); |
122 chrome::RemoveCommandObserver(browser_, IDC_BOOKMARK_PAGE, this); | 124 chrome::RemoveCommandObserver(browser_, IDC_BOOKMARK_PAGE, this); |
123 | 125 |
124 offscreen_entry_.Destroy(); | 126 offscreen_entry_.Destroy(); |
125 | 127 |
126 wrench_menu_.reset(); | 128 wrench_menu_.reset(); |
| 129 |
| 130 HostZoomMap::GetForBrowserContext( |
| 131 browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); |
127 } | 132 } |
128 | 133 |
129 void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { | 134 void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { |
130 Profile* profile = browser_->profile(); | 135 Profile* profile = browser_->profile(); |
131 theme_service_ = GtkThemeService::GetFrom(profile); | 136 theme_service_ = GtkThemeService::GetFrom(profile); |
132 registrar_.Add(this, | 137 registrar_.Add(this, |
133 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 138 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
134 content::Source<ThemeService>(theme_service_)); | 139 content::Source<ThemeService>(theme_service_)); |
135 | 140 |
136 offscreen_entry_.Own(gtk_entry_new()); | 141 offscreen_entry_.Own(gtk_entry_new()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); | 239 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); |
235 g_signal_connect_after(wrench_box, "expose-event", | 240 g_signal_connect_after(wrench_box, "expose-event", |
236 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); | 241 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); |
237 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); | 242 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); |
238 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); | 243 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); |
239 | 244 |
240 wrench_menu_.reset(new MenuGtk(this, wrench_menu_model_.get())); | 245 wrench_menu_.reset(new MenuGtk(this, wrench_menu_model_.get())); |
241 // The bookmark menu model needs to be able to force the wrench menu to close. | 246 // The bookmark menu model needs to be able to force the wrench menu to close. |
242 wrench_menu_model_->bookmark_sub_menu_model()->SetMenuGtk(wrench_menu_.get()); | 247 wrench_menu_model_->bookmark_sub_menu_model()->SetMenuGtk(wrench_menu_.get()); |
243 | 248 |
244 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 249 HostZoomMap::GetForBrowserContext( |
245 content::Source<HostZoomMap>( | 250 browser()->profile())->AddZoomLevelChangedCallback(zoom_callback_); |
246 HostZoomMap::GetForBrowserContext(profile))); | |
247 | 251 |
248 if (ShouldOnlyShowLocation()) { | 252 if (ShouldOnlyShowLocation()) { |
249 gtk_widget_show(event_box_); | 253 gtk_widget_show(event_box_); |
250 gtk_widget_show(alignment_); | 254 gtk_widget_show(alignment_); |
251 gtk_widget_show(toolbar_); | 255 gtk_widget_show(toolbar_); |
252 gtk_widget_show_all(location_hbox_); | 256 gtk_widget_show_all(location_hbox_); |
253 gtk_widget_hide(reload_->widget()); | 257 gtk_widget_hide(reload_->widget()); |
254 } else { | 258 } else { |
255 gtk_widget_show_all(event_box_); | 259 gtk_widget_show_all(event_box_); |
256 if (actions_toolbar_->button_count() == 0) | 260 if (actions_toolbar_->button_count() == 0) |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); | 413 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); |
410 } | 414 } |
411 | 415 |
412 UpdateRoundedness(); | 416 UpdateRoundedness(); |
413 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { | 417 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { |
414 // Redraw the wrench menu to update the badge. | 418 // Redraw the wrench menu to update the badge. |
415 gtk_widget_queue_draw(wrench_menu_button_->widget()); | 419 gtk_widget_queue_draw(wrench_menu_button_->widget()); |
416 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { | 420 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { |
417 is_wrench_menu_model_valid_ = false; | 421 is_wrench_menu_model_valid_ = false; |
418 gtk_widget_queue_draw(wrench_menu_button_->widget()); | 422 gtk_widget_queue_draw(wrench_menu_button_->widget()); |
419 } else if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { | |
420 // Since BrowserToolbarGtk create a new |wrench_menu_model_| in | |
421 // RebuildWrenchMenu(), the ordering of the observers of | |
422 // NOTIFICATION_ZOOM_LEVEL_CHANGED can change, and result in subtle bugs | |
423 // like http://crbug.com/118823. Rather than depending on the ordering | |
424 // of the notification observers, always update the WrenchMenuModel before | |
425 // updating the WrenchMenu. | |
426 wrench_menu_model_->UpdateZoomControls(); | |
427 | |
428 // If our zoom level changed, we need to tell the menu to update its state, | |
429 // since the menu could still be open. | |
430 wrench_menu_->UpdateMenu(); | |
431 } else { | 423 } else { |
432 NOTREACHED(); | 424 NOTREACHED(); |
433 } | 425 } |
434 } | 426 } |
435 | 427 |
436 // BrowserToolbarGtk, public --------------------------------------------------- | 428 // BrowserToolbarGtk, public --------------------------------------------------- |
437 | 429 |
438 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, | 430 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, |
439 bool should_restore_state) { | 431 bool should_restore_state) { |
440 location_bar_->Update(should_restore_state ? contents : NULL); | 432 location_bar_->Update(should_restore_state ? contents : NULL); |
441 | 433 |
442 if (actions_toolbar_.get()) | 434 if (actions_toolbar_.get()) |
443 actions_toolbar_->Update(); | 435 actions_toolbar_->Update(); |
444 } | 436 } |
445 | 437 |
446 bool BrowserToolbarGtk::IsWrenchMenuShowing() const { | 438 bool BrowserToolbarGtk::IsWrenchMenuShowing() const { |
447 return wrench_menu_.get() && gtk_widget_get_visible(wrench_menu_->widget()); | 439 return wrench_menu_.get() && gtk_widget_get_visible(wrench_menu_->widget()); |
448 } | 440 } |
449 | 441 |
450 // BrowserToolbarGtk, private -------------------------------------------------- | 442 // BrowserToolbarGtk, private -------------------------------------------------- |
451 | 443 |
| 444 void BrowserToolbarGtk::OnZoomLevelChanged(const std::string& host) { |
| 445 // Since BrowserToolbarGtk create a new |wrench_menu_model_| in |
| 446 // RebuildWrenchMenu(), the ordering of the observers of HostZoomMap |
| 447 // can change, and result in subtle bugs like http://crbug.com/118823. |
| 448 // Rather than depending on the ordering of the observers, always update |
| 449 // the WrenchMenuModel before updating the WrenchMenu. |
| 450 wrench_menu_model_->UpdateZoomControls(); |
| 451 |
| 452 // If our zoom level changed, we need to tell the menu to update its state, |
| 453 // since the menu could still be open. |
| 454 wrench_menu_->UpdateMenu(); |
| 455 } |
| 456 |
| 457 |
452 void BrowserToolbarGtk::SetUpDragForHomeButton() { | 458 void BrowserToolbarGtk::SetUpDragForHomeButton() { |
453 if (!home_page_.IsManaged() && !home_page_is_new_tab_page_.IsManaged()) { | 459 if (!home_page_.IsManaged() && !home_page_is_new_tab_page_.IsManaged()) { |
454 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, | 460 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, |
455 NULL, 0, GDK_ACTION_COPY); | 461 NULL, 0, GDK_ACTION_COPY); |
456 static const int targets[] = { ui::TEXT_PLAIN, ui::TEXT_URI_LIST, -1 }; | 462 static const int targets[] = { ui::TEXT_PLAIN, ui::TEXT_URI_LIST, -1 }; |
457 ui::SetDestTargetList(home_->widget(), targets); | 463 ui::SetDestTargetList(home_->widget(), targets); |
458 | 464 |
459 drop_handler_.reset(new ui::GtkSignalRegistrar()); | 465 drop_handler_.reset(new ui::GtkSignalRegistrar()); |
460 drop_handler_->Connect(home_->widget(), "drag-data-received", | 466 drop_handler_->Connect(home_->widget(), "drag-data-received", |
461 G_CALLBACK(OnDragDataReceivedThunk), this); | 467 G_CALLBACK(OnDragDataReceivedThunk), this); |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 allocation.x + x_offset, | 703 allocation.x + x_offset, |
698 allocation.y + y_offset); | 704 allocation.y + y_offset); |
699 | 705 |
700 return FALSE; | 706 return FALSE; |
701 } | 707 } |
702 | 708 |
703 void BrowserToolbarGtk::UpdateShowHomeButton() { | 709 void BrowserToolbarGtk::UpdateShowHomeButton() { |
704 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation(); | 710 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation(); |
705 gtk_widget_set_visible(home_->widget(), visible); | 711 gtk_widget_set_visible(home_->widget(), visible); |
706 } | 712 } |
OLD | NEW |