'tools.gyp:timer',
'tools.gyp:url_data_manager',
'views.gyp:views',
- 'views_animated.gyp:views_animated',
'xml.gyp:xml',
],
'msvs_settings': {
'<(skia_include_path)/utils/win',
'<(skia_include_path)/utils/SkDebugUtils.h',
'<(skia_include_path)/utils/SkJSONCPP.h',
- '<(skia_include_path)/views/animated',
'<(skia_include_path)/views/SkOSWindow_Android.h',
'<(skia_include_path)/views/SkOSWindow_iOS.h',
'<(skia_include_path)/views/SkOSWindow_Mac.h',
'../include/views/SkOSWindow_SDL.h',
'../include/views/SkOSWindow_Unix.h',
'../include/views/SkOSWindow_Win.h',
- '../include/views/SkStackViewLayout.h',
'../include/views/SkSystemEventTypes.h',
'../include/views/SkTouchGesture.h',
'../include/views/SkView.h',
'../src/views/SkEventSink.cpp',
'../src/views/SkOSMenu.cpp',
'../src/views/SkParsePaint.cpp',
- '../src/views/SkStackViewLayout.cpp',
'../src/views/SkTagList.cpp',
'../src/views/SkTagList.h',
'../src/views/SkTouchGesture.cpp',
+++ /dev/null
-# Copyright 2015 Google Inc.
-#
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-#Animated widgets are views which use animator.
-
-{
- 'targets': [
- {
- 'target_name': 'views_animated',
- 'type': 'static_library',
- 'dependencies': [
- 'skia_lib.gyp:skia_lib',
- 'animator.gyp:*',
- 'views.gyp:*',
- 'xml.gyp:*',
- ],
- 'include_dirs': [
- '../include/views/animated',
- '../include/views/unix',
- ],
- 'sources': [
- '../include/views/animated/SkBorderView.h',
- '../include/views/animated/SkImageView.h',
- '../include/views/animated/SkProgressBarView.h',
- '../include/views/animated/SkScrollBarView.h',
- '../include/views/animated/SkWidgetViews.h',
-
- '../src/views/animated/SkBorderView.cpp',
- '../src/views/animated/SkImageView.cpp',
- '../src/views/animated/SkProgressBarView.cpp',
- '../src/views/animated/SkScrollBarView.cpp',
- '../src/views/animated/SkStaticTextView.cpp',
- '../src/views/animated/SkWidgetViews.cpp',
- ],
- 'conditions': [
- [ 'skia_os == "mac"', {
- 'link_settings': {
- 'libraries': [
- '$(SDKROOT)/System/Library/Frameworks/Cocoa.framework',
- '$(SDKROOT)/System/Library/Frameworks/Foundation.framework',
- ],
- },
- }],
- [ 'skia_os == "android"', {
- # Android does not support animator so we need to remove all files
- # that have references to it.
- 'include_dirs!': [
- '../include/animator',
- ],
- 'sources!': [
- '../src/views/animated/SkBorderView.cpp',
- '../src/views/animated/SkImageView.cpp',
- '../src/views/animated/SkProgressBarView.cpp',
- '../src/views/animated/SkScrollBarView.cpp',
- '../src/views/animated/SkStaticTextView.cpp',
- '../src/views/animated/SkWidgetViews.cpp',
- ],
- }],
- ],
- 'direct_dependent_settings': {
- 'include_dirs': [
- '../include/views/animated',
- ],
- },
- },
- ],
-}
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkStackViewLayout_DEFINED
-#define SkStackViewLayout_DEFINED
-
-#include "SkView.h"
-
-class SkStackViewLayout : public SkView::Layout {
-public:
- SkStackViewLayout();
-
- enum Orient {
- kHorizontal_Orient,
- kVertical_Orient,
-
- kOrientCount
- };
- Orient getOrient() const { return (Orient)fOrient; }
- void setOrient(Orient);
-
- void getMargin(SkRect*) const;
- void setMargin(const SkRect&);
-
- SkScalar getSpacer() const { return fSpacer; }
- void setSpacer(SkScalar);
-
- /** Controls the posititioning in the same direction as the orientation
- */
- enum Pack {
- kStart_Pack,
- kCenter_Pack,
- kEnd_Pack,
-
- kPackCount
- };
- Pack getPack() const { return (Pack)fPack; }
- void setPack(Pack);
-
- /** Controls the posititioning at right angles to the orientation
- */
- enum Align {
- kStart_Align,
- kCenter_Align,
- kEnd_Align,
- kStretch_Align,
-
- kAlignCount
- };
- Align getAlign() const { return (Align)fAlign; }
- void setAlign(Align);
-
- bool getRound() const { return SkToBool(fRound); }
- void setRound(bool);
-
-protected:
- virtual void onLayoutChildren(SkView* parent);
- virtual void onInflate(const SkDOM&, const SkDOM::Node*);
-
-private:
- SkRect fMargin;
- SkScalar fSpacer;
- uint8_t fOrient, fPack, fAlign, fRound;
-};
-
-class SkFillViewLayout : public SkView::Layout {
-public:
- SkFillViewLayout();
- void getMargin(SkRect*) const;
- void setMargin(const SkRect&);
-
-protected:
- // overrides;
- virtual void onLayoutChildren(SkView* parent);
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
-
-private:
- SkRect fMargin;
- typedef SkView::Layout INHERITED;
-};
-
-#endif
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkBorderView_DEFINED
-#define SkBorderView_DEFINED
-
-#include "SkView.h"
-#include "SkWidgetViews.h"
-#include "SkAnimator.h"
-
-class SkBorderView : public SkWidgetView {
-public:
- SkBorderView();
- ~SkBorderView();
- void setSkin(const char skin[]);
- SkScalar getLeft() const { return fLeft; }
- SkScalar getRight() const { return fRight; }
- SkScalar getTop() const { return fTop; }
- SkScalar getBottom() const { return fBottom; }
-protected:
- //overrides
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
- virtual void onSizeChange();
- virtual void onDraw(SkCanvas* canvas);
- virtual bool onEvent(const SkEvent& evt);
-private:
- SkAnimator fAnim;
- SkScalar fLeft, fRight, fTop, fBottom; //margin on each side
- SkRect fMargin;
-
- typedef SkWidgetView INHERITED;
-};
-
-#endif
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkImageView_DEFINED
-#define SkImageView_DEFINED
-
-#include "SkView.h"
-#include "SkString.h"
-
-class SkAnimator;
-class SkBitmap;
-class SkMatrix;
-
-class SkImageView : public SkView {
-public:
- SkImageView();
- virtual ~SkImageView();
-
- void getUri(SkString*) const;
- void setUri(const char []);
- void setUri(const SkString&);
-
-
- enum ScaleType {
- kMatrix_ScaleType,
- kFitXY_ScaleType,
- kFitStart_ScaleType,
- kFitCenter_ScaleType,
- kFitEnd_ScaleType
- };
- ScaleType getScaleType() const { return (ScaleType)fScaleType; }
- void setScaleType(ScaleType);
-
- bool getImageMatrix(SkMatrix*) const;
- void setImageMatrix(const SkMatrix*);
-
-protected:
- // overrides
- virtual bool onEvent(const SkEvent&);
- virtual void onDraw(SkCanvas*);
- virtual void onInflate(const SkDOM&, const SkDOMNode*);
-
-private:
- SkString fUri;
- SkMatrix* fMatrix; // null or copy of caller's matrix ,,,,,
- union {
- SkAnimator* fAnim;
- SkBitmap* fBitmap;
- } fData;
- uint8_t fScaleType;
- SkBool8 fDataIsAnim; // as opposed to bitmap
- SkBool8 fUriIsValid;
-
- void onUriChange();
- bool getDataBounds(SkRect* bounds);
- bool freeData();
- bool ensureUriIsLoaded();
-
- typedef SkView INHERITED;
-};
-
-#endif
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkProgressBarView_DEFINED
-#define SkProgressBarView_DEFINED
-
-#include "SkView.h"
-#include "SkWidgetViews.h"
-#include "SkAnimator.h"
-
-class SkProgressBarView : public SkWidgetView {
- public:
- SkProgressBarView();
- //SkProgressBarView(int max);
-
- //inflate: "sk-progress"
-
- void reset(); //reset progress to zero
- void setProgress(int progress);
- void changeProgress(int diff);
- void setMax(int max);
-
- int getProgress() const { return fProgress; }
- int getMax() const { return fMax; }
-
- protected:
- //overrides
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
- virtual void onSizeChange();
- virtual void onDraw(SkCanvas* canvas);
- virtual bool onEvent(const SkEvent& evt);
-
- private:
- SkAnimator fAnim;
- int fProgress;
- int fMax;
-
- typedef SkWidgetView INHERITED;
-};
-
-
-
-
-#endif
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkScrollBarView_DEFINED
-#define SkScrollBarView_DEFINED
-
-#include "SkView.h"
-#include "SkWidgetViews.h"
-#include "SkAnimator.h"
-
-class SkScrollBarView : public SkWidgetView {
-public:
- SkScrollBarView();
-
- unsigned getStart() const { return fStartPoint; }
- unsigned getShown() const { return fShownLength; }
- unsigned getTotal() const { return fTotalLength; }
-
- void setStart(unsigned start);
- void setShown(unsigned shown);
- void setTotal(unsigned total);
-
-protected:
- //overrides
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
- virtual void onSizeChange();
- virtual void onDraw(SkCanvas* canvas);
- virtual bool onEvent(const SkEvent& evt);
-
-private:
- SkAnimator fAnim;
- unsigned fTotalLength, fStartPoint, fShownLength;
-
- void adjust();
-
- typedef SkWidgetView INHERITED;
-};
-#endif
+++ /dev/null
-
-/*
- * Copyright 2006 The Android Open Source Project
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-#ifndef SkWidgetViews_DEFINED
-#define SkWidgetViews_DEFINED
-
-#include "SkView.h"
-
-
-enum SkWidgetEnum {
- kBorder_WidgetEnum, //!< <sk-border>
- kButton_WidgetEnum, //!< <sk-button>
- kImage_WidgetEnum, //!< <sk-image>
- kList_WidgetEnum, //!< <sk-list>
- kProgress_WidgetEnum, //!< <sk-progress>
- kScroll_WidgetEnum, //!< <sk-scroll>
- kText_WidgetEnum, //!< <sk-text>
-
- kWidgetEnumCount
-};
-
-//determines which skin to use
-enum SkinEnum {
- kBorder_SkinEnum,
- kButton_SkinEnum,
- kProgress_SkinEnum,
- kScroll_SkinEnum,
- kStaticText_SkinEnum,
-
- kSkinEnumCount
-};
-
-#include "SkAnimator.h"
-//used for inflates
-const char* get_skin_enum_path(SkinEnum se);
-void init_skin_anim(const char path[], SkAnimator* anim);
-void init_skin_anim(SkinEnum se, SkAnimator* anim);
-void init_skin_paint(SkinEnum se, SkPaint* paint);
-void inflate_paint(const SkDOM& dom, const SkDOM::Node* node, SkPaint* paint);
-
-/** Given an enum value, return an instance of the specified widget.
- If the enum is out of range, returns null
-*/
-SkView* SkWidgetFactory(SkWidgetEnum);
-/** Given the inflate/element name of a widget, return an instance of
- the specified widget, or null if name does not match any known
- widget type.
-*/
-SkView* SkWidgetFactory(const char name[]);
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SkWidgetView : public SkView {
-public:
- SkWidgetView();
-
- const char* getLabel() const;
- void getLabel(SkString* label) const;
-
- void setLabel(const char[]);
- void setLabel(const char[], size_t len);
- void setLabel(const SkString&);
-
- SkEvent& event() { return fEvent; }
- const SkEvent& event() const { return fEvent; }
-
- /** Returns true if the widget can post its event to its listeners.
- */
- bool postWidgetEvent();
-
- /** Returns the sinkID of the widgetview that posted the event, or 0
- */
- static SkEventSinkID GetWidgetEventSinkID(const SkEvent&);
-
-protected:
- /** called when the label changes. override in subclasses. default action invals the view's bounds.
- called with the old and new labels, before the label has actually changed.
- */
- virtual void onLabelChange(const char oldLabel[], const char newLabel[]);
- /** called before posting the event to our listeners. Override to add slots to the event
- before posting. Return true to proceed with posting, or false to not post the event to any
- listener. Note: the event passed in may not be the same as calling this->event().
- Be sure to call your INHERITED method as well, so that all classes in the hierarchy get a shot
- at modifying the event (and possibly returning false to abort).
- */
- virtual bool onPrepareWidgetEvent(SkEvent* evt);
-
- // overrides
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
-
-private:
- SkString fLabel;
- SkEvent fEvent;
-
- typedef SkView INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SkButtonView : public SkWidgetView {
-public:
- // inflate: "sk-button"
-
-protected:
- // overrides
- virtual bool onEvent(const SkEvent&);
-private:
- typedef SkWidgetView INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SkCheckButtonView : public SkWidgetView {
-public:
- SkCheckButtonView();
-
- // inflate: "sk-checkbutton"
-
- enum CheckState {
- kOff_CheckState, //!< inflate: check-state="off"
- kOn_CheckState, //!< inflate: check-state="on"
- kUnknown_CheckState //!< inflate: check-state="unknown"
- };
- CheckState getCheckState() const { return (CheckState)fCheckState; }
- void setCheckState(CheckState);
-
- /** use this to extract the CheckState from an event (i.e. one that as posted
- by a SkCheckButtonView). Returns true if the proper slot was present in the event,
- and sets state to that value. If no proper slot is found, returns false and does not
- modify state.
- */
- static bool GetWidgetEventCheckState(const SkEvent&, CheckState* state);
-
-protected:
- // called when the check-state is about to change, but before it actually has
- virtual void onCheckStateChange(CheckState oldState, CheckState newState);
-
- // overrides
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
- virtual bool onPrepareWidgetEvent(SkEvent* evt);
-
-private:
- uint8_t fCheckState;
-
- typedef SkWidgetView INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-#include "SkTextBox.h"
-
-class SkStaticTextView : public SkView {
-public:
- SkStaticTextView();
- virtual ~SkStaticTextView();
-
- enum Mode {
- kFixedSize_Mode,
- kAutoWidth_Mode,
- kAutoHeight_Mode,
-
- kModeCount
- };
- Mode getMode() const { return (Mode)fMode; }
- void setMode(Mode);
-
- SkTextBox::SpacingAlign getSpacingAlign() const { return (SkTextBox::SpacingAlign)fSpacingAlign; }
- void setSpacingAlign(SkTextBox::SpacingAlign);
-
- void getMargin(SkPoint* margin) const;
- void setMargin(SkScalar dx, SkScalar dy);
-
- size_t getText(SkString* text = NULL) const;
- size_t getText(char text[] = NULL) const;
- void setText(const SkString&);
- void setText(const char text[]);
- void setText(const char text[], size_t len);
-
- void getPaint(SkPaint*) const;
- void setPaint(const SkPaint&);
-
-protected:
- // overrides
- virtual void onDraw(SkCanvas*);
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
-
-private:
- SkPoint fMargin;
- SkString fText;
- SkPaint fPaint;
- uint8_t fMode;
- uint8_t fSpacingAlign;
-
- void computeSize();
-
- typedef SkView INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SkAnimator;
-class SkListSource;
-class SkScrollBarView;
-
-class SkListView : public SkWidgetView {
-public:
- SkListView();
- virtual ~SkListView();
-
- bool hasScrollBar() const { return fScrollBar != NULL; }
- void setHasScrollBar(bool);
-
- /** Return the number of visible rows
- */
- int getVisibleRowCount() const { return fVisibleRowCount; }
- /** Return the index of the selected row, or -1 if none
- */
- int getSelection() const { return fCurrIndex; }
- /** Set the index of the selected row, or -1 for none
- */
- void setSelection(int);
- /** If possible, move the selection up and return true,
- else do nothing and return false
- If nothing is selected, select the last item (unless there are no items).
- */
- bool moveSelectionUp();
- /** If possible, move the selection down and return true,
- else do nothing and return false.
- If nothing is selected, select the first item (unless there are no items).
- */
- bool moveSelectionDown();
-
- SkListSource* getListSource() const { return fSource; }
- SkListSource* setListSource(SkListSource*);
-
- /** Call this in your event handler. If the specified event is from a SkListView,
- then it returns the index of the selected item in this list, otherwise it
- returns -1
- */
- static int GetWidgetEventListIndex(const SkEvent&);
-
-protected:
- // overrides
- virtual void onDraw(SkCanvas*);
- virtual void onSizeChange();
- virtual bool onEvent(const SkEvent&);
- virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
- virtual bool onPrepareWidgetEvent(SkEvent*);
-
-private:
- enum DirtyFlags {
- kAnimCount_DirtyFlag = 0x01,
- kAnimContent_DirtyFlag = 0x02
- };
- void dirtyCache(unsigned dirtyFlags);
- bool ensureCache();
-
- int logicalToVisualIndex(int index) const { return index - fScrollIndex; }
- void invalSelection();
- SkScalar getContentWidth() const;
- bool getRowRect(int index, SkRect*) const;
- void ensureSelectionIsVisible();
- void ensureVisibleRowCount();
-
- struct BindingRec;
-
- enum Heights {
- kNormal_Height,
- kSelected_Height
- };
- SkListSource* fSource;
- SkScrollBarView* fScrollBar;
- SkAnimator* fAnims;
- BindingRec* fBindings;
- SkString fSkinName;
- SkScalar fHeights[2];
- int16_t fScrollIndex, fCurrIndex;
- uint16_t fVisibleRowCount, fBindingCount;
- SkBool8 fAnimContentDirty;
- SkBool8 fAnimFocusDirty;
-
- typedef SkWidgetView INHERITED;
-};
-
-class SkListSource : public SkRefCnt {
-public:
-
-
- virtual int countFields();
- virtual void getFieldName(int index, SkString* field);
- /** Return the index of the named field, or -1 if not found */
- virtual int findFieldIndex(const char field[]);
-
- virtual int countRecords();
- virtual void getRecord(int rowIndex, int fieldIndex, SkString* data);
-
- virtual bool prepareWidgetEvent(SkEvent*, int rowIndex);
-
- static SkListSource* Factory(const char name[]);
-private:
- typedef SkRefCnt INHERITED;
-};
-
-#endif
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkStackViewLayout.h"
-
-SkStackViewLayout::SkStackViewLayout()
-{
- fMargin.set(0, 0, 0, 0);
- fSpacer = 0;
- fOrient = kHorizontal_Orient;
- fPack = kStart_Pack;
- fAlign = kStart_Align;
- fRound = false;
-}
-
-void SkStackViewLayout::setOrient(Orient ori)
-{
- SkASSERT((unsigned)ori < kOrientCount);
- fOrient = SkToU8(ori);
-}
-
-void SkStackViewLayout::getMargin(SkRect* margin) const
-{
- if (margin)
- *margin = fMargin;
-}
-
-void SkStackViewLayout::setMargin(const SkRect& margin)
-{
- fMargin = margin;
-}
-
-void SkStackViewLayout::setSpacer(SkScalar spacer)
-{
- fSpacer = spacer;
-}
-
-void SkStackViewLayout::setPack(Pack pack)
-{
- SkASSERT((unsigned)pack < kPackCount);
- fPack = SkToU8(pack);
-}
-
-void SkStackViewLayout::setAlign(Align align)
-{
- SkASSERT((unsigned)align < kAlignCount);
- fAlign = SkToU8(align);
-}
-
-void SkStackViewLayout::setRound(bool r)
-{
- fRound = SkToU8(r);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-typedef SkScalar (*AlignProc)(SkScalar childLimit, SkScalar parentLimit);
-typedef SkScalar (SkView::*GetSizeProc)() const;
-typedef void (SkView::*SetLocProc)(SkScalar coord);
-typedef void (SkView::*SetSizeProc)(SkScalar coord);
-
-static SkScalar left_align_proc(SkScalar childLimit, SkScalar parentLimit) { return 0; }
-static SkScalar center_align_proc(SkScalar childLimit, SkScalar parentLimit) { return SkScalarHalf(parentLimit - childLimit); }
-static SkScalar right_align_proc(SkScalar childLimit, SkScalar parentLimit) { return parentLimit - childLimit; }
-static SkScalar fill_align_proc(SkScalar childLimit, SkScalar parentLimit) { return 0; }
-
-/* Measure the main-dimension for all the children. If a child is marked flex in that direction
- ignore its current value but increment the counter for flexChildren
-*/
-static SkScalar compute_children_limit(SkView* parent, GetSizeProc sizeProc, int* count,
- uint32_t flexMask, int* flexCount)
-{
- SkView::B2FIter iter(parent);
- SkView* child;
- SkScalar limit = 0;
- int n = 0, flex = 0;
-
- while ((child = iter.next()) != nullptr)
- {
- n += 1;
- if (child->getFlags() & flexMask)
- flex += 1;
- else
- limit += (child->*sizeProc)();
- }
- if (count)
- *count = n;
- if (flexCount)
- *flexCount = flex;
- return limit;
-}
-
-void SkStackViewLayout::onLayoutChildren(SkView* parent)
-{
- static AlignProc gAlignProcs[] = {
- left_align_proc,
- center_align_proc,
- right_align_proc,
- fill_align_proc
- };
-
- SkScalar startM, endM, crossStartM, crossLimit;
- GetSizeProc mainGetSizeP, crossGetSizeP;
- SetLocProc mainLocP, crossLocP;
- SetSizeProc mainSetSizeP, crossSetSizeP;
- SkView::Flag_Mask flexMask;
-
- if (fOrient == kHorizontal_Orient)
- {
- startM = fMargin.fLeft;
- endM = fMargin.fRight;
- crossStartM = fMargin.fTop;
- crossLimit = -fMargin.fTop - fMargin.fBottom;
-
- mainGetSizeP = &SkView::width;
- crossGetSizeP = &SkView::height;
- mainLocP = &SkView::setLocX;
- crossLocP = &SkView::setLocY;
-
- mainSetSizeP = &SkView::setWidth;
- crossSetSizeP = &SkView::setHeight;
-
- flexMask = SkView::kFlexH_Mask;
- }
- else
- {
- startM = fMargin.fTop;
- endM = fMargin.fBottom;
- crossStartM = fMargin.fLeft;
- crossLimit = -fMargin.fLeft - fMargin.fRight;
-
- mainGetSizeP = &SkView::height;
- crossGetSizeP = &SkView::width;
- mainLocP = &SkView::setLocY;
- crossLocP = &SkView::setLocX;
-
- mainSetSizeP = &SkView::setHeight;
- crossSetSizeP = &SkView::setWidth;
-
- flexMask = SkView::kFlexV_Mask;
- }
- crossLimit += (parent->*crossGetSizeP)();
- if (fAlign != kStretch_Align)
- crossSetSizeP = nullptr;
-
- int childCount, flexCount;
- SkScalar childLimit = compute_children_limit(parent, mainGetSizeP, &childCount, flexMask, &flexCount);
-
- if (childCount == 0)
- return;
-
- childLimit += (childCount - 1) * fSpacer;
-
- SkScalar parentLimit = (parent->*mainGetSizeP)() - startM - endM;
- SkScalar pos = startM + gAlignProcs[fPack](childLimit, parentLimit);
- SkScalar flexAmount = 0;
- SkView::B2FIter iter(parent);
- SkView* child;
-
- if (flexCount > 0 && parentLimit > childLimit)
- flexAmount = (parentLimit - childLimit) / flexCount;
-
- while ((child = iter.next()) != nullptr)
- {
- if (fRound)
- pos = SkScalarRoundToScalar(pos);
- (child->*mainLocP)(pos);
- SkScalar crossLoc = crossStartM + gAlignProcs[fAlign]((child->*crossGetSizeP)(), crossLimit);
- if (fRound)
- crossLoc = SkScalarRoundToScalar(crossLoc);
- (child->*crossLocP)(crossLoc);
-
- if (crossSetSizeP)
- (child->*crossSetSizeP)(crossLimit);
- if (child->getFlags() & flexMask)
- (child->*mainSetSizeP)(flexAmount);
- pos += (child->*mainGetSizeP)() + fSpacer;
- }
-}
-
-//////////////////////////////////////////////////////////////////////////////////////
-
-#ifdef SK_DEBUG
- static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[])
- {
- const char* value = dom.findAttr(node, attr);
- if (value)
- SkDebugf("unknown attribute %s=\"%s\"\n", attr, value);
- }
-#else
- #define assert_no_attr(dom, node, attr)
-#endif
-
-void SkStackViewLayout::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- int index;
- SkScalar value[4];
-
- if ((index = dom.findList(node, "orient", "horizontal,vertical")) >= 0)
- this->setOrient((Orient)index);
- else {
- assert_no_attr(dom, node, "orient");
- }
-
- if (dom.findScalars(node, "margin", value, 4))
- {
- SkRect margin;
- margin.set(value[0], value[1], value[2], value[3]);
- this->setMargin(margin);
- }
- else {
- assert_no_attr(dom, node, "margin");
- }
-
- if (dom.findScalar(node, "spacer", value))
- this->setSpacer(value[0]);
- else {
- assert_no_attr(dom, node, "spacer");
- }
-
- if ((index = dom.findList(node, "pack", "start,center,end")) >= 0)
- this->setPack((Pack)index);
- else {
- assert_no_attr(dom, node, "pack");
- }
-
- if ((index = dom.findList(node, "align", "start,center,end,stretch")) >= 0)
- this->setAlign((Align)index);
- else {
- assert_no_attr(dom, node, "align");
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////
-
-SkFillViewLayout::SkFillViewLayout()
-{
- fMargin.setEmpty();
-}
-
-void SkFillViewLayout::getMargin(SkRect* r) const
-{
- if (r)
- *r = fMargin;
-}
-
-void SkFillViewLayout::setMargin(const SkRect& margin)
-{
- fMargin = margin;
-}
-
-void SkFillViewLayout::onLayoutChildren(SkView* parent)
-{
- SkView::B2FIter iter(parent);
- SkView* child;
-
- while ((child = iter.next()) != nullptr)
- {
- child->setLoc(fMargin.fLeft, fMargin.fTop);
- child->setSize( parent->width() - fMargin.fRight - fMargin.fLeft,
- parent->height() - fMargin.fBottom - fMargin.fTop);
- }
-}
-
-void SkFillViewLayout::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
- (void)dom.findScalars(node, "margin", (SkScalar*)&fMargin, 4);
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkBorderView.h"
-#include "SkAnimator.h"
-#include "SkWidgetViews.h"
-#include "SkSystemEventTypes.h"
-#include "SkTime.h"
-#include "SkStackViewLayout.h"
-
-SkBorderView::SkBorderView() : fLeft(SkIntToScalar(0)),
- fRight(SkIntToScalar(0)),
- fTop(SkIntToScalar(0)),
- fBottom(SkIntToScalar(0))
-{
- fAnim.setHostEventSink(this);
- init_skin_anim(kBorder_SkinEnum, &fAnim);
-}
-
-SkBorderView::~SkBorderView()
-{
-
-}
-
-void SkBorderView::setSkin(const char skin[])
-{
- init_skin_anim(skin, &fAnim);
-}
-
-/* virtual */ void SkBorderView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
-}
-
-/*virtual*/ void SkBorderView::onSizeChange()
-{
- this->INHERITED::onSizeChange();
- SkEvent evt("user");
- evt.setString("id", "setDim");
- evt.setScalar("dimX", this->width());
- evt.setScalar("dimY", this->height());
- fAnim.doUserEvent(evt);
-}
-
-/*virtual*/ void SkBorderView::onDraw(SkCanvas* canvas)
-{
- SkPaint paint;
- SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
-
- if (diff == SkAnimator::kDifferent)
- this->inval(nullptr);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fAnim.getInvalBounds(&bounds);
- this->inval(&bounds);
- }
-}
-
-/*virtual*/ bool SkBorderView::onEvent(const SkEvent& evt)
-{
- if (evt.isType(SK_EventType_Inval))
- {
- this->inval(nullptr);
- return true;
- }
- if (evt.isType("recommendDim"))
- {
- evt.findScalar("leftMargin", &fLeft);
- evt.findScalar("rightMargin", &fRight);
- evt.findScalar("topMargin", &fTop);
- evt.findScalar("bottomMargin", &fBottom);
-
- //setup_views.cpp uses SkView::Layout instead of SkStackViewLayout
- //but that gives me an error
- SkStackViewLayout* layout;
- fMargin.set(fLeft, fTop, fRight, fBottom);
- if (this->getLayout())
- {
- layout = (SkStackViewLayout*)this->getLayout();
- layout->setMargin(fMargin);
- }
- else
- {
- layout = new SkStackViewLayout;
- layout->setMargin(fMargin);
- this->setLayout(layout)->unref();
- }
- this->invokeLayout();
- }
- return this->INHERITED::onEvent(evt);
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkImageView.h"
-#include "SkAnimator.h"
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkImageDecoder.h"
-#include "SkMatrix.h"
-#include "SkSystemEventTypes.h"
-#include "SkTime.h"
-
-SkImageView::SkImageView()
-{
- fMatrix = nullptr;
- fScaleType = kMatrix_ScaleType;
-
- fData.fAnim = nullptr; // handles initializing the other union values
- fDataIsAnim = true;
-
- fUriIsValid = false; // an empty string is not valid
-}
-
-SkImageView::~SkImageView()
-{
- if (fMatrix)
- sk_free(fMatrix);
-
- this->freeData();
-}
-
-void SkImageView::getUri(SkString* uri) const
-{
- if (uri)
- *uri = fUri;
-}
-
-void SkImageView::setUri(const char uri[])
-{
- if (!fUri.equals(uri))
- {
- fUri.set(uri);
- this->onUriChange();
- }
-}
-
-void SkImageView::setUri(const SkString& uri)
-{
- if (fUri != uri)
- {
- fUri = uri;
- this->onUriChange();
- }
-}
-
-void SkImageView::setScaleType(ScaleType st)
-{
- SkASSERT((unsigned)st <= kFitEnd_ScaleType);
-
- if ((ScaleType)fScaleType != st)
- {
- fScaleType = SkToU8(st);
- if (fUriIsValid)
- this->inval(nullptr);
- }
-}
-
-bool SkImageView::getImageMatrix(SkMatrix* matrix) const
-{
- if (fMatrix)
- {
- SkASSERT(!fMatrix->isIdentity());
- if (matrix)
- *matrix = *fMatrix;
- return true;
- }
- else
- {
- if (matrix)
- matrix->reset();
- return false;
- }
-}
-
-void SkImageView::setImageMatrix(const SkMatrix* matrix)
-{
- bool changed = false;
-
- if (matrix && !matrix->isIdentity())
- {
- if (fMatrix == nullptr)
- fMatrix = (SkMatrix*)sk_malloc_throw(sizeof(SkMatrix));
- *fMatrix = *matrix;
- changed = true;
- }
- else // set us to identity
- {
- if (fMatrix)
- {
- SkASSERT(!fMatrix->isIdentity());
- sk_free(fMatrix);
- fMatrix = nullptr;
- changed = true;
- }
- }
-
- // only redraw if we changed our matrix and we're not in scaleToFit mode
- if (changed && this->getScaleType() == kMatrix_ScaleType && fUriIsValid)
- this->inval(nullptr);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-
-bool SkImageView::onEvent(const SkEvent& evt)
-{
- if (evt.isType(SK_EventType_Inval))
- {
- if (fUriIsValid)
- this->inval(nullptr);
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-static inline SkMatrix::ScaleToFit scaleTypeToScaleToFit(SkImageView::ScaleType st)
-{
- SkASSERT(st != SkImageView::kMatrix_ScaleType);
- SkASSERT((unsigned)st <= SkImageView::kFitEnd_ScaleType);
-
- SkASSERT(SkImageView::kFitXY_ScaleType - 1 == SkMatrix::kFill_ScaleToFit);
- SkASSERT(SkImageView::kFitStart_ScaleType - 1 == SkMatrix::kStart_ScaleToFit);
- SkASSERT(SkImageView::kFitCenter_ScaleType - 1 == SkMatrix::kCenter_ScaleToFit);
- SkASSERT(SkImageView::kFitEnd_ScaleType - 1 == SkMatrix::kEnd_ScaleToFit);
-
- return (SkMatrix::ScaleToFit)(st - 1);
-}
-
-void SkImageView::onDraw(SkCanvas* canvas)
-{
- SkRect src;
- if (!this->getDataBounds(&src))
- {
- SkDEBUGCODE(canvas->drawColor(SK_ColorRED);)
- return; // nothing to draw
- }
-
- SkAutoCanvasRestore restore(canvas, true);
- SkMatrix matrix;
-
- if (this->getScaleType() == kMatrix_ScaleType)
- (void)this->getImageMatrix(&matrix);
- else
- {
- SkRect dst;
- dst.set(0, 0, this->width(), this->height());
- matrix.setRectToRect(src, dst, scaleTypeToScaleToFit(this->getScaleType()));
- }
- canvas->concat(matrix);
-
- SkPaint paint;
-
- paint.setAntiAlias(true);
-
- if (fDataIsAnim)
- {
- SkMSec now = SkTime::GetMSecs();
-
- SkAnimator::DifferenceType diff = fData.fAnim->draw(canvas, &paint, now);
-
-SkDEBUGF(("SkImageView : now = %X[%12.3f], diff = %d\n", now, now/1000., diff));
-
- if (diff == SkAnimator::kDifferent)
- this->inval(nullptr);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fData.fAnim->getInvalBounds(&bounds);
- matrix.mapRect(&bounds); // get the bounds into view coordinates
- this->inval(&bounds);
- }
- }
- else
- canvas->drawBitmap(*fData.fBitmap, 0, 0, &paint);
-}
-
-void SkImageView::onInflate(const SkDOM& dom, const SkDOMNode* node)
-{
- this->INHERITED::onInflate(dom, node);
-
- const char* src = dom.findAttr(node, "src");
- if (src)
- this->setUri(src);
-
- int index = dom.findList(node, "scaleType", "matrix,fitXY,fitStart,fitCenter,fitEnd");
- if (index >= 0)
- this->setScaleType((ScaleType)index);
-
- // need inflate syntax/reader for matrix
-}
-
-/////////////////////////////////////////////////////////////////////////////////////
-
-void SkImageView::onUriChange()
-{
- if (this->freeData())
- this->inval(nullptr);
- fUriIsValid = true; // give ensureUriIsLoaded() a shot at the new uri
-}
-
-bool SkImageView::freeData()
-{
- if (fData.fAnim) // test is valid for all union values
- {
- if (fDataIsAnim)
- delete fData.fAnim;
- else
- delete fData.fBitmap;
-
- fData.fAnim = nullptr; // valid for all union values
- return true;
- }
- return false;
-}
-
-bool SkImageView::getDataBounds(SkRect* bounds)
-{
- SkASSERT(bounds);
-
- if (this->ensureUriIsLoaded())
- {
- SkScalar width, height;
-
- if (fDataIsAnim)
- {
- if (SkScalarIsNaN(width = fData.fAnim->getScalar("dimensions", "x")) ||
- SkScalarIsNaN(height = fData.fAnim->getScalar("dimensions", "y")))
- {
- // cons up fake bounds
- width = this->width();
- height = this->height();
- }
- }
- else
- {
- width = SkIntToScalar(fData.fBitmap->width());
- height = SkIntToScalar(fData.fBitmap->height());
- }
- bounds->set(0, 0, width, height);
- return true;
- }
- return false;
-}
-
-bool SkImageView::ensureUriIsLoaded()
-{
- if (fData.fAnim) // test is valid for all union values
- {
- SkASSERT(fUriIsValid);
- return true;
- }
- if (!fUriIsValid)
- return false;
-
- // try to load the url
- if (fUri.endsWith(".xml")) // assume it is screenplay
- {
- SkAnimator* anim = new SkAnimator;
-
- if (!anim->decodeURI(fUri.c_str()))
- {
- delete anim;
- fUriIsValid = false;
- return false;
- }
- anim->setHostEventSink(this);
-
- fData.fAnim = anim;
- fDataIsAnim = true;
- }
- else // assume it is an image format
- {
- #if 0
- SkBitmap* bitmap = new SkBitmap;
-
- if (!SkImageDecoder::DecodeURL(fUri.c_str(), bitmap))
- {
- delete bitmap;
- fUriIsValid = false;
- return false;
- }
- fData.fBitmap = bitmap;
- fDataIsAnim = false;
- #else
- return false;
- #endif
- }
- return true;
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkProgressBarView.h"
-#include "SkAnimator.h"
-#include "SkWidgetViews.h"
-#include "SkTime.h"
-#include "SkSystemEventTypes.h"
-
-SkProgressBarView::SkProgressBarView()
-{
- init_skin_anim(kProgress_SkinEnum, &fAnim);
- fAnim.setHostEventSink(this);
- fProgress = 0;
- fMax = 100;
-
-}
-
-void SkProgressBarView::changeProgress(int diff)
-{
- int newProg = fProgress + diff;
- if (newProg > 0 && newProg < fMax)
- this->setProgress(newProg);
- //otherwise i'll just leave it as it is
- //this implies that if a new max and progress are set, max must be set first
-}
-
-/*virtual*/ void SkProgressBarView::onDraw(SkCanvas* canvas)
-{
- SkPaint paint;
- SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
-
- if (diff == SkAnimator::kDifferent)
- this->inval(nullptr);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fAnim.getInvalBounds(&bounds);
- this->inval(&bounds);
- }
-}
-
-/*virtual*/ bool SkProgressBarView::onEvent(const SkEvent& evt)
-{
- if (evt.isType(SK_EventType_Inval))
- {
- this->inval(nullptr);
- return true;
- }
- if (evt.isType("recommendDim"))
- {
- SkScalar height;
-
- if (evt.findScalar("y", &height))
- this->setHeight(height);
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-/*virtual*/ void SkProgressBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
- int32_t temp;
- if (dom.findS32(node, "max", &temp))
- this->setMax(temp);
- if (dom.findS32(node, "progress", &temp))
- this->setProgress(temp);
-}
-
-/*virtual*/ void SkProgressBarView::onSizeChange()
-{
- this->INHERITED::onSizeChange();
- SkEvent evt("user");
- evt.setString("id", "setDim");
- evt.setScalar("dimX", this->width());
- evt.setScalar("dimY", this->height());
- fAnim.doUserEvent(evt);
-}
-
-void SkProgressBarView::reset()
-{
- fProgress = 0;
- SkEvent e("user");
- e.setString("id", "reset");
- fAnim.doUserEvent(e);
-}
-
-void SkProgressBarView::setMax(int max)
-{
- fMax = max;
- SkEvent e("user");
- e.setString("id", "setMax");
- e.setS32("newMax", max);
- fAnim.doUserEvent(e);
-}
-
-void SkProgressBarView::setProgress(int progress)
-{
- fProgress = progress;
- SkEvent e("user");
- e.setString("id", "setProgress");
- e.setS32("newProgress", progress);
- fAnim.doUserEvent(e);
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkScrollBarView.h"
-#include "SkAnimator.h"
-#include "SkWidgetViews.h"
-#include "SkSystemEventTypes.h"
-#include "SkTime.h"
-
-//see SkProgressBarView.cpp
-//#include "SkWidgetViews.cpp"
-
-SkScrollBarView::SkScrollBarView()
-{
- fAnim.setHostEventSink(this);
- init_skin_anim(kScroll_SkinEnum, &fAnim);
-
- fTotalLength = 0;
- fStartPoint = 0;
- fShownLength = 0;
-
- this->adjust();
-}
-
-void SkScrollBarView::setStart(unsigned start)
-{
- if ((int)start < 0)
- start = 0;
-
- if (fStartPoint != start)
- {
- fStartPoint = start;
- this->adjust();
- }
-}
-
-void SkScrollBarView::setShown(unsigned shown)
-{
- if ((int)shown < 0)
- shown = 0;
-
- if (fShownLength != shown)
- {
- fShownLength = shown;
- this->adjust();
- }
-}
-
-void SkScrollBarView::setTotal(unsigned total)
-{
- if ((int)total < 0)
- total = 0;
-
- if (fTotalLength != total)
- {
- fTotalLength = total;
- this->adjust();
- }
-}
-
-/* virtual */ void SkScrollBarView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
-
- int32_t value;
- if (dom.findS32(node, "total", &value))
- this->setTotal(value);
- if (dom.findS32(node, "shown", &value))
- this->setShown(value);
-}
-
-/*virtual*/ void SkScrollBarView::onSizeChange()
-{
- this->INHERITED::onSizeChange();
- SkEvent evt("user");
- evt.setString("id", "setDim");
- evt.setScalar("dimX", this->width());
- evt.setScalar("dimY", this->height());
- fAnim.doUserEvent(evt);
-}
-
-/*virtual*/ void SkScrollBarView::onDraw(SkCanvas* canvas)
-{
- SkPaint paint;
- SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
-
- if (diff == SkAnimator::kDifferent)
- this->inval(nullptr);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fAnim.getInvalBounds(&bounds);
- this->inval(&bounds);
- }
-}
-
-/*virtual*/ bool SkScrollBarView::onEvent(const SkEvent& evt)
-{
- if (evt.isType(SK_EventType_Inval))
- {
- this->inval(nullptr);
- return true;
- }
- if (evt.isType("recommendDim"))
- {
- SkScalar width;
-
- if (evt.findScalar("x", &width))
- this->setWidth(width);
- return true;
- }
-
- return this->INHERITED::onEvent(evt);
-}
-
-void SkScrollBarView::adjust()
-{
- int total = fTotalLength;
- int start = fStartPoint;
- int shown = fShownLength;
-// int hideBar = 0;
-
- if (total <= 0 || shown <= 0 || shown >= total) // no bar to show
- {
- total = 1; // avoid divide-by-zero. should be done by skin/script
-// hideBar = 1; // signal we don't want a thumb
- }
- else
- {
- if (start + shown > total)
- start = total - shown;
- }
-
- SkEvent e("user");
- e.setString("id", "adjustScrollBar");
- e.setScalar("_totalLength", SkIntToScalar(total));
- e.setScalar("_startPoint", SkIntToScalar(start));
- e.setScalar("_shownLength", SkIntToScalar(shown));
-// e.setS32("hideBar", hideBar);
- fAnim.doUserEvent(e);
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkWidgetViews.h"
-#include "SkTextBox.h"
-
-#ifdef SK_DEBUG
-static void assert_no_attr(const SkDOM& dom, const SkDOM::Node* node, const char attr[])
-{
- const char* value = dom.findAttr(node, attr);
- if (value)
- SkDebugf("unknown attribute %s=\"%s\"\n", attr, value);
-}
-#else
- #define assert_no_attr(dom, node, attr)
-#endif
-
-SkStaticTextView::SkStaticTextView()
-{
- fMargin.set(0, 0);
- fMode = kFixedSize_Mode;
- fSpacingAlign = SkTextBox::kStart_SpacingAlign;
-
-// init_skin_paint(kStaticText_SkinEnum, &fPaint);
-}
-
-SkStaticTextView::~SkStaticTextView()
-{
-}
-
-void SkStaticTextView::computeSize()
-{
- if (fMode == kAutoWidth_Mode)
- {
- SkScalar width = fPaint.measureText(fText.c_str(), fText.size());
- this->setWidth(width + fMargin.fX * 2);
- }
- else if (fMode == kAutoHeight_Mode)
- {
- SkScalar width = this->width() - fMargin.fX * 2;
- int lines = width > 0 ? SkTextLineBreaker::CountLines(fText.c_str(), fText.size(), fPaint, width) : 0;
-
- this->setHeight(lines * fPaint.getFontSpacing() + fMargin.fY * 2);
- }
-}
-
-void SkStaticTextView::setMode(Mode mode)
-{
- SkASSERT((unsigned)mode < kModeCount);
-
- if (fMode != mode)
- {
- fMode = SkToU8(mode);
- this->computeSize();
- }
-}
-
-void SkStaticTextView::setSpacingAlign(SkTextBox::SpacingAlign align)
-{
- fSpacingAlign = SkToU8(align);
- this->inval(nullptr);
-}
-
-void SkStaticTextView::getMargin(SkPoint* margin) const
-{
- if (margin)
- *margin = fMargin;
-}
-
-void SkStaticTextView::setMargin(SkScalar dx, SkScalar dy)
-{
- if (fMargin.fX != dx || fMargin.fY != dy)
- {
- fMargin.set(dx, dy);
- this->computeSize();
- this->inval(nullptr);
- }
-}
-
-size_t SkStaticTextView::getText(SkString* text) const
-{
- if (text)
- *text = fText;
- return fText.size();
-}
-
-size_t SkStaticTextView::getText(char text[]) const
-{
- if (text)
- memcpy(text, fText.c_str(), fText.size());
- return fText.size();
-}
-
-void SkStaticTextView::setText(const SkString& text)
-{
- this->setText(text.c_str(), text.size());
-}
-
-void SkStaticTextView::setText(const char text[])
-{
- if (text == nullptr)
- text = "";
- this->setText(text, strlen(text));
-}
-
-void SkStaticTextView::setText(const char text[], size_t len)
-{
- if (!fText.equals(text, len))
- {
- fText.set(text, len);
- this->computeSize();
- this->inval(nullptr);
- }
-}
-
-void SkStaticTextView::getPaint(SkPaint* paint) const
-{
- if (paint)
- *paint = fPaint;
-}
-
-void SkStaticTextView::setPaint(const SkPaint& paint)
-{
- if (fPaint != paint)
- {
- fPaint = paint;
- this->computeSize();
- this->inval(nullptr);
- }
-}
-
-void SkStaticTextView::onDraw(SkCanvas* canvas)
-{
- this->INHERITED::onDraw(canvas);
-
- if (fText.isEmpty())
- return;
-
- SkTextBox box;
-
- box.setMode(fMode == kAutoWidth_Mode ? SkTextBox::kOneLine_Mode : SkTextBox::kLineBreak_Mode);
- box.setSpacingAlign(this->getSpacingAlign());
- box.setBox(fMargin.fX, fMargin.fY, this->width() - fMargin.fX, this->height() - fMargin.fY);
- box.draw(canvas, fText.c_str(), fText.size(), fPaint);
-}
-
-void SkStaticTextView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
-if (false) { // avoid bit rot, suppress warning
- this->INHERITED::onInflate(dom, node);
-
- int index;
- if ((index = dom.findList(node, "mode", "fixed,auto-width,auto-height")) >= 0) {
- this->setMode((Mode)index);
- } else {
- assert_no_attr(dom, node, "mode");
- }
-
- if ((index = dom.findList(node, "spacing-align", "start,center,end")) >= 0) {
- this->setSpacingAlign((SkTextBox::SpacingAlign)index);
- } else {
- assert_no_attr(dom, node, "spacing-align");
- }
-
- SkScalar s[2];
- if (dom.findScalars(node, "margin", s, 2)) {
- this->setMargin(s[0], s[1]);
- } else {
- assert_no_attr(dom, node, "margin");
- }
-
- const char* text = dom.findAttr(node, "text");
- if (text) {
- this->setText(text);
- }
-
- if ((node = dom.getFirstChild(node, "paint")) != nullptr &&
- (node = dom.getFirstChild(node, "screenplay")) != nullptr)
- {
-// FIXME: Including inflate_paint causes Windows build to fail -- it complains
-// that SKListView::SkListView is undefined.
-#if 0
- inflate_paint(dom, node, &fPaint);
-#endif
- }
-}
-}
+++ /dev/null
-
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "SkWidgetViews.h"
-#include "SkAnimator.h"
-#include "SkCanvas.h"
-#include "SkPaint.h"
-#include "SkStream.h"
-#include "SkSystemEventTypes.h"
-
-/*
-I have moved this to SkWidgetViews.h
-enum SkinEnum {
- kButton_SkinEnum,
- kProgress_SkinEnum,
- kScroll_SkinEnum,
- kStaticText_SkinEnum,
-
- kSkinEnumCount
-};
-*/
-
-const char* get_skin_enum_path(SkinEnum se)
-{
- SkASSERT((unsigned)se < kSkinEnumCount);
-
- static const char* gSkinPaths[] = {
- "common/default/default/skins/border3.xml",
- "common/default/default/skins/button.xml",
- "common/default/default/skins/progressBar.xml",
- "common/default/default/skins/scrollBar.xml",
- "common/default/default/skins/statictextpaint.xml"
- };
-
- return gSkinPaths[se];
-}
-
-void init_skin_anim(const char path[], SkAnimator* anim) {
- SkASSERT(path && anim);
-
- SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
- if (!stream.get()) {
- SkDEBUGF(("init_skin_anim: loading skin failed <%s>\n", path));
- sk_throw();
- }
-
- if (!anim->decodeStream(stream)) {
- SkDEBUGF(("init_skin_anim: decoding skin failed <%s>\n", path));
- sk_throw();
- }
-}
-
-void init_skin_anim(SkinEnum se, SkAnimator* anim)
-{
- init_skin_anim(get_skin_enum_path(se), anim);
-}
-
-void init_skin_paint(SkinEnum se, SkPaint* paint)
-{
- SkASSERT(paint);
-
- SkAnimator anim;
- SkCanvas canvas;
-
- init_skin_anim(se, &anim);
- anim.draw(&canvas, paint, 0);
-}
-
-void inflate_paint(const SkDOM& dom, const SkDOM::Node* node, SkPaint* paint)
-{
- SkASSERT(paint);
-
- SkAnimator anim;
- SkCanvas canvas;
-
- if (!anim.decodeDOM(dom, node))
- {
- SkDEBUGF(("inflate_paint: decoding dom failed\n"));
- SkDEBUGCODE(dom.dump(node);)
- sk_throw();
- }
- anim.draw(&canvas, paint, 0);
-}
-
-////////////////////////////////////////////////////////////////////////////////////////
-
-SkWidgetView::SkWidgetView() : SkView(SkView::kFocusable_Mask | SkView::kEnabled_Mask)
-{
-}
-
-const char* SkWidgetView::getLabel() const
-{
- return fLabel.c_str();
-}
-
-void SkWidgetView::getLabel(SkString* label) const
-{
- if (label)
- *label = fLabel;
-}
-
-void SkWidgetView::setLabel(const char label[])
-{
- this->setLabel(label, label ? strlen(label) : 0);
-}
-
-void SkWidgetView::setLabel(const char label[], size_t len)
-{
- if ((label == nullptr && fLabel.size() != 0) || !fLabel.equals(label, len))
- {
- SkString tmp(label, len);
-
- this->onLabelChange(fLabel.c_str(), tmp.c_str());
- fLabel.swap(tmp);
- }
-}
-
-void SkWidgetView::setLabel(const SkString& label)
-{
- if (fLabel != label)
- {
- this->onLabelChange(fLabel.c_str(), label.c_str());
- fLabel = label;
- }
-}
-
-bool SkWidgetView::postWidgetEvent()
-{
- if (!fEvent.isType(""))
- {
- SkEvent evt(fEvent); // make a copy since onPrepareWidgetEvent may edit the event
-
- if (this->onPrepareWidgetEvent(&evt))
- {
- SkDEBUGCODE(evt.dump("SkWidgetView::postWidgetEvent");)
-
- this->postToListeners(evt); // wonder if this should return true if there are > 0 listeners...
- return true;
- }
- }
- return false;
-}
-
-/*virtual*/ void SkWidgetView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
-
- const char* label = dom.findAttr(node, "label");
- if (label)
- this->setLabel(label);
-
- if ((node = dom.getFirstChild(node, "event")) != nullptr)
- fEvent.inflate(dom, node);
-}
-
-/*virtual*/ void SkWidgetView::onLabelChange(const char oldLabel[], const char newLabel[])
-{
- this->inval(nullptr);
-}
-
-static const char gWidgetEventSinkIDSlotName[] = "sk-widget-sinkid-slot";
-
-/*virtual*/ bool SkWidgetView::onPrepareWidgetEvent(SkEvent* evt)
-{
- evt->setS32(gWidgetEventSinkIDSlotName, this->getSinkID());
- return true;
-}
-
-SkEventSinkID SkWidgetView::GetWidgetEventSinkID(const SkEvent& evt)
-{
- int32_t sinkID;
-
- return evt.findS32(gWidgetEventSinkIDSlotName, &sinkID) ? (SkEventSinkID)sinkID : 0;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-/*virtual*/ bool SkButtonView::onEvent(const SkEvent& evt)
-{
- if (evt.isType(SK_EventType_Key) && evt.getFast32() == kOK_SkKey)
- {
- this->postWidgetEvent();
- return true;
- }
- return this->INHERITED::onEvent(evt);
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-SkCheckButtonView::SkCheckButtonView() : fCheckState(kOff_CheckState)
-{
-}
-
-void SkCheckButtonView::setCheckState(CheckState state)
-{
- SkASSERT((unsigned)state <= kUnknown_CheckState);
-
- if (fCheckState != state)
- {
- this->onCheckStateChange(this->getCheckState(), state);
- fCheckState = SkToU8(state);
- }
-}
-
-/*virtual*/ void SkCheckButtonView::onCheckStateChange(CheckState oldState, CheckState newState)
-{
- this->inval(nullptr);
-}
-
-/*virtual*/ void SkCheckButtonView::onInflate(const SkDOM& dom, const SkDOM::Node* node)
-{
- this->INHERITED::onInflate(dom, node);
-
- int index = dom.findList(node, "check-state", "off,on,unknown");
- if (index >= 0)
- this->setCheckState((CheckState)index);
-}
-
-static const char gCheckStateSlotName[] = "sk-checkbutton-check-slot";
-
-/*virtual*/ bool SkCheckButtonView::onPrepareWidgetEvent(SkEvent* evt)
-{
- // could check if we're "disabled", and return false...
-
- evt->setS32(gCheckStateSlotName, this->getCheckState());
- return true;
-}
-
-bool SkCheckButtonView::GetWidgetEventCheckState(const SkEvent& evt, CheckState* state)
-{
- int32_t state32;
-
- if (evt.findS32(gCheckStateSlotName, &state32))
- {
- if (state)
- *state = (CheckState)state32;
- return true;
- }
- return false;
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-#include "SkTime.h"
-#include <stdio.h>
-
-class SkAnimButtonView : public SkButtonView {
-public:
- SkAnimButtonView()
- {
- fAnim.setHostEventSink(this);
- init_skin_anim(kButton_SkinEnum, &fAnim);
- }
-
-protected:
- virtual void onLabelChange(const char oldLabel[], const char newLabel[])
- {
- this->INHERITED::onLabelChange(oldLabel, newLabel);
-
- SkEvent evt("user");
- evt.setString("id", "setLabel");
- evt.setString("LABEL", newLabel);
- fAnim.doUserEvent(evt);
- }
-
- virtual void onFocusChange(bool gainFocus)
- {
- this->INHERITED::onFocusChange(gainFocus);
-
- SkEvent evt("user");
- evt.setString("id", "setFocus");
- evt.setS32("FOCUS", gainFocus);
- fAnim.doUserEvent(evt);
- }
-
- virtual void onSizeChange()
- {
- this->INHERITED::onSizeChange();
-
- SkEvent evt("user");
- evt.setString("id", "setDim");
- evt.setScalar("dimX", this->width());
- evt.setScalar("dimY", this->height());
- fAnim.doUserEvent(evt);
- }
-
- virtual void onDraw(SkCanvas* canvas)
- {
- SkPaint paint;
- SkAnimator::DifferenceType diff = fAnim.draw(canvas, &paint, SkTime::GetMSecs());
-
- if (diff == SkAnimator::kDifferent)
- this->inval(nullptr);
- else if (diff == SkAnimator::kPartiallyDifferent)
- {
- SkRect bounds;
- fAnim.getInvalBounds(&bounds);
- this->inval(&bounds);
- }
- }
-
- virtual bool onEvent(const SkEvent& evt)
- {
- if (evt.isType(SK_EventType_Inval))
- {
- this->inval(nullptr);
- return true;
- }
- if (evt.isType("recommendDim"))
- {
- SkScalar height;
-
- if (evt.findScalar("y", &height))
- this->setHeight(height);
- return true;
- }
- return this->INHERITED::onEvent(evt);
- }
-
- virtual bool onPrepareWidgetEvent(SkEvent* evt)
- {
- if (this->INHERITED::onPrepareWidgetEvent(evt))
- {
- SkEvent e("user");
- e.setString("id", "handlePress");
- (void)fAnim.doUserEvent(e);
- return true;
- }
- return false;
- }
-
-private:
- SkAnimator fAnim;
-
- typedef SkButtonView INHERITED;
-};
-
-////////////////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////////////////
-
-SkView* SkWidgetFactory(const char name[])
-{
- if (name == nullptr)
- return nullptr;
-
- // must be in the same order as the SkSkinWidgetEnum is declared
- static const char* gNames[] = {
- "sk-border",
- "sk-button",
- "sk-image",
- "sk-list",
- "sk-progress",
- "sk-scroll",
- "sk-text"
-
- };
-
- for (size_t i = 0; i < SK_ARRAY_COUNT(gNames); i++)
- if (!strcmp(gNames[i], name))
- return SkWidgetFactory((SkWidgetEnum)i);
-
- return nullptr;
-}
-
-#include "SkImageView.h"
-#include "SkProgressBarView.h"
-#include "SkScrollBarView.h"
-#include "SkBorderView.h"
-
-SkView* SkWidgetFactory(SkWidgetEnum sw)
-{
- switch (sw) {
- case kBorder_WidgetEnum:
- return new SkBorderView;
- case kButton_WidgetEnum:
- return new SkAnimButtonView;
- case kImage_WidgetEnum:
- return new SkImageView;
- case kList_WidgetEnum:
- return new SkListView;
- case kProgress_WidgetEnum:
- return new SkProgressBarView;
- case kScroll_WidgetEnum:
- return new SkScrollBarView;
- case kText_WidgetEnum:
- return new SkStaticTextView;
- default:
- SkDEBUGFAIL("unknown enum passed to SkWidgetFactory");
- break;
- }
- return nullptr;
-}