| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); | 234 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); |
| 235 g_signal_connect_after(wrench_box, "expose-event", | 235 g_signal_connect_after(wrench_box, "expose-event", |
| 236 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); | 236 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); |
| 237 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); | 237 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); |
| 238 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); | 238 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); |
| 239 | 239 |
| 240 wrench_menu_.reset(new MenuGtk(this, wrench_menu_model_.get())); | 240 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. | 241 // 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()); | 242 wrench_menu_model_->bookmark_sub_menu_model()->SetMenuGtk(wrench_menu_.get()); |
| 243 | 243 |
| 244 registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, | 244 content::HostZoomMap::Observer::Observe( |
| 245 content::Source<HostZoomMap>( | 245 HostZoomMap::GetForBrowserContext(profile)); |
| 246 HostZoomMap::GetForBrowserContext(profile))); | |
| 247 | 246 |
| 248 if (ShouldOnlyShowLocation()) { | 247 if (ShouldOnlyShowLocation()) { |
| 249 gtk_widget_show(event_box_); | 248 gtk_widget_show(event_box_); |
| 250 gtk_widget_show(alignment_); | 249 gtk_widget_show(alignment_); |
| 251 gtk_widget_show(toolbar_); | 250 gtk_widget_show(toolbar_); |
| 252 gtk_widget_show_all(location_hbox_); | 251 gtk_widget_show_all(location_hbox_); |
| 253 gtk_widget_hide(reload_->widget()); | 252 gtk_widget_hide(reload_->widget()); |
| 254 } else { | 253 } else { |
| 255 gtk_widget_show_all(event_box_); | 254 gtk_widget_show_all(event_box_); |
| 256 if (actions_toolbar_->button_count() == 0) | 255 if (actions_toolbar_->button_count() == 0) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 int id, | 364 int id, |
| 366 ui::Accelerator* out_accelerator) { | 365 ui::Accelerator* out_accelerator) { |
| 367 const ui::Accelerator* accelerator = | 366 const ui::Accelerator* accelerator = |
| 368 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(id); | 367 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(id); |
| 369 if (!accelerator) | 368 if (!accelerator) |
| 370 return false; | 369 return false; |
| 371 *out_accelerator = *accelerator; | 370 *out_accelerator = *accelerator; |
| 372 return true; | 371 return true; |
| 373 } | 372 } |
| 374 | 373 |
| 374 // content::HostZoomMap::Observer ---------------------------------------------- |
| 375 |
| 376 void BrowserToolbarGtk::OnZoomLevelChanged(const std::string& host) { |
| 377 // Since BrowserToolbarGtk create a new |wrench_menu_model_| in |
| 378 // RebuildWrenchMenu(), the ordering of the observers of HostZoomMap |
| 379 // can change, and result in subtle bugs like http://crbug.com/118823. |
| 380 // Rather than depending on the ordering of the observers, always update |
| 381 // the WrenchMenuModel before updating the WrenchMenu. |
| 382 wrench_menu_model_->UpdateZoomControls(); |
| 383 |
| 384 // If our zoom level changed, we need to tell the menu to update its state, |
| 385 // since the menu could still be open. |
| 386 wrench_menu_->UpdateMenu(); |
| 387 } |
| 388 |
| 375 // content::NotificationObserver ----------------------------------------------- | 389 // content::NotificationObserver ----------------------------------------------- |
| 376 | 390 |
| 377 void BrowserToolbarGtk::Observe(int type, | 391 void BrowserToolbarGtk::Observe(int type, |
| 378 const content::NotificationSource& source, | 392 const content::NotificationSource& source, |
| 379 const content::NotificationDetails& details) { | 393 const content::NotificationDetails& details) { |
| 380 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { | 394 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { |
| 381 // Update the spacing around the menu buttons | 395 // Update the spacing around the menu buttons |
| 382 bool use_gtk = theme_service_->UsingNativeTheme(); | 396 bool use_gtk = theme_service_->UsingNativeTheme(); |
| 383 int border = use_gtk ? 0 : 2; | 397 int border = use_gtk ? 0 : 2; |
| 384 gtk_container_set_border_width( | 398 gtk_container_set_border_width( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 409 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); | 423 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); |
| 410 } | 424 } |
| 411 | 425 |
| 412 UpdateRoundedness(); | 426 UpdateRoundedness(); |
| 413 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { | 427 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { |
| 414 // Redraw the wrench menu to update the badge. | 428 // Redraw the wrench menu to update the badge. |
| 415 gtk_widget_queue_draw(wrench_menu_button_->widget()); | 429 gtk_widget_queue_draw(wrench_menu_button_->widget()); |
| 416 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { | 430 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { |
| 417 is_wrench_menu_model_valid_ = false; | 431 is_wrench_menu_model_valid_ = false; |
| 418 gtk_widget_queue_draw(wrench_menu_button_->widget()); | 432 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 { | 433 } else { |
| 432 NOTREACHED(); | 434 NOTREACHED(); |
| 433 } | 435 } |
| 434 } | 436 } |
| 435 | 437 |
| 436 // BrowserToolbarGtk, public --------------------------------------------------- | 438 // BrowserToolbarGtk, public --------------------------------------------------- |
| 437 | 439 |
| 438 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, | 440 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, |
| 439 bool should_restore_state) { | 441 bool should_restore_state) { |
| 440 location_bar_->Update(should_restore_state ? contents : NULL); | 442 location_bar_->Update(should_restore_state ? contents : NULL); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 allocation.x + x_offset, | 699 allocation.x + x_offset, |
| 698 allocation.y + y_offset); | 700 allocation.y + y_offset); |
| 699 | 701 |
| 700 return FALSE; | 702 return FALSE; |
| 701 } | 703 } |
| 702 | 704 |
| 703 void BrowserToolbarGtk::UpdateShowHomeButton() { | 705 void BrowserToolbarGtk::UpdateShowHomeButton() { |
| 704 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation(); | 706 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation(); |
| 705 gtk_widget_set_visible(home_->widget(), visible); | 707 gtk_widget_set_visible(home_->widget(), visible); |
| 706 } | 708 } |
| OLD | NEW |