зеркало из https://github.com/mozilla/gecko-dev.git
Bug 526394. Part 12: Convert XUL layout code: scrollboxes and trees. r=mats
This commit is contained in:
Родитель
c73b06e1f3
Коммит
0c42dd5ebb
|
@ -46,10 +46,8 @@
|
|||
#include "nsIDOMElement.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
|
||||
|
||||
class nsScrollBoxObject : public nsIScrollBoxObject, public nsBoxObject
|
||||
{
|
||||
public:
|
||||
|
@ -59,7 +57,9 @@ public:
|
|||
nsScrollBoxObject();
|
||||
virtual ~nsScrollBoxObject();
|
||||
|
||||
virtual nsIScrollableView* GetScrollableView();
|
||||
virtual nsIScrollableFrame* GetScrollFrame() {
|
||||
return do_QueryFrame(GetFrame(PR_FALSE));
|
||||
}
|
||||
|
||||
/* additional members */
|
||||
};
|
||||
|
@ -86,12 +86,14 @@ nsScrollBoxObject::~nsScrollBoxObject()
|
|||
/* void scrollTo (in long x, in long y); */
|
||||
NS_IMETHODIMP nsScrollBoxObject::ScrollTo(PRInt32 x, PRInt32 y)
|
||||
{
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return scrollableView->ScrollTo(nsPresContext::CSSPixelsToAppUnits(x),
|
||||
nsPresContext::CSSPixelsToAppUnits(y), 0);
|
||||
sf->ScrollTo(nsPoint(nsPresContext::CSSPixelsToAppUnits(x),
|
||||
nsPresContext::CSSPixelsToAppUnits(y)),
|
||||
nsIScrollableFrame::INSTANT);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void scrollBy (in long dx, in long dy); */
|
||||
|
@ -108,11 +110,13 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollBy(PRInt32 dx, PRInt32 dy)
|
|||
/* void scrollByLine (in long dlines); */
|
||||
NS_IMETHODIMP nsScrollBoxObject::ScrollByLine(PRInt32 dlines)
|
||||
{
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return scrollableView->ScrollByLines(0, dlines);
|
||||
sf->ScrollBy(nsIntPoint(0, dlines), nsIScrollableFrame::LINES,
|
||||
nsIScrollableFrame::SMOOTH);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// XUL <scrollbox> elements have a single box child element.
|
||||
|
@ -139,8 +143,8 @@ static nsIFrame* GetScrolledBox(nsBoxObject* aScrollBox) {
|
|||
/* void scrollByIndex (in long dindexes); */
|
||||
NS_IMETHODIMP nsScrollBoxObject::ScrollByIndex(PRInt32 dindexes)
|
||||
{
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsIFrame* scrolledBox = GetScrolledBox(this);
|
||||
if (!scrolledBox)
|
||||
|
@ -152,8 +156,7 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollByIndex(PRInt32 dindexes)
|
|||
nsIFrame* child = scrolledBox->GetChildBox();
|
||||
|
||||
PRBool horiz = scrolledBox->IsHorizontal();
|
||||
nsPoint cp;
|
||||
scrollableView->GetScrollPosition(cp.x,cp.y);
|
||||
nsPoint cp = sf->GetScrollPosition();
|
||||
nscoord diff = 0;
|
||||
PRInt32 curIndex = 0;
|
||||
PRBool isLTR = scrolledBox->IsNormalDirection();
|
||||
|
@ -226,23 +229,24 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollByIndex(PRInt32 dindexes)
|
|||
// selected child is scrolled to the left edge of the scrollbox.
|
||||
// In the right-to-left case we scroll so that the right edge of the
|
||||
// selected child is scrolled to the right edge of the scrollbox.
|
||||
return scrollableView->ScrollTo((isLTR) ? rect.x :
|
||||
rect.x + rect.width - frameWidth, cp.y, 0);
|
||||
sf->ScrollTo(nsPoint(isLTR ? rect.x : rect.x + rect.width - frameWidth,
|
||||
cp.y),
|
||||
nsIScrollableFrame::INSTANT);
|
||||
else
|
||||
return scrollableView->ScrollTo(cp.x, rect.y, 0);
|
||||
sf->ScrollTo(nsPoint(cp.x, rect.y), nsIScrollableFrame::INSTANT);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void scrollToLine (in long line); */
|
||||
NS_IMETHODIMP nsScrollBoxObject::ScrollToLine(PRInt32 line)
|
||||
{
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nscoord height = 0;
|
||||
scrollableView->GetLineHeight(&height);
|
||||
scrollableView->ScrollTo(0, height * line, 0);
|
||||
|
||||
nscoord y = sf->GetLineScrollAmount().height * line;
|
||||
sf->ScrollTo(nsPoint(0, y), nsIScrollableFrame::INSTANT);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -250,8 +254,8 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollToLine(PRInt32 line)
|
|||
NS_IMETHODIMP nsScrollBoxObject::ScrollToElement(nsIDOMElement *child)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(child);
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell = GetPresShell(PR_FALSE);
|
||||
|
@ -285,9 +289,7 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollToElement(nsIDOMElement *child)
|
|||
// TODO: make sure the child is inside the box
|
||||
|
||||
// get our current info
|
||||
nsPoint cp;
|
||||
scrollableView->GetScrollPosition(cp.x,cp.y);
|
||||
|
||||
nsPoint cp = sf->GetScrollPosition();
|
||||
nsIntRect prect;
|
||||
GetOffsetRect(prect);
|
||||
crect = prect.ToAppUnits(nsPresContext::AppUnitsPerCSSPixel());
|
||||
|
@ -301,7 +303,8 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollToElement(nsIDOMElement *child)
|
|||
newy = rect.y - crect.y;
|
||||
}
|
||||
// scroll away
|
||||
return scrollableView->ScrollTo(newx, newy, 0);
|
||||
sf->ScrollTo(nsPoint(newx, newy), nsIScrollableFrame::INSTANT);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void scrollToIndex (in long index); */
|
||||
|
@ -313,17 +316,13 @@ NS_IMETHODIMP nsScrollBoxObject::ScrollToIndex(PRInt32 index)
|
|||
/* void getPosition (out long x, out long y); */
|
||||
NS_IMETHODIMP nsScrollBoxObject::GetPosition(PRInt32 *x, PRInt32 *y)
|
||||
{
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nscoord xc, yc;
|
||||
nsresult rv = scrollableView->GetScrollPosition(xc, yc);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
*x = nsPresContext::AppUnitsToIntCSSPixels(xc);
|
||||
*y = nsPresContext::AppUnitsToIntCSSPixels(yc);
|
||||
nsPoint pt = sf->GetScrollPosition();
|
||||
*x = nsPresContext::AppUnitsToIntCSSPixels(pt.x);
|
||||
*y = nsPresContext::AppUnitsToIntCSSPixels(pt.y);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -368,8 +367,8 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureElementIsVisible(nsIDOMElement *child)
|
|||
childBoxObject->GetWidth(&width);
|
||||
childBoxObject->GetHeight(&height);
|
||||
|
||||
nsIScrollableView* scrollableView = GetScrollableView();
|
||||
if (!scrollableView)
|
||||
nsIScrollableFrame* sf = GetScrollFrame();
|
||||
if (!sf)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsIFrame* scrolledBox = GetScrolledBox(this);
|
||||
|
@ -386,8 +385,7 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureElementIsVisible(nsIDOMElement *child)
|
|||
// TODO: make sure the child is inside the box
|
||||
|
||||
// get our current info
|
||||
nsPoint cp;
|
||||
scrollableView->GetScrollPosition(cp.x,cp.y);
|
||||
nsPoint cp = sf->GetScrollPosition();
|
||||
nsIntRect prect;
|
||||
GetOffsetRect(prect);
|
||||
crect = prect.ToAppUnits(nsPresContext::AppUnitsPerCSSPixel());
|
||||
|
@ -410,7 +408,8 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureElementIsVisible(nsIDOMElement *child)
|
|||
}
|
||||
|
||||
// scroll away
|
||||
return scrollableView->ScrollTo(newx, newy, 0);
|
||||
sf->ScrollTo(nsPoint(newx, newy), nsIScrollableFrame::INSTANT);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void ensureIndexIsVisible (in long index); */
|
||||
|
@ -425,25 +424,6 @@ NS_IMETHODIMP nsScrollBoxObject::EnsureLineIsVisible(PRInt32 line)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsIScrollableView*
|
||||
nsScrollBoxObject::GetScrollableView()
|
||||
{
|
||||
// get the frame.
|
||||
nsIFrame* frame = GetFrame(PR_FALSE);
|
||||
if (!frame)
|
||||
return nsnull;
|
||||
|
||||
nsIScrollableFrame* scrollFrame = do_QueryFrame(frame);
|
||||
if (!scrollFrame)
|
||||
return nsnull;
|
||||
|
||||
nsIScrollableView* scrollingView = scrollFrame->GetScrollableView();
|
||||
if (!scrollingView)
|
||||
return nsnull;
|
||||
|
||||
return scrollingView;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewScrollBoxObject(nsIBoxObject** aResult)
|
||||
{
|
||||
|
|
|
@ -93,7 +93,6 @@
|
|||
#include "nsTreeContentView.h"
|
||||
#include "nsTreeUtils.h"
|
||||
#include "nsChildIterator.h"
|
||||
#include "nsIScrollableView.h"
|
||||
#include "nsITheme.h"
|
||||
#include "nsITimelineService.h"
|
||||
#include "imgIRequest.h"
|
||||
|
@ -848,11 +847,11 @@ nsTreeBodyFrame::InvalidateColumnRange(PRInt32 aStart, PRInt32 aEnd, nsITreeColu
|
|||
static void
|
||||
FindScrollParts(nsIFrame* aCurrFrame, nsTreeBodyFrame::ScrollParts* aResult)
|
||||
{
|
||||
if (!aResult->mColumnsScrollableView) {
|
||||
if (!aResult->mColumnsScrollFrame) {
|
||||
nsIScrollableFrame* f = do_QueryFrame(aCurrFrame);
|
||||
if (f) {
|
||||
aResult->mColumnsFrame = aCurrFrame;
|
||||
aResult->mColumnsScrollableView = f->GetScrollableView();
|
||||
aResult->mColumnsScrollFrame = f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -874,7 +873,7 @@ FindScrollParts(nsIFrame* aCurrFrame, nsTreeBodyFrame::ScrollParts* aResult)
|
|||
nsIFrame* child = aCurrFrame->GetFirstChild(nsnull);
|
||||
while (child &&
|
||||
(!aResult->mVScrollbar || !aResult->mHScrollbar ||
|
||||
!aResult->mColumnsScrollableView)) {
|
||||
!aResult->mColumnsScrollFrame)) {
|
||||
FindScrollParts(child, aResult);
|
||||
child = child->GetNextSibling();
|
||||
}
|
||||
|
@ -2526,15 +2525,14 @@ nsTreeBodyFrame::CalcHorzWidth(const ScrollParts& aParts)
|
|||
mAdjustWidth = 0;
|
||||
|
||||
nscoord width = 0;
|
||||
nscoord height;
|
||||
|
||||
// We calculate this from the scrollable view, so that it
|
||||
// We calculate this from the scrollable frame, so that it
|
||||
// properly covers all contingencies of what could be
|
||||
// scrollable (columns, body, etc...)
|
||||
|
||||
if (aParts.mColumnsScrollableView) {
|
||||
if (NS_FAILED (aParts.mColumnsScrollableView->GetContainerSize(&width, &height)))
|
||||
width = 0;
|
||||
if (aParts.mColumnsScrollFrame) {
|
||||
width = aParts.mColumnsScrollFrame->GetScrollRange().width +
|
||||
aParts.mColumnsScrollFrame->GetScrollPortRect().width;
|
||||
}
|
||||
|
||||
// If no horz scrolling periphery is present, then just return our width
|
||||
|
@ -4165,7 +4163,7 @@ nsTreeBodyFrame::ScrollInternal(const ScrollParts& aParts, PRInt32 aRow)
|
|||
nsresult
|
||||
nsTreeBodyFrame::ScrollHorzInternal(const ScrollParts& aParts, PRInt32 aPosition)
|
||||
{
|
||||
if (!mView || !aParts.mColumnsScrollableView || !aParts.mHScrollbar)
|
||||
if (!mView || !aParts.mColumnsScrollFrame || !aParts.mHScrollbar)
|
||||
return NS_OK;
|
||||
|
||||
if (aPosition == mHorzPosition)
|
||||
|
@ -4216,7 +4214,8 @@ nsTreeBodyFrame::ScrollHorzInternal(const ScrollParts& aParts, PRInt32 aPosition
|
|||
}
|
||||
|
||||
// Update the column scroll view
|
||||
aParts.mColumnsScrollableView->ScrollTo(mHorzPosition, 0, 0);
|
||||
aParts.mColumnsScrollFrame->ScrollTo(nsPoint(mHorzPosition, 0),
|
||||
nsIScrollableFrame::INSTANT);
|
||||
|
||||
// And fire off an event about it all
|
||||
PostScrollEvent();
|
||||
|
|
|
@ -178,7 +178,7 @@ public:
|
|||
nsIScrollbarFrame* mHScrollbar;
|
||||
nsCOMPtr<nsIContent> mHScrollbarContent;
|
||||
nsIFrame* mColumnsFrame;
|
||||
nsIScrollableView* mColumnsScrollableView;
|
||||
nsIScrollableFrame* mColumnsScrollFrame;
|
||||
};
|
||||
|
||||
void PaintTreeBody(nsIRenderingContext& aRenderingContext,
|
||||
|
|
Загрузка…
Ссылка в новой задаче