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

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

Issue 7610003: More. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 9 years, 4 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"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 "activate", 206 "activate",
207 dummy_accel_group_, 207 dummy_accel_group_,
208 accelerator_gtk->GetGdkKeyCode(), 208 accelerator_gtk->GetGdkKeyCode(),
209 accelerator_gtk->gdk_modifier_type(), 209 accelerator_gtk->gdk_modifier_type(),
210 GTK_ACCEL_VISIBLE); 210 GTK_ACCEL_VISIBLE);
211 } 211 }
212 212
213 browser_->command_updater()->AddCommandObserver(it->first, this); 213 browser_->command_updater()->AddCommandObserver(it->first, this);
214 } 214 }
215 215
216 // Listen for bookmark bar visibility changes and set the initial state. 216 // Listen for bookmark bar visibility changes and set the initial state; we
217 Source<Profile> source(browser->profile()); 217 // need to listen to all profiles because of normal profile/incognito issues.
Peter Kasting 2011/08/10 21:30:15 Nit: "issues" is vague, maybe use same comment as
218 registrar_.Add(this, 218 registrar_.Add(this,
219 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 219 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
220 source); 220 NotificationService::AllBrowserContextsAndSources());
221 Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 221 Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
222 source, NotificationService::NoDetails()); 222 Source<Profile>(browser->profile()),
223 NotificationService::NoDetails());
223 } 224 }
224 225
225 GlobalMenuBar::~GlobalMenuBar() { 226 GlobalMenuBar::~GlobalMenuBar() {
226 Disable(); 227 Disable();
227 g_object_unref(dummy_accel_group_); 228 g_object_unref(dummy_accel_group_);
228 } 229 }
229 230
230 void GlobalMenuBar::Disable() { 231 void GlobalMenuBar::Disable() {
231 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); 232 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin();
232 it != id_to_menu_item_.end(); ++it) { 233 it != id_to_menu_item_.end(); ++it) {
233 browser_->command_updater()->RemoveCommandObserver(it->first, this); 234 browser_->command_updater()->RemoveCommandObserver(it->first, this);
234 } 235 }
235 id_to_menu_item_.clear(); 236 id_to_menu_item_.clear();
236 Source<Profile> source(browser_->profile()); 237
237 if (registrar_.IsRegistered(this, 238 if (registrar_.IsRegistered(this,
238 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 239 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
239 source)) { 240 NotificationService::AllBrowserContextsAndSources())) {
240 registrar_.Remove( 241 registrar_.Remove(
241 this, 242 this,
242 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, 243 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED,
243 source); 244 NotificationService::AllBrowserContextsAndSources());
244 } 245 }
245 } 246 }
246 247
247 void GlobalMenuBar::BuildGtkMenuFrom( 248 void GlobalMenuBar::BuildGtkMenuFrom(
248 int menu_str_id, 249 int menu_str_id,
249 std::map<int, GtkWidget*>* id_to_menu_item, 250 std::map<int, GtkWidget*>* id_to_menu_item,
250 GlobalMenuBarCommand* commands, 251 GlobalMenuBarCommand* commands,
251 GlobalMenuOwner* owner) { 252 GlobalMenuOwner* owner) {
252 GtkWidget* menu = gtk_menu_new(); 253 GtkWidget* menu = gtk_menu_new();
253 for (int i = 0; commands[i].str_id != MENU_END; ++i) { 254 for (int i = 0; commands[i].str_id != MENU_END; ++i) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) { 315 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) {
315 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id); 316 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id);
316 if (it != id_to_menu_item_.end()) 317 if (it != id_to_menu_item_.end())
317 gtk_widget_set_sensitive(it->second, enabled); 318 gtk_widget_set_sensitive(it->second, enabled);
318 } 319 }
319 320
320 void GlobalMenuBar::Observe(int type, 321 void GlobalMenuBar::Observe(int type,
321 const NotificationSource& source, 322 const NotificationSource& source,
322 const NotificationDetails& details) { 323 const NotificationDetails& details) {
323 DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED); 324 DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED);
324 DCHECK_EQ(Source<Profile>(source).ptr(), browser_->profile()); 325
326 if (!browser_->profile()->IsSameProfile(Source<Profile>(source).ptr()))
327 return;
325 328
326 CommandIDMenuItemMap::iterator it = 329 CommandIDMenuItemMap::iterator it =
327 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR); 330 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR);
328 if (it != id_to_menu_item_.end()) { 331 if (it != id_to_menu_item_.end()) {
329 PrefService* prefs = browser_->profile()->GetPrefs(); 332 PrefService* prefs = browser_->profile()->GetPrefs();
330 333
331 block_activation_ = true; 334 block_activation_ = true;
332 gtk_check_menu_item_set_active( 335 gtk_check_menu_item_set_active(
333 GTK_CHECK_MENU_ITEM(it->second), 336 GTK_CHECK_MENU_ITEM(it->second),
334 prefs->GetBoolean(prefs::kShowBookmarkBar)); 337 prefs->GetBoolean(prefs::kShowBookmarkBar));
335 block_activation_ = false; 338 block_activation_ = false;
336 } 339 }
337 } 340 }
338 341
339 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) { 342 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) {
340 if (block_activation_) 343 if (block_activation_)
341 return; 344 return;
342 345
343 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id")); 346 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id"));
344 browser_->ExecuteCommandIfEnabled(id); 347 browser_->ExecuteCommandIfEnabled(id);
345 } 348 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698