mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 01:29:17 +00:00
UI/AppKit: Extract gfx_bitmap_to_ns_image() code
This commit is contained in:
parent
bfd7ac1204
commit
e0b5e742de
Notes:
github-actions[bot]
2025-02-28 12:51:16 +00:00
Author: https://github.com/AtkinsSJ
Commit: e0b5e742de
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3644
3 changed files with 19 additions and 11 deletions
|
@ -7,7 +7,6 @@
|
||||||
#include <AK/ByteString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCore/Resource.h>
|
#include <LibCore/Resource.h>
|
||||||
#include <LibGfx/ImageFormats/PNGWriter.h>
|
|
||||||
#include <LibGfx/ShareableBitmap.h>
|
#include <LibGfx/ShareableBitmap.h>
|
||||||
#include <LibURL/URL.h>
|
#include <LibURL/URL.h>
|
||||||
#include <LibWebView/ViewImplementation.h>
|
#include <LibWebView/ViewImplementation.h>
|
||||||
|
@ -348,17 +347,8 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800;
|
||||||
|
|
||||||
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap
|
- (void)onFaviconChange:(Gfx::Bitmap const&)bitmap
|
||||||
{
|
{
|
||||||
auto png = Gfx::PNGWriter::encode(bitmap);
|
auto* favicon = Ladybird::gfx_bitmap_to_ns_image(bitmap);
|
||||||
if (png.is_error()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto* data = [NSData dataWithBytes:png.value().data()
|
|
||||||
length:png.value().size()];
|
|
||||||
|
|
||||||
auto* favicon = [[NSImage alloc] initWithData:data];
|
|
||||||
[favicon setResizingMode:NSImageResizingModeStretch];
|
[favicon setResizingMode:NSImageResizingModeStretch];
|
||||||
|
|
||||||
self.favicon = favicon;
|
self.favicon = favicon;
|
||||||
[self updateTabTitleAndFavicon];
|
[self updateTabTitleAndFavicon];
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/ByteString.h>
|
#include <AK/ByteString.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/StringView.h>
|
#include <AK/StringView.h>
|
||||||
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Color.h>
|
#include <LibGfx/Color.h>
|
||||||
#include <LibGfx/Point.h>
|
#include <LibGfx/Point.h>
|
||||||
#include <LibGfx/Rect.h>
|
#include <LibGfx/Rect.h>
|
||||||
|
@ -40,4 +41,6 @@ NSColor* gfx_color_to_ns_color(Gfx::Color);
|
||||||
|
|
||||||
Gfx::IntPoint compute_origin_relative_to_window(NSWindow*, Gfx::IntPoint);
|
Gfx::IntPoint compute_origin_relative_to_window(NSWindow*, Gfx::IntPoint);
|
||||||
|
|
||||||
|
NSImage* gfx_bitmap_to_ns_image(Gfx::Bitmap const&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibGfx/ImageFormats/PNGWriter.h>
|
||||||
|
|
||||||
#import <Utilities/Conversions.h>
|
#import <Utilities/Conversions.h>
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
@ -128,4 +131,16 @@ Gfx::IntPoint compute_origin_relative_to_window(NSWindow* window, Gfx::IntPoint
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSImage* gfx_bitmap_to_ns_image(Gfx::Bitmap const& bitmap)
|
||||||
|
{
|
||||||
|
auto png = Gfx::PNGWriter::encode(bitmap);
|
||||||
|
if (png.is_error())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
auto* data = [NSData dataWithBytes:png.value().data()
|
||||||
|
length:png.value().size()];
|
||||||
|
|
||||||
|
return [[NSImage alloc] initWithData:data];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue