Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / view / src / nsView.h
bloba99aae5656ef12b152b94ea62775964b10f54b4b
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #ifndef nsView_h___
39 #define nsView_h___
41 #include "nsIView.h"
42 #include "nsIWidget.h"
43 #include "nsRegion.h"
44 #include "nsRect.h"
45 #include "nsCRT.h"
46 #include "nsIFactory.h"
47 #include "nsEvent.h"
48 #include <stdio.h>
50 //mmptemp
52 class nsIViewManager;
53 class nsViewManager;
55 class nsView : public nsIView
57 public:
58 nsView(nsViewManager* aViewManager = nsnull,
59 nsViewVisibility aVisibility = nsViewVisibility_kShow);
61 NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
63 NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
65 /**
66 * Called to indicate that the position of the view has been changed.
67 * The specified coordinates are in the parent view's coordinate space.
68 * @param x new x position
69 * @param y new y position
71 virtual void SetPosition(nscoord aX, nscoord aY);
72 /**
73 * Called to indicate that the dimensions of the view have been changed.
74 * The x and y coordinates may be < 0, indicating that the view extends above
75 * or to the left of its origin position.
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; }
82 /**
83 * Called to indicate that the visibility of a view has been
84 * changed.
85 * @param visibility new visibility state
87 NS_IMETHOD SetVisibility(nsViewVisibility visibility);
89 /**
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();
119 public:
120 // NOT in nsIView, so only available in view module
121 // These are also present in nsIView, but these versions return nsView and nsViewManager
122 // instead of nsIView and nsIViewManager.
123 nsView* GetFirstChild() const { return mFirstChild; }
124 nsView* GetNextSibling() const { return mNextSibling; }
125 nsView* GetParent() const { return mParent; }
126 nsViewManager* GetViewManager() const { return mViewManager; }
127 // These are superceded by a better interface in nsIView
128 PRInt32 GetZIndex() const { return mZIndex; }
129 PRBool GetZIndexIsAuto() const { return (mVFlags & NS_VIEW_FLAG_AUTO_ZINDEX) != 0; }
130 // This is a better interface than GetDimensions(nsRect&) above
131 nsRect GetDimensions() const { nsRect r = mDimBounds; r.MoveBy(-mPosX, -mPosY); return r; }
132 // These are defined exactly the same in nsIView, but for now they have to be redeclared
133 // here because of stupid C++ method hiding rules
135 PRBool HasNonEmptyDirtyRegion() {
136 return mDirtyRegion && !mDirtyRegion->IsEmpty();
138 nsRegion* GetDirtyRegion() {
139 if (!mDirtyRegion) {
140 mDirtyRegion = new nsRegion();
141 NS_ASSERTION(mDirtyRegion, "Out of memory!");
143 return mDirtyRegion;
146 void InsertChild(nsView *aChild, nsView *aSibling);
147 void RemoveChild(nsView *aChild);
149 void SetParent(nsView *aParent) { mParent = aParent; }
150 void SetNextSibling(nsView *aSibling) { mNextSibling = aSibling; }
152 PRUint32 GetViewFlags() const { return mVFlags; }
153 void SetViewFlags(PRUint32 aFlags) { mVFlags = aFlags; }
155 void SetTopMost(PRBool aTopMost) { aTopMost ? mVFlags |= NS_VIEW_FLAG_TOPMOST : mVFlags &= ~NS_VIEW_FLAG_TOPMOST; }
156 PRBool IsTopMost() { return((mVFlags & NS_VIEW_FLAG_TOPMOST) != 0); }
158 // Don't use this method when you want to adjust an nsPoint.
159 // Just write "pt += view->GetPosition();"
160 // When everything's converted to nsPoint, this can go away.
161 void ConvertToParentCoords(nscoord* aX, nscoord* aY) const { *aX += mPosX; *aY += mPosY; }
162 // Don't use this method when you want to adjust an nsPoint.
163 // Just write "pt -= view->GetPosition();"
164 // When everything's converted to nsPoint, this can go away.
165 void ConvertFromParentCoords(nscoord* aX, nscoord* aY) const { *aX -= mPosX; *aY -= mPosY; }
166 void ResetWidgetBounds(PRBool aRecurse, PRBool aMoveOnly, PRBool aInvalidateChangedSize);
167 void SetPositionIgnoringChildWidgets(nscoord aX, nscoord aY);
168 nsresult LoadWidget(const nsCID &aClassIID);
170 // Update the cached RootViewManager for all view manager descendents,
171 // If the hierarchy is being removed, aViewManagerParent points to the view
172 // manager for the hierarchy's old parent, and will have its mouse grab
173 // released if it points to any view in this view hierarchy.
174 void InvalidateHierarchy(nsViewManager *aViewManagerParent);
176 virtual ~nsView();
178 // This is an app unit offset to add when converting view coordinates to
179 // widget coordinates. It is the offset in view coordinates from widget
180 // top-left to view top-left.
181 nsPoint ViewToWidgetOffset() const {
182 if (mParent && mParent->GetViewManager() != GetViewManager()) {
183 // The document root view's mViewToWidgetOffset is always (0,0).
184 // If it has a parent view, the parent view must be the inner view
185 // for an nsSubdocumentFrame; its top-left position in appunits
186 // is always positioned at that inner view's top-left, and its
187 // widget top-left is always positioned at that inner view's widget's
188 // top-left, so its ViewToWidgetOffset is actually the same as
189 // its parent's.
190 return mParent->ViewToWidgetOffset();
192 return mViewToWidgetOffset;
195 nsRect CalcWidgetBounds(nsWindowType aType);
197 protected:
198 // Do the actual work of ResetWidgetBounds, unconditionally. Don't
199 // call this method if we have no widget.
200 void DoResetWidgetBounds(PRBool aMoveOnly, PRBool aInvalidateChangedSize);
202 nsRegion* mDirtyRegion;
203 nsPoint mViewToWidgetOffset;
206 #endif