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