Home | History | Annotate | Download | only in platform
      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 UI_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_
      6 #define UI_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_
      7 
      8 #include "base/auto_reset.h"
      9 #include "base/basictypes.h"
     10 #include "ui/events/events_export.h"
     11 
     12 namespace ui {
     13 
     14 class PlatformEventDispatcher;
     15 
     16 // A temporary PlatformEventDispatcher can be installed on a
     17 // PlatformEventSource that overrides all installed event dispatchers, and
     18 // always gets a chance to dispatch the event first. The PlatformEventSource
     19 // returns a ScopedEventDispatcher object in such cases. This
     20 // ScopedEventDispatcher object can be used to dispatch the event to any
     21 // previous overridden dispatcher. When this object is destroyed, it removes the
     22 // override-dispatcher, and restores the previous override-dispatcher.
     23 class EVENTS_EXPORT ScopedEventDispatcher {
     24  public:
     25   ScopedEventDispatcher(PlatformEventDispatcher** scoped_dispatcher,
     26                         PlatformEventDispatcher* new_dispatcher);
     27   ~ScopedEventDispatcher();
     28 
     29   operator PlatformEventDispatcher*() const { return original_; }
     30 
     31  private:
     32   PlatformEventDispatcher* original_;
     33   base::AutoReset<PlatformEventDispatcher*> restore_;
     34 
     35   DISALLOW_COPY_AND_ASSIGN(ScopedEventDispatcher);
     36 };
     37 
     38 }  // namespace ui
     39 
     40 #endif  // UI_EVENTS_PLATFORM_SCOPED_EVENT_DISPATCHER_H_
     41