OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Samsung Electronics | 2 * Copyright (C) 2012 Samsung Electronics |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #include "config.h" | 20 #include "config.h" |
21 #include "modules/vibration/Vibration.h" | 21 #include "modules/vibration/Vibration.h" |
22 | 22 |
23 #if ENABLE(VIBRATION) | 23 #include "public/platform/Platform.h" |
24 | |
25 #include "modules/vibration/VibrationClient.h" | |
26 | 24 |
27 namespace WebCore { | 25 namespace WebCore { |
28 | 26 |
29 Vibration::Vibration(VibrationClient* client) | 27 Vibration::Vibration() |
30 : m_vibrationClient(client) | 28 : m_timerStart(this, &Vibration::timerStartFired) |
31 , m_timerStart(this, &Vibration::timerStartFired) | |
32 , m_timerStop(this, &Vibration::timerStopFired) | 29 , m_timerStop(this, &Vibration::timerStopFired) |
33 , m_isVibrating(false) | 30 , m_isVibrating(false) |
34 { | 31 { |
35 } | 32 } |
36 | 33 |
37 Vibration::~Vibration() | 34 Vibration::~Vibration() |
38 { | 35 { |
39 m_vibrationClient->vibrationDestroyed(); | 36 if (m_isVibrating) |
37 cancelVibration(); | |
40 } | 38 } |
41 | 39 |
42 PassOwnPtr<Vibration> Vibration::create(VibrationClient* client) | 40 PassOwnPtr<Vibration> Vibration::create() |
Peter Beverloo
2013/06/11 13:50:12
This method isn't being used anymore, please remov
Michael van Ouwerkerk
2013/06/11 14:16:43
Done.
| |
43 { | 41 { |
44 return adoptPtr(new Vibration(client)); | 42 return adoptPtr(new Vibration()); |
45 } | 43 } |
46 | 44 |
47 void Vibration::vibrate(const unsigned& time) | 45 void Vibration::vibrate(const unsigned& time) |
48 { | 46 { |
49 if (!time) { | 47 if (!time) { |
50 cancelVibration(); | 48 cancelVibration(); |
51 return; | 49 return; |
52 } | 50 } |
53 m_pattern.append(time); | 51 m_pattern.append(time); |
54 m_timerStart.startOneShot(0); | 52 m_timerStart.startOneShot(0); |
(...skipping 16 matching lines...) Expand all Loading... | |
71 m_timerStart.stop(); | 69 m_timerStart.stop(); |
72 | 70 |
73 m_pattern = pattern; | 71 m_pattern = pattern; |
74 m_timerStart.startOneShot(0); | 72 m_timerStart.startOneShot(0); |
75 } | 73 } |
76 | 74 |
77 void Vibration::cancelVibration() | 75 void Vibration::cancelVibration() |
78 { | 76 { |
79 m_pattern.clear(); | 77 m_pattern.clear(); |
80 if (m_isVibrating) { | 78 if (m_isVibrating) { |
81 m_vibrationClient->cancelVibration(); | 79 WebKit::Platform::current()->cancelVibration(); |
82 m_isVibrating = false; | 80 m_isVibrating = false; |
83 m_timerStop.stop(); | 81 m_timerStop.stop(); |
84 } | 82 } |
85 } | 83 } |
86 | 84 |
87 void Vibration::suspendVibration() | 85 void Vibration::suspendVibration() |
88 { | 86 { |
89 if (!m_isVibrating) | 87 if (!m_isVibrating) |
90 return; | 88 return; |
91 | 89 |
92 m_pattern.insert(0, m_timerStop.nextFireInterval()); | 90 m_pattern.insert(0, m_timerStop.nextFireInterval()); |
93 m_timerStop.stop(); | 91 m_timerStop.stop(); |
94 cancelVibration(); | 92 cancelVibration(); |
95 } | 93 } |
96 | 94 |
97 void Vibration::resumeVibration() | 95 void Vibration::resumeVibration() |
98 { | 96 { |
99 m_timerStart.startOneShot(0); | 97 m_timerStart.startOneShot(0); |
100 } | 98 } |
101 | 99 |
102 void Vibration::timerStartFired(Timer<Vibration>* timer) | 100 void Vibration::timerStartFired(Timer<Vibration>* timer) |
103 { | 101 { |
104 ASSERT_UNUSED(timer, timer == &m_timerStart); | 102 ASSERT_UNUSED(timer, timer == &m_timerStart); |
105 | 103 |
106 m_timerStart.stop(); | 104 m_timerStart.stop(); |
107 | 105 |
108 if (m_pattern.size()) { | 106 if (m_pattern.size()) { |
109 m_isVibrating = true; | 107 m_isVibrating = true; |
110 m_vibrationClient->vibrate(m_pattern[0]); | 108 WebKit::Platform::current()->vibrate(m_pattern[0]); |
111 m_timerStop.startOneShot(m_pattern[0] / 1000.0); | 109 m_timerStop.startOneShot(m_pattern[0] / 1000.0); |
112 m_pattern.remove(0); | 110 m_pattern.remove(0); |
113 } | 111 } |
114 } | 112 } |
115 | 113 |
116 void Vibration::timerStopFired(Timer<Vibration>* timer) | 114 void Vibration::timerStopFired(Timer<Vibration>* timer) |
117 { | 115 { |
118 ASSERT_UNUSED(timer, timer == &m_timerStop); | 116 ASSERT_UNUSED(timer, timer == &m_timerStop); |
119 | 117 |
120 m_timerStop.stop(); | 118 m_timerStop.stop(); |
121 m_isVibrating = false; | 119 m_isVibrating = false; |
122 | 120 |
123 if (m_pattern.size()) { | 121 if (m_pattern.size()) { |
124 m_timerStart.startOneShot(m_pattern[0] / 1000.0); | 122 m_timerStart.startOneShot(m_pattern[0] / 1000.0); |
125 m_pattern.remove(0); | 123 m_pattern.remove(0); |
126 } | 124 } |
127 } | 125 } |
128 | 126 |
129 const char* Vibration::supplementName() | 127 const char* Vibration::supplementName() |
130 { | 128 { |
131 return "Vibration"; | 129 return "Vibration"; |
132 } | 130 } |
133 | 131 |
132 Vibration* Vibration::from(Page* page) | |
133 { | |
134 if (!Supplement<Page>::from(page, supplementName())) | |
135 Supplement<Page>::provideTo(page, supplementName(), adoptPtr(new Vibrati on())); | |
136 return static_cast<Vibration*>(Supplement<Page>::from(page, supplementName() )); | |
137 } | |
138 | |
134 bool Vibration::isActive(Page* page) | 139 bool Vibration::isActive(Page* page) |
135 { | 140 { |
136 return static_cast<bool>(Vibration::from(page)); | 141 return static_cast<bool>(Vibration::from(page)); |
137 } | 142 } |
138 | 143 |
139 void provideVibrationTo(Page* page, VibrationClient* client) | |
140 { | |
141 Vibration::provideTo(page, Vibration::supplementName(), Vibration::create(cl ient)); | |
142 } | |
143 | |
144 } // namespace WebCore | 144 } // namespace WebCore |
145 | |
146 #endif // ENABLE(VIBRATION) | |
147 | |
OLD | NEW |