NavigatorVibration.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2012 Samsung Electronics
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  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
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. */
  19. #include "config.h"
  20. #include "NavigatorVibration.h"
  21. #if ENABLE(VIBRATION)
  22. #include "ExceptionCode.h"
  23. #include "Frame.h"
  24. #include "Navigator.h"
  25. #include "Page.h"
  26. #include "Vibration.h"
  27. #include <wtf/Uint32Array.h>
  28. namespace WebCore {
  29. NavigatorVibration::NavigatorVibration()
  30. {
  31. }
  32. NavigatorVibration::~NavigatorVibration()
  33. {
  34. }
  35. void NavigatorVibration::vibrate(Navigator* navigator, unsigned time, ExceptionCode& ec)
  36. {
  37. if (!navigator->frame()->page())
  38. return;
  39. #if ENABLE(PAGE_VISIBILITY_API)
  40. if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden)
  41. return;
  42. #endif
  43. if (!Vibration::isActive(navigator->frame()->page())) {
  44. ec = NOT_SUPPORTED_ERR;
  45. return;
  46. }
  47. Vibration::from(navigator->frame()->page())->vibrate(time);
  48. }
  49. void NavigatorVibration::vibrate(Navigator* navigator, const VibrationPattern& pattern, ExceptionCode& ec)
  50. {
  51. if (!navigator->frame()->page())
  52. return;
  53. #if ENABLE(PAGE_VISIBILITY_API)
  54. if (navigator->frame()->page()->visibilityState() == PageVisibilityStateHidden)
  55. return;
  56. #endif
  57. if (!Vibration::isActive(navigator->frame()->page())) {
  58. ec = NOT_SUPPORTED_ERR;
  59. return;
  60. }
  61. Vibration::from(navigator->frame()->page())->vibrate(pattern);
  62. }
  63. } // namespace WebCore
  64. #endif // ENABLE(VIBRATION)