1/*
2 * Copyright (C) 2018 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "FontShadow.h"
29#include "RenderStyleConstants.h"
30#include <wtf/RetainPtr.h>
31
32OBJC_CLASS NSDictionary;
33OBJC_CLASS NSFont;
34OBJC_CLASS NSTextList;
35OBJC_CLASS UIFont;
36
37namespace WebCore {
38
39struct TextList {
40 ListStyleType style { ListStyleType::None };
41 int startingItemNumber { 0 };
42 bool ordered { false };
43
44 template<class Encoder> void encode(Encoder&) const;
45 template<class Decoder> static Optional<TextList> decode(Decoder&);
46
47#if PLATFORM(COCOA)
48 RetainPtr<NSTextList> createTextList() const;
49#endif
50};
51
52template<class Encoder> inline void TextList::encode(Encoder& encoder) const
53{
54 encoder << static_cast<uint8_t>(style) << startingItemNumber << ordered;
55}
56
57template<class Decoder> inline Optional<TextList> TextList::decode(Decoder& decoder)
58{
59 Optional<uint8_t> style;
60 decoder >> style;
61 if (!style)
62 return WTF::nullopt;
63
64 Optional<int> startingItemNumber;
65 decoder >> startingItemNumber;
66 if (!startingItemNumber)
67 return WTF::nullopt;
68
69 Optional<bool> ordered;
70 decoder >> ordered;
71 if (!ordered)
72 return WTF::nullopt;
73
74 return {{ static_cast<ListStyleType>(WTFMove(*style)), WTFMove(*startingItemNumber), WTFMove(*ordered) }};
75}
76
77struct FontAttributes {
78 enum class SubscriptOrSuperscript : uint8_t { None, Subscript, Superscript };
79 enum class HorizontalAlignment : uint8_t { Left, Center, Right, Justify, Natural };
80
81#if PLATFORM(COCOA)
82 bool encodingRequiresPlatformData() const { return true; }
83
84 WEBCORE_EXPORT RetainPtr<NSDictionary> createDictionary() const;
85#else
86 bool encodingRequiresPlatformData() const { return false; }
87#endif
88
89#if PLATFORM(MAC)
90 RetainPtr<NSFont> font;
91#elif PLATFORM(IOS_FAMILY)
92 RetainPtr<UIFont> font;
93#endif
94 Color backgroundColor;
95 Color foregroundColor;
96 FontShadow fontShadow;
97 SubscriptOrSuperscript subscriptOrSuperscript { SubscriptOrSuperscript::None };
98 HorizontalAlignment horizontalAlignment { HorizontalAlignment::Left };
99 Vector<TextList> textLists;
100 bool hasUnderline { false };
101 bool hasStrikeThrough { false };
102};
103
104} // namespace WebCore
105
106namespace WTF {
107
108template<> struct EnumTraits<WebCore::FontAttributes::SubscriptOrSuperscript> {
109 using values = EnumValues<
110 WebCore::FontAttributes::SubscriptOrSuperscript,
111 WebCore::FontAttributes::SubscriptOrSuperscript::None,
112 WebCore::FontAttributes::SubscriptOrSuperscript::Subscript,
113 WebCore::FontAttributes::SubscriptOrSuperscript::Superscript
114 >;
115};
116
117template<> struct EnumTraits<WebCore::FontAttributes::HorizontalAlignment> {
118 using values = EnumValues<
119 WebCore::FontAttributes::HorizontalAlignment,
120 WebCore::FontAttributes::HorizontalAlignment::Left,
121 WebCore::FontAttributes::HorizontalAlignment::Center,
122 WebCore::FontAttributes::HorizontalAlignment::Right,
123 WebCore::FontAttributes::HorizontalAlignment::Justify,
124 WebCore::FontAttributes::HorizontalAlignment::Natural
125 >;
126};
127
128} // namespace WTF
129