diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 13:41:09 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-22 13:41:09 +0000 |
commit | d6cfa34c68c058010e598257f5bf0092a13f843e (patch) | |
tree | 49151bfb627308d803168040dfca9f39af3ed171 /app | |
parent | 01a68053fc4b29a244326513ed1ef69869f1cead (diff) | |
download | chromium_src-d6cfa34c68c058010e598257f5bf0092a13f843e.zip chromium_src-d6cfa34c68c058010e598257f5bf0092a13f843e.tar.gz chromium_src-d6cfa34c68c058010e598257f5bf0092a13f843e.tar.bz2 |
[Mac] Give the Wrench menu keyboard shortcuts.
Note that these key equivalents are for display only and do not get fired. Commands are routed through the main menu/CommandUpdater.
BUG=45098
TEST=Open Wrench menu, see keyboard shortcuts.
Review URL: http://codereview.chromium.org/2800019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50452 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/app_base.gypi | 1 | ||||
-rw-r--r-- | app/menus/accelerator_cocoa.h | 58 |
2 files changed, 59 insertions, 0 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index 5cd97ee..facbd4c 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -158,6 +158,7 @@ 'linear_animation.h', 'menus/accelerator.h', 'menus/accelerator_gtk.h', + 'menus/accelerator_cocoa.h', 'menus/menu_model.cc', 'menus/menu_model.h', 'menus/simple_menu_model.cc', diff --git a/app/menus/accelerator_cocoa.h b/app/menus/accelerator_cocoa.h new file mode 100644 index 0000000..1866b4a --- /dev/null +++ b/app/menus/accelerator_cocoa.h @@ -0,0 +1,58 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APP_MENUS_ACCELERATOR_COCOA_H_ +#define APP_MENUS_ACCELERATOR_COCOA_H_ + +#include <Foundation/Foundation.h> + +#include "app/menus/accelerator.h" +#include "base/scoped_nsobject.h" + +namespace menus { + +// This is a subclass of the cross-platform Accelerator, but with more direct +// support for Cocoa key equivalents. Note that the typical use case for this +// class is to initialize it with a string literal, which is why it sends +// |-copy| to the |key_code| paramater in the constructor. +class AcceleratorCocoa : public Accelerator { + public: + AcceleratorCocoa(NSString* key_code, NSUInteger mask) + : Accelerator(base::VKEY_UNKNOWN, mask), + characters_([key_code copy]) { + } + + AcceleratorCocoa(const AcceleratorCocoa& accelerator) + : Accelerator(accelerator) { + characters_.reset([accelerator.characters_ copy]); + } + + AcceleratorCocoa() : Accelerator() {} + virtual ~AcceleratorCocoa() {} + + AcceleratorCocoa& operator=(const AcceleratorCocoa& accelerator) { + if (this != &accelerator) { + *static_cast<Accelerator*>(this) = accelerator; + characters_.reset([accelerator.characters_ copy]); + } + return *this; + } + + bool operator==(const AcceleratorCocoa& rhs) const { + return [characters_ isEqualToString:rhs.characters_.get()] && + (modifiers_ == rhs.modifiers_); + } + + NSString* characters() const { + return characters_.get(); + } + + private: + // String of characters for the key equivalent. + scoped_nsobject<NSString> characters_; +}; + +} // namespace menus + +#endif // APP_MENUS_ACCELERATOR_COCOA_H_ |