Home | History | Annotate | Download | only in platform
      1 /*
      2  * Copyright (C) 2010 Google 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 are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef WebThemeEngine_h
     32 #define WebThemeEngine_h
     33 
     34 #include "WebCanvas.h"
     35 #include "WebColor.h"
     36 #include "WebSize.h"
     37 
     38 namespace blink {
     39 
     40 struct WebRect;
     41 
     42 // FIXME: crbug.com/327471. We need to merge the Apple and non-Apple implementations.
     43 
     44 class WebThemeEngine {
     45 public:
     46     // The current state of the associated Part.
     47     enum State {
     48         StateDisabled,
     49         StateHover, // non-Apple
     50         StateNormal, // non-Apple
     51         StatePressed,
     52         StateFocused, // non-Apple
     53         StateReadonly, // non-Apple
     54         StateInactive, // Apple-specific
     55         StateActive, // Apple-specific
     56     };
     57 
     58     // FIXME: The next section describes stuff only used on the Apple port.
     59     enum Size {
     60         SizeRegular,
     61         SizeSmall,
     62     };
     63 
     64     enum ScrollbarOrientation {
     65         ScrollbarOrientationHorizontal,
     66         ScrollbarOrientationVertical,
     67     };
     68 
     69     enum ScrollbarParent {
     70         ScrollbarParentScrollView,
     71         ScrollbarParentRenderLayer,
     72     };
     73 
     74     struct ScrollbarInfo {
     75         ScrollbarOrientation orientation;
     76         ScrollbarParent parent;
     77         int maxValue;
     78         int currentValue;
     79         int visibleSize;
     80         int totalSize;
     81     };
     82 
     83     virtual void paintScrollbarThumb(WebCanvas*, State, Size, const WebRect&, const ScrollbarInfo&) { }
     84 
     85     // FIXME: The remaining definitions are only used on the non-Apple ports.
     86 
     87     // The UI part which is being accessed.
     88     enum Part {
     89         // ScrollbarTheme parts
     90         PartScrollbarDownArrow,
     91         PartScrollbarLeftArrow,
     92         PartScrollbarRightArrow,
     93         PartScrollbarUpArrow,
     94         PartScrollbarHorizontalThumb,
     95         PartScrollbarVerticalThumb,
     96         PartScrollbarHorizontalTrack,
     97         PartScrollbarVerticalTrack,
     98         PartScrollbarCorner,
     99 
    100         // RenderTheme parts
    101         PartCheckbox,
    102         PartRadio,
    103         PartButton,
    104         PartTextField,
    105         PartMenuList,
    106         PartSliderTrack,
    107         PartSliderThumb,
    108         PartInnerSpinButton,
    109         PartProgressBar
    110     };
    111 
    112 
    113     // Extra parameters for drawing the PartScrollbarHorizontalTrack and
    114     // PartScrollbarVerticalTrack.
    115     struct ScrollbarTrackExtraParams {
    116         bool isBack; // Whether this is the 'back' part or the 'forward' part.
    117 
    118         // The bounds of the entire track, as opposed to the part being painted.
    119         int trackX;
    120         int trackY;
    121         int trackWidth;
    122         int trackHeight;
    123     };
    124 
    125     // Extra parameters for PartCheckbox, PartPushButton and PartRadio.
    126     struct ButtonExtraParams {
    127         bool checked;
    128         bool indeterminate; // Whether the button state is indeterminate.
    129         bool isDefault; // Whether the button is default button.
    130         bool hasBorder;
    131         WebColor backgroundColor;
    132     };
    133 
    134     // Extra parameters for PartTextField
    135     struct TextFieldExtraParams {
    136         bool isTextArea;
    137         bool isListbox;
    138         WebColor backgroundColor;
    139     };
    140 
    141     // Extra parameters for PartMenuList
    142     struct MenuListExtraParams {
    143         bool hasBorder;
    144         bool hasBorderRadius;
    145         int arrowX;
    146         int arrowY;
    147         int arrowHeight;
    148         WebColor backgroundColor;
    149         bool fillContentArea;
    150     };
    151 
    152     // Extra parameters for PartSliderTrack and PartSliderThumb
    153     struct SliderExtraParams {
    154         bool vertical;
    155         bool inDrag;
    156     };
    157 
    158     // Extra parameters for PartInnerSpinButton
    159     struct InnerSpinButtonExtraParams {
    160         bool spinUp;
    161         bool readOnly;
    162     };
    163 
    164     // Extra parameters for PartProgressBar
    165     struct ProgressBarExtraParams {
    166         bool determinate;
    167         int valueRectX;
    168         int valueRectY;
    169         int valueRectWidth;
    170         int valueRectHeight;
    171     };
    172 
    173     union ExtraParams {
    174         ScrollbarTrackExtraParams scrollbarTrack;
    175         ButtonExtraParams button;
    176         TextFieldExtraParams textField;
    177         MenuListExtraParams menuList;
    178         SliderExtraParams slider;
    179         InnerSpinButtonExtraParams innerSpin;
    180         ProgressBarExtraParams progressBar;
    181     };
    182 
    183     // Gets the size of the given theme part. For variable sized items
    184     // like vertical scrollbar thumbs, the width will be the required width of
    185     // the track while the height will be the minimum height.
    186     virtual WebSize getSize(Part) { return WebSize(); }
    187     // Paint the given the given theme part.
    188     virtual void paint(WebCanvas*, Part, State, const WebRect&, const ExtraParams*) { }
    189 };
    190 
    191 } // namespace blink
    192 
    193 #endif
    194