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.
23
* David W. Hyatt (hyatt@netscape.com) (Original Author)
24
* Joe Hewitt (hewitt@netscape.com)
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the NPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the NPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
41
#include "nsIListBoxObject.h"
42
#include "nsBoxObject.h"
44
#include "nsIDocument.h"
45
#include "nsIBindingManager.h"
46
#include "nsIDOMElement.h"
47
#include "nsIDOMNodeList.h"
48
#include "nsXULAtoms.h"
50
class nsListBoxObject : public nsIListBoxObject, public nsBoxObject
54
NS_DECL_NSILISTBOXOBJECT
57
virtual ~nsListBoxObject();
59
nsIListBoxObject* GetListBoxBody();
61
NS_IMETHOD InvalidatePresentationStuff();
66
NS_IMPL_ADDREF(nsListBoxObject)
67
NS_IMPL_RELEASE(nsListBoxObject)
70
nsListBoxObject::QueryInterface(REFNSIID iid, void** aResult)
73
return NS_ERROR_NULL_POINTER;
75
if (iid.Equals(NS_GET_IID(nsIListBoxObject))) {
76
*aResult = (nsIListBoxObject*)this;
81
return nsBoxObject::QueryInterface(iid, aResult);
84
nsListBoxObject::nsListBoxObject()
88
nsListBoxObject::~nsListBoxObject()
93
//////////////////////////////////////////////////////////////////////////
97
nsListBoxObject::GetListboxBody(nsIListBoxObject * *aListboxBody)
99
*aListboxBody = GetListBoxBody();
100
NS_IF_ADDREF(*aListboxBody);
105
nsListBoxObject::GetRowCount(PRInt32 *aResult)
107
nsIListBoxObject* body = GetListBoxBody();
109
return body->GetRowCount(aResult);
114
nsListBoxObject::GetNumberOfVisibleRows(PRInt32 *aResult)
116
nsIListBoxObject* body = GetListBoxBody();
118
return body->GetNumberOfVisibleRows(aResult);
123
nsListBoxObject::GetIndexOfFirstVisibleRow(PRInt32 *aResult)
125
nsIListBoxObject* body = GetListBoxBody();
127
return body->GetIndexOfFirstVisibleRow(aResult);
131
NS_IMETHODIMP nsListBoxObject::EnsureIndexIsVisible(PRInt32 aRowIndex)
133
nsIListBoxObject* body = GetListBoxBody();
135
return body->EnsureIndexIsVisible(aRowIndex);
140
nsListBoxObject::ScrollToIndex(PRInt32 aRowIndex)
142
nsIListBoxObject* body = GetListBoxBody();
144
return body->ScrollToIndex(aRowIndex);
149
nsListBoxObject::ScrollByLines(PRInt32 aNumLines)
151
nsIListBoxObject* body = GetListBoxBody();
153
return body->ScrollByLines(aNumLines);
158
nsListBoxObject::GetItemAtIndex(PRInt32 index, nsIDOMElement **_retval)
160
nsIListBoxObject* body = GetListBoxBody();
162
return body->GetItemAtIndex(index, _retval);
167
nsListBoxObject::GetIndexOfItem(nsIDOMElement* aElement, PRInt32 *aResult)
171
nsIListBoxObject* body = GetListBoxBody();
173
return body->GetIndexOfItem(aElement, aResult);
177
//////////////////////
180
FindBodyContent(nsIContent* aParent, nsIContent** aResult)
182
if (aParent->Tag() == nsXULAtoms::listboxbody) {
184
NS_IF_ADDREF(*aResult);
187
nsCOMPtr<nsIDOMNodeList> kids;
188
aParent->GetDocument()->GetBindingManager()->GetXBLChildNodesFor(aParent, getter_AddRefs(kids));
193
// start from the end, cuz we're smart and we know the listboxbody is probably at the end
195
nsCOMPtr<nsIDOMNode> childNode;
196
kids->Item(--i, getter_AddRefs(childNode));
197
nsCOMPtr<nsIContent> childContent(do_QueryInterface(childNode));
198
FindBodyContent(childContent, aResult);
206
nsListBoxObject::GetListBoxBody()
208
NS_NAMED_LITERAL_STRING(listboxbody, "listboxbody");
210
nsCOMPtr<nsISupports> supp;
211
GetPropertyAsSupports(listboxbody.get(), getter_AddRefs(supp));
214
nsCOMPtr<nsIListBoxObject> body(do_QueryInterface(supp));
218
nsIFrame* frame = GetFrame();
222
// Iterate over our content model children looking for the body.
223
nsCOMPtr<nsIContent> content;
224
FindBodyContent(frame->GetContent(), getter_AddRefs(content));
226
// this frame will be a nsGFXScrollFrame
227
mPresShell->GetPrimaryFrameFor(content, &frame);
231
// this frame will be a nsListBoxScrollPortFrame
232
nsIFrame* scrollPort = frame->GetFirstChild(nsnull);
236
// this frame will be the one we want
237
nsIFrame* yeahBaby = scrollPort->GetFirstChild(nsnull);
241
// It's a frame. Refcounts are irrelevant.
242
nsCOMPtr<nsIListBoxObject> body;
243
yeahBaby->QueryInterface(NS_GET_IID(nsIListBoxObject), getter_AddRefs(body));
244
SetPropertyAsSupports(listboxbody.get(), body);
249
nsListBoxObject::InvalidatePresentationStuff()
251
SetPropertyAsSupports(NS_LITERAL_STRING("listboxbody").get(), nsnull);
253
return nsBoxObject::InvalidatePresentationStuff();
256
// Creation Routine ///////////////////////////////////////////////////////////////////////
259
NS_NewListBoxObject(nsIBoxObject** aResult)
261
*aResult = new nsListBoxObject;
263
return NS_ERROR_OUT_OF_MEMORY;