gfx/skia/trunk/src/views/animated/SkStaticTextView.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.

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 "SkWidgetViews.h"
michael@0 9 #include "SkTextBox.h"
michael@0 10
michael@0 11 #ifdef SK_DEBUG
michael@0 12 static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[])
michael@0 13 {
michael@0 14 const char* value = dom.findAttr(node, attr);
michael@0 15 if (value)
michael@0 16 SkDebugf("unknown attribute %s=\"%s\"\n", attr, value);
michael@0 17 }
michael@0 18 #else
michael@0 19 #define assert_no_attr(dom, node, attr)
michael@0 20 #endif
michael@0 21
michael@0 22 SkStaticTextView::SkStaticTextView()
michael@0 23 {
michael@0 24 fMargin.set(0, 0);
michael@0 25 fMode = kFixedSize_Mode;
michael@0 26 fSpacingAlign = SkTextBox::kStart_SpacingAlign;
michael@0 27
michael@0 28 // init_skin_paint(kStaticText_SkinEnum, &fPaint);
michael@0 29 }
michael@0 30
michael@0 31 SkStaticTextView::~SkStaticTextView()
michael@0 32 {
michael@0 33 }
michael@0 34
michael@0 35 void SkStaticTextView::computeSize()
michael@0 36 {
michael@0 37 if (fMode == kAutoWidth_Mode)
michael@0 38 {
michael@0 39 SkScalar width = fPaint.measureText(fText.c_str(), fText.size());
michael@0 40 this->setWidth(width + fMargin.fX * 2);
michael@0 41 }
michael@0 42 else if (fMode == kAutoHeight_Mode)
michael@0 43 {
michael@0 44 SkScalar width = this->width() - fMargin.fX * 2;
michael@0 45 int lines = width > 0 ? SkTextLineBreaker::CountLines(fText.c_str(), fText.size(), fPaint, width) : 0;
michael@0 46
michael@0 47 this->setHeight(lines * fPaint.getFontSpacing() + fMargin.fY * 2);
michael@0 48 }
michael@0 49 }
michael@0 50
michael@0 51 void SkStaticTextView::setMode(Mode mode)
michael@0 52 {
michael@0 53 SkASSERT((unsigned)mode < kModeCount);
michael@0 54
michael@0 55 if (fMode != mode)
michael@0 56 {
michael@0 57 fMode = SkToU8(mode);
michael@0 58 this->computeSize();
michael@0 59 }
michael@0 60 }
michael@0 61
michael@0 62 void SkStaticTextView::setSpacingAlign(SkTextBox::SpacingAlign align)
michael@0 63 {
michael@0 64 fSpacingAlign = SkToU8(align);
michael@0 65 this->inval(NULL);
michael@0 66 }
michael@0 67
michael@0 68 void SkStaticTextView::getMargin(SkPoint* margin) const
michael@0 69 {
michael@0 70 if (margin)
michael@0 71 *margin = fMargin;
michael@0 72 }
michael@0 73
michael@0 74 void SkStaticTextView::setMargin(SkScalar dx, SkScalar dy)
michael@0 75 {
michael@0 76 if (fMargin.fX != dx || fMargin.fY != dy)
michael@0 77 {
michael@0 78 fMargin.set(dx, dy);
michael@0 79 this->computeSize();
michael@0 80 this->inval(NULL);
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 size_t SkStaticTextView::getText(SkString* text) const
michael@0 85 {
michael@0 86 if (text)
michael@0 87 *text = fText;
michael@0 88 return fText.size();
michael@0 89 }
michael@0 90
michael@0 91 size_t SkStaticTextView::getText(char text[]) const
michael@0 92 {
michael@0 93 if (text)
michael@0 94 memcpy(text, fText.c_str(), fText.size());
michael@0 95 return fText.size();
michael@0 96 }
michael@0 97
michael@0 98 void SkStaticTextView::setText(const SkString& text)
michael@0 99 {
michael@0 100 this->setText(text.c_str(), text.size());
michael@0 101 }
michael@0 102
michael@0 103 void SkStaticTextView::setText(const char text[])
michael@0 104 {
michael@0 105 if (text == NULL)
michael@0 106 text = "";
michael@0 107 this->setText(text, strlen(text));
michael@0 108 }
michael@0 109
michael@0 110 void SkStaticTextView::setText(const char text[], size_t len)
michael@0 111 {
michael@0 112 if (!fText.equals(text, len))
michael@0 113 {
michael@0 114 fText.set(text, len);
michael@0 115 this->computeSize();
michael@0 116 this->inval(NULL);
michael@0 117 }
michael@0 118 }
michael@0 119
michael@0 120 void SkStaticTextView::getPaint(SkPaint* paint) const
michael@0 121 {
michael@0 122 if (paint)
michael@0 123 *paint = fPaint;
michael@0 124 }
michael@0 125
michael@0 126 void SkStaticTextView::setPaint(const SkPaint& paint)
michael@0 127 {
michael@0 128 if (fPaint != paint)
michael@0 129 {
michael@0 130 fPaint = paint;
michael@0 131 this->computeSize();
michael@0 132 this->inval(NULL);
michael@0 133 }
michael@0 134 }
michael@0 135
michael@0 136 void SkStaticTextView::onDraw(SkCanvas* canvas)
michael@0 137 {
michael@0 138 this->INHERITED::onDraw(canvas);
michael@0 139
michael@0 140 if (fText.isEmpty())
michael@0 141 return;
michael@0 142
michael@0 143 SkTextBox box;
michael@0 144
michael@0 145 box.setMode(fMode == kAutoWidth_Mode ? SkTextBox::kOneLine_Mode : SkTextBox::kLineBreak_Mode);
michael@0 146 box.setSpacingAlign(this->getSpacingAlign());
michael@0 147 box.setBox(fMargin.fX, fMargin.fY, this->width() - fMargin.fX, this->height() - fMargin.fY);
michael@0 148 box.draw(canvas, fText.c_str(), fText.size(), fPaint);
michael@0 149 }
michael@0 150
michael@0 151 void SkStaticTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
michael@0 152 {
michael@0 153 if (false) { // avoid bit rot, suppress warning
michael@0 154 this->INHERITED::onInflate(dom, node);
michael@0 155
michael@0 156 int index;
michael@0 157 if ((index = dom.findList(node, "mode", "fixed,auto-width,auto-height")) >= 0) {
michael@0 158 this->setMode((Mode)index);
michael@0 159 } else {
michael@0 160 assert_no_attr(dom, node, "mode");
michael@0 161 }
michael@0 162
michael@0 163 if ((index = dom.findList(node, "spacing-align", "start,center,end")) >= 0) {
michael@0 164 this->setSpacingAlign((SkTextBox::SpacingAlign)index);
michael@0 165 } else {
michael@0 166 assert_no_attr(dom, node, "spacing-align");
michael@0 167 }
michael@0 168
michael@0 169 SkScalar s[2];
michael@0 170 if (dom.findScalars(node, "margin", s, 2)) {
michael@0 171 this->setMargin(s[0], s[1]);
michael@0 172 } else {
michael@0 173 assert_no_attr(dom, node, "margin");
michael@0 174 }
michael@0 175
michael@0 176 const char* text = dom.findAttr(node, "text");
michael@0 177 if (text) {
michael@0 178 this->setText(text);
michael@0 179 }
michael@0 180
michael@0 181 if ((node = dom.getFirstChild(node, "paint")) != NULL &&
michael@0 182 (node = dom.getFirstChild(node, "screenplay")) != NULL)
michael@0 183 {
michael@0 184 // FIXME: Including inflate_paint causes Windows build to fail -- it complains
michael@0 185 // that SKListView::SkListView is undefined.
michael@0 186 #if 0
michael@0 187 inflate_paint(dom, node, &fPaint);
michael@0 188 #endif
michael@0 189 }
michael@0 190 }
michael@0 191 }

mercurial