summaryrefslogtreecommitdiff
path: root/chromium/ui/events/ozone/event_factory_ozone.h
blob: 489d4aebce1f485df4298cc862fe0706222daef1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2013 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 UI_EVENTS_OZONE_EVENT_FACTORY_OZONE_H_
#define UI_EVENTS_OZONE_EVENT_FACTORY_OZONE_H_

#include <map>

#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_pump_libevent.h"
#include "ui/events/events_export.h"
#include "ui/events/ozone/event_converter_ozone.h"

namespace ui {

class EventFactoryDelegateOzone;

// Creates and dispatches |ui.Event|'s. Ozone assumes that events arrive on file
// descriptors with one  |EventConverterOzone| instance for each descriptor.
// Ozone presumes that the set of file desctiprtors can vary at runtime so this
// class supports dynamically adding and removing |EventConverterOzone|
// instances as necessary.
class UI_EXPORT EventFactoryOzone {
 public:
  EventFactoryOzone();
  ~EventFactoryOzone();

  // Sets an optional delegate responsible for creating the starting set of
  // EventConvertOzones under management. This permits embedders to override the
  // Linux /dev/input/*-based default as desired. The caller must manage the
  // scope of this object.
  static void SetEventFactoryDelegateOzone(EventFactoryDelegateOzone* delegate);

  // Called from RootWindowHostOzone to create the starting set of event
  // converters.
  void CreateStartupEventConverters();

  // Add an |EventConverterOzone| instances for the given file descriptor.
  // Transfers ownership of the |EventConverterOzone| to this class.
  void AddEventConverter(int fd, scoped_ptr<EventConverterOzone> converter);

  // Remote the |EventConverterOzone|
  void RemoveEventConverter(int fd);

 private:
  // |EventConverterOzone| for each file descriptor.
  typedef EventConverterOzone* Converter;
  typedef base::MessagePumpLibevent::FileDescriptorWatcher* FDWatcher;
  std::map<int, Converter> converters_;
  std::map<int, FDWatcher> watchers_;

  static EventFactoryDelegateOzone* delegate_;

  DISALLOW_COPY_AND_ASSIGN(EventFactoryOzone);
};

}  // namespace ui

#endif  // UI_EVENTS_OZONE_EVENT_FACTORY_OZONE_H_