1 | /* |
2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 | * Copyright (C) 2003-2017 Apple Inc. All right reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | * |
20 | */ |
21 | |
22 | #pragma once |
23 | |
24 | #include <unicode/uchar.h> |
25 | #include <wtf/RefCounted.h> |
26 | #include <wtf/RefPtr.h> |
27 | |
28 | namespace WebCore { |
29 | |
30 | enum BidiEmbeddingSource { FromStyleOrDOM, FromUnicode }; |
31 | |
32 | // Used to keep track of explicit embeddings. |
33 | class BidiContext : public RefCounted<BidiContext> { |
34 | public: |
35 | WEBCORE_EXPORT static Ref<BidiContext> create(unsigned char level, UCharDirection, bool override = false, BidiEmbeddingSource = FromStyleOrDOM, BidiContext* parent = nullptr); |
36 | |
37 | BidiContext* parent() const { return m_parent.get(); } |
38 | unsigned char level() const { return m_level; } |
39 | UCharDirection dir() const { return static_cast<UCharDirection>(m_direction); } |
40 | bool override() const { return m_override; } |
41 | BidiEmbeddingSource source() const { return static_cast<BidiEmbeddingSource>(m_source); } |
42 | |
43 | WEBCORE_EXPORT Ref<BidiContext> copyStackRemovingUnicodeEmbeddingContexts(); |
44 | |
45 | private: |
46 | BidiContext(unsigned char level, UCharDirection, bool override, BidiEmbeddingSource, BidiContext* parent); |
47 | |
48 | static Ref<BidiContext> createUncached(unsigned char level, UCharDirection, bool override, BidiEmbeddingSource, BidiContext* parent); |
49 | |
50 | unsigned m_level : 6; // The maximium bidi level is 62: http://unicode.org/reports/tr9/#Explicit_Levels_and_Directions |
51 | unsigned m_direction : 5; // Direction |
52 | unsigned m_override : 1; |
53 | unsigned m_source : 1; // BidiEmbeddingSource |
54 | RefPtr<BidiContext> m_parent; |
55 | }; |
56 | |
57 | inline unsigned char nextGreaterOddLevel(unsigned char level) |
58 | { |
59 | return (level + 1) | 1; |
60 | } |
61 | |
62 | inline unsigned char nextGreaterEvenLevel(unsigned char level) |
63 | { |
64 | return (level + 2) & ~1; |
65 | } |
66 | |
67 | bool operator==(const BidiContext&, const BidiContext&); |
68 | |
69 | } // namespace WebCore |
70 | |