Sat, 03 Jan 2015 20:18:00 +0100
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.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "SkWidget.h" |
michael@0 | 9 | #include "SkCanvas.h" |
michael@0 | 10 | #include "SkMath.h" |
michael@0 | 11 | #include "SkShader.h" |
michael@0 | 12 | #include "SkInterpolator.h" |
michael@0 | 13 | #include "SkTime.h" |
michael@0 | 14 | |
michael@0 | 15 | SkProgressView::SkProgressView(uint32_t flags) : SkView(flags), fOnShader(NULL), fOffShader(NULL) |
michael@0 | 16 | { |
michael@0 | 17 | fValue = 0; |
michael@0 | 18 | fMax = 0; |
michael@0 | 19 | fInterp = NULL; |
michael@0 | 20 | fDoInterp = false; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | SkProgressView::~SkProgressView() |
michael@0 | 24 | { |
michael@0 | 25 | delete fInterp; |
michael@0 | 26 | SkSafeUnref(fOnShader); |
michael@0 | 27 | SkSafeUnref(fOffShader); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | void SkProgressView::setMax(U16CPU max) |
michael@0 | 31 | { |
michael@0 | 32 | if (fMax != max) |
michael@0 | 33 | { |
michael@0 | 34 | fMax = SkToU16(max); |
michael@0 | 35 | if (fValue > 0) |
michael@0 | 36 | this->inval(NULL); |
michael@0 | 37 | } |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | void SkProgressView::setValue(U16CPU value) |
michael@0 | 41 | { |
michael@0 | 42 | if (fValue != value) |
michael@0 | 43 | { |
michael@0 | 44 | if (fDoInterp) |
michael@0 | 45 | { |
michael@0 | 46 | if (fInterp) |
michael@0 | 47 | delete fInterp; |
michael@0 | 48 | fInterp = new SkInterpolator(1, 2); |
michael@0 | 49 | SkScalar x = (SkScalar)(fValue << 8); |
michael@0 | 50 | fInterp->setKeyFrame(0, SkTime::GetMSecs(), &x, 0); |
michael@0 | 51 | x = (SkScalar)(value << 8); |
michael@0 | 52 | fInterp->setKeyFrame(1, SkTime::GetMSecs() + 333, &x); |
michael@0 | 53 | } |
michael@0 | 54 | fValue = SkToU16(value); |
michael@0 | 55 | this->inval(NULL); |
michael@0 | 56 | } |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | void SkProgressView::onDraw(SkCanvas* canvas) |
michael@0 | 60 | { |
michael@0 | 61 | if (fMax == 0) |
michael@0 | 62 | return; |
michael@0 | 63 | |
michael@0 | 64 | SkFixed percent; |
michael@0 | 65 | |
michael@0 | 66 | if (fInterp) |
michael@0 | 67 | { |
michael@0 | 68 | SkScalar x; |
michael@0 | 69 | if (fInterp->timeToValues(SkTime::GetMSecs(), &x) == SkInterpolator::kFreezeEnd_Result) |
michael@0 | 70 | { |
michael@0 | 71 | delete fInterp; |
michael@0 | 72 | fInterp = NULL; |
michael@0 | 73 | } |
michael@0 | 74 | percent = (SkFixed)x; // now its 16.8 |
michael@0 | 75 | percent = SkMax32(0, SkMin32(percent, fMax << 8)); // now its pinned |
michael@0 | 76 | percent = SkFixedDiv(percent, fMax << 8); // now its 0.16 |
michael@0 | 77 | this->inval(NULL); |
michael@0 | 78 | } |
michael@0 | 79 | else |
michael@0 | 80 | { |
michael@0 | 81 | U16CPU value = SkMax32(0, SkMin32(fValue, fMax)); |
michael@0 | 82 | percent = SkFixedDiv(value, fMax); |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | |
michael@0 | 86 | SkRect r; |
michael@0 | 87 | SkPaint p; |
michael@0 | 88 | |
michael@0 | 89 | r.set(0, 0, this->width(), this->height()); |
michael@0 | 90 | p.setAntiAlias(true); |
michael@0 | 91 | |
michael@0 | 92 | r.fRight = r.fLeft + SkScalarMul(r.width(), SkFixedToScalar(percent)); |
michael@0 | 93 | p.setStyle(SkPaint::kFill_Style); |
michael@0 | 94 | |
michael@0 | 95 | p.setColor(SK_ColorDKGRAY); |
michael@0 | 96 | p.setShader(fOnShader); |
michael@0 | 97 | canvas->drawRect(r, p); |
michael@0 | 98 | |
michael@0 | 99 | p.setColor(SK_ColorWHITE); |
michael@0 | 100 | p.setShader(fOffShader); |
michael@0 | 101 | r.fLeft = r.fRight; |
michael@0 | 102 | r.fRight = this->width() - SK_Scalar1; |
michael@0 | 103 | if (r.width() > 0) |
michael@0 | 104 | canvas->drawRect(r, p); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | #include "SkImageDecoder.h" |
michael@0 | 108 | |
michael@0 | 109 | static SkShader* inflate_shader(const char file[]) |
michael@0 | 110 | { |
michael@0 | 111 | SkBitmap bm; |
michael@0 | 112 | |
michael@0 | 113 | return SkImageDecoder::DecodeFile(file, &bm) ? |
michael@0 | 114 | SkShader::CreateBitmapShader(bm, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode) : |
michael@0 | 115 | NULL; |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | void SkProgressView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 119 | { |
michael@0 | 120 | this->INHERITED::onInflate(dom, node); |
michael@0 | 121 | |
michael@0 | 122 | const char* s; |
michael@0 | 123 | |
michael@0 | 124 | SkASSERT(fOnShader == NULL); |
michael@0 | 125 | SkASSERT(fOffShader == NULL); |
michael@0 | 126 | |
michael@0 | 127 | if ((s = dom.findAttr(node, "src-on")) != NULL) |
michael@0 | 128 | fOnShader = inflate_shader(s); |
michael@0 | 129 | if ((s = dom.findAttr(node, "src-off")) != NULL) |
michael@0 | 130 | fOffShader = inflate_shader(s); |
michael@0 | 131 | (void)dom.findBool(node, "do-interp", &fDoInterp); |
michael@0 | 132 | } |