OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2003, 2004, 2006, 2007, 2009, 2010 Apple Inc. | 3 * Copyright (C) 2003, 2004, 2006, 2007, 2009, 2010 Apple Inc. |
4 * All right reserved. | 4 * All right reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 BidiEmbeddingSource source, | 44 BidiEmbeddingSource source, |
45 BidiContext* parent) { | 45 BidiContext* parent) { |
46 return adoptRef(new BidiContext(level, direction, override, source, parent)); | 46 return adoptRef(new BidiContext(level, direction, override, source, parent)); |
47 } | 47 } |
48 | 48 |
49 PassRefPtr<BidiContext> BidiContext::create(unsigned char level, | 49 PassRefPtr<BidiContext> BidiContext::create(unsigned char level, |
50 CharDirection direction, | 50 CharDirection direction, |
51 bool override, | 51 bool override, |
52 BidiEmbeddingSource source, | 52 BidiEmbeddingSource source, |
53 BidiContext* parent) { | 53 BidiContext* parent) { |
54 ASSERT(direction == (level % 2 ? RightToLeft : LeftToRight)); | 54 DCHECK_EQ(direction, (level % 2 ? RightToLeft : LeftToRight)); |
55 | 55 |
56 if (parent || level >= 2) | 56 if (parent || level >= 2) |
57 return createUncached(level, direction, override, source, parent); | 57 return createUncached(level, direction, override, source, parent); |
58 | 58 |
59 ASSERT(level <= 1); | 59 DCHECK_LE(level, 1); |
60 if (!level) { | 60 if (!level) { |
61 if (!override) { | 61 if (!override) { |
62 DEFINE_STATIC_REF( | 62 DEFINE_STATIC_REF( |
63 BidiContext, ltrContext, | 63 BidiContext, ltrContext, |
64 (createUncached(0, LeftToRight, false, FromStyleOrDOM, 0))); | 64 (createUncached(0, LeftToRight, false, FromStyleOrDOM, 0))); |
65 return ltrContext; | 65 return ltrContext; |
66 } | 66 } |
67 | 67 |
68 DEFINE_STATIC_REF( | 68 DEFINE_STATIC_REF( |
69 BidiContext, ltrOverrideContext, | 69 BidiContext, ltrOverrideContext, |
70 (createUncached(0, LeftToRight, true, FromStyleOrDOM, 0))); | 70 (createUncached(0, LeftToRight, true, FromStyleOrDOM, 0))); |
71 return ltrOverrideContext; | 71 return ltrOverrideContext; |
72 } | 72 } |
73 | 73 |
74 if (!override) { | 74 if (!override) { |
75 DEFINE_STATIC_REF( | 75 DEFINE_STATIC_REF( |
76 BidiContext, rtlContext, | 76 BidiContext, rtlContext, |
77 (createUncached(1, RightToLeft, false, FromStyleOrDOM, 0))); | 77 (createUncached(1, RightToLeft, false, FromStyleOrDOM, 0))); |
78 return rtlContext; | 78 return rtlContext; |
79 } | 79 } |
80 | 80 |
81 DEFINE_STATIC_REF(BidiContext, rtlOverrideContext, | 81 DEFINE_STATIC_REF(BidiContext, rtlOverrideContext, |
82 (createUncached(1, RightToLeft, true, FromStyleOrDOM, 0))); | 82 (createUncached(1, RightToLeft, true, FromStyleOrDOM, 0))); |
83 return rtlOverrideContext; | 83 return rtlOverrideContext; |
84 } | 84 } |
85 | 85 |
86 static inline PassRefPtr<BidiContext> copyContextAndRebaselineLevel( | 86 static inline PassRefPtr<BidiContext> copyContextAndRebaselineLevel( |
87 BidiContext* context, | 87 BidiContext* context, |
88 BidiContext* parent) { | 88 BidiContext* parent) { |
89 ASSERT(context); | 89 DCHECK(context); |
90 unsigned char newLevel = parent ? parent->level() : 0; | 90 unsigned char newLevel = parent ? parent->level() : 0; |
91 if (context->dir() == RightToLeft) | 91 if (context->dir() == RightToLeft) |
92 newLevel = nextGreaterOddLevel(newLevel); | 92 newLevel = nextGreaterOddLevel(newLevel); |
93 else if (parent) | 93 else if (parent) |
94 newLevel = nextGreaterEvenLevel(newLevel); | 94 newLevel = nextGreaterEvenLevel(newLevel); |
95 | 95 |
96 return BidiContext::create(newLevel, context->dir(), context->override(), | 96 return BidiContext::create(newLevel, context->dir(), context->override(), |
97 context->source(), parent); | 97 context->source(), parent); |
98 } | 98 } |
99 | 99 |
100 // The BidiContext stack must be immutable -- they're re-used for re-layout | 100 // The BidiContext stack must be immutable -- they're re-used for re-layout |
101 // after DOM modification/editing -- so we copy all the non-unicode contexts, | 101 // after DOM modification/editing -- so we copy all the non-unicode contexts, |
102 // and recalculate their levels. | 102 // and recalculate their levels. |
103 PassRefPtr<BidiContext> | 103 PassRefPtr<BidiContext> |
104 BidiContext::copyStackRemovingUnicodeEmbeddingContexts() { | 104 BidiContext::copyStackRemovingUnicodeEmbeddingContexts() { |
105 Vector<BidiContext*, 64> contexts; | 105 Vector<BidiContext*, 64> contexts; |
106 for (BidiContext* iter = this; iter; iter = iter->parent()) { | 106 for (BidiContext* iter = this; iter; iter = iter->parent()) { |
107 if (iter->source() != FromUnicode) | 107 if (iter->source() != FromUnicode) |
108 contexts.push_back(iter); | 108 contexts.push_back(iter); |
109 } | 109 } |
110 ASSERT(contexts.size()); | 110 DCHECK(contexts.size()); |
111 | 111 |
112 RefPtr<BidiContext> topContext = | 112 RefPtr<BidiContext> topContext = |
113 copyContextAndRebaselineLevel(contexts.back(), 0); | 113 copyContextAndRebaselineLevel(contexts.back(), 0); |
114 for (int i = contexts.size() - 1; i > 0; --i) | 114 for (int i = contexts.size() - 1; i > 0; --i) |
115 topContext = | 115 topContext = |
116 copyContextAndRebaselineLevel(contexts[i - 1], topContext.get()); | 116 copyContextAndRebaselineLevel(contexts[i - 1], topContext.get()); |
117 | 117 |
118 return topContext.release(); | 118 return topContext.release(); |
119 } | 119 } |
120 | 120 |
121 bool operator==(const BidiContext& c1, const BidiContext& c2) { | 121 bool operator==(const BidiContext& c1, const BidiContext& c2) { |
122 if (&c1 == &c2) | 122 if (&c1 == &c2) |
123 return true; | 123 return true; |
124 if (c1.level() != c2.level() || c1.override() != c2.override() || | 124 if (c1.level() != c2.level() || c1.override() != c2.override() || |
125 c1.dir() != c2.dir() || c1.source() != c2.source()) | 125 c1.dir() != c2.dir() || c1.source() != c2.source()) |
126 return false; | 126 return false; |
127 if (!c1.parent()) | 127 if (!c1.parent()) |
128 return !c2.parent(); | 128 return !c2.parent(); |
129 return c2.parent() && *c1.parent() == *c2.parent(); | 129 return c2.parent() && *c1.parent() == *c2.parent(); |
130 } | 130 } |
131 | 131 |
132 } // namespace blink | 132 } // namespace blink |
OLD | NEW |