Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: chrome/browser/ui/gtk/browser_toolbar_gtk.cc

Issue 12039058: content: convert zoom notifications to observer usage (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: callbacks Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 117
118 BrowserToolbarGtk::~BrowserToolbarGtk() { 118 BrowserToolbarGtk::~BrowserToolbarGtk() {
119 chrome::RemoveCommandObserver(browser_, IDC_BACK, this); 119 chrome::RemoveCommandObserver(browser_, IDC_BACK, this);
120 chrome::RemoveCommandObserver(browser_, IDC_FORWARD, this); 120 chrome::RemoveCommandObserver(browser_, IDC_FORWARD, this);
121 chrome::RemoveCommandObserver(browser_, IDC_HOME, this); 121 chrome::RemoveCommandObserver(browser_, IDC_HOME, this);
122 chrome::RemoveCommandObserver(browser_, IDC_BOOKMARK_PAGE, this); 122 chrome::RemoveCommandObserver(browser_, IDC_BOOKMARK_PAGE, this);
123 123
124 offscreen_entry_.Destroy(); 124 offscreen_entry_.Destroy();
125 125
126 wrench_menu_.reset(); 126 wrench_menu_.reset();
127
128 HostZoomMap::GetForBrowserContext(
129 browser()->profile())->AddZoomLevelChangedCallback(
130 base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged,
131 base::Unretained(this)));
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
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(
246 HostZoomMap::GetForBrowserContext(profile))); 251 base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged,
252 base::Unretained(this)));
247 253
248 if (ShouldOnlyShowLocation()) { 254 if (ShouldOnlyShowLocation()) {
249 gtk_widget_show(event_box_); 255 gtk_widget_show(event_box_);
250 gtk_widget_show(alignment_); 256 gtk_widget_show(alignment_);
251 gtk_widget_show(toolbar_); 257 gtk_widget_show(toolbar_);
252 gtk_widget_show_all(location_hbox_); 258 gtk_widget_show_all(location_hbox_);
253 gtk_widget_hide(reload_->widget()); 259 gtk_widget_hide(reload_->widget());
254 } else { 260 } else {
255 gtk_widget_show_all(event_box_); 261 gtk_widget_show_all(event_box_);
256 if (actions_toolbar_->button_count() == 0) 262 if (actions_toolbar_->button_count() == 0)
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 int id, 371 int id,
366 ui::Accelerator* out_accelerator) { 372 ui::Accelerator* out_accelerator) {
367 const ui::Accelerator* accelerator = 373 const ui::Accelerator* accelerator =
368 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(id); 374 AcceleratorsGtk::GetInstance()->GetPrimaryAcceleratorForCommand(id);
369 if (!accelerator) 375 if (!accelerator)
370 return false; 376 return false;
371 *out_accelerator = *accelerator; 377 *out_accelerator = *accelerator;
372 return true; 378 return true;
373 } 379 }
374 380
381 // content::HostZoomMapObserver ------------------------------------------------
382
383 void BrowserToolbarGtk::OnZoomLevelChanged(const std::string& host) {
384 // Since BrowserToolbarGtk create a new |wrench_menu_model_| in
385 // RebuildWrenchMenu(), the ordering of the observers of HostZoomMap
386 // can change, and result in subtle bugs like http://crbug.com/118823.
387 // Rather than depending on the ordering of the observers, always update
388 // the WrenchMenuModel before updating the WrenchMenu.
389 wrench_menu_model_->UpdateZoomControls();
390
391 // If our zoom level changed, we need to tell the menu to update its state,
392 // since the menu could still be open.
393 wrench_menu_->UpdateMenu();
394 }
395
375 // content::NotificationObserver ----------------------------------------------- 396 // content::NotificationObserver -----------------------------------------------
376 397
377 void BrowserToolbarGtk::Observe(int type, 398 void BrowserToolbarGtk::Observe(int type,
378 const content::NotificationSource& source, 399 const content::NotificationSource& source,
379 const content::NotificationDetails& details) { 400 const content::NotificationDetails& details) {
380 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { 401 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) {
381 // Update the spacing around the menu buttons 402 // Update the spacing around the menu buttons
382 bool use_gtk = theme_service_->UsingNativeTheme(); 403 bool use_gtk = theme_service_->UsingNativeTheme();
383 int border = use_gtk ? 0 : 2; 404 int border = use_gtk ? 0 : 2;
384 gtk_container_set_border_width( 405 gtk_container_set_border_width(
(...skipping 24 matching lines...) Expand all
409 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); 430 theme_service_->GetRTLEnabledPixbufNamed(IDR_TOOLS));
410 } 431 }
411 432
412 UpdateRoundedness(); 433 UpdateRoundedness();
413 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) { 434 } else if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
414 // Redraw the wrench menu to update the badge. 435 // Redraw the wrench menu to update the badge.
415 gtk_widget_queue_draw(wrench_menu_button_->widget()); 436 gtk_widget_queue_draw(wrench_menu_button_->widget());
416 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { 437 } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) {
417 is_wrench_menu_model_valid_ = false; 438 is_wrench_menu_model_valid_ = false;
418 gtk_widget_queue_draw(wrench_menu_button_->widget()); 439 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 { 440 } else {
432 NOTREACHED(); 441 NOTREACHED();
433 } 442 }
434 } 443 }
435 444
436 // BrowserToolbarGtk, public --------------------------------------------------- 445 // BrowserToolbarGtk, public ---------------------------------------------------
437 446
438 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents, 447 void BrowserToolbarGtk::UpdateWebContents(WebContents* contents,
439 bool should_restore_state) { 448 bool should_restore_state) {
440 location_bar_->Update(should_restore_state ? contents : NULL); 449 location_bar_->Update(should_restore_state ? contents : NULL);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 allocation.x + x_offset, 706 allocation.x + x_offset,
698 allocation.y + y_offset); 707 allocation.y + y_offset);
699 708
700 return FALSE; 709 return FALSE;
701 } 710 }
702 711
703 void BrowserToolbarGtk::UpdateShowHomeButton() { 712 void BrowserToolbarGtk::UpdateShowHomeButton() {
704 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation(); 713 bool visible = show_home_button_.GetValue() && !ShouldOnlyShowLocation();
705 gtk_widget_set_visible(home_->widget(), visible); 714 gtk_widget_set_visible(home_->widget(), visible);
706 } 715 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698