Commit 6f6afe2f authored by Koji Ishii's avatar Koji Ishii Committed by Commit Bot

Fix not to wrap in 'nowrap' elements

When a word in 'nowrap' element fits but its trailing space
does not, issue 561997 fixed not to wrap before the 'nowrap'
element.

The fix, however, creates a wrap opportunity even if 'nowrap'
content follows. This patch ensures the fix is valid only if
no content follows or autowrap content follows; i.e., only
when we really have a break opportunity after the space.

Ideally, the original fix should have been done when the line
breaker reads the next item. But we have a lot of places that
call FitsOnLine() without 'ExcludeWhitespace' option and
probably some of them are not correct. To make the fix safer,
this patch limits the original fix instead of cleaning up all
FitsOnLine() calls.

Change-Id: I78c499cc6c1d7c30261e031ec19124ae9d3fbcf1
Bug: 561997, 840755
Reviewed-on: https://chromium-review.googlesource.com/1053341Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557556}
parent 035c0c8f
<!DOCTYPE html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<style>
.container {
width:200px;
background-color:#eee;
}
.spacer {
height:10px; background-color:black;
}
.nowrap {
white-space: nowrap;
}
</style>
<body>
<p>Spaces in nowrap shold not break when the text before it fits but the space overflows.</p>
<template id=template>
<div class=container>
<img class=spacer />
<span class=nowrap><span>foo</span> <span>bar</span></span>
</div>
</template>
<script>
run();
function run() {
let tests = [];
for (let width = 170; width < 180; width++) {
let element = template.content.children[0].cloneNode(true);
let spacer = element.querySelector('img');
spacer.style.width = width + 'px';
document.body.appendChild(element);
tests.push({width: width, element: element});
}
let results = [];
for (let t of tests) {
test(() => {
let nowrap = t.element.querySelector('.nowrap');
let child1 = nowrap.children[0];
let child2 = nowrap.children[1];
assert_equals(child1.offsetTop, child2.offsetTop);
}, `width: ${t.width}`);
}
}
</script>
</body>
...@@ -1491,7 +1491,11 @@ inline void BreakingContext::CommitAndUpdateLineBreakIfNeeded() { ...@@ -1491,7 +1491,11 @@ inline void BreakingContext::CommitAndUpdateLineBreakIfNeeded() {
bool check_for_break = auto_wrap_; bool check_for_break = auto_wrap_;
if (width_.CommittedWidth() && !width_.FitsOnLine() && if (width_.CommittedWidth() && !width_.FitsOnLine() &&
line_break_.GetLineLayoutItem() && curr_ws_ == EWhiteSpace::kNowrap) { line_break_.GetLineLayoutItem() && curr_ws_ == EWhiteSpace::kNowrap) {
if (width_.FitsOnLine(0, kExcludeWhitespace)) { // If this nowrap item fits but its trailing spaces does not, and if the
// next item is auto-wrap, break before the next item.
// TODO(kojii): This case should be handled when we read next item.
if (width_.FitsOnLine(0, kExcludeWhitespace) &&
(!next_object_ || next_object_.StyleRef().AutoWrap())) {
width_.Commit(); width_.Commit();
line_break_.MoveToStartOf(next_object_); line_break_.MoveToStartOf(next_object_);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment