diff --git a/layout/xul/base/src/Makefile.in b/layout/xul/base/src/Makefile.in index 20bfbaba777d..64a834f335df 100644 --- a/layout/xul/base/src/Makefile.in +++ b/layout/xul/base/src/Makefile.in @@ -38,6 +38,7 @@ LOCAL_INCLUDES = \ # Note the sophisticated alphabetical ordering :-| CPPSRCS = \ + nsFrameNavigator.cpp \ nsSplitterFrame.cpp \ nsGrippyFrame.cpp \ nsTabFrame.cpp \ diff --git a/layout/xul/base/src/makefile.win b/layout/xul/base/src/makefile.win index d775c18e40de..06d0a778c72c 100644 --- a/layout/xul/base/src/makefile.win +++ b/layout/xul/base/src/makefile.win @@ -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 \ diff --git a/layout/xul/base/src/nsFrameNavigator.cpp b/layout/xul/base/src/nsFrameNavigator.cpp new file mode 100644 index 000000000000..745413c7f86c --- /dev/null +++ b/layout/xul/base/src/nsFrameNavigator.cpp @@ -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 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; +} + diff --git a/layout/xul/base/src/nsFrameNavigator.h b/layout/xul/base/src/nsFrameNavigator.h new file mode 100644 index 000000000000..d8dd13250628 --- /dev/null +++ b/layout/xul/base/src/nsFrameNavigator.h @@ -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 +