OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 InputDeviceCapabilities_h | 5 #ifndef InputDeviceCapabilities_h |
6 #define InputDeviceCapabilities_h | 6 #define InputDeviceCapabilities_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
10 #include "core/input/InputDeviceCapabilitiesInit.h" | 10 #include "core/input/InputDeviceCapabilitiesInit.h" |
11 | 11 |
12 namespace blink { | 12 namespace blink { |
13 | 13 |
| 14 class DOMWindow; |
| 15 |
14 class CORE_EXPORT InputDeviceCapabilities final | 16 class CORE_EXPORT InputDeviceCapabilities final |
15 : public GarbageCollected<InputDeviceCapabilities>, | 17 : public GarbageCollected<InputDeviceCapabilities>, |
16 public ScriptWrappable { | 18 public ScriptWrappable { |
17 DEFINE_WRAPPERTYPEINFO(); | 19 DEFINE_WRAPPERTYPEINFO(); |
18 | 20 |
19 public: | 21 public: |
20 static InputDeviceCapabilities* create(bool firesTouchEvents) { | 22 enum Descriptor { |
21 return new InputDeviceCapabilities(firesTouchEvents); | 23 // |Null| represents a null InputDeviceCapabilities*. |
| 24 Null = 0x0, |
| 25 // |None| represents an empty InputDeviceCapabilities instance with |
| 26 // no capabilities. |
| 27 None = 0x1, |
| 28 FiresTouchEvents = 0x2, |
| 29 }; |
| 30 |
| 31 static InputDeviceCapabilities* create(Descriptor descriptor) { |
| 32 return new InputDeviceCapabilities(descriptor); |
22 } | 33 } |
23 | 34 |
24 static InputDeviceCapabilities* create( | 35 static InputDeviceCapabilities* create( |
25 const InputDeviceCapabilitiesInit& initializer) { | 36 const InputDeviceCapabilitiesInit& initializer) { |
26 return new InputDeviceCapabilities(initializer); | 37 return new InputDeviceCapabilities(initializer); |
27 } | 38 } |
28 | 39 |
29 bool firesTouchEvents() const { return m_firesTouchEvents; } | 40 bool firesTouchEvents() const { return m_firesTouchEvents; } |
30 | 41 |
31 DEFINE_INLINE_TRACE() {} | 42 DEFINE_INLINE_TRACE() {} |
32 | 43 |
33 private: | 44 private: |
34 InputDeviceCapabilities(bool firesTouchEvents); | 45 explicit InputDeviceCapabilities(Descriptor); |
35 InputDeviceCapabilities(const InputDeviceCapabilitiesInit&); | 46 explicit InputDeviceCapabilities(const InputDeviceCapabilitiesInit&); |
36 | 47 |
37 // Whether this device dispatches touch events. This mainly lets developers | 48 // Whether this device dispatches touch events. This mainly lets developers |
38 // avoid handling both touch and mouse events dispatched for a single user | 49 // avoid handling both touch and mouse events dispatched for a single user |
39 // action. | 50 // action. |
40 bool m_firesTouchEvents; | 51 bool m_firesTouchEvents; |
41 }; | 52 }; |
42 | 53 |
43 // Grouping constant-valued InputDeviceCapabilities objects together, | 54 // To be able to delay the creation of InputDeviceCapabilities instances |
44 // which is kept and used by each 'view' (DOMWindow) that dispatches | 55 // until requested from script, we characterize the capabilities by a |
45 // events parameterized over InputDeviceCapabilities. | 56 // descriptor and propagate its value internally. |
46 // | 57 class InputDeviceCapabilitiesValue final { |
47 // TODO(sof): lazily instantiate InputDeviceCapabilities instances upon | 58 DISALLOW_NEW(); |
48 // UIEvent access instead. This would allow internal tracking of such | 59 |
49 // capabilities by value. | 60 public: |
| 61 InputDeviceCapabilitiesValue() |
| 62 : m_descriptor(InputDeviceCapabilities::Null) {} |
| 63 |
| 64 InputDeviceCapabilitiesValue(const InputDeviceCapabilities::Descriptor desc) |
| 65 : m_descriptor(desc) {} |
| 66 |
| 67 // Provided for convenience while InputDeviceCapabilities only supports |
| 68 // a single capability. |
| 69 explicit InputDeviceCapabilitiesValue(bool firesTouchEvents) |
| 70 : m_descriptor(firesTouchEvents |
| 71 ? InputDeviceCapabilities::FiresTouchEvents |
| 72 : InputDeviceCapabilities::None) {} |
| 73 |
| 74 explicit InputDeviceCapabilitiesValue(InputDeviceCapabilities* capabilities) |
| 75 : m_descriptor(InputDeviceCapabilities::Null), |
| 76 m_capabilities(capabilities) {} |
| 77 |
| 78 InputDeviceCapabilitiesValue(const InputDeviceCapabilitiesValue& other) |
| 79 : m_descriptor(other.m_descriptor), |
| 80 m_capabilities(other.m_capabilities) {} |
| 81 |
| 82 InputDeviceCapabilities* getCapabilities(DOMWindow*); |
| 83 |
| 84 DEFINE_INLINE_TRACE() { visitor->trace(m_capabilities); } |
| 85 |
| 86 private: |
| 87 InputDeviceCapabilities::Descriptor m_descriptor; |
| 88 Member<InputDeviceCapabilities> m_capabilities; |
| 89 }; |
| 90 |
| 91 // Grouping a DOMWindow's InputDeviceCapabilities objects together. |
50 class InputDeviceCapabilitiesConstants final | 92 class InputDeviceCapabilitiesConstants final |
51 : public GarbageCollected<InputDeviceCapabilitiesConstants> { | 93 : public GarbageCollected<InputDeviceCapabilitiesConstants> { |
52 public: | 94 public: |
53 // Returns an InputDeviceCapabilities which has | 95 // Returns an InputDeviceCapabilities which has |
54 // |firesTouchEvents| set to value of |firesTouch|. | 96 // |firesTouchEvents| set to value of |firesTouch|. |
55 InputDeviceCapabilities* firesTouchEvents(bool firesTouch); | 97 InputDeviceCapabilities* get(InputDeviceCapabilities::Descriptor); |
56 | 98 |
57 DEFINE_INLINE_TRACE() { | 99 DEFINE_INLINE_TRACE() { |
58 visitor->trace(m_firesTouchEvents); | 100 visitor->trace(m_firesTouchEvents); |
59 visitor->trace(m_doesntFireTouchEvents); | 101 visitor->trace(m_doesntFireTouchEvents); |
60 } | 102 } |
61 | 103 |
62 private: | 104 private: |
63 Member<InputDeviceCapabilities> m_firesTouchEvents; | 105 Member<InputDeviceCapabilities> m_firesTouchEvents; |
64 Member<InputDeviceCapabilities> m_doesntFireTouchEvents; | 106 Member<InputDeviceCapabilities> m_doesntFireTouchEvents; |
65 }; | 107 }; |
66 | 108 |
67 } // namespace blink | 109 } // namespace blink |
68 | 110 |
69 #endif // InputDeviceCapabilities_h | 111 #endif // InputDeviceCapabilities_h |
OLD | NEW |