| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef COMPONENTS_MUS_WS_ACCELERATOR_H_ | 5 #ifndef COMPONENTS_MUS_WS_ACCELERATOR_H_ |
| 6 #define COMPONENTS_MUS_WS_ACCELERATOR_H_ | 6 #define COMPONENTS_MUS_WS_ACCELERATOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "components/mus/public/interfaces/input_event_matcher.mojom.h" | 12 #include "components/mus/public/interfaces/input_event_matcher.mojom.h" |
| 13 #include "ui/events/event.h" | 13 #include "components/mus/ws/event_matcher.h" |
| 14 #include "ui/gfx/geometry/rect_f.h" | 14 |
| 15 namespace ui { |
| 16 class Event; |
| 17 } |
| 15 | 18 |
| 16 namespace mus { | 19 namespace mus { |
| 17 namespace ws { | 20 namespace ws { |
| 18 | 21 |
| 19 // An Accelerator encompasses an id defined by the client, along with a unique | 22 // An Accelerator encompasses an id defined by the client, along with a unique |
| 20 // mojom::EventMatcher. See WindowManagerClient. | 23 // mojom::EventMatcher. See WindowManagerClient. |
| 21 // | 24 // |
| 22 // This provides a WeakPtr, as the client might delete the accelerator between | 25 // This provides a WeakPtr, as the client might delete the accelerator between |
| 23 // an event having been matched and the dispatch of the accelerator to the | 26 // an event having been matched and the dispatch of the accelerator to the |
| 24 // client. | 27 // client. |
| 25 class Accelerator { | 28 class Accelerator { |
| 26 public: | 29 public: |
| 27 Accelerator(uint32_t id, const mojom::EventMatcher& matcher); | 30 Accelerator(uint32_t id, const mojom::EventMatcher& matcher); |
| 28 ~Accelerator(); | 31 ~Accelerator(); |
| 29 | 32 |
| 30 // Returns true if |event| and |phase | matches the definition in the | 33 // Returns true if |event| and |phase | matches the definition in the |
| 31 // mojom::EventMatcher used for initialization. | 34 // mojom::EventMatcher used for initialization. |
| 32 bool MatchesEvent(const ui::Event& event, | 35 bool MatchesEvent(const ui::Event& event, |
| 33 const mojom::AcceleratorPhase phase) const; | 36 const mojom::AcceleratorPhase phase) const; |
| 34 | 37 |
| 35 // Returns true if |other| was created with an identical mojom::EventMatcher. | 38 // Returns true if |other| was created with an identical mojom::EventMatcher. |
| 36 bool EqualEventMatcher(const Accelerator* other) const; | 39 bool EqualEventMatcher(const Accelerator* other) const; |
| 37 | 40 |
| 38 base::WeakPtr<Accelerator> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 41 base::WeakPtr<Accelerator> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 39 | 42 |
| 40 uint32_t id() const { return id_; } | 43 uint32_t id() const { return id_; } |
| 41 | 44 |
| 42 private: | 45 private: |
| 43 enum MatchFields { | |
| 44 NONE = 0, | |
| 45 TYPE = 1 << 0, | |
| 46 FLAGS = 1 << 1, | |
| 47 KEYBOARD_CODE = 1 << 2, | |
| 48 POINTER_KIND = 1 << 3, | |
| 49 POINTER_LOCATION = 1 << 4, | |
| 50 }; | |
| 51 | |
| 52 uint32_t id_; | 46 uint32_t id_; |
| 53 uint32_t fields_to_match_; | |
| 54 mojom::AcceleratorPhase accelerator_phase_; | 47 mojom::AcceleratorPhase accelerator_phase_; |
| 55 ui::EventType event_type_; | 48 EventMatcher event_matcher_; |
| 56 // Bitfields of kEventFlag* and kMouseEventFlag* values in | |
| 57 // input_event_constants.mojom. | |
| 58 int event_flags_; | |
| 59 int ignore_event_flags_; | |
| 60 uint16_t keyboard_code_; | |
| 61 ui::EventPointerType pointer_type_; | |
| 62 gfx::RectF pointer_region_; | |
| 63 | |
| 64 base::WeakPtrFactory<Accelerator> weak_factory_; | 49 base::WeakPtrFactory<Accelerator> weak_factory_; |
| 65 | 50 |
| 66 DISALLOW_COPY_AND_ASSIGN(Accelerator); | 51 DISALLOW_COPY_AND_ASSIGN(Accelerator); |
| 67 }; | 52 }; |
| 68 | 53 |
| 69 } // namespace ws | 54 } // namespace ws |
| 70 } // namespace mus | 55 } // namespace mus |
| 71 | 56 |
| 72 #endif // COMPONENTS_MUS_WS_ACCELERATOR_H_ | 57 #endif // COMPONENTS_MUS_WS_ACCELERATOR_H_ |
| OLD | NEW |