mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
Ladybird/AppKit: Listen for device pixel ratio changes
This commit is contained in:
parent
7718842829
commit
0574c0e474
6 changed files with 28 additions and 5 deletions
|
@ -60,4 +60,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
||||||
|
{
|
||||||
|
[[[self console] web_view] handleDevicePixelRatioChange];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
- (String const&)handle;
|
- (String const&)handle;
|
||||||
|
|
||||||
- (void)handleResize;
|
- (void)handleResize;
|
||||||
|
- (void)handleDevicePixelRatioChange;
|
||||||
- (void)handleScroll;
|
- (void)handleScroll;
|
||||||
- (void)handleVisibility:(BOOL)is_visible;
|
- (void)handleVisibility:(BOOL)is_visible;
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,7 @@ struct HideCursor {
|
||||||
screen_rects.unchecked_append(screen_rect);
|
screen_rects.unchecked_append(screen_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This returns device pixel ratio of the screen the window is opened in
|
||||||
auto device_pixel_ratio = [[NSScreen mainScreen] backingScaleFactor];
|
auto device_pixel_ratio = [[NSScreen mainScreen] backingScaleFactor];
|
||||||
|
|
||||||
m_web_view_bridge = MUST(Ladybird::WebViewBridge::create(move(screen_rects), device_pixel_ratio, [delegate webdriverContentIPCPath], [delegate preferredColorScheme]));
|
m_web_view_bridge = MUST(Ladybird::WebViewBridge::create(move(screen_rects), device_pixel_ratio, [delegate webdriverContentIPCPath], [delegate preferredColorScheme]));
|
||||||
|
@ -130,6 +131,13 @@ struct HideCursor {
|
||||||
[self updateStatusLabelPosition];
|
[self updateStatusLabelPosition];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)handleDevicePixelRatioChange
|
||||||
|
{
|
||||||
|
m_web_view_bridge->set_device_pixel_ratio([[self window] backingScaleFactor]);
|
||||||
|
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::Yes];
|
||||||
|
[self updateStatusLabelPosition];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)handleScroll
|
- (void)handleScroll
|
||||||
{
|
{
|
||||||
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::No];
|
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::No];
|
||||||
|
|
|
@ -34,7 +34,6 @@ WebViewBridge::WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pix
|
||||||
, m_preferred_color_scheme(preferred_color_scheme)
|
, m_preferred_color_scheme(preferred_color_scheme)
|
||||||
{
|
{
|
||||||
m_device_pixel_ratio = device_pixel_ratio;
|
m_device_pixel_ratio = device_pixel_ratio;
|
||||||
m_inverse_device_pixel_ratio = 1.0 / device_pixel_ratio;
|
|
||||||
|
|
||||||
create_client(WebView::EnableCallgrindProfiling::No);
|
create_client(WebView::EnableCallgrindProfiling::No);
|
||||||
|
|
||||||
|
@ -70,6 +69,12 @@ WebViewBridge::WebViewBridge(Vector<Gfx::IntRect> screen_rects, float device_pix
|
||||||
|
|
||||||
WebViewBridge::~WebViewBridge() = default;
|
WebViewBridge::~WebViewBridge() = default;
|
||||||
|
|
||||||
|
void WebViewBridge::set_device_pixel_ratio(float device_pixel_ratio)
|
||||||
|
{
|
||||||
|
m_device_pixel_ratio = device_pixel_ratio;
|
||||||
|
client().async_set_device_pixels_per_css_pixel(device_pixel_ratio);
|
||||||
|
}
|
||||||
|
|
||||||
void WebViewBridge::set_system_visibility_state(bool is_visible)
|
void WebViewBridge::set_system_visibility_state(bool is_visible)
|
||||||
{
|
{
|
||||||
client().async_set_system_visibility_state(is_visible);
|
client().async_set_system_visibility_state(is_visible);
|
||||||
|
@ -169,7 +174,7 @@ Gfx::IntPoint WebViewBridge::to_content_position(Gfx::IntPoint widget_position)
|
||||||
|
|
||||||
Gfx::IntPoint WebViewBridge::to_widget_position(Gfx::IntPoint content_position) const
|
Gfx::IntPoint WebViewBridge::to_widget_position(Gfx::IntPoint content_position) const
|
||||||
{
|
{
|
||||||
return scale_for_device(content_position, m_inverse_device_pixel_ratio);
|
return scale_for_device(content_position, inverse_device_pixel_ratio());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebViewBridge::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling)
|
void WebViewBridge::create_client(WebView::EnableCallgrindProfiling enable_callgrind_profiling)
|
||||||
|
|
|
@ -26,7 +26,8 @@ public:
|
||||||
virtual ~WebViewBridge() override;
|
virtual ~WebViewBridge() override;
|
||||||
|
|
||||||
float device_pixel_ratio() const { return m_device_pixel_ratio; }
|
float device_pixel_ratio() const { return m_device_pixel_ratio; }
|
||||||
float inverse_device_pixel_ratio() const { return m_inverse_device_pixel_ratio; }
|
void set_device_pixel_ratio(float device_pixel_ratio);
|
||||||
|
float inverse_device_pixel_ratio() const { return 1.0f / m_device_pixel_ratio; }
|
||||||
|
|
||||||
void set_system_visibility_state(bool is_visible);
|
void set_system_visibility_state(bool is_visible);
|
||||||
|
|
||||||
|
@ -67,8 +68,6 @@ private:
|
||||||
Vector<Gfx::IntRect> m_screen_rects;
|
Vector<Gfx::IntRect> m_screen_rects;
|
||||||
Gfx::IntRect m_viewport_rect;
|
Gfx::IntRect m_viewport_rect;
|
||||||
|
|
||||||
float m_inverse_device_pixel_ratio { 1.0 };
|
|
||||||
|
|
||||||
Optional<StringView> m_webdriver_content_ipc_path;
|
Optional<StringView> m_webdriver_content_ipc_path;
|
||||||
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
|
Web::CSS::PreferredColorScheme m_preferred_color_scheme { Web::CSS::PreferredColorScheme::Auto };
|
||||||
};
|
};
|
||||||
|
|
|
@ -472,6 +472,11 @@ enum class IsHistoryNavigation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
||||||
|
{
|
||||||
|
[[[self tab] web_view] handleDevicePixelRatioChange];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)validateMenuItem:(NSMenuItem*)item
|
- (BOOL)validateMenuItem:(NSMenuItem*)item
|
||||||
{
|
{
|
||||||
if ([item action] == @selector(toggleLineBoxBorders:)) {
|
if ([item action] == @selector(toggleLineBoxBorders:)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue