2015-10-21 07:00:35 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04: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 11:59:13 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/BoxObject.h"
|
2006-11-06 19:08:20 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2000-05-30 11:59:13 +04:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIPresShell.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2000-07-27 10:19:30 +04:00
|
|
|
#include "nsIContent.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2002-04-26 03:04:52 +04:00
|
|
|
#include "nsIDocShell.h"
|
2001-03-08 11:05:05 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2011-10-03 23:11:31 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
#include "nsView.h"
|
2008-01-16 04:27:53 +03:00
|
|
|
#ifdef MOZ_XUL
|
2001-04-30 22:30:18 +04:00
|
|
|
#include "nsIDOMXULElement.h"
|
2008-01-16 04:27:53 +03:00
|
|
|
#else
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#endif
|
2006-06-16 06:40:29 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2006-11-06 19:08:20 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-09-06 21:50:24 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/BoxObjectBinding.h"
|
2000-05-30 11:59:13 +04:00
|
|
|
|
|
|
|
// Implementation /////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
// Static member variable initialization
|
|
|
|
|
|
|
|
// Implement our nsISupports methods
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(BoxObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(BoxObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(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 21:42:36 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
// QueryInterface implementation for BoxObject
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BoxObject)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
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 21:42:36 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIBoxObject)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(BoxObject)
|
|
|
|
// XXX jmorton: why aren't we unlinking mPropertyTable?
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(BoxObject)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2009-08-21 16:51:08 +04:00
|
|
|
if (tmp->mPropertyTable) {
|
2015-10-21 07:00:35 +03:00
|
|
|
for (auto iter = tmp->mPropertyTable->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
cb.NoteXPCOMChild(iter.UserData());
|
|
|
|
}
|
2009-08-21 16:51:08 +04:00
|
|
|
}
|
2009-08-21 16:50:15 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2000-05-30 11:59:13 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(BoxObject)
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
// Constructors/Destructors
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::BoxObject()
|
|
|
|
: mContent(nullptr)
|
2000-05-30 11:59:13 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::~BoxObject()
|
2000-05-30 11:59:13 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-01-16 06:01:28 +03:00
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetElement(nsIDOMElement** aResult)
|
2002-01-16 06:01:28 +03:00
|
|
|
{
|
2006-03-07 06:20:39 +03:00
|
|
|
if (mContent) {
|
|
|
|
return CallQueryInterface(mContent, aResult);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2002-01-16 06:01:28 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
// nsPIBoxObject //////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2006-11-06 19:08:20 +03:00
|
|
|
nsresult
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::Init(nsIContent* aContent)
|
2000-05-30 11:59:13 +04:00
|
|
|
{
|
|
|
|
mContent = aContent;
|
2006-11-06 19:08:20 +03:00
|
|
|
return NS_OK;
|
2000-05-30 11:59:13 +04:00
|
|
|
}
|
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
void
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::Clear()
|
2000-05-30 11:59:13 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mPropertyTable = nullptr;
|
|
|
|
mContent = nullptr;
|
2002-04-23 03:48:14 +04:00
|
|
|
}
|
|
|
|
|
2006-07-13 13:02:05 +04:00
|
|
|
void
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::ClearCachedValues()
|
2006-07-13 13:02:05 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
nsIFrame*
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetFrame(bool aFlushLayout)
|
2000-05-30 11:59:13 +04:00
|
|
|
{
|
2006-03-07 06:20:39 +03:00
|
|
|
nsIPresShell* shell = GetPresShell(aFlushLayout);
|
2006-03-06 04:46:46 +03:00
|
|
|
if (!shell)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-08-23 02:24:29 +04:00
|
|
|
|
2006-03-07 06:20:39 +03: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-25 00:20:06 +03:00
|
|
|
// The flush might have killed mContent.
|
|
|
|
if (!mContent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-12-25 00:20:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return mContent->GetPrimaryFrame();
|
2006-03-06 04:46:46 +03:00
|
|
|
}
|
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
nsIPresShell*
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetPresShell(bool aFlushLayout)
|
2006-03-06 04:46:46 +03:00
|
|
|
{
|
2006-03-07 06:20:39 +03:00
|
|
|
if (!mContent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-03-06 04:46:46 +03:00
|
|
|
}
|
2006-03-07 06:20:39 +03:00
|
|
|
|
2013-03-22 02:00:04 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = mContent->GetCurrentDoc();
|
2006-03-07 06:20:39 +03:00
|
|
|
if (!doc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2006-03-07 06:20:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aFlushLayout) {
|
|
|
|
doc->FlushPendingNotifications(Flush_Layout);
|
|
|
|
}
|
|
|
|
|
2010-06-25 17:59:57 +04:00
|
|
|
return doc->GetShell();
|
2000-05-30 11:59:13 +04:00
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
nsresult
|
|
|
|
BoxObject::GetOffsetRect(nsIntRect& aRect)
|
2000-07-27 10:19:30 +04:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
aRect.SetRect(0, 0, 0, 0);
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2003-09-24 05:47:46 +04:00
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
// Get the Frame for our content
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(true);
|
2006-03-07 06:20:39 +03:00
|
|
|
if (frame) {
|
|
|
|
// Get its origin
|
2006-06-16 06:40:29 +04:00
|
|
|
nsPoint origin = frame->GetPositionIgnoringScrolling();
|
2006-03-07 06:20:39 +03:00
|
|
|
|
|
|
|
// Find the frame parent whose content is the document element.
|
2014-08-06 03:23:54 +04:00
|
|
|
Element* docElement = mContent->GetComposedDoc()->GetRootElement();
|
2006-03-07 06:20:39 +03:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
2006-06-16 06:40:29 +04:00
|
|
|
for (;;) {
|
2006-03-07 06:20:39 +03:00
|
|
|
// If we've hit the document element, break here
|
|
|
|
if (parent->GetContent() == docElement) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-06-16 06:40:29 +04:00
|
|
|
nsIFrame* next = parent->GetParent();
|
|
|
|
if (!next) {
|
|
|
|
NS_WARNING("We should have hit the document element...");
|
|
|
|
origin += parent->GetPosition();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
// Add the parent's origin to our own to get to the
|
|
|
|
// right coordinate system
|
2006-06-16 06:40:29 +04:00
|
|
|
origin += next->GetPositionOfChildIgnoringScrolling(parent);
|
|
|
|
parent = next;
|
2006-03-07 06:20:39 +03:00
|
|
|
}
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
// For the origin, add in the border for the frame
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder* border = frame->StyleBorder();
|
2012-05-31 09:19:49 +04:00
|
|
|
origin.x += border->GetComputedBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y += border->GetComputedBorderWidth(NS_SIDE_TOP);
|
2006-03-07 06:20:39 +03:00
|
|
|
|
|
|
|
// And subtract out the border for the parent
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder* parentBorder = parent->StyleBorder();
|
2012-05-31 09:19:49 +04:00
|
|
|
origin.x -= parentBorder->GetComputedBorderWidth(NS_SIDE_LEFT);
|
|
|
|
origin.y -= parentBorder->GetComputedBorderWidth(NS_SIDE_TOP);
|
2006-03-07 06:20:39 +03:00
|
|
|
|
2007-02-07 10:46:44 +03:00
|
|
|
aRect.x = nsPresContext::AppUnitsToIntCSSPixels(origin.x);
|
|
|
|
aRect.y = nsPresContext::AppUnitsToIntCSSPixels(origin.y);
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2008-02-27 12:26:15 +03: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 10:46:44 +03:00
|
|
|
aRect.width = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.width);
|
|
|
|
aRect.height = nsPresContext::AppUnitsToIntCSSPixels(rcFrame.height);
|
2000-07-27 10:19:30 +04:00
|
|
|
}
|
2008-02-27 12:26:15 +03:00
|
|
|
|
2006-03-07 06:20:39 +03:00
|
|
|
return NS_OK;
|
2001-04-30 22:30:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetScreenPosition(nsIntPoint& aPoint)
|
2001-04-30 22:30:18 +04:00
|
|
|
{
|
2004-11-23 20:26:19 +03:00
|
|
|
aPoint.x = aPoint.y = 0;
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2003-09-24 05:47:46 +04:00
|
|
|
if (!mContent)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(true);
|
2006-03-07 06:20:39 +03:00
|
|
|
if (frame) {
|
|
|
|
nsIntRect rect = frame->GetScreenRect();
|
|
|
|
aPoint.x = rect.x;
|
|
|
|
aPoint.y = rect.y;
|
2001-04-30 22:30:18 +04:00
|
|
|
}
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2001-04-30 22:30:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-07-27 10:19:30 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetX(int32_t* aResult)
|
2000-07-27 10:19:30 +04:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect rect;
|
2000-07-27 10:19:30 +04:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.x;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BoxObject::GetY(int32_t* aResult)
|
2000-07-27 10:19:30 +04:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect rect;
|
2000-07-27 10:19:30 +04:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.y;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetWidth(int32_t* aResult)
|
2000-07-27 10:19:30 +04:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect rect;
|
2000-07-27 10:19:30 +04:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.width;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BoxObject::GetHeight(int32_t* aResult)
|
2000-07-27 10:19:30 +04:00
|
|
|
{
|
2009-01-15 06:27:09 +03:00
|
|
|
nsIntRect rect;
|
2000-07-27 10:19:30 +04:00
|
|
|
GetOffsetRect(rect);
|
|
|
|
*aResult = rect.height;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-30 22:30:18 +04:00
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetScreenX(int32_t *_retval)
|
2001-04-30 22:30:18 +04:00
|
|
|
{
|
2004-11-23 20:26:19 +03:00
|
|
|
nsIntPoint position;
|
|
|
|
nsresult rv = GetScreenPosition(position);
|
2001-04-30 22:30:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2004-11-23 20:26:19 +03:00
|
|
|
*_retval = position.x;
|
2001-04-30 22:30:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetScreenY(int32_t *_retval)
|
2001-04-30 22:30:18 +04:00
|
|
|
{
|
2004-11-23 20:26:19 +03:00
|
|
|
nsIntPoint position;
|
|
|
|
nsresult rv = GetScreenPosition(position);
|
2001-04-30 22:30:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2004-11-23 20:26:19 +03:00
|
|
|
*_retval = position.y;
|
2001-04-30 22:30:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-10-03 03:23:55 +04:00
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetPropertyAsSupports(const char16_t* aPropertyName, nsISupports** aResult)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
2006-07-29 14:23:42 +04:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 19:08:20 +03:00
|
|
|
if (!mPropertyTable) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2000-10-03 03:23:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-23 03:48:14 +04:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-11-23 04:09:19 +03:00
|
|
|
mPropertyTable->Get(propertyName, aResult); // Addref here.
|
|
|
|
return NS_OK;
|
2000-10-03 03:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::SetPropertyAsSupports(const char16_t* aPropertyName, nsISupports* aValue)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
2006-02-21 04:18:36 +03:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2014-08-06 17:31:21 +04:00
|
|
|
|
|
|
|
if (!mPropertyTable) {
|
|
|
|
mPropertyTable = new nsInterfaceHashtable<nsStringHashKey,nsISupports>(4);
|
2006-02-21 04:18:36 +03:00
|
|
|
}
|
2000-10-03 03:23:55 +04:00
|
|
|
|
2002-04-23 03:48:14 +04:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2012-05-18 21:30:49 +04:00
|
|
|
mPropertyTable->Put(propertyName, aValue);
|
2006-11-23 04:09:19 +03:00
|
|
|
return NS_OK;
|
2000-10-03 03:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetProperty(const char16_t* aPropertyName, char16_t** aResult)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
2006-11-06 19:08:20 +03:00
|
|
|
nsCOMPtr<nsISupports> data;
|
2006-11-23 04:09:19 +03:00
|
|
|
nsresult rv = GetPropertyAsSupports(aPropertyName,getter_AddRefs(data));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!data) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2000-10-03 03:23:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-06 19:08:20 +03:00
|
|
|
nsCOMPtr<nsISupportsString> supportsStr = do_QueryInterface(data);
|
2014-10-15 00:15:21 +04:00
|
|
|
if (!supportsStr) {
|
2006-11-06 19:08:20 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-10-15 00:15:21 +04:00
|
|
|
}
|
2014-08-06 17:31:21 +04:00
|
|
|
|
2008-12-12 22:25:22 +03:00
|
|
|
return supportsStr->ToString(aResult);
|
2000-10-03 03:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::SetProperty(const char16_t* aPropertyName, const char16_t* aPropertyValue)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
2006-07-28 10:28:27 +04:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 19:08:20 +03:00
|
|
|
|
2002-04-23 03:48:14 +04:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-07-28 10:28:27 +04:00
|
|
|
nsDependentString propertyValue;
|
|
|
|
if (aPropertyValue) {
|
|
|
|
propertyValue.Rebind(aPropertyValue);
|
|
|
|
} else {
|
2011-10-17 18:59:28 +04:00
|
|
|
propertyValue.SetIsVoid(true);
|
2006-07-28 10:28:27 +04:00
|
|
|
}
|
2014-08-06 17:31:21 +04:00
|
|
|
|
2006-11-06 19:08:20 +03: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-03 03:23:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::RemoveProperty(const char16_t* aPropertyName)
|
2000-10-03 03:23:55 +04:00
|
|
|
{
|
2006-07-29 14:23:42 +04:00
|
|
|
NS_ENSURE_ARG(aPropertyName && *aPropertyName);
|
2006-11-06 19:08:20 +03:00
|
|
|
|
|
|
|
if (!mPropertyTable) return NS_OK;
|
2000-10-03 03:23:55 +04:00
|
|
|
|
2002-04-23 03:48:14 +04:00
|
|
|
nsDependentString propertyName(aPropertyName);
|
2006-11-06 19:08:20 +03:00
|
|
|
mPropertyTable->Remove(propertyName);
|
|
|
|
return NS_OK;
|
2000-10-03 03:23:55 +04:00
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BoxObject::GetParentBox(nsIDOMElement * *aParentBox)
|
2001-09-26 02:17:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aParentBox = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 16:39:51 +04:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!parent) return NS_OK;
|
|
|
|
|
2003-08-04 16:39:51 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(parent->GetContent());
|
2001-09-26 02:17:00 +04:00
|
|
|
*aParentBox = el;
|
|
|
|
NS_IF_ADDREF(*aParentBox);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
BoxObject::GetFirstChild(nsIDOMElement * *aFirstVisibleChild)
|
2001-09-26 02:17:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aFirstVisibleChild = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2005-02-18 12:22:33 +03:00
|
|
|
if (!frame) return NS_OK;
|
2011-08-25 00:54:30 +04:00
|
|
|
nsIFrame* firstFrame = frame->GetFirstPrincipalChild();
|
2005-02-18 12:22:33 +03: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-26 02:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetLastChild(nsIDOMElement * *aLastVisibleChild)
|
2001-09-26 02:17:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aLastVisibleChild = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2005-02-18 12:22:33 +03:00
|
|
|
if (!frame) return NS_OK;
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetPreviousSibling(frame, nullptr, aLastVisibleChild);
|
2001-09-26 02:17:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetNextSibling(nsIDOMElement **aNextOrdinalSibling)
|
2001-09-26 02:17:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aNextOrdinalSibling = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 16:39:51 +04:00
|
|
|
nsIFrame* nextFrame = frame->GetNextSibling();
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!nextFrame) return NS_OK;
|
|
|
|
// get the content for the box and query to a dom element
|
2003-08-04 16:39:51 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(nextFrame->GetContent());
|
2005-02-18 12:22:33 +03:00
|
|
|
el.swap(*aNextOrdinalSibling);
|
2001-09-26 02:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetPreviousSibling(nsIDOMElement **aPreviousOrdinalSibling)
|
2001-09-26 02:17:00 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aPreviousOrdinalSibling = nullptr;
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!frame) return NS_OK;
|
2003-08-04 16:39:51 +04:00
|
|
|
nsIFrame* parentFrame = frame->GetParent();
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!parentFrame) return NS_OK;
|
2005-02-18 12:22:33 +03:00
|
|
|
return GetPreviousSibling(parentFrame, frame, aPreviousOrdinalSibling);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-10-15 00:15:21 +04:00
|
|
|
BoxObject::GetPreviousSibling(nsIFrame* aParentFrame, nsIFrame* aFrame,
|
|
|
|
nsIDOMElement** aResult)
|
2005-02-18 12:22:33 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aResult = nullptr;
|
2011-08-25 00:54:30 +04:00
|
|
|
nsIFrame* nextFrame = aParentFrame->GetFirstPrincipalChild();
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIFrame* prevFrame = nullptr;
|
2001-09-26 02:17:00 +04:00
|
|
|
while (nextFrame) {
|
2005-02-18 12:22:33 +03:00
|
|
|
if (nextFrame == aFrame)
|
2001-09-26 02:17:00 +04:00
|
|
|
break;
|
|
|
|
prevFrame = nextFrame;
|
2003-08-04 16:39:51 +04:00
|
|
|
nextFrame = nextFrame->GetNextSibling();
|
2001-09-26 02:17:00 +04:00
|
|
|
}
|
2014-10-15 00:15:21 +04:00
|
|
|
|
2001-09-26 02:17:00 +04:00
|
|
|
if (!prevFrame) return NS_OK;
|
|
|
|
// get the content for the box and query to a dom element
|
2003-08-04 16:39:51 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> el = do_QueryInterface(prevFrame->GetContent());
|
2005-02-18 12:22:33 +03:00
|
|
|
el.swap(*aResult);
|
2001-09-26 02:17:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
nsIContent*
|
|
|
|
BoxObject::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mContent;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
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 17:13:33 +03:00
|
|
|
BoxObject::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-10-15 00:15:21 +04: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 17:13:33 +03:00
|
|
|
return BoxObjectBinding::Wrap(aCx, this, aGivenProto);
|
2014-10-15 00:15:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Element*
|
|
|
|
BoxObject::GetElement() const
|
|
|
|
{
|
|
|
|
return mContent && mContent->IsElement() ? mContent->AsElement() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::X()
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
GetX(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::Y()
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
GetY(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::GetScreenX(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
aRv = GetScreenX(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::GetScreenY(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
aRv = GetScreenY(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::Width()
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
GetWidth(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
BoxObject::Height()
|
|
|
|
{
|
|
|
|
int32_t ret = 0;
|
|
|
|
GetHeight(&ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsISupports>
|
|
|
|
BoxObject::GetPropertyAsSupports(const nsAString& propertyName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> ret;
|
|
|
|
GetPropertyAsSupports(PromiseFlatString(propertyName).get(), getter_AddRefs(ret));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BoxObject::SetPropertyAsSupports(const nsAString& propertyName, nsISupports* value)
|
|
|
|
{
|
|
|
|
SetPropertyAsSupports(PromiseFlatString(propertyName).get(), value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BoxObject::GetProperty(const nsAString& propertyName, nsString& aRetVal, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> data(GetPropertyAsSupports(propertyName));
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> supportsStr(do_QueryInterface(data));
|
|
|
|
if (!supportsStr) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
supportsStr->GetData(aRetVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BoxObject::SetProperty(const nsAString& propertyName, const nsAString& propertyValue)
|
|
|
|
{
|
|
|
|
SetProperty(PromiseFlatString(propertyName).get(), PromiseFlatString(propertyValue).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BoxObject::RemoveProperty(const nsAString& propertyName)
|
|
|
|
{
|
|
|
|
RemoveProperty(PromiseFlatString(propertyName).get());
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
BoxObject::GetParentBox()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetParentBox(getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
BoxObject::GetFirstChild()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetFirstChild(getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
BoxObject::GetLastChild()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetLastChild(getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
BoxObject::GetNextSibling()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetNextSibling(getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Element>
|
|
|
|
BoxObject::GetPreviousSibling()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> el;
|
|
|
|
GetPreviousSibling(getter_AddRefs(el));
|
|
|
|
nsCOMPtr<Element> ret(do_QueryInterface(el));
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2000-05-30 11:59:13 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
2014-10-15 00:15:21 +04:00
|
|
|
NS_ADDREF(*aResult = new BoxObject());
|
2000-05-30 11:59:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|