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 "SkStackViewLayout.h" |
michael@0 | 9 | |
michael@0 | 10 | SkStackViewLayout::SkStackViewLayout() |
michael@0 | 11 | { |
michael@0 | 12 | fMargin.set(0, 0, 0, 0); |
michael@0 | 13 | fSpacer = 0; |
michael@0 | 14 | fOrient = kHorizontal_Orient; |
michael@0 | 15 | fPack = kStart_Pack; |
michael@0 | 16 | fAlign = kStart_Align; |
michael@0 | 17 | fRound = false; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | void SkStackViewLayout::setOrient(Orient ori) |
michael@0 | 21 | { |
michael@0 | 22 | SkASSERT((unsigned)ori < kOrientCount); |
michael@0 | 23 | fOrient = SkToU8(ori); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | void SkStackViewLayout::getMargin(SkRect* margin) const |
michael@0 | 27 | { |
michael@0 | 28 | if (margin) |
michael@0 | 29 | *margin = fMargin; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | void SkStackViewLayout::setMargin(const SkRect& margin) |
michael@0 | 33 | { |
michael@0 | 34 | fMargin = margin; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | void SkStackViewLayout::setSpacer(SkScalar spacer) |
michael@0 | 38 | { |
michael@0 | 39 | fSpacer = spacer; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | void SkStackViewLayout::setPack(Pack pack) |
michael@0 | 43 | { |
michael@0 | 44 | SkASSERT((unsigned)pack < kPackCount); |
michael@0 | 45 | fPack = SkToU8(pack); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | void SkStackViewLayout::setAlign(Align align) |
michael@0 | 49 | { |
michael@0 | 50 | SkASSERT((unsigned)align < kAlignCount); |
michael@0 | 51 | fAlign = SkToU8(align); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | void SkStackViewLayout::setRound(bool r) |
michael@0 | 55 | { |
michael@0 | 56 | fRound = SkToU8(r); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 60 | |
michael@0 | 61 | typedef SkScalar (*AlignProc)(SkScalar childLimit, SkScalar parentLimit); |
michael@0 | 62 | typedef SkScalar (SkView::*GetSizeProc)() const; |
michael@0 | 63 | typedef void (SkView::*SetLocProc)(SkScalar coord); |
michael@0 | 64 | typedef void (SkView::*SetSizeProc)(SkScalar coord); |
michael@0 | 65 | |
michael@0 | 66 | static SkScalar left_align_proc(SkScalar childLimit, SkScalar parentLimit) { return 0; } |
michael@0 | 67 | static SkScalar center_align_proc(SkScalar childLimit, SkScalar parentLimit) { return SkScalarHalf(parentLimit - childLimit); } |
michael@0 | 68 | static SkScalar right_align_proc(SkScalar childLimit, SkScalar parentLimit) { return parentLimit - childLimit; } |
michael@0 | 69 | static SkScalar fill_align_proc(SkScalar childLimit, SkScalar parentLimit) { return 0; } |
michael@0 | 70 | |
michael@0 | 71 | /* Measure the main-dimension for all the children. If a child is marked flex in that direction |
michael@0 | 72 | ignore its current value but increment the counter for flexChildren |
michael@0 | 73 | */ |
michael@0 | 74 | static SkScalar compute_children_limit(SkView* parent, GetSizeProc sizeProc, int* count, |
michael@0 | 75 | uint32_t flexMask, int* flexCount) |
michael@0 | 76 | { |
michael@0 | 77 | SkView::B2FIter iter(parent); |
michael@0 | 78 | SkView* child; |
michael@0 | 79 | SkScalar limit = 0; |
michael@0 | 80 | int n = 0, flex = 0; |
michael@0 | 81 | |
michael@0 | 82 | while ((child = iter.next()) != NULL) |
michael@0 | 83 | { |
michael@0 | 84 | n += 1; |
michael@0 | 85 | if (child->getFlags() & flexMask) |
michael@0 | 86 | flex += 1; |
michael@0 | 87 | else |
michael@0 | 88 | limit += (child->*sizeProc)(); |
michael@0 | 89 | } |
michael@0 | 90 | if (count) |
michael@0 | 91 | *count = n; |
michael@0 | 92 | if (flexCount) |
michael@0 | 93 | *flexCount = flex; |
michael@0 | 94 | return limit; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | void SkStackViewLayout::onLayoutChildren(SkView* parent) |
michael@0 | 98 | { |
michael@0 | 99 | static AlignProc gAlignProcs[] = { |
michael@0 | 100 | left_align_proc, |
michael@0 | 101 | center_align_proc, |
michael@0 | 102 | right_align_proc, |
michael@0 | 103 | fill_align_proc |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | SkScalar startM, endM, crossStartM, crossLimit; |
michael@0 | 107 | GetSizeProc mainGetSizeP, crossGetSizeP; |
michael@0 | 108 | SetLocProc mainLocP, crossLocP; |
michael@0 | 109 | SetSizeProc mainSetSizeP, crossSetSizeP; |
michael@0 | 110 | SkView::Flag_Mask flexMask; |
michael@0 | 111 | |
michael@0 | 112 | if (fOrient == kHorizontal_Orient) |
michael@0 | 113 | { |
michael@0 | 114 | startM = fMargin.fLeft; |
michael@0 | 115 | endM = fMargin.fRight; |
michael@0 | 116 | crossStartM = fMargin.fTop; |
michael@0 | 117 | crossLimit = -fMargin.fTop - fMargin.fBottom; |
michael@0 | 118 | |
michael@0 | 119 | mainGetSizeP = &SkView::width; |
michael@0 | 120 | crossGetSizeP = &SkView::height; |
michael@0 | 121 | mainLocP = &SkView::setLocX; |
michael@0 | 122 | crossLocP = &SkView::setLocY; |
michael@0 | 123 | |
michael@0 | 124 | mainSetSizeP = &SkView::setWidth; |
michael@0 | 125 | crossSetSizeP = &SkView::setHeight; |
michael@0 | 126 | |
michael@0 | 127 | flexMask = SkView::kFlexH_Mask; |
michael@0 | 128 | } |
michael@0 | 129 | else |
michael@0 | 130 | { |
michael@0 | 131 | startM = fMargin.fTop; |
michael@0 | 132 | endM = fMargin.fBottom; |
michael@0 | 133 | crossStartM = fMargin.fLeft; |
michael@0 | 134 | crossLimit = -fMargin.fLeft - fMargin.fRight; |
michael@0 | 135 | |
michael@0 | 136 | mainGetSizeP = &SkView::height; |
michael@0 | 137 | crossGetSizeP = &SkView::width; |
michael@0 | 138 | mainLocP = &SkView::setLocY; |
michael@0 | 139 | crossLocP = &SkView::setLocX; |
michael@0 | 140 | |
michael@0 | 141 | mainSetSizeP = &SkView::setHeight; |
michael@0 | 142 | crossSetSizeP = &SkView::setWidth; |
michael@0 | 143 | |
michael@0 | 144 | flexMask = SkView::kFlexV_Mask; |
michael@0 | 145 | } |
michael@0 | 146 | crossLimit += (parent->*crossGetSizeP)(); |
michael@0 | 147 | if (fAlign != kStretch_Align) |
michael@0 | 148 | crossSetSizeP = NULL; |
michael@0 | 149 | |
michael@0 | 150 | int childCount, flexCount; |
michael@0 | 151 | SkScalar childLimit = compute_children_limit(parent, mainGetSizeP, &childCount, flexMask, &flexCount); |
michael@0 | 152 | |
michael@0 | 153 | if (childCount == 0) |
michael@0 | 154 | return; |
michael@0 | 155 | |
michael@0 | 156 | childLimit += (childCount - 1) * fSpacer; |
michael@0 | 157 | |
michael@0 | 158 | SkScalar parentLimit = (parent->*mainGetSizeP)() - startM - endM; |
michael@0 | 159 | SkScalar pos = startM + gAlignProcs[fPack](childLimit, parentLimit); |
michael@0 | 160 | SkScalar flexAmount = 0; |
michael@0 | 161 | SkView::B2FIter iter(parent); |
michael@0 | 162 | SkView* child; |
michael@0 | 163 | |
michael@0 | 164 | if (flexCount > 0 && parentLimit > childLimit) |
michael@0 | 165 | flexAmount = (parentLimit - childLimit) / flexCount; |
michael@0 | 166 | |
michael@0 | 167 | while ((child = iter.next()) != NULL) |
michael@0 | 168 | { |
michael@0 | 169 | if (fRound) |
michael@0 | 170 | pos = SkScalarRoundToScalar(pos); |
michael@0 | 171 | (child->*mainLocP)(pos); |
michael@0 | 172 | SkScalar crossLoc = crossStartM + gAlignProcs[fAlign]((child->*crossGetSizeP)(), crossLimit); |
michael@0 | 173 | if (fRound) |
michael@0 | 174 | crossLoc = SkScalarRoundToScalar(crossLoc); |
michael@0 | 175 | (child->*crossLocP)(crossLoc); |
michael@0 | 176 | |
michael@0 | 177 | if (crossSetSizeP) |
michael@0 | 178 | (child->*crossSetSizeP)(crossLimit); |
michael@0 | 179 | if (child->getFlags() & flexMask) |
michael@0 | 180 | (child->*mainSetSizeP)(flexAmount); |
michael@0 | 181 | pos += (child->*mainGetSizeP)() + fSpacer; |
michael@0 | 182 | } |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | ////////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 186 | |
michael@0 | 187 | #ifdef SK_DEBUG |
michael@0 | 188 | static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[]) |
michael@0 | 189 | { |
michael@0 | 190 | const char* value = dom.findAttr(node, attr); |
michael@0 | 191 | if (value) |
michael@0 | 192 | SkDebugf("unknown attribute %s=\"%s\"\n", attr, value); |
michael@0 | 193 | } |
michael@0 | 194 | #else |
michael@0 | 195 | #define assert_no_attr(dom, node, attr) |
michael@0 | 196 | #endif |
michael@0 | 197 | |
michael@0 | 198 | void SkStackViewLayout::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 199 | { |
michael@0 | 200 | int index; |
michael@0 | 201 | SkScalar value[4]; |
michael@0 | 202 | |
michael@0 | 203 | if ((index = dom.findList(node, "orient", "horizontal,vertical")) >= 0) |
michael@0 | 204 | this->setOrient((Orient)index); |
michael@0 | 205 | else { |
michael@0 | 206 | assert_no_attr(dom, node, "orient"); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | if (dom.findScalars(node, "margin", value, 4)) |
michael@0 | 210 | { |
michael@0 | 211 | SkRect margin; |
michael@0 | 212 | margin.set(value[0], value[1], value[2], value[3]); |
michael@0 | 213 | this->setMargin(margin); |
michael@0 | 214 | } |
michael@0 | 215 | else { |
michael@0 | 216 | assert_no_attr(dom, node, "margin"); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | if (dom.findScalar(node, "spacer", value)) |
michael@0 | 220 | this->setSpacer(value[0]); |
michael@0 | 221 | else { |
michael@0 | 222 | assert_no_attr(dom, node, "spacer"); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | if ((index = dom.findList(node, "pack", "start,center,end")) >= 0) |
michael@0 | 226 | this->setPack((Pack)index); |
michael@0 | 227 | else { |
michael@0 | 228 | assert_no_attr(dom, node, "pack"); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | if ((index = dom.findList(node, "align", "start,center,end,stretch")) >= 0) |
michael@0 | 232 | this->setAlign((Align)index); |
michael@0 | 233 | else { |
michael@0 | 234 | assert_no_attr(dom, node, "align"); |
michael@0 | 235 | } |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | /////////////////////////////////////////////////////////////////////////////////////////// |
michael@0 | 239 | |
michael@0 | 240 | SkFillViewLayout::SkFillViewLayout() |
michael@0 | 241 | { |
michael@0 | 242 | fMargin.setEmpty(); |
michael@0 | 243 | } |
michael@0 | 244 | |
michael@0 | 245 | void SkFillViewLayout::getMargin(SkRect* r) const |
michael@0 | 246 | { |
michael@0 | 247 | if (r) |
michael@0 | 248 | *r = fMargin; |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | void SkFillViewLayout::setMargin(const SkRect& margin) |
michael@0 | 252 | { |
michael@0 | 253 | fMargin = margin; |
michael@0 | 254 | } |
michael@0 | 255 | |
michael@0 | 256 | void SkFillViewLayout::onLayoutChildren(SkView* parent) |
michael@0 | 257 | { |
michael@0 | 258 | SkView::B2FIter iter(parent); |
michael@0 | 259 | SkView* child; |
michael@0 | 260 | |
michael@0 | 261 | while ((child = iter.next()) != NULL) |
michael@0 | 262 | { |
michael@0 | 263 | child->setLoc(fMargin.fLeft, fMargin.fTop); |
michael@0 | 264 | child->setSize( parent->width() - fMargin.fRight - fMargin.fLeft, |
michael@0 | 265 | parent->height() - fMargin.fBottom - fMargin.fTop); |
michael@0 | 266 | } |
michael@0 | 267 | } |
michael@0 | 268 | |
michael@0 | 269 | void SkFillViewLayout::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
michael@0 | 270 | { |
michael@0 | 271 | this->INHERITED::onInflate(dom, node); |
michael@0 | 272 | (void)dom.findScalars(node, "margin", (SkScalar*)&fMargin, 4); |
michael@0 | 273 | } |