Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Iri-Hor committed Sep 26, 2023
1 parent 77f0333 commit 1dbd5a2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/desktop_webview_window/lib/src/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ abstract class Webview {
/// Move and Resize the webview window
Future<void> moveWebviewWindow(int left, int top, int width, int height);

/// get position, extents and maximization info of the webview window
Future<Map<dynamic,dynamic>?> getPositionalParameters();

/// Activates the webview window (giving it the focus)
Future<void> bringToForeground();

Expand Down
7 changes: 7 additions & 0 deletions packages/desktop_webview_window/lib/src/webview_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ class WebviewImpl extends Webview {
});
}

@override
Future<Map<dynamic,dynamic>?> getPositionalParameters() async {
return await channel.invokeMethod("getPositionalParameters", {
"viewId": viewId,
});
}

@override
Future<void> bringToForeground() {
return channel.invokeMethod("bringToForeground", {
Expand Down
12 changes: 12 additions & 0 deletions packages/desktop_webview_window/windows/web_view_window_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ void WebviewWindowPlugin::HandleMethodCall(
}
windows_[window_id]->moveWebviewWindow(left, top, width, height);
result->Success();
} else if (method_call.method_name() == "getPositionalParameters") {
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
auto window_id = arguments->at(flutter::EncodableValue("viewId")).LongValue();
if (!windows_.count(window_id)) {
result->Error("0", "can not find webview window for id");
return;
}
if (!windows_[window_id]->GetWebView()) {
result->Error("0", "webview window not ready");
return;
}
windows_[window_id]->getPositionalParameters(std::move(result));
} else if (method_call.method_name() == "bringToForeground") {
auto* arguments = std::get_if<flutter::EncodableMap>(method_call.arguments());
auto window_id = arguments->at(flutter::EncodableValue("viewId")).LongValue();
Expand Down
15 changes: 15 additions & 0 deletions packages/desktop_webview_window/windows/webview_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ void WebviewWindow::moveWebviewWindow(int left, int top, int width, int height)
::SetWindowPos(hwnd_.get(), nullptr, left, top, width, height, SWP_NOZORDER | SWP_NOACTIVATE);
}

void WebviewWindow::getPositionalParameters(std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer) {
RECT rc;
GetWindowRect(hwnd_.get(), &rc);

std::unique_ptr<WINDOWPLACEMENT> wp(new WINDOWPLACEMENT);
GetWindowPlacement(hwnd_.get(), wp.get());
std::map<flutter::EncodableValue, flutter::EncodableValue> m{
{"left", rc.left},
{"top", rc.top},
{"width", rc.right-rc.left},
{"height", rc.bottom-rc.top},
{"maximized", wp->showCmd==SW_MAXIMIZE}};
completer->Success(flutter::EncodableValue(m));
}

void WebviewWindow::bringToForeground() {
SetForegroundWindow(hwnd_.get());
}
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop_webview_window/windows/webview_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class WebviewWindow {

void moveWebviewWindow(int left, int top, int width, int height);

void getPositionalParameters(std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> completer);

void bringToForeground();

[[nodiscard]] const std::unique_ptr<webview_window::WebView> &GetWebView() const {
Expand Down

0 comments on commit 1dbd5a2

Please sign in to comment.