-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
134 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Copyright 2024 the SumatraPDF project authors (see AUTHORS file). | ||
License: Simplified BSD (see COPYING.BSD) */ | ||
|
||
#include "utils/BaseUtil.h" | ||
#include "utils/Archive.h" | ||
#include "utils/FileUtil.h" | ||
#include "utils/WinUtil.h" | ||
#include "utils/GdiPlusUtil.h" | ||
#include "utils/GuessFileType.h" | ||
#include "utils/Timer.h" | ||
#include "utils/ZipUtil.h" | ||
|
||
#include "wingui/UIModels.h" | ||
#include "wingui/Layout.h" | ||
#include "wingui/WinGui.h" | ||
#include "wingui/WebView.h" | ||
|
||
#include "AppTools.h" | ||
|
||
#include "SimpleBrowserWindow.h" | ||
|
||
SimpleBrowserWindow::~SimpleBrowserWindow() { | ||
delete webView; | ||
} | ||
|
||
LRESULT SimpleBrowserWindow::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { | ||
if (msg == WM_CLOSE) { | ||
OnClose(); | ||
return 0; | ||
} | ||
if (msg == WM_SIZE && webView) { | ||
Rect rc = ClientRect(hwnd); | ||
rc.x += 10; | ||
rc.y += 10; | ||
rc.dx -= 20; | ||
rc.dy -= 20; | ||
webView->SetBounds(rc); | ||
} | ||
return WndProcDefault(hwnd, msg, wparam, lparam); | ||
} | ||
|
||
HWND SimpleBrowserWindow::Create(const SimpleBrowserCreateArgs& args) { | ||
HWND hwnd = nullptr; | ||
{ | ||
CreateCustomArgs cargs; | ||
cargs.pos = args.pos; | ||
if (cargs.pos.IsZero()) { | ||
cargs.pos = {CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT}; | ||
} | ||
cargs.title = args.title; | ||
if (!cargs.title) { | ||
cargs.title = "Browser Window"; | ||
} | ||
// TODO: if set, navigate to url doesn't work | ||
// args.visible = false; | ||
hwnd = CreateCustom(cargs); | ||
ReportIf(!hwnd); | ||
} | ||
{ | ||
Rect rc = ClientRect(hwnd); | ||
webView = new Webview2Wnd(); | ||
const char* dataDir = args.dataDir; | ||
if (!dataDir) { | ||
dataDir = AppGenDataFilenameTemp("webViewData"); | ||
} | ||
webView->dataDir = str::Dup(dataDir); | ||
CreateWebViewArgs cargs; | ||
cargs.parent = hwnd; | ||
cargs.pos = {10, 10, rc.dx - 20, rc.dy - 20}; | ||
hwnd = webView->Create(cargs); | ||
if (!hwnd) { | ||
// ReportIfQuick(!hwnd); | ||
return nullptr; | ||
} | ||
webView->SetIsVisible(true); | ||
} | ||
// important to call this after hooking up onSize to ensure | ||
// first layout is triggered | ||
webView->Navigate(args.url); | ||
SetIsVisible(true); | ||
return hwnd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* Copyright 2024 the SumatraPDF project authors (see AUTHORS file). | ||
License: Simplified BSD (see COPYING.BSD) */ | ||
|
||
struct SimpleBrowserCreateArgs { | ||
const char* title = nullptr; | ||
Rect pos{}; // if empty, will use CW_USEDEFAULT | ||
const char* url = nullptr; | ||
const char* dataDir = nullptr; | ||
}; | ||
|
||
struct SimpleBrowserWindow : Wnd { | ||
Webview2Wnd* webView = nullptr; | ||
HWND Create(const SimpleBrowserCreateArgs&); | ||
LRESULT WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) override; | ||
~SimpleBrowserWindow() override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters