mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +00:00
LibWeb: Refactor int types in WebContentServer to DevicePixels
This commit is contained in:
parent
8730e56f62
commit
c069ab1ca0
18 changed files with 169 additions and 69 deletions
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
|
||||
namespace Web {
|
||||
|
@ -25,3 +27,69 @@ int CSSPixels::to_int() const
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixels const& value)
|
||||
{
|
||||
TRY(encoder.encode(value.value()));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixels> decode(Decoder& decoder)
|
||||
{
|
||||
auto value = TRY(decoder.decode<int>());
|
||||
return Web::DevicePixels(value);
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelPoint const& value)
|
||||
{
|
||||
TRY(encoder.encode(value.x()));
|
||||
TRY(encoder.encode(value.y()));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelPoint> decode(Decoder& decoder)
|
||||
{
|
||||
auto x = TRY(decoder.decode<Web::DevicePixels>());
|
||||
auto y = TRY(decoder.decode<Web::DevicePixels>());
|
||||
return Web::DevicePixelPoint { x, y };
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelSize const& value)
|
||||
{
|
||||
TRY(encoder.encode(value.width()));
|
||||
TRY(encoder.encode(value.height()));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelSize> decode(Decoder& decoder)
|
||||
{
|
||||
auto width = TRY(decoder.decode<Web::DevicePixels>());
|
||||
auto height = TRY(decoder.decode<Web::DevicePixels>());
|
||||
return Web::DevicePixelSize { width, height };
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelRect const& value)
|
||||
{
|
||||
TRY(encoder.encode(value.location()));
|
||||
TRY(encoder.encode(value.size()));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelRect> decode(Decoder& decoder)
|
||||
{
|
||||
auto location = TRY(decoder.decode<Web::DevicePixelPoint>());
|
||||
auto size = TRY(decoder.decode<Web::DevicePixelSize>());
|
||||
return Web::DevicePixelRect { location, size };
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <AK/Traits.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Web {
|
||||
|
@ -504,3 +505,27 @@ struct Formatter<Web::DevicePixels> : Formatter<Web::DevicePixels::Type> {
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixels const& value);
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixels> decode(Decoder& decoder);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelPoint const& value);
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelPoint> decode(Decoder& decoder);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelSize const& value);
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelSize> decode(Decoder& decoder);
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::DevicePixelRect const& value);
|
||||
template<>
|
||||
ErrorOr<Web::DevicePixelRect> decode(Decoder& decoder);
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,12 @@ void OutOfProcessWebView::create_client()
|
|||
|
||||
client().async_update_system_theme(Gfx::current_system_theme_buffer());
|
||||
client().async_update_system_fonts(Gfx::FontDatabase::default_font_query(), Gfx::FontDatabase::fixed_width_font_query(), Gfx::FontDatabase::window_title_font_query());
|
||||
client().async_update_screen_rects(GUI::Desktop::the().rects(), GUI::Desktop::the().main_screen_index());
|
||||
|
||||
Vector<Web::DevicePixelRect> screen_rects;
|
||||
for (auto const& screen_rect : GUI::Desktop::the().rects()) {
|
||||
screen_rects.append(screen_rect.to_type<Web::DevicePixels>());
|
||||
}
|
||||
client().async_update_screen_rects(screen_rects, GUI::Desktop::the().main_screen_index());
|
||||
}
|
||||
|
||||
void OutOfProcessWebView::paint_event(GUI::PaintEvent& event)
|
||||
|
@ -132,13 +137,13 @@ void OutOfProcessWebView::paint_event(GUI::PaintEvent& event)
|
|||
void OutOfProcessWebView::resize_event(GUI::ResizeEvent& event)
|
||||
{
|
||||
Super::resize_event(event);
|
||||
client().async_set_viewport_rect(Gfx::IntRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, available_size()));
|
||||
client().async_set_viewport_rect(Web::DevicePixelRect({ horizontal_scrollbar().value(), vertical_scrollbar().value() }, available_size()));
|
||||
handle_resize();
|
||||
}
|
||||
|
||||
Gfx::IntRect OutOfProcessWebView::viewport_rect() const
|
||||
Web::DevicePixelRect OutOfProcessWebView::viewport_rect() const
|
||||
{
|
||||
return visible_content_rect();
|
||||
return visible_content_rect().to_type<Web::DevicePixels>();
|
||||
}
|
||||
|
||||
Gfx::IntPoint OutOfProcessWebView::to_content_position(Gfx::IntPoint widget_position) const
|
||||
|
@ -210,12 +215,16 @@ void OutOfProcessWebView::theme_change_event(GUI::ThemeChangeEvent& event)
|
|||
|
||||
void OutOfProcessWebView::screen_rects_change_event(GUI::ScreenRectsChangeEvent& event)
|
||||
{
|
||||
client().async_update_screen_rects(event.rects(), event.main_screen_index());
|
||||
Vector<Web::DevicePixelRect> screen_rects;
|
||||
for (auto const& screen_rect : event.rects()) {
|
||||
screen_rects.append(screen_rect.to_type<Web::DevicePixels>());
|
||||
}
|
||||
client().async_update_screen_rects(screen_rects, event.main_screen_index());
|
||||
}
|
||||
|
||||
void OutOfProcessWebView::did_scroll()
|
||||
{
|
||||
client().async_set_viewport_rect(visible_content_rect());
|
||||
client().async_set_viewport_rect(visible_content_rect().to_type<Web::DevicePixels>());
|
||||
request_repaint();
|
||||
}
|
||||
|
||||
|
@ -261,12 +270,12 @@ void OutOfProcessWebView::connect_to_webdriver(DeprecatedString const& webdriver
|
|||
|
||||
void OutOfProcessWebView::set_window_position(Gfx::IntPoint position)
|
||||
{
|
||||
client().async_set_window_position(position);
|
||||
client().async_set_window_position(position.to_type<Web::DevicePixels>());
|
||||
}
|
||||
|
||||
void OutOfProcessWebView::set_window_size(Gfx::IntSize size)
|
||||
{
|
||||
client().async_set_window_size(size);
|
||||
client().async_set_window_size(size.to_type<Web::DevicePixels>());
|
||||
}
|
||||
|
||||
void OutOfProcessWebView::focusin_event(GUI::FocusEvent&)
|
||||
|
|
|
@ -81,7 +81,7 @@ private:
|
|||
virtual void create_client() override;
|
||||
virtual void update_zoom() override;
|
||||
|
||||
virtual Gfx::IntRect viewport_rect() const override;
|
||||
virtual Web::DevicePixelRect viewport_rect() const override;
|
||||
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const override;
|
||||
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const override;
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ void ViewImplementation::server_did_paint(Badge<WebContentClient>, i32 bitmap_id
|
|||
|
||||
m_client_state.has_usable_bitmap = true;
|
||||
m_client_state.back_bitmap.pending_paints--;
|
||||
m_client_state.back_bitmap.last_painted_size = size;
|
||||
m_client_state.back_bitmap.last_painted_size = size.to_type<Web::DevicePixels>();
|
||||
swap(m_client_state.back_bitmap, m_client_state.front_bitmap);
|
||||
|
||||
// We don't need the backup bitmap anymore, so drop it.
|
||||
|
@ -310,7 +310,7 @@ void ViewImplementation::resize_backing_stores_if_needed(WindowResizeInProgress
|
|||
if (viewport_rect.is_empty())
|
||||
return;
|
||||
|
||||
Gfx::IntSize minimum_needed_size;
|
||||
Web::DevicePixelSize minimum_needed_size;
|
||||
|
||||
if (window_resize_in_progress == WindowResizeInProgress::Yes) {
|
||||
// Pad the minimum needed size so that we don't have to keep reallocating backing stores while the window is being resized.
|
||||
|
@ -323,8 +323,8 @@ void ViewImplementation::resize_backing_stores_if_needed(WindowResizeInProgress
|
|||
}
|
||||
|
||||
auto reallocate_backing_store_if_needed = [&](SharedBitmap& backing_store) {
|
||||
if (!backing_store.bitmap || !backing_store.bitmap->size().contains(minimum_needed_size)) {
|
||||
if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, minimum_needed_size); !new_bitmap_or_error.is_error()) {
|
||||
if (!backing_store.bitmap || !backing_store.bitmap->size().contains(minimum_needed_size.to_type<int>())) {
|
||||
if (auto new_bitmap_or_error = Gfx::Bitmap::create_shareable(Gfx::BitmapFormat::BGRA8888, minimum_needed_size.to_type<int>()); !new_bitmap_or_error.is_error()) {
|
||||
if (backing_store.bitmap)
|
||||
client().async_remove_backing_store(backing_store.id);
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ public:
|
|||
Function<void(i32, Gfx::IntPoint, String const&, Optional<String> const&, Optional<Attribute> const&)> on_inspector_requested_dom_tree_context_menu;
|
||||
Function<void(String const&)> on_inspector_executed_console_script;
|
||||
|
||||
virtual Gfx::IntRect viewport_rect() const = 0;
|
||||
virtual Web::DevicePixelRect viewport_rect() const = 0;
|
||||
virtual Gfx::IntPoint to_content_position(Gfx::IntPoint widget_position) const = 0;
|
||||
virtual Gfx::IntPoint to_widget_position(Gfx::IntPoint content_position) const = 0;
|
||||
|
||||
|
@ -205,7 +205,7 @@ protected:
|
|||
struct SharedBitmap {
|
||||
i32 id { -1 };
|
||||
i32 pending_paints { 0 };
|
||||
Gfx::IntSize last_painted_size;
|
||||
Web::DevicePixelSize last_painted_size;
|
||||
RefPtr<Gfx::Bitmap> bitmap;
|
||||
};
|
||||
|
||||
|
@ -227,7 +227,7 @@ protected:
|
|||
RefPtr<Core::Timer> m_backing_store_shrink_timer;
|
||||
|
||||
RefPtr<Gfx::Bitmap> m_backup_bitmap;
|
||||
Gfx::IntSize m_backup_bitmap_size;
|
||||
Web::DevicePixelSize m_backup_bitmap_size;
|
||||
|
||||
size_t m_crash_count = 0;
|
||||
RefPtr<Core::Timer> m_repeated_crash_timer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue