Added a helper class to search frame hierarchys.

This commit is contained in:
evaughan%netscape.com 1999-09-05 20:35:41 +00:00
Родитель 0cc0bf5862
Коммит b2747f9b04
4 изменённых файлов: 177 добавлений и 0 удалений

Просмотреть файл

@ -38,6 +38,7 @@ LOCAL_INCLUDES = \
# Note the sophisticated alphabetical ordering :-|
CPPSRCS = \
nsFrameNavigator.cpp \
nsSplitterFrame.cpp \
nsGrippyFrame.cpp \
nsTabFrame.cpp \

Просмотреть файл

@ -24,6 +24,7 @@ REQUIRES=xpcom raptor pref
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
CPPSRCS= \
nsFrameNavigator.cpp \
nsRepeatService.cpp \
nsToolbarDragListener.cpp \
nsToolbarItemFrame.cpp \
@ -58,6 +59,7 @@ CPPSRCS= \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsFrameNavigator.obj \
.\$(OBJDIR)\nsRepeatService.obj \
.\$(OBJDIR)\nsToolbarDragListener.obj \
.\$(OBJDIR)\nsToolbarItemFrame.obj \

Просмотреть файл

@ -0,0 +1,127 @@
/* -*- 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.0 (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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
//
// Eric Vaughan
// Netscape Communications
//
// See documentation in associated header file
//
#include "nsFrameNavigator.h"
#include "nsCOMPtr.h"
#include "nsIContent.h"
nsIAtom*
nsFrameNavigator::GetTag(nsIFrame* frame)
{
nsCOMPtr<nsIContent> content;
frame->GetContent(getter_AddRefs(content));
if (content) {
nsIAtom* atom = nsnull;
content->GetTag(atom);
return atom;
}
return nsnull;
}
nsIFrame*
nsFrameNavigator::GetChildBeforeAfter(nsIFrame* start, PRBool before)
{
nsIFrame* parent = nsnull;
start->GetParent(&parent);
PRInt32 index = IndexOf(parent,start);
PRInt32 count = CountFrames(parent);
if (index == -1)
return nsnull;
if (before) {
if (index == 0) {
return nsnull;
}
return GetChildAt(parent, index-1);
}
if (index == count-1)
return nsnull;
return GetChildAt(parent, index+1);
}
PRInt32
nsFrameNavigator::IndexOf(nsIFrame* parent, nsIFrame* child)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (childFrame == child)
return count;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return -1;
}
PRInt32
nsFrameNavigator::CountFrames(nsIFrame* aFrame)
{
PRInt32 count = 0;
nsIFrame* childFrame;
aFrame->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return count;
}
nsIFrame*
nsFrameNavigator::GetChildAt(nsIFrame* parent, PRInt32 index)
{
PRInt32 count = 0;
nsIFrame* childFrame;
parent->FirstChild(nsnull, &childFrame);
while (nsnull != childFrame)
{
if (count == index)
return childFrame;
nsresult rv = childFrame->GetNextSibling(&childFrame);
NS_ASSERTION(rv == NS_OK,"failed to get next child");
count++;
}
return nsnull;
}

Просмотреть файл

@ -0,0 +1,47 @@
/* -*- 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.0 (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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/**
Eric D Vaughan
This class lays out its children either vertically or horizontally
**/
#ifndef nsGrippyFrame_h___
#define nsGrippyFrame_h___
#include "nsIFrame.h"
class nsFrameNavigator
{
public:
static nsIFrame* GetChildBeforeAfter(nsIFrame* start, PRBool before);
static nsIFrame* GetChildAt(nsIFrame* parent, PRInt32 index);
static PRInt32 IndexOf(nsIFrame* parent, nsIFrame* child);
static PRInt32 CountFrames(nsIFrame* aFrame);
static nsIAtom* GetTag(nsIFrame* frame);
};
#endif