mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09:00
UI/AppKit: Inform WebContent of the UI window position/size
This is required for APIs like window.screenX, as well as for WebDriver and WPT.
This commit is contained in:
parent
777eec095b
commit
102a125ea5
Notes:
github-actions[bot]
2024-10-29 11:05:17 +00:00
Author: https://github.com/trflynn89
Commit: 102a125ea5
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2028
Reviewed-by: https://github.com/tcl3 ✅
9 changed files with 52 additions and 12 deletions
|
@ -65,6 +65,9 @@
|
||||||
- (WebView::ViewImplementation&)view;
|
- (WebView::ViewImplementation&)view;
|
||||||
- (String const&)handle;
|
- (String const&)handle;
|
||||||
|
|
||||||
|
- (void)setWindowPosition:(Gfx::IntPoint)position;
|
||||||
|
- (void)setWindowSize:(Gfx::IntSize)size;
|
||||||
|
|
||||||
- (void)handleResize;
|
- (void)handleResize;
|
||||||
- (void)handleDevicePixelRatioChange;
|
- (void)handleDevicePixelRatioChange;
|
||||||
- (void)handleScroll;
|
- (void)handleScroll;
|
||||||
|
|
|
@ -184,6 +184,16 @@ struct HideCursor {
|
||||||
return m_web_view_bridge->handle();
|
return m_web_view_bridge->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setWindowPosition:(Gfx::IntPoint)position
|
||||||
|
{
|
||||||
|
m_web_view_bridge->set_window_position(Ladybird::compute_origin_relative_to_window([self window], position));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setWindowSize:(Gfx::IntSize)size
|
||||||
|
{
|
||||||
|
m_web_view_bridge->set_window_size(size);
|
||||||
|
}
|
||||||
|
|
||||||
- (void)handleResize
|
- (void)handleResize
|
||||||
{
|
{
|
||||||
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::Yes];
|
[self updateViewportRect:Ladybird::WebViewBridge::ForResize::Yes];
|
||||||
|
@ -1546,6 +1556,10 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
||||||
{
|
{
|
||||||
[super viewDidMoveToWindow];
|
[super viewDidMoveToWindow];
|
||||||
[self handleResize];
|
[self handleResize];
|
||||||
|
|
||||||
|
auto window = Ladybird::ns_rect_to_gfx_rect([[self window] frame]);
|
||||||
|
[self setWindowPosition:window.location()];
|
||||||
|
[self setWindowSize:window.size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidEndLiveResize
|
- (void)viewDidEndLiveResize
|
||||||
|
|
|
@ -607,6 +607,12 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
|
||||||
[delegate removeTab:self];
|
[delegate removeTab:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)windowDidMove:(NSNotification*)notification
|
||||||
|
{
|
||||||
|
auto position = Ladybird::ns_point_to_gfx_point([[self tab] frame].origin);
|
||||||
|
[[[self tab] web_view] setWindowPosition:position];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)windowDidResize:(NSNotification*)notification
|
- (void)windowDidResize:(NSNotification*)notification
|
||||||
{
|
{
|
||||||
if (self.location_toolbar_item_width != nil) {
|
if (self.location_toolbar_item_width != nil) {
|
||||||
|
@ -620,6 +626,9 @@ static NSString* const TOOLBAR_TAB_OVERVIEW_IDENTIFIER = @"ToolbarTabOverviewIde
|
||||||
if (![[self window] inLiveResize]) {
|
if (![[self window] inLiveResize]) {
|
||||||
[[[self tab] web_view] handleResize];
|
[[[self tab] web_view] handleResize];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto size = Ladybird::ns_size_to_gfx_size([[self tab] frame].size);
|
||||||
|
[[[self tab] web_view] setWindowSize:size];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
||||||
|
|
|
@ -38,4 +38,6 @@ NSPoint gfx_point_to_ns_point(Gfx::IntPoint);
|
||||||
Gfx::Color ns_color_to_gfx_color(NSColor*);
|
Gfx::Color ns_color_to_gfx_color(NSColor*);
|
||||||
NSColor* gfx_color_to_ns_color(Gfx::Color);
|
NSColor* gfx_color_to_ns_color(Gfx::Color);
|
||||||
|
|
||||||
|
Gfx::IntPoint compute_origin_relative_to_window(NSWindow*, Gfx::IntPoint);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,4 +117,15 @@ NSColor* gfx_color_to_ns_color(Gfx::Color color)
|
||||||
alpha:(color.alpha() / 255.f)];
|
alpha:(color.alpha() / 255.f)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Gfx::IntPoint compute_origin_relative_to_window(NSWindow* window, Gfx::IntPoint position)
|
||||||
|
{
|
||||||
|
// The origin of the NSWindow is its bottom-left corner, relative to the bottom-left of the screen. We must convert
|
||||||
|
// window positions sent to/from WebContent between this origin and the window's and screen's top-left corners.
|
||||||
|
auto screen_frame = Ladybird::ns_rect_to_gfx_rect([[window screen] frame]);
|
||||||
|
auto window_frame = Ladybird::ns_rect_to_gfx_rect([window frame]);
|
||||||
|
|
||||||
|
position.set_y(screen_frame.height() - window_frame.height() - position.y());
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -536,16 +536,6 @@ void WebContentView::set_viewport_rect(Gfx::IntRect rect)
|
||||||
client().async_set_viewport_size(m_client_state.page_index, rect.size().to_type<Web::DevicePixels>());
|
client().async_set_viewport_size(m_client_state.page_index, rect.size().to_type<Web::DevicePixels>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentView::set_window_size(Gfx::IntSize size)
|
|
||||||
{
|
|
||||||
client().async_set_window_size(m_client_state.page_index, size.to_type<Web::DevicePixels>());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebContentView::set_window_position(Gfx::IntPoint position)
|
|
||||||
{
|
|
||||||
client().async_set_window_position(m_client_state.page_index, position.to_type<Web::DevicePixels>());
|
|
||||||
}
|
|
||||||
|
|
||||||
void WebContentView::set_device_pixel_ratio(double device_pixel_ratio)
|
void WebContentView::set_device_pixel_ratio(double device_pixel_ratio)
|
||||||
{
|
{
|
||||||
m_device_pixel_ratio = device_pixel_ratio;
|
m_device_pixel_ratio = device_pixel_ratio;
|
||||||
|
|
|
@ -73,8 +73,6 @@ public:
|
||||||
virtual bool event(QEvent*) override;
|
virtual bool event(QEvent*) override;
|
||||||
|
|
||||||
void set_viewport_rect(Gfx::IntRect);
|
void set_viewport_rect(Gfx::IntRect);
|
||||||
void set_window_size(Gfx::IntSize);
|
|
||||||
void set_window_position(Gfx::IntPoint);
|
|
||||||
void set_device_pixel_ratio(double);
|
void set_device_pixel_ratio(double);
|
||||||
|
|
||||||
enum class PaletteMode {
|
enum class PaletteMode {
|
||||||
|
|
|
@ -77,6 +77,16 @@ void ViewImplementation::server_did_paint(Badge<WebContentClient>, i32 bitmap_id
|
||||||
client().async_ready_to_paint(page_id());
|
client().async_ready_to_paint(page_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewImplementation::set_window_position(Gfx::IntPoint position)
|
||||||
|
{
|
||||||
|
client().async_set_window_position(m_client_state.page_index, position.to_type<Web::DevicePixels>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewImplementation::set_window_size(Gfx::IntSize size)
|
||||||
|
{
|
||||||
|
client().async_set_window_size(m_client_state.page_index, size.to_type<Web::DevicePixels>());
|
||||||
|
}
|
||||||
|
|
||||||
void ViewImplementation::load(URL::URL const& url)
|
void ViewImplementation::load(URL::URL const& url)
|
||||||
{
|
{
|
||||||
m_url = url;
|
m_url = url;
|
||||||
|
|
|
@ -50,6 +50,9 @@ public:
|
||||||
|
|
||||||
void server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size);
|
void server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize size);
|
||||||
|
|
||||||
|
void set_window_position(Gfx::IntPoint);
|
||||||
|
void set_window_size(Gfx::IntSize);
|
||||||
|
|
||||||
void load(URL::URL const&);
|
void load(URL::URL const&);
|
||||||
void load_html(StringView);
|
void load_html(StringView);
|
||||||
void load_empty_document();
|
void load_empty_document();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue