Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(prompt): add prompt support #250

Merged
merged 38 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cf804dd
feat(context-menu): create webview on wayland
pewsheen Nov 12, 2024
b010dc1
Merge branch 'main' into wayland-webview-context-menu
pewsheen Nov 13, 2024
ecf72f9
dynamic generate menu items on html
pewsheen Nov 13, 2024
15b7cb6
add context_menu.html
pewsheen Nov 13, 2024
5213d8c
add check mouse hit on context-menu webview
pewsheen Nov 13, 2024
4b9814f
fix: context menu prompt back to verso
pewsheen Nov 13, 2024
487d6ba
feat(context-menu): on linux, handle selection
pewsheen Nov 14, 2024
5b0a26a
fix: disble right click on context menu
pewsheen Nov 14, 2024
80961bc
Merge branch 'main' into wayland-webview-context-menu
pewsheen Nov 14, 2024
0c63a6d
organize code
pewsheen Nov 14, 2024
d7d97e3
adding cfg target linux
pewsheen Nov 14, 2024
73f63e2
fix(linux): shift context menu to avoid overflow, best effort
pewsheen Nov 15, 2024
26fcf7a
Merge branch 'main' into wayland-webview-context-menu
pewsheen Nov 15, 2024
ab68e2c
prompt temp
pewsheen Nov 15, 2024
a818059
Merge branch 'main' into prompt
pewsheen Nov 20, 2024
c3d6988
add alert prompt
pewsheen Nov 20, 2024
250cf5d
Merge branch 'main' into prompt
pewsheen Nov 20, 2024
a6c9b7b
refactor: move prompt and context menu to components
pewsheen Nov 20, 2024
3a6fc4a
remove redundant import
pewsheen Nov 20, 2024
71b2ac3
feat(prompt): add ok/cancel, yes/no prompt
pewsheen Nov 22, 2024
2e9173a
feat(prompt): add input prompt dialog
pewsheen Nov 22, 2024
9caab41
fix: add serde to all platform's dep
pewsheen Nov 22, 2024
3cca459
refactor: organize verso html files
pewsheen Nov 25, 2024
130fd20
Merge branch 'main' into prompt
pewsheen Nov 25, 2024
ffa235b
update gitignore
pewsheen Nov 25, 2024
f188af7
refactor: remove dialog show method depends on Window
pewsheen Nov 26, 2024
2544d0e
refactor: code clean
pewsheen Nov 26, 2024
5098cac
fix: don't show context menu when prompt exist
pewsheen Nov 26, 2024
027aa54
update css
pewsheen Nov 26, 2024
183dcb3
fix(prompt): handle resize when prompt exists
pewsheen Nov 27, 2024
33fe310
fix(prompt): close prompt when navigate to new url
pewsheen Nov 28, 2024
8edeb6e
chore: restore default home page
pewsheen Dec 2, 2024
a2f2e37
Merge branch 'main' into prompt
pewsheen Dec 2, 2024
bb8c538
chore: fix linux mod path, remove unused pipeline fn
pewsheen Dec 2, 2024
b71c98b
Merge branch 'main' into prompt
pewsheen Dec 2, 2024
3eddf79
feat: handle EmbedderMsg::PromptPermission
pewsheen Dec 4, 2024
fe62206
refactor: rename components to webview and move WebView into it
pewsheen Dec 4, 2024
9c31e62
Merge branch 'main' into prompt
pewsheen Dec 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Cargo.lock
libmozjs*
cargo-sources.json

resources/
!resources/panel.html
!resources/context-menu.html
resources/*
!resources/components/
!resources/prefs.json
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ cargo-packager-resource-resolver = { version = "0.1.1", features = [
url = { workspace = true }
headers = "0.3"
versoview_messages = { path = "./versoview_messages" }

[target.'cfg(all(unix, not(apple), not(android)))'.dependencies]
serde_json = "1.0"
serde = { workspace = true }

Expand Down
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions resources/components/prompt/alert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
</head>
<body>
<div class="dialog">
<div id="msg" class="msg"></div>
<button onclick="sendToVersoAndClose()">Ok</button>
</div>
</body>
<script>
let url = URL.parse(window.location.href);
let msg = url.searchParams.get('msg');

// Set dialog message
const msgEl = document.getElementById('msg');
msgEl.textContent = msg ?? '';

function sendToVersoAndClose() {
window.alert(''); // Use as an IPC between Verso and WebView
window.close();
}
</script>
</html>
57 changes: 57 additions & 0 deletions resources/components/prompt/ok_cancel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
</head>
<body>
<div class="dialog">
<div id="msg" class="msg"></div>
<div class="btn-group">
<button onclick="sendToVersoAndClose('cancel')">Cancel</button>
<button onclick="sendToVersoAndClose('ok')">Ok</button>
</div>
</div>
</body>
<script>
let url = URL.parse(window.location.href);
let msg = url.searchParams.get('msg');

// Set dialog message
const msgEl = document.getElementById('msg');
msgEl.textContent = msg ?? '';

function sendToVersoAndClose(action) {
window.alert(action); // Use as an IPC between Verso and WebView
window.close();
}
</script>
</html>
72 changes: 72 additions & 0 deletions resources/components/prompt/prompt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
</head>
<body>
<div class="dialog">
<div id="msg" class="msg"></div>
<input type="text" id="input" />
<div class="btn-group">
<button onclick="sendToVersoAndClose('cancel')">Cancel</button>
<button onclick="sendToVersoAndClose('ok')">Ok</button>
</div>
</div>
</body>
<script>
const inputEl = document.getElementById('input');
const msgEl = document.getElementById('msg');

const params = URL.parse(window.location.href).searchParams;

// Set input default value
const defaultValue = params.get('defaultValue');
if (typeof defaultValue === 'string' || defaultValue instanceof String) {
inputEl.defaultValue = defaultValue;
}

// Set dialog message
const msg = params.get('msg');
msgEl.textContent = msg ?? '';

function sendToVersoAndClose(action) {
// Use as an IPC between Verso and WebView
window.alert(
JSON.stringify({
action,
value: inputEl.value,
})
);
window.close();
}
</script>
</html>
30 changes: 30 additions & 0 deletions resources/components/prompt/prompt_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<html>
<body>
<div style="display: block">
<button onclick="window.alert('<a> HREF </a>');">alert</button>
<button onclick="sendConfirm();">confirm</button>
<button onclick="sendPrompt('');">prompt</button>
<button onclick="sendPrompt(null, '>> default value >>');">
prompt with default value
</button>
</div>

<div style="display: inline-block" id="result"></div>

<script>
const resultEl = document.getElementById('result');

function sendConfirm(text) {
let result = window.confirm(text);
resultEl.textContent = JSON.stringify(result);
console.log(result);
}

function sendPrompt(text, defaultValue) {
let result = window.prompt(text, defaultValue);
resultEl.textContent = JSON.stringify(result);
console.log(result);
}
</script>
</body>
</html>
57 changes: 57 additions & 0 deletions resources/components/prompt/yes_no.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<html>
<head>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
justify-content: center;
align-items: center;
padding: 0;
margin: 0;
background-color: #7d818644;
}
.dialog {
display: flex;
background: #ffffff;
width: 400px;
min-height: 110px;
max-height: 300px;
flex-direction: column;
align-items: center;
border-radius: 10px;
box-shadow: 0 0 50px #ccc;
box-sizing: border-box;
padding: 8px;
gap: 8px;
}
.msg {
display: inline-block;
width: 100%;
min-height: 90px;
text-align: center;
}
</style>
</head>
<body>
<div class="dialog">
<div id="msg" class="msg"></div>
<div class="btn-group">
<button onclick="sendToVersoAndClose('no')">No</button>
<button onclick="sendToVersoAndClose('yes')">Yes</button>
</div>
</div>
</body>
<script>
let url = URL.parse(window.location.href);
let msg = url.searchParams.get('msg');

// Set dialog message
const msgEl = document.getElementById('msg');
msgEl.textContent = msg ?? '';

function sendToVersoAndClose(action) {
window.alert(action); // Use as an IPC between Verso and WebView
window.close();
}
</script>
</html>
8 changes: 6 additions & 2 deletions src/context_menu.rs → src/components/context_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ impl ContextMenu {
/// Get resource URL of the context menu
fn resource_url(&self) -> ServoUrl {
let items_json: String = self.to_items_json();
let url_str = format!("verso://context_menu.html?items={}", items_json);
let url_str = format!(
"verso://resources/components/context_menu.html?items={}",
items_json
);
ServoUrl::parse(&url_str).unwrap()
}

Expand Down Expand Up @@ -221,8 +224,9 @@ impl MenuItem {
/// Context Menu Click Result
#[cfg(linux)]
#[derive(Debug, Clone, Serialize, Deserialize)]

pub struct ContextMenuResult {
/// The id of the menu ite /// Get the label of the menu item
/// The id of the menu item
pub id: String,
/// Close the context menu
pub close: bool,
Expand Down
4 changes: 4 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// Context Menu
pub mod context_menu;
/// Prompt Dialog
pub mod prompt;
Loading