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