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