OLD | NEW |
---|---|
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. |
217 Source<Profile> source(browser->profile()); | |
218 registrar_.Add(this, | 217 registrar_.Add(this, |
219 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 218 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
220 source); | 219 NotificationService::AllSources()); |
Peter Kasting
2011/08/10 21:03:21
Nit: AllBrowserContextsAndSources()?
Might also w
Elliot Glaysher
2011/08/10 21:19:23
Done.
| |
221 Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 220 Observe(chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
222 source, NotificationService::NoDetails()); | 221 Source<Profile>(browser->profile()), |
222 NotificationService::NoDetails()); | |
223 } | 223 } |
224 | 224 |
225 GlobalMenuBar::~GlobalMenuBar() { | 225 GlobalMenuBar::~GlobalMenuBar() { |
226 Disable(); | 226 Disable(); |
227 g_object_unref(dummy_accel_group_); | 227 g_object_unref(dummy_accel_group_); |
228 } | 228 } |
229 | 229 |
230 void GlobalMenuBar::Disable() { | 230 void GlobalMenuBar::Disable() { |
231 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); | 231 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); |
232 it != id_to_menu_item_.end(); ++it) { | 232 it != id_to_menu_item_.end(); ++it) { |
233 browser_->command_updater()->RemoveCommandObserver(it->first, this); | 233 browser_->command_updater()->RemoveCommandObserver(it->first, this); |
234 } | 234 } |
235 id_to_menu_item_.clear(); | 235 id_to_menu_item_.clear(); |
236 Source<Profile> source(browser_->profile()); | 236 |
237 if (registrar_.IsRegistered(this, | 237 if (registrar_.IsRegistered(this, |
238 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 238 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
239 source)) { | 239 NotificationService::AllBrowserContextsAndSources())) { |
240 registrar_.Remove( | 240 registrar_.Remove( |
241 this, | 241 this, |
242 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 242 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
243 source); | 243 NotificationService::AllBrowserContextsAndSources()); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void GlobalMenuBar::BuildGtkMenuFrom( | 247 void GlobalMenuBar::BuildGtkMenuFrom( |
248 int menu_str_id, | 248 int menu_str_id, |
249 std::map<int, GtkWidget*>* id_to_menu_item, | 249 std::map<int, GtkWidget*>* id_to_menu_item, |
250 GlobalMenuBarCommand* commands, | 250 GlobalMenuBarCommand* commands, |
251 GlobalMenuOwner* owner) { | 251 GlobalMenuOwner* owner) { |
252 GtkWidget* menu = gtk_menu_new(); | 252 GtkWidget* menu = gtk_menu_new(); |
253 for (int i = 0; commands[i].str_id != MENU_END; ++i) { | 253 for (int i = 0; commands[i].str_id != MENU_END; ++i) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) { | 314 void GlobalMenuBar::EnabledStateChangedForCommand(int id, bool enabled) { |
315 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id); | 315 CommandIDMenuItemMap::iterator it = id_to_menu_item_.find(id); |
316 if (it != id_to_menu_item_.end()) | 316 if (it != id_to_menu_item_.end()) |
317 gtk_widget_set_sensitive(it->second, enabled); | 317 gtk_widget_set_sensitive(it->second, enabled); |
318 } | 318 } |
319 | 319 |
320 void GlobalMenuBar::Observe(int type, | 320 void GlobalMenuBar::Observe(int type, |
321 const NotificationSource& source, | 321 const NotificationSource& source, |
322 const NotificationDetails& details) { | 322 const NotificationDetails& details) { |
323 DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED); | 323 DCHECK_EQ(type, chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED); |
324 DCHECK_EQ(Source<Profile>(source).ptr(), browser_->profile()); | 324 |
325 if (!browser_->profile()->IsSameProfile(Source<Profile>(source).ptr())) | |
326 return; | |
325 | 327 |
326 CommandIDMenuItemMap::iterator it = | 328 CommandIDMenuItemMap::iterator it = |
327 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR); | 329 id_to_menu_item_.find(IDC_SHOW_BOOKMARK_BAR); |
328 if (it != id_to_menu_item_.end()) { | 330 if (it != id_to_menu_item_.end()) { |
329 PrefService* prefs = browser_->profile()->GetPrefs(); | 331 PrefService* prefs = browser_->profile()->GetPrefs(); |
330 | 332 |
331 block_activation_ = true; | 333 block_activation_ = true; |
332 gtk_check_menu_item_set_active( | 334 gtk_check_menu_item_set_active( |
333 GTK_CHECK_MENU_ITEM(it->second), | 335 GTK_CHECK_MENU_ITEM(it->second), |
334 prefs->GetBoolean(prefs::kShowBookmarkBar)); | 336 prefs->GetBoolean(prefs::kShowBookmarkBar)); |
335 block_activation_ = false; | 337 block_activation_ = false; |
336 } | 338 } |
337 } | 339 } |
338 | 340 |
339 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) { | 341 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) { |
340 if (block_activation_) | 342 if (block_activation_) |
341 return; | 343 return; |
342 | 344 |
343 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id")); | 345 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id")); |
344 browser_->ExecuteCommandIfEnabled(id); | 346 browser_->ExecuteCommandIfEnabled(id); |
345 } | 347 } |
OLD | NEW |