Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : /* representation of media lists for servo backend */
8 :
9 : #include "mozilla/ServoMediaList.h"
10 :
11 : #include "mozilla/ServoBindings.h"
12 : #include "mozilla/ServoStyleSet.h"
13 :
14 : namespace mozilla {
15 :
16 : already_AddRefed<dom::MediaList>
17 0 : ServoMediaList::Clone()
18 : {
19 : RefPtr<ServoMediaList> clone =
20 0 : new ServoMediaList(Servo_MediaList_DeepClone(mRawList).Consume());
21 0 : return clone.forget();
22 : }
23 :
24 0 : ServoMediaList::ServoMediaList()
25 0 : : mRawList(Servo_MediaList_Create().Consume())
26 : {
27 0 : }
28 :
29 0 : ServoMediaList::ServoMediaList(const nsAString& aMedia)
30 0 : : ServoMediaList()
31 : {
32 0 : SetText(aMedia);
33 0 : }
34 :
35 : void
36 0 : ServoMediaList::GetText(nsAString& aMediaText)
37 : {
38 0 : Servo_MediaList_GetText(mRawList, &aMediaText);
39 0 : }
40 :
41 : void
42 0 : ServoMediaList::SetText(const nsAString& aMediaText)
43 : {
44 0 : NS_ConvertUTF16toUTF8 mediaText(aMediaText);
45 0 : Servo_MediaList_SetText(mRawList, &mediaText);
46 0 : }
47 :
48 : uint32_t
49 0 : ServoMediaList::Length()
50 : {
51 0 : return Servo_MediaList_GetLength(mRawList);
52 : }
53 :
54 : void
55 0 : ServoMediaList::IndexedGetter(uint32_t aIndex, bool& aFound,
56 : nsAString& aReturn)
57 : {
58 0 : aFound = Servo_MediaList_GetMediumAt(mRawList, aIndex, &aReturn);
59 0 : if (!aFound) {
60 0 : SetDOMStringToNull(aReturn);
61 : }
62 0 : }
63 :
64 : nsresult
65 0 : ServoMediaList::Append(const nsAString& aNewMedium)
66 : {
67 0 : if (aNewMedium.IsEmpty()) {
68 0 : return NS_ERROR_DOM_NOT_FOUND_ERR;
69 : }
70 0 : NS_ConvertUTF16toUTF8 newMedium(aNewMedium);
71 0 : Servo_MediaList_AppendMedium(mRawList, &newMedium);
72 0 : return NS_OK;
73 : }
74 :
75 : nsresult
76 0 : ServoMediaList::Delete(const nsAString& aOldMedium)
77 : {
78 0 : NS_ConvertUTF16toUTF8 oldMedium(aOldMedium);
79 0 : if (Servo_MediaList_DeleteMedium(mRawList, &oldMedium)) {
80 0 : return NS_OK;
81 : }
82 0 : return NS_ERROR_DOM_NOT_FOUND_ERR;
83 : }
84 :
85 : bool
86 0 : ServoMediaList::Matches(nsPresContext* aPresContext) const
87 : {
88 : const RawServoStyleSet* rawSet =
89 0 : aPresContext->StyleSet()->AsServo()->RawSet();
90 0 : MOZ_ASSERT(rawSet, "The RawServoStyleSet should be valid!");
91 0 : return Servo_MediaList_Matches(mRawList, rawSet);
92 : }
93 :
94 : } // namespace mozilla
|