view/public/nsView.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsView_h__
michael@0 7 #define nsView_h__
michael@0 8
michael@0 9 #include "nsCoord.h"
michael@0 10 #include "nsRect.h"
michael@0 11 #include "nsPoint.h"
michael@0 12 #include "nsRegion.h"
michael@0 13 #include "nsCRT.h"
michael@0 14 #include "nsWidgetInitData.h" // for nsWindowType
michael@0 15 #include "nsIWidgetListener.h"
michael@0 16 #include "mozilla/EventForwards.h"
michael@0 17
michael@0 18 class nsViewManager;
michael@0 19 class nsIWidget;
michael@0 20 class nsIFrame;
michael@0 21
michael@0 22 // Enumerated type to indicate the visibility of a layer.
michael@0 23 // hide - the layer is not shown.
michael@0 24 // show - the layer is shown irrespective of the visibility of
michael@0 25 // the layer's parent.
michael@0 26 enum nsViewVisibility {
michael@0 27 nsViewVisibility_kHide = 0,
michael@0 28 nsViewVisibility_kShow = 1
michael@0 29 };
michael@0 30
michael@0 31 // Public view flags
michael@0 32
michael@0 33 // Indicates that the view is using auto z-indexing
michael@0 34 #define NS_VIEW_FLAG_AUTO_ZINDEX 0x0004
michael@0 35
michael@0 36 // Indicates that the view is a floating view.
michael@0 37 #define NS_VIEW_FLAG_FLOATING 0x0008
michael@0 38
michael@0 39 //----------------------------------------------------------------------
michael@0 40
michael@0 41 /**
michael@0 42 * View interface
michael@0 43 *
michael@0 44 * Views are NOT reference counted. Use the Destroy() member function to
michael@0 45 * destroy a view.
michael@0 46 *
michael@0 47 * The lifetime of the view hierarchy is bounded by the lifetime of the
michael@0 48 * view manager that owns the views.
michael@0 49 *
michael@0 50 * Most of the methods here are read-only. To set the corresponding properties
michael@0 51 * of a view, go through nsViewManager.
michael@0 52 */
michael@0 53
michael@0 54 class nsView MOZ_FINAL : public nsIWidgetListener
michael@0 55 {
michael@0 56 public:
michael@0 57 friend class nsViewManager;
michael@0 58
michael@0 59 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
michael@0 60
michael@0 61 /**
michael@0 62 * Get the view manager which "owns" the view.
michael@0 63 * This method might require some expensive traversal work in the future. If you can get the
michael@0 64 * view manager from somewhere else, do that instead.
michael@0 65 * @result the view manager
michael@0 66 */
michael@0 67 nsViewManager* GetViewManager() const { return mViewManager; }
michael@0 68
michael@0 69 /**
michael@0 70 * Find the view for the given widget, if there is one.
michael@0 71 * @return the view the widget belongs to, or null if the widget doesn't
michael@0 72 * belong to any view.
michael@0 73 */
michael@0 74 static nsView* GetViewFor(nsIWidget* aWidget);
michael@0 75
michael@0 76 /**
michael@0 77 * Destroy the view.
michael@0 78 *
michael@0 79 * The view destroys its child views, and destroys and releases its
michael@0 80 * widget (if it has one).
michael@0 81 *
michael@0 82 * Also informs the view manager that the view is destroyed by calling
michael@0 83 * SetRootView(NULL) if the view is the root view and calling RemoveChild()
michael@0 84 * otherwise.
michael@0 85 */
michael@0 86 void Destroy();
michael@0 87
michael@0 88 /**
michael@0 89 * Called to get the position of a view.
michael@0 90 * The specified coordinates are relative to the parent view's origin, but
michael@0 91 * are in appunits of this.
michael@0 92 * This is the (0, 0) origin of the coordinate space established by this view.
michael@0 93 * @param x out parameter for x position
michael@0 94 * @param y out parameter for y position
michael@0 95 */
michael@0 96 nsPoint GetPosition() const {
michael@0 97 NS_ASSERTION(!IsRoot() || (mPosX == 0 && mPosY == 0),
michael@0 98 "root views should always have explicit position of (0,0)");
michael@0 99 return nsPoint(mPosX, mPosY);
michael@0 100 }
michael@0 101
michael@0 102 /**
michael@0 103 * Called to get the dimensions and position of the view's bounds.
michael@0 104 * The view's bounds (x,y) are relative to the origin of the parent view, but
michael@0 105 * are in appunits of this.
michael@0 106 * The view's bounds (x,y) might not be the same as the view's position,
michael@0 107 * if the view has content above or to the left of its origin.
michael@0 108 * @param aBounds out parameter for bounds
michael@0 109 */
michael@0 110 nsRect GetBounds() const { return mDimBounds; }
michael@0 111
michael@0 112 /**
michael@0 113 * The bounds of this view relative to this view. So this is the same as
michael@0 114 * GetBounds except this is relative to this view instead of the parent view.
michael@0 115 */
michael@0 116 nsRect GetDimensions() const {
michael@0 117 nsRect r = mDimBounds; r.MoveBy(-mPosX, -mPosY); return r;
michael@0 118 }
michael@0 119
michael@0 120 /**
michael@0 121 * Get the offset between the coordinate systems of |this| and aOther.
michael@0 122 * Adding the return value to a point in the coordinate system of |this|
michael@0 123 * will transform the point to the coordinate system of aOther.
michael@0 124 *
michael@0 125 * The offset is expressed in appunits of |this|. So if you are getting the
michael@0 126 * offset between views in different documents that might have different
michael@0 127 * appunits per devpixel ratios you need to be careful how you use the
michael@0 128 * result.
michael@0 129 *
michael@0 130 * If aOther is null, this will return the offset of |this| from the
michael@0 131 * root of the viewmanager tree.
michael@0 132 *
michael@0 133 * This function is fastest when aOther is an ancestor of |this|.
michael@0 134 *
michael@0 135 * NOTE: this actually returns the offset from aOther to |this|, but
michael@0 136 * that offset is added to transform _coordinates_ from |this| to aOther.
michael@0 137 */
michael@0 138 nsPoint GetOffsetTo(const nsView* aOther) const;
michael@0 139
michael@0 140 /**
michael@0 141 * Get the offset between the origin of |this| and the origin of aWidget.
michael@0 142 * Adding the return value to a point in the coordinate system of |this|
michael@0 143 * will transform the point to the coordinate system of aWidget.
michael@0 144 *
michael@0 145 * The offset is expressed in appunits of |this|.
michael@0 146 */
michael@0 147 nsPoint GetOffsetToWidget(nsIWidget* aWidget) const;
michael@0 148
michael@0 149 /**
michael@0 150 * Takes a point aPt that is in the coordinate system of |this|'s parent view
michael@0 151 * and converts it to be in the coordinate system of |this| taking into
michael@0 152 * account the offset and any app unit per dev pixel ratio differences.
michael@0 153 */
michael@0 154 nsPoint ConvertFromParentCoords(nsPoint aPt) const;
michael@0 155
michael@0 156 /**
michael@0 157 * Called to query the visibility state of a view.
michael@0 158 * @result current visibility state
michael@0 159 */
michael@0 160 nsViewVisibility GetVisibility() const { return mVis; }
michael@0 161
michael@0 162 /**
michael@0 163 * Get whether the view "floats" above all other views,
michael@0 164 * which tells the compositor not to consider higher views in
michael@0 165 * the view hierarchy that would geometrically intersect with
michael@0 166 * this view. This is a hack, but it fixes some problems with
michael@0 167 * views that need to be drawn in front of all other views.
michael@0 168 * @result true if the view floats, false otherwise.
michael@0 169 */
michael@0 170 bool GetFloating() const { return (mVFlags & NS_VIEW_FLAG_FLOATING) != 0; }
michael@0 171
michael@0 172 /**
michael@0 173 * Called to query the parent of the view.
michael@0 174 * @result view's parent
michael@0 175 */
michael@0 176 nsView* GetParent() const { return mParent; }
michael@0 177
michael@0 178 /**
michael@0 179 * The view's first child is the child which is earliest in document order.
michael@0 180 * @result first child
michael@0 181 */
michael@0 182 nsView* GetFirstChild() const { return mFirstChild; }
michael@0 183
michael@0 184 /**
michael@0 185 * Called to query the next sibling of the view.
michael@0 186 * @result view's next sibling
michael@0 187 */
michael@0 188 nsView* GetNextSibling() const { return mNextSibling; }
michael@0 189
michael@0 190 /**
michael@0 191 * Set the view's frame.
michael@0 192 */
michael@0 193 void SetFrame(nsIFrame* aRootFrame) { mFrame = aRootFrame; }
michael@0 194
michael@0 195 /**
michael@0 196 * Retrieve the view's frame.
michael@0 197 */
michael@0 198 nsIFrame* GetFrame() const { return mFrame; }
michael@0 199
michael@0 200 /**
michael@0 201 * Get the nearest widget in this view or a parent of this view and
michael@0 202 * the offset from the widget's origin to this view's origin
michael@0 203 * @param aOffset - if non-null the offset from this view's origin to the
michael@0 204 * widget's origin (usually positive) expressed in appunits of this will be
michael@0 205 * returned in aOffset.
michael@0 206 * @return the widget closest to this view; can be null because some view trees
michael@0 207 * don't have widgets at all (e.g., printing), but if any view in the view tree
michael@0 208 * has a widget, then it's safe to assume this will not return null
michael@0 209 */
michael@0 210 nsIWidget* GetNearestWidget(nsPoint* aOffset) const;
michael@0 211
michael@0 212 /**
michael@0 213 * Create a widget to associate with this view. This variant of
michael@0 214 * CreateWidget*() will look around in the view hierarchy for an
michael@0 215 * appropriate parent widget for the view.
michael@0 216 *
michael@0 217 * @param aWidgetInitData data used to initialize this view's widget before
michael@0 218 * its create is called.
michael@0 219 * @return error status
michael@0 220 */
michael@0 221 nsresult CreateWidget(nsWidgetInitData *aWidgetInitData = nullptr,
michael@0 222 bool aEnableDragDrop = true,
michael@0 223 bool aResetVisibility = true);
michael@0 224
michael@0 225 /**
michael@0 226 * Create a widget for this view with an explicit parent widget.
michael@0 227 * |aParentWidget| must be nonnull. The other params are the same
michael@0 228 * as for |CreateWidget()|.
michael@0 229 */
michael@0 230 nsresult CreateWidgetForParent(nsIWidget* aParentWidget,
michael@0 231 nsWidgetInitData *aWidgetInitData = nullptr,
michael@0 232 bool aEnableDragDrop = true,
michael@0 233 bool aResetVisibility = true);
michael@0 234
michael@0 235 /**
michael@0 236 * Create a popup widget for this view. Pass |aParentWidget| to
michael@0 237 * explicitly set the popup's parent. If it's not passed, the view
michael@0 238 * hierarchy will be searched for an appropriate parent widget. The
michael@0 239 * other params are the same as for |CreateWidget()|, except that
michael@0 240 * |aWidgetInitData| must be nonnull.
michael@0 241 */
michael@0 242 nsresult CreateWidgetForPopup(nsWidgetInitData *aWidgetInitData,
michael@0 243 nsIWidget* aParentWidget = nullptr,
michael@0 244 bool aEnableDragDrop = true,
michael@0 245 bool aResetVisibility = true);
michael@0 246
michael@0 247 /**
michael@0 248 * Destroys the associated widget for this view. If this method is
michael@0 249 * not called explicitly, the widget when be destroyed when its
michael@0 250 * view gets destroyed.
michael@0 251 */
michael@0 252 void DestroyWidget();
michael@0 253
michael@0 254 /**
michael@0 255 * Attach/detach a top level widget from this view. When attached, the view
michael@0 256 * updates the widget's device context and allows the view to begin receiving
michael@0 257 * gecko events. The underlying base window associated with the widget will
michael@0 258 * continues to receive events it expects.
michael@0 259 *
michael@0 260 * An attached widget will not be destroyed when the view is destroyed,
michael@0 261 * allowing the recycling of a single top level widget over multiple views.
michael@0 262 *
michael@0 263 * @param aWidget The widget to attach to / detach from.
michael@0 264 */
michael@0 265 nsresult AttachToTopLevelWidget(nsIWidget* aWidget);
michael@0 266 nsresult DetachFromTopLevelWidget();
michael@0 267
michael@0 268 /**
michael@0 269 * Returns a flag indicating whether the view owns it's widget
michael@0 270 * or is attached to an existing top level widget.
michael@0 271 */
michael@0 272 bool IsAttachedToTopLevel() const { return mWidgetIsTopLevel; }
michael@0 273
michael@0 274 /**
michael@0 275 * In 4.0, the "cutout" nature of a view is queryable.
michael@0 276 * If we believe that all cutout view have a native widget, this
michael@0 277 * could be a replacement.
michael@0 278 * @param aWidget out parameter for widget that this view contains,
michael@0 279 * or nullptr if there is none.
michael@0 280 */
michael@0 281 nsIWidget* GetWidget() const { return mWindow; }
michael@0 282
michael@0 283 /**
michael@0 284 * Returns true if the view has a widget associated with it.
michael@0 285 */
michael@0 286 bool HasWidget() const { return mWindow != nullptr; }
michael@0 287
michael@0 288 void SetForcedRepaint(bool aForceRepaint) {
michael@0 289 mForcedRepaint = aForceRepaint;
michael@0 290 }
michael@0 291
michael@0 292 /**
michael@0 293 * Make aWidget direct its events to this view.
michael@0 294 * The caller must call DetachWidgetEventHandler before this view
michael@0 295 * is destroyed.
michael@0 296 */
michael@0 297 void AttachWidgetEventHandler(nsIWidget* aWidget);
michael@0 298 /**
michael@0 299 * Stop aWidget directing its events to this view.
michael@0 300 */
michael@0 301 void DetachWidgetEventHandler(nsIWidget* aWidget);
michael@0 302
michael@0 303 #ifdef DEBUG
michael@0 304 /**
michael@0 305 * Output debug info to FILE
michael@0 306 * @param out output file handle
michael@0 307 * @param aIndent indentation depth
michael@0 308 * NOTE: virtual so that debugging tools not linked into gklayout can access it
michael@0 309 */
michael@0 310 virtual void List(FILE* out, int32_t aIndent = 0) const;
michael@0 311 #endif // DEBUG
michael@0 312
michael@0 313 /**
michael@0 314 * @result true iff this is the root view for its view manager
michael@0 315 */
michael@0 316 bool IsRoot() const;
michael@0 317
michael@0 318 nsIntRect CalcWidgetBounds(nsWindowType aType);
michael@0 319
michael@0 320 // This is an app unit offset to add when converting view coordinates to
michael@0 321 // widget coordinates. It is the offset in view coordinates from widget
michael@0 322 // origin (unlike views, widgets can't extend above or to the left of their
michael@0 323 // origin) to view origin expressed in appunits of this.
michael@0 324 nsPoint ViewToWidgetOffset() const { return mViewToWidgetOffset; }
michael@0 325
michael@0 326 /**
michael@0 327 * Called to indicate that the position of the view has been changed.
michael@0 328 * The specified coordinates are in the parent view's coordinate space.
michael@0 329 * @param x new x position
michael@0 330 * @param y new y position
michael@0 331 */
michael@0 332 void SetPosition(nscoord aX, nscoord aY);
michael@0 333
michael@0 334 /**
michael@0 335 * Called to indicate that the z-index of a view has been changed.
michael@0 336 * The z-index is relative to all siblings of the view.
michael@0 337 * @param aAuto Indicate that the z-index of a view is "auto". An "auto" z-index
michael@0 338 * means that the view does not define a new stacking context,
michael@0 339 * which means that the z-indicies of the view's children are
michael@0 340 * relative to the view's siblings.
michael@0 341 * @param zindex new z depth
michael@0 342 */
michael@0 343 void SetZIndex(bool aAuto, int32_t aZIndex);
michael@0 344 bool GetZIndexIsAuto() const { return (mVFlags & NS_VIEW_FLAG_AUTO_ZINDEX) != 0; }
michael@0 345 int32_t GetZIndex() const { return mZIndex; }
michael@0 346
michael@0 347 void SetParent(nsView *aParent) { mParent = aParent; }
michael@0 348 void SetNextSibling(nsView *aSibling)
michael@0 349 {
michael@0 350 NS_ASSERTION(aSibling != this, "Can't be our own sibling!");
michael@0 351 mNextSibling = aSibling;
michael@0 352 }
michael@0 353
michael@0 354 nsRegion* GetDirtyRegion() {
michael@0 355 if (!mDirtyRegion) {
michael@0 356 NS_ASSERTION(!mParent || GetFloating(),
michael@0 357 "Only display roots should have dirty regions");
michael@0 358 mDirtyRegion = new nsRegion();
michael@0 359 NS_ASSERTION(mDirtyRegion, "Out of memory!");
michael@0 360 }
michael@0 361 return mDirtyRegion;
michael@0 362 }
michael@0 363
michael@0 364 // nsIWidgetListener
michael@0 365 virtual nsIPresShell* GetPresShell() MOZ_OVERRIDE;
michael@0 366 virtual nsView* GetView() MOZ_OVERRIDE { return this; }
michael@0 367 virtual bool WindowMoved(nsIWidget* aWidget, int32_t x, int32_t y) MOZ_OVERRIDE;
michael@0 368 virtual bool WindowResized(nsIWidget* aWidget, int32_t aWidth, int32_t aHeight) MOZ_OVERRIDE;
michael@0 369 virtual bool RequestWindowClose(nsIWidget* aWidget) MOZ_OVERRIDE;
michael@0 370 virtual void WillPaintWindow(nsIWidget* aWidget) MOZ_OVERRIDE;
michael@0 371 virtual bool PaintWindow(nsIWidget* aWidget, nsIntRegion aRegion) MOZ_OVERRIDE;
michael@0 372 virtual void DidPaintWindow() MOZ_OVERRIDE;
michael@0 373 virtual void DidCompositeWindow() MOZ_OVERRIDE;
michael@0 374 virtual void RequestRepaint() MOZ_OVERRIDE;
michael@0 375 virtual nsEventStatus HandleEvent(mozilla::WidgetGUIEvent* aEvent,
michael@0 376 bool aUseAttachedEvents) MOZ_OVERRIDE;
michael@0 377
michael@0 378 virtual ~nsView();
michael@0 379
michael@0 380 nsPoint GetOffsetTo(const nsView* aOther, const int32_t aAPD) const;
michael@0 381 nsIWidget* GetNearestWidget(nsPoint* aOffset, const int32_t aAPD) const;
michael@0 382
michael@0 383 private:
michael@0 384 nsView(nsViewManager* aViewManager = nullptr,
michael@0 385 nsViewVisibility aVisibility = nsViewVisibility_kShow);
michael@0 386
michael@0 387 bool ForcedRepaint() { return mForcedRepaint; }
michael@0 388
michael@0 389 // Do the actual work of ResetWidgetBounds, unconditionally. Don't
michael@0 390 // call this method if we have no widget.
michael@0 391 void DoResetWidgetBounds(bool aMoveOnly, bool aInvalidateChangedSize);
michael@0 392 void InitializeWindow(bool aEnableDragDrop, bool aResetVisibility);
michael@0 393
michael@0 394 bool IsEffectivelyVisible();
michael@0 395
michael@0 396 /**
michael@0 397 * Called to indicate that the dimensions of the view have been changed.
michael@0 398 * The x and y coordinates may be < 0, indicating that the view extends above
michael@0 399 * or to the left of its origin position. The term 'dimensions' indicates it
michael@0 400 * is relative to this view.
michael@0 401 */
michael@0 402 void SetDimensions(const nsRect &aRect, bool aPaint = true,
michael@0 403 bool aResizeWidget = true);
michael@0 404
michael@0 405 /**
michael@0 406 * Called to indicate that the visibility of a view has been
michael@0 407 * changed.
michael@0 408 * @param visibility new visibility state
michael@0 409 */
michael@0 410 void SetVisibility(nsViewVisibility visibility);
michael@0 411
michael@0 412 /**
michael@0 413 * Set/Get whether the view "floats" above all other views,
michael@0 414 * which tells the compositor not to consider higher views in
michael@0 415 * the view hierarchy that would geometrically intersect with
michael@0 416 * this view. This is a hack, but it fixes some problems with
michael@0 417 * views that need to be drawn in front of all other views.
michael@0 418 * @result true if the view floats, false otherwise.
michael@0 419 */
michael@0 420 void SetFloating(bool aFloatingView);
michael@0 421
michael@0 422 // Helper function to get mouse grabbing off this view (by moving it to the
michael@0 423 // parent, if we can)
michael@0 424 void DropMouseGrabbing();
michael@0 425
michael@0 426 // Same as GetBounds but converts to parent appunits if they are different.
michael@0 427 nsRect GetBoundsInParentUnits() const;
michael@0 428
michael@0 429 bool HasNonEmptyDirtyRegion() {
michael@0 430 return mDirtyRegion && !mDirtyRegion->IsEmpty();
michael@0 431 }
michael@0 432
michael@0 433 void InsertChild(nsView *aChild, nsView *aSibling);
michael@0 434 void RemoveChild(nsView *aChild);
michael@0 435
michael@0 436 void ResetWidgetBounds(bool aRecurse, bool aForceSync);
michael@0 437 void AssertNoWindow();
michael@0 438
michael@0 439 void NotifyEffectiveVisibilityChanged(bool aEffectivelyVisible);
michael@0 440
michael@0 441 // Update the cached RootViewManager for all view manager descendents,
michael@0 442 // If the hierarchy is being removed, aViewManagerParent points to the view
michael@0 443 // manager for the hierarchy's old parent, and will have its mouse grab
michael@0 444 // released if it points to any view in this view hierarchy.
michael@0 445 void InvalidateHierarchy(nsViewManager *aViewManagerParent);
michael@0 446
michael@0 447 nsViewManager *mViewManager;
michael@0 448 nsView *mParent;
michael@0 449 nsIWidget *mWindow;
michael@0 450 nsView *mNextSibling;
michael@0 451 nsView *mFirstChild;
michael@0 452 nsIFrame *mFrame;
michael@0 453 nsRegion *mDirtyRegion;
michael@0 454 int32_t mZIndex;
michael@0 455 nsViewVisibility mVis;
michael@0 456 // position relative our parent view origin but in our appunits
michael@0 457 nscoord mPosX, mPosY;
michael@0 458 // relative to parent, but in our appunits
michael@0 459 nsRect mDimBounds;
michael@0 460 // in our appunits
michael@0 461 nsPoint mViewToWidgetOffset;
michael@0 462 uint32_t mVFlags;
michael@0 463 bool mWidgetIsTopLevel;
michael@0 464 bool mForcedRepaint;
michael@0 465 };
michael@0 466
michael@0 467 #endif

mercurial