1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
45 #include "nsIFactory.h"
54 class nsView
: public nsIView
57 nsView(nsViewManager
* aViewManager
= nsnull
,
58 nsViewVisibility aVisibility
= nsViewVisibility_kShow
);
60 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
62 NS_IMETHOD
QueryInterface(const nsIID
& aIID
, void** aInstancePtr
);
65 * Called to indicate that the position of the view has been changed.
66 * The specified coordinates are in the parent view's coordinate space.
67 * @param x new x position
68 * @param y new y position
70 virtual void SetPosition(nscoord aX
, nscoord aY
);
72 * Called to indicate that the dimensions of the view have been changed.
73 * The x and y coordinates may be < 0, indicating that the view extends above
74 * or to the left of its origin position. The term 'dimensions' indicates it
75 * is relative to this view.
77 virtual void SetDimensions(const nsRect
&aRect
, PRBool aPaint
= PR_TRUE
,
78 PRBool aResizeWidget
= PR_TRUE
);
79 void GetDimensions(nsRect
&aRect
) const { aRect
= mDimBounds
; aRect
.x
-= mPosX
; aRect
.y
-= mPosY
; }
80 void GetDimensions(nsSize
&aSize
) const { aSize
.width
= mDimBounds
.width
; aSize
.height
= mDimBounds
.height
; }
83 * Called to indicate that the visibility of a view has been
85 * @param visibility new visibility state
87 NS_IMETHOD
SetVisibility(nsViewVisibility visibility
);
90 * Called to indicate that the z-index of a view has been changed.
91 * The z-index is relative to all siblings of the view.
92 * @param aAuto Indicate that the z-index of a view is "auto". An "auto" z-index
93 * means that the view does not define a new stacking context,
94 * which means that the z-indicies of the view's children are
95 * relative to the view's siblings.
96 * @param zindex new z depth
98 void SetZIndex(PRBool aAuto
, PRInt32 aZIndex
, PRBool aTopMost
);
101 * Set/Get whether the view "floats" above all other views,
102 * which tells the compositor not to consider higher views in
103 * the view hierarchy that would geometrically intersect with
104 * this view. This is a hack, but it fixes some problems with
105 * views that need to be drawn in front of all other views.
106 * @result PR_TRUE if the view floats, PR_FALSE otherwise.
108 NS_IMETHOD
SetFloating(PRBool aFloatingView
);
110 // Helper function to get the view that's associated with a widget
111 static nsView
* GetViewFor(nsIWidget
* aWidget
) {
112 return static_cast<nsView
*>(nsIView::GetViewFor(aWidget
));
115 // Helper function to get mouse grabbing off this view (by moving it to the
116 // parent, if we can)
117 void DropMouseGrabbing();
120 // See nsIView::CreateWidget.
121 nsresult
CreateWidget(nsWidgetInitData
*aWidgetInitData
,
122 PRBool aEnableDragDrop
,
123 PRBool aResetVisibility
);
125 // See nsIView::CreateWidgetForParent.
126 nsresult
CreateWidgetForParent(nsIWidget
* aParentWidget
,
127 nsWidgetInitData
*aWidgetInitData
,
128 PRBool aEnableDragDrop
,
129 PRBool aResetVisibility
);
131 // See nsIView::CreateWidgetForPopup.
132 nsresult
CreateWidgetForPopup(nsWidgetInitData
*aWidgetInitData
,
133 nsIWidget
* aParentWidget
,
134 PRBool aEnableDragDrop
,
135 PRBool aResetVisibility
);
137 // NOT in nsIView, so only available in view module
138 // These are also present in nsIView, but these versions return nsView and nsViewManager
139 // instead of nsIView and nsIViewManager.
140 nsView
* GetFirstChild() const { return mFirstChild
; }
141 nsView
* GetNextSibling() const { return mNextSibling
; }
142 nsView
* GetParent() const { return mParent
; }
143 nsViewManager
* GetViewManager() const { return mViewManager
; }
144 // These are superseded by a better interface in nsIView
145 PRInt32
GetZIndex() const { return mZIndex
; }
146 PRBool
GetZIndexIsAuto() const { return (mVFlags
& NS_VIEW_FLAG_AUTO_ZINDEX
) != 0; }
147 // This is a better interface than GetDimensions(nsRect&) above
148 nsRect
GetDimensions() const { nsRect r
= mDimBounds
; r
.MoveBy(-mPosX
, -mPosY
); return r
; }
149 // Same as GetBounds but converts to parent appunits if they are different.
150 nsRect
GetBoundsInParentUnits() const;
151 // These are defined exactly the same in nsIView, but for now they have to be redeclared
152 // here because of stupid C++ method hiding rules
154 PRBool
HasNonEmptyDirtyRegion() {
155 return mDirtyRegion
&& !mDirtyRegion
->IsEmpty();
157 nsRegion
* GetDirtyRegion() {
159 NS_ASSERTION(!mParent
|| GetFloating(),
160 "Only display roots should have dirty regions");
161 mDirtyRegion
= new nsRegion();
162 NS_ASSERTION(mDirtyRegion
, "Out of memory!");
167 void InsertChild(nsView
*aChild
, nsView
*aSibling
);
168 void RemoveChild(nsView
*aChild
);
170 void SetParent(nsView
*aParent
) { mParent
= aParent
; }
171 void SetNextSibling(nsView
*aSibling
) { mNextSibling
= aSibling
; }
173 PRUint32
GetViewFlags() const { return mVFlags
; }
174 void SetViewFlags(PRUint32 aFlags
) { mVFlags
= aFlags
; }
176 void SetTopMost(PRBool aTopMost
) { aTopMost
? mVFlags
|= NS_VIEW_FLAG_TOPMOST
: mVFlags
&= ~NS_VIEW_FLAG_TOPMOST
; }
177 PRBool
IsTopMost() { return((mVFlags
& NS_VIEW_FLAG_TOPMOST
) != 0); }
179 nsPoint
ConvertFromParentCoords(nsPoint aPt
) const;
180 void ResetWidgetBounds(PRBool aRecurse
, PRBool aMoveOnly
, PRBool aInvalidateChangedSize
);
181 void SetPositionIgnoringChildWidgets(nscoord aX
, nscoord aY
);
182 void AssertNoWindow();
184 void NotifyEffectiveVisibilityChanged(PRBool aEffectivelyVisible
);
186 // Update the cached RootViewManager for all view manager descendents,
187 // If the hierarchy is being removed, aViewManagerParent points to the view
188 // manager for the hierarchy's old parent, and will have its mouse grab
189 // released if it points to any view in this view hierarchy.
190 void InvalidateHierarchy(nsViewManager
*aViewManagerParent
);
194 nsPoint
GetOffsetTo(const nsView
* aOther
) const;
195 nsIWidget
* GetNearestWidget(nsPoint
* aOffset
) const;
196 nsPoint
GetOffsetTo(const nsView
* aOther
, const PRInt32 aAPD
) const;
197 nsIWidget
* GetNearestWidget(nsPoint
* aOffset
, const PRInt32 aAPD
) const;
200 // Do the actual work of ResetWidgetBounds, unconditionally. Don't
201 // call this method if we have no widget.
202 void DoResetWidgetBounds(PRBool aMoveOnly
, PRBool aInvalidateChangedSize
);
204 nsRegion
* mDirtyRegion
;
207 void InitializeWindow(PRBool aEnableDragDrop
, PRBool aResetVisibility
);