2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/* base class for DOM objects for element.style and cssStyleRule.style */
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2013-08-22 10:29:57 +04:00
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
#include "nsCSSParser.h"
|
2016-11-03 06:41:02 +03:00
|
|
|
#include "mozilla/DeclarationBlockInlines.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2011-04-08 05:23:46 +04:00
|
|
|
#include "mozilla/css/Rule.h"
|
2013-08-22 10:29:57 +04:00
|
|
|
#include "mozilla/dom/CSS2PropertiesBinding.h"
|
1998-09-25 04:51:45 +04:00
|
|
|
#include "nsCSSProps.h"
|
2000-04-20 17:50:56 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2009-12-11 19:13:19 +03:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
#include "nsIURI.h"
|
2014-03-07 21:14:26 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "nsContentUtils.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2015-12-14 22:47:24 +03:00
|
|
|
#include "mozilla/layers/ScrollLinkedEffectDetector.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
using namespace mozilla;
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-22 10:29:57 +04:00
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
nsDOMCSSDeclaration::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-08-22 10:29:57 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return dom::CSS2PropertiesBinding::Wrap(aCx, this, aGivenProto);
|
2013-08-22 10:29:57 +04:00
|
|
|
}
|
|
|
|
|
2017-08-16 23:37:20 +03:00
|
|
|
NS_IMPL_QUERY_INTERFACE(nsDOMCSSDeclaration,
|
|
|
|
nsICSSDeclaration,
|
|
|
|
nsIDOMCSSStyleDeclaration)
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
NS_IMETHODIMP
|
2016-08-17 04:37:48 +03:00
|
|
|
nsDOMCSSDeclaration::GetPropertyValue(const nsCSSPropertyID aPropID,
|
2004-06-08 05:32:29 +04:00
|
|
|
nsAString& aValue)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aPropID != eCSSProperty_UNKNOWN,
|
|
|
|
"Should never pass eCSSProperty_UNKNOWN around");
|
2010-06-29 02:49:35 +04:00
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
aValue.Truncate();
|
2016-11-03 06:41:02 +03:00
|
|
|
if (DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read)) {
|
2016-11-03 06:41:02 +03:00
|
|
|
decl->GetPropertyValueByID(aPropID, aValue);
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
2010-07-23 22:00:34 +04:00
|
|
|
return NS_OK;
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-08-17 04:37:48 +03:00
|
|
|
nsDOMCSSDeclaration::SetPropertyValue(const nsCSSPropertyID aPropID,
|
2017-11-04 07:44:03 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal)
|
2004-06-08 05:32:29 +04:00
|
|
|
{
|
2015-12-14 22:47:24 +03:00
|
|
|
switch (aPropID) {
|
|
|
|
case eCSSProperty_background_position:
|
2016-04-26 01:56:47 +03:00
|
|
|
case eCSSProperty_background_position_x:
|
|
|
|
case eCSSProperty_background_position_y:
|
2015-12-14 22:47:24 +03:00
|
|
|
case eCSSProperty_transform:
|
|
|
|
case eCSSProperty_top:
|
|
|
|
case eCSSProperty_left:
|
|
|
|
case eCSSProperty_bottom:
|
|
|
|
case eCSSProperty_right:
|
2016-04-21 18:41:17 +03:00
|
|
|
case eCSSProperty_margin:
|
2015-12-14 22:47:24 +03:00
|
|
|
case eCSSProperty_margin_top:
|
|
|
|
case eCSSProperty_margin_left:
|
|
|
|
case eCSSProperty_margin_bottom:
|
|
|
|
case eCSSProperty_margin_right:
|
2016-04-21 18:41:17 +03:00
|
|
|
case eCSSProperty_margin_inline_start:
|
|
|
|
case eCSSProperty_margin_inline_end:
|
|
|
|
case eCSSProperty_margin_block_start:
|
|
|
|
case eCSSProperty_margin_block_end:
|
2015-12-14 22:47:24 +03:00
|
|
|
mozilla::layers::ScrollLinkedEffectDetector::PositioningPropertyMutated();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
if (aValue.IsEmpty()) {
|
|
|
|
// If the new value of the property is an empty string we remove the
|
|
|
|
// property.
|
2016-11-03 06:41:02 +03:00
|
|
|
return RemovePropertyInternal(aPropID);
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
|
|
|
|
2017-11-04 07:44:03 +03:00
|
|
|
return ParsePropertyValue(aPropID, aValue, false, aSubjectPrincipal);
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
nsDOMCSSDeclaration::GetCssText(nsAString& aCssText)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
|
2000-04-20 17:50:56 +04:00
|
|
|
aCssText.Truncate();
|
2001-05-15 12:25:03 +04:00
|
|
|
|
|
|
|
if (decl) {
|
|
|
|
decl->ToString(aCssText);
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
2017-11-04 07:44:03 +03:00
|
|
|
nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText,
|
|
|
|
nsIPrincipal* aSubjectPrincipal)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2010-07-23 22:00:49 +04:00
|
|
|
// We don't need to *do* anything with the old declaration, but we need
|
|
|
|
// to ensure that it exists, or else SetCSSDeclaration may crash.
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_Modify);
|
2010-07-23 22:00:49 +04:00
|
|
|
if (!olddecl) {
|
2015-11-05 11:44:09 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2010-07-23 22:00:19 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:47 +04:00
|
|
|
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
|
2010-07-23 22:00:19 +04:00
|
|
|
// Attribute setting code, which leads in turn to BeginUpdate. We
|
|
|
|
// need to start the update now so that the old rule doesn't get used
|
|
|
|
// between when we mutate the declaration and when we set the new
|
|
|
|
// rule (see stack in bug 209575).
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
|
2010-07-23 22:00:19 +04:00
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
RefPtr<DeclarationBlock> newdecl;
|
|
|
|
if (olddecl->IsServo()) {
|
2017-05-11 19:06:43 +03:00
|
|
|
ServoCSSParsingEnvironment servoEnv = GetServoCSSParsingEnvironment();
|
|
|
|
if (!servoEnv.mUrlExtraData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2017-05-06 01:12:03 +03:00
|
|
|
newdecl = ServoDeclarationBlock::FromCssText(aCssText, servoEnv.mUrlExtraData,
|
2017-07-11 00:52:00 +03:00
|
|
|
servoEnv.mCompatMode, servoEnv.mLoader);
|
2016-11-03 06:41:02 +03:00
|
|
|
} else {
|
2017-05-11 19:06:43 +03:00
|
|
|
CSSParsingEnvironment geckoEnv;
|
|
|
|
GetCSSParsingEnvironment(geckoEnv);
|
|
|
|
if (!geckoEnv.mPrincipal) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
RefPtr<css::Declaration> decl(new css::Declaration());
|
|
|
|
decl->InitializeEmpty();
|
2017-05-11 19:06:43 +03:00
|
|
|
nsCSSParser cssParser(geckoEnv.mCSSLoader);
|
2016-11-03 06:41:02 +03:00
|
|
|
bool changed;
|
2017-05-11 19:06:43 +03:00
|
|
|
nsresult result = cssParser.ParseDeclarations(aCssText, geckoEnv.mSheetURI,
|
|
|
|
geckoEnv.mBaseURI, geckoEnv.mPrincipal,
|
2016-11-03 06:41:02 +03:00
|
|
|
decl, &changed);
|
|
|
|
if (NS_FAILED(result) || !changed) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
newdecl = decl.forget();
|
2010-07-23 22:00:19 +04:00
|
|
|
}
|
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
return SetCSSDeclaration(newdecl);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-20 17:50:56 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsDOMCSSDeclaration::GetLength(uint32_t* aLength)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
|
2010-06-29 02:49:35 +04:00
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
if (decl) {
|
2002-01-16 01:43:37 +03:00
|
|
|
*aLength = decl->Count();
|
2003-06-18 05:59:57 +04:00
|
|
|
} else {
|
|
|
|
*aLength = 0;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
return NS_OK;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
already_AddRefed<dom::CSSValue>
|
|
|
|
nsDOMCSSDeclaration::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorResult& aRv)
|
2000-04-20 17:50:56 +04:00
|
|
|
{
|
|
|
|
// We don't support CSSValue yet so we'll just return null...
|
|
|
|
|
2012-10-01 20:49:41 +04:00
|
|
|
return nullptr;
|
2000-04-20 17:50:56 +04:00
|
|
|
}
|
|
|
|
|
2012-08-24 08:08:08 +04:00
|
|
|
void
|
|
|
|
nsDOMCSSDeclaration::IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aPropName)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
|
2012-08-24 08:08:08 +04:00
|
|
|
aFound = decl && decl->GetNthProperty(aIndex, aPropName);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
|
2002-03-24 01:56:05 +03:00
|
|
|
nsAString& aReturn)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
aReturn.Truncate();
|
2016-11-03 06:41:02 +03:00
|
|
|
if (DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read)) {
|
2016-11-03 06:41:02 +03:00
|
|
|
decl->GetPropertyValue(aPropertyName, aReturn);
|
2013-09-16 03:35:49 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::GetPropertyPriority(const nsAString& aPropertyName,
|
2002-03-24 01:56:05 +03:00
|
|
|
nsAString& aReturn)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* decl = GetCSSDeclaration(eOperation_Read);
|
1998-09-25 04:51:45 +04:00
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
aReturn.Truncate();
|
2016-11-03 06:41:02 +03:00
|
|
|
if (decl && decl->GetPropertyIsImportant(aPropertyName)) {
|
2010-07-23 22:00:34 +04:00
|
|
|
aReturn.AssignLiteral("important");
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
return NS_OK;
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:34 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
|
|
|
|
const nsAString& aValue,
|
2017-11-04 07:44:03 +03:00
|
|
|
const nsAString& aPriority,
|
|
|
|
nsIPrincipal* aSubjectPrincipal)
|
1998-09-25 04:51:45 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
if (aValue.IsEmpty()) {
|
|
|
|
// If the new value of the property is an empty string we remove the
|
|
|
|
// property.
|
|
|
|
// XXX this ignores the priority string, should it?
|
|
|
|
return RemovePropertyInternal(aPropertyName);
|
|
|
|
}
|
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
// In the common (and fast) cases we can use the property id
|
2016-08-17 04:37:48 +03:00
|
|
|
nsCSSPropertyID propID =
|
2016-05-10 11:44:05 +03:00
|
|
|
nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
|
2004-06-08 05:32:29 +04:00
|
|
|
if (propID == eCSSProperty_UNKNOWN) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-04-02 10:07:40 +04:00
|
|
|
|
2013-12-12 06:09:46 +04:00
|
|
|
bool important;
|
2002-08-08 21:40:20 +04:00
|
|
|
if (aPriority.IsEmpty()) {
|
2013-12-12 06:09:46 +04:00
|
|
|
important = false;
|
|
|
|
} else if (aPriority.EqualsLiteral("important")) {
|
|
|
|
important = true;
|
|
|
|
} else {
|
|
|
|
// XXX silent failure?
|
|
|
|
return NS_OK;
|
2002-08-08 21:40:20 +04:00
|
|
|
}
|
2002-10-03 23:41:42 +04:00
|
|
|
|
2013-12-12 06:09:46 +04:00
|
|
|
if (propID == eCSSPropertyExtra_variable) {
|
2017-11-04 07:44:03 +03:00
|
|
|
return ParseCustomPropertyValue(aPropertyName, aValue, important,
|
|
|
|
aSubjectPrincipal);
|
2010-04-02 10:07:40 +04:00
|
|
|
}
|
2017-11-04 07:44:03 +03:00
|
|
|
return ParsePropertyValue(propID, aValue, important, aSubjectPrincipal);
|
1998-09-25 04:51:45 +04:00
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMCSSDeclaration::RemoveProperty(const nsAString& aPropertyName,
|
|
|
|
nsAString& aReturn)
|
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
nsresult rv = GetPropertyValue(aPropertyName, aReturn);
|
2004-06-08 05:32:29 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2016-11-03 06:41:02 +03:00
|
|
|
return RemovePropertyInternal(aPropertyName);
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2011-04-28 00:53:49 +04:00
|
|
|
/* static */ void
|
2011-04-08 05:23:46 +04:00
|
|
|
nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(css::Rule* aRule,
|
2011-04-28 00:53:49 +04:00
|
|
|
CSSParsingEnvironment& aCSSParseEnv)
|
2011-04-12 10:18:42 +04:00
|
|
|
{
|
2016-11-23 02:26:20 +03:00
|
|
|
StyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nullptr;
|
2015-11-17 09:04:09 +03:00
|
|
|
if (!sheet) {
|
2012-07-30 18:20:58 +04:00
|
|
|
aCSSParseEnv.mPrincipal = nullptr;
|
2011-04-28 00:53:49 +04:00
|
|
|
return;
|
2011-04-12 10:18:42 +04:00
|
|
|
}
|
|
|
|
|
2017-01-20 07:49:44 +03:00
|
|
|
nsIDocument* document = sheet->GetAssociatedDocument();
|
2011-04-28 00:53:49 +04:00
|
|
|
aCSSParseEnv.mSheetURI = sheet->GetSheetURI();
|
|
|
|
aCSSParseEnv.mBaseURI = sheet->GetBaseURI();
|
2015-11-17 09:04:09 +03:00
|
|
|
aCSSParseEnv.mPrincipal = sheet->Principal();
|
2012-07-30 18:20:58 +04:00
|
|
|
aCSSParseEnv.mCSSLoader = document ? document->CSSLoader() : nullptr;
|
2011-04-12 10:18:42 +04:00
|
|
|
}
|
|
|
|
|
2017-05-11 19:06:43 +03:00
|
|
|
/* static */ nsDOMCSSDeclaration::ServoCSSParsingEnvironment
|
|
|
|
nsDOMCSSDeclaration::GetServoCSSParsingEnvironmentForRule(const css::Rule* aRule)
|
2017-04-04 09:09:20 +03:00
|
|
|
{
|
2017-05-11 19:06:43 +03:00
|
|
|
StyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nullptr;
|
|
|
|
if (!sheet) {
|
2017-07-11 00:52:00 +03:00
|
|
|
return { nullptr, eCompatibility_FullStandards, nullptr };
|
2017-05-11 19:06:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsIDocument* document = aRule->GetDocument()) {
|
2017-05-21 16:06:27 +03:00
|
|
|
return {
|
|
|
|
sheet->AsServo()->URLData(),
|
|
|
|
document->GetCompatibilityMode(),
|
2017-07-11 00:52:00 +03:00
|
|
|
document->CSSLoader(),
|
2017-05-21 16:06:27 +03:00
|
|
|
};
|
2017-04-04 09:09:20 +03:00
|
|
|
}
|
2017-05-21 16:06:27 +03:00
|
|
|
|
|
|
|
return {
|
|
|
|
sheet->AsServo()->URLData(),
|
|
|
|
eCompatibility_FullStandards,
|
2017-07-11 00:52:00 +03:00
|
|
|
nullptr,
|
2017-05-21 16:06:27 +03:00
|
|
|
};
|
2017-04-04 09:09:20 +03:00
|
|
|
}
|
|
|
|
|
2017-04-04 08:28:07 +03:00
|
|
|
template<typename GeckoFunc, typename ServoFunc>
|
2003-06-18 05:59:57 +04:00
|
|
|
nsresult
|
2017-04-04 08:28:07 +03:00
|
|
|
nsDOMCSSDeclaration::ModifyDeclaration(GeckoFunc aGeckoFunc,
|
|
|
|
ServoFunc aServoFunc)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_Modify);
|
2010-07-23 22:00:49 +04:00
|
|
|
if (!olddecl) {
|
2015-11-05 11:44:09 +03:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2010-07-23 22:00:47 +04:00
|
|
|
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
|
2009-12-11 19:13:19 +03:00
|
|
|
// Attribute setting code, which leads in turn to BeginUpdate. We
|
|
|
|
// need to start the update now so that the old rule doesn't get used
|
|
|
|
// between when we mutate the declaration and when we set the new
|
|
|
|
// rule (see stack in bug 209575).
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
|
2017-09-29 05:04:34 +03:00
|
|
|
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool changed;
|
2016-11-03 06:41:02 +03:00
|
|
|
if (decl->IsGecko()) {
|
2017-05-11 19:06:43 +03:00
|
|
|
CSSParsingEnvironment geckoEnv;
|
|
|
|
GetCSSParsingEnvironment(geckoEnv);
|
|
|
|
if (!geckoEnv.mPrincipal) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aGeckoFunc(decl->AsGecko(), geckoEnv, &changed);
|
2016-11-03 06:41:02 +03:00
|
|
|
} else {
|
2017-05-11 19:06:43 +03:00
|
|
|
ServoCSSParsingEnvironment servoEnv = GetServoCSSParsingEnvironment();
|
|
|
|
if (!servoEnv.mUrlExtraData) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2017-05-14 18:11:18 +03:00
|
|
|
changed = aServoFunc(decl->AsServo(), servoEnv);
|
2016-11-03 06:41:02 +03:00
|
|
|
}
|
2015-03-29 14:57:04 +03:00
|
|
|
if (!changed) {
|
|
|
|
// Parsing failed -- but we don't throw an exception for that.
|
|
|
|
return NS_OK;
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:47 +04:00
|
|
|
return SetCSSDeclaration(decl);
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2017-04-04 08:28:07 +03:00
|
|
|
nsresult
|
|
|
|
nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSPropertyID aPropID,
|
|
|
|
const nsAString& aPropValue,
|
2017-11-04 07:44:03 +03:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal)
|
2017-04-04 08:28:07 +03:00
|
|
|
{
|
|
|
|
return ModifyDeclaration(
|
2017-05-19 09:12:34 +03:00
|
|
|
[&](css::Declaration* decl, CSSParsingEnvironment& env, bool* changed) {
|
2017-04-04 08:28:07 +03:00
|
|
|
nsCSSParser cssParser(env.mCSSLoader);
|
|
|
|
cssParser.ParseProperty(aPropID, aPropValue,
|
|
|
|
env.mSheetURI, env.mBaseURI, env.mPrincipal,
|
|
|
|
decl, changed, aIsImportant);
|
|
|
|
},
|
2017-05-14 18:11:18 +03:00
|
|
|
[&](ServoDeclarationBlock* decl, ServoCSSParsingEnvironment& env) {
|
2017-04-04 08:28:07 +03:00
|
|
|
NS_ConvertUTF16toUTF8 value(aPropValue);
|
|
|
|
return Servo_DeclarationBlock_SetPropertyById(
|
2017-05-14 18:11:18 +03:00
|
|
|
decl->Raw(), aPropID, &value, aIsImportant, env.mUrlExtraData,
|
2017-07-11 00:52:00 +03:00
|
|
|
ParsingMode::Default, env.mCompatMode, env.mLoader);
|
2017-04-04 08:28:07 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-12-12 06:09:46 +04:00
|
|
|
nsresult
|
|
|
|
nsDOMCSSDeclaration::ParseCustomPropertyValue(const nsAString& aPropertyName,
|
|
|
|
const nsAString& aPropValue,
|
2017-11-04 07:44:03 +03:00
|
|
|
bool aIsImportant,
|
|
|
|
nsIPrincipal* aSubjectPrincipal)
|
2013-12-12 06:09:46 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsCSSProps::IsCustomPropertyName(aPropertyName));
|
2017-04-04 08:28:07 +03:00
|
|
|
return ModifyDeclaration(
|
2017-05-19 09:12:34 +03:00
|
|
|
[&](css::Declaration* decl, CSSParsingEnvironment& env, bool* changed) {
|
2017-04-04 08:28:07 +03:00
|
|
|
nsCSSParser cssParser(env.mCSSLoader);
|
|
|
|
auto propName = Substring(aPropertyName, CSS_CUSTOM_NAME_PREFIX_LENGTH);
|
|
|
|
cssParser.ParseVariable(propName, aPropValue, env.mSheetURI,
|
|
|
|
env.mBaseURI, env.mPrincipal, decl,
|
|
|
|
changed, aIsImportant);
|
|
|
|
},
|
2017-05-14 18:11:18 +03:00
|
|
|
[&](ServoDeclarationBlock* decl, ServoCSSParsingEnvironment& env) {
|
2017-04-04 08:28:07 +03:00
|
|
|
NS_ConvertUTF16toUTF8 property(aPropertyName);
|
|
|
|
NS_ConvertUTF16toUTF8 value(aPropValue);
|
|
|
|
return Servo_DeclarationBlock_SetProperty(
|
2017-05-14 18:11:18 +03:00
|
|
|
decl->Raw(), &property, &value, aIsImportant, env.mUrlExtraData,
|
2017-07-11 00:52:00 +03:00
|
|
|
ParsingMode::Default, env.mCompatMode, env.mLoader);
|
2017-04-04 08:28:07 +03:00
|
|
|
});
|
2013-12-12 06:09:46 +04:00
|
|
|
}
|
|
|
|
|
2004-06-08 05:32:29 +04:00
|
|
|
nsresult
|
2016-11-03 06:41:02 +03:00
|
|
|
nsDOMCSSDeclaration::RemovePropertyInternal(nsCSSPropertyID aPropID)
|
2004-06-08 05:32:29 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_RemoveProperty);
|
2015-11-05 11:44:08 +03:00
|
|
|
if (!olddecl) {
|
2010-07-23 22:00:34 +04:00
|
|
|
return NS_OK; // no decl, so nothing to remove
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
|
|
|
|
2010-07-23 22:00:47 +04:00
|
|
|
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
|
2009-12-11 19:13:19 +03:00
|
|
|
// Attribute setting code, which leads in turn to BeginUpdate. We
|
|
|
|
// need to start the update now so that the old rule doesn't get used
|
|
|
|
// between when we mutate the declaration and when we set the new
|
|
|
|
// rule (see stack in bug 209575).
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
|
2009-12-11 19:13:19 +03:00
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
|
2016-11-03 06:41:02 +03:00
|
|
|
decl->RemovePropertyByID(aPropID);
|
2010-07-23 22:00:47 +04:00
|
|
|
return SetCSSDeclaration(decl);
|
2004-06-08 05:32:29 +04:00
|
|
|
}
|
2013-12-12 06:09:46 +04:00
|
|
|
|
|
|
|
nsresult
|
2016-11-03 06:41:02 +03:00
|
|
|
nsDOMCSSDeclaration::RemovePropertyInternal(const nsAString& aPropertyName)
|
2013-12-12 06:09:46 +04:00
|
|
|
{
|
2016-11-03 06:41:02 +03:00
|
|
|
DeclarationBlock* olddecl = GetCSSDeclaration(eOperation_RemoveProperty);
|
2015-11-05 11:44:08 +03:00
|
|
|
if (!olddecl) {
|
2013-12-12 06:09:46 +04:00
|
|
|
return NS_OK; // no decl, so nothing to remove
|
|
|
|
}
|
|
|
|
|
|
|
|
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
|
|
|
|
// Attribute setting code, which leads in turn to BeginUpdate. We
|
|
|
|
// need to start the update now so that the old rule doesn't get used
|
|
|
|
// between when we mutate the declaration and when we set the new
|
|
|
|
// rule (see stack in bug 209575).
|
|
|
|
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), true);
|
|
|
|
|
2016-11-03 06:41:02 +03:00
|
|
|
RefPtr<DeclarationBlock> decl = olddecl->EnsureMutable();
|
2016-11-03 06:41:02 +03:00
|
|
|
decl->RemoveProperty(aPropertyName);
|
2013-12-12 06:09:46 +04:00
|
|
|
return SetCSSDeclaration(decl);
|
|
|
|
}
|