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/NavigatorVibration.h" | 21 #include "modules/vibration/NavigatorVibration.h" |
22 | 22 |
23 #if ENABLE(VIBRATION) | |
24 | |
25 #include "core/dom/ExceptionCode.h" | |
26 #include "core/page/Frame.h" | 23 #include "core/page/Frame.h" |
27 #include "core/page/Navigator.h" | 24 #include "core/page/Navigator.h" |
28 #include "core/page/Page.h" | 25 #include "core/page/Page.h" |
29 #include "modules/vibration/Vibration.h" | 26 #include "modules/vibration/Vibration.h" |
30 #include "wtf/Uint32Array.h" | 27 #include "wtf/Uint32Array.h" |
31 | 28 |
32 namespace WebCore { | 29 namespace WebCore { |
33 | 30 |
34 NavigatorVibration::NavigatorVibration() | 31 void NavigatorVibration::vibrate(Navigator* navigator, unsigned time) |
35 { | 32 { |
33 Page* page = navigator->frame()->page(); | |
34 | |
35 if (!page) | |
36 return; | |
37 | |
38 if (page->visibilityState() == PageVisibilityStateHidden) | |
39 return; | |
40 | |
41 Vibration::from(page)->vibrate(time); | |
36 } | 42 } |
37 | 43 |
38 NavigatorVibration::~NavigatorVibration() | 44 void NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& p attern) |
39 { | 45 { |
40 } | 46 Page* page = navigator->frame()->page(); |
41 | 47 |
42 void NavigatorVibration::vibrate(Navigator* navigator, unsigned time, ExceptionC ode& ec) | 48 if (!page) |
43 { | |
44 if (!navigator->frame()->page()) | |
45 return; | 49 return; |
46 | 50 |
47 if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidd en) | 51 if (page->visibilityState() == PageVisibilityStateHidden) |
48 return; | 52 return; |
abarth-chromium
2013/06/11 23:55:36
Can you extract this copy/paste code into a helper
Michael van Ouwerkerk
2013/06/12 16:44:50
I've changed it so the one vibrate method calls th
| |
49 | 53 |
50 if (!Vibration::isActive(navigator->frame()->page())) { | 54 Vibration::from(page)->vibrate(pattern); |
51 ec = NOT_SUPPORTED_ERR; | |
52 return; | |
53 } | |
54 | |
55 Vibration::from(navigator->frame()->page())->vibrate(time); | |
56 } | |
57 | |
58 void NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& p attern, ExceptionCode& ec) | |
59 { | |
60 if (!navigator->frame()->page()) | |
61 return; | |
62 | |
63 if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidd en) | |
64 return; | |
65 | |
66 if (!Vibration::isActive(navigator->frame()->page())) { | |
67 ec = NOT_SUPPORTED_ERR; | |
68 return; | |
69 } | |
70 | |
71 Vibration::from(navigator->frame()->page())->vibrate(pattern); | |
72 } | 55 } |
73 | 56 |
74 } // namespace WebCore | 57 } // namespace WebCore |
75 | |
76 #endif // ENABLE(VIBRATION) | |
77 | |
OLD | NEW |