mirror of
https://github.com/servo/servo.git
synced 2025-08-02 04:00:32 +01:00
Add support for parsing and applying viewport
<meta>
(#35901)
This patch comprises following steps: 1. Parses the `viewport` Attribute from `<meta>`. 2. Creates a `ViewportDescription` struct. 3. Populate values into Viewport struct. 4. Pass & Stash Viewport Description to Webview. 5. Process parsed values of `viewport <meta>` Testing: Tested locally. Fixes: #36159 --------- Signed-off-by: Shubham Gupta <shubham13297@gmail.com> Signed-off-by: Xiaocheng Hu <xiaochengh.work@gmail.com> Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
This commit is contained in:
parent
c7a215faba
commit
aff2a85372
6 changed files with 248 additions and 19 deletions
|
@ -2,6 +2,10 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use compositing_traits::CompositorMsg;
|
||||
use compositing_traits::viewport_description::ViewportDescription;
|
||||
use dom_struct::dom_struct;
|
||||
use html5ever::{LocalName, Prefix, local_name, ns};
|
||||
use js::rust::HandleObject;
|
||||
|
@ -61,6 +65,9 @@ impl HTMLMetaElement {
|
|||
if name == "referrer" {
|
||||
self.apply_referrer();
|
||||
}
|
||||
if name == "viewport" {
|
||||
self.parse_and_send_viewport_if_necessary();
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv
|
||||
} else if !self.HttpEquiv().is_empty() {
|
||||
// TODO: Implement additional http-equiv candidates
|
||||
|
@ -115,6 +122,29 @@ impl HTMLMetaElement {
|
|||
}
|
||||
}
|
||||
|
||||
/// <https://drafts.csswg.org/css-viewport/#parsing-algorithm>
|
||||
fn parse_and_send_viewport_if_necessary(&self) {
|
||||
// Skip processing if this isn't the top level frame
|
||||
if !self.owner_window().is_top_level() {
|
||||
return;
|
||||
}
|
||||
let element = self.upcast::<Element>();
|
||||
let Some(content) = element.get_attribute(&ns!(), &local_name!("content")) else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Ok(viewport) = ViewportDescription::from_str(&content.value()) {
|
||||
self.owner_window()
|
||||
.compositor_api()
|
||||
.sender()
|
||||
.send(CompositorMsg::Viewport(
|
||||
self.owner_window().webview_id(),
|
||||
viewport,
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// <https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv-content-security-policy>
|
||||
fn apply_csp_list(&self) {
|
||||
if let Some(parent) = self.upcast::<Node>().GetParentElement() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue