Commit f460ee2b authored by Mathias Bynens's avatar Mathias Bynens Committed by Chromium LUCI CQ

Simplify view-source line-wrapping implementation

Previously, we created a wrapper <div>, added an `id` attribute to
the <input type=checkbox>, and added the corresponding `for`
attribute to the <label>. This patch simplifies the implementation
as follows:

- We get rid of both the `id` and `for` attributes by wrapping the
  checkbox and the text label inside of the <label>.
- We then also get rid of the wrapper <div>.

This simplifies the code and reduces the resulting DOM size.

This patch also improves the UI: now, the entire horizontal bar can
be clicked to toggle the checkbox, as opposed to just the checkbox
itself + the text label (whose length is variable, based on the
user’s locale + font sizing/zoom preferences).

Tests:

    autoninja -C out/Release blink_unittests
    out/Release/blink_unittests --gtest_filter=HTMLViewSourceDocumentTest.*

Bug: chromium:920571
Change-Id: I42873f62d94b264a1b7edf3567e539301be07ed1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598907
Commit-Queue: Mason Freed <masonfreed@chromium.org>
Reviewed-by: default avatarMason Freed <masonfreed@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840782}
parent c882f512
...@@ -108,25 +108,21 @@ void HTMLViewSourceDocument::CreateContainingTable() { ...@@ -108,25 +108,21 @@ void HTMLViewSourceDocument::CreateContainingTable() {
line_number_ = 0; line_number_ = 0;
// Create a checkbox to control line wrapping. // Create a checkbox to control line wrapping.
auto* line_wrap_div = MakeGarbageCollected<HTMLDivElement>(*this); auto* label = MakeGarbageCollected<HTMLLabelElement>(*this);
line_wrap_div->setAttribute(html_names::kClassAttr, "line-wrap-control"); label->setAttribute(html_names::kClassAttr, "line-wrap-control");
auto* checkbox = auto* checkbox =
MakeGarbageCollected<HTMLInputElement>(*this, CreateElementFlags()); MakeGarbageCollected<HTMLInputElement>(*this, CreateElementFlags());
checkbox->setAttribute(html_names::kTypeAttr, "checkbox"); checkbox->setAttribute(html_names::kTypeAttr, "checkbox");
checkbox->setAttribute(html_names::kIdAttr, "line-wrap-checkbox"); label->ParserAppendChild(checkbox);
line_wrap_div->ParserAppendChild(checkbox);
auto* label = MakeGarbageCollected<HTMLLabelElement>(*this);
label->setAttribute(html_names::kForAttr, "line-wrap-checkbox");
label->ParserAppendChild( label->ParserAppendChild(
Text::Create(*this, WTF::AtomicString(Locale::DefaultLocale().QueryString( Text::Create(*this, WTF::AtomicString(Locale::DefaultLocale().QueryString(
IDS_VIEW_SOURCE_LINE_WRAP)))); IDS_VIEW_SOURCE_LINE_WRAP))));
line_wrap_div->ParserAppendChild(label);
auto* tr = MakeGarbageCollected<HTMLTableRowElement>(*this); auto* tr = MakeGarbageCollected<HTMLTableRowElement>(*this);
auto* td = auto* td =
MakeGarbageCollected<HTMLTableCellElement>(html_names::kTdTag, *this); MakeGarbageCollected<HTMLTableCellElement>(html_names::kTdTag, *this);
td->setAttribute(html_names::kColspanAttr, "2"); td->setAttribute(html_names::kColspanAttr, "2");
td->setAttribute(html_names::kClassAttr, "line-wrap-cell"); td->setAttribute(html_names::kClassAttr, "line-wrap-cell");
td->ParserAppendChild(line_wrap_div); td->ParserAppendChild(label);
tr->ParserAppendChild(td); tr->ParserAppendChild(td);
tbody_->ParserAppendChild(tr); tbody_->ParserAppendChild(tr);
......
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