Bug 1392996 - Part 1 - Add meta viewport tag to view-source document. r=hsivonen

Adding <meta name="viewport" content="width=device-width"/> to the view-source
document achieves two things when used in a mobile browser, such as Fennec:
1. When word-wrapping is turned off, the page displays at a more readable
   initial zoom level.
2. As of now, font inflation (when enabled) kicks in on the document when word-
   wrapping is turned on, which leads to the line numbers appearing in a
   noticeably smaller font size than the rest of the page.
   Adding the above meta viewport header marks the document as "mobile-friendly"
   and suppresses font inflation, which means that line numbers will appear
   normally even with word-wrapping enabled.

getMathMLSelection() in browser-content.js isn't actually used in Fennec at the
moment, but for consistency we add the meta viewport tag there as well.

MozReview-Commit-ID: K9KVHh7g7TF
This commit is contained in:
Jan Henning
2018-01-23 22:25:09 +01:00
parent b083dcbf32
commit 4f977fe88f
5 changed files with 25 additions and 1 deletions

View File

@@ -54,3 +54,15 @@ nsHtml5ViewSourceUtils::NewLinkAttributes()
linkAttrs->addAttribute(nsHtml5AttributeName::ATTR_HREF, href, -1);
return linkAttrs;
}
// static
nsHtml5HtmlAttributes*
nsHtml5ViewSourceUtils::NewMetaViewportAttributes()
{
nsHtml5HtmlAttributes* metaVpAttrs = new nsHtml5HtmlAttributes(0);
nsHtml5String name = nsHtml5Portability::newStringFromLiteral("viewport");
metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_NAME, name, -1);
nsHtml5String content = nsHtml5Portability::newStringFromLiteral("width=device-width");
metaVpAttrs->addAttribute(nsHtml5AttributeName::ATTR_CONTENT, content, -1);
return metaVpAttrs;
}