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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ 6 #define CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ 7 8 #include <map> 9 10 #include "ui/base/accelerators/accelerator.h" 11 12 template <typename T> struct DefaultSingletonTraits; 13 14 // This class maintains a map of command_ids to Accelerator objects (see 15 // chrome/app/chrome_command_ids.h). Currently, this only lists the commands 16 // that are used in the Wrench menu. 17 // 18 // It is recommended that this class be used as a singleton so that the key map 19 // isn't created multiple places. 20 // 21 // #import "base/memory/singleton.h" 22 // ... 23 // AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance(); 24 // return keymap->GetAcceleratorForCommand(IDC_COPY); 25 // 26 class AcceleratorsCocoa { 27 public: 28 typedef std::map<int, ui::Accelerator> AcceleratorMap; 29 typedef AcceleratorMap::const_iterator const_iterator; 30 begin()31 const_iterator const begin() { return accelerators_.begin(); } end()32 const_iterator const end() { return accelerators_.end(); } 33 34 // Returns NULL if there is no accelerator for the command. 35 const ui::Accelerator* GetAcceleratorForCommand(int command_id); 36 37 // Returns the singleton instance. 38 static AcceleratorsCocoa* GetInstance(); 39 40 private: 41 friend struct DefaultSingletonTraits<AcceleratorsCocoa>; 42 43 AcceleratorsCocoa(); 44 ~AcceleratorsCocoa(); 45 46 AcceleratorMap accelerators_; 47 48 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa); 49 }; 50 51 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_ 52