epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 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 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #include "SkBorderView.h" |
| 9 | #include "SkAnimator.h" |
| 10 | #include "SkWidgetViews.h" |
| 11 | #include "SkSystemEventTypes.h" |
| 12 | #include "SkTime.h" |
| 13 | #include "SkStackViewLayout.h" |
| 14 | |
senorblanco@chromium.org | 64cc579 | 2011-05-19 19:58:58 +0000 | [diff] [blame] | 15 | SkBorderView::SkBorderView() : fLeft(SkIntToScalar(0)), |
| 16 | fRight(SkIntToScalar(0)), |
| 17 | fTop(SkIntToScalar(0)), |
| 18 | fBottom(SkIntToScalar(0)) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 19 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 20 | fAnim.setHostEventSink(this); |
| 21 | init_skin_anim(kBorder_SkinEnum, &fAnim); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | SkBorderView::~SkBorderView() |
| 25 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 26 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void SkBorderView::setSkin(const char skin[]) |
| 30 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 31 | init_skin_anim(skin, &fAnim); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /* virtual */ void SkBorderView::onInflate(const SkDOM& dom, const SkDOM::Node* node) |
| 35 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 36 | this->INHERITED::onInflate(dom, node); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /*virtual*/ void SkBorderView::onSizeChange() |
| 40 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 41 | this->INHERITED::onSizeChange(); |
| 42 | SkEvent evt("user"); |
| 43 | evt.setString("id", "setDim"); |
| 44 | evt.setScalar("dimX", this->width()); |
| 45 | evt.setScalar("dimY", this->height()); |
| 46 | fAnim.doUserEvent(evt); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /*virtual*/ void SkBorderView::onDraw(SkCanvas* canvas) |
| 50 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 51 | SkPaint paint; |
| 52 | SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs()); |
| 53 | |
| 54 | if (diff == SkAnimator::kDifferent) |
| 55 | this->inval(NULL); |
| 56 | else if (diff == SkAnimator::kPartiallyDifferent) |
| 57 | { |
| 58 | SkRect bounds; |
| 59 | fAnim.getInvalBounds(&bounds); |
| 60 | this->inval(&bounds); |
| 61 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /*virtual*/ bool SkBorderView::onEvent(const SkEvent& evt) |
| 65 | { |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 66 | if (evt.isType(SK_EventType_Inval)) |
| 67 | { |
| 68 | this->inval(NULL); |
| 69 | return true; |
| 70 | } |
| 71 | if (evt.isType("recommendDim")) |
| 72 | { |
| 73 | evt.findScalar("leftMargin", &fLeft); |
| 74 | evt.findScalar("rightMargin", &fRight); |
| 75 | evt.findScalar("topMargin", &fTop); |
| 76 | evt.findScalar("bottomMargin", &fBottom); |
| 77 | |
| 78 | //setup_views.cpp uses SkView::Layout instead of SkStackViewLayout |
| 79 | //but that gives me an error |
| 80 | SkStackViewLayout* layout; |
| 81 | fMargin.set(fLeft, fTop, fRight, fBottom); |
| 82 | if (this->getLayout()) |
| 83 | { |
| 84 | layout = (SkStackViewLayout*)this->getLayout(); |
| 85 | layout->setMargin(fMargin); |
| 86 | } |
| 87 | else |
| 88 | { |
| 89 | layout = new SkStackViewLayout; |
| 90 | layout->setMargin(fMargin); |
| 91 | this->setLayout(layout)->unref(); |
| 92 | } |
| 93 | this->invokeLayout(); |
| 94 | } |
| 95 | return this->INHERITED::onEvent(evt); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | } |