2002-01-12 01:18:10 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2002-01-12 01:18:10 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
#include "mozilla/dom/ListBoxObject.h"
|
2002-01-12 01:18:10 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIFrame.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2005-04-03 21:02:47 +00:00
|
|
|
#include "nsIScrollableFrame.h"
|
2008-08-24 15:14:09 +00:00
|
|
|
#include "nsListBoxBodyFrame.h"
|
2013-05-01 22:50:08 +00:00
|
|
|
#include "ChildIterator.h"
|
2014-10-14 20:15:21 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/ListBoxObjectBinding.h"
|
2002-01-12 01:18:10 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2014-07-08 21:23:18 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(ListBoxObject, BoxObject, nsIListBoxObject,
|
2014-04-27 07:06:00 +00:00
|
|
|
nsPIListBoxObject)
|
2002-01-12 01:18:10 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::ListBoxObject()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mListBoxBody(nullptr)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::~ListBoxObject()
|
|
|
|
{
|
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
JSObject* ListBoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-14 20:15:21 +00:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 14:13:33 +00:00
|
|
|
return ListBoxObjectBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIListBoxObject
|
2002-01-12 01:18:10 +00:00
|
|
|
NS_IMETHODIMP
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::GetRowCount(int32_t *aResult)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
*aResult = GetRowCount();
|
2002-01-12 01:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::GetItemAtIndex(int32_t index, nsIDOMElement **_retval)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
return body->GetItemAtIndex(index, _retval);
|
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
return NS_OK;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::GetIndexOfItem(nsIDOMElement* aElement, int32_t *aResult)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
*aResult = 0;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
return body->GetIndexOfItem(aElement, aResult);
|
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
// ListBoxObject
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
ListBoxObject::GetRowCount()
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
return body->GetRowCount();
|
|
|
|
}
|
|
|
|
return 0;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 21:12:21 +00:00
|
|
|
int32_t
|
|
|
|
ListBoxObject::GetRowHeight()
|
|
|
|
{
|
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
|
|
|
if (body) {
|
|
|
|
return body->GetRowHeightPixels();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
int32_t
|
|
|
|
ListBoxObject::GetNumberOfVisibleRows()
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
return body->GetNumberOfVisibleRows();
|
|
|
|
}
|
|
|
|
return 0;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
int32_t
|
|
|
|
ListBoxObject::GetIndexOfFirstVisibleRow()
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
return body->GetIndexOfFirstVisibleRow();
|
|
|
|
}
|
|
|
|
return 0;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
ListBoxObject::EnsureIndexIsVisible(int32_t aRowIndex)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
body->EnsureIndexIsVisible(aRowIndex);
|
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
ListBoxObject::ScrollToIndex(int32_t aRowIndex)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
|
|
|
if (body) {
|
|
|
|
body->ScrollToIndex(aRowIndex);
|
|
|
|
}
|
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
void
|
|
|
|
ListBoxObject::ScrollByLines(int32_t aNumLines)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
nsListBoxBodyFrame* body = GetListBoxBody(true);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (body) {
|
|
|
|
body->ScrollByLines(aNumLines);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
ListBoxObject::GetItemAtIndex(int32_t index)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetItemAtIndex(index, getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
ListBoxObject::GetIndexOfItem(Element& aElement)
|
|
|
|
{
|
|
|
|
int32_t ret;
|
|
|
|
nsCOMPtr<nsIDOMElement> el(do_QueryInterface(&aElement));
|
|
|
|
GetIndexOfItem(el, &ret);
|
|
|
|
return ret;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
|
2013-05-01 22:50:08 +00:00
|
|
|
static nsIContent*
|
|
|
|
FindBodyContent(nsIContent* aParent)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2015-03-03 11:09:00 +00:00
|
|
|
if (aParent->IsXULElement(nsGkAtoms::listboxbody)) {
|
2013-05-01 22:50:08 +00:00
|
|
|
return aParent;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
mozilla::dom::FlattenedChildIterator iter(aParent);
|
|
|
|
for (nsIContent* child = iter.GetNextChild(); child; child = iter.GetNextChild()) {
|
|
|
|
nsIContent* result = FindBodyContent(child);
|
|
|
|
if (result) {
|
|
|
|
return result;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-01 22:50:08 +00:00
|
|
|
|
|
|
|
return nullptr;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2008-10-28 04:47:19 +00:00
|
|
|
nsListBoxBodyFrame*
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::GetListBoxBody(bool aFlush)
|
2002-01-12 01:18:10 +00:00
|
|
|
{
|
2006-01-30 21:29:10 +00:00
|
|
|
if (mListBoxBody) {
|
|
|
|
return mListBoxBody;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIPresShell* shell = GetPresShell(false);
|
2006-03-06 01:46:46 +00:00
|
|
|
if (!shell) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-03-06 01:46:46 +00:00
|
|
|
}
|
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
nsIFrame* frame = aFlush ?
|
2017-01-05 07:31:56 +00:00
|
|
|
GetFrame(false) /* does FlushType::Frames */ :
|
2009-12-24 21:20:06 +00:00
|
|
|
mContent->GetPrimaryFrame();
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!frame) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2007-10-06 15:03:35 +00:00
|
|
|
|
2002-01-12 01:18:10 +00:00
|
|
|
// Iterate over our content model children looking for the body.
|
2013-05-01 22:50:08 +00:00
|
|
|
nsCOMPtr<nsIContent> content = FindBodyContent(frame->GetContent());
|
2002-01-12 01:18:10 +00:00
|
|
|
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!content) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2009-12-28 19:47:27 +00:00
|
|
|
|
2002-01-12 01:18:10 +00:00
|
|
|
// this frame will be a nsGFXScrollFrame
|
2009-12-24 21:20:06 +00:00
|
|
|
frame = content->GetPrimaryFrame();
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!frame) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollableFrame* scrollFrame = do_QueryFrame(frame);
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!scrollFrame) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
|
|
|
|
// this frame will be the one we want
|
2005-04-03 21:02:47 +00:00
|
|
|
nsIFrame* yeahBaby = scrollFrame->GetScrolledFrame();
|
2014-10-14 20:15:21 +00:00
|
|
|
if (!yeahBaby) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2014-10-14 20:15:21 +00:00
|
|
|
}
|
2002-01-12 01:18:10 +00:00
|
|
|
|
|
|
|
// It's a frame. Refcounts are irrelevant.
|
2009-01-12 19:20:59 +00:00
|
|
|
nsListBoxBodyFrame* listBoxBody = do_QueryFrame(yeahBaby);
|
2008-08-24 15:14:09 +00:00
|
|
|
NS_ENSURE_TRUE(listBoxBody &&
|
2008-10-28 04:47:19 +00:00
|
|
|
listBoxBody->SetBoxObject(this),
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
2008-08-24 15:14:09 +00:00
|
|
|
mListBoxBody = listBoxBody;
|
2006-01-30 21:29:10 +00:00
|
|
|
return mListBoxBody;
|
2002-01-12 01:18:10 +00:00
|
|
|
}
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
void
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::Clear()
|
2002-04-22 23:48:14 +00:00
|
|
|
{
|
2006-07-13 09:02:05 +00:00
|
|
|
ClearCachedValues();
|
2014-10-14 20:15:21 +00:00
|
|
|
BoxObject::Clear();
|
2002-04-22 23:48:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 09:02:05 +00:00
|
|
|
void
|
2014-10-14 20:15:21 +00:00
|
|
|
ListBoxObject::ClearCachedValues()
|
2006-07-13 09:02:05 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mListBoxBody = nullptr;
|
2006-07-13 09:02:05 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2014-10-14 20:15:21 +00:00
|
|
|
|
2002-01-12 01:18:10 +00:00
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewListBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
2014-10-14 20:15:21 +00:00
|
|
|
NS_ADDREF(*aResult = new mozilla::dom::ListBoxObject());
|
2002-01-12 01:18:10 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|