2012-11-25 04:26:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* DOM object holding utility CSS functions */
|
|
|
|
|
|
|
|
#include "CSS.h"
|
|
|
|
|
2012-12-03 20:07:49 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2016-07-18 11:29:04 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2012-11-25 04:26:07 +04:00
|
|
|
#include "nsCSSParser.h"
|
|
|
|
#include "nsGlobalWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIURI.h"
|
2014-03-21 07:19:43 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2014-10-30 00:00:48 +03:00
|
|
|
#include "xpcpublic.h"
|
2012-11-25 04:26:07 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct SupportsParsingInfo
|
|
|
|
{
|
|
|
|
nsIURI* mDocURI;
|
|
|
|
nsIURI* mBaseURI;
|
|
|
|
nsIPrincipal* mPrincipal;
|
2016-07-18 11:29:04 +03:00
|
|
|
StyleBackendType mStyleBackendType;
|
2012-11-25 04:26:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static nsresult
|
2014-10-30 00:00:48 +03:00
|
|
|
GetParsingInfo(const GlobalObject& aGlobal,
|
2012-11-25 04:26:07 +04:00
|
|
|
SupportsParsingInfo& aInfo)
|
|
|
|
{
|
2014-10-30 00:00:48 +03:00
|
|
|
nsGlobalWindow* win = xpc::WindowOrNull(aGlobal.Get());
|
|
|
|
if (!win) {
|
2012-12-26 13:00:19 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-11-25 04:26:07 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = win->GetDoc();
|
|
|
|
if (!doc) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-05-01 21:29:23 +03:00
|
|
|
aInfo.mDocURI = nsCOMPtr<nsIURI>(doc->GetDocumentURI()).get();
|
|
|
|
aInfo.mBaseURI = nsCOMPtr<nsIURI>(doc->GetBaseURI()).get();
|
2012-11-25 04:26:07 +04:00
|
|
|
aInfo.mPrincipal = win->GetPrincipal();
|
2016-07-18 11:29:04 +03:00
|
|
|
aInfo.mStyleBackendType = doc->GetStyleBackendType();
|
2012-11-25 04:26:07 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2012-12-03 20:07:49 +04:00
|
|
|
CSS::Supports(const GlobalObject& aGlobal,
|
2012-11-25 04:26:07 +04:00
|
|
|
const nsAString& aProperty,
|
|
|
|
const nsAString& aValue,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SupportsParsingInfo info;
|
|
|
|
|
2014-10-30 00:00:48 +03:00
|
|
|
nsresult rv = GetParsingInfo(aGlobal, info);
|
2012-11-25 04:26:07 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-18 11:29:04 +03:00
|
|
|
if (info.mStyleBackendType == StyleBackendType::Servo) {
|
|
|
|
NS_ConvertUTF16toUTF8 property(aProperty);
|
|
|
|
NS_ConvertUTF16toUTF8 value(aValue);
|
|
|
|
|
|
|
|
return Servo_CSSSupports(reinterpret_cast<const uint8_t*>(property.get()),
|
|
|
|
property.Length(),
|
|
|
|
reinterpret_cast<const uint8_t*>(value.get()),
|
|
|
|
value.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSParser parser;
|
2012-11-25 04:26:07 +04:00
|
|
|
return parser.EvaluateSupportsDeclaration(aProperty, aValue, info.mDocURI,
|
|
|
|
info.mBaseURI, info.mPrincipal);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ bool
|
2012-12-03 20:07:49 +04:00
|
|
|
CSS::Supports(const GlobalObject& aGlobal,
|
2012-11-25 04:26:07 +04:00
|
|
|
const nsAString& aCondition,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
SupportsParsingInfo info;
|
|
|
|
|
2014-10-30 00:00:48 +03:00
|
|
|
nsresult rv = GetParsingInfo(aGlobal, info);
|
2012-11-25 04:26:07 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-18 11:29:04 +03:00
|
|
|
if (info.mStyleBackendType == StyleBackendType::Servo) {
|
|
|
|
MOZ_CRASH("stylo: CSS.supports() with arguments is not yet implemented");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSParser parser;
|
2012-11-25 04:26:07 +04:00
|
|
|
return parser.EvaluateSupportsCondition(aCondition, info.mDocURI,
|
|
|
|
info.mBaseURI, info.mPrincipal);
|
|
|
|
}
|
|
|
|
|
2014-03-21 07:19:43 +04:00
|
|
|
/* static */ void
|
|
|
|
CSS::Escape(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aIdent,
|
2016-01-05 23:05:23 +03:00
|
|
|
nsAString& aReturn)
|
2014-03-21 07:19:43 +04:00
|
|
|
{
|
2016-01-05 23:05:23 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSIdent(aIdent, aReturn);
|
2014-03-21 07:19:43 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|