1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
* All right reserved.
* Copyright (C) 2010 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#ifndef BidiRunForLine_h
#define BidiRunForLine_h
#include "config.h"
#include "core/rendering/BidiRunForLine.h"
#include "core/rendering/InlineIterator.h"
namespace blink {
using namespace WTF::Unicode;
static RenderObject* firstRenderObjectForDirectionalityDetermination(
RenderObject* root, RenderObject* current = 0)
{
RenderObject* next = current;
while (current) {
if (isIsolated(current->style()->unicodeBidi())
&& (current->isRenderInline() || current->isRenderBlock())) {
if (current != root)
current = 0;
else
current = next;
break;
}
current = current->parent();
}
if (!current)
current = root->slowFirstChild();
while (current) {
next = 0;
if (isIteratorTarget(current) && !(current->isText()
&& toRenderText(current)->isAllCollapsibleWhitespace()))
break;
if (!isIteratorTarget(current)
&& !isIsolated(current->style()->unicodeBidi()))
next = current->slowFirstChild();
if (!next) {
while (current && current != root) {
next = current->nextSibling();
if (next)
break;
current = current->parent();
}
}
if (!next)
break;
current = next;
}
return current;
}
TextDirection determinePlaintextDirectionality(RenderObject* root,
RenderObject* current = 0, unsigned pos = 0)
{
RenderObject* firstRenderObject = firstRenderObjectForDirectionalityDetermination(root, current);
InlineIterator iter(root, firstRenderObject, firstRenderObject == current ? pos : 0);
InlineBidiResolver observer;
observer.setStatus(BidiStatus(root->style()->direction(),
isOverride(root->style()->unicodeBidi())));
observer.setPositionIgnoringNestedIsolates(iter);
return observer.determineParagraphDirectionality();
}
// FIXME: This should be a BidiStatus constructor or create method.
static inline BidiStatus statusWithDirection(TextDirection textDirection,
bool isOverride)
{
WTF::Unicode::Direction direction = textDirection == LTR
? LeftToRight
: RightToLeft;
RefPtr<BidiContext> context = BidiContext::create(
textDirection == LTR ? 0 : 1, direction, isOverride, FromStyleOrDOM);
// This copies BidiStatus and may churn the ref on BidiContext.
// I doubt it matters.
return BidiStatus(direction, direction, direction, context.release());
}
static inline void setupResolverToResumeInIsolate(InlineBidiResolver& resolver,
RenderObject* root, RenderObject* startObject)
{
if (root != startObject) {
RenderObject* parent = startObject->parent();
setupResolverToResumeInIsolate(resolver, root, parent);
notifyObserverEnteredObject(&resolver, startObject);
}
}
static void restoreIsolatedMidpointStates(InlineBidiResolver& topResolver,
InlineBidiResolver& isolatedResolver)
{
while (!isolatedResolver.isolatedRuns().isEmpty()) {
BidiRun* run = isolatedResolver.isolatedRuns().last();
isolatedResolver.isolatedRuns().removeLast();
topResolver.setMidpointStateForIsolatedRun(run,
isolatedResolver.midpointStateForIsolatedRun(run));
}
}
void constructBidiRunsForLine(InlineBidiResolver& topResolver,
BidiRunList<BidiRun>& bidiRuns, const InlineIterator& endOfLine,
VisualDirectionOverride override, bool previousLineBrokeCleanly,
bool isNewUBAParagraph)
{
// FIXME: We should pass a BidiRunList into createBidiRunsForLine instead
// of the resolver owning the runs.
ASSERT(&topResolver.runs() == &bidiRuns);
ASSERT(topResolver.position() != endOfLine);
RenderObject* currentRoot = topResolver.position().root();
topResolver.createBidiRunsForLine(endOfLine, override,
previousLineBrokeCleanly);
while (!topResolver.isolatedRuns().isEmpty()) {
// It does not matter which order we resolve the runs as long as we
// resolve them all.
BidiRun* isolatedRun = topResolver.isolatedRuns().last();
topResolver.isolatedRuns().removeLast();
RenderObject* startObj = isolatedRun->object();
// Only inlines make sense with unicode-bidi: isolate (blocks are
// already isolated).
// FIXME: Because enterIsolate is not passed a RenderObject, we have to
// crawl up the tree to see which parent inline is the isolate. We could
// change enterIsolate to take a RenderObject and do this logic there,
// but that would be a layering violation for BidiResolver (which knows
// nothing about RenderObject).
RenderInline* isolatedInline = toRenderInline(
highestContainingIsolateWithinRoot(startObj, currentRoot));
ASSERT(isolatedInline);
InlineBidiResolver isolatedResolver;
LineMidpointState& isolatedLineMidpointState =
isolatedResolver.midpointState();
isolatedLineMidpointState = topResolver.midpointStateForIsolatedRun(
isolatedRun);
EUnicodeBidi unicodeBidi = isolatedInline->style()->unicodeBidi();
TextDirection direction;
if (unicodeBidi == Plaintext) {
direction = determinePlaintextDirectionality(isolatedInline,
isNewUBAParagraph ? startObj : 0);
} else {
ASSERT(unicodeBidi == Isolate || unicodeBidi == IsolateOverride);
direction = isolatedInline->style()->direction();
}
isolatedResolver.setStatus(statusWithDirection(direction,
isOverride(unicodeBidi)));
setupResolverToResumeInIsolate(isolatedResolver, isolatedInline,
startObj);
// The starting position is the beginning of the first run within the
// isolate that was identified during the earlier call to
// createBidiRunsForLine. This can be but is not necessarily the first
// run within the isolate.
InlineIterator iter = InlineIterator(isolatedInline, startObj,
isolatedRun->m_start);
isolatedResolver.setPositionIgnoringNestedIsolates(iter);
// We stop at the next end of line; we may re-enter this isolate in the
// next call to constructBidiRuns().
// FIXME: What should end and previousLineBrokeCleanly be?
// rniwa says previousLineBrokeCleanly is just a WinIE hack and could
// always be false here?
isolatedResolver.createBidiRunsForLine(endOfLine, NoVisualOverride,
previousLineBrokeCleanly);
ASSERT(isolatedResolver.runs().runCount());
if (isolatedResolver.runs().runCount())
bidiRuns.replaceRunWithRuns(isolatedRun, isolatedResolver.runs());
// If we encountered any nested isolate runs, just move them
// to the top resolver's list for later processing.
if (!isolatedResolver.isolatedRuns().isEmpty()) {
topResolver.isolatedRuns().appendVector(
isolatedResolver.isolatedRuns());
currentRoot = isolatedInline;
restoreIsolatedMidpointStates(topResolver, isolatedResolver);
}
}
}
} // namespace blink
#endif // BidiRunForLine_h
|