11e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)/*
21e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
31e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *
41e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
51e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * modification, are permitted provided that the following conditions
61e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * are met:
71e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
81e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
91e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *    documentation and/or other materials provided with the distribution.
121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) *
131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) */
251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#ifndef ScrollTypes_h
271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#define ScrollTypes_h
281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "wtf/Assertions.h"
301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
31c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollDirection {
341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollUp,
351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollDown,
361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollLeft,
3709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    ScrollRight,
381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollBlockDirectionBackward,
401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollBlockDirectionForward,
411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollInlineDirectionBackward,
421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollInlineDirectionForward
431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)inline bool isLogical(ScrollDirection direction)
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return direction >= ScrollBlockDirectionBackward;
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// Convert logical scroll direction to physical. Physical scroll directions are unaffected.
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)inline ScrollDirection toPhysicalDirection(ScrollDirection direction, bool isVertical, bool isFlipped)
521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles){
531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    switch (direction) {
541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case ScrollBlockDirectionBackward: {
551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (isVertical) {
561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            if (!isFlipped)
571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)                return ScrollUp;
581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollDown;
591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (!isFlipped)
611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollLeft;
621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return ScrollRight;
631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case ScrollBlockDirectionForward: {
651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (isVertical) {
661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            if (!isFlipped)
671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)                return ScrollDown;
681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollUp;
691e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (!isFlipped)
711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollRight;
721e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return ScrollLeft;
731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case ScrollInlineDirectionBackward: {
751e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (isVertical) {
761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            if (!isFlipped)
771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)                return ScrollLeft;
781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollRight;
791e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
801e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (!isFlipped)
811e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollUp;
821e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return ScrollDown;
831e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
841e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    case ScrollInlineDirectionForward: {
851e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (isVertical) {
861e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            if (!isFlipped)
871e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)                return ScrollRight;
881e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollLeft;
891e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        }
901e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        if (!isFlipped)
911e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)            return ScrollDown;
921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        return ScrollUp;
931e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
9409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    // Direction is already physical
9509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case ScrollUp:
9609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case ScrollDown:
9709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case ScrollLeft:
9809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    case ScrollRight:
9909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return direction;
1001e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    default:
1011e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        ASSERT_NOT_REACHED();
1021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)        break;
1031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    }
10409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return direction;
1051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1061e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1071e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollGranularity {
1081e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollByLine,
1091e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollByPage,
1101e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollByDocument,
1111e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollByPixel,
1121e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollByPrecisePixel
1131e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1141e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1151e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollElasticity {
1161e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollElasticityAutomatic,
1171e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollElasticityNone,
1181e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollElasticityAllowed
1191e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1201e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1211e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarOrientation { HorizontalScrollbar, VerticalScrollbar };
1221e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1231e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarMode { ScrollbarAuto, ScrollbarAlwaysOff, ScrollbarAlwaysOn };
1241e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1251e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarControlSize { RegularScrollbar, SmallScrollbar };
1261e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1271e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)typedef unsigned ScrollbarControlState;
1281e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarControlStateMask {
1301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ActiveScrollbarState = 1,
1311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    EnabledScrollbarState = 1 << 1,
1321e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    PressedScrollbarState = 1 << 2
1331e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarPart {
1361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    NoPart = 0,
1371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    BackButtonStartPart = 1,
1381e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ForwardButtonStartPart = 1 << 1,
1391e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    BackTrackPart = 1 << 2,
1401e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ThumbPart = 1 << 3,
1411e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ForwardTrackPart = 1 << 4,
1421e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    BackButtonEndPart = 1 << 5,
1431e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ForwardButtonEndPart = 1 << 6,
1441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarBGPart = 1 << 7,
1451e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    TrackBGPart = 1 << 8,
1461e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    AllParts = 0xffffffff
1471e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1481e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1491e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarButtonsPlacement {
1501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarButtonsNone,
1511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarButtonsSingle,
1521e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarButtonsDoubleStart,
1531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarButtonsDoubleEnd,
1541e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarButtonsDoubleBoth
1551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1561e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)enum ScrollbarOverlayStyle {
1581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarOverlayStyleDefault,
1591e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarOverlayStyleDark,
1601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    ScrollbarOverlayStyleLight
1611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)};
1621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1631e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)typedef unsigned ScrollbarControlPartMask;
1641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1651e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)}
1661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)
1671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#endif
168