Home | History | Annotate | Download | only in input
      1 // Copyright 2014 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 ATHENA_INPUT_ACCELERATOR_MANAGER_H_
      6 #define ATHENA_INPUT_ACCELERATOR_MANAGER_H_
      7 
      8 #include "athena/input/public/accelerator_manager.h"
      9 
     10 #include <map>
     11 
     12 #include "base/macros.h"
     13 #include "ui/base/accelerators/accelerator.h"
     14 #include "ui/events/event_target_iterator.h"
     15 
     16 namespace aura {
     17 class Window;
     18 }
     19 
     20 namespace wm {
     21 class AcceleratorFilter;
     22 class NestedAcceleratorController;
     23 }
     24 
     25 namespace athena {
     26 
     27 // AcceleratorManagerImpl provides a API to register accelerators
     28 // for athena modules. It hides various details on accelerator handling
     29 // such as how to handle accelerator in a nested loop, reserved accelerators
     30 // and repeated accelerators.
     31 class AcceleratorManagerImpl : public AcceleratorManager,
     32                                public ui::AcceleratorTarget {
     33  public:
     34   class AcceleratorWrapper;
     35 
     36   // Creates an AcceleratorManager for global accelerators.
     37   // This is the one returned by AcceleratorManager::Get()
     38   static AcceleratorManagerImpl* CreateGlobalAcceleratorManager();
     39 
     40   // Creates an AcceleratorManager for focus manager.
     41   static scoped_ptr<AcceleratorManager> CreateForFocusManager(
     42       views::FocusManager* focus_manager);
     43 
     44   virtual ~AcceleratorManagerImpl();
     45 
     46   void Init();
     47 
     48   void OnRootWindowCreated(aura::Window* root_window);
     49 
     50   bool Process(const ui::Accelerator& accelerator);
     51 
     52   // AcceleratorManager:
     53   // This is made public so that implementation classes can use this.
     54   virtual bool IsRegistered(const ui::Accelerator& accelerator,
     55                             int flags) const OVERRIDE;
     56 
     57  private:
     58   class InternalData;
     59 
     60   explicit AcceleratorManagerImpl(AcceleratorWrapper* wrapper);
     61 
     62   // AcceleratorManager:
     63   virtual void RegisterAccelerators(const AcceleratorData accelerators[],
     64                                     size_t num_accelerators,
     65                                     AcceleratorHandler* handler) OVERRIDE;
     66   virtual void SetDebugAcceleratorsEnabled(bool enabled) OVERRIDE;
     67 
     68   // ui::AcceleratorTarget:
     69   virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
     70   virtual bool CanHandleAccelerators() const OVERRIDE;
     71 
     72   void RegisterAccelerator(const AcceleratorData& accelerator,
     73                            AcceleratorHandler* handler);
     74 
     75   std::map<ui::Accelerator, InternalData> accelerators_;
     76   scoped_ptr<AcceleratorWrapper> accelerator_wrapper_;
     77   scoped_ptr<wm::AcceleratorFilter> accelerator_filter_;
     78   scoped_ptr<wm::NestedAcceleratorController> nested_accelerator_controller_;
     79   bool debug_accelerators_enabled_;
     80 
     81   DISALLOW_COPY_AND_ASSIGN(AcceleratorManagerImpl);
     82 };
     83 
     84 }  // namespace athena
     85 
     86 #endif  // ATHENA_INPUT_ACCELERATOR_MANAGER_H_
     87