WebWheelEvent.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2010 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebEvent.h"
  27. #include "Arguments.h"
  28. #include "WebCoreArgumentCoders.h"
  29. using namespace WebCore;
  30. namespace WebKit {
  31. WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, Modifiers modifiers, double timestamp)
  32. : WebEvent(type, modifiers, timestamp)
  33. , m_position(position)
  34. , m_globalPosition(globalPosition)
  35. , m_delta(delta)
  36. , m_wheelTicks(wheelTicks)
  37. , m_granularity(granularity)
  38. , m_directionInvertedFromDevice(false)
  39. #if PLATFORM(MAC)
  40. , m_phase(PhaseNone)
  41. , m_hasPreciseScrollingDeltas(false)
  42. , m_scrollCount(0)
  43. #endif
  44. {
  45. ASSERT(isWheelEventType(type));
  46. }
  47. #if PLATFORM(MAC)
  48. WebWheelEvent::WebWheelEvent(Type type, const IntPoint& position, const IntPoint& globalPosition, const FloatSize& delta, const FloatSize& wheelTicks, Granularity granularity, bool directionInvertedFromDevice, Phase phase, Phase momentumPhase, bool hasPreciseScrollingDeltas, uint32_t scrollCount, const WebCore::FloatSize& unacceleratedScrollingDelta, Modifiers modifiers, double timestamp)
  49. : WebEvent(type, modifiers, timestamp)
  50. , m_position(position)
  51. , m_globalPosition(globalPosition)
  52. , m_delta(delta)
  53. , m_wheelTicks(wheelTicks)
  54. , m_granularity(granularity)
  55. , m_directionInvertedFromDevice(directionInvertedFromDevice)
  56. , m_phase(phase)
  57. , m_momentumPhase(momentumPhase)
  58. , m_hasPreciseScrollingDeltas(hasPreciseScrollingDeltas)
  59. , m_scrollCount(scrollCount)
  60. , m_unacceleratedScrollingDelta(unacceleratedScrollingDelta)
  61. {
  62. ASSERT(isWheelEventType(type));
  63. }
  64. #endif
  65. void WebWheelEvent::encode(CoreIPC::ArgumentEncoder& encoder) const
  66. {
  67. WebEvent::encode(encoder);
  68. encoder << m_position;
  69. encoder << m_globalPosition;
  70. encoder << m_delta;
  71. encoder << m_wheelTicks;
  72. encoder << m_granularity;
  73. encoder << m_directionInvertedFromDevice;
  74. #if PLATFORM(MAC)
  75. encoder << m_phase;
  76. encoder << m_momentumPhase;
  77. encoder << m_hasPreciseScrollingDeltas;
  78. encoder << m_scrollCount;
  79. encoder << m_unacceleratedScrollingDelta;
  80. #endif
  81. }
  82. bool WebWheelEvent::decode(CoreIPC::ArgumentDecoder& decoder, WebWheelEvent& t)
  83. {
  84. if (!WebEvent::decode(decoder, t))
  85. return false;
  86. if (!decoder.decode(t.m_position))
  87. return false;
  88. if (!decoder.decode(t.m_globalPosition))
  89. return false;
  90. if (!decoder.decode(t.m_delta))
  91. return false;
  92. if (!decoder.decode(t.m_wheelTicks))
  93. return false;
  94. if (!decoder.decode(t.m_granularity))
  95. return false;
  96. if (!decoder.decode(t.m_directionInvertedFromDevice))
  97. return false;
  98. #if PLATFORM(MAC)
  99. if (!decoder.decode(t.m_phase))
  100. return false;
  101. if (!decoder.decode(t.m_momentumPhase))
  102. return false;
  103. if (!decoder.decode(t.m_hasPreciseScrollingDeltas))
  104. return false;
  105. if (!decoder.decode(t.m_scrollCount))
  106. return false;
  107. if (!decoder.decode(t.m_unacceleratedScrollingDelta))
  108. return false;
  109. #endif
  110. return true;
  111. }
  112. bool WebWheelEvent::isWheelEventType(Type type)
  113. {
  114. return type == Wheel;
  115. }
  116. } // namespace WebKit