| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2014 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
 | 
					
						
							|  |  |  | #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2018-11-07 09:40:38 -08:00
										 |  |  | #include <vector>
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-02-03 12:43:42 +01:00
										 |  |  | #include "base/functional/callback.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | #include "chrome/browser/extensions/global_shortcut_listener.h"
 | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  | #include "gin/handle.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:33:45 -07:00
										 |  |  | #include "gin/wrappable.h"
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | #include "ui/base/accelerators/accelerator.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | namespace electron::api { | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-21 14:21:31 -05:00
										 |  |  | class GlobalShortcut : private extensions::GlobalShortcutListener::Observer, | 
					
						
							| 
									
										
										
										
											2020-03-19 14:33:45 -07:00
										 |  |  |                        public gin::Wrappable<GlobalShortcut> { | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  |  public: | 
					
						
							| 
									
										
										
										
											2019-10-25 22:03:28 +09:00
										 |  |  |   static gin::Handle<GlobalShortcut> Create(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-19 14:33:45 -07:00
										 |  |  |   // gin::Wrappable
 | 
					
						
							|  |  |  |   static gin::WrapperInfo kWrapperInfo; | 
					
						
							|  |  |  |   gin::ObjectTemplateBuilder GetObjectTemplateBuilder( | 
					
						
							|  |  |  |       v8::Isolate* isolate) override; | 
					
						
							|  |  |  |   const char* GetTypeName() override; | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-03 12:41:45 +01:00
										 |  |  |   // disable copy
 | 
					
						
							|  |  |  |   GlobalShortcut(const GlobalShortcut&) = delete; | 
					
						
							|  |  |  |   GlobalShortcut& operator=(const GlobalShortcut&) = delete; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2016-04-25 10:17:54 +09:00
										 |  |  |   explicit GlobalShortcut(v8::Isolate* isolate); | 
					
						
							| 
									
										
										
										
											2015-11-04 18:21:03 +08:00
										 |  |  |   ~GlobalShortcut() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2021-05-06 15:01:04 -07:00
										 |  |  |   typedef std::map<ui::Accelerator, base::RepeatingClosure> | 
					
						
							|  |  |  |       AcceleratorCallbackMap; | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-07 09:40:38 -08:00
										 |  |  |   bool RegisterAll(const std::vector<ui::Accelerator>& accelerators, | 
					
						
							| 
									
										
										
										
											2021-05-06 15:01:04 -07:00
										 |  |  |                    const base::RepeatingClosure& callback); | 
					
						
							| 
									
										
										
										
											2014-08-05 00:00:39 +08:00
										 |  |  |   bool Register(const ui::Accelerator& accelerator, | 
					
						
							| 
									
										
										
										
											2021-05-06 15:01:04 -07:00
										 |  |  |                 const base::RepeatingClosure& callback); | 
					
						
							| 
									
										
										
										
											2014-08-05 00:00:39 +08:00
										 |  |  |   bool IsRegistered(const ui::Accelerator& accelerator); | 
					
						
							|  |  |  |   void Unregister(const ui::Accelerator& accelerator); | 
					
						
							| 
									
										
										
										
											2018-11-07 09:40:38 -08:00
										 |  |  |   void UnregisterSome(const std::vector<ui::Accelerator>& accelerators); | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  |   void UnregisterAll(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // GlobalShortcutListener::Observer implementation.
 | 
					
						
							| 
									
										
										
										
											2015-01-09 17:24:36 -08:00
										 |  |  |   void OnKeyPressed(const ui::Accelerator& accelerator) override; | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   AcceleratorCallbackMap accelerator_callback_map_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-29 12:55:47 -07:00
										 |  |  | }  // namespace electron::api
 | 
					
						
							| 
									
										
										
										
											2014-07-31 12:22:29 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #endif  // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_GLOBAL_SHORTCUT_H_
 |