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 */
8#include "SkViewPriv.h"
9
10//////////////////////////////////////////////////////////////////////
11
12void SkView::Artist::draw(SkView* view, SkCanvas* canvas)
13{
14    SkASSERT(view && canvas);
15    this->onDraw(view, canvas);
16}
17
18void SkView::Artist::inflate(const SkDOM& dom, const SkDOM::Node* node)
19{
20    SkASSERT(node);
21    this->onInflate(dom, node);
22}
23
24void SkView::Artist::onInflate(const SkDOM&, const SkDOM::Node*)
25{
26    // subclass should override this as needed
27}
28
29SkView::Artist* SkView::getArtist() const
30{
31    Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
32    SkASSERT(rec == nullptr || rec->fArtist != nullptr);
33
34    return rec ? rec->fArtist : nullptr;
35}
36
37SkView::Artist* SkView::setArtist(Artist* obj)
38{
39    if (obj == nullptr)
40    {
41        this->removeTagList(kViewArtist_SkTagList);
42    }
43    else    // add/replace
44    {
45        Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
46
47        if (rec)
48            SkRefCnt_SafeAssign(rec->fArtist, obj);
49        else
50            this->addTagList(new Artist_SkTagList(obj));
51    }
52    return obj;
53}
54
55////////////////////////////////////////////////////////////////////////////////
56
57void SkView::Layout::layoutChildren(SkView* parent)
58{
59    SkASSERT(parent);
60    if (parent->width() > 0 && parent->height() > 0)
61        this->onLayoutChildren(parent);
62}
63
64void SkView::Layout::inflate(const SkDOM& dom, const SkDOM::Node* node)
65{
66    SkASSERT(node);
67    this->onInflate(dom, node);
68}
69
70void SkView::Layout::onInflate(const SkDOM&, const SkDOM::Node*)
71{
72    // subclass should override this as needed
73}
74
75SkView::Layout* SkView::getLayout() const
76{
77    Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
78    SkASSERT(rec == nullptr || rec->fLayout != nullptr);
79
80    return rec ? rec->fLayout : nullptr;
81}
82
83SkView::Layout* SkView::setLayout(Layout* obj, bool invokeLayoutNow)
84{
85    if (obj == nullptr)
86    {
87        this->removeTagList(kViewLayout_SkTagList);
88    }
89    else    // add/replace
90    {
91        Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
92
93        if (rec)
94            SkRefCnt_SafeAssign(rec->fLayout, obj);
95        else
96            this->addTagList(new Layout_SkTagList(obj));
97    }
98
99    if (invokeLayoutNow)
100        this->invokeLayout();
101
102    return obj;
103}
104