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

Side by Side Diff: Source/core/rendering/InlineIterator.h

Issue 26315003: Bidi-Isolate inlines break layout with collapsed whitespace (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All right r eserved. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All right r eserved.
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // FIXME: This belongs on InlineBidiResolver, except it's a template specializat ion 467 // FIXME: This belongs on InlineBidiResolver, except it's a template specializat ion
468 // of BidiResolver which knows nothing about RenderObjects. 468 // of BidiResolver which knows nothing about RenderObjects.
469 static inline void addPlaceholderRunForIsolatedInline(InlineBidiResolver& resolv er, RenderObject* obj, unsigned pos) 469 static inline void addPlaceholderRunForIsolatedInline(InlineBidiResolver& resolv er, RenderObject* obj, unsigned pos)
470 { 470 {
471 ASSERT(obj); 471 ASSERT(obj);
472 BidiRun* isolatedRun = new BidiRun(pos, 0, obj, resolver.context(), resolver .dir()); 472 BidiRun* isolatedRun = new BidiRun(pos, 0, obj, resolver.context(), resolver .dir());
473 resolver.runs().addRun(isolatedRun); 473 resolver.runs().addRun(isolatedRun);
474 // FIXME: isolatedRuns() could be a hash of object->run and then we could ch eaply 474 // FIXME: isolatedRuns() could be a hash of object->run and then we could ch eaply
475 // ASSERT here that we didn't create multiple objects for the same inline. 475 // ASSERT here that we didn't create multiple objects for the same inline.
476 resolver.isolatedRuns().append(isolatedRun); 476 resolver.isolatedRuns().append(isolatedRun);
477 LineMidpointState& lineMidpointState = resolver.midpointState();
478 resolver.setMidpointStateForIsolatedRun(isolatedRun, lineMidpointState);
477 } 479 }
478 480
479 class IsolateTracker { 481 class IsolateTracker {
480 public: 482 public:
481 explicit IsolateTracker(unsigned nestedIsolateCount) 483 explicit IsolateTracker(unsigned nestedIsolateCount)
482 : m_nestedIsolateCount(nestedIsolateCount) 484 : m_nestedIsolateCount(nestedIsolateCount)
483 , m_haveAddedFakeRunForRootIsolate(false) 485 , m_haveAddedFakeRunForRootIsolate(false)
484 { 486 {
485 } 487 }
486 488
487 void enterIsolate() { m_nestedIsolateCount++; } 489 void enterIsolate() { m_nestedIsolateCount++; }
488 void exitIsolate() 490 void exitIsolate()
489 { 491 {
490 ASSERT(m_nestedIsolateCount >= 1); 492 ASSERT(m_nestedIsolateCount >= 1);
491 m_nestedIsolateCount--; 493 m_nestedIsolateCount--;
492 if (!inIsolate()) 494 if (!inIsolate())
493 m_haveAddedFakeRunForRootIsolate = false; 495 m_haveAddedFakeRunForRootIsolate = false;
494 } 496 }
495 bool inIsolate() const { return m_nestedIsolateCount; } 497 bool inIsolate() const { return m_nestedIsolateCount; }
496 498
497 // We don't care if we encounter bidi directional overrides. 499 // We don't care if we encounter bidi directional overrides.
498 void embed(WTF::Unicode::Direction, BidiEmbeddingSource) { } 500 void embed(WTF::Unicode::Direction, BidiEmbeddingSource) { }
499 void commitExplicitEmbedding() { } 501 void commitExplicitEmbedding() { }
500 502
501 void addFakeRunIfNecessary(RenderObject* obj, unsigned pos, InlineBidiResolv er& resolver) 503 void adjustMidpointForIsolatedRun(RenderObject* obj, unsigned start, unsigne d end, InlineBidiResolver& resolver)
leviw_travelin_and_unemployed 2013/10/07 21:58:42 This seems really similar to RenderBlock::appendRu
504 {
505 if (start > end)
506 return;
507
508 LineMidpointState& lineMidpointState = resolver.midpointState();
509 bool haveNextMidpoint = (lineMidpointState.currentMidpoint < lineMidpoin tState.numMidpoints);
510 InlineIterator nextMidpoint;
511 if (haveNextMidpoint)
512 nextMidpoint = lineMidpointState.midpoints[lineMidpointState.current Midpoint];
513 if (lineMidpointState.betweenMidpoints) {
514 if (!(haveNextMidpoint && nextMidpoint.m_obj == obj))
515 return;
516 lineMidpointState.betweenMidpoints = false;
517 lineMidpointState.currentMidpoint++;
518 if (start < end)
519 return adjustMidpointForIsolatedRun(obj, start, end, resolver);
520 } else {
521 if (!haveNextMidpoint || (obj != nextMidpoint.m_obj))
522 return;
523 if (static_cast<int>(nextMidpoint.m_pos + 1) <= end) {
524 lineMidpointState.betweenMidpoints = true;
525 lineMidpointState.currentMidpoint++;
526 if (nextMidpoint.m_pos != UINT_MAX)
527 return adjustMidpointForIsolatedRun(obj, nextMidpoint.m_pos + 1, end, resolver);
528 }
529 }
530 }
531
532 void addFakeRunIfNecessary(RenderObject* obj, unsigned pos, unsigned end, In lineBidiResolver& resolver)
502 { 533 {
503 // We only need to add a fake run for a given isolated span once during each call to createBidiRunsForLine. 534 // We only need to add a fake run for a given isolated span once during each call to createBidiRunsForLine.
504 // We'll be called for every span inside the isolated span so we just ig nore subsequent calls. 535 // We'll be called for every span inside the isolated span so we just ig nore subsequent calls.
505 // We also avoid creating a fake run until we hit a child that warrants one, e.g. we skip floats. 536 // We also avoid creating a fake run until we hit a child that warrants one, e.g. we skip floats.
506 if (m_haveAddedFakeRunForRootIsolate || RenderBlock::shouldSkipCreatingR unsForObject(obj)) 537 if (!(m_haveAddedFakeRunForRootIsolate || RenderBlock::shouldSkipCreatin gRunsForObject(obj))) {
507 return; 538 addPlaceholderRunForIsolatedInline(resolver, obj, pos);
508 m_haveAddedFakeRunForRootIsolate = true; 539 m_haveAddedFakeRunForRootIsolate = true;
540 }
541 adjustMidpointForIsolatedRun(obj, pos, end, resolver);
542
509 // obj and pos together denote a single position in the inline, from whi ch the parsing of the isolate will start. 543 // obj and pos together denote a single position in the inline, from whi ch the parsing of the isolate will start.
510 // We don't need to mark the end of the run because this is implicit: it is either endOfLine or the end of the 544 // We don't need to mark the end of the run because this is implicit: it is either endOfLine or the end of the
511 // isolate, when we call createBidiRunsForLine it will stop at whichever comes first. 545 // isolate, when we call createBidiRunsForLine it will stop at whichever comes first.
512 addPlaceholderRunForIsolatedInline(resolver, obj, pos);
513 // FIXME: Inline isolates don't work properly with collapsing whitespace , see webkit.org/b/109624
514 // For now, if we enter an isolate between midpoints, we increment our c urrent midpoint or else
515 // we'll leave the isolate and ignore the content that follows.
516 MidpointState<InlineIterator>& midpointState = resolver.midpointState();
517 if (midpointState.betweenMidpoints && midpointState.midpoints[midpointSt ate.currentMidpoint].object() == obj) {
518 midpointState.betweenMidpoints = false;
519 ++midpointState.currentMidpoint;
520 }
521 } 546 }
522 547
523 private: 548 private:
524 unsigned m_nestedIsolateCount; 549 unsigned m_nestedIsolateCount;
525 bool m_haveAddedFakeRunForRootIsolate; 550 bool m_haveAddedFakeRunForRootIsolate;
526 }; 551 };
527 552
528 template <> 553 template <>
529 inline void InlineBidiResolver::appendRun() 554 inline void InlineBidiResolver::appendRun()
530 { 555 {
531 if (!m_emptyRun && !m_eor.atEnd() && !m_reachedEndOfLine) { 556 if (!m_emptyRun && !m_eor.atEnd() && !m_reachedEndOfLine) {
532 // Keep track of when we enter/leave "unicode-bidi: isolate" inlines. 557 // Keep track of when we enter/leave "unicode-bidi: isolate" inlines.
533 // Initialize our state depending on if we're starting in the middle of such an inline. 558 // Initialize our state depending on if we're starting in the middle of such an inline.
534 // FIXME: Could this initialize from this->inIsolate() instead of walkin g up the render tree? 559 // FIXME: Could this initialize from this->inIsolate() instead of walkin g up the render tree?
535 IsolateTracker isolateTracker(numberOfIsolateAncestors(m_sor)); 560 IsolateTracker isolateTracker(numberOfIsolateAncestors(m_sor));
536 int start = m_sor.m_pos; 561 int start = m_sor.m_pos;
537 RenderObject* obj = m_sor.m_obj; 562 RenderObject* obj = m_sor.m_obj;
538 while (obj && obj != m_eor.m_obj && obj != endOfLine.m_obj) { 563 while (obj && obj != m_eor.m_obj && obj != endOfLine.m_obj) {
539 if (isolateTracker.inIsolate()) 564 if (isolateTracker.inIsolate())
540 isolateTracker.addFakeRunIfNecessary(obj, start, *this); 565 isolateTracker.addFakeRunIfNecessary(obj, start, obj->length(), *this);
541 else 566 else
542 RenderBlock::appendRunsForObject(m_runs, start, obj->length(), o bj, *this); 567 RenderBlock::appendRunsForObject(m_runs, start, obj->length(), o bj, *this);
543 // FIXME: start/obj should be an InlineIterator instead of two separ ate variables. 568 // FIXME: start/obj should be an InlineIterator instead of two separ ate variables.
544 start = 0; 569 start = 0;
545 obj = bidiNextSkippingEmptyInlines(m_sor.root(), obj, &isolateTracke r); 570 obj = bidiNextSkippingEmptyInlines(m_sor.root(), obj, &isolateTracke r);
546 } 571 }
547 if (obj) { 572 if (obj) {
548 unsigned pos = obj == m_eor.m_obj ? m_eor.m_pos : INT_MAX; 573 unsigned pos = obj == m_eor.m_obj ? m_eor.m_pos : INT_MAX;
549 if (obj == endOfLine.m_obj && endOfLine.m_pos <= pos) { 574 if (obj == endOfLine.m_obj && endOfLine.m_pos <= pos) {
550 m_reachedEndOfLine = true; 575 m_reachedEndOfLine = true;
551 pos = endOfLine.m_pos; 576 pos = endOfLine.m_pos;
552 } 577 }
553 // It's OK to add runs for zero-length RenderObjects, just don't mak e the run larger than it should be 578 // It's OK to add runs for zero-length RenderObjects, just don't mak e the run larger than it should be
554 int end = obj->length() ? pos + 1 : 0; 579 int end = obj->length() ? pos + 1 : 0;
555 if (isolateTracker.inIsolate()) 580 if (isolateTracker.inIsolate())
556 isolateTracker.addFakeRunIfNecessary(obj, start, *this); 581 isolateTracker.addFakeRunIfNecessary(obj, start, end, *this);
557 else 582 else
558 RenderBlock::appendRunsForObject(m_runs, start, end, obj, *this) ; 583 RenderBlock::appendRunsForObject(m_runs, start, end, obj, *this) ;
559 } 584 }
560 585
561 m_eor.increment(); 586 m_eor.increment();
562 m_sor = m_eor; 587 m_sor = m_eor;
563 } 588 }
564 589
565 m_direction = WTF::Unicode::OtherNeutral; 590 m_direction = WTF::Unicode::OtherNeutral;
566 m_status.eor = WTF::Unicode::OtherNeutral; 591 m_status.eor = WTF::Unicode::OtherNeutral;
567 } 592 }
568 593
569 } 594 }
570 595
571 #endif // InlineIterator_h 596 #endif // InlineIterator_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698