2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsPIListBoxObject.h"
|
|
|
|
#include "nsBoxObject.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsBindingManager.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIScrollableFrame.h"
|
2008-08-24 08:14:09 -07:00
|
|
|
#include "nsListBoxBodyFrame.h"
|
2013-05-01 15:50:08 -07:00
|
|
|
#include "ChildIterator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsListBoxObject : public nsPIListBoxObject, public nsBoxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSILISTBOXOBJECT
|
|
|
|
|
|
|
|
// nsPIListBoxObject
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual nsListBoxBodyFrame* GetListBoxBody(bool aFlush) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsListBoxObject();
|
|
|
|
|
|
|
|
// nsPIBoxObject
|
2014-02-24 06:41:56 -08:00
|
|
|
virtual void Clear() MOZ_OVERRIDE;
|
|
|
|
virtual void ClearCachedValues() MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2008-10-27 21:47:19 -07:00
|
|
|
nsListBoxBodyFrame *mListBoxBody;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsListBoxObject, nsBoxObject, nsIListBoxObject,
|
|
|
|
nsPIListBoxObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsListBoxObject::nsListBoxObject()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mListBoxBody(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//// nsIListBoxObject
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::GetRowCount(int32_t *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->GetRowCount(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::GetNumberOfVisibleRows(int32_t *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->GetNumberOfVisibleRows(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::GetIndexOfFirstVisibleRow(int32_t *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->GetIndexOfFirstVisibleRow(aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHODIMP nsListBoxObject::EnsureIndexIsVisible(int32_t aRowIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->EnsureIndexIsVisible(aRowIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::ScrollToIndex(int32_t aRowIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->ScrollToIndex(aRowIndex);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::ScrollByLines(int32_t aNumLines)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->ScrollByLines(aNumLines);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::GetItemAtIndex(int32_t index, nsIDOMElement **_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->GetItemAtIndex(index, _retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsListBoxObject::GetIndexOfItem(nsIDOMElement* aElement, int32_t *aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aResult = 0;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (body)
|
|
|
|
return body->GetIndexOfItem(aElement, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
|
2013-05-01 15:50:08 -07:00
|
|
|
static nsIContent*
|
|
|
|
FindBodyContent(nsIContent* aParent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aParent->Tag() == nsGkAtoms::listboxbody) {
|
2013-05-01 15:50:08 -07:00
|
|
|
return aParent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
mozilla::dom::FlattenedChildIterator iter(aParent);
|
|
|
|
for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
|
|
|
|
nsIContent* result = FindBodyContent(child);
|
|
|
|
if (result) {
|
|
|
|
return result;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-05-01 15:50:08 -07:00
|
|
|
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-10-27 21:47:19 -07:00
|
|
|
nsListBoxBodyFrame*
|
2011-09-28 23:19:26 -07:00
|
|
|
nsListBoxObject::GetListBoxBody(bool aFlush)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mListBoxBody) {
|
|
|
|
return mListBoxBody;
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsIPresShell* shell = GetPresShell(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!shell) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-10-06 08:03:35 -07:00
|
|
|
nsIFrame* frame = aFlush ?
|
2011-10-17 07:59:28 -07:00
|
|
|
GetFrame(false) /* does Flush_Frames */ :
|
2009-12-24 13:20:06 -08:00
|
|
|
mContent->GetPrimaryFrame();
|
2007-10-06 08:03:35 -07:00
|
|
|
if (!frame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-10-06 08:03:35 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Iterate over our content model children looking for the body.
|
2013-05-01 15:50:08 -07:00
|
|
|
nsCOMPtr<nsIContent> content = FindBodyContent(frame->GetContent());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-28 11:47:27 -08:00
|
|
|
if (!content)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-12-28 11:47:27 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// this frame will be a nsGFXScrollFrame
|
2009-12-24 13:20:06 -08:00
|
|
|
frame = content->GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!frame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-01-12 11:20:59 -08:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(frame);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!scrollFrame)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// this frame will be the one we want
|
|
|
|
nsIFrame* yeahBaby = scrollFrame->GetScrolledFrame();
|
|
|
|
if (!yeahBaby)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// It's a frame. Refcounts are irrelevant.
|
2009-01-12 11:20:59 -08:00
|
|
|
nsListBoxBodyFrame* listBoxBody = do_QueryFrame(yeahBaby);
|
2008-08-24 08:14:09 -07:00
|
|
|
NS_ENSURE_TRUE(listBoxBody &&
|
2008-10-27 21:47:19 -07:00
|
|
|
listBoxBody->SetBoxObject(this),
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr);
|
2008-08-24 08:14:09 -07:00
|
|
|
mListBoxBody = listBoxBody;
|
2007-03-22 10:30:00 -07:00
|
|
|
return mListBoxBody;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListBoxObject::Clear()
|
|
|
|
{
|
|
|
|
ClearCachedValues();
|
|
|
|
|
|
|
|
nsBoxObject::Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsListBoxObject::ClearCachedValues()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mListBoxBody = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewListBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsListBoxObject;
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|