gecko-dev/view/public/nsIView.h

361 lines
13 KiB
C
Raw Normal View History

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
1998-04-13 20:24:54 +00:00
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
1998-04-13 20:24:54 +00:00
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
1998-04-13 20:24:54 +00:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
1998-04-13 20:24:54 +00:00
#ifndef nsIView_h___
#define nsIView_h___
#include "nsISupports.h"
#include "nsCoord.h"
#include "nsRect.h"
#include "nsPoint.h"
#include <stdio.h>
#include "nsIWidget.h"
class nsIViewManager;
class nsViewManager;
class nsView;
1998-04-13 20:24:54 +00:00
struct nsRect;
// Enumerated type to indicate the visibility of a layer.
// hide - the layer is not shown.
// show - the layer is shown irrespective of the visibility of
// the layer's parent.
enum nsViewVisibility {
1998-04-13 20:24:54 +00:00
nsViewVisibility_kHide = 0,
nsViewVisibility_kShow = 1
};
1998-04-13 20:24:54 +00:00
// IID for the nsIView interface
#define NS_IVIEW_IID \
{ 0xf0a21c40, 0xa7e1, 0x11d1, \
{ 0xa8, 0x24, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
//Flag to determine whether the view will check if events can be handled
//by its children or just handle the events itself
#define NS_VIEW_FLAG_DONT_CHECK_CHILDREN 0x0001
// indicates that the view is or contains a placeholder view
#define NS_VIEW_FLAG_CONTAINS_PLACEHOLDER 0x0002
//the view is transparent
#define NS_VIEW_FLAG_TRANSPARENT 0x0004
// The view is always painted onto a background consisting
// of a uniform field of opaque pixels.
#define NS_VIEW_FLAG_UNIFORM_BACKGROUND 0x0008
//indicates that the view should not be bitblt'd when moved
//or scrolled and instead must be repainted
#define NS_VIEW_FLAG_DONT_BITBLT 0x0010
// indicates that the view is using auto z-indexing
#define NS_VIEW_FLAG_AUTO_ZINDEX 0x0020
// indicates that the view is a floating view.
#define NS_VIEW_FLAG_FLOATING 0x0040
// set if our widget resized.
#define NS_VIEW_FLAG_WIDGET_RESIZED 0x0080
// set if our widget moved.
#define NS_VIEW_FLAG_WIDGET_MOVED 0x0100
#define NS_VIEW_FLAG_CLIPCHILDREN 0x0200
// if set it indicates that this view should be
// displayed above z-index:auto views if this view
// is z-index:auto also
#define NS_VIEW_FLAG_TOPMOST 0x0400
struct nsViewZIndex {
PRBool mIsAuto;
PRInt32 mZIndex;
PRBool mIsTopmost;
nsViewZIndex(PRBool aIsAuto, PRInt32 aZIndex, PRBool aIsTopmost)
: mIsAuto(aIsAuto), mZIndex(aZIndex), mIsTopmost(aIsTopmost) {}
};
1998-04-13 20:24:54 +00:00
//----------------------------------------------------------------------
/**
* View interface
*
* Views are NOT reference counted. Use the Destroy() member function to
* destroy a view.
*
* The lifetime of the view hierarchy is bounded by the lifetime of the
* view manager that owns the views.
*
* Most of the methods here are read-only. To set the corresponding properties
* of a view, go through nsIViewManager.
*/
1998-04-13 20:24:54 +00:00
class nsIView : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IVIEW_IID)
1998-04-15 20:25:02 +00:00
/**
* Initialize the view
* @param aManager view manager that "owns" the view. The view does NOT
* hold a reference to the view manager
1998-04-15 20:25:02 +00:00
* @param aBounds initial bounds for view
1998-10-27 03:36:49 +00:00
* @param aParent intended parent for view. this is not actually set in the
* nsIView through this method. it is only used by the initialization
* code to walk up the view tree, if necessary, to find resources.
1998-04-15 20:25:02 +00:00
* @param aVisibilityFlag initial visibility state of view
* @result The result of the initialization, NS_OK if no errors
*/
NS_IMETHOD Init(nsIViewManager* aManager,
const nsRect &aBounds,
1998-10-27 03:36:49 +00:00
const nsIView *aParent,
nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow) = 0;
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Destroy the view.
*
* The view destroys its child views, and destroys and releases its
* widget (if it has one).
*
* Also informs the view manager that the view is destroyed by calling
* SetRootView(NULL) if the view is the root view and calling RemoveChild()
* otherwise.
1998-04-15 20:25:02 +00:00
*/
NS_IMETHOD Destroy() = 0;
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Get the view manager which "owns" the view.
* This method might require some expensive traversal work in the future. If you can get the
* view manager from somewhere else, do that instead.
* @result the view manager
1998-04-15 20:25:02 +00:00
*/
nsIViewManager* GetViewManager() const
{ return NS_REINTERPRET_CAST(nsIViewManager*, mViewManager); }
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Called to get the position of a view.
* The specified coordinates are in the parent view's coordinate space.
* This is the (0, 0) origin of the coordinate space established by this view.
1998-04-15 20:25:02 +00:00
* @param x out parameter for x position
* @param y out parameter for y position
*/
nsPoint GetPosition() const {
// this assertion should go away once we're confident that it's not needed
NS_ASSERTION(!IsRoot() || (mPosX == 0 && mPosY == 0),
"root views should always have explicit position of (0,0)");
return nsPoint(mPosX, mPosY);
}
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Called to get the dimensions and position of the view's bounds.
* The view's bounds (x,y) are in the coordinate space of the parent view.
* The view's bounds (x,y) might not be the same as the view's position,
* if the view has content above or to the left of its origin.
1998-04-15 20:25:02 +00:00
* @param aBounds out parameter for bounds
*/
nsRect GetBounds() const {
// this assertion should go away once we're confident that it's not needed
NS_ASSERTION(!IsRoot() || (mDimBounds.x == 0 && mDimBounds.y == 0),
"root views should always have explicit position of (0,0)");
return mDimBounds;
}
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Called to query the visibility state of a view.
* @result current visibility state
*/
nsViewVisibility GetVisibility() const { return mVis; }
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Called to query the z-index of a view.
* The z-index is relative to all siblings of the view.
* @result mZIndex: explicit z-index value or 0 if none is set
* mIsAuto: PR_TRUE if the view is zindex:auto
* mIsTopMost: used when this view is zindex:auto
* PR_TRUE if the view is topmost when compared
* with another z-index:auto view
1998-04-15 20:25:02 +00:00
*/
nsViewZIndex GetZIndex() const { return nsViewZIndex((mVFlags & NS_VIEW_FLAG_AUTO_ZINDEX) != 0,
mZIndex,
(mVFlags & NS_VIEW_FLAG_TOPMOST) != 0); }
1998-04-13 20:24:54 +00:00
/**
* Get whether the view "floats" above all other views,
* which tells the compositor not to consider higher views in
* the view hierarchy that would geometrically intersect with
* this view. This is a hack, but it fixes some problems with
* views that need to be drawn in front of all other views.
* @result PR_TRUE if the view floats, PR_FALSE otherwise.
*/
PRBool GetFloating() const { return (mVFlags & NS_VIEW_FLAG_FLOATING) != 0; }
1998-04-15 20:25:02 +00:00
/**
* Called to query the parent of the view.
* @result view's parent
*/
nsIView* GetParent() const { return NS_REINTERPRET_CAST(nsIView*, mParent); }
1998-04-13 20:24:54 +00:00
/**
* The view's first child is the child which is earliest in document order.
* @result first child
*/
nsIView* GetFirstChild() const { return NS_REINTERPRET_CAST(nsIView*, mFirstChild); }
1998-04-15 20:25:02 +00:00
/**
* Called to query the next sibling of the view.
* @result view's next sibling
*/
nsIView* GetNextSibling() const { return NS_REINTERPRET_CAST(nsIView*, mNextSibling); }
1998-04-15 20:25:02 +00:00
/**
* Note: This didn't exist in 4.0. Called to get the opacity of a view.
1998-04-15 20:25:02 +00:00
* A value of 0.0 means completely transparent. A value of 1.0 means
* completely opaque.
* @result view's opacity value
*/
float GetOpacity() const { return mOpacity; }
1998-04-13 20:24:54 +00:00
/**
* Indicate that this view is always painted onto a uniform field of pixels. Thus,
* even if the view is transparent, it may still be bitblit scrollable because
* the background that shines through does not vary with position.
*/
void SetHasUniformBackground(PRBool aUniform) {
if (aUniform) {
mVFlags |= NS_VIEW_FLAG_UNIFORM_BACKGROUND;
} else {
mVFlags &= ~NS_VIEW_FLAG_UNIFORM_BACKGROUND;
}
}
PRBool HasUniformBackground() {
return mVFlags & NS_VIEW_FLAG_UNIFORM_BACKGROUND;
}
1998-04-15 20:25:02 +00:00
/**
* Set the view's link to client owned data.
* @param aData - data to associate with view. nsnull to disassociate
1998-04-15 20:25:02 +00:00
*/
NS_IMETHOD SetClientData(void *aData) = 0;
1998-04-15 20:25:02 +00:00
/**
* Query the view for it's link to client owned data.
* @result data associated with view or nsnull if there is none.
1998-04-15 20:25:02 +00:00
*/
void* GetClientData() const { return mClientData; }
1998-04-13 20:24:54 +00:00
1998-04-15 20:25:02 +00:00
/**
* Get the nearest widget in this view or a parent of this view and
* the offset from the view that contains the widget to this view
* @param aDx out parameter for x offset
* @param aDy out parameter for y offset
* @return widget (if there is one) closest to view
1998-04-15 20:25:02 +00:00
*/
NS_IMETHOD GetOffsetFromWidget(nscoord *aDx, nscoord *aDy, nsIWidget *&aWidget) = 0;
/**
* Create a widget to associate with this view. This is a helper
* function for SetWidget.
* @param aWindowIID IID for Widget type that this view
* should have associated with it. if nsull, then no
* width will be created for this view
* @param aWidgetInitData data used to initialize this view's widget before
* its create is called.
* @param aNative native window that will be used as parent of
* aWindowIID. if nsnull, then parent will be derived from
* parent view and it's ancestors
* @param aWindowType is either content, UI or inherit from parent window.
* This is used to expose what type of window this is to
* assistive technology like screen readers.
* @return error status
*/
NS_IMETHOD CreateWidget(const nsIID &aWindowIID,
nsWidgetInitData *aWidgetInitData = nsnull,
nsNativeWidget aNative = nsnull,
PRBool aEnableDragDrop = PR_TRUE,
PRBool aResetVisibility = PR_TRUE,
nsContentType aWindowType = eContentTypeInherit) = 0;
/**
* In 4.0, the "cutout" nature of a view is queryable.
* If we believe that all cutout view have a native widget, this
* could be a replacement.
* @param aWidget out parameter for widget that this view contains,
* or nsnull if there is none.
*/
nsIWidget* GetWidget() const { return mWindow; }
/**
* Returns PR_TRUE if the view has a widget associated with it.
*/
PRBool HasWidget() const { return mWindow != nsnull; }
// XXX Temporary for Bug #19416
NS_IMETHOD IgnoreSetPosition(PRBool aShouldIgnore) = 0;
/**
* Output debug info to FILE
* @param out output file handle
* @param aIndent indentation depth
*/
NS_IMETHOD List(FILE* out, PRInt32 aIndent = 0) const = 0;
/**
* @result true iff this is the root view for its view manager
*/
virtual PRBool IsRoot() const = 0;
private:
NS_IMETHOD_(nsrefcnt) AddRef(void) = 0;
NS_IMETHOD_(nsrefcnt) Release(void) = 0;
protected:
nsViewManager *mViewManager;
nsView *mParent;
nsIWidget *mWindow;
nsView *mNextSibling;
nsView *mFirstChild;
void *mClientData;
PRInt32 mZIndex;
nsViewVisibility mVis;
nscoord mPosX, mPosY;
nsRect mDimBounds; // relative to parent
float mOpacity;
PRUint32 mVFlags;
1998-04-13 20:24:54 +00:00
};
#endif