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