2011-04-23 23:54:25 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07: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/.
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* This Original Code has been modified by IBM Corporation.
|
|
|
|
* Modifications made by IBM described herein are
|
|
|
|
* Copyright (c) International Business Machines
|
|
|
|
* Corporation, 2000
|
|
|
|
*
|
|
|
|
* Modifications to Mozilla code or documentation
|
|
|
|
* identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
|
|
|
|
* use in OS2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMCID.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDOMString.h"
|
|
|
|
#include "nsIDOMEvent.h"
|
|
|
|
#include "nsIAtom.h"
|
2007-10-29 21:03:42 -07:00
|
|
|
#include "nsIBaseWindow.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMAttr.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
|
|
|
#include "nsIDOMXULCommandDispatcher.h"
|
|
|
|
#include "nsIDOMXULElement.h"
|
|
|
|
#include "nsIDOMElementCSSInlineStyle.h"
|
|
|
|
#include "nsIDOMXULSelectCntrlItemEl.h"
|
|
|
|
#include "nsIDocument.h"
|
2011-06-23 19:18:01 -07:00
|
|
|
#include "nsEventListenerManager.h"
|
2011-04-21 10:35:52 -07:00
|
|
|
#include "nsEventStateManager.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
#include "nsFocusManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIRDFCompositeDataSource.h"
|
|
|
|
#include "nsIRDFNode.h"
|
|
|
|
#include "nsIRDFService.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptRuntime.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2013-08-08 16:51:34 -07:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIServiceManager.h"
|
2011-03-10 18:48:57 -08:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStyleSheet.h"
|
|
|
|
#include "nsIURL.h"
|
2013-01-04 19:12:24 -08:00
|
|
|
#include "nsViewManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIWidget.h"
|
|
|
|
#include "nsIXULDocument.h"
|
|
|
|
#include "nsIXULTemplateBuilder.h"
|
|
|
|
#include "nsLayoutCID.h"
|
|
|
|
#include "nsContentCID.h"
|
2013-04-05 17:44:15 -07:00
|
|
|
#include "nsDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRDFCID.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsXULControllers.h"
|
|
|
|
#include "nsIBoxObject.h"
|
|
|
|
#include "nsPIBoxObject.h"
|
2013-03-26 08:31:53 -07:00
|
|
|
#include "XULDocument.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsXULPopupListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsRuleWalker.h"
|
|
|
|
#include "nsIDOMCSSStyleDeclaration.h"
|
2010-03-02 12:59:32 -08:00
|
|
|
#include "nsCSSParser.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIListBoxObject.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsContentList.h"
|
|
|
|
#include "nsMutationEvent.h"
|
2011-12-16 22:02:05 -08:00
|
|
|
#include "nsAsyncDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2013-08-08 16:51:34 -07:00
|
|
|
#include "nsJSPrincipals.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsDOMAttributeMap.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsXULContentUtils.h"
|
|
|
|
#include "nsNodeUtils.h"
|
2008-03-21 04:18:10 -07:00
|
|
|
#include "nsFrameLoader.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prlog.h"
|
|
|
|
#include "rdf.h"
|
|
|
|
#include "nsIControllers.h"
|
2012-02-13 18:00:56 -08:00
|
|
|
#include "nsAttrValueOrString.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValueInlines.h"
|
2012-06-18 19:30:09 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-01-15 04:22:03 -08:00
|
|
|
#include <algorithm>
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The XUL doc interface
|
|
|
|
#include "nsIDOMXULDocument.h"
|
|
|
|
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
|
|
|
#include "nsXBLBinding.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
2008-04-11 10:29:06 -07:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-06-04 13:23:37 -07:00
|
|
|
#include "nsIDOMXULCommandEvent.h"
|
2008-10-08 04:41:52 -07:00
|
|
|
#include "nsCCUncollectableMarker.h"
|
2012-10-16 04:51:00 -07:00
|
|
|
#include "nsICSSDeclaration.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
#include "mozilla/dom/XULElementBinding.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2013-03-26 08:31:53 -07:00
|
|
|
using namespace mozilla::dom;
|
2011-03-10 18:48:57 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kXULPopupListenerCID, NS_XULPOPUPLISTENER_CID);
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t nsXULPrototypeAttribute::gNumElements;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumAttributes;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheTests;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheHits;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheSets;
|
|
|
|
uint32_t nsXULPrototypeAttribute::gNumCacheFills;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-06-18 19:30:09 -07:00
|
|
|
class nsXULElementTearoff MOZ_FINAL : public nsIDOMElementCSSInlineStyle,
|
|
|
|
public nsIFrameLoaderOwner
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2008-03-21 04:18:10 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULElementTearoff,
|
|
|
|
nsIDOMElementCSSInlineStyle)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXULElementTearoff(nsXULElement *aElement)
|
|
|
|
: mElement(aElement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-05 14:59:36 -07:00
|
|
|
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
2013-01-11 00:42:59 -08:00
|
|
|
nsXULElement* element = static_cast<nsXULElement*>(mElement.get());
|
|
|
|
NS_ADDREF(*aStyle = element->Style());
|
2010-08-05 14:59:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-09 09:23:19 -08:00
|
|
|
NS_FORWARD_NSIFRAMELOADEROWNER(static_cast<nsXULElement*>(mElement.get())->)
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
2008-03-21 04:18:10 -07:00
|
|
|
nsCOMPtr<nsIDOMXULElement> mElement;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2008-03-21 04:18:10 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_1(nsXULElementTearoff, mElement)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULElementTearoff)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULElementTearoff)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-21 04:18:10 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXULElementTearoff)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMElementCSSInlineStyle)
|
|
|
|
NS_INTERFACE_MAP_END_AGGREGATED(mElement)
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsXULElement
|
|
|
|
//
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsXULElement::nsXULElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2010-02-23 20:37:46 -08:00
|
|
|
: nsStyledElement(aNodeInfo),
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingParent(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumElements);
|
2011-05-31 18:46:57 -07:00
|
|
|
|
|
|
|
// We may be READWRITE by default; check.
|
|
|
|
if (IsReadWriteTextElement()) {
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_MOZ_READWRITE);
|
|
|
|
RemoveStatesSilently(NS_EVENT_STATE_MOZ_READONLY);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 19:29:49 -07:00
|
|
|
nsXULElement::nsXULSlots::nsXULSlots()
|
|
|
|
: nsXULElement::nsDOMSlots()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXULElement::nsXULSlots::~nsXULSlots()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mControllers); // Forces release
|
2008-03-21 04:18:10 -07:00
|
|
|
if (mFrameLoader) {
|
|
|
|
mFrameLoader->Destroy();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-08-28 07:07:24 -07:00
|
|
|
void
|
|
|
|
nsXULElement::nsXULSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
|
|
|
|
{
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mFrameLoader");
|
|
|
|
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIFrameLoader*, mFrameLoader));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINode::nsSlots*
|
|
|
|
nsXULElement::CreateSlots()
|
|
|
|
{
|
2011-04-07 19:29:49 -07:00
|
|
|
return new nsXULSlots();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-04 15:22:51 -08:00
|
|
|
void
|
|
|
|
nsXULElement::MaybeUpdatePrivateLifetime()
|
|
|
|
{
|
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::windowtype,
|
|
|
|
NS_LITERAL_STRING("navigator:browser"),
|
|
|
|
eCaseMatters)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindow* win = OwnerDoc()->GetWindow();
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = win ? win->GetDocShell() : nullptr;
|
|
|
|
if (docShell) {
|
|
|
|
docShell->SetAffectPrivateSessionLifetime(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsXULElement>
|
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype, nsINodeInfo *aNodeInfo,
|
2013-02-04 15:22:51 -08:00
|
|
|
bool aIsScriptable, bool aIsRoot)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 02:49:57 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (element) {
|
2007-09-18 01:38:24 -07:00
|
|
|
if (aPrototype->mHasIdAttribute) {
|
2011-04-07 19:29:50 -07:00
|
|
|
element->SetHasID();
|
2007-09-18 01:38:24 -07:00
|
|
|
}
|
|
|
|
if (aPrototype->mHasClassAttribute) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (aPrototype->mHasStyleAttribute) {
|
2011-04-07 19:29:50 -07:00
|
|
|
element->SetMayHaveStyle();
|
2007-09-18 01:38:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-14 08:28:54 -07:00
|
|
|
element->MakeHeavyweight(aPrototype);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aIsScriptable) {
|
|
|
|
// Check each attribute on the prototype to see if we need to do
|
|
|
|
// any additional processing and hookup that would otherwise be
|
|
|
|
// done 'automagically' by SetAttr().
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aPrototype->mNumAttributes; ++i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
element->AddListenerFor(aPrototype->mAttributes[i].mName,
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-02-04 15:22:51 -08:00
|
|
|
|
|
|
|
if (aIsRoot && aPrototype->mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
for (uint32_t i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
if (aPrototype->mAttributes[i].mName.Equals(nsGkAtoms::windowtype)) {
|
|
|
|
element->MaybeUpdatePrivateLifetime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
return element.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::Create(nsXULPrototypeElement* aPrototype,
|
|
|
|
nsIDocument* aDocument,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsScriptable,
|
2013-02-04 15:22:51 -08:00
|
|
|
bool aIsRoot,
|
2010-04-30 06:12:05 -07:00
|
|
|
Element** aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Create an nsXULElement from a prototype
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aPrototype != nullptr, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! aPrototype)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_PRECONDITION(aResult != nullptr, "null ptr");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
|
|
|
if (aDocument) {
|
|
|
|
nsINodeInfo* ni = aPrototype->mNodeInfo;
|
2011-06-14 00:56:49 -07:00
|
|
|
nodeInfo = aDocument->NodeInfoManager()->
|
|
|
|
GetNodeInfo(ni->NameAtom(), ni->GetPrefixAtom(), ni->NamespaceID(),
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nodeInfo = aPrototype->mNodeInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsXULElement> element = Create(aPrototype, nodeInfo,
|
2013-02-04 15:22:51 -08:00
|
|
|
aIsScriptable, aIsRoot);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!element) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2012-07-14 08:28:54 -07:00
|
|
|
element.forget(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-07-23 02:49:57 -07:00
|
|
|
NS_NewXULElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-23 02:49:57 -07:00
|
|
|
NS_PRECONDITION(aNodeInfo.get(), "need nodeinfo for non-proto Create");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
nsIDocument* doc = aNodeInfo.get()->GetDocument();
|
|
|
|
if (doc && !doc->AllowXULXBL()) {
|
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
NS_ADDREF(*aResult = new nsXULElement(aNodeInfo));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-19 18:41:58 -07:00
|
|
|
return NS_OK;
|
2010-08-19 16:12:46 -07:00
|
|
|
}
|
|
|
|
|
2010-08-19 16:12:46 -07:00
|
|
|
void
|
|
|
|
NS_TrustedNewXULElement(nsIContent** aResult, already_AddRefed<nsINodeInfo> aNodeInfo)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNodeInfo.get(), "need nodeinfo for non-proto Create");
|
|
|
|
|
|
|
|
// Create an nsXULElement with the specified namespace and tag.
|
|
|
|
NS_ADDREF(*aResult = new nsXULElement(aNodeInfo));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsISupports interface
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULElement)
|
|
|
|
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULElement,
|
2010-02-23 20:37:46 -08:00
|
|
|
nsStyledElement)
|
2011-02-16 04:07:47 -08:00
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(tmp->GetExistingSlots());
|
|
|
|
if (slots) {
|
2011-08-28 07:07:24 -07:00
|
|
|
slots->Traverse(cb);
|
2011-02-16 04:07:47 -08:00
|
|
|
}
|
|
|
|
}
|
2007-05-24 07:10:02 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsXULElement, nsStyledElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsXULElement, nsStyledElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsXULElement)
|
2013-05-21 12:59:27 -07:00
|
|
|
NS_INTERFACE_TABLE_INHERITED3(nsXULElement, nsIDOMNode, nsIDOMElement,
|
|
|
|
nsIDOMXULElement)
|
2008-11-03 02:31:47 -08:00
|
|
|
NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMElementCSSInlineStyle,
|
|
|
|
new nsXULElementTearoff(this))
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIFrameLoaderOwner,
|
|
|
|
new nsXULElementTearoff(this))
|
2013-08-07 13:23:08 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsStyledElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// nsIDOMNode interface
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-14 08:28:54 -07:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfo;
|
|
|
|
nsRefPtr<nsXULElement> element = new nsXULElement(ni.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX TODO: set up RDF generic builder n' stuff if there is a
|
|
|
|
// 'datasources' attribute? This is really kind of tricky,
|
|
|
|
// because then we'd need to -selectively- copy children that
|
|
|
|
// -weren't- generated from RDF. Ugh. Forget it.
|
|
|
|
|
|
|
|
// Note that we're _not_ copying mControllers.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = mAttrsAndChildren.AttrCount();
|
2012-07-19 02:21:40 -07:00
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2012-07-19 02:21:40 -07:00
|
|
|
const nsAttrName* originalName = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
const nsAttrValue* originalValue = mAttrsAndChildren.AttrAt(i);
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
|
|
|
|
// Style rules need to be cloned.
|
|
|
|
if (originalValue->Type() == nsAttrValue::eCSSStyleRule) {
|
|
|
|
nsRefPtr<css::Rule> ruleClone =
|
|
|
|
originalValue->GetCSSStyleRuleValue()->Clone();
|
|
|
|
|
|
|
|
nsString stringValue;
|
|
|
|
originalValue->ToString(stringValue);
|
|
|
|
|
|
|
|
nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
|
|
|
|
attrValue.SetTo(styleRule, &stringValue);
|
|
|
|
} else {
|
|
|
|
attrValue.SetTo(*originalValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (originalName->IsAtom()) {
|
|
|
|
rv = element->mAttrsAndChildren.SetAndTakeAttr(originalName->Atom(),
|
|
|
|
attrValue);
|
|
|
|
} else {
|
|
|
|
rv = element->mAttrsAndChildren.SetAndTakeAttr(originalName->NodeInfo(),
|
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
element->AddListenerFor(*originalName, true);
|
2012-07-20 14:55:19 -07:00
|
|
|
if (originalName->Equals(nsGkAtoms::id) &&
|
|
|
|
!originalValue->IsEmptyString()) {
|
2012-07-19 02:21:40 -07:00
|
|
|
element->SetHasID();
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::_class)) {
|
|
|
|
element->SetFlags(NODE_MAY_HAVE_CLASS);
|
|
|
|
}
|
|
|
|
if (originalName->Equals(nsGkAtoms::style)) {
|
|
|
|
element->SetMayHaveStyle();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-07-19 02:21:40 -07:00
|
|
|
element.forget(aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
*aReturn = GetElementsByAttribute(aAttribute, aValue).get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
|
|
|
|
void* attrValue = new nsString(aValue);
|
2013-01-29 09:51:55 -08:00
|
|
|
nsRefPtr<nsContentList> list =
|
2007-03-22 10:30:00 -07:00
|
|
|
new nsContentList(this,
|
2013-03-26 08:31:53 -07:00
|
|
|
XULDocument::MatchAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 07:59:28 -07:00
|
|
|
true,
|
2007-03-22 10:30:00 -07:00
|
|
|
attrAtom,
|
|
|
|
kNameSpaceID_Unknown);
|
2013-01-29 09:51:55 -08:00
|
|
|
return list.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsIDOMNodeList** aReturn)
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aReturn =
|
|
|
|
GetElementsByAttributeNS(aNamespaceURI, aAttribute, aValue, rv).get();
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsXULElement::GetElementsByAttributeNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
ErrorResult& rv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAtom> attrAtom(do_GetAtom(aAttribute));
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nameSpaceId = kNameSpaceID_Wildcard;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!aNamespaceURI.EqualsLiteral("*")) {
|
2013-01-29 09:51:55 -08:00
|
|
|
rv =
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::NameSpaceManager()->RegisterNameSpace(aNamespaceURI,
|
|
|
|
nameSpaceId);
|
2013-01-29 09:51:55 -08:00
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void* attrValue = new nsString(aValue);
|
2013-01-29 09:51:55 -08:00
|
|
|
nsRefPtr<nsContentList> list =
|
2007-03-22 10:30:00 -07:00
|
|
|
new nsContentList(this,
|
2013-03-26 08:31:53 -07:00
|
|
|
XULDocument::MatchAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsContentUtils::DestroyMatchString,
|
|
|
|
attrValue,
|
2011-10-17 07:59:28 -07:00
|
|
|
true,
|
2007-03-22 10:30:00 -07:00
|
|
|
attrAtom,
|
|
|
|
nameSpaceId);
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
return list.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-07-29 12:37:17 -07:00
|
|
|
nsEventListenerManager*
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXXbz sXBL/XBL2 issue: should we instead use GetCurrentDoc()
|
|
|
|
// here, override BindToTree for those classes and munge event
|
|
|
|
// listeners there?
|
2011-10-18 03:53:36 -07:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-05-07 21:57:21 -07:00
|
|
|
nsPIDOMWindow *window;
|
2010-04-30 06:12:05 -07:00
|
|
|
Element *root = doc->GetRootElement();
|
2008-05-07 21:57:21 -07:00
|
|
|
if ((!root || root == this) && !mNodeInfo->Equals(nsGkAtoms::overlay) &&
|
2013-04-29 08:34:16 -07:00
|
|
|
(window = doc->GetInnerWindow())) {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-04-05 17:44:15 -07:00
|
|
|
nsCOMPtr<EventTarget> piTarget = do_QueryInterface(window);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aDefer = false;
|
|
|
|
return piTarget->GetListenerManager(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 08:54:50 -07:00
|
|
|
return nsStyledElement::GetEventListenerManagerForAttr(aAttrName, aDefer);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
// returns true if the element is not a list
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool IsNonList(nsINodeInfo* aNodeInfo)
|
2010-04-21 07:53:42 -07:00
|
|
|
{
|
|
|
|
return !aNodeInfo->Equals(nsGkAtoms::tree) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::listbox) &&
|
|
|
|
!aNodeInfo->Equals(nsGkAtoms::richlistbox);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::IsFocusable(int32_t *aTabIndex, bool aWithMouse)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-03-07 08:33:38 -08:00
|
|
|
/*
|
|
|
|
* Returns true if an element may be focused, and false otherwise. The inout
|
|
|
|
* argument aTabIndex will be set to the tab order index to be used; -1 for
|
|
|
|
* elements that should not be part of the tab order and a greater value to
|
|
|
|
* indicate its tab order.
|
|
|
|
*
|
|
|
|
* Confusingly, the supplied value for the aTabIndex argument may indicate
|
|
|
|
* whether the element may be focused as a result of the -moz-user-focus
|
2008-03-27 09:19:05 -07:00
|
|
|
* property, where -1 means no and 0 means yes.
|
2008-03-07 08:33:38 -08:00
|
|
|
*
|
|
|
|
* For controls, the element cannot be focused and is not part of the tab
|
|
|
|
* order if it is disabled.
|
|
|
|
*
|
|
|
|
* Controls (those that implement nsIDOMXULControlElement):
|
|
|
|
* *aTabIndex = -1 no tabindex Not focusable or tabbable
|
|
|
|
* *aTabIndex = -1 tabindex="-1" Not focusable or tabbable
|
|
|
|
* *aTabIndex = -1 tabindex=">=0" Focusable and tabbable
|
|
|
|
* *aTabIndex >= 0 no tabindex Focusable and tabbable
|
|
|
|
* *aTabIndex >= 0 tabindex="-1" Focusable but not tabbable
|
|
|
|
* *aTabIndex >= 0 tabindex=">=0" Focusable and tabbable
|
|
|
|
* Non-controls:
|
|
|
|
* *aTabIndex = -1 Not focusable or tabbable
|
|
|
|
* *aTabIndex >= 0 Focusable and tabbable
|
|
|
|
*
|
|
|
|
* If aTabIndex is null, then the tabindex is not computed, and
|
|
|
|
* true is returned for non-disabled controls and false otherwise.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// elements are not focusable by default
|
2011-09-28 23:19:26 -07:00
|
|
|
bool shouldFocus = false;
|
2008-03-07 08:33:38 -08:00
|
|
|
|
2010-04-21 07:53:42 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// on Mac, mouse interactions only focus the element if it's a list
|
|
|
|
if (aWithMouse && IsNonList(mNodeInfo))
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-04-21 07:53:42 -07:00
|
|
|
#endif
|
|
|
|
|
2011-08-30 14:45:31 -07:00
|
|
|
nsCOMPtr<nsIDOMXULControlElement> xulControl = do_QueryObject(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (xulControl) {
|
2008-03-07 08:33:38 -08:00
|
|
|
// a disabled element cannot be focused and is not part of the tab order
|
2011-09-28 23:19:26 -07:00
|
|
|
bool disabled;
|
2007-03-22 10:30:00 -07:00
|
|
|
xulControl->GetDisabled(&disabled);
|
|
|
|
if (disabled) {
|
2008-03-07 08:33:38 -08:00
|
|
|
if (aTabIndex)
|
|
|
|
*aTabIndex = -1;
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
shouldFocus = true;
|
2008-03-07 08:33:38 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex) {
|
2008-03-27 09:19:05 -07:00
|
|
|
if (xulControl) {
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
|
|
|
|
// if either the aTabIndex argument or a specified tabindex is non-negative,
|
|
|
|
// the element becomes focusable.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t tabIndex = 0;
|
2008-03-27 09:19:05 -07:00
|
|
|
xulControl->GetTabIndex(&tabIndex);
|
|
|
|
shouldFocus = *aTabIndex >= 0 || tabIndex >= 0;
|
|
|
|
*aTabIndex = tabIndex;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// otherwise, if there is no tabindex attribute, just use the value of
|
2009-11-20 04:09:33 -08:00
|
|
|
// *aTabIndex to indicate focusability. Reset any supplied tabindex to 0.
|
2008-03-27 09:19:05 -07:00
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2009-11-20 04:09:33 -08:00
|
|
|
if (shouldFocus)
|
|
|
|
*aTabIndex = 0;
|
2008-03-27 09:19:05 -07:00
|
|
|
}
|
2008-03-13 07:07:23 -07:00
|
|
|
|
|
|
|
if (shouldFocus && sTabFocusModelAppliesToXUL &&
|
|
|
|
!(sTabFocusModel & eTabFocus_formElementsMask)) {
|
|
|
|
// By default, the tab focus model doesn't apply to xul element on any system but OS X.
|
|
|
|
// on OS X we're following it for UI elements (XUL) as sTabFocusModel is based on
|
|
|
|
// "Full Keyboard Access" system setting (see mac/nsILookAndFeel).
|
|
|
|
// both textboxes and list elements (i.e. trees and list) should always be focusable
|
|
|
|
// (textboxes are handled as html:input)
|
|
|
|
// For compatibility, we only do this for controls, otherwise elements like <browser>
|
|
|
|
// cannot take this focus.
|
2010-04-21 07:53:42 -07:00
|
|
|
if (IsNonList(mNodeInfo))
|
2008-03-13 07:07:23 -07:00
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
2008-03-07 08:33:38 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
shouldFocus = *aTabIndex >= 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-07 08:33:38 -08:00
|
|
|
return shouldFocus;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> content(this);
|
|
|
|
|
|
|
|
if (Tag() == nsGkAtoms::label) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
|
|
|
|
nsAutoString control;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::control, control);
|
|
|
|
if (!control.IsEmpty()) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDocument =
|
|
|
|
do_QueryInterface(content->GetCurrentDoc());
|
|
|
|
if (domDocument)
|
|
|
|
domDocument->GetElementById(control, getter_AddRefs(element));
|
|
|
|
}
|
|
|
|
// here we'll either change |content| to the element referenced by
|
|
|
|
// |element|, or clear it.
|
|
|
|
content = do_QueryInterface(element);
|
|
|
|
|
|
|
|
if (!content)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = content->GetPrimaryFrame();
|
2011-10-26 16:57:55 -07:00
|
|
|
if (!frame || !frame->IsVisibleConsideringAncestors())
|
2007-03-22 10:30:00 -07:00
|
|
|
return;
|
|
|
|
|
2010-08-27 14:26:24 -07:00
|
|
|
nsXULElement* elm = FromContent(content);
|
2007-11-11 14:44:48 -08:00
|
|
|
if (elm) {
|
|
|
|
// Define behavior for each type of XUL element.
|
|
|
|
nsIAtom *tag = content->Tag();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (tag != nsGkAtoms::toolbarbutton) {
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2009-06-15 08:08:41 -07:00
|
|
|
if (fm) {
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
// for radio buttons, focus the radiogroup instead
|
|
|
|
if (tag == nsGkAtoms::radio) {
|
2010-08-27 14:26:24 -07:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> controlItem(do_QueryInterface(content));
|
2009-06-15 08:08:41 -07:00
|
|
|
if (controlItem) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool disabled;
|
2009-06-15 08:08:41 -07:00
|
|
|
controlItem->GetDisabled(&disabled);
|
|
|
|
if (!disabled) {
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlElement> selectControl;
|
|
|
|
controlItem->GetControl(getter_AddRefs(selectControl));
|
|
|
|
element = do_QueryInterface(selectControl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
element = do_QueryInterface(content);
|
|
|
|
}
|
|
|
|
if (element)
|
|
|
|
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
|
|
|
|
}
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
}
|
2010-04-06 05:59:24 -07:00
|
|
|
if (aKeyCausesActivation && tag != nsGkAtoms::textbox && tag != nsGkAtoms::menulist) {
|
2011-08-26 00:43:56 -07:00
|
|
|
elm->ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
|
2010-04-06 05:59:24 -07:00
|
|
|
}
|
2007-11-11 14:44:48 -08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
content->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::AddListenerFor(const nsAttrName& aName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// If appropriate, add a popup listener and/or compile the event
|
|
|
|
// handler. Called when we change the element's document, create a
|
|
|
|
// new element, change an attribute's value, etc.
|
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (aName.IsAtom()) {
|
|
|
|
nsIAtom *attr = aName.Atom();
|
|
|
|
MaybeAddPopupListener(attr);
|
2007-04-02 10:17:36 -07:00
|
|
|
if (aCompileEventHandlers &&
|
|
|
|
nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 09:25:10 -07:00
|
|
|
SetEventHandler(attr, value, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::MaybeAddPopupListener(nsIAtom* aLocalName)
|
|
|
|
{
|
|
|
|
// If appropriate, add a popup listener. Called when we change the
|
|
|
|
// element's document, create a new element, change an attribute's
|
|
|
|
// value, etc.
|
|
|
|
if (aLocalName == nsGkAtoms::menu ||
|
|
|
|
aLocalName == nsGkAtoms::contextmenu ||
|
|
|
|
// XXXdwh popup and context are deprecated
|
|
|
|
aLocalName == nsGkAtoms::popup ||
|
|
|
|
aLocalName == nsGkAtoms::context) {
|
|
|
|
AddPopupListener(aLocalName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsIContent interface
|
|
|
|
//
|
2011-05-31 18:46:57 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::UpdateEditableState(bool aNotify)
|
2011-05-31 18:46:57 -07:00
|
|
|
{
|
2012-11-14 14:10:08 -08:00
|
|
|
// Don't call through to Element here because the things
|
2011-05-31 18:46:57 -07:00
|
|
|
// it does don't work for cases when we're an editable control.
|
|
|
|
nsIContent *parent = GetParent();
|
|
|
|
|
|
|
|
SetEditableFlag(parent && parent->HasFlag(NODE_IS_EDITABLE));
|
|
|
|
UpdateState(aNotify);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-03-21 04:18:10 -07:00
|
|
|
nsresult
|
|
|
|
nsXULElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers)
|
2008-03-21 04:18:10 -07:00
|
|
|
{
|
2010-06-03 18:09:20 -07:00
|
|
|
nsresult rv = nsStyledElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2008-03-21 04:18:10 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aDocument) {
|
2009-01-02 07:41:43 -08:00
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Missing a script blocker!");
|
2008-03-21 04:18:10 -07:00
|
|
|
// We're in a document now. Kick off the frame load.
|
|
|
|
LoadSrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-05-21 15:22:51 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-05-21 15:22:51 -07:00
|
|
|
{
|
|
|
|
// mControllers can own objects that are implemented
|
|
|
|
// in JavaScript (such as some implementations of
|
|
|
|
// nsIControllers. These objects prevent their global
|
|
|
|
// object's script object from being garbage collected,
|
|
|
|
// which means JS continues to hold an owning reference
|
|
|
|
// to the nsGlobalWindow, which owns the document,
|
|
|
|
// which owns this content. That's a cycle, so we break
|
|
|
|
// it here. (It might be better to break this by releasing
|
|
|
|
// mDocument in nsGlobalWindow::SetDocShell, but I'm not
|
|
|
|
// sure whether that would fix all possible cycles through
|
|
|
|
// mControllers.)
|
2008-03-21 04:18:10 -07:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-05-21 15:22:51 -07:00
|
|
|
if (slots) {
|
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
2008-03-21 04:18:10 -07:00
|
|
|
if (slots->mFrameLoader) {
|
|
|
|
// This element is being taken out of the document, destroy the
|
|
|
|
// possible frame loader.
|
|
|
|
// XXXbz we really want to only partially destroy the frame
|
|
|
|
// loader... we don't want to tear down the docshell. Food for
|
|
|
|
// later bug.
|
|
|
|
slots->mFrameLoader->Destroy();
|
2012-07-30 07:20:58 -07:00
|
|
|
slots->mFrameLoader = nullptr;
|
2008-03-21 04:18:10 -07:00
|
|
|
}
|
2007-05-21 15:22:51 -07:00
|
|
|
}
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
nsStyledElement::UnbindFromTree(aDeep, aNullParent);
|
2007-05-21 15:22:51 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 14:09:07 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
|
|
|
|
if (!oldKid) {
|
2012-03-29 14:09:07 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// On the removal of a <treeitem>, <treechildren>, or <treecell> element,
|
|
|
|
// the possibility exists that some of the items in the removed subtree
|
|
|
|
// are selected (and therefore need to be deselected). We need to account for this.
|
|
|
|
nsCOMPtr<nsIDOMXULMultiSelectControlElement> controlElement;
|
|
|
|
nsCOMPtr<nsIListBoxObject> listBox;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool fireSelectionHandler = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// -1 = do nothing, -2 = null out current item
|
|
|
|
// anything else = index to re-set as current
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t newCurrentIndex = -1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (oldKid->NodeInfo()->Equals(nsGkAtoms::listitem, kNameSpaceID_XUL)) {
|
|
|
|
// This is the nasty case. We have (potentially) a slew of selected items
|
|
|
|
// and cells going away.
|
|
|
|
// First, retrieve the tree.
|
|
|
|
// Check first whether this element IS the tree
|
2011-08-30 14:45:31 -07:00
|
|
|
controlElement = do_QueryObject(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If it's not, look at our parent
|
|
|
|
if (!controlElement)
|
2012-03-29 14:09:07 -07:00
|
|
|
GetParentTree(getter_AddRefs(controlElement));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> oldKidElem = do_QueryInterface(oldKid);
|
|
|
|
if (controlElement && oldKidElem) {
|
|
|
|
// Iterate over all of the items and find out if they are contained inside
|
|
|
|
// the removed subtree.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t length;
|
2007-03-22 10:30:00 -07:00
|
|
|
controlElement->GetSelectedCount(&length);
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t i = 0; i < length; i++) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> node;
|
2012-08-07 00:06:29 -07:00
|
|
|
controlElement->MultiGetSelectedItem(i, getter_AddRefs(node));
|
2007-03-22 10:30:00 -07:00
|
|
|
// we need to QI here to do an XPCOM-correct pointercompare
|
|
|
|
nsCOMPtr<nsIDOMElement> selElem = do_QueryInterface(node);
|
|
|
|
if (selElem == oldKidElem &&
|
|
|
|
NS_SUCCEEDED(controlElement->RemoveItemFromSelection(node))) {
|
|
|
|
length--;
|
|
|
|
i--;
|
2011-10-17 07:59:28 -07:00
|
|
|
fireSelectionHandler = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> curItem;
|
|
|
|
controlElement->GetCurrentItem(getter_AddRefs(curItem));
|
|
|
|
nsCOMPtr<nsIContent> curNode = do_QueryInterface(curItem);
|
|
|
|
if (curNode && nsContentUtils::ContentIsDescendantOf(curNode, oldKid)) {
|
|
|
|
// Current item going away
|
|
|
|
nsCOMPtr<nsIBoxObject> box;
|
|
|
|
controlElement->GetBoxObject(getter_AddRefs(box));
|
|
|
|
listBox = do_QueryInterface(box);
|
|
|
|
if (listBox && oldKidElem) {
|
|
|
|
listBox->GetIndexOfItem(oldKidElem, &newCurrentIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If any of this fails, we'll just set the current item to null
|
|
|
|
if (newCurrentIndex == -1)
|
|
|
|
newCurrentIndex = -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 14:09:07 -07:00
|
|
|
nsStyledElement::RemoveChildAt(aIndex, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (newCurrentIndex == -2)
|
2012-07-30 07:20:58 -07:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (newCurrentIndex > -1) {
|
|
|
|
// Make sure the index is still valid
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t treeRows;
|
2007-03-22 10:30:00 -07:00
|
|
|
listBox->GetRowCount(&treeRows);
|
|
|
|
if (treeRows > 0) {
|
2013-01-15 04:22:03 -08:00
|
|
|
newCurrentIndex = std::min((treeRows - 1), newCurrentIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> newCurrentItem;
|
|
|
|
listBox->GetItemAtIndex(newCurrentIndex, getter_AddRefs(newCurrentItem));
|
|
|
|
nsCOMPtr<nsIDOMXULSelectControlItemElement> xulCurItem = do_QueryInterface(newCurrentItem);
|
|
|
|
if (xulCurItem)
|
|
|
|
controlElement->SetCurrentItem(xulCurItem);
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
controlElement->SetCurrentItem(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument* doc;
|
|
|
|
if (fireSelectionHandler && (doc = GetCurrentDoc())) {
|
|
|
|
nsContentUtils::DispatchTrustedEvent(doc,
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsIContent*>(this),
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_LITERAL_STRING("select"),
|
2011-10-17 07:59:28 -07:00
|
|
|
false,
|
|
|
|
true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::UnregisterAccessKey(const nsAString& aOldValue)
|
|
|
|
{
|
|
|
|
// If someone changes the accesskey, unregister the old one
|
|
|
|
//
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (doc && !aOldValue.IsEmpty()) {
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (shell) {
|
|
|
|
nsIContent *content = this;
|
|
|
|
|
|
|
|
// find out what type of content node this is
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::label)) {
|
|
|
|
// For anonymous labels the unregistering must
|
|
|
|
// occur on the binding parent control.
|
2008-07-22 21:50:20 -07:00
|
|
|
// XXXldb: And what if the binding parent is null?
|
2007-03-22 10:30:00 -07:00
|
|
|
content = GetBindingParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content) {
|
|
|
|
shell->GetPresContext()->EventStateManager()->
|
|
|
|
UnregisterAccessKey(content, aOldValue.First());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2012-02-13 18:00:56 -08:00
|
|
|
const nsAttrValueOrString* aValue, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::accesskey &&
|
|
|
|
IsInDoc()) {
|
2012-07-14 08:28:54 -07:00
|
|
|
nsAutoString oldValue;
|
|
|
|
if (GetAttr(aNamespaceID, aName, oldValue)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
UnregisterAccessKey(oldValue);
|
|
|
|
}
|
2008-01-29 07:12:34 -08:00
|
|
|
}
|
|
|
|
else if (aNamespaceID == kNameSpaceID_None && (aName ==
|
|
|
|
nsGkAtoms::command || aName == nsGkAtoms::observes) && IsInDoc()) {
|
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
|
|
|
nsAutoString oldValue;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::observes, oldValue);
|
|
|
|
if (oldValue.IsEmpty()) {
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::command, oldValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!oldValue.IsEmpty()) {
|
|
|
|
RemoveBroadcaster(oldValue);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-24 19:01:07 -07:00
|
|
|
else if (aNamespaceID == kNameSpaceID_None &&
|
|
|
|
aValue &&
|
|
|
|
mNodeInfo->Equals(nsGkAtoms::window) &&
|
|
|
|
aName == nsGkAtoms::chromemargin) {
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
// Make sure the margin format is valid first
|
2012-02-13 18:00:56 -08:00
|
|
|
if (!attrValue.ParseIntMarginValue(aValue->String())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2010-06-24 19:01:07 -07:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
return nsStyledElement::BeforeSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2012-02-13 18:00:56 -08:00
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2012-07-19 02:14:27 -07:00
|
|
|
if (aValue) {
|
|
|
|
// Add popup and event listeners. We can't call AddListenerFor since
|
|
|
|
// the attribute isn't set yet.
|
|
|
|
MaybeAddPopupListener(aName);
|
|
|
|
if (nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL)) {
|
|
|
|
if (aValue->Type() == nsAttrValue::eString) {
|
2012-08-30 09:25:10 -07:00
|
|
|
SetEventHandler(aName, aValue->GetStringValue(), true);
|
2012-07-19 02:14:27 -07:00
|
|
|
} else {
|
|
|
|
nsAutoString body;
|
|
|
|
aValue->ToString(body);
|
2012-08-30 09:25:10 -07:00
|
|
|
SetEventHandler(aName, body, true);
|
2012-07-19 02:14:27 -07:00
|
|
|
}
|
2012-02-13 18:00:56 -08:00
|
|
|
}
|
2012-07-19 02:14:27 -07:00
|
|
|
|
2013-02-04 15:22:51 -08:00
|
|
|
nsIDocument *document = GetCurrentDoc();
|
|
|
|
|
2012-07-19 02:14:27 -07:00
|
|
|
// Hide chrome if needed
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::chromemargin) {
|
|
|
|
SetChromeMargins(aValue);
|
|
|
|
}
|
2013-02-04 15:22:51 -08:00
|
|
|
|
|
|
|
else if (aName == nsGkAtoms::windowtype &&
|
|
|
|
document && document->GetRootElement() == this) {
|
|
|
|
MaybeUpdatePrivateLifetime();
|
|
|
|
}
|
2009-07-29 11:33:53 -07:00
|
|
|
}
|
2012-07-19 02:14:27 -07:00
|
|
|
// title, (in)activetitlebarcolor and drawintitlebar are settable on
|
|
|
|
// any root node (windows, dialogs, etc)
|
|
|
|
if (document && document->GetRootElement() == this) {
|
|
|
|
if (aName == nsGkAtoms::title) {
|
|
|
|
document->NotifyPossibleTitleChange(false);
|
|
|
|
}
|
|
|
|
else if ((aName == nsGkAtoms::activetitlebarcolor ||
|
|
|
|
aName == nsGkAtoms::inactivetitlebarcolor)) {
|
|
|
|
nscolor color = NS_RGBA(0, 0, 0, 0);
|
|
|
|
if (aValue->Type() == nsAttrValue::eColor) {
|
|
|
|
aValue->GetColorValue(color);
|
|
|
|
} else {
|
|
|
|
nsAutoString tmp;
|
|
|
|
nsAttrValue attrValue;
|
|
|
|
aValue->ToString(tmp);
|
|
|
|
attrValue.ParseColor(tmp);
|
|
|
|
attrValue.GetColorValue(color);
|
|
|
|
}
|
|
|
|
SetTitlebarColor(color, aName == nsGkAtoms::activetitlebarcolor);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::drawintitlebar) {
|
|
|
|
SetDrawsInTitlebar(
|
|
|
|
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::localedir) {
|
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::lwtheme ||
|
|
|
|
aName == nsGkAtoms::lwthemetextcolor) {
|
|
|
|
// if the lwtheme changed, make sure to reset the document lwtheme cache
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(document);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentLWTheme();
|
|
|
|
}
|
2012-02-13 18:00:56 -08:00
|
|
|
}
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
2012-07-19 02:14:27 -07:00
|
|
|
|
|
|
|
if (aName == nsGkAtoms::src && document) {
|
|
|
|
LoadSrc();
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
2012-07-19 02:14:27 -07:00
|
|
|
} else {
|
|
|
|
if (mNodeInfo->Equals(nsGkAtoms::window)) {
|
|
|
|
if (aName == nsGkAtoms::hidechrome) {
|
|
|
|
HideWindowChrome(false);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::chromemargin) {
|
|
|
|
ResetChromeMargins();
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-19 02:14:27 -07:00
|
|
|
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (doc && doc->GetRootElement() == this) {
|
|
|
|
if ((aName == nsGkAtoms::activetitlebarcolor ||
|
|
|
|
aName == nsGkAtoms::inactivetitlebarcolor)) {
|
|
|
|
// Use 0, 0, 0, 0 as the "none" color.
|
|
|
|
SetTitlebarColor(NS_RGBA(0, 0, 0, 0), aName == nsGkAtoms::activetitlebarcolor);
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::localedir) {
|
|
|
|
// if the localedir changed on the root element, reset the document direction
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentDirection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((aName == nsGkAtoms::lwtheme ||
|
|
|
|
aName == nsGkAtoms::lwthemetextcolor)) {
|
|
|
|
// if the lwtheme changed, make sure to restyle appropriately
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(doc);
|
|
|
|
if (xuldoc) {
|
|
|
|
xuldoc->ResetDocumentLWTheme();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aName == nsGkAtoms::drawintitlebar) {
|
|
|
|
SetDrawsInTitlebar(false);
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
2009-10-01 23:22:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX need to check if they're changing an event handler: if
|
|
|
|
// so, then we need to unhook the old one. Or something.
|
|
|
|
}
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
return nsStyledElement::AfterSetAttr(aNamespaceID, aName,
|
|
|
|
aValue, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::ParseAttribute(int32_t aNamespaceID,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
// Parse into a nsAttrValue
|
2010-02-23 20:37:46 -08:00
|
|
|
if (!nsStyledElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
|
|
|
aResult)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Fall back to parsing as atom for short values
|
|
|
|
aResult.ParseStringOrAtom(aValue);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-01-29 07:12:34 -08:00
|
|
|
void
|
|
|
|
nsXULElement::RemoveBroadcaster(const nsAString & broadcasterId)
|
|
|
|
{
|
2011-10-18 03:53:36 -07:00
|
|
|
nsCOMPtr<nsIDOMXULDocument> xuldoc = do_QueryInterface(OwnerDoc());
|
2008-01-29 07:12:34 -08:00
|
|
|
if (xuldoc) {
|
|
|
|
nsCOMPtr<nsIDOMElement> broadcaster;
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc (do_QueryInterface(xuldoc));
|
|
|
|
domDoc->GetElementById(broadcasterId, getter_AddRefs(broadcaster));
|
|
|
|
if (broadcaster) {
|
|
|
|
xuldoc->RemoveBroadcastListenerFor(broadcaster, this,
|
|
|
|
NS_LITERAL_STRING("*"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-30 09:57:03 -08:00
|
|
|
void
|
|
|
|
nsXULElement::DestroyContent()
|
|
|
|
{
|
2008-03-21 04:18:10 -07:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
2007-11-30 09:57:03 -08:00
|
|
|
if (slots) {
|
2008-03-21 04:18:10 -07:00
|
|
|
NS_IF_RELEASE(slots->mControllers);
|
|
|
|
if (slots->mFrameLoader) {
|
|
|
|
slots->mFrameLoader->Destroy();
|
2012-07-30 07:20:58 -07:00
|
|
|
slots->mFrameLoader = nullptr;
|
2008-03-21 04:18:10 -07:00
|
|
|
}
|
2007-11-30 09:57:03 -08:00
|
|
|
}
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
nsStyledElement::DestroyContent();
|
2007-11-30 09:57:03 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-08-13 08:38:23 -07:00
|
|
|
nsCString prefix("XUL");
|
2007-03-22 10:30:00 -07:00
|
|
|
if (HasSlots()) {
|
|
|
|
prefix.Append('*');
|
|
|
|
}
|
|
|
|
prefix.Append(' ');
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
nsStyledElement::List(out, aIndent, prefix);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
aVisitor.mForceContentDispatch = true; //FIXME! Bug 329119
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* tag = Tag();
|
2009-06-23 03:07:39 -07:00
|
|
|
if (IsRootOfNativeAnonymousSubtree() &&
|
|
|
|
(tag == nsGkAtoms::scrollbar || tag == nsGkAtoms::scrollcorner) &&
|
|
|
|
(aVisitor.mEvent->message == NS_MOUSE_CLICK ||
|
|
|
|
aVisitor.mEvent->message == NS_MOUSE_DOUBLECLICK ||
|
|
|
|
aVisitor.mEvent->message == NS_XUL_COMMAND ||
|
2009-08-03 00:55:35 -07:00
|
|
|
aVisitor.mEvent->message == NS_CONTEXTMENU ||
|
|
|
|
aVisitor.mEvent->message == NS_DRAGDROP_START ||
|
|
|
|
aVisitor.mEvent->message == NS_DRAGDROP_GESTURE)) {
|
2009-06-23 03:07:39 -07:00
|
|
|
// Don't propagate these events from native anonymous scrollbar.
|
2011-10-17 07:59:28 -07:00
|
|
|
aVisitor.mCanHandle = true;
|
2012-07-30 07:20:58 -07:00
|
|
|
aVisitor.mParentTarget = nullptr;
|
2009-06-23 03:07:39 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aVisitor.mEvent->message == NS_XUL_COMMAND &&
|
2009-06-30 00:56:40 -07:00
|
|
|
aVisitor.mEvent->eventStructType == NS_INPUT_EVENT &&
|
2007-07-08 00:08:04 -07:00
|
|
|
aVisitor.mEvent->originalTarget == static_cast<nsIContent*>(this) &&
|
2007-03-22 10:30:00 -07:00
|
|
|
tag != nsGkAtoms::command) {
|
2009-06-30 00:56:40 -07:00
|
|
|
// Check that we really have an xul command event. That will be handled
|
|
|
|
// in a special way.
|
|
|
|
nsCOMPtr<nsIDOMXULCommandEvent> xulEvent =
|
|
|
|
do_QueryInterface(aVisitor.mDOMEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if we have a command elt. If so, we execute on the command
|
|
|
|
// instead of on our content element.
|
|
|
|
nsAutoString command;
|
2009-06-30 00:56:40 -07:00
|
|
|
if (xulEvent && GetAttr(kNameSpaceID_None, nsGkAtoms::command, command) &&
|
|
|
|
!command.IsEmpty()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Stop building the event target chain for the original event.
|
|
|
|
// We don't want it to propagate to any DOM nodes.
|
2011-10-17 07:59:28 -07:00
|
|
|
aVisitor.mCanHandle = false;
|
2013-01-03 07:17:36 -08:00
|
|
|
aVisitor.mAutomaticChromeDispatch = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(GetCurrentDoc()));
|
|
|
|
NS_ENSURE_STATE(domDoc);
|
|
|
|
nsCOMPtr<nsIDOMElement> commandElt;
|
|
|
|
domDoc->GetElementById(command, getter_AddRefs(commandElt));
|
|
|
|
nsCOMPtr<nsIContent> commandContent(do_QueryInterface(commandElt));
|
|
|
|
if (commandContent) {
|
|
|
|
// Create a new command event to dispatch to the element
|
|
|
|
// pointed to by the command attribute. The new event's
|
|
|
|
// sourceEvent will be the original command event that we're
|
|
|
|
// handling.
|
2012-08-04 00:44:00 -07:00
|
|
|
nsCOMPtr<nsIDOMEvent> domEvent = aVisitor.mDOMEvent;
|
|
|
|
while (domEvent) {
|
2013-04-05 17:44:15 -07:00
|
|
|
nsDOMEvent* event = domEvent->InternalDOMEvent();
|
|
|
|
NS_ENSURE_STATE(!SameCOMIdentity(event->GetOriginalTarget(),
|
|
|
|
commandContent));
|
2008-06-04 13:23:37 -07:00
|
|
|
nsCOMPtr<nsIDOMXULCommandEvent> commandEvent =
|
2012-08-04 00:44:00 -07:00
|
|
|
do_QueryInterface(domEvent);
|
2008-06-04 13:23:37 -07:00
|
|
|
if (commandEvent) {
|
2012-08-04 00:44:00 -07:00
|
|
|
commandEvent->GetSourceEvent(getter_AddRefs(domEvent));
|
|
|
|
} else {
|
2013-04-02 18:14:24 -07:00
|
|
|
domEvent = nullptr;
|
2008-06-04 13:23:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 00:56:40 -07:00
|
|
|
nsInputEvent* orig =
|
|
|
|
static_cast<nsInputEvent*>(aVisitor.mEvent);
|
|
|
|
nsContentUtils::DispatchXULCommand(
|
|
|
|
commandContent,
|
2012-12-15 17:26:03 -08:00
|
|
|
aVisitor.mEvent->mFlags.mIsTrusted,
|
2009-06-30 00:56:40 -07:00
|
|
|
aVisitor.mDOMEvent,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr,
|
2012-04-24 20:00:02 -07:00
|
|
|
orig->IsControl(),
|
|
|
|
orig->IsAlt(),
|
|
|
|
orig->IsShift(),
|
|
|
|
orig->IsMeta());
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
NS_WARNING("A XUL element is attached to a command that doesn't exist!\n");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-23 20:37:46 -08:00
|
|
|
return nsStyledElement::PreHandleEvent(aVisitor);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX This _should_ be an implementation method, _not_ publicly exposed :-(
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetResource(nsIRDFResource** aResource)
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
*aResource = GetResource(rv).get();
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIRDFResource>
|
|
|
|
nsXULElement::GetResource(ErrorResult& rv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsAutoString id;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::ref, id);
|
|
|
|
if (id.IsEmpty()) {
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, id);
|
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
if (id.IsEmpty()) {
|
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
nsCOMPtr<nsIRDFResource> resource;
|
|
|
|
rv = nsXULContentUtils::RDFService()->
|
|
|
|
GetUnicodeResource(id, getter_AddRefs(resource));
|
|
|
|
return resource.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetDatabase(nsIRDFCompositeDataSource** aDatabase)
|
|
|
|
{
|
2013-01-29 09:51:55 -08:00
|
|
|
*aDatabase = GetDatabase().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
already_AddRefed<nsIRDFCompositeDataSource>
|
|
|
|
nsXULElement::GetDatabase()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder = GetBuilder();
|
|
|
|
if (!builder) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
nsCOMPtr<nsIRDFCompositeDataSource> database;
|
|
|
|
builder->GetDatabase(getter_AddRefs(database));
|
|
|
|
return database.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetBuilder(nsIXULTemplateBuilder** aBuilder)
|
|
|
|
{
|
2013-01-29 09:51:55 -08:00
|
|
|
*aBuilder = GetBuilder().get();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
already_AddRefed<nsIXULTemplateBuilder>
|
|
|
|
nsXULElement::GetBuilder()
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
|
|
|
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(GetCurrentDoc());
|
2013-01-29 09:51:55 -08:00
|
|
|
if (!xuldoc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
nsCOMPtr<nsIXULTemplateBuilder> builder;
|
|
|
|
xuldoc->GetTemplateBuilderFor(this, getter_AddRefs(builder));
|
|
|
|
return builder.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// Implementation methods
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsChangeHint
|
|
|
|
nsXULElement::GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsChangeHint retval(NS_STYLE_HINT_NONE);
|
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::value &&
|
|
|
|
(aModType == nsIDOMMutationEvent::REMOVAL ||
|
|
|
|
aModType == nsIDOMMutationEvent::ADDITION)) {
|
|
|
|
nsIAtom *tag = Tag();
|
|
|
|
if (tag == nsGkAtoms::label || tag == nsGkAtoms::description)
|
|
|
|
// Label and description dynamically morph between a normal
|
|
|
|
// block and a cropping single-line XUL text frame. If the
|
|
|
|
// value attribute is being added or removed, then we need to
|
|
|
|
// return a hint of frame change. (See bugzilla bug 95475 for
|
|
|
|
// details.)
|
|
|
|
retval = NS_STYLE_HINT_FRAMECHANGE;
|
|
|
|
} else {
|
|
|
|
// if left or top changes we reflow. This will happen in xul
|
2009-07-29 11:33:53 -07:00
|
|
|
// containers that manage positioned children such as a stack.
|
2009-09-13 14:13:54 -07:00
|
|
|
if (nsGkAtoms::left == aAttribute || nsGkAtoms::top == aAttribute ||
|
2011-02-28 10:06:29 -08:00
|
|
|
nsGkAtoms::right == aAttribute || nsGkAtoms::bottom == aAttribute ||
|
|
|
|
nsGkAtoms::start == aAttribute || nsGkAtoms::end == aAttribute)
|
2007-03-22 10:30:00 -07:00
|
|
|
retval = NS_STYLE_HINT_REFLOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Controllers Methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetControllers(nsIControllers** aResult)
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
NS_IF_ADDREF(*aResult = GetControllers(rv));
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIControllers*
|
|
|
|
nsXULElement::GetControllers(ErrorResult& rv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (! Controllers()) {
|
2010-12-21 17:04:00 -08:00
|
|
|
nsDOMSlots* slots = DOMSlots();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = NS_NewXULControllers(nullptr, NS_GET_IID(nsIControllers),
|
2007-07-08 00:08:04 -07:00
|
|
|
reinterpret_cast<void**>(&slots->mControllers));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv.ErrorCode()),
|
|
|
|
"unable to create a controllers");
|
|
|
|
if (rv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
return Controllers();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
2013-01-29 09:51:55 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
*aResult = GetBoxObject(rv).get();
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
already_AddRefed<nsIBoxObject>
|
|
|
|
nsXULElement::GetBoxObject(ErrorResult& rv)
|
|
|
|
{
|
|
|
|
// XXX sXBL/XBL2 issue! Owner or current document?
|
2013-03-26 08:31:53 -07:00
|
|
|
return OwnerDoc()->GetBoxObjectFor(this, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods for setting/getting attributes from nsIDOMXULElement
|
|
|
|
#define NS_IMPL_XUL_STRING_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Get##_method(nsAString& aReturn) \
|
|
|
|
{ \
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aReturn); \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
nsXULElement::Set##_method(const nsAString& aValue) \
|
|
|
|
{ \
|
|
|
|
return SetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue, \
|
2011-10-17 07:59:28 -07:00
|
|
|
true); \
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NS_IMPL_XUL_BOOL_ATTR(_method, _atom) \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 09:51:55 -08:00
|
|
|
nsXULElement::Get##_method(bool* aResult) \
|
2007-03-22 10:30:00 -07:00
|
|
|
{ \
|
2013-01-29 09:51:55 -08:00
|
|
|
*aResult = _method(); \
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
NS_IMETHODIMP \
|
2013-01-29 09:51:55 -08:00
|
|
|
nsXULElement::Set##_method(bool aValue) \
|
2007-03-22 10:30:00 -07:00
|
|
|
{ \
|
2013-01-29 09:51:55 -08:00
|
|
|
SetXULBoolAttr(nsGkAtoms::_atom, aValue); \
|
|
|
|
return NS_OK; \
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(ClassName, _class)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Align, align)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Dir, dir)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Flex, flex)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(FlexGroup, flexgroup)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Ordinal, ordinal)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Orient, orient)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Pack, pack)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(Hidden, hidden)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(Collapsed, collapsed)
|
|
|
|
NS_IMPL_XUL_BOOL_ATTR(AllowEvents, allowevents)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Observes, observes)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Menu, menu)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(ContextMenu, contextmenu)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Tooltip, tooltip)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Width, width)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Height, height)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MinWidth, minwidth)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MinHeight, minheight)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MaxWidth, maxwidth)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(MaxHeight, maxheight)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Persist, persist)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Left, left)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Top, top)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Datasources, datasources)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(Ref, ref)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(TooltipText, tooltiptext)
|
|
|
|
NS_IMPL_XUL_STRING_ATTR(StatusText, statustext)
|
|
|
|
|
2008-03-21 04:18:10 -07:00
|
|
|
nsresult
|
|
|
|
nsXULElement::LoadSrc()
|
|
|
|
{
|
|
|
|
// Allow frame loader only on objects for which a container box object
|
|
|
|
// can be obtained.
|
|
|
|
nsIAtom* tag = Tag();
|
|
|
|
if (tag != nsGkAtoms::browser &&
|
|
|
|
tag != nsGkAtoms::editor &&
|
|
|
|
tag != nsGkAtoms::iframe) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (!IsInDoc() ||
|
2011-10-18 03:53:36 -07:00
|
|
|
!OwnerDoc()->GetRootElement() ||
|
|
|
|
OwnerDoc()->GetRootElement()->
|
2008-03-21 04:18:10 -07:00
|
|
|
NodeInfo()->Equals(nsGkAtoms::overlay, kNameSpaceID_XUL)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-10 15:27:28 -07:00
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(Slots());
|
2008-03-21 04:18:10 -07:00
|
|
|
if (!slots->mFrameLoader) {
|
2011-10-17 07:59:28 -07:00
|
|
|
// false as the last parameter so that xul:iframe/browser/editor
|
2010-08-17 07:13:55 -07:00
|
|
|
// session history handling works like dynamic html:iframes.
|
|
|
|
// Usually xul elements are used in chrome, which doesn't have
|
|
|
|
// session history at all.
|
2011-10-17 07:59:28 -07:00
|
|
|
slots->mFrameLoader = nsFrameLoader::Create(this, false);
|
2009-08-19 02:09:26 -07:00
|
|
|
NS_ENSURE_TRUE(slots->mFrameLoader, NS_OK);
|
2008-03-21 04:18:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return slots->mFrameLoader->LoadFrame();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
|
|
|
|
{
|
2009-10-20 14:33:59 -07:00
|
|
|
*aFrameLoader = GetFrameLoader().get();
|
2008-03-21 04:18:10 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-20 14:33:59 -07:00
|
|
|
already_AddRefed<nsFrameLoader>
|
|
|
|
nsXULElement::GetFrameLoader()
|
|
|
|
{
|
|
|
|
nsXULSlots* slots = static_cast<nsXULSlots*>(GetExistingSlots());
|
|
|
|
if (!slots)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-20 14:33:59 -07:00
|
|
|
|
2013-04-22 04:15:59 -07:00
|
|
|
nsRefPtr<nsFrameLoader> loader = slots->mFrameLoader;
|
|
|
|
return loader.forget();
|
2009-10-20 14:33:59 -07:00
|
|
|
}
|
|
|
|
|
2008-08-11 01:38:43 -07:00
|
|
|
nsresult
|
|
|
|
nsXULElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContent> otherContent(do_QueryInterface(aOtherOwner));
|
|
|
|
NS_ENSURE_TRUE(otherContent, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
|
|
|
|
nsXULElement* otherEl = FromContent(otherContent);
|
|
|
|
NS_ENSURE_TRUE(otherEl, NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
SwapFrameLoaders(*otherEl, rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::SwapFrameLoaders(nsXULElement& aOtherElement, ErrorResult& rv)
|
|
|
|
{
|
|
|
|
if (&aOtherElement == this) {
|
2008-08-11 01:38:43 -07:00
|
|
|
// nothing to do
|
2013-01-29 09:51:55 -08:00
|
|
|
return;
|
2008-08-11 01:38:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXULSlots *ourSlots = static_cast<nsXULSlots*>(GetExistingDOMSlots());
|
|
|
|
nsXULSlots *otherSlots =
|
2013-01-29 09:51:55 -08:00
|
|
|
static_cast<nsXULSlots*>(aOtherElement.GetExistingDOMSlots());
|
2008-08-11 01:38:43 -07:00
|
|
|
if (!ourSlots || !ourSlots->mFrameLoader ||
|
|
|
|
!otherSlots || !otherSlots->mFrameLoader) {
|
|
|
|
// Can't handle swapping when there is nothing to swap... yet.
|
2013-01-29 09:51:55 -08:00
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2008-08-11 01:38:43 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
rv = ourSlots->mFrameLoader->SwapWithOtherLoader(otherSlots->mFrameLoader,
|
|
|
|
ourSlots->mFrameLoader,
|
|
|
|
otherSlots->mFrameLoader);
|
2008-08-11 01:38:43 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::GetParentTree(nsIDOMXULMultiSelectControlElement** aTreeElement)
|
|
|
|
{
|
|
|
|
for (nsIContent* current = GetParent(); current;
|
|
|
|
current = current->GetParent()) {
|
|
|
|
if (current->NodeInfo()->Equals(nsGkAtoms::listbox,
|
|
|
|
kNameSpaceID_XUL)) {
|
|
|
|
CallQueryInterface(current, aTreeElement);
|
|
|
|
// XXX returning NS_OK because that's what the code used to do;
|
|
|
|
// is that the right thing, though?
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Focus()
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Focus(rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::Focus(ErrorResult& rv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2011-08-30 14:45:31 -07:00
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryObject(this);
|
2013-01-29 09:51:55 -08:00
|
|
|
if (fm) {
|
|
|
|
rv = fm->SetFocus(this, 0);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Blur()
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
Blur(rv);
|
|
|
|
return rv.ErrorCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::Blur(ErrorResult& rv)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
if (!ShouldBlur(this))
|
2013-01-29 09:51:55 -08:00
|
|
|
return;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
if (!doc)
|
2013-01-29 09:51:55 -08:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 11:00:39 -07:00
|
|
|
nsIDOMWindow* win = doc->GetWindow();
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
2013-01-29 09:51:55 -08:00
|
|
|
if (win && fm) {
|
|
|
|
rv = fm->ClearFocus(win);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::Click()
|
2010-04-06 05:59:24 -07:00
|
|
|
{
|
2011-08-26 00:43:56 -07:00
|
|
|
return ClickWithInputSource(nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN);
|
2010-04-06 05:59:24 -07:00
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
void
|
|
|
|
nsXULElement::Click(ErrorResult& rv)
|
|
|
|
{
|
|
|
|
rv = Click();
|
|
|
|
}
|
|
|
|
|
2010-04-06 05:59:24 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::ClickWithInputSource(uint16_t aInputSource)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (BoolAttrIsTrue(nsGkAtoms::disabled))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetCurrentDoc(); // Strong just in case
|
|
|
|
if (doc) {
|
2010-06-25 06:59:57 -07:00
|
|
|
nsCOMPtr<nsIPresShell> shell = doc->GetShell();
|
2010-01-07 02:36:11 -08:00
|
|
|
if (shell) {
|
2007-05-22 14:45:03 -07:00
|
|
|
// strong ref to PresContext so events don't destroy it
|
2010-03-25 06:17:11 -07:00
|
|
|
nsRefPtr<nsPresContext> context = shell->GetPresContext();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isCallerChrome = nsContentUtils::IsCallerChrome();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMouseEvent eventDown(isCallerChrome, NS_MOUSE_BUTTON_DOWN,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, nsMouseEvent::eReal);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent eventUp(isCallerChrome, NS_MOUSE_BUTTON_UP,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, nsMouseEvent::eReal);
|
|
|
|
nsMouseEvent eventClick(isCallerChrome, NS_MOUSE_CLICK, nullptr,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMouseEvent::eReal);
|
2010-04-06 05:59:24 -07:00
|
|
|
eventDown.inputSource = eventUp.inputSource = eventClick.inputSource
|
|
|
|
= aInputSource;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// send mouse down
|
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
2007-07-08 00:08:04 -07:00
|
|
|
nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
2012-07-30 07:20:58 -07:00
|
|
|
context, &eventDown, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// send mouse up
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2007-07-08 00:08:04 -07:00
|
|
|
nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
2012-07-30 07:20:58 -07:00
|
|
|
context, &eventUp, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// send mouse click
|
|
|
|
status = nsEventStatus_eIgnore; // reset status
|
2007-07-08 00:08:04 -07:00
|
|
|
nsEventDispatcher::Dispatch(static_cast<nsIContent*>(this),
|
2012-07-30 07:20:58 -07:00
|
|
|
context, &eventClick, nullptr, &status);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// oncommand is fired when an element is clicked...
|
|
|
|
return DoCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXULElement::DoCommand()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetCurrentDoc(); // strong just in case
|
|
|
|
if (doc) {
|
2011-10-17 07:59:28 -07:00
|
|
|
nsContentUtils::DispatchXULCommand(this, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *
|
|
|
|
nsXULElement::GetBindingParent() const
|
|
|
|
{
|
|
|
|
return mBindingParent;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULElement::IsNodeOfType(uint32_t aFlags) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
return !(aFlags & ~eCONTENT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULElement::AddPopupListener(nsIAtom* aName)
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
// Add a popup listener to the element
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isContext = (aName == nsGkAtoms::context ||
|
2007-07-04 08:49:38 -07:00
|
|
|
aName == nsGkAtoms::contextmenu);
|
2012-10-16 05:37:26 -07:00
|
|
|
uint32_t listenerFlag = isContext ?
|
|
|
|
XUL_ELEMENT_HAS_CONTENTMENU_LISTENER :
|
|
|
|
XUL_ELEMENT_HAS_POPUP_LISTENER;
|
|
|
|
|
|
|
|
if (HasFlag(listenerFlag)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-29 15:15:59 -07:00
|
|
|
|
2012-10-16 05:37:26 -07:00
|
|
|
nsCOMPtr<nsIDOMEventListener> listener =
|
|
|
|
new nsXULPopupListener(this, isContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Add the popup as a listener on this element.
|
2011-10-17 07:59:28 -07:00
|
|
|
nsEventListenerManager* manager = GetListenerManager(true);
|
2012-10-16 05:37:26 -07:00
|
|
|
SetFlags(listenerFlag);
|
2009-06-23 03:07:39 -07:00
|
|
|
|
|
|
|
if (isContext) {
|
2011-06-23 19:18:02 -07:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("contextmenu"),
|
2012-12-15 17:26:05 -08:00
|
|
|
dom::TrustedEventsAtSystemGroupBubble());
|
2009-06-23 03:07:39 -07:00
|
|
|
} else {
|
2011-06-23 19:18:02 -07:00
|
|
|
manager->AddEventListenerByType(listener,
|
|
|
|
NS_LITERAL_STRING("mousedown"),
|
2012-12-15 17:26:05 -08:00
|
|
|
dom::TrustedEventsAtSystemGroupBubble());
|
2009-06-23 03:07:39 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates
|
2007-06-27 19:48:16 -07:00
|
|
|
nsXULElement::IntrinsicState() const
|
|
|
|
{
|
2010-10-20 04:26:32 -07:00
|
|
|
nsEventStates state = nsStyledElement::IntrinsicState();
|
2007-06-27 19:48:16 -07:00
|
|
|
|
2011-05-31 18:46:57 -07:00
|
|
|
if (IsReadWriteTextElement()) {
|
2007-06-27 19:48:16 -07:00
|
|
|
state |= NS_EVENT_STATE_MOZ_READWRITE;
|
|
|
|
state &= ~NS_EVENT_STATE_MOZ_READONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2012-07-14 08:28:54 -07:00
|
|
|
nsresult
|
|
|
|
nsXULElement::MakeHeavyweight(nsXULPrototypeElement* aPrototype)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-14 08:28:54 -07:00
|
|
|
if (!aPrototype) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
2012-07-14 08:28:54 -07:00
|
|
|
for (i = 0; i < aPrototype->mNumAttributes; ++i) {
|
|
|
|
nsXULPrototypeAttribute* protoattr = &aPrototype->mAttributes[i];
|
2010-08-12 23:03:23 -07:00
|
|
|
nsAttrValue attrValue;
|
2007-04-29 10:58:52 -07:00
|
|
|
|
|
|
|
// Style rules need to be cloned.
|
2010-08-12 23:03:23 -07:00
|
|
|
if (protoattr->mValue.Type() == nsAttrValue::eCSSStyleRule) {
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<css::Rule> ruleClone =
|
2010-08-15 08:19:34 -07:00
|
|
|
protoattr->mValue.GetCSSStyleRuleValue()->Clone();
|
2007-04-29 10:58:52 -07:00
|
|
|
|
2010-08-12 23:03:23 -07:00
|
|
|
nsString stringValue;
|
|
|
|
protoattr->mValue.ToString(stringValue);
|
|
|
|
|
2011-03-10 18:48:57 -08:00
|
|
|
nsRefPtr<css::StyleRule> styleRule = do_QueryObject(ruleClone);
|
2010-08-12 23:03:23 -07:00
|
|
|
attrValue.SetTo(styleRule, &stringValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
attrValue.SetTo(protoattr->mValue);
|
2007-04-29 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
2010-08-12 23:03:23 -07:00
|
|
|
// XXX we might wanna have a SetAndTakeAttr that takes an nsAttrName
|
2007-03-22 10:30:00 -07:00
|
|
|
if (protoattr->mName.IsAtom()) {
|
|
|
|
rv = mAttrsAndChildren.SetAndTakeAttr(protoattr->mName.Atom(), attrValue);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = mAttrsAndChildren.SetAndTakeAttr(protoattr->mName.NodeInfo(),
|
|
|
|
attrValue);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::HideWindowChrome(bool aShouldHide)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
2010-04-30 06:12:05 -07:00
|
|
|
if (!doc || doc->GetRootElement() != this)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2007-08-20 23:44:43 -07:00
|
|
|
// only top level chrome documents can hide the window chrome
|
2008-10-04 13:00:09 -07:00
|
|
|
if (!doc->IsRootDisplayDocument())
|
2007-08-20 23:44:43 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-06-25 06:59:57 -07:00
|
|
|
nsIPresShell *shell = doc->GetShell();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (shell) {
|
2009-12-24 13:20:05 -08:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsPresContext *presContext = shell->GetPresContext();
|
|
|
|
|
2007-08-20 23:44:43 -07:00
|
|
|
if (frame && presContext && presContext->IsChrome()) {
|
2013-01-03 05:23:11 -08:00
|
|
|
nsView* view = frame->GetClosestView();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (view) {
|
|
|
|
nsIWidget* w = view->GetWidget();
|
|
|
|
NS_ENSURE_STATE(w);
|
|
|
|
w->HideWindowChrome(aShouldHide);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-10-21 00:05:34 -07:00
|
|
|
nsIWidget*
|
|
|
|
nsXULElement::GetWindowWidget()
|
2007-10-29 21:03:42 -07:00
|
|
|
{
|
|
|
|
nsIDocument* doc = GetCurrentDoc();
|
|
|
|
|
|
|
|
// only top level chrome documents can set the titlebar color
|
2008-10-04 13:00:09 -07:00
|
|
|
if (doc->IsRootDisplayDocument()) {
|
2007-10-29 21:03:42 -07:00
|
|
|
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(container);
|
|
|
|
if (baseWindow) {
|
|
|
|
nsCOMPtr<nsIWidget> mainWidget;
|
|
|
|
baseWindow->GetMainWidget(getter_AddRefs(mainWidget));
|
2009-10-21 00:05:34 -07:00
|
|
|
return mainWidget;
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::SetTitlebarColor(nscolor aColor, bool aActive)
|
2009-10-21 00:05:34 -07:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
|
|
|
mainWidget->SetWindowTitlebarColor(aColor, aActive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-04 04:59:33 -08:00
|
|
|
class SetDrawInTitleBarEvent : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
2011-09-28 23:19:26 -07:00
|
|
|
SetDrawInTitleBarEvent(nsIWidget* aWidget, bool aState)
|
2011-02-04 04:59:33 -08:00
|
|
|
: mWidget(aWidget)
|
|
|
|
, mState(aState)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
NS_ASSERTION(mWidget, "You shouldn't call this runnable with a null widget!");
|
|
|
|
|
|
|
|
mWidget->SetDrawsInTitlebar(mState);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mState;
|
2011-02-04 04:59:33 -08:00
|
|
|
};
|
|
|
|
|
2009-10-21 00:05:34 -07:00
|
|
|
void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsXULElement::SetDrawsInTitlebar(bool aState)
|
2009-10-21 00:05:34 -07:00
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (mainWidget) {
|
2011-02-09 16:45:54 -08:00
|
|
|
nsContentUtils::AddScriptRunner(new SetDrawInTitleBarEvent(mainWidget, aState));
|
2009-10-21 00:05:34 -07:00
|
|
|
}
|
2007-10-29 21:03:42 -07:00
|
|
|
}
|
|
|
|
|
2011-08-03 11:32:32 -07:00
|
|
|
class MarginSetter : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MarginSetter(nsIWidget* aWidget) :
|
|
|
|
mWidget(aWidget), mMargin(-1, -1, -1, -1)
|
|
|
|
{}
|
|
|
|
MarginSetter(nsIWidget *aWidget, const nsIntMargin& aMargin) :
|
|
|
|
mWidget(aWidget), mMargin(aMargin)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
// SetNonClientMargins can dispatch native events, hence doing
|
|
|
|
// it off a script runner.
|
|
|
|
mWidget->SetNonClientMargins(mMargin);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIWidget> mWidget;
|
|
|
|
nsIntMargin mMargin;
|
|
|
|
};
|
|
|
|
|
2010-06-24 19:01:07 -07:00
|
|
|
void
|
2012-02-13 18:00:56 -08:00
|
|
|
nsXULElement::SetChromeMargins(const nsAttrValue* aValue)
|
2010-06-24 19:01:07 -07:00
|
|
|
{
|
|
|
|
if (!aValue)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// top, right, bottom, left - see nsAttrValue
|
|
|
|
nsIntMargin margins;
|
2012-02-13 18:00:56 -08:00
|
|
|
bool gotMargins = false;
|
2010-06-24 19:01:07 -07:00
|
|
|
|
2012-02-13 18:00:56 -08:00
|
|
|
if (aValue->Type() == nsAttrValue::eIntMarginValue) {
|
|
|
|
gotMargins = aValue->GetIntMarginValue(margins);
|
|
|
|
} else {
|
|
|
|
nsAutoString tmp;
|
|
|
|
aValue->ToString(tmp);
|
|
|
|
gotMargins = nsContentUtils::ParseIntMarginValue(tmp, margins);
|
|
|
|
}
|
|
|
|
if (gotMargins) {
|
2011-08-03 11:32:32 -07:00
|
|
|
nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget, margins));
|
2010-06-24 19:01:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::ResetChromeMargins()
|
|
|
|
{
|
|
|
|
nsIWidget* mainWidget = GetWindowWidget();
|
|
|
|
if (!mainWidget)
|
|
|
|
return;
|
|
|
|
// See nsIWidget
|
2011-08-03 11:32:32 -07:00
|
|
|
nsContentUtils::AddScriptRunner(new MarginSetter(mainWidget));
|
2010-06-24 19:01:07 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-01-29 09:51:55 -08:00
|
|
|
nsXULElement::BoolAttrIsTrue(nsIAtom* aName) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
const nsAttrValue* attr =
|
2012-07-14 08:28:54 -07:00
|
|
|
GetAttrInfo(kNameSpaceID_None, aName).mValue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return attr && attr->Type() == nsAttrValue::eAtom &&
|
|
|
|
attr->GetAtomValue() == nsGkAtoms::_true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsXULElement::RecompileScriptEventListeners()
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t i, count = mAttrsAndChildren.AttrCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
|
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (!name->IsAtom()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *attr = name->Atom();
|
2007-04-02 10:17:36 -07:00
|
|
|
if (!nsContentUtils::IsEventAttributeName(attr, EventNameType_XUL)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 09:25:10 -07:00
|
|
|
SetEventHandler(attr, value, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-02 12:24:07 -08:00
|
|
|
bool
|
|
|
|
nsXULElement::IsEventAttributeName(nsIAtom *aName)
|
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_XUL);
|
|
|
|
}
|
|
|
|
|
2013-01-29 09:51:55 -08:00
|
|
|
JSObject*
|
2013-04-25 09:29:54 -07:00
|
|
|
nsXULElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aScope)
|
2013-01-29 09:51:55 -08:00
|
|
|
{
|
2013-03-11 16:03:47 -07:00
|
|
|
return dom::XULElementBinding::Wrap(aCx, aScope, this);
|
2013-01-29 09:51:55 -08:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:29:05 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeNode)
|
|
|
|
|
2012-11-22 09:15:38 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULPrototypeNode)
|
2007-11-01 15:51:57 -07:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
static_cast<nsXULPrototypeElement*>(tmp)->Unlink();
|
|
|
|
}
|
2010-11-08 07:02:49 -08:00
|
|
|
else if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
|
|
|
static_cast<nsXULPrototypeScript*>(tmp)->UnlinkJSObjects();
|
|
|
|
}
|
2007-11-01 15:51:57 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-11-22 09:15:38 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeNode)
|
2007-05-24 07:10:02 -07:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
nsXULPrototypeElement *elem =
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsXULPrototypeElement*>(tmp);
|
2012-01-23 15:25:53 -08:00
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mNodeInfo");
|
2008-03-28 07:09:00 -07:00
|
|
|
cb.NoteXPCOMChild(elem->mNodeInfo);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2008-03-28 07:09:00 -07:00
|
|
|
for (i = 0; i < elem->mNumAttributes; ++i) {
|
|
|
|
const nsAttrName& name = elem->mAttributes[i].mName;
|
2012-01-23 15:25:53 -08:00
|
|
|
if (!name.IsAtom()) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb,
|
|
|
|
"mAttributes[i].mName.NodeInfo()");
|
2008-03-28 07:09:00 -07:00
|
|
|
cb.NoteXPCOMChild(name.NodeInfo());
|
2012-01-23 15:25:53 -08:00
|
|
|
}
|
2008-03-28 07:09:00 -07:00
|
|
|
}
|
2012-11-14 23:32:39 -08:00
|
|
|
ImplCycleCollectionTraverse(cb, elem->mChildren, "mChildren");
|
2007-05-24 07:10:02 -07:00
|
|
|
}
|
2007-10-29 06:45:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2012-11-23 11:27:06 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsXULPrototypeNode)
|
2012-07-19 02:18:01 -07:00
|
|
|
if (tmp->mType == nsXULPrototypeNode::eType_Script) {
|
2007-10-29 06:45:07 -07:00
|
|
|
nsXULPrototypeScript *script =
|
|
|
|
static_cast<nsXULPrototypeScript*>(tmp);
|
2013-05-27 04:50:49 -07:00
|
|
|
script->Trace(aCallbacks, aClosure);
|
2007-05-24 07:10:02 -07:00
|
|
|
}
|
2007-10-29 06:45:07 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
2012-04-30 15:54:16 -07:00
|
|
|
|
2012-08-24 09:50:06 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(nsXULPrototypeNode, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXULPrototypeNode, Release)
|
2007-05-24 07:10:02 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeAttribute
|
|
|
|
//
|
|
|
|
|
|
|
|
nsXULPrototypeAttribute::~nsXULPrototypeAttribute()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsXULPrototypeAttribute);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeElement
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
|
|
|
// Write Node Info
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = aNodeInfos->IndexOf(mNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(index >= 0, "unknown nsINodeInfo index");
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Write Attributes
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Write32(mNumAttributes);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString attributeValue;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
for (i = 0; i < mNumAttributes; ++i) {
|
|
|
|
nsCOMPtr<nsINodeInfo> ni;
|
|
|
|
if (mAttributes[i].mName.IsAtom()) {
|
2008-09-12 15:32:18 -07:00
|
|
|
ni = mNodeInfo->NodeInfoManager()->
|
2012-07-30 07:20:58 -07:00
|
|
|
GetNodeInfo(mAttributes[i].mName.Atom(), nullptr,
|
2011-06-14 00:56:49 -07:00
|
|
|
kNameSpaceID_None,
|
|
|
|
nsIDOMNode::ATTRIBUTE_NODE);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(ni, "the nodeinfo should already exist");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ni = mAttributes[i].mName.NodeInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
index = aNodeInfos->IndexOf(ni);
|
|
|
|
NS_ASSERTION(index >= 0, "unknown nsINodeInfo index");
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Write32(index);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mAttributes[i].mValue.ToString(attributeValue);
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteWStringZ(attributeValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now write children
|
2012-08-22 08:56:38 -07:00
|
|
|
tmp = aStream->Write32(uint32_t(mChildren.Length()));
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2008-10-08 04:41:52 -07:00
|
|
|
for (i = 0; i < mChildren.Length(); i++) {
|
|
|
|
nsXULPrototypeNode* child = mChildren[i].get();
|
2007-03-22 10:30:00 -07:00
|
|
|
switch (child->mType) {
|
|
|
|
case eType_Element:
|
|
|
|
case eType_Text:
|
|
|
|
case eType_PI:
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = child->Serialize(aStream, aGlobal, aNodeInfos);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eType_Script:
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Write32(child->mType);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-07-08 00:08:04 -07:00
|
|
|
nsXULPrototypeScript* script = static_cast<nsXULPrototypeScript*>(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Write8(script->mOutOfLine);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! script->mOutOfLine) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = script->Serialize(aStream, aGlobal, aNodeInfos);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->WriteCompoundObject(script->mSrcURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_GET_IID(nsIURI),
|
2011-10-17 07:59:28 -07:00
|
|
|
true);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-24 13:22:23 -07:00
|
|
|
if (script->GetScriptObject()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// This may return NS_OK without muxing script->mSrcURI's
|
2010-08-12 12:42:36 -07:00
|
|
|
// data into the cache file, in the case where that
|
2007-03-22 10:30:00 -07:00
|
|
|
// muxed document is already there (written by a prior
|
2010-08-12 12:42:36 -07:00
|
|
|
// session, or by an earlier cache episode during this
|
2007-03-22 10:30:00 -07:00
|
|
|
// session).
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = script->SerializeOutOfLine(aStream, aGlobal);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
nsIURI* aDocumentURI,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aNodeInfos, "missing nodeinfo array");
|
|
|
|
|
|
|
|
// Read Node Info
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t number;
|
2012-04-11 07:48:14 -07:00
|
|
|
nsresult rv = aStream->Read32(&number);
|
2007-03-22 10:30:00 -07:00
|
|
|
mNodeInfo = aNodeInfos->SafeObjectAt(number);
|
|
|
|
if (!mNodeInfo)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// Read Attributes
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
mNumAttributes = int32_t(number);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mNumAttributes > 0) {
|
|
|
|
mAttributes = new nsXULPrototypeAttribute[mNumAttributes];
|
|
|
|
if (! mAttributes)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
nsAutoString attributeValue;
|
|
|
|
for (i = 0; i < mNumAttributes; ++i) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
nsINodeInfo* ni = aNodeInfos->SafeObjectAt(number);
|
|
|
|
if (!ni)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
mAttributes[i].mName.SetTo(ni);
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadString(attributeValue);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = SetAttrAt(i, attributeValue, aDocumentURI);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t numChildren = int32_t(number);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
if (numChildren > 0) {
|
2013-03-21 11:56:07 -07:00
|
|
|
mChildren.SetCapacity(numChildren);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
for (i = 0; i < numChildren; i++) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->Read32(&number);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
Type childType = (Type)number;
|
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
nsRefPtr<nsXULPrototypeNode> child;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
switch (childType) {
|
|
|
|
case eType_Element:
|
|
|
|
child = new nsXULPrototypeElement();
|
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
aNodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eType_Text:
|
|
|
|
child = new nsXULPrototypeText();
|
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
aNodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eType_PI:
|
|
|
|
child = new nsXULPrototypePI();
|
|
|
|
if (! child)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = child->Deserialize(aStream, aGlobal, aDocumentURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
aNodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
case eType_Script: {
|
|
|
|
// language version/options obtained during deserialization.
|
2012-04-24 15:31:28 -07:00
|
|
|
nsXULPrototypeScript* script = new nsXULPrototypeScript(0, 0);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! script)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
child = script;
|
|
|
|
child->mType = childType;
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadBoolean(&script->mOutOfLine);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (! script->mOutOfLine) {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = script->Deserialize(aStream, aGlobal, aDocumentURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
aNodeInfos);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = aStream->ReadObject(true, getter_AddRefs(script->mSrcURI));
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
tmp = script->DeserializeOutOfLine(aStream, aGlobal);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// If we failed to deserialize, consider deleting 'script'?
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Unexpected child type!");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2008-10-08 04:41:52 -07:00
|
|
|
mChildren.AppendElement(child);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Oh dear. Something failed during the deserialization.
|
|
|
|
// We don't know what. But likely consequences of failed
|
2010-08-12 12:42:36 -07:00
|
|
|
// deserializations included calls to |AbortCaching| which
|
|
|
|
// shuts down the cache and closes our streams.
|
2007-03-22 10:30:00 -07:00
|
|
|
// If that happens, next time through this loop, we die a messy
|
|
|
|
// death. So, let's just fail now, and propagate that failure
|
|
|
|
// upward so that the ChromeProtocolHandler knows it can't use
|
|
|
|
// a cached chrome channel for this.
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULPrototypeElement::SetAttrAt(uint32_t aPos, const nsAString& aValue,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* aDocumentURI)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPos < mNumAttributes, "out-of-bounds");
|
|
|
|
|
|
|
|
// WARNING!!
|
|
|
|
// This code is largely duplicated in nsXULElement::SetAttr.
|
|
|
|
// Any changes should be made to both functions.
|
|
|
|
|
|
|
|
if (!mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
|
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mAttributes[aPos].mName.Equals(nsGkAtoms::id) &&
|
|
|
|
!aValue.IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasIdAttribute = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Store id as atom.
|
|
|
|
// id="" means that the element has no id. Not that it has
|
|
|
|
// emptystring as id.
|
|
|
|
mAttributes[aPos].mValue.ParseAtom(aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mAttributes[aPos].mName.Equals(nsGkAtoms::_class)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasClassAttribute = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Compute the element's class list
|
|
|
|
mAttributes[aPos].mValue.ParseAtomArray(aValue);
|
2010-03-02 12:59:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (mAttributes[aPos].mName.Equals(nsGkAtoms::style)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mHasStyleAttribute = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Parse the element's 'style' attribute
|
2011-03-10 18:48:57 -08:00
|
|
|
nsRefPtr<css::StyleRule> rule;
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
nsCSSParser parser;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX Get correct Base URI (need GetBaseURI on *prototype* element)
|
2012-08-30 10:58:24 -07:00
|
|
|
// TODO: If we implement Content Security Policy for chrome documents
|
|
|
|
// as has been discussed, the CSP should be checked here to see if
|
|
|
|
// inline styles are allowed to be applied.
|
2010-03-02 12:59:32 -08:00
|
|
|
parser.ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
|
|
|
|
// This is basically duplicating what
|
|
|
|
// nsINode::NodePrincipal() does
|
|
|
|
mNodeInfo->NodeInfoManager()->
|
|
|
|
DocumentPrincipal(),
|
|
|
|
getter_AddRefs(rule));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rule) {
|
2010-08-12 23:03:23 -07:00
|
|
|
mAttributes[aPos].mValue.SetTo(rule, &aValue);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// Don't abort if parsing failed, it could just be malformed css.
|
|
|
|
}
|
|
|
|
|
|
|
|
mAttributes[aPos].mValue.ParseStringOrAtom(aValue);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-29 06:45:07 -07:00
|
|
|
void
|
2010-11-08 07:02:49 -08:00
|
|
|
nsXULPrototypeElement::Unlink()
|
2007-10-29 06:45:07 -07:00
|
|
|
{
|
|
|
|
mNumAttributes = 0;
|
|
|
|
delete[] mAttributes;
|
2012-07-30 07:20:58 -07:00
|
|
|
mAttributes = nullptr;
|
2013-08-06 17:37:05 -07:00
|
|
|
mChildren.Clear();
|
2007-10-29 06:45:07 -07:00
|
|
|
}
|
|
|
|
|
2012-08-24 13:22:23 -07:00
|
|
|
void
|
|
|
|
nsXULPrototypeElement::TraceAllScripts(JSTracer* aTrc)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mChildren.Length(); ++i) {
|
|
|
|
nsXULPrototypeNode* child = mChildren[i];
|
|
|
|
if (child->mType == nsXULPrototypeNode::eType_Element) {
|
|
|
|
static_cast<nsXULPrototypeElement*>(child)->TraceAllScripts(aTrc);
|
|
|
|
} else if (child->mType == nsXULPrototypeNode::eType_Script) {
|
2013-03-28 13:37:22 -07:00
|
|
|
static_cast<nsXULPrototypeScript*>(child)->TraceScriptObject(aTrc);
|
2012-08-24 13:22:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeScript
|
|
|
|
//
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXULPrototypeScript::nsXULPrototypeScript(uint32_t aLineNo, uint32_t aVersion)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsXULPrototypeNode(eType_Script),
|
|
|
|
mLineNo(aLineNo),
|
2011-10-17 07:59:28 -07:00
|
|
|
mSrcLoading(false),
|
|
|
|
mOutOfLine(true),
|
2012-07-30 07:20:58 -07:00
|
|
|
mSrcLoadWaiters(nullptr),
|
2007-03-22 10:30:00 -07:00
|
|
|
mLangVersion(aVersion),
|
2012-08-24 13:22:23 -07:00
|
|
|
mScriptObject(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsXULPrototypeScript::~nsXULPrototypeScript()
|
|
|
|
{
|
2008-01-29 18:05:43 -08:00
|
|
|
UnlinkJSObjects();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
2012-03-23 10:13:29 -07:00
|
|
|
nsIScriptContext *context = aGlobal->GetScriptContext();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-24 13:22:23 -07:00
|
|
|
!mScriptObject,
|
2007-03-22 10:30:00 -07:00
|
|
|
"script source still loading when serializing?!");
|
2012-08-24 13:22:23 -07:00
|
|
|
if (!mScriptObject)
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
nsresult rv;
|
|
|
|
rv = aStream->Write32(mLineNo);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = aStream->Write32(mLangVersion);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2013-07-23 02:58:28 -07:00
|
|
|
|
|
|
|
// And delegate the writing to the nsIScriptContext.
|
|
|
|
//
|
|
|
|
// Calling fromMarkedLocation() is safe because we trace mScriptObject in
|
|
|
|
// TraceScriptObject() and because its value is never changed after it has
|
|
|
|
// been set.
|
2013-07-23 02:58:27 -07:00
|
|
|
JS::Handle<JSScript*> script =
|
|
|
|
JS::Handle<JSScript*>::fromMarkedLocation(mScriptObject.address());
|
|
|
|
rv = context->Serialize(aStream, script);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::SerializeOutOfLine(nsIObjectOutputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal)
|
|
|
|
{
|
2010-08-12 12:42:36 -07:00
|
|
|
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome = false;
|
2010-08-12 12:42:36 -07:00
|
|
|
if (NS_FAILED(mSrcURI->SchemeIs("chrome", &isChrome)) || !isChrome)
|
|
|
|
// Don't cache scripts that don't come from chrome uris.
|
|
|
|
return rv;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
|
|
|
if (!cache)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ASSERTION(cache->IsEnabled(),
|
2010-08-12 12:42:36 -07:00
|
|
|
"writing to the cache file, but the XUL cache is off?");
|
2011-09-28 23:19:26 -07:00
|
|
|
bool exists;
|
2010-08-12 12:42:36 -07:00
|
|
|
cache->HasData(mSrcURI, &exists);
|
2013-07-23 02:58:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/* return will be NS_OK from GetAsciiSpec.
|
|
|
|
* that makes no sense.
|
|
|
|
* nor does returning NS_OK from HasMuxedDocument.
|
|
|
|
* XXX return something meaningful.
|
|
|
|
*/
|
|
|
|
if (exists)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-12 12:42:36 -07:00
|
|
|
nsCOMPtr<nsIObjectOutputStream> oos;
|
|
|
|
rv = cache->GetOutputStream(mSrcURI, getter_AddRefs(oos));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-07-30 07:28:15 -07:00
|
|
|
nsresult tmp = Serialize(oos, aGlobal, nullptr);
|
2012-07-27 07:03:08 -07:00
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = cache->FinishOutputStream(mSrcURI);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
2010-08-12 12:42:36 -07:00
|
|
|
cache->AbortCaching();
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
nsIURI* aDocumentURI,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nullptr ||
|
2012-08-24 13:22:23 -07:00
|
|
|
!mScriptObject,
|
2007-03-22 10:30:00 -07:00
|
|
|
"prototype script not well-initialized when deserializing?!");
|
|
|
|
|
|
|
|
// Read basic prototype data
|
|
|
|
aStream->Read32(&mLineNo);
|
|
|
|
aStream->Read32(&mLangVersion);
|
|
|
|
|
2012-03-23 10:13:29 -07:00
|
|
|
nsIScriptContext *context = aGlobal->GetScriptContext();
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(context != nullptr, "Have no context for deserialization");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
|
2013-06-20 11:05:34 -07:00
|
|
|
JSAutoRequest ar(context->GetNativeContext());
|
2013-03-20 13:09:09 -07:00
|
|
|
JS::Rooted<JSScript*> newScriptObject(context->GetNativeContext());
|
|
|
|
rv = context->Deserialize(aStream, &newScriptObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Language deseralization failed");
|
|
|
|
return rv;
|
|
|
|
}
|
2007-10-29 06:45:07 -07:00
|
|
|
Set(newScriptObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::DeserializeOutOfLine(nsIObjectInputStream* aInput,
|
|
|
|
nsIScriptGlobalObject* aGlobal)
|
|
|
|
{
|
2010-08-12 12:42:36 -07:00
|
|
|
// Keep track of failure via rv, so we can
|
|
|
|
// AbortCaching if things look bad.
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
2010-08-12 12:42:36 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIObjectInputStream> objectInput = aInput;
|
2010-08-12 12:42:36 -07:00
|
|
|
if (cache) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool useXULCache = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mSrcURI) {
|
|
|
|
// NB: we must check the XUL script cache early, to avoid
|
2010-08-12 12:42:36 -07:00
|
|
|
// multiple deserialization attempts for a given script.
|
2013-03-26 08:31:53 -07:00
|
|
|
// Note that XULDocument::LoadScript
|
2007-03-22 10:30:00 -07:00
|
|
|
// checks the XUL script cache too, in order to handle the
|
|
|
|
// serialization case.
|
|
|
|
//
|
|
|
|
// We need do this only for <script src='strres.js'> and the
|
|
|
|
// like, i.e., out-of-line scripts that are included by several
|
2010-08-12 12:42:36 -07:00
|
|
|
// different XUL documents stored in the cache file.
|
2007-03-22 10:30:00 -07:00
|
|
|
useXULCache = cache->IsEnabled();
|
|
|
|
|
|
|
|
if (useXULCache) {
|
2011-10-29 13:13:31 -07:00
|
|
|
JSScript* newScriptObject =
|
2012-04-24 15:31:28 -07:00
|
|
|
cache->GetScript(mSrcURI);
|
|
|
|
if (newScriptObject)
|
2007-10-29 06:45:07 -07:00
|
|
|
Set(newScriptObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-24 13:22:23 -07:00
|
|
|
if (!mScriptObject) {
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mSrcURI) {
|
2010-08-12 12:42:36 -07:00
|
|
|
rv = cache->GetInputStream(mSrcURI, getter_AddRefs(objectInput));
|
|
|
|
}
|
|
|
|
// If !mSrcURI, we have an inline script. We shouldn't have
|
|
|
|
// to do anything else in that case, I think.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// We do reflect errors into rv, but our caller may want to
|
|
|
|
// ignore our return value, because mScriptObject will be null
|
|
|
|
// after any error, and that suffices to cause the script to
|
|
|
|
// be reloaded (from the src= URI, if any) and recompiled.
|
|
|
|
// We're better off slow-loading than bailing out due to a
|
2010-08-12 12:42:36 -07:00
|
|
|
// error.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-07-30 07:20:58 -07:00
|
|
|
rv = Deserialize(objectInput, aGlobal, nullptr, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (useXULCache && mSrcURI) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isChrome = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
mSrcURI->SchemeIs("chrome", &isChrome);
|
2012-04-24 15:31:28 -07:00
|
|
|
if (isChrome)
|
2013-05-20 05:40:06 -07:00
|
|
|
cache->PutScript(mSrcURI, GetScriptObject());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-08-12 12:42:36 -07:00
|
|
|
cache->FinishInputStream(mSrcURI);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2010-08-12 12:42:36 -07:00
|
|
|
// If mSrcURI is not in the cache,
|
2007-03-22 10:30:00 -07:00
|
|
|
// rv will be NS_ERROR_NOT_AVAILABLE and we'll try to
|
2010-08-12 12:42:36 -07:00
|
|
|
// update the cache file to hold a serialization of
|
2007-03-22 10:30:00 -07:00
|
|
|
// this script, once it has finished loading.
|
|
|
|
if (rv != NS_ERROR_NOT_AVAILABLE)
|
2010-08-12 12:42:36 -07:00
|
|
|
cache->AbortCaching();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeScript::Compile(const PRUnichar* aText,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aTextLength,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNo,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDocument* aDocument,
|
2013-02-15 11:19:54 -08:00
|
|
|
nsIScriptGlobalObject* aGlobal)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// We'll compile the script using the prototype document's special
|
|
|
|
// script object as the parent. This ensures that we won't end up
|
|
|
|
// with an uncollectable reference.
|
|
|
|
//
|
|
|
|
// Compiling it using (for example) the first document's global
|
|
|
|
// object would cause JS to keep a reference via the __proto__ or
|
2010-04-11 13:51:00 -07:00
|
|
|
// parent pointer to the first document's global. If that happened,
|
|
|
|
// our script object would reference the first document, and the
|
|
|
|
// first document would indirectly reference the prototype document
|
|
|
|
// because it keeps the prototype cache alive. Circularity!
|
2013-02-15 11:19:54 -08:00
|
|
|
NS_ASSERTION(aGlobal, "prototype doc has no script global");
|
|
|
|
if (!aGlobal) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Use the prototype document's special context
|
2013-02-15 11:19:54 -08:00
|
|
|
nsIScriptContext *context = aGlobal->GetScriptContext();
|
|
|
|
NS_ASSERTION(context, "no context for script global");
|
|
|
|
if (! context) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString urlspec;
|
2008-11-13 16:00:11 -08:00
|
|
|
nsContentUtils::GetWrapperSafeScriptFilename(aDocument, aURI, urlspec);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Ok, compile it to create a prototype script object!
|
|
|
|
|
2013-08-08 16:51:34 -07:00
|
|
|
JSContext* cx = context->GetNativeContext();
|
|
|
|
AutoCxPusher pusher(cx);
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
nsresult rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
CanExecuteScripts(cx, aDocument->NodePrincipal(), &ok);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_OK);
|
|
|
|
NS_ENSURE_TRUE(JSVersion(mLangVersion) != JSVERSION_UNKNOWN, NS_OK);
|
2012-08-07 10:39:47 -07:00
|
|
|
|
2013-08-08 16:51:34 -07:00
|
|
|
JS::CompileOptions options(cx);
|
|
|
|
options.setPrincipals(nsJSPrincipals::get(aDocument->NodePrincipal()))
|
|
|
|
.setFileAndLine(urlspec.get(), aLineNo)
|
|
|
|
.setVersion(JSVersion(mLangVersion));
|
2012-08-07 10:39:47 -07:00
|
|
|
// If the script was inline, tell the JS parser to save source for
|
|
|
|
// Function.prototype.toSource(). If it's out of line, we retrieve the
|
|
|
|
// source from the files on demand.
|
2013-08-08 16:51:34 -07:00
|
|
|
options.setSourcePolicy(mOutOfLine ? JS::CompileOptions::LAZY_SOURCE
|
|
|
|
: JS::CompileOptions::SAVE_SOURCE);
|
|
|
|
JS::RootedObject scope(cx, JS::CurrentGlobalOrNull(cx));
|
|
|
|
xpc_UnmarkGrayObject(scope);
|
|
|
|
JSScript* script = JS::Compile(cx, scope, options,
|
|
|
|
static_cast<const jschar*>(aText), aTextLength);
|
|
|
|
if (!script)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
Set(script);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-08-11 06:29:50 -07:00
|
|
|
void
|
|
|
|
nsXULPrototypeScript::UnlinkJSObjects()
|
|
|
|
{
|
2012-08-24 13:22:23 -07:00
|
|
|
if (mScriptObject) {
|
|
|
|
mScriptObject = nullptr;
|
2012-11-27 17:37:57 -08:00
|
|
|
nsContentUtils::DropJSObjects(this);
|
2011-08-11 06:29:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-10-29 13:13:31 -07:00
|
|
|
nsXULPrototypeScript::Set(JSScript* aObject)
|
2011-08-11 06:29:50 -07:00
|
|
|
{
|
2012-08-24 13:22:23 -07:00
|
|
|
MOZ_ASSERT(!mScriptObject, "Leaking script object.");
|
2011-08-11 06:29:50 -07:00
|
|
|
if (!aObject) {
|
2012-08-24 13:22:23 -07:00
|
|
|
mScriptObject = nullptr;
|
2011-08-11 06:29:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-20 05:40:06 -07:00
|
|
|
mScriptObject = aObject;
|
2012-11-12 17:15:00 -08:00
|
|
|
nsContentUtils::HoldJSObjects(
|
2012-06-03 23:30:26 -07:00
|
|
|
this, NS_CYCLE_COLLECTION_PARTICIPANT(nsXULPrototypeNode));
|
2011-08-11 06:29:50 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypeText
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->WriteWStringZ(mValue.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
nsIURI* aDocumentURI,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = aStream->ReadString(mValue);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// nsXULPrototypePI
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Serialize(nsIObjectOutputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Write basic prototype data
|
|
|
|
rv = aStream->Write32(mType);
|
|
|
|
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->WriteWStringZ(mTarget.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
|
|
|
tmp = aStream->WriteWStringZ(mData.get());
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsXULPrototypePI::Deserialize(nsIObjectInputStream* aStream,
|
|
|
|
nsIScriptGlobalObject* aGlobal,
|
|
|
|
nsIURI* aDocumentURI,
|
|
|
|
const nsCOMArray<nsINodeInfo> *aNodeInfos)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = aStream->ReadString(mTarget);
|
2012-07-27 07:03:08 -07:00
|
|
|
nsresult tmp = aStream->ReadString(mData);
|
|
|
|
if (NS_FAILED(tmp)) {
|
|
|
|
rv = tmp;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|