mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:07:36 +00:00
LibWeb: Support window.devicePixelRatio
This always returns 1 for now. I've added a FIXME about returning 2 in HiDPI mode.
This commit is contained in:
parent
e26e85a3d2
commit
7410736b0f
4 changed files with 19 additions and 0 deletions
|
@ -67,6 +67,7 @@ void WindowObject::initialize_global_object()
|
||||||
define_native_accessor("screen", screen_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor("screen", screen_getter, {}, JS::Attribute::Enumerable);
|
||||||
define_native_accessor("innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor("innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
|
||||||
define_native_accessor("innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
|
define_native_accessor("innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
|
||||||
|
define_native_accessor("devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
|
||||||
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
u8 attr = JS::Attribute::Writable | JS::Attribute::Enumerable | JS::Attribute::Configurable;
|
||||||
define_native_function("alert", alert, 0, attr);
|
define_native_function("alert", alert, 0, attr);
|
||||||
define_native_function("confirm", confirm, 0, attr);
|
define_native_function("confirm", confirm, 0, attr);
|
||||||
|
@ -506,6 +507,14 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::inner_height_getter)
|
||||||
return JS::Value(impl->inner_height());
|
return JS::Value(impl->inner_height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::device_pixel_ratio_getter)
|
||||||
|
{
|
||||||
|
auto* impl = impl_from(vm, global_object);
|
||||||
|
if (!impl)
|
||||||
|
return {};
|
||||||
|
return JS::Value(impl->device_pixel_ratio());
|
||||||
|
}
|
||||||
|
|
||||||
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
JS_DEFINE_NATIVE_FUNCTION(WindowObject::get_computed_style)
|
||||||
{
|
{
|
||||||
auto* impl = impl_from(vm, global_object);
|
auto* impl = impl_from(vm, global_object);
|
||||||
|
|
|
@ -81,6 +81,8 @@ private:
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
JS_DECLARE_NATIVE_FUNCTION(parent_getter);
|
||||||
|
|
||||||
|
JS_DECLARE_NATIVE_FUNCTION(device_pixel_ratio_getter);
|
||||||
|
|
||||||
JS_DECLARE_NATIVE_GETTER(scroll_x_getter);
|
JS_DECLARE_NATIVE_GETTER(scroll_x_getter);
|
||||||
JS_DECLARE_NATIVE_GETTER(scroll_y_getter);
|
JS_DECLARE_NATIVE_GETTER(scroll_y_getter);
|
||||||
JS_DECLARE_NATIVE_FUNCTION(scroll);
|
JS_DECLARE_NATIVE_FUNCTION(scroll);
|
||||||
|
|
|
@ -309,4 +309,10 @@ void Window::queue_microtask(JS::FunctionObject& callback)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float Window::device_pixel_ratio() const
|
||||||
|
{
|
||||||
|
// FIXME: Return 2.0f if we're in HiDPI mode!
|
||||||
|
return 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,8 @@ public:
|
||||||
|
|
||||||
void fire_a_page_transition_event(FlyString event_name, bool persisted);
|
void fire_a_page_transition_event(FlyString event_name, bool persisted);
|
||||||
|
|
||||||
|
float device_pixel_ratio() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Window(Document&);
|
explicit Window(Document&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue