2017-03-09 09:56:31 +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: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
/* representation of media lists for servo backend */
|
|
|
|
|
|
|
|
#include "mozilla/ServoMediaList.h"
|
|
|
|
|
|
|
|
#include "mozilla/ServoBindings.h"
|
2017-04-10 05:25:33 +03:00
|
|
|
#include "mozilla/ServoStyleSet.h"
|
2017-03-09 09:56:31 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
already_AddRefed<dom::MediaList>
|
|
|
|
ServoMediaList::Clone()
|
|
|
|
{
|
2017-04-10 09:36:45 +03:00
|
|
|
RefPtr<ServoMediaList> clone =
|
|
|
|
new ServoMediaList(Servo_MediaList_DeepClone(mRawList).Consume());
|
|
|
|
return clone.forget();
|
2017-03-09 09:56:31 +03:00
|
|
|
}
|
|
|
|
|
2017-04-10 03:01:38 +03:00
|
|
|
ServoMediaList::ServoMediaList()
|
|
|
|
: mRawList(Servo_MediaList_Create().Consume())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ServoMediaList::ServoMediaList(const nsAString& aMedia)
|
|
|
|
: ServoMediaList()
|
|
|
|
{
|
|
|
|
SetText(aMedia);
|
|
|
|
}
|
|
|
|
|
2017-03-09 09:56:31 +03:00
|
|
|
void
|
|
|
|
ServoMediaList::GetText(nsAString& aMediaText)
|
|
|
|
{
|
|
|
|
Servo_MediaList_GetText(mRawList, &aMediaText);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoMediaList::SetText(const nsAString& aMediaText)
|
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 mediaText(aMediaText);
|
|
|
|
Servo_MediaList_SetText(mRawList, &mediaText);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
ServoMediaList::Length()
|
|
|
|
{
|
|
|
|
return Servo_MediaList_GetLength(mRawList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ServoMediaList::IndexedGetter(uint32_t aIndex, bool& aFound,
|
|
|
|
nsAString& aReturn)
|
|
|
|
{
|
|
|
|
aFound = Servo_MediaList_GetMediumAt(mRawList, aIndex, &aReturn);
|
2017-06-08 23:32:25 +03:00
|
|
|
if (!aFound) {
|
|
|
|
SetDOMStringToNull(aReturn);
|
|
|
|
}
|
2017-03-09 09:56:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoMediaList::Append(const nsAString& aNewMedium)
|
|
|
|
{
|
|
|
|
if (aNewMedium.IsEmpty()) {
|
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
}
|
|
|
|
NS_ConvertUTF16toUTF8 newMedium(aNewMedium);
|
|
|
|
Servo_MediaList_AppendMedium(mRawList, &newMedium);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
ServoMediaList::Delete(const nsAString& aOldMedium)
|
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 oldMedium(aOldMedium);
|
|
|
|
if (Servo_MediaList_DeleteMedium(mRawList, &oldMedium)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
}
|
|
|
|
|
2017-04-10 05:25:33 +03:00
|
|
|
bool
|
2017-04-14 04:39:53 +03:00
|
|
|
ServoMediaList::Matches(nsPresContext* aPresContext) const
|
2017-04-10 05:25:33 +03:00
|
|
|
{
|
2017-06-05 06:57:13 +03:00
|
|
|
const RawServoStyleSet* rawSet =
|
2017-04-14 04:39:53 +03:00
|
|
|
aPresContext->StyleSet()->AsServo()->RawSet();
|
2017-06-05 06:57:13 +03:00
|
|
|
MOZ_ASSERT(rawSet, "The RawServoStyleSet should be valid!");
|
|
|
|
return Servo_MediaList_Matches(mRawList, rawSet);
|
2017-04-10 05:25:33 +03:00
|
|
|
}
|
|
|
|
|
2017-03-09 09:56:31 +03:00
|
|
|
} // namespace mozilla
|