1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2003, 2004, 2006, 2007 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 #ifndef BidiContext_h 23 #define BidiContext_h 24 25 #include <wtf/Assertions.h> 26 #include <wtf/RefPtr.h> 27 #include <wtf/unicode/Unicode.h> 28 29 namespace WebCore { 30 31 // Used to keep track of explicit embeddings. 32 class BidiContext { 33 public: 34 BidiContext(unsigned char level, WTF::Unicode::Direction direction, bool override = false, BidiContext* parent = 0) m_level(level)35 : m_level(level) 36 , m_direction(direction) 37 , m_override(override) 38 , m_parent(parent) 39 , m_refCount(0) 40 { 41 ASSERT(direction == WTF::Unicode::LeftToRight || direction == WTF::Unicode::RightToLeft); 42 } 43 ref()44 void ref() const { m_refCount++; } deref()45 void deref() const 46 { 47 m_refCount--; 48 if (m_refCount <= 0) 49 delete this; 50 } 51 parent()52 BidiContext* parent() const { return m_parent.get(); } level()53 unsigned char level() const { return m_level; } dir()54 WTF::Unicode::Direction dir() const { return static_cast<WTF::Unicode::Direction>(m_direction); } override()55 bool override() const { return m_override; } 56 57 private: 58 unsigned char m_level; 59 unsigned m_direction : 5; // Direction 60 bool m_override : 1; 61 RefPtr<BidiContext> m_parent; 62 mutable int m_refCount; 63 }; 64 65 bool operator==(const BidiContext&, const BidiContext&); 66 67 } // namespace WebCore 68 69 #endif // BidiContext_h 70