2001-09-28 20:14:13 +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/. */
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
#include "nsBoxObject.h"
|
2006-11-06 16:08:20 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-05-30 07:59:13 +00:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2000-07-27 06:19:30 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIFrame.h"
|
2002-04-25 23:04:52 +00:00
|
|
|
#include "nsIDocShell.h"
|
2001-03-08 08:05:05 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2011-10-03 19:11:31 +00:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-01-03 13:23:11 +00:00
|
|
|
#include "nsView.h"
|
2008-01-16 01:27:53 +00:00
|
|
|
#ifdef MOZ_XUL
|
2001-04-30 18:30:18 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2008-01-16 01:27:53 +00:00
|
|
|
#else
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#endif
|
2006-06-16 02:40:29 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-11-06 16:08:20 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-09-06 17:50:24 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2010-04-30 13:12:05 +00:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Static member variable initialization
|
|
|
|
|
|
|
|
// Implement our nsISupports methods
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2009-08-21 12:50:15 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsBoxObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBoxObject)
|
|
|
|
|
2010-01-12 13:08:43 +00:00
|
|
|
DOMCI_DATA(BoxObject, nsBoxObject)
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
// QueryInterface implementation for nsBoxObject
|
2009-08-21 12:50:15 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsBoxObject)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2009-02-17 14:08:08 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(BoxObject)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2012-10-08 16:15:12 +00:00
|
|
|
static PLDHashOperator
|
2009-08-21 12:51:08 +00:00
|
|
|
PropertyTraverser(const nsAString& aKey, nsISupports* aProperty, void* userArg)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback *cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*>(userArg);
|
|
|
|
|
|
|
|
cb->NoteXPCOMChild(aProperty);
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 17:42:36 +00:00
|
|
|
|
2009-08-21 12:51:08 +00:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2013-08-02 01:29:05 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsBoxObject)
|
|
|
|
|
2009-08-21 12:51:08 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsBoxObject)
|
2009-08-21 12:50:15 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBoxObject)
|
2009-08-21 12:51:08 +00:00
|
|
|
if (tmp->mPropertyTable) {
|
|
|
|
tmp->mPropertyTable->EnumerateRead(PropertyTraverser, &cb);
|
|
|
|
}
|
2009-08-21 12:50:15 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
// Constructors/Destructors
|
|
|
|
nsBoxObject::nsBoxObject(void)
|
2012-07-30 14:20:58 +00:00
|
|
|
:mContent(nullptr)
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsBoxObject::~nsBoxObject(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-16 03:01:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetElement(nsIDOMElement** aResult)
|
|
|
|
{
|
2006-03-07 03:20:39 +00:00
|
|
|
if (mContent) {
|
|
|
|
return CallQueryInterface(mContent, aResult);
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2002-01-16 03:01:28 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
// nsPIBoxObject //////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-11-06 16:08:20 +00:00
|
|
|
nsresult
|
2006-03-07 03:20:39 +00:00
|
|
|
nsBoxObject::Init(nsIContent* aContent)
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
|
|
|
mContent = aContent;
|
2006-11-06 16:08:20 +00:00
|
|
|
return NS_OK;
|
2000-05-30 07:59:13 +00:00
|
|
|
}
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
void
|
|
|
|
nsBoxObject::Clear()
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
mPropertyTable = nullptr;
|
|
|
|
mContent = nullptr;
|
2002-04-22 23:48:14 +00:00
|
|
|
}
|
|
|
|
|
2006-07-13 09:02:05 +00:00
|
|
|
void
|
|
|
|
nsBoxObject::ClearCachedValues()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
nsIFrame*
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBoxObject::GetFrame(bool aFlushLayout)
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIPresShell* shell = GetPresShell(aFlushLayout);
|
2006-03-06 01:46:46 +00:00
|
|
|
if (!shell)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-08-22 22:24:29 +00:00
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
if (!aFlushLayout) {
|
|
|
|
// If we didn't flush layout when getting the presshell, we should at least
|
|
|
|
// flush to make sure our frame model is up to date.
|
|
|
|
// XXXbz should flush on document, no? Except people call this from
|
|
|
|
// frame code, maybe?
|
|
|
|
shell->FlushPendingNotifications(Flush_Frames);
|
|
|
|
}
|
|
|
|
|
2009-12-24 21:20:06 +00:00
|
|
|
// The flush might have killed mContent.
|
|
|
|
if (!mContent) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-12-24 21:20:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return mContent->GetPrimaryFrame();
|
2006-03-06 01:46:46 +00:00
|
|
|
}
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIPresShell*
|
2011-09-29 06:19:26 +00:00
|
|
|
nsBoxObject::GetPresShell(bool aFlushLayout)
|
2006-03-06 01:46:46 +00:00
|
|
|
{
|
2006-03-07 03:20:39 +00:00
|
|
|
if (!mContent) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-03-06 01:46:46 +00:00
|
|
|
}
|
2006-03-07 03:20:39 +00:00
|
|
|
|
2013-03-21 22:00:04 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetCurrentDoc();
|
2006-03-07 03:20:39 +00:00
|
|
|
if (!doc) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2006-03-07 03:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlushLayout) {
|
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2010-06-25 13:59:57 +00:00
|
|
|
return doc->GetShell();
|
2000-05-30 07:59:13 +00:00
|
|
|
}
|
|
|
|
|
2000-07-27 06:19:30 +00:00
|
|
|
nsresult
|
2009-01-15 03:27:09 +00:00
|
|
|
nsBoxObject::GetOffsetRect(nsIntRect& aRect)
|
2000-07-27 06:19:30 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
aRect.SetRect(0, 0, 0, 0);
|
2000-07-27 06:19:30 +00:00
|
|
|
|
2003-09-24 01:47:46 +00:00
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
// Get the Frame for our content
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(true);
|
2006-03-07 03:20:39 +00:00
|
|
|
if (frame) {
|
|
|
|
// Get its origin
|
2006-06-16 02:40:29 +00:00
|
|
|
nsPoint origin = frame->GetPositionIgnoringScrolling();
|
2006-03-07 03:20:39 +00:00
|
|
|
|
|
|
|
// Find the frame parent whose content is the document element.
|
2010-04-30 13:12:05 +00:00
|
|
|
Element *docElement = mContent->GetCurrentDoc()->GetRootElement();
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
2006-06-16 02:40:29 +00:00
|
|
|
for (;;) {
|
2006-03-07 03:20:39 +00:00
|
|
|
// If we've hit the document element, break here
|
|
|
|
if (parent->GetContent() == docElement) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-16 02:40:29 +00:00
|
|
|
nsIFrame* next = parent->GetParent();
|
|
|
|
if (!next) {
|
|
|
|
NS_WARNING("We should have hit the document element...");
|
|
|
|
origin += parent->GetPosition();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
// Add the parent's origin to our own to get to the
|
|
|
|
// right coordinate system
|
2006-06-16 02:40:29 +00:00
|
|
|
origin += next->GetPositionOfChildIgnoringScrolling(parent);
|
|
|
|
parent = next;
|
2006-03-07 03:20:39 +00:00
|
|
|
}
|
2000-07-27 06:19:30 +00:00
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
// For the origin, add in the border for the frame
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleBorder* border = frame->StyleBorder();
|
2012-05-31 05:19:49 +00:00
|
|
|
origin.x += border->GetComputedBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y += border->GetComputedBorderWidth(NS_SIDE_TOP);
|
2006-03-07 03:20:39 +00:00
|
|
|
|
|
|
|
// And subtract out the border for the parent
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleBorder* parentBorder = parent->StyleBorder();
|
2012-05-31 05:19:49 +00:00
|
|
|
origin.x -= parentBorder->GetComputedBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y -= parentBorder->GetComputedBorderWidth(NS_SIDE_TOP);
|
2006-03-07 03:20:39 +00:00
|
|
|
|
2007-02-07 07:46:44 +00:00
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y);
|
2008-02-27 09:26:15 +00:00
|
|
|
|
|
|
|
// Get the union of all rectangles in this and continuation frames.
|
|
|
|
// It doesn't really matter what we use as aRelativeTo here, since
|
|
|
|
// we only care about the size. Using 'parent' might make things
|
|
|
|
// a bit faster by speeding up the internal GetOffsetTo operations.
|
|
|
|
nsRect rcFrame = nsLayoutUtils::GetAllInFlowRectsUnion(frame, parent);
|
2007-02-07 07:46:44 +00:00
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.width);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.height);
|
2000-07-27 06:19:30 +00:00
|
|
|
}
|
2008-02-27 09:26:15 +00:00
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
return NS_OK;
|
2001-04-30 18:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-11-23 17:26:19 +00:00
|
|
|
nsBoxObject::GetScreenPosition(nsIntPoint& aPoint)
|
2001-04-30 18:30:18 +00:00
|
|
|
{
|
2004-11-23 17:26:19 +00:00
|
|
|
aPoint.x = aPoint.y = 0;
|
|
|
|
|
2003-09-24 01:47:46 +00:00
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(true);
|
2006-03-07 03:20:39 +00:00
|
|
|
if (frame) {
|
|
|
|
nsIntRect rect = frame->GetScreenRect();
|
|
|
|
aPoint.x = rect.x;
|
|
|
|
aPoint.y = rect.y;
|
2001-04-30 18:30:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetX(int32_t* aResult)
|
2000-07-27 06:19:30 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntRect rect;
|
2000-07-27 06:19:30 +00:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetY(int32_t* aResult)
|
2000-07-27 06:19:30 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntRect rect;
|
2000-07-27 06:19:30 +00:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.y;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetWidth(int32_t* aResult)
|
2000-07-27 06:19:30 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntRect rect;
|
2000-07-27 06:19:30 +00:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetHeight(int32_t* aResult)
|
2000-07-27 06:19:30 +00:00
|
|
|
{
|
2009-01-15 03:27:09 +00:00
|
|
|
nsIntRect rect;
|
2000-07-27 06:19:30 +00:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-30 18:30:18 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetScreenX(int32_t *_retval)
|
2001-04-30 18:30:18 +00:00
|
|
|
{
|
2004-11-23 17:26:19 +00:00
|
|
|
nsIntPoint position;
|
|
|
|
nsresult rv = GetScreenPosition(position);
|
2001-04-30 18:30:18 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2004-11-23 17:26:19 +00:00
|
|
|
*_retval = position.x;
|
2001-04-30 18:30:18 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsBoxObject::GetScreenY(int32_t *_retval)
|
2001-04-30 18:30:18 +00:00
|
|
|
{
|
2004-11-23 17:26:19 +00:00
|
|
|
nsIntPoint position;
|
|
|
|
nsresult rv = GetScreenPosition(position);
|
2001-04-30 18:30:18 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2004-11-23 17:26:19 +00:00
|
|
|
*_retval = position.y;
|
2001-04-30 18:30:18 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-02 23:23:55 +00:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsBoxObject::GetPropertyAsSupports(const char16_t* aPropertyName, nsISupports** aResult)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2006-07-29 10:23:42 +00:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 16:08:20 +00:00
|
|
|
if (!mPropertyTable) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2000-10-02 23:23:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-11-23 01:09:19 +00:00
|
|
|
mPropertyTable->Get(propertyName, aResult); // Addref here.
|
|
|
|
return NS_OK;
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsBoxObject::SetPropertyAsSupports(const char16_t* aPropertyName, nsISupports* aValue)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2006-02-21 01:18:36 +00:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-01-30 21:29:10 +00:00
|
|
|
|
2006-11-06 16:08:20 +00:00
|
|
|
if (!mPropertyTable) {
|
2013-09-02 08:41:57 +00:00
|
|
|
mPropertyTable = new nsInterfaceHashtable<nsStringHashKey,nsISupports>(8);
|
2006-02-21 01:18:36 +00:00
|
|
|
}
|
2000-10-02 23:23:55 +00:00
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2012-05-18 17:30:49 +00:00
|
|
|
mPropertyTable->Put(propertyName, aValue);
|
2006-11-23 01:09:19 +00:00
|
|
|
return NS_OK;
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsBoxObject::GetProperty(const char16_t* aPropertyName, char16_t** aResult)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2006-11-06 16:08:20 +00:00
|
|
|
nsCOMPtr<nsISupports> data;
|
2006-11-23 01:09:19 +00:00
|
|
|
nsresult rv = GetPropertyAsSupports(aPropertyName,getter_AddRefs(data));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!data) {
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2000-10-02 23:23:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-06 16:08:20 +00:00
|
|
|
nsCOMPtr<nsISupportsString> supportsStr = do_QueryInterface(data);
|
|
|
|
if (!supportsStr)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-12-12 19:25:22 +00:00
|
|
|
|
|
|
|
return supportsStr->ToString(aResult);
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsBoxObject::SetProperty(const char16_t* aPropertyName, const char16_t* aPropertyValue)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2006-07-28 06:28:27 +00:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 16:08:20 +00:00
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-07-28 06:28:27 +00:00
|
|
|
nsDependentString propertyValue;
|
|
|
|
if (aPropertyValue) {
|
|
|
|
propertyValue.Rebind(aPropertyValue);
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
propertyValue.SetIsVoid(true);
|
2006-07-28 06:28:27 +00:00
|
|
|
}
|
2006-11-06 16:08:20 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> supportsStr(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(supportsStr, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
supportsStr->SetData(propertyValue);
|
|
|
|
|
|
|
|
return SetPropertyAsSupports(aPropertyName,supportsStr);
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 15:02:17 +00:00
|
|
|
nsBoxObject::RemoveProperty(const char16_t* aPropertyName)
|
2000-10-02 23:23:55 +00:00
|
|
|
{
|
2006-07-29 10:23:42 +00:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 16:08:20 +00:00
|
|
|
|
|
|
|
if (!mPropertyTable) return NS_OK;
|
2000-10-02 23:23:55 +00:00
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-11-06 16:08:20 +00:00
|
|
|
mPropertyTable->Remove(propertyName);
|
|
|
|
return NS_OK;
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
2001-09-25 22:17:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetParentBox(nsIDOMElement * *aParentBox)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aParentBox = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!parent) return NS_OK;
|
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(parent->GetContent());
|
2001-09-25 22:17:00 +00:00
|
|
|
*aParentBox = el;
|
|
|
|
NS_IF_ADDREF(*aParentBox);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetFirstChild(nsIDOMElement * *aFirstVisibleChild)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aFirstVisibleChild = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2005-02-18 09:22:33 +00:00
|
|
|
if (!frame) return NS_OK;
|
2011-08-24 20:54:30 +00:00
|
|
|
nsIFrame* firstFrame = frame->GetFirstPrincipalChild();
|
2005-02-18 09:22:33 +00:00
|
|
|
if (!firstFrame) return NS_OK;
|
|
|
|
// get the content for the box and query to a dom element
|
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(firstFrame->GetContent());
|
|
|
|
el.swap(*aFirstVisibleChild);
|
2001-09-25 22:17:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetLastChild(nsIDOMElement * *aLastVisibleChild)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aLastVisibleChild = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2005-02-18 09:22:33 +00:00
|
|
|
if (!frame) return NS_OK;
|
2012-07-30 14:20:58 +00:00
|
|
|
return GetPreviousSibling(frame, nullptr, aLastVisibleChild);
|
2001-09-25 22:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetNextSibling(nsIDOMElement **aNextOrdinalSibling)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aNextOrdinalSibling = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIFrame* nextFrame = frame->GetNextSibling();
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!nextFrame) return NS_OK;
|
|
|
|
// get the content for the box and query to a dom element
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(nextFrame->GetContent());
|
2005-02-18 09:22:33 +00:00
|
|
|
el.swap(*aNextOrdinalSibling);
|
2001-09-25 22:17:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetPreviousSibling(nsIDOMElement **aPreviousOrdinalSibling)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aPreviousOrdinalSibling = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIFrame* parentFrame = frame->GetParent();
|
2001-09-25 22:17:00 +00:00
|
|
|
if (!parentFrame) return NS_OK;
|
2005-02-18 09:22:33 +00:00
|
|
|
return GetPreviousSibling(parentFrame, frame, aPreviousOrdinalSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsBoxObject::GetPreviousSibling(nsIFrame* aParentFrame, nsIFrame* aFrame,
|
|
|
|
nsIDOMElement** aResult)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2011-08-24 20:54:30 +00:00
|
|
|
nsIFrame* nextFrame = aParentFrame->GetFirstPrincipalChild();
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIFrame* prevFrame = nullptr;
|
2001-09-25 22:17:00 +00:00
|
|
|
while (nextFrame) {
|
2005-02-18 09:22:33 +00:00
|
|
|
if (nextFrame == aFrame)
|
2001-09-25 22:17:00 +00:00
|
|
|
break;
|
|
|
|
prevFrame = nextFrame;
|
2003-08-04 12:39:51 +00:00
|
|
|
nextFrame = nextFrame->GetNextSibling();
|
2001-09-25 22:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!prevFrame) return NS_OK;
|
|
|
|
// get the content for the box and query to a dom element
|
2003-08-04 12:39:51 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(prevFrame->GetContent());
|
2005-02-18 09:22:33 +00:00
|
|
|
el.swap(*aResult);
|
2001-09-25 22:17:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsBoxObject;
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-09-25 22:17:00 +00:00
|
|
|
|