gfx/skia/trunk/src/views/SkParsePaint.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "SkParsePaint.h"
     9 #include "SkTSearch.h"
    10 #include "SkParse.h"
    11 #include "SkImageDecoder.h"
    12 #include "SkGradientShader.h"
    14 static SkShader* inflate_shader(const SkDOM& dom, const SkDOM::Node* node)
    15 {
    16     if ((node = dom.getFirstChild(node, "shader")) == NULL)
    17         return NULL;
    19     const char* str;
    21     if (dom.hasAttr(node, "type", "linear-gradient"))
    22     {
    23         SkColor        colors[2];
    24         SkPoint        pts[2];
    26         colors[0] = colors[1] = SK_ColorBLACK;    // need to initialized the alpha to opaque, since FindColor doesn't set it
    27         if ((str = dom.findAttr(node, "c0")) != NULL &&
    28             SkParse::FindColor(str, &colors[0]) &&
    29             (str = dom.findAttr(node, "c1")) != NULL &&
    30             SkParse::FindColor(str, &colors[1]) &&
    31             dom.findScalars(node, "p0", &pts[0].fX, 2) &&
    32             dom.findScalars(node, "p1", &pts[1].fX, 2))
    33         {
    34             SkShader::TileMode    mode = SkShader::kClamp_TileMode;
    35             int                    index;
    37             if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror")) >= 0)
    38                 mode = (SkShader::TileMode)index;
    39             return SkGradientShader::CreateLinear(pts, colors, NULL, 2, mode);
    40         }
    41     }
    42     else if (dom.hasAttr(node, "type", "bitmap"))
    43     {
    44         if ((str = dom.findAttr(node, "src")) == NULL)
    45             return NULL;
    47         SkBitmap    bm;
    49         if (SkImageDecoder::DecodeFile(str, &bm))
    50         {
    51             SkShader::TileMode    mode = SkShader::kRepeat_TileMode;
    52             int                    index;
    54             if ((index = dom.findList(node, "tile-mode", "clamp,repeat,mirror")) >= 0)
    55                 mode = (SkShader::TileMode)index;
    57             return SkShader::CreateBitmapShader(bm, mode, mode);
    58         }
    59     }
    60     return NULL;
    61 }
    63 void SkPaint_Inflate(SkPaint* paint, const SkDOM& dom, const SkDOM::Node* node)
    64 {
    65     SkASSERT(paint);
    66     SkASSERT(&dom);
    67     SkASSERT(node);
    69     SkScalar x;
    71     if (dom.findScalar(node, "stroke-width", &x))
    72         paint->setStrokeWidth(x);
    73     if (dom.findScalar(node, "text-size", &x))
    74         paint->setTextSize(x);
    76     bool    b;
    78     SkASSERT("legacy: use is-stroke" && !dom.findBool(node, "is-frame", &b));
    80     if (dom.findBool(node, "is-stroke", &b))
    81         paint->setStyle(b ? SkPaint::kStroke_Style : SkPaint::kFill_Style);
    82     if (dom.findBool(node, "is-antialias", &b))
    83         paint->setAntiAlias(b);
    84     if (dom.findBool(node, "is-lineartext", &b))
    85         paint->setLinearText(b);
    87     const char* str = dom.findAttr(node, "color");
    88     if (str)
    89     {
    90         SkColor    c = paint->getColor();
    91         if (SkParse::FindColor(str, &c))
    92             paint->setColor(c);
    93     }
    95     // do this AFTER parsing for the color
    96     if (dom.findScalar(node, "opacity", &x))
    97     {
    98         x = SkMaxScalar(0, SkMinScalar(x, SK_Scalar1));
    99         paint->setAlpha(SkScalarRoundToInt(x * 255));
   100     }
   102     int    index = dom.findList(node, "text-anchor", "left,center,right");
   103     if (index >= 0)
   104         paint->setTextAlign((SkPaint::Align)index);
   106     SkShader* shader = inflate_shader(dom, node);
   107     if (shader)
   108         paint->setShader(shader)->unref();
   109 }

mercurial