gfx/skia/trunk/include/views/animated/SkWidgetViews.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkWidgetViews_DEFINED
michael@0 11 #define SkWidgetViews_DEFINED
michael@0 12
michael@0 13 #include "SkView.h"
michael@0 14
michael@0 15
michael@0 16 enum SkWidgetEnum {
michael@0 17 kBorder_WidgetEnum, //!< <sk-border>
michael@0 18 kButton_WidgetEnum, //!< <sk-button>
michael@0 19 kImage_WidgetEnum, //!< <sk-image>
michael@0 20 kList_WidgetEnum, //!< <sk-list>
michael@0 21 kProgress_WidgetEnum, //!< <sk-progress>
michael@0 22 kScroll_WidgetEnum, //!< <sk-scroll>
michael@0 23 kText_WidgetEnum, //!< <sk-text>
michael@0 24
michael@0 25 kWidgetEnumCount
michael@0 26 };
michael@0 27
michael@0 28 //determines which skin to use
michael@0 29 enum SkinEnum {
michael@0 30 kBorder_SkinEnum,
michael@0 31 kButton_SkinEnum,
michael@0 32 kProgress_SkinEnum,
michael@0 33 kScroll_SkinEnum,
michael@0 34 kStaticText_SkinEnum,
michael@0 35
michael@0 36 kSkinEnumCount
michael@0 37 };
michael@0 38
michael@0 39 #include "SkAnimator.h"
michael@0 40 //used for inflates
michael@0 41 const char* get_skin_enum_path(SkinEnum se);
michael@0 42 void init_skin_anim(const char path[], SkAnimator* anim);
michael@0 43 void init_skin_anim(SkinEnum se, SkAnimator* anim);
michael@0 44 void init_skin_paint(SkinEnum se, SkPaint* paint);
michael@0 45 void inflate_paint(const SkDOM& dom, const SkDOM::Node* node, SkPaint* paint);
michael@0 46
michael@0 47 /** Given an enum value, return an instance of the specified widget.
michael@0 48 If the enum is out of range, returns null
michael@0 49 */
michael@0 50 SkView* SkWidgetFactory(SkWidgetEnum);
michael@0 51 /** Given the inflate/element name of a widget, return an instance of
michael@0 52 the specified widget, or null if name does not match any known
michael@0 53 widget type.
michael@0 54 */
michael@0 55 SkView* SkWidgetFactory(const char name[]);
michael@0 56
michael@0 57 ////////////////////////////////////////////////////////////////////////////////////////////////
michael@0 58
michael@0 59 class SkWidgetView : public SkView {
michael@0 60 public:
michael@0 61 SkWidgetView();
michael@0 62
michael@0 63 const char* getLabel() const;
michael@0 64 void getLabel(SkString* label) const;
michael@0 65
michael@0 66 void setLabel(const char[]);
michael@0 67 void setLabel(const char[], size_t len);
michael@0 68 void setLabel(const SkString&);
michael@0 69
michael@0 70 SkEvent& event() { return fEvent; }
michael@0 71 const SkEvent& event() const { return fEvent; }
michael@0 72
michael@0 73 /** Returns true if the widget can post its event to its listeners.
michael@0 74 */
michael@0 75 bool postWidgetEvent();
michael@0 76
michael@0 77 /** Returns the sinkID of the widgetview that posted the event, or 0
michael@0 78 */
michael@0 79 static SkEventSinkID GetWidgetEventSinkID(const SkEvent&);
michael@0 80
michael@0 81 protected:
michael@0 82 /** called when the label changes. override in subclasses. default action invals the view's bounds.
michael@0 83 called with the old and new labels, before the label has actually changed.
michael@0 84 */
michael@0 85 virtual void onLabelChange(const char oldLabel[], const char newLabel[]);
michael@0 86 /** called before posting the event to our listeners. Override to add slots to the event
michael@0 87 before posting. Return true to proceed with posting, or false to not post the event to any
michael@0 88 listener. Note: the event passed in may not be the same as calling this->event().
michael@0 89 Be sure to call your INHERITED method as well, so that all classes in the hierarchy get a shot
michael@0 90 at modifying the event (and possibly returning false to abort).
michael@0 91 */
michael@0 92 virtual bool onPrepareWidgetEvent(SkEvent* evt);
michael@0 93
michael@0 94 // overrides
michael@0 95 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 96
michael@0 97 private:
michael@0 98 SkString fLabel;
michael@0 99 SkEvent fEvent;
michael@0 100
michael@0 101 typedef SkView INHERITED;
michael@0 102 };
michael@0 103
michael@0 104 ////////////////////////////////////////////////////////////////////////////////////////////////
michael@0 105
michael@0 106 class SkButtonView : public SkWidgetView {
michael@0 107 public:
michael@0 108 // inflate: "sk-button"
michael@0 109
michael@0 110 protected:
michael@0 111 // overrides
michael@0 112 virtual bool onEvent(const SkEvent&);
michael@0 113 private:
michael@0 114 typedef SkWidgetView INHERITED;
michael@0 115 };
michael@0 116
michael@0 117 ////////////////////////////////////////////////////////////////////////////////////////////////
michael@0 118
michael@0 119 class SkCheckButtonView : public SkWidgetView {
michael@0 120 public:
michael@0 121 SkCheckButtonView();
michael@0 122
michael@0 123 // inflate: "sk-checkbutton"
michael@0 124
michael@0 125 enum CheckState {
michael@0 126 kOff_CheckState, //!< inflate: check-state="off"
michael@0 127 kOn_CheckState, //!< inflate: check-state="on"
michael@0 128 kUnknown_CheckState //!< inflate: check-state="unknown"
michael@0 129 };
michael@0 130 CheckState getCheckState() const { return (CheckState)fCheckState; }
michael@0 131 void setCheckState(CheckState);
michael@0 132
michael@0 133 /** use this to extract the CheckState from an event (i.e. one that as posted
michael@0 134 by a SkCheckButtonView). Returns true if the proper slot was present in the event,
michael@0 135 and sets state to that value. If no proper slot is found, returns false and does not
michael@0 136 modify state.
michael@0 137 */
michael@0 138 static bool GetWidgetEventCheckState(const SkEvent&, CheckState* state);
michael@0 139
michael@0 140 protected:
michael@0 141 // called when the check-state is about to change, but before it actually has
michael@0 142 virtual void onCheckStateChange(CheckState oldState, CheckState newState);
michael@0 143
michael@0 144 // overrides
michael@0 145 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 146 virtual bool onPrepareWidgetEvent(SkEvent* evt);
michael@0 147
michael@0 148 private:
michael@0 149 uint8_t fCheckState;
michael@0 150
michael@0 151 typedef SkWidgetView INHERITED;
michael@0 152 };
michael@0 153
michael@0 154 ////////////////////////////////////////////////////////////////////////////////////////////////
michael@0 155 #include "SkTextBox.h"
michael@0 156
michael@0 157 class SkStaticTextView : public SkView {
michael@0 158 public:
michael@0 159 SkStaticTextView();
michael@0 160 virtual ~SkStaticTextView();
michael@0 161
michael@0 162 enum Mode {
michael@0 163 kFixedSize_Mode,
michael@0 164 kAutoWidth_Mode,
michael@0 165 kAutoHeight_Mode,
michael@0 166
michael@0 167 kModeCount
michael@0 168 };
michael@0 169 Mode getMode() const { return (Mode)fMode; }
michael@0 170 void setMode(Mode);
michael@0 171
michael@0 172 SkTextBox::SpacingAlign getSpacingAlign() const { return (SkTextBox::SpacingAlign)fSpacingAlign; }
michael@0 173 void setSpacingAlign(SkTextBox::SpacingAlign);
michael@0 174
michael@0 175 void getMargin(SkPoint* margin) const;
michael@0 176 void setMargin(SkScalar dx, SkScalar dy);
michael@0 177
michael@0 178 size_t getText(SkString* text = NULL) const;
michael@0 179 size_t getText(char text[] = NULL) const;
michael@0 180 void setText(const SkString&);
michael@0 181 void setText(const char text[]);
michael@0 182 void setText(const char text[], size_t len);
michael@0 183
michael@0 184 void getPaint(SkPaint*) const;
michael@0 185 void setPaint(const SkPaint&);
michael@0 186
michael@0 187 protected:
michael@0 188 // overrides
michael@0 189 virtual void onDraw(SkCanvas*);
michael@0 190 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 191
michael@0 192 private:
michael@0 193 SkPoint fMargin;
michael@0 194 SkString fText;
michael@0 195 SkPaint fPaint;
michael@0 196 uint8_t fMode;
michael@0 197 uint8_t fSpacingAlign;
michael@0 198
michael@0 199 void computeSize();
michael@0 200
michael@0 201 typedef SkView INHERITED;
michael@0 202 };
michael@0 203
michael@0 204 ////////////////////////////////////////////////////////////////////////////////////////////////
michael@0 205
michael@0 206 class SkAnimator;
michael@0 207 class SkListSource;
michael@0 208 class SkScrollBarView;
michael@0 209
michael@0 210 class SkListView : public SkWidgetView {
michael@0 211 public:
michael@0 212 SkListView();
michael@0 213 virtual ~SkListView();
michael@0 214
michael@0 215 bool hasScrollBar() const { return fScrollBar != NULL; }
michael@0 216 void setHasScrollBar(bool);
michael@0 217
michael@0 218 /** Return the number of visible rows
michael@0 219 */
michael@0 220 int getVisibleRowCount() const { return fVisibleRowCount; }
michael@0 221 /** Return the index of the selected row, or -1 if none
michael@0 222 */
michael@0 223 int getSelection() const { return fCurrIndex; }
michael@0 224 /** Set the index of the selected row, or -1 for none
michael@0 225 */
michael@0 226 void setSelection(int);
michael@0 227 /** If possible, move the selection up and return true,
michael@0 228 else do nothing and return false
michael@0 229 If nothing is selected, select the last item (unless there are no items).
michael@0 230 */
michael@0 231 bool moveSelectionUp();
michael@0 232 /** If possible, move the selection down and return true,
michael@0 233 else do nothing and return false.
michael@0 234 If nothing is selected, select the first item (unless there are no items).
michael@0 235 */
michael@0 236 bool moveSelectionDown();
michael@0 237
michael@0 238 SkListSource* getListSource() const { return fSource; }
michael@0 239 SkListSource* setListSource(SkListSource*);
michael@0 240
michael@0 241 /** Call this in your event handler. If the specified event is from a SkListView,
michael@0 242 then it returns the index of the selected item in this list, otherwise it
michael@0 243 returns -1
michael@0 244 */
michael@0 245 static int GetWidgetEventListIndex(const SkEvent&);
michael@0 246
michael@0 247 protected:
michael@0 248 // overrides
michael@0 249 virtual void onDraw(SkCanvas*);
michael@0 250 virtual void onSizeChange();
michael@0 251 virtual bool onEvent(const SkEvent&);
michael@0 252 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 253 virtual bool onPrepareWidgetEvent(SkEvent*);
michael@0 254
michael@0 255 private:
michael@0 256 enum DirtyFlags {
michael@0 257 kAnimCount_DirtyFlag = 0x01,
michael@0 258 kAnimContent_DirtyFlag = 0x02
michael@0 259 };
michael@0 260 void dirtyCache(unsigned dirtyFlags);
michael@0 261 bool ensureCache();
michael@0 262
michael@0 263 int logicalToVisualIndex(int index) const { return index - fScrollIndex; }
michael@0 264 void invalSelection();
michael@0 265 SkScalar getContentWidth() const;
michael@0 266 bool getRowRect(int index, SkRect*) const;
michael@0 267 void ensureSelectionIsVisible();
michael@0 268 void ensureVisibleRowCount();
michael@0 269
michael@0 270 struct BindingRec;
michael@0 271
michael@0 272 enum Heights {
michael@0 273 kNormal_Height,
michael@0 274 kSelected_Height
michael@0 275 };
michael@0 276 SkListSource* fSource;
michael@0 277 SkScrollBarView* fScrollBar;
michael@0 278 SkAnimator* fAnims;
michael@0 279 BindingRec* fBindings;
michael@0 280 SkString fSkinName;
michael@0 281 SkScalar fHeights[2];
michael@0 282 int16_t fScrollIndex, fCurrIndex;
michael@0 283 uint16_t fVisibleRowCount, fBindingCount;
michael@0 284 SkBool8 fAnimContentDirty;
michael@0 285 SkBool8 fAnimFocusDirty;
michael@0 286
michael@0 287 typedef SkWidgetView INHERITED;
michael@0 288 };
michael@0 289
michael@0 290 class SkListSource : public SkRefCnt {
michael@0 291 public:
michael@0 292 SK_DECLARE_INST_COUNT(SkListSource)
michael@0 293
michael@0 294 virtual int countFields();
michael@0 295 virtual void getFieldName(int index, SkString* field);
michael@0 296 /** Return the index of the named field, or -1 if not found */
michael@0 297 virtual int findFieldIndex(const char field[]);
michael@0 298
michael@0 299 virtual int countRecords();
michael@0 300 virtual void getRecord(int rowIndex, int fieldIndex, SkString* data);
michael@0 301
michael@0 302 virtual bool prepareWidgetEvent(SkEvent*, int rowIndex);
michael@0 303
michael@0 304 static SkListSource* Factory(const char name[]);
michael@0 305 private:
michael@0 306 typedef SkRefCnt INHERITED;
michael@0 307 };
michael@0 308
michael@0 309 #endif

mercurial