forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch makes line-break-ascii.html faster by using the shared JavaScript code with word-break-all-ascii.html, which was made faster in r511361. Bug: 658211, 879822 Change-Id: I172aac89c4edd96ea61d2fedaff22ed9fbd0c9d9 Reviewed-on: https://chromium-review.googlesource.com/1220949 Commit-Queue: Emil A Eklund <eae@chromium.org> Reviewed-by: Emil A Eklund <eae@chromium.org> Cr-Commit-Position: refs/heads/master@{#590742}
- Loading branch information
Showing
5 changed files
with
63 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 11 additions & 43 deletions
54
third_party/WebKit/LayoutTests/fast/text/line-break-ascii.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,22 @@ | ||
<!DOCTYPE html> | ||
<style> | ||
#break-test { | ||
font:50px/1 Ahem; | ||
width:3em; | ||
#container { | ||
font:50px/1 Ahem; | ||
width:3em; | ||
} | ||
#result { | ||
font:15px/1 monospace; | ||
white-space:pre; | ||
font:15px/1 monospace; | ||
white-space:pre; | ||
} | ||
</style> | ||
<div id="result"></div> | ||
<div id="break-test"></div> | ||
<div id="container"></div> | ||
<script src="resources/line-break-test.js"></script> | ||
<script> | ||
var beginChar = 33; | ||
var endChar = 127; | ||
var breakTest = document.getElementById("break-test"); | ||
var breakTestFontsize = parseFloat(getComputedStyle(breakTest).fontSize); | ||
var nbsp = String.fromCharCode(0xA0); | ||
nbsp = nbsp + nbsp; | ||
let matrix = new LineBreakTest(33, 127); | ||
result.textContent = matrix.toResultString(); | ||
container.remove(); | ||
|
||
var matrix = getLineBreakMatrix(); | ||
|
||
var header = []; | ||
for (var i = 0; i < matrix.length; i++) | ||
header.push(String.fromCharCode(beginChar + i)); | ||
var rows = [" " + header.join("")]; | ||
for (var i = 0; i < matrix.length; i++) { | ||
rows.push(String.fromCharCode(beginChar + i) + " " + matrix[i].map(function (canBreak) { | ||
return canBreak ? "/" : "X"; | ||
}).join("")); | ||
} | ||
result.textContent = rows.join("\n"); | ||
|
||
function getLineBreakMatrix() { | ||
var matrix = []; | ||
for (var last = beginChar; last < endChar; last++) { | ||
var canBreakBefore = []; | ||
for (var current = beginChar; current < endChar; current++) | ||
canBreakBefore.push(canBreakBetween(last, current)); | ||
matrix.push(canBreakBefore); | ||
} | ||
return matrix; | ||
} | ||
|
||
function canBreakBetween(last, current) { | ||
breakTest.textContent = nbsp + String.fromCharCode(last) + String.fromCharCode(current); | ||
return breakTest.offsetHeight / breakTestFontsize > 1.9; | ||
} | ||
|
||
breakTest.textContent = ""; | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
testRunner.dumpAsText(); | ||
</script> |
45 changes: 45 additions & 0 deletions
45
third_party/WebKit/LayoutTests/fast/text/resources/line-break-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
let container = document.getElementById("container"); | ||
let breakTestFontsize = parseFloat(getComputedStyle(container).fontSize); | ||
let nbsp = String.fromCharCode(0xA0); | ||
nbsp = nbsp + nbsp; | ||
|
||
class LineBreakTestElement { | ||
constructor(last, current) { | ||
let element = document.createElement('div'); | ||
element.textContent = nbsp + String.fromCharCode(last) + String.fromCharCode(current); | ||
container.appendChild(element); | ||
this.element = element; | ||
} | ||
|
||
get canBreak() { | ||
return this.element.offsetHeight / breakTestFontsize > 1.9; | ||
} | ||
} | ||
|
||
class LineBreakTest { | ||
constructor(begin, end) { | ||
let rows = []; | ||
for (let last = begin; last < end; last++) { | ||
let row = []; | ||
for (let current = begin; current < end; current++) | ||
row.push(new LineBreakTestElement(last, current)); | ||
rows.push(row); | ||
} | ||
this.begin = begin; | ||
this.rows = rows; | ||
} | ||
|
||
toResultString() { | ||
let header = []; | ||
for (let i = 0; i < this.rows.length; i++) | ||
header.push(String.fromCharCode(this.begin + i)); | ||
let rows = [" " + header.join("")]; | ||
for (let i = 0; i < this.rows.length; i++) { | ||
let row = String.fromCharCode(this.begin + i) + " " + | ||
this.rows[i].map((test) => test.canBreak ? "/" : "X") | ||
.join(""); | ||
rows.push(row); | ||
} | ||
return rows.join("\n"); | ||
} | ||
} |