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

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

Issue 10677009: Move command handling and updating off Browser and onto a helper object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/browser/ui/gtk/global_menu_bar.h ('k') | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/browser_commands.h"
14 #include "chrome/browser/ui/gtk/accelerators_gtk.h" 15 #include "chrome/browser/ui/gtk/accelerators_gtk.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"
20 #include "content/public/browser/notification_details.h" 21 #include "content/public/browser/notification_details.h"
21 #include "content/public/browser/notification_source.h" 22 #include "content/public/browser/notification_source.h"
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
23 #include "ui/base/gtk/menu_label_accelerator_util.h" 24 #include "ui/base/gtk/menu_label_accelerator_util.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 BuildGtkMenuFrom(IDS_VIEW_MENU_LINUX, &id_to_menu_item_, view_menu, NULL); 163 BuildGtkMenuFrom(IDS_VIEW_MENU_LINUX, &id_to_menu_item_, view_menu, NULL);
163 BuildGtkMenuFrom(IDS_HISTORY_MENU_LINUX, &id_to_menu_item_, 164 BuildGtkMenuFrom(IDS_HISTORY_MENU_LINUX, &id_to_menu_item_,
164 history_menu, &history_menu_); 165 history_menu, &history_menu_);
165 166
166 BuildGtkMenuFrom(IDS_TOOLS_MENU_LINUX, &id_to_menu_item_, tools_menu, NULL); 167 BuildGtkMenuFrom(IDS_TOOLS_MENU_LINUX, &id_to_menu_item_, tools_menu, NULL);
167 BuildGtkMenuFrom(IDS_HELP_MENU_LINUX, &id_to_menu_item_, help_menu, NULL); 168 BuildGtkMenuFrom(IDS_HELP_MENU_LINUX, &id_to_menu_item_, help_menu, NULL);
168 169
169 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); 170 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin();
170 it != id_to_menu_item_.end(); ++it) { 171 it != id_to_menu_item_.end(); ++it) {
171 // Get the starting enabled state. 172 // Get the starting enabled state.
172 gtk_widget_set_sensitive( 173 gtk_widget_set_sensitive(it->second,
173 it->second, 174 chrome::IsCommandEnabled(browser_, it->first));
174 browser_->command_updater()->IsCommandEnabled(it->first));
175 175
176 // Set the accelerator for each menu item. 176 // Set the accelerator for each menu item.
177 AcceleratorsGtk* accelerators = AcceleratorsGtk::GetInstance(); 177 AcceleratorsGtk* accelerators = AcceleratorsGtk::GetInstance();
178 const ui::AcceleratorGtk* accelerator = 178 const ui::AcceleratorGtk* accelerator =
179 accelerators->GetPrimaryAcceleratorForCommand(it->first); 179 accelerators->GetPrimaryAcceleratorForCommand(it->first);
180 if (accelerator) { 180 if (accelerator) {
181 gtk_widget_add_accelerator(it->second, 181 gtk_widget_add_accelerator(it->second,
182 "activate", 182 "activate",
183 dummy_accel_group_, 183 dummy_accel_group_,
184 accelerator->GetGdkKeyCode(), 184 accelerator->GetGdkKeyCode(),
185 accelerator->gdk_modifier_type(), 185 accelerator->gdk_modifier_type(),
186 GTK_ACCEL_VISIBLE); 186 GTK_ACCEL_VISIBLE);
187 } 187 }
188 188
189 browser_->command_updater()->AddCommandObserver(it->first, this); 189 chrome::AddCommandObserver(browser_, it->first, this);
190 } 190 }
191 191
192 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); 192 pref_change_registrar_.Init(browser_->profile()->GetPrefs());
193 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); 193 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this);
194 OnBookmarkBarVisibilityChanged(); 194 OnBookmarkBarVisibilityChanged();
195 } 195 }
196 196
197 GlobalMenuBar::~GlobalMenuBar() { 197 GlobalMenuBar::~GlobalMenuBar() {
198 Disable(); 198 Disable();
199 g_object_unref(dummy_accel_group_); 199 g_object_unref(dummy_accel_group_);
200 } 200 }
201 201
202 void GlobalMenuBar::Disable() { 202 void GlobalMenuBar::Disable() {
203 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin(); 203 for (CommandIDMenuItemMap::const_iterator it = id_to_menu_item_.begin();
204 it != id_to_menu_item_.end(); ++it) { 204 it != id_to_menu_item_.end(); ++it) {
205 browser_->command_updater()->RemoveCommandObserver(it->first, this); 205 chrome::RemoveCommandObserver(browser_, it->first, this);
206 } 206 }
207 id_to_menu_item_.clear(); 207 id_to_menu_item_.clear();
208 208
209 pref_change_registrar_.RemoveAll(); 209 pref_change_registrar_.RemoveAll();
210 } 210 }
211 211
212 void GlobalMenuBar::BuildGtkMenuFrom( 212 void GlobalMenuBar::BuildGtkMenuFrom(
213 int menu_str_id, 213 int menu_str_id,
214 std::map<int, GtkWidget*>* id_to_menu_item, 214 std::map<int, GtkWidget*>* id_to_menu_item,
215 GlobalMenuBarCommand* commands, 215 GlobalMenuBarCommand* commands,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 prefs->GetBoolean(prefs::kShowBookmarkBar)); 301 prefs->GetBoolean(prefs::kShowBookmarkBar));
302 block_activation_ = false; 302 block_activation_ = false;
303 } 303 }
304 } 304 }
305 305
306 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) { 306 void GlobalMenuBar::OnItemActivated(GtkWidget* sender) {
307 if (block_activation_) 307 if (block_activation_)
308 return; 308 return;
309 309
310 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id")); 310 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(sender), "command-id"));
311 browser_->ExecuteCommandIfEnabled(id); 311 chrome::ExecuteCommand(browser_, id);
312 } 312 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/global_menu_bar.h ('k') | chrome/browser/ui/gtk/location_bar_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698