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"
|
|
|
|
#include "nsIBoxLayoutManager.h"
|
|
|
|
#include "nsIBoxPaintManager.h"
|
|
|
|
#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 "nsIFrameFrame.h"
|
|
|
|
#include "nsIDocShell.h"
|
2001-03-08 08:05:05 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2000-12-01 01:45:37 +00:00
|
|
|
#include "nsILookAndFeel.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIServiceManager.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"
|
2001-04-30 18:30:18 +00:00
|
|
|
#include "nsIDOMXULElement.h"
|
2004-09-28 18:37:50 +00:00
|
|
|
#include "nsIFrame.h"
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
// Static IIDs/CIDs. Try to minimize these.
|
2000-12-01 01:45:37 +00:00
|
|
|
static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
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)
|
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
|
|
|
:mContent(nsnull), mPresShell(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)
|
|
|
|
{
|
|
|
|
if (mContent)
|
|
|
|
mContent->QueryInterface(NS_GET_IID(nsIDOMElement), (void**)aResult);
|
|
|
|
else
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetLayoutManager(nsIBoxLayoutManager** aResult)
|
|
|
|
{
|
|
|
|
*aResult = mLayoutManager;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::SetLayoutManager(nsIBoxLayoutManager* aLayoutManager)
|
|
|
|
{
|
|
|
|
mLayoutManager = aLayoutManager;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetPaintManager(nsIBoxPaintManager** aResult)
|
|
|
|
{
|
|
|
|
*aResult = mPaintManager;
|
|
|
|
NS_IF_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::SetPaintManager(nsIBoxPaintManager* aPaintManager)
|
|
|
|
{
|
|
|
|
mPaintManager = aPaintManager;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsPIBoxObject //////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::Init(nsIContent* aContent, nsIPresShell* aShell)
|
|
|
|
{
|
|
|
|
mContent = aContent;
|
|
|
|
mPresShell = aShell;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::SetDocument(nsIDocument* aDocument)
|
|
|
|
{
|
2000-10-02 23:23:55 +00:00
|
|
|
mPresState = nsnull;
|
2000-05-30 07:59:13 +00:00
|
|
|
if (aDocument) {
|
2003-09-27 04:18:26 +00:00
|
|
|
mPresShell = aDocument->GetShellAt(0);
|
2000-05-30 07:59:13 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mPresShell = nsnull;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::InvalidatePresentationStuff()
|
|
|
|
{
|
2002-04-25 18:18:12 +00:00
|
|
|
mPresShell = nsnull;
|
2002-04-22 23:48:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsBoxObject::GetFrame()
|
|
|
|
{
|
2005-08-22 22:24:29 +00:00
|
|
|
if (!mPresShell)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
mPresShell->FlushPendingNotifications(Flush_Frames);
|
|
|
|
return mPresShell->GetPrimaryFrameFor(mContent);
|
2000-05-30 07:59:13 +00:00
|
|
|
}
|
|
|
|
|
2000-07-27 06:19:30 +00:00
|
|
|
nsresult
|
|
|
|
nsBoxObject::GetOffsetRect(nsRect& aRect)
|
|
|
|
{
|
|
|
|
aRect.x = aRect.y = 0;
|
|
|
|
aRect.Empty();
|
|
|
|
|
2003-09-24 01:47:46 +00:00
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsresult res = NS_OK;
|
2003-07-28 21:25:13 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
// Get Presentation shell 0
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *presShell = doc->GetShellAt(0);
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
if(presShell) {
|
|
|
|
// Flush all pending notifications so that our frames are uptodate
|
2004-05-27 22:08:42 +00:00
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
// Get the Frame for our content
|
2005-08-22 22:24:29 +00:00
|
|
|
nsIFrame* frame = presShell->GetPrimaryFrameFor(mContent);
|
|
|
|
if(frame) {
|
2000-07-27 06:19:30 +00:00
|
|
|
// Get its origin
|
2003-08-04 12:39:51 +00:00
|
|
|
nsPoint origin = frame->GetPosition();
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
// Get the union of all rectangles in this and continuation frames
|
|
|
|
nsRect rcFrame;
|
|
|
|
nsIFrame* next = frame;
|
|
|
|
do {
|
2003-08-04 12:39:51 +00:00
|
|
|
rcFrame.UnionRect(rcFrame, next->GetRect());
|
2004-09-14 02:28:03 +00:00
|
|
|
next = next->GetNextInFlow();
|
2000-07-27 06:19:30 +00:00
|
|
|
} while (nsnull != next);
|
|
|
|
|
|
|
|
|
|
|
|
// Find the frame parent whose content's tagName either matches
|
|
|
|
// the tagName passed in or is the document element.
|
2003-10-22 06:09:48 +00:00
|
|
|
nsIContent *docElement = doc->GetRootContent();
|
2003-08-04 12:39:51 +00:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
2000-07-27 06:19:30 +00:00
|
|
|
while (parent) {
|
2003-08-04 12:39:51 +00:00
|
|
|
// If we've hit the document element, break here
|
2003-10-22 06:09:48 +00:00
|
|
|
if (parent->GetContent() == docElement) {
|
2003-08-04 12:39:51 +00:00
|
|
|
break;
|
2000-07-27 06:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add the parent's origin to our own to get to the
|
|
|
|
// right coordinate system
|
2003-08-04 12:39:51 +00:00
|
|
|
origin += parent->GetPosition();
|
2000-07-27 06:19:30 +00:00
|
|
|
|
2003-08-04 12:39:51 +00:00
|
|
|
parent = parent->GetParent();
|
2000-07-27 06:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// For the origin, add in the border for the frame
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* border = frame->GetStyleBorder();
|
2005-04-29 15:44:38 +00:00
|
|
|
origin.x += border->GetBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y += border->GetBorderWidth(NS_SIDE_TOP);
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
// And subtract out the border for the parent
|
|
|
|
if (parent) {
|
2003-05-15 03:42:21 +00:00
|
|
|
const nsStyleBorder* parentBorder = parent->GetStyleBorder();
|
2005-04-29 15:44:38 +00:00
|
|
|
origin.x -= parentBorder->GetBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y -= parentBorder->GetBorderWidth(NS_SIDE_TOP);
|
2000-07-27 06:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the Presentation Context from the Shell
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *context = presShell->GetPresContext();
|
|
|
|
if (context) {
|
2000-07-27 06:19:30 +00:00
|
|
|
// Get the scale from that Presentation Context
|
|
|
|
float scale;
|
2004-02-11 04:57:07 +00:00
|
|
|
scale = context->TwipsToPixels();
|
2000-07-27 06:19:30 +00:00
|
|
|
|
|
|
|
// Convert to pixels using that scale
|
|
|
|
aRect.x = NSTwipsToIntPixels(origin.x, scale);
|
|
|
|
aRect.y = NSTwipsToIntPixels(origin.y, scale);
|
|
|
|
aRect.width = NSTwipsToIntPixels(rcFrame.width, scale);
|
|
|
|
aRect.height = NSTwipsToIntPixels(rcFrame.height, scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
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;
|
|
|
|
|
2003-07-28 21:25:13 +00:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetDocument();
|
2001-04-30 18:30:18 +00:00
|
|
|
|
|
|
|
if (doc) {
|
|
|
|
// Get Presentation shell 0
|
2003-09-27 04:18:26 +00:00
|
|
|
nsIPresShell *presShell = doc->GetShellAt(0);
|
|
|
|
|
2001-04-30 18:30:18 +00:00
|
|
|
if (presShell) {
|
|
|
|
// Flush all pending notifications so that our frames are uptodate
|
2004-05-27 22:08:42 +00:00
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
2001-04-30 18:30:18 +00:00
|
|
|
|
2004-08-20 20:34:37 +00:00
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
2001-04-30 18:30:18 +00:00
|
|
|
if (presContext) {
|
2005-08-22 22:24:29 +00:00
|
|
|
nsIFrame* frame = presShell->GetPrimaryFrameFor(mContent);
|
2001-04-30 18:30:18 +00:00
|
|
|
|
2004-11-23 17:26:19 +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
|
|
|
|
nsBoxObject::GetX(PRInt32* aResult)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetY(PRInt32* aResult)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.y;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetWidth(PRInt32* aResult)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetHeight(PRInt32* aResult)
|
|
|
|
{
|
|
|
|
nsRect rect;
|
|
|
|
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-12-01 01:45:37 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetLookAndFeelMetric(const PRUnichar* aPropertyName,
|
|
|
|
PRUnichar** aResult)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILookAndFeel> lookAndFeel(do_GetService(kLookAndFeelCID));
|
|
|
|
if (!lookAndFeel)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsAutoString property(aPropertyName);
|
2004-06-17 00:13:25 +00:00
|
|
|
if (property.LowerCaseEqualsLiteral("scrollbarstyle")) {
|
2000-12-01 01:45:37 +00:00
|
|
|
PRInt32 metricResult;
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollArrowStyle, metricResult);
|
|
|
|
switch (metricResult) {
|
|
|
|
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtBottom:
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("doublebottom"));
|
2000-12-01 01:45:37 +00:00
|
|
|
break;
|
|
|
|
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtEachEnd:
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("double"));
|
2000-12-01 01:45:37 +00:00
|
|
|
break;
|
|
|
|
case nsILookAndFeel::eMetric_ScrollArrowStyleBothAtTop:
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("doubletop"));
|
2000-12-01 01:45:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("single"));
|
2000-12-01 01:45:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 00:13:25 +00:00
|
|
|
else if (property.LowerCaseEqualsLiteral("thumbstyle")) {
|
2000-12-01 01:45:37 +00:00
|
|
|
PRInt32 metricResult;
|
|
|
|
lookAndFeel->GetMetric(nsILookAndFeel::eMetric_ScrollSliderStyle, metricResult);
|
|
|
|
if ( metricResult == nsILookAndFeel::eMetric_ScrollThumbStyleNormal )
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("fixed"));
|
2000-12-01 01:45:37 +00:00
|
|
|
else
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(NS_LITERAL_STRING("proportional"));
|
2000-12-01 01:45:37 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-02 23:23:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports** aResult)
|
|
|
|
{
|
|
|
|
if (!mPresState) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2000-10-02 23:23:55 +00:00
|
|
|
return mPresState->GetStatePropertyAsSupports(propertyName, aResult); // Addref here.
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::SetPropertyAsSupports(const PRUnichar* aPropertyName, nsISupports* aValue)
|
|
|
|
{
|
|
|
|
if (!mPresState)
|
2005-01-27 22:52:53 +00:00
|
|
|
NS_NewPresState(getter_Transfers(mPresState));
|
2000-10-02 23:23:55 +00:00
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2000-10-02 23:23:55 +00:00
|
|
|
return mPresState->SetStatePropertyAsSupports(propertyName, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetProperty(const PRUnichar* aPropertyName, PRUnichar** aResult)
|
|
|
|
{
|
|
|
|
if (!mPresState) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2000-10-02 23:23:55 +00:00
|
|
|
nsAutoString result;
|
|
|
|
nsresult rv = mPresState->GetStateProperty(propertyName, result);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-03-08 08:05:05 +00:00
|
|
|
*aResult = ToNewUnicode(result);
|
2000-10-02 23:23:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::SetProperty(const PRUnichar* aPropertyName, const PRUnichar* aPropertyValue)
|
|
|
|
{
|
|
|
|
if (!mPresState)
|
2005-01-27 22:52:53 +00:00
|
|
|
NS_NewPresState(getter_Transfers(mPresState));
|
2000-10-02 23:23:55 +00:00
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
|
|
|
nsDependentString propertyValue(aPropertyValue);
|
2000-10-02 23:23:55 +00:00
|
|
|
return mPresState->SetStateProperty(propertyName, propertyValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::RemoveProperty(const PRUnichar* aPropertyName)
|
|
|
|
{
|
|
|
|
if (!mPresState)
|
|
|
|
return NS_OK;
|
|
|
|
|
2002-04-22 23:48:14 +00:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2000-10-02 23:23:55 +00:00
|
|
|
return mPresState->RemoveStateProperty(propertyName);
|
|
|
|
}
|
|
|
|
|
2001-09-25 22:17:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsBoxObject::GetParentBox(nsIDOMElement * *aParentBox)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
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;
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
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;
|
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
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;
|
2001-09-25 22:17:00 +00:00
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
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;
|
2001-09-25 22:17:00 +00:00
|
|
|
nsIFrame* frame = GetFrame();
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-04-25 23:04:52 +00:00
|
|
|
nsresult
|
|
|
|
nsBoxObject::GetDocShell(nsIDocShell** aResult)
|
|
|
|
{
|
|
|
|
*aResult = nsnull;
|
|
|
|
|
|
|
|
if (!mPresShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame *frame = GetFrame();
|
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
nsIFrameFrame *frame_frame = nsnull;
|
|
|
|
CallQueryInterface(frame, &frame_frame);
|
|
|
|
|
|
|
|
if (frame_frame) {
|
|
|
|
// Ok, the frame for mContent is a nsIFrameFrame, it knows how
|
|
|
|
// to reach the docshell, so ask it...
|
|
|
|
|
|
|
|
return frame_frame->GetDocShell(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No nsIFrameFrame available for mContent, try if there's a mapping
|
|
|
|
// between mContent's document to mContent's subdocument.
|
|
|
|
|
2004-08-02 04:52:55 +00:00
|
|
|
nsIDocument *sub_doc =
|
|
|
|
mPresShell->GetDocument()->GetSubDocumentFor(mContent);
|
2002-04-25 23:04:52 +00:00
|
|
|
|
|
|
|
if (!sub_doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-22 06:09:48 +00:00
|
|
|
nsCOMPtr<nsISupports> container = sub_doc->GetContainer();
|
2002-04-25 23:04:52 +00:00
|
|
|
|
|
|
|
if (!container) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(container, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|