BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / accelerators_cocoa.h
blob5c8961976e1c05471dd2acbf01c663b10f059fdd
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.
5 #ifndef CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_
6 #define CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_
8 #import <Cocoa/Cocoa.h>
10 #include <map>
11 #include <vector>
13 #include "base/gtest_prod_util.h"
14 #include "ui/base/accelerators/accelerator.h"
16 namespace base {
17 template <typename T>
18 struct DefaultSingletonTraits;
19 } // namespace base
21 // This class maintains a map of command_ids to Accelerator objects (see
22 // chrome/app/chrome_command_ids.h). Currently, this only lists the commands
23 // that are used in the Wrench menu.
25 // It is recommended that this class be used as a singleton so that the key map
26 // isn't created multiple places.
28 // #import "base/memory/singleton.h"
29 // ...
30 // AcceleratorsCocoa* keymap = AcceleratorsCocoa::GetInstance();
31 // return keymap->GetAcceleratorForCommand(IDC_COPY);
33 class AcceleratorsCocoa {
34 public:
35 typedef std::map<int, ui::Accelerator> AcceleratorMap;
36 typedef std::vector<ui::Accelerator> AcceleratorVector;
37 typedef AcceleratorMap::const_iterator const_iterator;
39 const_iterator const begin() { return accelerators_.begin(); }
40 const_iterator const end() { return accelerators_.end(); }
42 // Returns NULL if there is no accelerator for the command.
43 const ui::Accelerator* GetAcceleratorForCommand(int command_id);
44 // Searches the list of accelerators without a command_id for an accelerator
45 // that matches the given |key_equivalent| and |modifiers|.
46 const ui::Accelerator* GetAcceleratorForHotKey(NSString* key_equivalent,
47 NSUInteger modifiers) const;
49 // Returns the singleton instance.
50 static AcceleratorsCocoa* GetInstance();
52 private:
53 friend struct base::DefaultSingletonTraits<AcceleratorsCocoa>;
54 FRIEND_TEST_ALL_PREFIXES(AcceleratorsCocoaBrowserTest,
55 MappingAcceleratorsInMainMenu);
57 AcceleratorsCocoa();
58 ~AcceleratorsCocoa();
60 // A map from command_id to Accelerator. The accelerator is fully filled out,
61 // and its platform_accelerator is also fully filled out.
62 // Contains accelerators from both the wrench menu and the main menu.
63 AcceleratorMap accelerators_;
64 // A list of accelerators used in the main menu that have no associated
65 // command_id. The accelerator is fully filled out, and its
66 // platform_accelerator is also fully filled out.
67 AcceleratorVector accelerator_vector_;
69 DISALLOW_COPY_AND_ASSIGN(AcceleratorsCocoa);
72 #endif // CHROME_BROWSER_UI_COCOA_ACCELERATORS_COCOA_H_