• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #include "SkDOM.h"
9 #include "SkViewPriv.h"
10 
11 //////////////////////////////////////////////////////////////////////
12 
draw(SkView * view,SkCanvas * canvas)13 void SkView::Artist::draw(SkView* view, SkCanvas* canvas)
14 {
15     SkASSERT(view && canvas);
16     this->onDraw(view, canvas);
17 }
18 
inflate(const SkDOM & dom,const SkDOM::Node * node)19 void SkView::Artist::inflate(const SkDOM& dom, const SkDOM::Node* node)
20 {
21     SkASSERT(node);
22     this->onInflate(dom, node);
23 }
24 
onInflate(const SkDOM &,const SkDOM::Node *)25 void SkView::Artist::onInflate(const SkDOM&, const SkDOM::Node*)
26 {
27     // subclass should override this as needed
28 }
29 
getArtist() const30 SkView::Artist* SkView::getArtist() const
31 {
32     Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
33     SkASSERT(rec == nullptr || rec->fArtist != nullptr);
34 
35     return rec ? rec->fArtist : nullptr;
36 }
37 
setArtist(Artist * obj)38 SkView::Artist* SkView::setArtist(Artist* obj)
39 {
40     if (obj == nullptr)
41     {
42         this->removeTagList(kViewArtist_SkTagList);
43     }
44     else    // add/replace
45     {
46         Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
47 
48         if (rec)
49             SkRefCnt_SafeAssign(rec->fArtist, obj);
50         else
51             this->addTagList(new Artist_SkTagList(obj));
52     }
53     return obj;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 
layoutChildren(SkView * parent)58 void SkView::Layout::layoutChildren(SkView* parent)
59 {
60     SkASSERT(parent);
61     if (parent->width() > 0 && parent->height() > 0)
62         this->onLayoutChildren(parent);
63 }
64 
inflate(const SkDOM & dom,const SkDOM::Node * node)65 void SkView::Layout::inflate(const SkDOM& dom, const SkDOM::Node* node)
66 {
67     SkASSERT(node);
68     this->onInflate(dom, node);
69 }
70 
onInflate(const SkDOM &,const SkDOM::Node *)71 void SkView::Layout::onInflate(const SkDOM&, const SkDOM::Node*)
72 {
73     // subclass should override this as needed
74 }
75 
getLayout() const76 SkView::Layout* SkView::getLayout() const
77 {
78     Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
79     SkASSERT(rec == nullptr || rec->fLayout != nullptr);
80 
81     return rec ? rec->fLayout : nullptr;
82 }
83 
setLayout(Layout * obj,bool invokeLayoutNow)84 SkView::Layout* SkView::setLayout(Layout* obj, bool invokeLayoutNow)
85 {
86     if (obj == nullptr)
87     {
88         this->removeTagList(kViewLayout_SkTagList);
89     }
90     else    // add/replace
91     {
92         Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
93 
94         if (rec)
95             SkRefCnt_SafeAssign(rec->fLayout, obj);
96         else
97             this->addTagList(new Layout_SkTagList(obj));
98     }
99 
100     if (invokeLayoutNow)
101         this->invokeLayout();
102 
103     return obj;
104 }
105