gfx/skia/trunk/include/views/SkView.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 /*
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 SkView_DEFINED
michael@0 11 #define SkView_DEFINED
michael@0 12
michael@0 13 #include "SkEventSink.h"
michael@0 14 #include "SkRect.h"
michael@0 15 #include "SkDOM.h"
michael@0 16 #include "SkTDict.h"
michael@0 17 #include "SkMatrix.h"
michael@0 18 #include "SkMetaData.h"
michael@0 19
michael@0 20 class SkCanvas;
michael@0 21 class SkLayerView;
michael@0 22
michael@0 23 /** \class SkView
michael@0 24
michael@0 25 SkView is the base class for screen management. All widgets and controls inherit
michael@0 26 from SkView.
michael@0 27 */
michael@0 28 class SkView : public SkEventSink {
michael@0 29 public:
michael@0 30 enum Flag_Shift {
michael@0 31 kVisible_Shift,
michael@0 32 kEnabled_Shift,
michael@0 33 kFocusable_Shift,
michael@0 34 kFlexH_Shift,
michael@0 35 kFlexV_Shift,
michael@0 36 kNoClip_Shift,
michael@0 37
michael@0 38 kFlagShiftCount
michael@0 39 };
michael@0 40 enum Flag_Mask {
michael@0 41 kVisible_Mask = 1 << kVisible_Shift, //!< set if the view is visible
michael@0 42 kEnabled_Mask = 1 << kEnabled_Shift, //!< set if the view is enabled
michael@0 43 kFocusable_Mask = 1 << kFocusable_Shift, //!< set if the view can receive focus
michael@0 44 kFlexH_Mask = 1 << kFlexH_Shift, //!< set if the view's width is stretchable
michael@0 45 kFlexV_Mask = 1 << kFlexV_Shift, //!< set if the view's height is stretchable
michael@0 46 kNoClip_Mask = 1 << kNoClip_Shift, //!< set if the view is not clipped to its bounds
michael@0 47
michael@0 48 kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount)
michael@0 49 };
michael@0 50
michael@0 51 SkView(uint32_t flags = 0);
michael@0 52 virtual ~SkView();
michael@0 53
michael@0 54 /** Return the flags associated with the view
michael@0 55 */
michael@0 56 uint32_t getFlags() const { return fFlags; }
michael@0 57 /** Set the flags associated with the view
michael@0 58 */
michael@0 59 void setFlags(uint32_t flags);
michael@0 60
michael@0 61 /** Helper that returns non-zero if the kVisible_Mask bit is set in the view's flags
michael@0 62 */
michael@0 63 int isVisible() const { return fFlags & kVisible_Mask; }
michael@0 64 int isEnabled() const { return fFlags & kEnabled_Mask; }
michael@0 65 int isFocusable() const { return fFlags & kFocusable_Mask; }
michael@0 66 int isClipToBounds() const { return !(fFlags & kNoClip_Mask); }
michael@0 67 /** Helper to set/clear the view's kVisible_Mask flag */
michael@0 68 void setVisibleP(bool);
michael@0 69 void setEnabledP(bool);
michael@0 70 void setFocusableP(bool);
michael@0 71 void setClipToBounds(bool);
michael@0 72
michael@0 73 /** Return the view's width */
michael@0 74 SkScalar width() const { return fWidth; }
michael@0 75 /** Return the view's height */
michael@0 76 SkScalar height() const { return fHeight; }
michael@0 77 /** Set the view's width and height. These must both be >= 0. This does not affect the view's loc */
michael@0 78 void setSize(SkScalar width, SkScalar height);
michael@0 79 void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); }
michael@0 80 void setWidth(SkScalar width) { this->setSize(width, fHeight); }
michael@0 81 void setHeight(SkScalar height) { this->setSize(fWidth, height); }
michael@0 82 /** Return a rectangle set to [0, 0, width, height] */
michael@0 83 void getLocalBounds(SkRect* bounds) const;
michael@0 84
michael@0 85 /** Loc - the view's offset with respect to its parent in its view hiearchy.
michael@0 86 NOTE: For more complex transforms, use Local Matrix. The tranformations
michael@0 87 are applied in the following order:
michael@0 88 canvas->translate(fLoc.fX, fLoc.fY);
michael@0 89 canvas->concat(fMatrix);
michael@0 90 */
michael@0 91 /** Return the view's left edge */
michael@0 92 SkScalar locX() const { return fLoc.fX; }
michael@0 93 /** Return the view's top edge */
michael@0 94 SkScalar locY() const { return fLoc.fY; }
michael@0 95 /** Set the view's left and top edge. This does not affect the view's size */
michael@0 96 void setLoc(SkScalar x, SkScalar y);
michael@0 97 void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); }
michael@0 98 void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); }
michael@0 99 void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); }
michael@0 100
michael@0 101 /** Local Matrix - matrix used to tranform the view with respect to its
michael@0 102 parent in its view hiearchy. Use setLocalMatrix to apply matrix
michael@0 103 transformations to the current view and in turn affect its children.
michael@0 104 NOTE: For simple offsets, use Loc. The transformations are applied in
michael@0 105 the following order:
michael@0 106 canvas->translate(fLoc.fX, fLoc.fY);
michael@0 107 canvas->concat(fMatrix);
michael@0 108 */
michael@0 109 const SkMatrix& getLocalMatrix() const { return fMatrix; }
michael@0 110 void setLocalMatrix(const SkMatrix& matrix);
michael@0 111
michael@0 112 /** Offset (move) the view by the specified dx and dy. This does not affect the view's size */
michael@0 113 void offset(SkScalar dx, SkScalar dy);
michael@0 114
michael@0 115 /** Call this to have the view draw into the specified canvas. */
michael@0 116 virtual void draw(SkCanvas* canvas);
michael@0 117
michael@0 118 /** Call this to invalidate part of all of a view, requesting that the view's
michael@0 119 draw method be called. The rectangle parameter specifies the part of the view
michael@0 120 that should be redrawn. If it is null, it specifies the entire view bounds.
michael@0 121 */
michael@0 122 void inval(SkRect* rectOrNull);
michael@0 123
michael@0 124 // Focus management
michael@0 125
michael@0 126 SkView* getFocusView() const;
michael@0 127 bool hasFocus() const;
michael@0 128
michael@0 129 enum FocusDirection {
michael@0 130 kNext_FocusDirection,
michael@0 131 kPrev_FocusDirection,
michael@0 132
michael@0 133 kFocusDirectionCount
michael@0 134 };
michael@0 135 bool acceptFocus();
michael@0 136 SkView* moveFocus(FocusDirection);
michael@0 137
michael@0 138 // Click handling
michael@0 139
michael@0 140 class Click {
michael@0 141 public:
michael@0 142 Click(SkView* target);
michael@0 143 virtual ~Click();
michael@0 144
michael@0 145 const char* getType() const { return fType; }
michael@0 146 bool isType(const char type[]) const;
michael@0 147 void setType(const char type[]); // does NOT make a copy of the string
michael@0 148 void copyType(const char type[]); // makes a copy of the string
michael@0 149
michael@0 150 enum State {
michael@0 151 kDown_State,
michael@0 152 kMoved_State,
michael@0 153 kUp_State
michael@0 154 };
michael@0 155 SkPoint fOrig, fPrev, fCurr;
michael@0 156 SkIPoint fIOrig, fIPrev, fICurr;
michael@0 157 State fState;
michael@0 158 void* fOwner;
michael@0 159 unsigned fModifierKeys;
michael@0 160
michael@0 161 SkMetaData fMeta;
michael@0 162 private:
michael@0 163 SkEventSinkID fTargetID;
michael@0 164 char* fType;
michael@0 165 bool fWeOwnTheType;
michael@0 166
michael@0 167 void resetType();
michael@0 168
michael@0 169 friend class SkView;
michael@0 170 };
michael@0 171 Click* findClickHandler(SkScalar x, SkScalar y, unsigned modifierKeys);
michael@0 172
michael@0 173 static void DoClickDown(Click*, int x, int y, unsigned modi);
michael@0 174 static void DoClickMoved(Click*, int x, int y, unsigned modi);
michael@0 175 static void DoClickUp(Click*, int x, int y, unsigned modi);
michael@0 176
michael@0 177 /** Send the event to the view's parent, and its parent etc. until one of them
michael@0 178 returns true from its onEvent call. This view is returned. If no parent handles
michael@0 179 the event, null is returned.
michael@0 180 */
michael@0 181 SkView* sendEventToParents(const SkEvent&);
michael@0 182 /** Send the query to the view's parent, and its parent etc. until one of them
michael@0 183 returns true from its onQuery call. This view is returned. If no parent handles
michael@0 184 the query, null is returned.
michael@0 185 */
michael@0 186 SkView* sendQueryToParents(SkEvent*);
michael@0 187
michael@0 188 // View hierarchy management
michael@0 189
michael@0 190 /** Return the view's parent, or null if it has none. This does not affect the parent's reference count. */
michael@0 191 SkView* getParent() const { return fParent; }
michael@0 192 SkView* attachChildToFront(SkView* child);
michael@0 193 /** Attach the child view to this view, and increment the child's reference count. The child view is added
michael@0 194 such that it will be drawn before all other child views.
michael@0 195 The child view parameter is returned.
michael@0 196 */
michael@0 197 SkView* attachChildToBack(SkView* child);
michael@0 198 /** If the view has a parent, detach the view from its parent and decrement the view's reference count.
michael@0 199 If the parent was the only owner of the view, this will cause the view to be deleted.
michael@0 200 */
michael@0 201 void detachFromParent();
michael@0 202 /** Attach the child view to this view, and increment the child's reference count. The child view is added
michael@0 203 such that it will be drawn after all other child views.
michael@0 204 The child view parameter is returned.
michael@0 205 */
michael@0 206 /** Detach all child views from this view. */
michael@0 207 void detachAllChildren();
michael@0 208
michael@0 209 /** Convert the specified point from global coordinates into view-local coordinates
michael@0 210 * Return true on success; false on failure
michael@0 211 */
michael@0 212 bool globalToLocal(SkPoint* pt) const {
michael@0 213 if (NULL != pt) {
michael@0 214 return this->globalToLocal(pt->fX, pt->fY, pt);
michael@0 215 }
michael@0 216 return true; // nothing to do so return true
michael@0 217 }
michael@0 218 /** Convert the specified x,y from global coordinates into view-local coordinates, returning
michael@0 219 the answer in the local parameter.
michael@0 220 */
michael@0 221 bool globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const;
michael@0 222
michael@0 223 /** \class F2BIter
michael@0 224
michael@0 225 Iterator that will return each of this view's children, in
michael@0 226 front-to-back order (the order used for clicking). The first
michael@0 227 call to next() returns the front-most child view. When
michael@0 228 next() returns null, there are no more child views.
michael@0 229 */
michael@0 230 class F2BIter {
michael@0 231 public:
michael@0 232 F2BIter(const SkView* parent);
michael@0 233 SkView* next();
michael@0 234 private:
michael@0 235 SkView* fFirstChild, *fChild;
michael@0 236 };
michael@0 237
michael@0 238 /** \class B2FIter
michael@0 239
michael@0 240 Iterator that will return each of this view's children, in
michael@0 241 back-to-front order (the order they are drawn). The first
michael@0 242 call to next() returns the back-most child view. When
michael@0 243 next() returns null, there are no more child views.
michael@0 244 */
michael@0 245 class B2FIter {
michael@0 246 public:
michael@0 247 B2FIter(const SkView* parent);
michael@0 248 SkView* next();
michael@0 249 private:
michael@0 250 SkView* fFirstChild, *fChild;
michael@0 251 };
michael@0 252
michael@0 253 /** \class Artist
michael@0 254
michael@0 255 Install a subclass of this in a view (calling setArtist()), and then the
michael@0 256 default implementation of that view's onDraw() will invoke this object
michael@0 257 automatically.
michael@0 258 */
michael@0 259 class Artist : public SkRefCnt {
michael@0 260 public:
michael@0 261 SK_DECLARE_INST_COUNT(Artist)
michael@0 262
michael@0 263 void draw(SkView*, SkCanvas*);
michael@0 264 void inflate(const SkDOM&, const SkDOM::Node*);
michael@0 265 protected:
michael@0 266 virtual void onDraw(SkView*, SkCanvas*) = 0;
michael@0 267 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
michael@0 268 private:
michael@0 269 typedef SkRefCnt INHERITED;
michael@0 270 };
michael@0 271 /** Return the artist attached to this view (or null). The artist's reference
michael@0 272 count is not affected.
michael@0 273 */
michael@0 274 Artist* getArtist() const;
michael@0 275 /** Attach the specified artist (or null) to the view, replacing any existing
michael@0 276 artist. If the new artist is not null, its reference count is incremented.
michael@0 277 The artist parameter is returned.
michael@0 278 */
michael@0 279 Artist* setArtist(Artist* artist);
michael@0 280
michael@0 281 /** \class Layout
michael@0 282
michael@0 283 Install a subclass of this in a view (calling setLayout()), and then the
michael@0 284 default implementation of that view's onLayoutChildren() will invoke
michael@0 285 this object automatically.
michael@0 286 */
michael@0 287 class Layout : public SkRefCnt {
michael@0 288 public:
michael@0 289 SK_DECLARE_INST_COUNT(Layout)
michael@0 290
michael@0 291 void layoutChildren(SkView* parent);
michael@0 292 void inflate(const SkDOM&, const SkDOM::Node*);
michael@0 293 protected:
michael@0 294 virtual void onLayoutChildren(SkView* parent) = 0;
michael@0 295 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
michael@0 296 private:
michael@0 297 typedef SkRefCnt INHERITED;
michael@0 298 };
michael@0 299
michael@0 300 /** Return the layout attached to this view (or null). The layout's reference
michael@0 301 count is not affected.
michael@0 302 */
michael@0 303 Layout* getLayout() const;
michael@0 304 /** Attach the specified layout (or null) to the view, replacing any existing
michael@0 305 layout. If the new layout is not null, its reference count is incremented.
michael@0 306 The layout parameter is returned.
michael@0 307 */
michael@0 308 Layout* setLayout(Layout*, bool invokeLayoutNow = true);
michael@0 309 /** If a layout is attached to this view, call its layoutChildren() method
michael@0 310 */
michael@0 311 void invokeLayout();
michael@0 312
michael@0 313 /** Call this to initialize this view based on the specified XML node
michael@0 314 */
michael@0 315 void inflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 316 /** After a view hierarchy is inflated, this may be called with a dictionary
michael@0 317 containing pairs of <name, view*>, where the name string was the view's
michael@0 318 "id" attribute when it was inflated.
michael@0 319
michael@0 320 This will call the virtual onPostInflate for this view, and the recursively
michael@0 321 call postInflate on all of the view's children.
michael@0 322 */
michael@0 323 void postInflate(const SkTDict<SkView*>& ids);
michael@0 324
michael@0 325 SkDEBUGCODE(void dump(bool recurse) const;)
michael@0 326
michael@0 327 protected:
michael@0 328 /** Override this to draw inside the view. Be sure to call the inherited version too */
michael@0 329 virtual void onDraw(SkCanvas*);
michael@0 330 /** Override this to be notified when the view's size changes. Be sure to call the inherited version too */
michael@0 331 virtual void onSizeChange();
michael@0 332 /** Override this if you want to handle an inval request from this view or one of its children.
michael@0 333 Tyically this is only overridden by the by the "window". If your subclass does handle the
michael@0 334 request, return true so the request will not continue to propogate to the parent.
michael@0 335 */
michael@0 336 virtual bool handleInval(const SkRect*);
michael@0 337 //! called once before all of the children are drawn (or clipped/translated)
michael@0 338 virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; }
michael@0 339 //! called once after all of the children are drawn (or clipped/translated)
michael@0 340 virtual void afterChildren(SkCanvas* orig) {}
michael@0 341
michael@0 342 //! called right before this child's onDraw is called
michael@0 343 virtual void beforeChild(SkView* child, SkCanvas* canvas) {}
michael@0 344 //! called right after this child's onDraw is called
michael@0 345 virtual void afterChild(SkView* child, SkCanvas* canvas) {}
michael@0 346
michael@0 347 /** Override this if you might handle the click
michael@0 348 */
michael@0 349 virtual Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi);
michael@0 350 /** Override this to decide if your children are targets for a click.
michael@0 351 The default returns true, in which case your children views will be
michael@0 352 candidates for onFindClickHandler. Returning false wil skip the children
michael@0 353 and just call your onFindClickHandler.
michael@0 354 */
michael@0 355 virtual bool onSendClickToChildren(SkScalar x, SkScalar y, unsigned modi);
michael@0 356 /** Override this to track clicks, returning true as long as you want to track
michael@0 357 the pen/mouse.
michael@0 358 */
michael@0 359 virtual bool onClick(Click*);
michael@0 360 /** Override this to initialize your subclass from the XML node. Be sure to call the inherited version too */
michael@0 361 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
michael@0 362 /** Override this if you want to perform post initialization work based on the ID dictionary built
michael@0 363 during XML parsing. Be sure to call the inherited version too.
michael@0 364 */
michael@0 365 virtual void onPostInflate(const SkTDict<SkView*>&);
michael@0 366
michael@0 367 public:
michael@0 368 #ifdef SK_DEBUG
michael@0 369 void validate() const;
michael@0 370 #else
michael@0 371 void validate() const {}
michael@0 372 #endif
michael@0 373 // default action is to inval the view
michael@0 374 virtual void onFocusChange(bool gainFocusP);
michael@0 375
michael@0 376 protected:
michael@0 377
michael@0 378 // override these if you're acting as a layer/host
michael@0 379 virtual bool onGetFocusView(SkView**) const { return false; }
michael@0 380 virtual bool onSetFocusView(SkView*) { return false; }
michael@0 381
michael@0 382 private:
michael@0 383 SkScalar fWidth, fHeight;
michael@0 384 SkMatrix fMatrix;
michael@0 385 SkPoint fLoc;
michael@0 386 SkView* fParent;
michael@0 387 SkView* fFirstChild;
michael@0 388 SkView* fNextSibling;
michael@0 389 SkView* fPrevSibling;
michael@0 390 uint8_t fFlags;
michael@0 391 uint8_t fContainsFocus;
michael@0 392
michael@0 393 friend class B2FIter;
michael@0 394 friend class F2BIter;
michael@0 395
michael@0 396 friend class SkLayerView;
michael@0 397
michael@0 398 bool setFocusView(SkView* fvOrNull);
michael@0 399 SkView* acceptFocus(FocusDirection);
michael@0 400 void detachFromParent_NoLayout();
michael@0 401 /** Compute the matrix to transform view-local coordinates into global ones */
michael@0 402 void localToGlobal(SkMatrix* matrix) const;
michael@0 403 };
michael@0 404
michael@0 405 #endif

mercurial