Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: Source/core/platform/text/BidiContext.cpp

Issue 25555005: Move text/BidiContext to Source/platform/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2009, 2010 Apple Inc. All right reserve d.
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 #include "config.h"
23 #include "core/platform/text/BidiContext.h"
24 #include "wtf/Vector.h"
25
26 namespace WebCore {
27
28 using namespace WTF::Unicode;
29
30 struct SameSizeAsBidiContext : public RefCounted<SameSizeAsBidiContext> {
31 uint32_t bitfields : 16;
32 void* parent;
33 };
34
35 COMPILE_ASSERT(sizeof(BidiContext) == sizeof(SameSizeAsBidiContext), BidiContext _should_stay_small);
36
37 inline PassRefPtr<BidiContext> BidiContext::createUncached(unsigned char level, Direction direction, bool override, BidiEmbeddingSource source, BidiContext* par ent)
38 {
39 return adoptRef(new BidiContext(level, direction, override, source, parent)) ;
40 }
41
42 PassRefPtr<BidiContext> BidiContext::create(unsigned char level, Direction direc tion, bool override, BidiEmbeddingSource source, BidiContext* parent)
43 {
44 ASSERT(direction == (level % 2 ? RightToLeft : LeftToRight));
45
46 if (parent)
47 return createUncached(level, direction, override, source, parent);
48
49 ASSERT(level <= 1);
50 if (!level) {
51 if (!override) {
52 static BidiContext* ltrContext = createUncached(0, LeftToRight, fals e, FromStyleOrDOM, 0).leakRef();
53 return ltrContext;
54 }
55
56 static BidiContext* ltrOverrideContext = createUncached(0, LeftToRight, true, FromStyleOrDOM, 0).leakRef();
57 return ltrOverrideContext;
58 }
59
60 if (!override) {
61 static BidiContext* rtlContext = createUncached(1, RightToLeft, false, F romStyleOrDOM, 0).leakRef();
62 return rtlContext;
63 }
64
65 static BidiContext* rtlOverrideContext = createUncached(1, RightToLeft, true , FromStyleOrDOM, 0).leakRef();
66 return rtlOverrideContext;
67 }
68
69 static inline PassRefPtr<BidiContext> copyContextAndRebaselineLevel(BidiContext* context, BidiContext* parent)
70 {
71 ASSERT(context);
72 unsigned char newLevel = parent ? parent->level() : 0;
73 if (context->dir() == RightToLeft)
74 newLevel = nextGreaterOddLevel(newLevel);
75 else if (parent)
76 newLevel = nextGreaterEvenLevel(newLevel);
77
78 return BidiContext::create(newLevel, context->dir(), context->override(), co ntext->source(), parent);
79 }
80
81 // The BidiContext stack must be immutable -- they're re-used for re-layout afte r
82 // DOM modification/editing -- so we copy all the non-unicode contexts, and
83 // recalculate their levels.
84 PassRefPtr<BidiContext> BidiContext::copyStackRemovingUnicodeEmbeddingContexts()
85 {
86 Vector<BidiContext*, 64> contexts;
87 for (BidiContext* iter = this; iter; iter = iter->parent()) {
88 if (iter->source() != FromUnicode)
89 contexts.append(iter);
90 }
91 ASSERT(contexts.size());
92
93 RefPtr<BidiContext> topContext = copyContextAndRebaselineLevel(contexts.last (), 0);
94 for (int i = contexts.size() - 1; i > 0; --i)
95 topContext = copyContextAndRebaselineLevel(contexts[i - 1], topContext.g et());
96
97 return topContext.release();
98 }
99
100 bool operator==(const BidiContext& c1, const BidiContext& c2)
101 {
102 if (&c1 == &c2)
103 return true;
104 if (c1.level() != c2.level() || c1.override() != c2.override() || c1.dir() ! = c2.dir() || c1.source() != c2.source())
105 return false;
106 if (!c1.parent())
107 return !c2.parent();
108 return c2.parent() && *c1.parent() == *c2.parent();
109 }
110
111 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698