mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 15:55:36 +00:00
Bug 1520684 part 1 - Add plumbing for handling physical/logical corner values. r=emilio
This commit is contained in:
parent
90dd635403
commit
5890654480
@ -171,6 +171,49 @@ impl WritingMode {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn physical_sides_to_corner(block_side: PhysicalSide, inline_side: PhysicalSide) -> PhysicalCorner {
|
||||
match (block_side, inline_side) {
|
||||
(PhysicalSide::Top, PhysicalSide::Left) |
|
||||
(PhysicalSide::Left, PhysicalSide::Top) => PhysicalCorner::TopLeft,
|
||||
(PhysicalSide::Top, PhysicalSide::Right) |
|
||||
(PhysicalSide::Right, PhysicalSide::Top) => PhysicalCorner::TopRight,
|
||||
(PhysicalSide::Bottom, PhysicalSide::Right) |
|
||||
(PhysicalSide::Right, PhysicalSide::Bottom) => PhysicalCorner::BottomRight,
|
||||
(PhysicalSide::Bottom, PhysicalSide::Left) |
|
||||
(PhysicalSide::Left, PhysicalSide::Bottom) => PhysicalCorner::BottomLeft,
|
||||
_ => unreachable!("block and inline sides must be orthogonal")
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn start_start_physical_corner(&self) -> PhysicalCorner {
|
||||
WritingMode::physical_sides_to_corner(
|
||||
self.block_start_physical_side(),
|
||||
self.inline_start_physical_side())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn start_end_physical_corner(&self) -> PhysicalCorner {
|
||||
WritingMode::physical_sides_to_corner(
|
||||
self.block_start_physical_side(),
|
||||
self.inline_end_physical_side())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn end_start_physical_corner(&self) -> PhysicalCorner {
|
||||
WritingMode::physical_sides_to_corner(
|
||||
self.block_end_physical_side(),
|
||||
self.inline_start_physical_side())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn end_end_physical_corner(&self) -> PhysicalCorner {
|
||||
WritingMode::physical_sides_to_corner(
|
||||
self.block_end_physical_side(),
|
||||
self.inline_end_physical_side())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn block_flow_direction(&self) -> BlockFlowDirection {
|
||||
match (self.is_vertical(), self.is_vertical_lr()) {
|
||||
@ -1314,3 +1357,11 @@ pub enum PhysicalSide {
|
||||
Bottom,
|
||||
Left,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum PhysicalCorner {
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomRight,
|
||||
BottomLeft,
|
||||
}
|
||||
|
@ -8,10 +8,13 @@ PHYSICAL_SIDES = ["top", "right", "bottom", "left"]
|
||||
LOGICAL_SIDES = ["block-start", "block-end", "inline-start", "inline-end"]
|
||||
PHYSICAL_SIZES = ["width", "height"]
|
||||
LOGICAL_SIZES = ["block-size", "inline-size"]
|
||||
PHYSICAL_CORNERS = ["top-left", "top-right", "bottom-right", "bottom-left"]
|
||||
LOGICAL_CORNERS = ["start-start", "start-end", "end-start", "end-end"]
|
||||
|
||||
# bool is True when logical
|
||||
ALL_SIDES = [(side, False) for side in PHYSICAL_SIDES] + [(side, True) for side in LOGICAL_SIDES]
|
||||
ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size in LOGICAL_SIZES]
|
||||
ALL_CORNERS = [(corner, False) for corner in PHYSICAL_CORNERS] + [(corner, True) for corner in LOGICAL_CORNERS]
|
||||
|
||||
SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
|
||||
font_variant_caps font_stretch font_kerning
|
||||
@ -239,12 +242,14 @@ class Longhand(object):
|
||||
def all_physical_mapped_properties(self):
|
||||
assert self.logical
|
||||
logical_side = None
|
||||
for s in LOGICAL_SIDES + LOGICAL_SIZES:
|
||||
for s in LOGICAL_SIDES + LOGICAL_SIZES + LOGICAL_CORNERS:
|
||||
if s in self.name:
|
||||
assert not logical_side
|
||||
logical_side = s
|
||||
assert logical_side
|
||||
physical = PHYSICAL_SIDES if logical_side in LOGICAL_SIDES else PHYSICAL_SIZES
|
||||
physical = PHYSICAL_SIDES if logical_side in LOGICAL_SIDES else \
|
||||
PHYSICAL_SIZES if logical_side in LOGICAL_SIZES else \
|
||||
LOGICAL_CORNERS
|
||||
return [self.name.replace(logical_side, physical_side).replace("inset-", "")
|
||||
for physical_side in physical]
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
<%!
|
||||
from data import Keyword, to_rust_ident, to_camel_case
|
||||
from data import LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES, SYSTEM_FONT_LONGHANDS
|
||||
from data import LOGICAL_CORNERS, PHYSICAL_CORNERS, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES, SYSTEM_FONT_LONGHANDS
|
||||
%>
|
||||
|
||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse',
|
||||
@ -842,12 +842,16 @@
|
||||
<%
|
||||
side = None
|
||||
size = None
|
||||
corner = None
|
||||
maybe_side = [s for s in LOGICAL_SIDES if s in name]
|
||||
maybe_size = [s for s in LOGICAL_SIZES if s in name]
|
||||
maybe_corner = [s for s in LOGICAL_CORNERS if s in name]
|
||||
if len(maybe_side) == 1:
|
||||
side = maybe_side[0]
|
||||
elif len(maybe_size) == 1:
|
||||
size = maybe_size[0]
|
||||
elif len(maybe_corner) == 1:
|
||||
corner = maybe_corner[0]
|
||||
def phys_ident(side, phy_side):
|
||||
return to_rust_ident(name.replace(side, phy_side).replace("inset-", ""))
|
||||
%>
|
||||
@ -860,6 +864,15 @@
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
% elif corner is not None:
|
||||
use crate::logical_geometry::PhysicalCorner;
|
||||
match wm.${to_rust_ident(corner)}_physical_corner() {
|
||||
% for phy_corner in PHYSICAL_CORNERS:
|
||||
PhysicalCorner::${to_camel_case(phy_corner)} => {
|
||||
${caller.inner(physical_ident=phys_ident(corner, phy_corner))}
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
% elif size is not None:
|
||||
<%
|
||||
# (horizontal, vertical)
|
||||
|
Loading…
Reference in New Issue
Block a user