| 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 ? kRightToLeft : kLeftToRight)); | 54 DCHECK_EQ(direction, (level % 2 ? kRightToLeft : kLeftToRight)); |
| 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, ltr_context, | 63 BidiContext, ltr_context, |
| 64 (CreateUncached(0, kLeftToRight, false, kFromStyleOrDOM, 0))); | 64 (CreateUncached(0, kLeftToRight, false, kFromStyleOrDOM, 0))); |
| 65 return ltr_context; | 65 return ltr_context; |
| 66 } | 66 } |
| 67 | 67 |
| 68 DEFINE_STATIC_REF( | 68 DEFINE_STATIC_REF( |
| 69 BidiContext, ltr_override_context, | 69 BidiContext, ltr_override_context, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 | 80 |
| 81 DEFINE_STATIC_REF( | 81 DEFINE_STATIC_REF( |
| 82 BidiContext, rtl_override_context, | 82 BidiContext, rtl_override_context, |
| 83 (CreateUncached(1, kRightToLeft, true, kFromStyleOrDOM, 0))); | 83 (CreateUncached(1, kRightToLeft, true, kFromStyleOrDOM, 0))); |
| 84 return rtl_override_context; | 84 return rtl_override_context; |
| 85 } | 85 } |
| 86 | 86 |
| 87 static inline PassRefPtr<BidiContext> CopyContextAndRebaselineLevel( | 87 static inline PassRefPtr<BidiContext> CopyContextAndRebaselineLevel( |
| 88 BidiContext* context, | 88 BidiContext* context, |
| 89 BidiContext* parent) { | 89 BidiContext* parent) { |
| 90 ASSERT(context); | 90 DCHECK(context); |
| 91 unsigned char new_level = parent ? parent->Level() : 0; | 91 unsigned char new_level = parent ? parent->Level() : 0; |
| 92 if (context->Dir() == kRightToLeft) | 92 if (context->Dir() == kRightToLeft) |
| 93 new_level = NextGreaterOddLevel(new_level); | 93 new_level = NextGreaterOddLevel(new_level); |
| 94 else if (parent) | 94 else if (parent) |
| 95 new_level = NextGreaterEvenLevel(new_level); | 95 new_level = NextGreaterEvenLevel(new_level); |
| 96 | 96 |
| 97 return BidiContext::Create(new_level, context->Dir(), context->Override(), | 97 return BidiContext::Create(new_level, context->Dir(), context->Override(), |
| 98 context->Source(), parent); | 98 context->Source(), parent); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // The BidiContext stack must be immutable -- they're re-used for re-layout | 101 // The BidiContext stack must be immutable -- they're re-used for re-layout |
| 102 // after DOM modification/editing -- so we copy all the non-unicode contexts, | 102 // after DOM modification/editing -- so we copy all the non-unicode contexts, |
| 103 // and recalculate their levels. | 103 // and recalculate their levels. |
| 104 PassRefPtr<BidiContext> | 104 PassRefPtr<BidiContext> |
| 105 BidiContext::CopyStackRemovingUnicodeEmbeddingContexts() { | 105 BidiContext::CopyStackRemovingUnicodeEmbeddingContexts() { |
| 106 Vector<BidiContext*, 64> contexts; | 106 Vector<BidiContext*, 64> contexts; |
| 107 for (BidiContext* iter = this; iter; iter = iter->Parent()) { | 107 for (BidiContext* iter = this; iter; iter = iter->Parent()) { |
| 108 if (iter->Source() != kFromUnicode) | 108 if (iter->Source() != kFromUnicode) |
| 109 contexts.push_back(iter); | 109 contexts.push_back(iter); |
| 110 } | 110 } |
| 111 ASSERT(contexts.size()); | 111 DCHECK(contexts.size()); |
| 112 | 112 |
| 113 RefPtr<BidiContext> top_context = | 113 RefPtr<BidiContext> top_context = |
| 114 CopyContextAndRebaselineLevel(contexts.back(), 0); | 114 CopyContextAndRebaselineLevel(contexts.back(), 0); |
| 115 for (int i = contexts.size() - 1; i > 0; --i) | 115 for (int i = contexts.size() - 1; i > 0; --i) |
| 116 top_context = | 116 top_context = |
| 117 CopyContextAndRebaselineLevel(contexts[i - 1], top_context.Get()); | 117 CopyContextAndRebaselineLevel(contexts[i - 1], top_context.Get()); |
| 118 | 118 |
| 119 return top_context.Release(); | 119 return top_context.Release(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool operator==(const BidiContext& c1, const BidiContext& c2) { | 122 bool operator==(const BidiContext& c1, const BidiContext& c2) { |
| 123 if (&c1 == &c2) | 123 if (&c1 == &c2) |
| 124 return true; | 124 return true; |
| 125 if (c1.Level() != c2.Level() || c1.Override() != c2.Override() || | 125 if (c1.Level() != c2.Level() || c1.Override() != c2.Override() || |
| 126 c1.Dir() != c2.Dir() || c1.Source() != c2.Source()) | 126 c1.Dir() != c2.Dir() || c1.Source() != c2.Source()) |
| 127 return false; | 127 return false; |
| 128 if (!c1.Parent()) | 128 if (!c1.Parent()) |
| 129 return !c2.Parent(); | 129 return !c2.Parent(); |
| 130 return c2.Parent() && *c1.Parent() == *c2.Parent(); | 130 return c2.Parent() && *c1.Parent() == *c2.Parent(); |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace blink | 133 } // namespace blink |
| OLD | NEW |