Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove most of the things in layout 2020 #23896

Merged
merged 3 commits into from Aug 1, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Some generated files are not rendered by default. Learn more.

@@ -7,9 +7,28 @@ edition = "2018"
publish = false

[lib]
name = "layout"
path = "lib.rs"
test = false
doctest = false

[dependencies]
app_units = "0.7"
euclid = "0.20"
fnv = "1.0"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
ipc-channel = "0.11"
libc = "0.2"
malloc_size_of = { path = "../malloc_size_of" }
msg = {path = "../msg"}
range = {path = "../range"}
rayon = "1"
script_layout_interface = {path = "../script_layout_interface"}
script_traits = {path = "../script_traits"}
serde = "1.0"
servo_arc = {path = "../servo_arc"}
servo_url = {path = "../url"}
style = {path = "../style", features = ["servo", "servo-layout-2020"]}
style_traits = {path = "../style_traits"}
webrender_api = {git = "https://github.com/servo/webrender", features = ["ipc"]}
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 msg::constellation_msg::PipelineId;
use style::context::SharedStyleContext;

pub struct LayoutContext<'a> {
pub id: PipelineId,
pub style_context: SharedStyleContext<'a>,
}

impl<'a> LayoutContext<'a> {
#[inline(always)]
pub fn shared_context(&self) -> &SharedStyleContext {
&self.style_context
}
}
@@ -0,0 +1,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 script_layout_interface::StyleData;

#[repr(C)]
pub struct StyleAndLayoutData {
pub style_data: StyleData,
}

impl StyleAndLayoutData {
pub fn new() -> Self {
Self {
style_data: StyleData::new(),
}
}
}
@@ -0,0 +1,53 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

//! Builds display lists from flows and fragments.
//!
//! Other browser engines sometimes call this "painting", but it is more accurately called display
//! list building, as the actual painting does not happen here—only deciding *what* we're going to
//! paint.

use crate::display_list::items::OpaqueNode;
use app_units::Au;
use euclid::default::Point2D;
use fnv::FnvHashMap;
use gfx::text::glyph::ByteIndex;
use gfx::text::TextRun;
use range::Range;
use std::sync::Arc;

pub struct IndexableTextItem {
/// The placement of the text item on the plane.
pub origin: Point2D<Au>,
/// The text run.
pub text_run: Arc<TextRun>,
/// The range of text within the text run.
pub range: Range<ByteIndex>,
/// The position of the start of the baseline of this text.
pub baseline_origin: Point2D<Au>,
}

#[derive(Default)]
pub struct IndexableText {
inner: FnvHashMap<OpaqueNode, Vec<IndexableTextItem>>,
}

impl IndexableText {
pub fn get(&self, node: OpaqueNode) -> Option<&[IndexableTextItem]> {
self.inner.get(&node).map(|x| x.as_slice())
}

// Returns the text index within a node for the point of interest.
pub fn text_index(&self, node: OpaqueNode, point_in_item: Point2D<Au>) -> Option<usize> {
let item = self.inner.get(&node)?;
// TODO(#20020): access all elements
let point = point_in_item + item[0].origin.to_vector();
let offset = point - item[0].baseline_origin;
Some(
item[0]
.text_run
.range_index_of_advance(&item[0].range, offset.x),
)
}
}
@@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 euclid::Vector2D;
use gfx_traits;
use std::collections::HashMap;
use std::f32;
use webrender_api::units::LayoutPixel;
use webrender_api::ExternalScrollId;

pub use style::dom::OpaqueNode;

#[derive(Serialize)]
pub struct DisplayList {}

impl gfx_traits::DisplayList for DisplayList {
fn is_contentful(&self) -> bool {
false
}
}

/// The type of the scroll offset list. This is only populated if WebRender is in use.
pub type ScrollOffsetMap = HashMap<ExternalScrollId, Vector2D<f32, LayoutPixel>>;
@@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */

pub use self::builder::IndexableText;
pub use self::webrender_helpers::WebRenderDisplayListConverter;

mod builder;
pub mod items;
mod webrender_helpers;
@@ -0,0 +1,26 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 crate::display_list::items::DisplayList;
use msg::constellation_msg::PipelineId;
use webrender_api::units::LayoutSize;
use webrender_api::{self, DisplayListBuilder};

pub trait WebRenderDisplayListConverter {
fn convert_to_webrender(&mut self, pipeline_id: PipelineId) -> DisplayListBuilder;
}

impl WebRenderDisplayListConverter for DisplayList {
fn convert_to_webrender(&mut self, pipeline_id: PipelineId) -> DisplayListBuilder {
let webrender_pipeline = pipeline_id.to_webrender();

let builder = DisplayListBuilder::with_capacity(
webrender_pipeline,
LayoutSize::zero(),
1024 * 1024, // 1 MB of space
);

builder
}
}
@@ -0,0 +1,38 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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::fmt;
use style::selector_parser::RestyleDamage;

#[allow(unsafe_code)]
pub unsafe trait HasBaseFlow {}

pub trait GetBaseFlow {
fn base(&self) -> &BaseFlow;
fn mut_base(&mut self) -> &mut BaseFlow;
}

impl<T: HasBaseFlow + ?Sized> GetBaseFlow for T {
#[inline(always)]
#[allow(unsafe_code)]
fn base(&self) -> &BaseFlow {
let ptr: *const Self = self;
let ptr = ptr as *const BaseFlow;
unsafe { &*ptr }
}

#[inline(always)]
#[allow(unsafe_code)]
fn mut_base(&mut self) -> &mut BaseFlow {
let ptr: *mut Self = self;
let ptr = ptr as *mut BaseFlow;
unsafe { &mut *ptr }
}
}

pub trait Flow: HasBaseFlow + fmt::Debug + Sync + Send + 'static {}

pub struct BaseFlow {
pub restyle_damage: RestyleDamage,
}
@@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 crate::flow::Flow;
use std::ops::Deref;
use std::sync::Arc;

#[derive(Clone, Debug)]
pub struct FlowRef(Arc<dyn Flow>);

impl Deref for FlowRef {
type Target = dyn Flow;
fn deref(&self) -> &dyn Flow {
self.0.deref()
}
}

impl FlowRef {
pub fn new(mut r: Arc<dyn Flow>) -> Self {
assert!(Arc::get_mut(&mut r).is_some());
FlowRef(r)
}

#[allow(unsafe_code)]
pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow {
let ptr: *const dyn Flow = &*this.0;
unsafe { &mut *(ptr as *mut dyn Flow) }
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.