~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/layout/xul/base/src/nsGrippyFrame.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is Mozilla Communicator client code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
//
 
39
// Eric Vaughan
 
40
// Netscape Communications
 
41
//
 
42
// See documentation in associated header file
 
43
//
 
44
 
 
45
#include "nsGrippyFrame.h"
 
46
#include "nsScrollbarButtonFrame.h"
 
47
#include "nsIPresContext.h"
 
48
#include "nsIContent.h"
 
49
#include "nsCOMPtr.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"
 
60
#include "nsIView.h"
 
61
#include "nsIViewManager.h"
 
62
#include "nsHTMLContainerFrame.h"
 
63
 
 
64
 
 
65
//
 
66
// NS_NewToolbarFrame
 
67
//
 
68
// Creates a new Toolbar frame and returns it in |aNewFrame|
 
69
//
 
70
nsresult
 
71
NS_NewGrippyFrame ( nsIPresShell* aPresShell, nsIFrame** aNewFrame )
 
72
{
 
73
  NS_PRECONDITION(aNewFrame, "null OUT ptr");
 
74
  if (nsnull == aNewFrame) {
 
75
    return NS_ERROR_NULL_POINTER;
 
76
  }
 
77
  nsGrippyFrame* it = new (aPresShell) nsGrippyFrame (aPresShell);
 
78
  if (nsnull == it)
 
79
    return NS_ERROR_OUT_OF_MEMORY;
 
80
 
 
81
  *aNewFrame = it;
 
82
  return NS_OK;
 
83
  
 
84
} // NS_NewGrippyFrame
 
85
 
 
86
nsGrippyFrame::nsGrippyFrame(nsIPresShell* aShell):nsButtonBoxFrame(aShell),mCollapsed(PR_FALSE)
 
87
{
 
88
}
 
89
 
 
90
void
 
91
nsGrippyFrame::MouseClicked (nsIPresContext* aPresContext, nsGUIEvent* aEvent) 
 
92
{
 
93
    // update the splitter first, in case someone's listening on the command event
 
94
    nsIFrame* splitter;
 
95
    nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
 
96
    if (splitter) {
 
97
 
 
98
        // get the splitters content node
 
99
        nsIContent* content = splitter->GetContent();
 
100
 
 
101
        nsAutoString newState(NS_LITERAL_STRING("collapsed"));
 
102
        nsAutoString oldState;
 
103
        if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::state, oldState))
 
104
        {
 
105
            if (oldState.Equals(newState))
 
106
                newState.Assign(NS_LITERAL_STRING("open"));
 
107
        }
 
108
 
 
109
        content->SetAttr(kNameSpaceID_None, nsXULAtoms::state, newState, PR_TRUE);
 
110
    }
 
111
 
 
112
    nsButtonBoxFrame::MouseClicked(aPresContext, aEvent);
 
113
}
 
114
 
 
115
/*
 
116
void
 
117
nsGrippyFrame::MouseClicked(nsIPresContext* aPresContext) 
 
118
{
 
119
 
 
120
  nsString style;
 
121
 
 
122
  if (mCollapsed) {
 
123
    style = mCollapsedChildStyle;
 
124
  } else {
 
125
    // when clicked see if we are in a splitter. 
 
126
    nsIFrame* splitter;
 
127
    nsScrollbarButtonFrame::GetParentWithTag(nsXULAtoms::splitter, this, splitter);
 
128
 
 
129
    if (splitter == nsnull)
 
130
       return;
 
131
 
 
132
    // get the splitters content node
 
133
    nsIContent* content = splitter->GetContent();
 
134
 
 
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;
 
138
    nsString value;
 
139
    if (NS_CONTENT_ATTR_HAS_VALUE == content->GetAttr(kNameSpaceID_None, nsXULAtoms::collapse, value))
 
140
    {
 
141
     if (value=="after")
 
142
       before = PR_FALSE;
 
143
    }
 
144
 
 
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);
 
149
    if (child == nsnull)
 
150
      return;
 
151
 
 
152
    mCollapsedChild = child->GetContent();
 
153
 
 
154
    style = "visibility: collapse";
 
155
    mCollapsedChildStyle = "";
 
156
    mCollapsedChild->GetAttr(kNameSpaceID_None, nsHTMLAtoms::style, mCollapsedChildStyle);
 
157
  }
 
158
 
 
159
  mCollapsedChild->SetAttr(kNameSpaceID_None, nsHTMLAtoms::style, style, PR_TRUE);
 
160
 
 
161
  mCollapsed = !mCollapsed;
 
162
 
 
163
}
 
164
*/
 
165
 
 
166
 
 
167
nsIFrame*
 
168
nsGrippyFrame::GetChildBeforeAfter(nsIPresContext* aPresContext, nsIFrame* start, PRBool before)
 
169
{
 
170
   nsIFrame* parent = start->GetParent();
 
171
   PRInt32 index = IndexOf(aPresContext, parent, start);
 
172
   PRInt32 count = CountFrames(aPresContext, parent);
 
173
 
 
174
   if (index == -1) 
 
175
     return nsnull;
 
176
 
 
177
   if (before) {
 
178
     if (index == 0) {
 
179
         return nsnull;
 
180
     }
 
181
 
 
182
     return GetChildAt(aPresContext, parent, index-1);
 
183
   }
 
184
 
 
185
 
 
186
   if (index == count-1)
 
187
       return nsnull;
 
188
 
 
189
   return GetChildAt(aPresContext, parent, index+1);
 
190
 
 
191
}
 
192
 
 
193
PRInt32
 
194
nsGrippyFrame::IndexOf(nsIPresContext* aPresContext, nsIFrame* parent, nsIFrame* child)
 
195
{
 
196
  PRInt32 count = 0;
 
197
 
 
198
  nsIFrame* childFrame = parent->GetFirstChild(nsnull); 
 
199
  while (nsnull != childFrame) 
 
200
  {    
 
201
    if (childFrame == child)
 
202
       return count;
 
203
 
 
204
    childFrame = childFrame->GetNextSibling();
 
205
    count++;
 
206
  }
 
207
 
 
208
  return -1;
 
209
}
 
210
 
 
211
PRInt32
 
212
nsGrippyFrame::CountFrames(nsIPresContext* aPresContext, nsIFrame* aFrame)
 
213
{
 
214
  PRInt32 count = 0;
 
215
 
 
216
  nsIFrame* childFrame = aFrame->GetFirstChild(nsnull);
 
217
  while (nsnull != childFrame) 
 
218
  {    
 
219
    childFrame = childFrame->GetNextSibling();
 
220
    count++;
 
221
  }
 
222
 
 
223
  return count;
 
224
}
 
225
 
 
226
nsIFrame*
 
227
nsGrippyFrame::GetChildAt(nsIPresContext* aPresContext, nsIFrame* parent, PRInt32 index)
 
228
{
 
229
  PRInt32 count = 0;
 
230
 
 
231
  nsIFrame* childFrame = parent->GetFirstChild(nsnull);
 
232
  while (nsnull != childFrame) 
 
233
  {    
 
234
    if (count == index)
 
235
       return childFrame;
 
236
 
 
237
    childFrame = childFrame->GetNextSibling();
 
238
    count++;
 
239
  }
 
240
 
 
241
  return nsnull;
 
242
}
 
243
 
 
244
#ifdef DEBUG
 
245
NS_IMETHODIMP
 
246
nsGrippyFrame::GetFrameName(nsAString& aResult) const
 
247
{
 
248
  return MakeFrameName(NS_LITERAL_STRING("Grippy"), aResult);
 
249
}
 
250
#endif