Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / gfx / thebes / public / gfxTextRunCache.h
blob92d09446de308b43da3a3a736c5b1522cbef6df8
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla Foundation code.
17 * The Initial Developer of the Original Code is Mozilla Foundation.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Vladimir Vukicevic <vladimir@pobox.com>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef GFX_TEXT_RUN_CACHE_H
39 #define GFX_TEXT_RUN_CACHE_H
41 #include "gfxFont.h"
43 /**
44 * A simple textrun cache for textruns that do not carry state
45 * (e.g., actual or potential linebreaks) and do not need complex initialization.
46 * The lifetimes of these textruns are managed by the cache (they are auto-expired
47 * after a certain period of time).
49 class THEBES_API gfxTextRunCache {
50 public:
51 /**
52 * Get a textrun for the given text, using a global cache. The textrun
53 * must be released via ReleaseTextRun, not deleted.
54 * Do not set any state in the textrun (e.g. actual or potential linebreaks).
55 * Flags IS_8BIT, IS_ASCII and HAS_SURROGATES are automatically set
56 * appropriately.
57 * Flag IS_PERSISTENT must NOT be set unless aText is guaranteed to live
58 * forever.
59 * The string can contain any characters, invalid ones will be stripped
60 * properly.
62 static gfxTextRun *MakeTextRun(const PRUnichar *aText, PRUint32 aLength,
63 gfxFontGroup *aFontGroup,
64 gfxContext *aRefContext,
65 PRUint32 aAppUnitsPerDevUnit,
66 PRUint32 aFlags);
68 /**
69 * As above, but allows a full Parameters object to be passed in.
71 static gfxTextRun *MakeTextRun(const PRUnichar *aText, PRUint32 aLength,
72 gfxFontGroup *aFontGroup,
73 const gfxTextRunFactory::Parameters* aParams,
74 PRUint32 aFlags);
76 /**
77 * Get a textrun for the given text, using a global cache. The textrun
78 * must be released via ReleaseTextRun, not deleted.
79 * Do not set any state in the textrun (e.g. actual or potential linebreaks).
80 * Flags IS_8BIT, IS_ASCII and HAS_SURROGATES are automatically set
81 * appropriately.
82 * Flag IS_PERSISTENT must NOT be set unless aText is guaranteed to live
83 * forever.
84 * The string can contain any characters, invalid ones will be stripped
85 * properly.
87 static gfxTextRun *MakeTextRun(const PRUint8 *aText, PRUint32 aLength,
88 gfxFontGroup *aFontGroup,
89 gfxContext *aRefContext,
90 PRUint32 aAppUnitsPerDevUnit,
91 PRUint32 aFlags);
93 /**
94 * Release a previously acquired textrun. Consider using AutoTextRun
95 * instead of calling this.
97 static void ReleaseTextRun(gfxTextRun *aTextRun);
99 class AutoTextRun {
100 public:
101 AutoTextRun(gfxTextRun *aTextRun) : mTextRun(aTextRun) {}
102 AutoTextRun() : mTextRun(nsnull) {}
103 AutoTextRun& operator=(gfxTextRun *aTextRun) {
104 gfxTextRunCache::ReleaseTextRun(mTextRun);
105 mTextRun = aTextRun;
106 return *this;
108 ~AutoTextRun() {
109 gfxTextRunCache::ReleaseTextRun(mTextRun);
111 gfxTextRun *get() { return mTextRun; }
112 gfxTextRun *operator->() { return mTextRun; }
113 private:
114 gfxTextRun *mTextRun;
117 protected:
118 friend class gfxPlatform;
120 static nsresult Init();
121 static void Shutdown();
124 #endif /* GFX_TEXT_RUN_CACHE_H */