Home | History | Annotate | Download | only in views
      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 
     12 void SkView::Artist::draw(SkView* view, SkCanvas* canvas)
     13 {
     14     SkASSERT(view && canvas);
     15     this->onDraw(view, canvas);
     16 }
     17 
     18 void SkView::Artist::inflate(const SkDOM& dom, const SkDOM::Node* node)
     19 {
     20     SkASSERT(node);
     21     this->onInflate(dom, node);
     22 }
     23 
     24 void SkView::Artist::onInflate(const SkDOM&, const SkDOM::Node*)
     25 {
     26     // subclass should override this as needed
     27 }
     28 
     29 SkView::Artist* SkView::getArtist() const
     30 {
     31     Artist_SkTagList* rec = (Artist_SkTagList*)this->findTagList(kViewArtist_SkTagList);
     32     SkASSERT(rec == NULL || rec->fArtist != NULL);
     33 
     34     return rec ? rec->fArtist : NULL;
     35 }
     36 
     37 SkView::Artist* SkView::setArtist(Artist* obj)
     38 {
     39     if (obj == NULL)
     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 
     57 void SkView::Layout::layoutChildren(SkView* parent)
     58 {
     59     SkASSERT(parent);
     60     if (parent->width() > 0 && parent->height() > 0)
     61         this->onLayoutChildren(parent);
     62 }
     63 
     64 void SkView::Layout::inflate(const SkDOM& dom, const SkDOM::Node* node)
     65 {
     66     SkASSERT(node);
     67     this->onInflate(dom, node);
     68 }
     69 
     70 void SkView::Layout::onInflate(const SkDOM&, const SkDOM::Node*)
     71 {
     72     // subclass should override this as needed
     73 }
     74 
     75 SkView::Layout* SkView::getLayout() const
     76 {
     77     Layout_SkTagList* rec = (Layout_SkTagList*)this->findTagList(kViewLayout_SkTagList);
     78     SkASSERT(rec == NULL || rec->fLayout != NULL);
     79 
     80     return rec ? rec->fLayout : NULL;
     81 }
     82 
     83 SkView::Layout* SkView::setLayout(Layout* obj, bool invokeLayoutNow)
     84 {
     85     if (obj == NULL)
     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