Home | History | Annotate | Download | only in mac
      1 /*
      2  * Copyright (C) 2004, 2006, 2010, 2011 Apple Computer, 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 COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #import "config.h"
     27 #import "PlatformWheelEvent.h"
     28 
     29 #import "PlatformMouseEvent.h"
     30 #import "Scrollbar.h"
     31 #import "WebCoreSystemInterface.h"
     32 #import <wtf/UnusedParam.h>
     33 
     34 namespace WebCore {
     35 
     36 static PlatformWheelEventPhase momentumPhaseForEvent(NSEvent *event)
     37 {
     38     uint32_t phase = PlatformWheelEventPhaseNone;
     39 
     40 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
     41     if ([event momentumPhase] & NSEventPhaseBegan)
     42         phase |= PlatformWheelEventPhaseBegan;
     43     if ([event momentumPhase] & NSEventPhaseStationary)
     44         phase |= PlatformWheelEventPhaseStationary;
     45     if ([event momentumPhase] & NSEventPhaseChanged)
     46         phase |= PlatformWheelEventPhaseChanged;
     47     if ([event momentumPhase] & NSEventPhaseEnded)
     48         phase |= PlatformWheelEventPhaseEnded;
     49     if ([event momentumPhase] & NSEventPhaseCancelled)
     50         phase |= PlatformWheelEventPhaseCancelled;
     51 #else
     52     switch (wkGetNSEventMomentumPhase(event)) {
     53     case wkEventPhaseNone:
     54         phase = PlatformWheelEventPhaseNone;
     55         break;
     56     case wkEventPhaseBegan:
     57         phase = PlatformWheelEventPhaseBegan;
     58         break;
     59     case wkEventPhaseChanged:
     60         phase = PlatformWheelEventPhaseChanged;
     61         break;
     62     case wkEventPhaseEnded:
     63         phase = PlatformWheelEventPhaseEnded;
     64         break;
     65     }
     66 #endif
     67 
     68     return static_cast<PlatformWheelEventPhase>(phase);
     69 }
     70 
     71 static PlatformWheelEventPhase phaseForEvent(NSEvent *event)
     72 {
     73 #if !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD)
     74     uint32_t phase = PlatformWheelEventPhaseNone;
     75     if ([event phase] & NSEventPhaseBegan)
     76         phase |= PlatformWheelEventPhaseBegan;
     77     if ([event phase] & NSEventPhaseStationary)
     78         phase |= PlatformWheelEventPhaseStationary;
     79     if ([event phase] & NSEventPhaseChanged)
     80         phase |= PlatformWheelEventPhaseChanged;
     81     if ([event phase] & NSEventPhaseEnded)
     82         phase |= PlatformWheelEventPhaseEnded;
     83     if ([event phase] & NSEventPhaseCancelled)
     84         phase |= PlatformWheelEventPhaseCancelled;
     85     return static_cast<PlatformWheelEventPhase>(phase);
     86 #else
     87     UNUSED_PARAM(event);
     88     return PlatformWheelEventPhaseNone;
     89 #endif
     90 }
     91 
     92 PlatformWheelEvent::PlatformWheelEvent(NSEvent* event, NSView *windowView)
     93     : m_position(pointForEvent(event, windowView))
     94     , m_globalPosition(globalPointForEvent(event))
     95     , m_granularity(ScrollByPixelWheelEvent)
     96     , m_isAccepted(false)
     97     , m_shiftKey([event modifierFlags] & NSShiftKeyMask)
     98     , m_ctrlKey([event modifierFlags] & NSControlKeyMask)
     99     , m_altKey([event modifierFlags] & NSAlternateKeyMask)
    100     , m_metaKey([event modifierFlags] & NSCommandKeyMask)
    101     , m_phase(phaseForEvent(event))
    102     , m_momentumPhase(momentumPhaseForEvent(event))
    103     , m_timestamp([event timestamp])
    104 {
    105     BOOL continuous;
    106     wkGetWheelEventDeltas(event, &m_deltaX, &m_deltaY, &continuous);
    107     if (continuous) {
    108         m_wheelTicksX = m_deltaX / static_cast<float>(Scrollbar::pixelsPerLineStep());
    109         m_wheelTicksY = m_deltaY / static_cast<float>(Scrollbar::pixelsPerLineStep());
    110         m_hasPreciseScrollingDeltas = true;
    111     } else {
    112         m_wheelTicksX = m_deltaX;
    113         m_wheelTicksY = m_deltaY;
    114         m_deltaX *= static_cast<float>(Scrollbar::pixelsPerLineStep());
    115         m_deltaY *= static_cast<float>(Scrollbar::pixelsPerLineStep());
    116         m_hasPreciseScrollingDeltas = false;
    117     }
    118 }
    119 
    120 } // namespace WebCore
    121