Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009 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 #include "config.h"
     32 #include "WebColorName.h"
     33 
     34 #include "CSSValueKeywords.h"
     35 #include "core/platform/graphics/Color.h"
     36 #include "core/rendering/RenderTheme.h"
     37 #include "public/platform/WebColor.h"
     38 #include "wtf/UnusedParam.h"
     39 
     40 using namespace::WebCore;
     41 
     42 namespace WebKit {
     43 
     44 static int toCSSValueKeyword(WebColorName name)
     45 {
     46     switch (name) {
     47     case WebColorActiveBorder:
     48         return CSSValueActiveborder;
     49     case WebColorActiveCaption:
     50         return CSSValueActivecaption;
     51     case WebColorAppworkspace:
     52         return CSSValueAppworkspace;
     53     case WebColorBackground:
     54         return CSSValueBackground;
     55     case WebColorButtonFace:
     56         return CSSValueButtonface;
     57     case WebColorButtonHighlight:
     58         return CSSValueButtonhighlight;
     59     case WebColorButtonShadow:
     60         return CSSValueButtonshadow;
     61     case WebColorButtonText:
     62         return CSSValueButtontext;
     63     case WebColorCaptionText:
     64         return CSSValueCaptiontext;
     65     case WebColorGrayText:
     66         return CSSValueGraytext;
     67     case WebColorHighlight:
     68         return CSSValueHighlight;
     69     case WebColorHighlightText:
     70         return CSSValueHighlighttext;
     71     case WebColorInactiveBorder:
     72         return CSSValueInactiveborder;
     73     case WebColorInactiveCaption:
     74         return CSSValueInactivecaption;
     75     case WebColorInactiveCaptionText:
     76         return CSSValueInactivecaptiontext;
     77     case WebColorInfoBackground:
     78         return CSSValueInfobackground;
     79     case WebColorInfoText:
     80         return CSSValueInfotext;
     81     case WebColorMenu:
     82         return CSSValueMenu;
     83     case WebColorMenuText:
     84         return CSSValueMenutext;
     85     case WebColorScrollbar:
     86         return CSSValueScrollbar;
     87     case WebColorText:
     88         return CSSValueText;
     89     case WebColorThreedDarkShadow:
     90         return CSSValueThreeddarkshadow;
     91     case WebColorThreedShadow:
     92         return CSSValueThreedshadow;
     93     case WebColorThreedFace:
     94         return CSSValueThreedface;
     95     case WebColorThreedHighlight:
     96         return CSSValueThreedhighlight;
     97     case WebColorThreedLightShadow:
     98         return CSSValueThreedlightshadow;
     99     case WebColorWebkitFocusRingColor:
    100         return CSSValueWebkitFocusRingColor;
    101     case WebColorWindow:
    102         return CSSValueWindow;
    103     case WebColorWindowFrame:
    104         return CSSValueWindowframe;
    105     case WebColorWindowText:
    106         return CSSValueWindowtext;
    107     default:
    108         return CSSValueInvalid;
    109     }
    110 }
    111 
    112 void setNamedColors(const WebColorName* colorNames, const WebColor* colors, size_t length)
    113 {
    114     for (size_t i = 0; i < length; ++i) {
    115         WebColorName colorName = colorNames[i];
    116         WebColor color = colors[i];
    117 
    118         // Convert color to internal value identifier.
    119         int internalColorName = toCSSValueKeyword(colorName);
    120         if (internalColorName == CSSValueWebkitFocusRingColor) {
    121             RenderTheme::setCustomFocusRingColor(color);
    122             continue;
    123         }
    124     }
    125 
    126     // TODO(jeremy): Tell RenderTheme to update colors.
    127 }
    128 
    129 } // WebKit
    130