Home | History | Annotate | Download | only in events
      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 CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_CONTROLLER_H_
      6 #define CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_CONTROLLER_H_
      7 
      8 #include <list>
      9 #include <vector>
     10 
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/memory/scoped_vector.h"
     13 #include "ui/aura/env_observer.h"
     14 #include "ui/events/event_rewriter.h"
     15 
     16 namespace ui {
     17 class EventSource;
     18 }  // namespace ui
     19 
     20 namespace chromeos {
     21 
     22 // Owns |ui::EventRewriter|s and ensures that they are added to all root
     23 // windows |EventSource|s, current and future, in the order that they are
     24 // added to this.
     25 class EventRewriterController : public aura::EnvObserver {
     26  public:
     27   EventRewriterController();
     28   virtual ~EventRewriterController();
     29 
     30   // Takes ownership of an EventRewriter; can only be called before Init().
     31   void AddEventRewriter(scoped_ptr<ui::EventRewriter> rewriter);
     32 
     33   // Add rewriters to any existing root windows; must be called once only
     34   // after ash::Shell has been initialized.
     35   void Init();
     36 
     37   // aura::EnvObserver overrides:
     38   virtual void OnWindowInitialized(aura::Window* window) OVERRIDE {}
     39   virtual void OnHostInitialized(aura::WindowTreeHost* host) OVERRIDE;
     40 
     41  private:
     42   typedef std::list<ui::EventSource*> EventSourceList;
     43   typedef ScopedVector<ui::EventRewriter> EventRewriters;
     44 
     45   void AddToEventSource(ui::EventSource* source);
     46 
     47   // The |EventRewriter|s managed by this controller.
     48   EventRewriters rewriters_;
     49 
     50   // Whether the owned event rewriters have been added to existing
     51   // root windows; after this no more rewriters can be added.
     52   bool initialized_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(EventRewriterController);
     55 };
     56 
     57 }  // namespace chromeos
     58 
     59 #endif  // CHROME_BROWSER_CHROMEOS_EVENTS_EVENT_REWRITER_CONTROLLER_H_
     60