1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is Mozilla Communicator client code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
40
// Netscape Communications
42
// See documentation in associated header file
45
#include "nsGrippyFrame.h"
46
#include "nsScrollbarButtonFrame.h"
47
#include "nsIPresContext.h"
48
#include "nsIContent.h"
50
#include "nsUnitConversion.h"
51
#include "nsINameSpaceManager.h"
52
#include "nsHTMLAtoms.h"
53
#include "nsXULAtoms.h"
54
//#include "nsSliderFrame.h"
55
#include "nsIDOMElement.h"
56
#include "nsIDOMDocument.h"
57
#include "nsIDocument.h"
58
#include "nsHTMLParts.h"
59
#include "nsIPresShell.h"
61
#include "nsIViewManager.h"
62
#include "nsHTMLContainerFrame.h"
68
// Creates a new Toolbar frame and returns it in |aNewFrame|
71
NS_NewGrippyFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
73
NS_PRECONDITION(aNewFrame, "null OUT ptr");
74
if (nsnull == aNewFrame) {
75
return NS_ERROR_NULL_POINTER;
77
nsGrippyFrame* it = new (aPresShell) nsGrippyFrame (aPresShell);
79
return NS_ERROR_OUT_OF_MEMORY;
84
} // NS_NewGrippyFrame
86
nsGrippyFrame::nsGrippyFrame(nsIPresShell* aShell):nsButtonBoxFrame(aShell),mCollapsed(PR_FALSE)
91
nsGrippyFrame::MouseClicked (nsIPresContext* aPresContext, nsGUIEvent* aEvent)
93
// update the splitter first, in case someone's listening on the command event
95
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
98
// get the splitters content node
99
nsIContent* content = splitter->GetContent();
101
nsAutoString newState(NS_LITERAL_STRING("collapsed"));
102
nsAutoString oldState;
103
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::state, oldState))
105
if (oldState.Equals(newState))
106
newState.Assign(NS_LITERAL_STRING("open"));
109
content->SetAttr(kNameSpaceID_None, nsXULAtoms::state, newState, PR_TRUE);
112
nsButtonBoxFrame::MouseClicked(aPresContext, aEvent);
117
nsGrippyFrame::MouseClicked(nsIPresContext* aPresContext)
123
style = mCollapsedChildStyle;
125
// when clicked see if we are in a splitter.
127
nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
129
if (splitter == nsnull)
132
// get the splitters content node
133
nsIContent* content = splitter->GetContent();
135
// get the collapse attribute. If the attribute is not set collapse
136
// the child before otherwise collapse the child after
137
PRBool before = PR_TRUE;
139
if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::collapse, value))
145
// find the child just in the box just before the splitter. If we are not currently collapsed then
146
// then get the childs style attribute and store it. Then set the child style attribute to be display none.
147
// if we are already collapsed then set the child's style back to our stored value.
148
nsIFrame* child = GetChildBeforeAfter(splitter,before);
152
mCollapsedChild = child->GetContent();
154
style = "visibility: collapse";
155
mCollapsedChildStyle = "";
156
mCollapsedChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
159
mCollapsedChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::style, style, PR_TRUE);
161
mCollapsed = !mCollapsed;
168
nsGrippyFrame::GetChildBeforeAfter(nsIPresContext* aPresContext, nsIFrame* start, PRBool before)
170
nsIFrame* parent = start->GetParent();
171
PRInt32 index = IndexOf(aPresContext, parent, start);
172
PRInt32 count = CountFrames(aPresContext, parent);
182
return GetChildAt(aPresContext, parent, index-1);
186
if (index == count-1)
189
return GetChildAt(aPresContext, parent, index+1);
194
nsGrippyFrame::IndexOf(nsIPresContext* aPresContext, nsIFrame* parent, nsIFrame* child)
198
nsIFrame* childFrame = parent->GetFirstChild(nsnull);
199
while (nsnull != childFrame)
201
if (childFrame == child)
204
childFrame = childFrame->GetNextSibling();
212
nsGrippyFrame::CountFrames(nsIPresContext* aPresContext, nsIFrame* aFrame)
216
nsIFrame* childFrame = aFrame->GetFirstChild(nsnull);
217
while (nsnull != childFrame)
219
childFrame = childFrame->GetNextSibling();
227
nsGrippyFrame::GetChildAt(nsIPresContext* aPresContext, nsIFrame* parent, PRInt32 index)
231
nsIFrame* childFrame = parent->GetFirstChild(nsnull);
232
while (nsnull != childFrame)
237
childFrame = childFrame->GetNextSibling();
246
nsGrippyFrame::GetFrameName(nsAString& aResult) const
248
return MakeFrameName(NS_LITERAL_STRING("Grippy"), aResult);