gfx/skia/trunk/include/views/SkWidget.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2006 The Android Open Source Project
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef SkWidget_DEFINED
michael@0 9 #define SkWidget_DEFINED
michael@0 10
michael@0 11 #include "SkBitmap.h"
michael@0 12 #include "SkDOM.h"
michael@0 13 #include "SkPaint.h"
michael@0 14 #include "SkString.h"
michael@0 15 #include "SkTDArray.h"
michael@0 16 #include "SkTextBox.h"
michael@0 17 #include "SkView.h"
michael@0 18
michael@0 19 class SkEvent;
michael@0 20 class SkInterpolator;
michael@0 21 class SkShader;
michael@0 22
michael@0 23 ////////////////////////////////////////////////////////////////////////////////
michael@0 24
michael@0 25 class SkWidget : public SkView {
michael@0 26 public:
michael@0 27 SkWidget(uint32_t flags = 0) : SkView(flags | kFocusable_Mask | kEnabled_Mask) {}
michael@0 28
michael@0 29 /** Call this to post the widget's event to its listeners */
michael@0 30 void postWidgetEvent();
michael@0 31
michael@0 32 static void Init();
michael@0 33 static void Term();
michael@0 34 protected:
michael@0 35 // override to add slots to an event before posting
michael@0 36 virtual void prepareWidgetEvent(SkEvent*);
michael@0 37 virtual void onEnabledChange();
michael@0 38
michael@0 39 // <event ...> to initialize the event from XML
michael@0 40 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 41
michael@0 42 private:
michael@0 43 SkEvent fEvent;
michael@0 44 typedef SkView INHERITED;
michael@0 45 };
michael@0 46
michael@0 47 ////////////////////////////////////////////////////////////////////////////////
michael@0 48
michael@0 49 class SkHasLabelWidget : public SkWidget {
michael@0 50 public:
michael@0 51 SkHasLabelWidget(uint32_t flags = 0) : SkWidget(flags) {}
michael@0 52
michael@0 53 size_t getLabel(SkString* label = NULL) const;
michael@0 54 size_t getLabel(char lable[] = NULL) const;
michael@0 55 void setLabel(const SkString&);
michael@0 56 void setLabel(const char label[]);
michael@0 57 void setLabel(const char label[], size_t len);
michael@0 58
michael@0 59 protected:
michael@0 60 // called when the label changes
michael@0 61 virtual void onLabelChange();
michael@0 62
michael@0 63 // overrides
michael@0 64 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 65
michael@0 66 private:
michael@0 67 SkString fLabel;
michael@0 68 typedef SkWidget INHERITED;
michael@0 69 };
michael@0 70
michael@0 71 ////////////////////////////////////////////////////////////////////////////////
michael@0 72
michael@0 73 class SkButtonWidget : public SkHasLabelWidget {
michael@0 74 public:
michael@0 75 SkButtonWidget(uint32_t flags = 0) : SkHasLabelWidget(flags), fState(kOff_State) {}
michael@0 76
michael@0 77 enum State {
michael@0 78 kOff_State, //!< XML: buttonState="off"
michael@0 79 kOn_State, //!< XML: buttonState="on"
michael@0 80 kUnknown_State //!< XML: buttonState="unknown"
michael@0 81 };
michael@0 82 State getButtonState() const { return fState; }
michael@0 83 void setButtonState(State);
michael@0 84
michael@0 85 protected:
michael@0 86 /** called when the label changes. default behavior is to inval the widget */
michael@0 87 virtual void onButtonStateChange();
michael@0 88
michael@0 89 // overrides
michael@0 90 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 91
michael@0 92 private:
michael@0 93 State fState;
michael@0 94 typedef SkHasLabelWidget INHERITED;
michael@0 95 };
michael@0 96
michael@0 97 ////////////////////////////////////////////////////////////////////////////////
michael@0 98
michael@0 99 class SkPushButtonWidget : public SkButtonWidget {
michael@0 100 public:
michael@0 101 SkPushButtonWidget(uint32_t flags = 0) : SkButtonWidget(flags) {}
michael@0 102
michael@0 103 protected:
michael@0 104 virtual bool onEvent(const SkEvent&);
michael@0 105 virtual void onDraw(SkCanvas*);
michael@0 106 virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) SK_OVERRIDE;
michael@0 107 virtual bool onClick(Click* click);
michael@0 108
michael@0 109 private:
michael@0 110 typedef SkButtonWidget INHERITED;
michael@0 111 };
michael@0 112
michael@0 113 ////////////////////////////////////////////////////////////////////////////////
michael@0 114
michael@0 115 class SkCheckBoxWidget : public SkButtonWidget {
michael@0 116 public:
michael@0 117 SkCheckBoxWidget(uint32_t flags = 0);
michael@0 118
michael@0 119 protected:
michael@0 120 virtual bool onEvent(const SkEvent&);
michael@0 121 virtual void onDraw(SkCanvas*);
michael@0 122 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 123
michael@0 124 private:
michael@0 125 typedef SkButtonWidget INHERITED;
michael@0 126 };
michael@0 127
michael@0 128 ////////////////////////////////////////////////////////////////////////////////
michael@0 129
michael@0 130 class SkStaticTextView : public SkView {
michael@0 131 public:
michael@0 132 SkStaticTextView(uint32_t flags = 0);
michael@0 133 virtual ~SkStaticTextView();
michael@0 134
michael@0 135 enum Mode {
michael@0 136 kFixedSize_Mode,
michael@0 137 kAutoWidth_Mode,
michael@0 138 kAutoHeight_Mode,
michael@0 139
michael@0 140 kModeCount
michael@0 141 };
michael@0 142 Mode getMode() const { return (Mode)fMode; }
michael@0 143 void setMode(Mode);
michael@0 144
michael@0 145 SkTextBox::SpacingAlign getSpacingAlign() const { return (SkTextBox::SpacingAlign)fSpacingAlign; }
michael@0 146 void setSpacingAlign(SkTextBox::SpacingAlign);
michael@0 147
michael@0 148 void getMargin(SkPoint* margin) const;
michael@0 149 void setMargin(SkScalar dx, SkScalar dy);
michael@0 150
michael@0 151 size_t getText(SkString* text = NULL) const;
michael@0 152 size_t getText(char text[] = NULL) const;
michael@0 153 void setText(const SkString&);
michael@0 154 void setText(const char text[]);
michael@0 155 void setText(const char text[], size_t len);
michael@0 156
michael@0 157 void getPaint(SkPaint*) const;
michael@0 158 void setPaint(const SkPaint&);
michael@0 159
michael@0 160 protected:
michael@0 161 // overrides
michael@0 162 virtual void onDraw(SkCanvas*);
michael@0 163 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 164
michael@0 165 private:
michael@0 166 SkPoint fMargin;
michael@0 167 SkString fText;
michael@0 168 SkPaint fPaint;
michael@0 169 uint8_t fMode;
michael@0 170 uint8_t fSpacingAlign;
michael@0 171
michael@0 172 void computeSize();
michael@0 173
michael@0 174 typedef SkView INHERITED;
michael@0 175 };
michael@0 176
michael@0 177 ////////////////////////////////////////////////////////////////////////////////
michael@0 178
michael@0 179 class SkBitmapView : public SkView {
michael@0 180 public:
michael@0 181 SkBitmapView(uint32_t flags = 0);
michael@0 182 virtual ~SkBitmapView();
michael@0 183
michael@0 184 bool getBitmap(SkBitmap*) const;
michael@0 185 void setBitmap(const SkBitmap*, bool viewOwnsPixels);
michael@0 186 bool loadBitmapFromFile(const char path[]);
michael@0 187
michael@0 188 protected:
michael@0 189 virtual void onDraw(SkCanvas*);
michael@0 190 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
michael@0 191
michael@0 192 private:
michael@0 193 SkBitmap fBitmap;
michael@0 194 typedef SkView INHERITED;
michael@0 195 };
michael@0 196
michael@0 197 ////////////////////////////////////////////////////////////////////////////////
michael@0 198
michael@0 199 class SkHasLabelView : public SkView {
michael@0 200 public:
michael@0 201 void getLabel(SkString*) const;
michael@0 202 void setLabel(const SkString&);
michael@0 203 void setLabel(const char label[]);
michael@0 204
michael@0 205 protected:
michael@0 206 SkString fLabel;
michael@0 207
michael@0 208 // called when the label changes
michael@0 209 virtual void onLabelChange();
michael@0 210
michael@0 211 // overrides
michael@0 212 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 213 };
michael@0 214
michael@0 215 ////////////////////////////////////////////////////////////////////////////////
michael@0 216
michael@0 217 class SkPushButtonView : public SkHasLabelView {
michael@0 218 public:
michael@0 219 SkPushButtonView(uint32_t flags = 0);
michael@0 220
michael@0 221 protected:
michael@0 222 virtual void onDraw(SkCanvas*);
michael@0 223 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 224 };
michael@0 225
michael@0 226 ////////////////////////////////////////////////////////////////////////////////
michael@0 227
michael@0 228 class SkCheckBoxView : public SkHasLabelView {
michael@0 229 public:
michael@0 230 SkCheckBoxView(uint32_t flags = 0);
michael@0 231
michael@0 232 enum State {
michael@0 233 kOff_State,
michael@0 234 kOn_State,
michael@0 235 kMaybe_State
michael@0 236 };
michael@0 237 State getState() const { return fState; }
michael@0 238 void setState(State);
michael@0 239
michael@0 240 protected:
michael@0 241 virtual void onDraw(SkCanvas*);
michael@0 242 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
michael@0 243
michael@0 244 private:
michael@0 245 State fState;
michael@0 246 };
michael@0 247
michael@0 248 ////////////////////////////////////////////////////////////////////////////////
michael@0 249
michael@0 250 class SkProgressView : public SkView {
michael@0 251 public:
michael@0 252 SkProgressView(uint32_t flags = 0);
michael@0 253 virtual ~SkProgressView();
michael@0 254
michael@0 255 uint16_t getValue() const { return fValue; }
michael@0 256 uint16_t getMax() const { return fMax; }
michael@0 257
michael@0 258 void setMax(U16CPU max);
michael@0 259 void setValue(U16CPU value);
michael@0 260
michael@0 261 protected:
michael@0 262 virtual void onDraw(SkCanvas*);
michael@0 263 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 264
michael@0 265 private:
michael@0 266 uint16_t fValue, fMax;
michael@0 267 SkShader* fOnShader, *fOffShader;
michael@0 268 SkInterpolator* fInterp;
michael@0 269 bool fDoInterp;
michael@0 270
michael@0 271 typedef SkView INHERITED;
michael@0 272 };
michael@0 273
michael@0 274 ////////////////////////////////////////////////////////////////////////////////
michael@0 275
michael@0 276 class SkListSource : public SkEventSink {
michael@0 277 public:
michael@0 278 virtual int countRows() = 0;
michael@0 279 virtual void getRow(int index, SkString* left, SkString* right) = 0;
michael@0 280 virtual SkEvent* getEvent(int index);
michael@0 281
michael@0 282 static SkListSource* CreateFromDir(const char path[], const char suffix[],
michael@0 283 const char targetPrefix[]);
michael@0 284 static SkListSource* CreateFromDOM(const SkDOM& dom, const SkDOM::Node* node);
michael@0 285 };
michael@0 286
michael@0 287 ////////////////////////////////////////////////////////////////////////////////
michael@0 288
michael@0 289 class SkListView : public SkView {
michael@0 290 public:
michael@0 291 SkListView(uint32_t flags = 0);
michael@0 292 virtual ~SkListView();
michael@0 293
michael@0 294 SkScalar getRowHeight() const { return fRowHeight; }
michael@0 295 void setRowHeight(SkScalar);
michael@0 296
michael@0 297 /** Return the index of the selected row, or -1 if none
michael@0 298 */
michael@0 299 int getSelection() const { return fCurrIndex; }
michael@0 300 /** Set the index of the selected row, or -1 for none
michael@0 301 */
michael@0 302 void setSelection(int);
michael@0 303
michael@0 304 void moveSelectionUp();
michael@0 305 void moveSelectionDown();
michael@0 306
michael@0 307 enum Attr {
michael@0 308 kBG_Attr,
michael@0 309 kNormalText_Attr,
michael@0 310 kHiliteText_Attr,
michael@0 311 kHiliteCell_Attr,
michael@0 312 kAttrCount
michael@0 313 };
michael@0 314 SkPaint& paint(Attr);
michael@0 315
michael@0 316 SkListSource* getListSource() const { return fSource; }
michael@0 317 SkListSource* setListSource(SkListSource*);
michael@0 318
michael@0 319 #if 0
michael@0 320 enum Action {
michael@0 321 kSelectionChange_Action,
michael@0 322 kSelectionPicked_Action,
michael@0 323 kActionCount
michael@0 324 };
michael@0 325 /** If event is not null, it is retained by the view, and a copy
michael@0 326 of the event will be posted to its listeners when the specified
michael@0 327 action occurs. If event is null, then no event will be posted for
michael@0 328 the specified action.
michael@0 329 */
michael@0 330 void setActionEvent(Action, SkEvent* event);
michael@0 331 #endif
michael@0 332
michael@0 333 protected:
michael@0 334 virtual void onDraw(SkCanvas*);
michael@0 335 virtual void onSizeChange();
michael@0 336 virtual bool onEvent(const SkEvent&);
michael@0 337 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 338
michael@0 339 private:
michael@0 340 SkPaint fPaint[kAttrCount];
michael@0 341 SkListSource* fSource;
michael@0 342 SkScalar fRowHeight;
michael@0 343 int fCurrIndex; // logical index
michael@0 344 int fScrollIndex; // logical index of top-most visible row
michael@0 345 int fVisibleRowCount;
michael@0 346 SkString* fStrCache;
michael@0 347
michael@0 348 void dirtyStrCache();
michael@0 349 void ensureStrCache(int visibleCount);
michael@0 350
michael@0 351 int logicalToVisualIndex(int index) const { return index - fScrollIndex; }
michael@0 352 void invalSelection();
michael@0 353 bool getRowRect(int index, SkRect*) const;
michael@0 354 void ensureSelectionIsVisible();
michael@0 355
michael@0 356 typedef SkView INHERITED;
michael@0 357 };
michael@0 358
michael@0 359 ////////////////////////////////////////////////////////////////////////////////
michael@0 360
michael@0 361 class SkGridView : public SkView {
michael@0 362 public:
michael@0 363 SkGridView(uint32_t flags = 0);
michael@0 364 virtual ~SkGridView();
michael@0 365
michael@0 366 void getCellSize(SkPoint*) const;
michael@0 367 void setCellSize(SkScalar x, SkScalar y);
michael@0 368
michael@0 369 /** Return the index of the selected item, or -1 if none
michael@0 370 */
michael@0 371 int getSelection() const { return fCurrIndex; }
michael@0 372 /** Set the index of the selected row, or -1 for none
michael@0 373 */
michael@0 374 void setSelection(int);
michael@0 375
michael@0 376 void moveSelectionUp();
michael@0 377 void moveSelectionDown();
michael@0 378
michael@0 379 enum Attr {
michael@0 380 kBG_Attr,
michael@0 381 kHiliteCell_Attr,
michael@0 382 kAttrCount
michael@0 383 };
michael@0 384 SkPaint& paint(Attr);
michael@0 385
michael@0 386 SkListSource* getListSource() const { return fSource; }
michael@0 387 SkListSource* setListSource(SkListSource*);
michael@0 388
michael@0 389 protected:
michael@0 390 virtual void onDraw(SkCanvas*);
michael@0 391 virtual void onSizeChange();
michael@0 392 virtual bool onEvent(const SkEvent&);
michael@0 393 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 394
michael@0 395 private:
michael@0 396 SkView* fScrollBar;
michael@0 397 SkPaint fPaint[kAttrCount];
michael@0 398 SkListSource* fSource;
michael@0 399 int fCurrIndex; // logical index
michael@0 400
michael@0 401 SkPoint fCellSize;
michael@0 402 SkIPoint fVisibleCount;
michael@0 403
michael@0 404 int logicalToVisualIndex(int index) const { return index; }
michael@0 405 void invalSelection();
michael@0 406 bool getCellRect(int index, SkRect*) const;
michael@0 407 void ensureSelectionIsVisible();
michael@0 408
michael@0 409 typedef SkView INHERITED;
michael@0 410 };
michael@0 411
michael@0 412 #endif

mercurial