Home | History | Annotate | Download | only in runner
      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 // WebTestThemeControlWin implements the generic rendering of controls
     32 // needed by WebThemeEngineDRTWin. See the comments in that class
     33 // header file for why this class is needed and used.
     34 //
     35 // This class implements a generic set of widgets using Skia. The widgets
     36 // are optimized for testability, not a pleasing appearance.
     37 //
     38 
     39 #ifndef WebTestThemeControlWin_h
     40 #define WebTestThemeControlWin_h
     41 
     42 #include "public/platform/WebNonCopyable.h"
     43 #include "third_party/skia/include/core/SkColor.h"
     44 #include "third_party/skia/include/core/SkRect.h"
     45 
     46 // Skia forward declarations
     47 class SkCanvas;
     48 
     49 namespace WebTestRunner {
     50 
     51 class WebTestThemeControlWin : public blink::WebNonCopyable {
     52 public:
     53     // This list of states mostly mirrors the list in WebCore/platform/ThemeTypes.h
     54     // but is maintained separately since that isn't public and also to minimize
     55     // dependencies.
     56     // Note that the WebKit ThemeTypes seem to imply that a control can be
     57     // in multiple states simultaneously but WebThemeEngine only allows for
     58     // a single state at a time.
     59     //
     60     // Some definitions for the various states:
     61     //   Disabled - indicates that a control can't be modified or selected
     62     //              (corresponds to HTML 'disabled' attribute)
     63     //   ReadOnly - indicates that a control can't be modified but can be
     64     //              selected
     65     //   Normal   - the normal state of control on the page when it isn't
     66     //              focused or otherwise active
     67     //   Hot      - when the mouse is hovering over a part of the control,
     68     //              all the other parts are considered "hot"
     69     //   Hover    - when the mouse is directly over a control (the CSS
     70     //               :hover pseudo-class)
     71     //   Focused  - when the control has the keyboard focus
     72     //   Pressed  - when the control is being triggered (by a mousedown or
     73     //              a key event).
     74     //   Indeterminate - when set to indeterminate (only for progress bar)
     75     enum State {
     76         UnknownState = 0,
     77         DisabledState,
     78         ReadOnlyState,
     79         NormalState,
     80         HotState,
     81         HoverState,
     82         FocusedState,
     83         PressedState,
     84         IndeterminateState
     85     };
     86 
     87     // This list of types mostly mirrors the list in
     88     // WebCore/platform/ThemeTypes.h but is maintained
     89     // separately since that isn't public and also to minimize dependencies.
     90     //
     91     // Note that what the user might think of as a single control can be
     92     // made up of multiple parts. For example, a single scroll bar contains
     93     // six clickable parts - two arrows, the "thumb" indicating the current
     94     // position on the bar, the other two parts of the bar (before and after
     95     // the thumb) and the "gripper" on the thumb itself.
     96     //
     97     enum Type {
     98         UnknownType = 0,
     99         TextFieldType,
    100         PushButtonType,
    101         UncheckedBoxType,
    102         CheckedBoxType,
    103         IndeterminateCheckboxType,
    104         UncheckedRadioType,
    105         CheckedRadioType,
    106         HorizontalScrollTrackBackType,
    107         HorizontalScrollTrackForwardType,
    108         HorizontalScrollThumbType,
    109         HorizontalScrollGripType,
    110         VerticalScrollTrackBackType,
    111         VerticalScrollTrackForwardType,
    112         VerticalScrollThumbType,
    113         VerticalScrollGripType,
    114         LeftArrowType,
    115         RightArrowType,
    116         UpArrowType,
    117         DownArrowType,
    118         HorizontalSliderTrackType,
    119         HorizontalSliderThumbType,
    120         VerticalSliderTrackType,
    121         VerticalSliderThumbType,
    122         DropDownButtonType,
    123         ProgressBarType
    124     };
    125 
    126     // Constructs a control of the given size, type and state to draw
    127     // on to the given canvas.
    128     WebTestThemeControlWin(SkCanvas*, const SkIRect&, Type, State);
    129     ~WebTestThemeControlWin();
    130 
    131     // Draws the control.
    132     void draw();
    133 
    134     // Use this for TextField controls instead, because the logic
    135     // for drawing them is dependent on what WebKit tells us to do.
    136     // If drawEdges is true, draw an edge around the control. If
    137     // fillContentArea is true, fill the content area with the given color.
    138     void drawTextField(bool drawEdges, bool fillContentArea, SkColor);
    139 
    140     // Use this for drawing ProgressBar controls instead, since we
    141     // need to know the rect to fill inside the bar.
    142     void drawProgressBar(const SkIRect& fillRect);
    143 
    144 private:
    145     // Draws a box of size specified by irect, filled with the given color.
    146     // The box will have a border drawn in the default edge color.
    147     void box(const SkIRect& irect, SkColor);
    148 
    149 
    150     // Draws a triangle of size specified by the three pairs of coordinates,
    151     // filled with the given color. The box will have an edge drawn in the
    152     // default edge color.
    153     void triangle(int x0, int y0, int x1, int y1, int x2, int y2, SkColor);
    154 
    155     // Draws a rectangle the size of the control with rounded corners, filled
    156     // with the specified color (and with a border in the default edge color).
    157     void roundRect(SkColor);
    158 
    159     // Draws an oval the size of the control, filled with the specified color
    160     // and with a border in the default edge color.
    161     void oval(SkColor);
    162 
    163     // Draws a circle centered in the control with the specified radius,
    164     // filled with the specified color, and with a border draw in the
    165     // default edge color.
    166     void circle(SkScalar radius, SkColor);
    167 
    168     // Draws a box the size of the control, filled with the outerColor and
    169     // with a border in the default edge color, and then draws another box
    170     // indented on all four sides by the specified amounts, filled with the
    171     // inner color and with a border in the default edge color.
    172     void nestedBoxes(int indentLeft, int indentTop, int indentRight, int indentBottom, SkColor outerColor, SkColor innerColor);
    173 
    174     // Draws a line between the two points in the given color.
    175     void line(int x0, int y0, int x1, int y1, SkColor);
    176 
    177     // Draws a distinctive mark on the control for each state, so that the
    178     // state of the control can be determined without needing to know which
    179     // color is which.
    180     void markState();
    181 
    182     SkCanvas* m_canvas;
    183     const SkIRect m_irect;
    184     const Type m_type;
    185     const State m_state;
    186     const SkColor m_edgeColor;
    187     const SkColor m_bgColor;
    188     const SkColor m_fgColor;
    189 
    190     // The following are convenience accessors for m_irect.
    191     const int m_left;
    192     const int m_right;
    193     const int m_top;
    194     const int m_bottom;
    195     const int m_width;
    196     const int m_height;
    197 };
    198 
    199 }
    200 
    201 #endif // WebTestThemeControlWin_h
    202