gfx/skia/trunk/src/views/animated/SkScrollBarView.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 "SkScrollBarView.h"
     9 #include "SkAnimator.h"
    10 #include "SkWidgetViews.h"
    11 #include "SkSystemEventTypes.h"
    12 #include "SkTime.h"
    14 //see SkProgressBarView.cpp
    15 //#include "SkWidgetViews.cpp"
    17 SkScrollBarView::SkScrollBarView()
    18 {
    19     fAnim.setHostEventSink(this);
    20     init_skin_anim(kScroll_SkinEnum, &fAnim);
    22     fTotalLength = 0;
    23     fStartPoint = 0;
    24     fShownLength = 0;
    26     this->adjust();
    27 }
    29 void SkScrollBarView::setStart(unsigned start)
    30 {
    31     if ((int)start < 0)
    32         start = 0;
    34     if (fStartPoint != start)
    35     {
    36         fStartPoint = start;
    37         this->adjust();
    38     }
    39 }
    41 void SkScrollBarView::setShown(unsigned shown)
    42 {
    43     if ((int)shown < 0)
    44         shown = 0;
    46     if (fShownLength != shown)
    47     {
    48         fShownLength = shown;
    49         this->adjust();
    50     }
    51 }
    53 void SkScrollBarView::setTotal(unsigned total)
    54 {
    55     if ((int)total < 0)
    56         total = 0;
    58     if (fTotalLength != total)
    59     {
    60         fTotalLength = total;
    61         this->adjust();
    62     }
    63 }
    65 /* virtual */ void SkScrollBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
    66 {
    67     this->INHERITED::onInflate(dom, node);
    69     int32_t value;
    70     if (dom.findS32(node, "total", &value))
    71         this->setTotal(value);
    72     if (dom.findS32(node, "shown", &value))
    73         this->setShown(value);
    74 }
    76 /*virtual*/ void SkScrollBarView::onSizeChange()
    77 {
    78     this->INHERITED::onSizeChange();
    79     SkEvent evt("user");
    80     evt.setString("id", "setDim");
    81     evt.setScalar("dimX", this->width());
    82     evt.setScalar("dimY", this->height());
    83     fAnim.doUserEvent(evt);
    84 }
    86 /*virtual*/ void SkScrollBarView::onDraw(SkCanvas* canvas)
    87 {
    88     SkPaint                        paint;
    89     SkAnimator::DifferenceType    diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
    91     if (diff == SkAnimator::kDifferent)
    92         this->inval(NULL);
    93     else if (diff == SkAnimator::kPartiallyDifferent)
    94     {
    95         SkRect    bounds;
    96         fAnim.getInvalBounds(&bounds);
    97         this->inval(&bounds);
    98     }
    99 }
   101 /*virtual*/ bool SkScrollBarView::onEvent(const SkEvent& evt)
   102 {
   103     if (evt.isType(SK_EventType_Inval))
   104     {
   105         this->inval(NULL);
   106         return true;
   107     }
   108     if (evt.isType("recommendDim"))
   109     {
   110         SkScalar    width;
   112         if (evt.findScalar("x", &width))
   113             this->setWidth(width);
   114         return true;
   115     }
   117     return this->INHERITED::onEvent(evt);
   118 }
   120 void SkScrollBarView::adjust()
   121 {
   122     int total = fTotalLength;
   123     int start = fStartPoint;
   124     int shown = fShownLength;
   125 //    int hideBar = 0;
   127     if (total <= 0 || shown <= 0 || shown >= total)    // no bar to show
   128     {
   129         total = 1;        // avoid divide-by-zero. should be done by skin/script
   130 //        hideBar = 1;    // signal we don't want a thumb
   131     }
   132     else
   133     {
   134         if (start + shown > total)
   135             start = total - shown;
   136     }
   138     SkEvent e("user");
   139     e.setString("id", "adjustScrollBar");
   140     e.setScalar("_totalLength", SkIntToScalar(total));
   141     e.setScalar("_startPoint", SkIntToScalar(start));
   142     e.setScalar("_shownLength", SkIntToScalar(shown));
   143 //    e.setS32("hideBar", hideBar);
   144     fAnim.doUserEvent(e);
   145 }

mercurial