OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkWidgetViews.h" | 8 #include "SkWidgetViews.h" |
9 #include "SkAnimator.h" | 9 #include "SkAnimator.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 *label = fLabel; | 103 *label = fLabel; |
104 } | 104 } |
105 | 105 |
106 void SkWidgetView::setLabel(const char label[]) | 106 void SkWidgetView::setLabel(const char label[]) |
107 { | 107 { |
108 this->setLabel(label, label ? strlen(label) : 0); | 108 this->setLabel(label, label ? strlen(label) : 0); |
109 } | 109 } |
110 | 110 |
111 void SkWidgetView::setLabel(const char label[], size_t len) | 111 void SkWidgetView::setLabel(const char label[], size_t len) |
112 { | 112 { |
113 if ((label == NULL && fLabel.size() != 0) || !fLabel.equals(label, len)) | 113 if ((label == nullptr && fLabel.size() != 0) || !fLabel.equals(label, len)) |
114 { | 114 { |
115 SkString tmp(label, len); | 115 SkString tmp(label, len); |
116 | 116 |
117 this->onLabelChange(fLabel.c_str(), tmp.c_str()); | 117 this->onLabelChange(fLabel.c_str(), tmp.c_str()); |
118 fLabel.swap(tmp); | 118 fLabel.swap(tmp); |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void SkWidgetView::setLabel(const SkString& label) | 122 void SkWidgetView::setLabel(const SkString& label) |
123 { | 123 { |
(...skipping 22 matching lines...) Expand all Loading... |
146 } | 146 } |
147 | 147 |
148 /*virtual*/ void SkWidgetView::onInflate(const SkDOM& dom, const SkDOM::Node* no
de) | 148 /*virtual*/ void SkWidgetView::onInflate(const SkDOM& dom, const SkDOM::Node* no
de) |
149 { | 149 { |
150 this->INHERITED::onInflate(dom, node); | 150 this->INHERITED::onInflate(dom, node); |
151 | 151 |
152 const char* label = dom.findAttr(node, "label"); | 152 const char* label = dom.findAttr(node, "label"); |
153 if (label) | 153 if (label) |
154 this->setLabel(label); | 154 this->setLabel(label); |
155 | 155 |
156 if ((node = dom.getFirstChild(node, "event")) != NULL) | 156 if ((node = dom.getFirstChild(node, "event")) != nullptr) |
157 fEvent.inflate(dom, node); | 157 fEvent.inflate(dom, node); |
158 } | 158 } |
159 | 159 |
160 /*virtual*/ void SkWidgetView::onLabelChange(const char oldLabel[], const char n
ewLabel[]) | 160 /*virtual*/ void SkWidgetView::onLabelChange(const char oldLabel[], const char n
ewLabel[]) |
161 { | 161 { |
162 this->inval(NULL); | 162 this->inval(nullptr); |
163 } | 163 } |
164 | 164 |
165 static const char gWidgetEventSinkIDSlotName[] = "sk-widget-sinkid-slot"; | 165 static const char gWidgetEventSinkIDSlotName[] = "sk-widget-sinkid-slot"; |
166 | 166 |
167 /*virtual*/ bool SkWidgetView::onPrepareWidgetEvent(SkEvent* evt) | 167 /*virtual*/ bool SkWidgetView::onPrepareWidgetEvent(SkEvent* evt) |
168 { | 168 { |
169 evt->setS32(gWidgetEventSinkIDSlotName, this->getSinkID()); | 169 evt->setS32(gWidgetEventSinkIDSlotName, this->getSinkID()); |
170 return true; | 170 return true; |
171 } | 171 } |
172 | 172 |
(...skipping 28 matching lines...) Expand all Loading... |
201 | 201 |
202 if (fCheckState != state) | 202 if (fCheckState != state) |
203 { | 203 { |
204 this->onCheckStateChange(this->getCheckState(), state); | 204 this->onCheckStateChange(this->getCheckState(), state); |
205 fCheckState = SkToU8(state); | 205 fCheckState = SkToU8(state); |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 /*virtual*/ void SkCheckButtonView::onCheckStateChange(CheckState oldState, Chec
kState newState) | 209 /*virtual*/ void SkCheckButtonView::onCheckStateChange(CheckState oldState, Chec
kState newState) |
210 { | 210 { |
211 this->inval(NULL); | 211 this->inval(nullptr); |
212 } | 212 } |
213 | 213 |
214 /*virtual*/ void SkCheckButtonView::onInflate(const SkDOM& dom, const SkDOM::Nod
e* node) | 214 /*virtual*/ void SkCheckButtonView::onInflate(const SkDOM& dom, const SkDOM::Nod
e* node) |
215 { | 215 { |
216 this->INHERITED::onInflate(dom, node); | 216 this->INHERITED::onInflate(dom, node); |
217 | 217 |
218 int index = dom.findList(node, "check-state", "off,on,unknown"); | 218 int index = dom.findList(node, "check-state", "off,on,unknown"); |
219 if (index >= 0) | 219 if (index >= 0) |
220 this->setCheckState((CheckState)index); | 220 this->setCheckState((CheckState)index); |
221 } | 221 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 evt.setScalar("dimY", this->height()); | 289 evt.setScalar("dimY", this->height()); |
290 fAnim.doUserEvent(evt); | 290 fAnim.doUserEvent(evt); |
291 } | 291 } |
292 | 292 |
293 virtual void onDraw(SkCanvas* canvas) | 293 virtual void onDraw(SkCanvas* canvas) |
294 { | 294 { |
295 SkPaint paint; | 295 SkPaint paint; |
296 SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::
GetMSecs()); | 296 SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::
GetMSecs()); |
297 | 297 |
298 if (diff == SkAnimator::kDifferent) | 298 if (diff == SkAnimator::kDifferent) |
299 this->inval(NULL); | 299 this->inval(nullptr); |
300 else if (diff == SkAnimator::kPartiallyDifferent) | 300 else if (diff == SkAnimator::kPartiallyDifferent) |
301 { | 301 { |
302 SkRect bounds; | 302 SkRect bounds; |
303 fAnim.getInvalBounds(&bounds); | 303 fAnim.getInvalBounds(&bounds); |
304 this->inval(&bounds); | 304 this->inval(&bounds); |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 virtual bool onEvent(const SkEvent& evt) | 308 virtual bool onEvent(const SkEvent& evt) |
309 { | 309 { |
310 if (evt.isType(SK_EventType_Inval)) | 310 if (evt.isType(SK_EventType_Inval)) |
311 { | 311 { |
312 this->inval(NULL); | 312 this->inval(nullptr); |
313 return true; | 313 return true; |
314 } | 314 } |
315 if (evt.isType("recommendDim")) | 315 if (evt.isType("recommendDim")) |
316 { | 316 { |
317 SkScalar height; | 317 SkScalar height; |
318 | 318 |
319 if (evt.findScalar("y", &height)) | 319 if (evt.findScalar("y", &height)) |
320 this->setHeight(height); | 320 this->setHeight(height); |
321 return true; | 321 return true; |
322 } | 322 } |
(...skipping 16 matching lines...) Expand all Loading... |
339 SkAnimator fAnim; | 339 SkAnimator fAnim; |
340 | 340 |
341 typedef SkButtonView INHERITED; | 341 typedef SkButtonView INHERITED; |
342 }; | 342 }; |
343 | 343 |
344 ////////////////////////////////////////////////////////////////////////////////
//////////// | 344 ////////////////////////////////////////////////////////////////////////////////
//////////// |
345 ////////////////////////////////////////////////////////////////////////////////
//////////// | 345 ////////////////////////////////////////////////////////////////////////////////
//////////// |
346 | 346 |
347 SkView* SkWidgetFactory(const char name[]) | 347 SkView* SkWidgetFactory(const char name[]) |
348 { | 348 { |
349 if (name == NULL) | 349 if (name == nullptr) |
350 return NULL; | 350 return nullptr; |
351 | 351 |
352 // must be in the same order as the SkSkinWidgetEnum is declared | 352 // must be in the same order as the SkSkinWidgetEnum is declared |
353 static const char* gNames[] = { | 353 static const char* gNames[] = { |
354 "sk-border", | 354 "sk-border", |
355 "sk-button", | 355 "sk-button", |
356 "sk-image", | 356 "sk-image", |
357 "sk-list", | 357 "sk-list", |
358 "sk-progress", | 358 "sk-progress", |
359 "sk-scroll", | 359 "sk-scroll", |
360 "sk-text" | 360 "sk-text" |
361 | 361 |
362 }; | 362 }; |
363 | 363 |
364 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++) | 364 for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++) |
365 if (!strcmp(gNames[i], name)) | 365 if (!strcmp(gNames[i], name)) |
366 return SkWidgetFactory((SkWidgetEnum)i); | 366 return SkWidgetFactory((SkWidgetEnum)i); |
367 | 367 |
368 return NULL; | 368 return nullptr; |
369 } | 369 } |
370 | 370 |
371 #include "SkImageView.h" | 371 #include "SkImageView.h" |
372 #include "SkProgressBarView.h" | 372 #include "SkProgressBarView.h" |
373 #include "SkScrollBarView.h" | 373 #include "SkScrollBarView.h" |
374 #include "SkBorderView.h" | 374 #include "SkBorderView.h" |
375 | 375 |
376 SkView* SkWidgetFactory(SkWidgetEnum sw) | 376 SkView* SkWidgetFactory(SkWidgetEnum sw) |
377 { | 377 { |
378 switch (sw) { | 378 switch (sw) { |
379 case kBorder_WidgetEnum: | 379 case kBorder_WidgetEnum: |
380 return new SkBorderView; | 380 return new SkBorderView; |
381 case kButton_WidgetEnum: | 381 case kButton_WidgetEnum: |
382 return new SkAnimButtonView; | 382 return new SkAnimButtonView; |
383 case kImage_WidgetEnum: | 383 case kImage_WidgetEnum: |
384 return new SkImageView; | 384 return new SkImageView; |
385 case kList_WidgetEnum: | 385 case kList_WidgetEnum: |
386 return new SkListView; | 386 return new SkListView; |
387 case kProgress_WidgetEnum: | 387 case kProgress_WidgetEnum: |
388 return new SkProgressBarView; | 388 return new SkProgressBarView; |
389 case kScroll_WidgetEnum: | 389 case kScroll_WidgetEnum: |
390 return new SkScrollBarView; | 390 return new SkScrollBarView; |
391 case kText_WidgetEnum: | 391 case kText_WidgetEnum: |
392 return new SkStaticTextView; | 392 return new SkStaticTextView; |
393 default: | 393 default: |
394 SkDEBUGFAIL("unknown enum passed to SkWidgetFactory"); | 394 SkDEBUGFAIL("unknown enum passed to SkWidgetFactory"); |
395 break; | 395 break; |
396 } | 396 } |
397 return NULL; | 397 return nullptr; |
398 } | 398 } |
OLD | NEW |