1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll (at) kde.org) 3 * Copyright (C) 2003, 2004, 2006, 2007, 2009 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 #include "config.h" 23 #include "BidiContext.h" 24 25 #include <wtf/StdLibExtras.h> 26 27 namespace WebCore { 28 29 using namespace WTF::Unicode; 30 31 PassRefPtr<BidiContext> BidiContext::create(unsigned char level, Direction direction, bool override, BidiContext* parent) 32 { 33 ASSERT(direction == (level % 2 ? RightToLeft : LeftToRight)); 34 35 if (parent) 36 return adoptRef(new BidiContext(level, direction, override, parent)); 37 38 ASSERT(level <= 1); 39 if (!level) { 40 DEFINE_STATIC_LOCAL(BidiContext, ltrContext, (0, LeftToRight, false, 0)); 41 if (!override) 42 return <rContext; 43 44 DEFINE_STATIC_LOCAL(BidiContext, ltrOverrideContext, (0, LeftToRight, true, 0)); 45 return <rOverrideContext; 46 } 47 48 DEFINE_STATIC_LOCAL(BidiContext, rtlContext, (1, RightToLeft, false, 0)); 49 if (!override) 50 return &rtlContext; 51 52 DEFINE_STATIC_LOCAL(BidiContext, rtlOverrideContext, (1, RightToLeft, true, 0)); 53 return &rtlOverrideContext; 54 } 55 56 bool operator==(const BidiContext& c1, const BidiContext& c2) 57 { 58 if (&c1 == &c2) 59 return true; 60 if (c1.level() != c2.level() || c1.override() != c2.override() || c1.dir() != c2.dir()) 61 return false; 62 if (!c1.parent()) 63 return !c2.parent(); 64 return c2.parent() && *c1.parent() == *c2.parent(); 65 } 66 67 } // namespace WebCore 68