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

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

Issue 8135001: Fixed behavior of the bookmark bar visibility. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 9 years, 2 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) 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/global_menu_bar.h" 5 #include "chrome/browser/ui/gtk/global_menu_bar.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/gtk/accelerators_gtk.h" 14 #include "chrome/browser/ui/gtk/accelerators_gtk.h"
15 #include "chrome/browser/ui/gtk/global_bookmark_menu.h"
15 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 16 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
16 #include "chrome/browser/ui/gtk/gtk_util.h" 17 #include "chrome/browser/ui/gtk/gtk_util.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/pref_names.h" 20 #include "chrome/common/pref_names.h"
21 #include "content/common/notification_details.h"
20 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
21 #include "content/common/notification_source.h" 23 #include "content/common/notification_source.h"
22 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/gtk_util.h" 26 #include "ui/gfx/gtk_util.h"
25 27
26 struct GlobalMenuBarCommand { 28 struct GlobalMenuBarCommand {
27 int str_id; 29 int str_id;
28 int command; 30 int command;
29 int tag; 31 int tag;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 "activate", 208 "activate",
207 dummy_accel_group_, 209 dummy_accel_group_,
208 accelerator_gtk->GetGdkKeyCode(), 210 accelerator_gtk->GetGdkKeyCode(),
209 accelerator_gtk->gdk_modifier_type(), 211 accelerator_gtk->gdk_modifier_type(),
210 GTK_ACCEL_VISIBLE); 212 GTK_ACCEL_VISIBLE);
211 } 213 }
212 214
213 browser_->command_updater()->AddCommandObserver(it->first, this); 215 browser_->command_updater()->AddCommandObserver(it->first, this);
214 } 216 }
215 217
216 // We listen to all notification sources because the bookmark bar 218 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
217 // state needs to stay in sync between the incognito and normal profiles. 219 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
218 registrar_.Add(this, 220 OnBookmarkBarVisibilityChanged();
219 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
220 NotificationService::AllBrowserContextsAndSources());
221 Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
222 Source<Profile>(browser->profile()),
223 NotificationService::NoDetails());
224 } 221 }
225 222
226 GlobalMenuBar::~GlobalMenuBar() { 223 GlobalMenuBar::~GlobalMenuBar() {
227 Disable(); 224 Disable();
228 g_object_unref(dummy_accel_group_); 225 g_object_unref(dummy_accel_group_);
229 } 226 }
230 227
231 void GlobalMenuBar::Disable() { 228 void GlobalMenuBar::Disable() {
232 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); 229 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin();
233 it != id_to_menu_item_.end(); ++it) { 230 it != id_to_menu_item_.end(); ++it) {
234 browser_->command_updater()->RemoveCommandObserver(it->first, this); 231 browser_->command_updater()->RemoveCommandObserver(it->first, this);
235 } 232 }
236 id_to_menu_item_.clear(); 233 id_to_menu_item_.clear();
237 234
238 if (registrar_.IsRegistered(this, 235 pref_change_registrar_.RemoveAll();
239 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
240 NotificationService::AllBrowserContextsAndSources())) {
241 registrar_.Remove(
242 this,
243 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
244 NotificationService::AllBrowserContextsAndSources());
245 }
246 } 236 }
247 237
248 void GlobalMenuBar::BuildGtkMenuFrom( 238 void GlobalMenuBar::BuildGtkMenuFrom(
249 int menu_str_id, 239 int menu_str_id,
250 std::map<int, GtkWidget*>* id_to_menu_item, 240 std::map<int, GtkWidget*>* id_to_menu_item,
251 GlobalMenuBarCommand* commands, 241 GlobalMenuBarCommand* commands,
252 GlobalMenuOwner* owner) { 242 GlobalMenuOwner* owner) {
253 GtkWidget* menu = gtk_menu_new(); 243 GtkWidget* menu = gtk_menu_new();
254 for (int i = 0; commands[i].str_id != MENU_END; ++i) { 244 for (int i = 0; commands[i].str_id != MENU_END; ++i) {
255 GtkWidget* menu_item = BuildMenuItem( 245 GtkWidget* menu_item = BuildMenuItem(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 304
315 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) { 305 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) {
316 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id); 306 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id);
317 if (it != id_to_menu_item_.end()) 307 if (it != id_to_menu_item_.end())
318 gtk_widget_set_sensitive(it->second, enabled); 308 gtk_widget_set_sensitive(it->second, enabled);
319 } 309 }
320 310
321 void GlobalMenuBar::Observe(int type, 311 void GlobalMenuBar::Observe(int type,
322 const NotificationSource& source, 312 const NotificationSource& source,
323 const NotificationDetails& details) { 313 const NotificationDetails& details) {
324 DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED); 314 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
Evan Stade 2011/10/10 21:33:15 I prefer DCHECKs to if/NOTREACHED. Easier to read.
Joao da Silva 2011/10/10 21:44:28 Done.
315 const std::string& pref_name = *Details<std::string>(details).ptr();
316 if (pref_name == prefs::kShowBookmarkBar)
317 OnBookmarkBarVisibilityChanged();
318 else
319 NOTREACHED();
320 } else {
321 NOTREACHED();
322 }
323 }
325 324
326 if (!browser_->profile()->IsSameProfile(Source<Profile>(source).ptr())) 325 void GlobalMenuBar::OnBookmarkBarVisibilityChanged() {
327 return;
328
329 CommandIDMenuItemMap::iterator it = 326 CommandIDMenuItemMap::iterator it =
330 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR); 327 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR);
331 if (it != id_to_menu_item_.end()) { 328 if (it != id_to_menu_item_.end()) {
332 PrefService* prefs = browser_->profile()->GetPrefs(); 329 PrefService* prefs = browser_->profile()->GetPrefs();
333
334 block_activation_ = true; 330 block_activation_ = true;
335 gtk_check_menu_item_set_active( 331 gtk_check_menu_item_set_active(
336 GTK_CHECK_MENU_ITEM(it->second), 332 GTK_CHECK_MENU_ITEM(it->second),
337 prefs->GetBoolean(prefs::kShowBookmarkBar)); 333 prefs->GetBoolean(prefs::kShowBookmarkBar));
338 block_activation_ = false; 334 block_activation_ = false;
339 } 335 }
340 } 336 }
341 337
342 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) { 338 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) {
343 if (block_activation_) 339 if (block_activation_)
344 return; 340 return;
345 341
346 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id")); 342 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id"));
347 browser_->ExecuteCommandIfEnabled(id); 343 browser_->ExecuteCommandIfEnabled(id);
348 } 344 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/global_menu_bar.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_context_menu_controller_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698