mirror of
https://github.com/chenasraf/webview_cef.git
synced 2026-05-18 01:49:03 +00:00
[macos] hi DPI support
This commit is contained in:
@@ -204,8 +204,9 @@ void SimpleHandler::sendScrollEvent(int x, int y, int deltaX, int deltaY) {
|
||||
}
|
||||
}
|
||||
|
||||
void SimpleHandler::changeSize(int w, int h)
|
||||
void SimpleHandler::changeSize(float dpi, int w, int h)
|
||||
{
|
||||
this->dpi = dpi;
|
||||
this->width = w;
|
||||
this->height = h;
|
||||
BrowserList::const_iterator it = browser_list_.begin();
|
||||
@@ -253,7 +254,7 @@ void SimpleHandler::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) {
|
||||
|
||||
bool SimpleHandler::GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info) {
|
||||
//todo: hi dpi support
|
||||
screen_info.device_scale_factor = 1;
|
||||
screen_info.device_scale_factor = this->dpi;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
|
||||
void sendScrollEvent(int x, int y, int deltaX, int deltaY);
|
||||
|
||||
void changeSize(int width, int height);
|
||||
void changeSize(float dpi, int width, int height);
|
||||
|
||||
void cursorClick(int x, int y, bool up);
|
||||
|
||||
@@ -90,6 +90,7 @@ public:
|
||||
private:
|
||||
uint32_t width = 1280;
|
||||
uint32_t height = 720;
|
||||
float dpi = 1.0;
|
||||
|
||||
// Platform-specific implementation.
|
||||
void PlatformTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
|
||||
@@ -101,13 +101,13 @@ class WebviewController extends ValueNotifier<bool> {
|
||||
}
|
||||
|
||||
/// Sets the surface size to the provided [size].
|
||||
Future<void> _setSize(Size size) async {
|
||||
Future<void> _setSize(double dpi, Size size) async {
|
||||
if (_isDisposed) {
|
||||
return;
|
||||
}
|
||||
assert(value);
|
||||
return _pluginChannel
|
||||
.invokeMethod('setSize', [size.width.round(), size.height.round()]);
|
||||
.invokeMethod('setSize', [dpi, size.width, size.height]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ class WebviewState extends State<Webview> {
|
||||
final box = _key.currentContext?.findRenderObject() as RenderBox?;
|
||||
if (box != null) {
|
||||
await _controller.ready;
|
||||
unawaited(_controller._setSize(Size(box.size.width, box.size.height)));
|
||||
unawaited(_controller._setSize(dpi, Size(box.size.width, box.size.height)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ extern int64_t textureId;
|
||||
|
||||
+ (void)sendScrollEvent:(int)x y:(int)y deltaX:(int)deltaX deltaY:(int)deltaY;
|
||||
|
||||
+ (void) sizeChanged: (int)width height:(int)height;
|
||||
+ (void) sizeChanged: (float)dpi width:(int)width height:(int)height;
|
||||
|
||||
+ (void) loadUrl: (NSString *)url;
|
||||
|
||||
|
||||
@@ -111,8 +111,8 @@ int64_t textureId;
|
||||
handler.get()->cursorClick(x, y, false);
|
||||
}
|
||||
|
||||
+ (void)sizeChanged:(int)width height:(int)height {
|
||||
handler.get()->changeSize(width, height);
|
||||
+ (void)sizeChanged:(float)dpi width:(int)width height:(int)height {
|
||||
handler.get()->changeSize(dpi, width, height);
|
||||
}
|
||||
|
||||
+ (void)loadUrl:(NSString*)url {
|
||||
|
||||
@@ -58,9 +58,10 @@
|
||||
}
|
||||
else if([@"setSize" isEqualToString:call.method]){
|
||||
NSArray<NSNumber *> *_arg = call.arguments;
|
||||
NSNumber *width = [_arg objectAtIndex:0];
|
||||
NSNumber *height = [_arg objectAtIndex:1];
|
||||
[CefWrapper sizeChanged:[width intValue] height:[height intValue]];
|
||||
NSNumber *dpi = [_arg objectAtIndex:0];
|
||||
NSNumber *width = [_arg objectAtIndex:1];
|
||||
NSNumber *height = [_arg objectAtIndex:2];
|
||||
[CefWrapper sizeChanged: [dpi floatValue] width:[width intValue] height:[height intValue]];
|
||||
result(nil);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user