2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2004-04-18 14:30:37 +00:00
|
|
|
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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 "nsIDocument.h"
|
|
|
|
#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"
|
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
|
|
|
#include "nsIDOMClassInfo.h"
|
2001-04-30 18:30:18 +00:00
|
|
|
#include "nsIView.h"
|
2001-07-16 02:40:48 +00:00
|
|
|
#include "nsIWidget.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
|
2004-09-28 18:37:50 +00:00
|
|
|
#include "nsIFrame.h"
|
2006-06-16 02:40:29 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-11-06 16:08:20 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
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
|
|
|
|
|
|
|
// QueryInterface implementation for nsBoxObject
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(BoxObject)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsBoxObject)
|
|
|
|
NS_IMPL_RELEASE(nsBoxObject)
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
// Constructors/Destructors
|
|
|
|
nsBoxObject::nsBoxObject(void)
|
2006-03-07 03:20:39 +00:00
|
|
|
:mContent(nsnull)
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
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
|
|
|
{
|
2006-11-06 16:08:20 +00:00
|
|
|
mPropertyTable = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
mContent = nsnull;
|
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*
|
2006-03-07 03:20:39 +00:00
|
|
|
nsBoxObject::GetFrame(PRBool 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)
|
2005-08-22 22:24:29 +00:00
|
|
|
return nsnull;
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-03-06 01:46:46 +00:00
|
|
|
return shell->GetPrimaryFrameFor(mContent);
|
|
|
|
}
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIPresShell*
|
|
|
|
nsBoxObject::GetPresShell(PRBool aFlushLayout)
|
2006-03-06 01:46:46 +00:00
|
|
|
{
|
2006-03-07 03:20:39 +00:00
|
|
|
if (!mContent) {
|
2006-03-06 01:46:46 +00:00
|
|
|
return nsnull;
|
|
|
|
}
|
2006-03-07 03:20:39 +00:00
|
|
|
|
|
|
|
nsIDocument* doc = mContent->GetCurrentDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlushLayout) {
|
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2007-05-01 22:24:20 +00:00
|
|
|
return doc->GetPrimaryShell();
|
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
|
|
|
|
nsIFrame* frame = GetFrame(PR_TRUE);
|
|
|
|
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.
|
|
|
|
nsIContent *docElement = mContent->GetCurrentDoc()->GetRootContent();
|
|
|
|
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
|
|
|
|
const nsStyleBorder* border = frame->GetStyleBorder();
|
2008-07-17 06:30:25 +00:00
|
|
|
origin.x += border->GetActualBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y += border->GetActualBorderWidth(NS_SIDE_TOP);
|
2006-03-07 03:20:39 +00:00
|
|
|
|
|
|
|
// And subtract out the border for the parent
|
2006-09-22 07:27:49 +00:00
|
|
|
const nsStyleBorder* parentBorder = parent->GetStyleBorder();
|
2008-07-17 06:30:25 +00:00
|
|
|
origin.x -= parentBorder->GetActualBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y -= parentBorder->GetActualBorderWidth(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;
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_TRUE);
|
|
|
|
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
|
|
|
|
nsBoxObject::GetX(PRInt32* aResult)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetY(PRInt32* aResult)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetWidth(PRInt32* aResult)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetHeight(PRInt32* aResult)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetScreenX(PRInt32 *_retval)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetScreenY(PRInt32 *_retval)
|
|
|
|
{
|
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
|
|
|
|
nsBoxObject::GetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports** aResult)
|
|
|
|
{
|
2006-07-29 10:23:42 +00:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 16:08:20 +00:00
|
|
|
if (!mPropertyTable) {
|
2000-10-02 23:23:55 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
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
|
|
|
|
nsBoxObject::SetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports* aValue)
|
|
|
|
{
|
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) {
|
|
|
|
mPropertyTable = new nsInterfaceHashtable<nsStringHashKey,nsISupports>;
|
|
|
|
if (!mPropertyTable) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
if (NS_FAILED(mPropertyTable->Init(8))) {
|
|
|
|
mPropertyTable = nsnull;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
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);
|
2006-11-23 01:09:19 +00:00
|
|
|
if (!mPropertyTable->Put(propertyName, aValue))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return NS_OK;
|
2000-10-02 23:23:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetProperty(const PRUnichar* aPropertyName, PRUnichar** aResult)
|
|
|
|
{
|
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) {
|
2000-10-02 23:23:55 +00:00
|
|
|
*aResult = nsnull;
|
|
|
|
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
|
|
|
|
nsBoxObject::SetProperty(const PRUnichar* aPropertyName, const PRUnichar* aPropertyValue)
|
|
|
|
{
|
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 {
|
|
|
|
propertyValue.SetIsVoid(PR_TRUE);
|
|
|
|
}
|
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
|
|
|
|
nsBoxObject::RemoveProperty(const PRUnichar* aPropertyName)
|
|
|
|
{
|
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)
|
|
|
|
{
|
2006-07-29 10:23:42 +00:00
|
|
|
*aParentBox = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_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)
|
|
|
|
{
|
2005-02-18 09:22:33 +00:00
|
|
|
*aFirstVisibleChild = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
2005-02-18 09:22:33 +00:00
|
|
|
if (!frame) return NS_OK;
|
|
|
|
nsIFrame* firstFrame = frame->GetFirstChild(nsnull);
|
|
|
|
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)
|
|
|
|
{
|
2005-02-18 09:22:33 +00:00
|
|
|
*aLastVisibleChild = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
2005-02-18 09:22:33 +00:00
|
|
|
if (!frame) return NS_OK;
|
|
|
|
return GetPreviousSibling(frame, nsnull, aLastVisibleChild);
|
2001-09-25 22:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetNextSibling(nsIDOMElement **aNextOrdinalSibling)
|
|
|
|
{
|
2005-02-18 09:22:33 +00:00
|
|
|
*aNextOrdinalSibling = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_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)
|
|
|
|
{
|
2005-02-18 09:22:33 +00:00
|
|
|
*aPreviousOrdinalSibling = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_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)
|
|
|
|
{
|
2006-07-29 10:23:42 +00:00
|
|
|
*aResult = nsnull;
|
2005-02-18 09:22:33 +00:00
|
|
|
nsIFrame* nextFrame = aParentFrame->GetFirstChild(nsnull);
|
2001-09-25 22:17:00 +00:00
|
|
|
nsIFrame* prevFrame = nsnull;
|
|
|
|
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
|
|
|
|