pjs/layout/generic/nsSpaceManager.h

178 строки
6.0 KiB
C
Исходник Обычный вид История

1998-04-14 00:24:54 +04:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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-14 00:24:54 +04: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-14 00:24:54 +04:00
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
1998-04-14 00:24:54 +04:00
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
1998-04-14 00:24:54 +04:00
*/
#ifndef nsSpaceManager_h___
#define nsSpaceManager_h___
#include "nsISpaceManager.h"
1998-05-19 07:00:56 +04:00
#include "prclist.h"
1998-04-14 00:24:54 +04:00
/**
* Implementation of nsISpaceManager that maintains a region data structure of
* unavailable space
*/
1998-05-28 06:37:37 +04:00
class nsSpaceManager : public nsISpaceManager {
1998-04-14 00:24:54 +04:00
public:
1998-05-28 06:37:37 +04:00
nsSpaceManager(nsIFrame* aFrame);
1998-04-14 00:24:54 +04:00
// nsISupports
NS_DECL_ISUPPORTS
1998-05-19 07:00:56 +04:00
// nsISpaceManager
NS_IMETHOD GetFrame(nsIFrame*& aFrame) const;
1998-04-14 00:24:54 +04:00
NS_IMETHOD Translate(nscoord aDx, nscoord aDy);
NS_IMETHOD GetTranslation(nscoord& aX, nscoord& aY) const;
NS_IMETHOD YMost(nscoord& aYMost) const;
1998-05-13 03:02:02 +04:00
NS_IMETHOD GetBandData(nscoord aYOffset,
const nsSize& aMaxSize,
nsBandData& aBandData) const;
1998-05-13 03:02:02 +04:00
NS_IMETHOD AddRectRegion(nsIFrame* aFrame,
const nsRect& aUnavailableSpace);
NS_IMETHOD ResizeRectRegion(nsIFrame* aFrame,
nscoord aDeltaWidth,
nscoord aDeltaHeight,
AffectedEdge aEdge);
NS_IMETHOD OffsetRegion(nsIFrame* aFrame, nscoord aDx, nscoord aDy);
NS_IMETHOD RemoveRegion(nsIFrame* aFrame);
1998-05-13 03:02:02 +04:00
NS_IMETHOD ClearRegions();
1998-04-14 00:24:54 +04:00
#ifdef DEBUG
NS_IMETHOD List(FILE* out);
void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
#endif
1998-04-14 00:24:54 +04:00
protected:
1998-05-19 07:00:56 +04:00
// Structure that maintains information about the region associated
// with a particular frame
struct FrameInfo {
nsIFrame* const mFrame;
nsRect mRect; // rectangular region
FrameInfo* mNext;
1998-05-19 07:00:56 +04:00
FrameInfo(nsIFrame* aFrame, const nsRect& aRect);
#ifdef NS_BUILD_REFCNT_LOGGING
~FrameInfo();
#endif
1998-05-19 07:00:56 +04:00
};
public:
1998-05-19 07:00:56 +04:00
// Doubly linked list of band rects
struct BandRect : PRCListStr {
nscoord mLeft, mTop;
nscoord mRight, mBottom;
PRIntn mNumFrames; // number of frames occupying this rect
union {
nsIFrame* mFrame; // single frame occupying the space
nsVoidArray* mFrames; // list of frames occupying the space
};
1998-05-19 07:00:56 +04:00
BandRect(nscoord aLeft, nscoord aTop,
nscoord aRight, nscoord aBottom,
nsIFrame*);
BandRect(nscoord aLeft, nscoord aTop,
nscoord aRight, nscoord aBottom,
nsVoidArray*);
~BandRect();
1998-05-20 02:55:40 +04:00
// List operations
BandRect* Next() const {return (BandRect*)PR_NEXT_LINK(this);}
BandRect* Prev() const {return (BandRect*)PR_PREV_LINK(this);}
void InsertBefore(BandRect* aBandRect) {PR_INSERT_BEFORE(aBandRect, this);}
void InsertAfter(BandRect* aBandRect) {PR_INSERT_AFTER(aBandRect, this);}
void Remove() {PR_REMOVE_LINK(this);}
1998-05-19 07:00:56 +04:00
// Split the band rect into two vertically, with this band rect becoming
// the top part, and a new band rect being allocated and returned for the
// bottom part
1998-05-20 02:55:40 +04:00
//
// Does not insert the new band rect into the linked list
1998-05-19 07:00:56 +04:00
BandRect* SplitVertically(nscoord aBottom);
// Split the band rect into two horizontally, with this band rect becoming
// the left part, and a new band rect being allocated and returned for the
// right part
1998-05-20 02:55:40 +04:00
//
// Does not insert the new band rect into the linked list
1998-05-19 07:00:56 +04:00
BandRect* SplitHorizontally(nscoord aRight);
// Accessor functions
1998-05-19 19:30:10 +04:00
PRBool IsOccupiedBy(const nsIFrame*) const;
void AddFrame(const nsIFrame*);
void RemoveFrame(const nsIFrame*);
PRBool HasSameFrameList(const BandRect* aBandRect) const;
PRInt32 Length() const;
};
1998-05-20 02:55:40 +04:00
// Circular linked list of band rects
struct BandList : BandRect {
BandList();
// Accessors
PRBool IsEmpty() const {return PR_CLIST_IS_EMPTY((PRCListStr*)this);}
BandRect* Head() const {return (BandRect*)PR_LIST_HEAD(this);}
BandRect* Tail() const {return (BandRect*)PR_LIST_TAIL(this);}
// Operations
void Append(BandRect* aBandRect) {PR_APPEND_LINK(aBandRect, this);}
// Remove and delete all the band rects in the list
void Clear();
};
protected:
1998-05-19 07:00:56 +04:00
nsIFrame* const mFrame; // frame associated with the space manager
nscoord mX, mY; // translation from local to global coordinate space
BandList mBandList; // header/sentinel for circular linked list of band rects
FrameInfo* mFrameInfoMap;
1998-04-14 00:24:54 +04:00
1998-05-19 07:00:56 +04:00
protected:
virtual ~nsSpaceManager();
1998-05-19 07:00:56 +04:00
FrameInfo* GetFrameInfoFor(nsIFrame* aFrame);
FrameInfo* CreateFrameInfo(nsIFrame* aFrame, const nsRect& aRect);
void DestroyFrameInfo(FrameInfo*);
1998-04-14 00:24:54 +04:00
1998-05-19 07:00:56 +04:00
void ClearFrameInfo();
void ClearBandRects();
1998-04-14 00:24:54 +04:00
1998-05-19 07:00:56 +04:00
BandRect* GetNextBand(const BandRect* aBandRect) const;
void DivideBand(BandRect* aBand, nscoord aBottom);
1998-05-20 02:55:40 +04:00
PRBool CanJoinBands(BandRect* aBand, BandRect* aPrevBand);
1998-05-19 19:30:10 +04:00
PRBool JoinBands(BandRect* aBand, BandRect* aPrevBand);
1998-05-19 07:00:56 +04:00
void AddRectToBand(BandRect* aBand, BandRect* aBandRect);
void InsertBandRect(BandRect* aBandRect);
1998-04-14 00:24:54 +04:00
nsresult GetBandAvailableSpace(const BandRect* aBand,
1998-05-19 07:00:56 +04:00
nscoord aY,
const nsSize& aMaxSize,
nsBandData& aAvailableSpace) const;
1998-04-14 00:24:54 +04:00
private:
nsSpaceManager(const nsSpaceManager&); // no implementation
1998-05-28 06:37:37 +04:00
void operator=(const nsSpaceManager&); // no implementation
1998-04-14 00:24:54 +04:00
};
#endif /* nsSpaceManager_h___ */