Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions capsules/browser/browser/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const BROWSER_AUTHORITY_RENEWAL_RETRY_DELAYS_MS = Object.freeze([
30_000,
]);
const HOME_GUI_OPAQUE_ORIGIN = "null";
const WINDOW_DRAG_MESSAGE_TYPE = "elastos.home.window-drag/v1";
const params = new URLSearchParams(window.location.search);
const browserInstanceId = params.get("browser_instance") || "";
const launchToken = new URLSearchParams(window.location.hash.replace(/^#/, "")).get("home_token") || "";
Expand Down Expand Up @@ -842,6 +843,58 @@ function postHomeBrowserWindowCloseResult(message, owner, outcome, error = null)
);
}

/** Home draws only the window dots over this bar, so a press on an empty part
* of it moves the window the way a title bar does. */
function installChromeWindowDrag(chrome) {
// Home moves the window only for the launch token it gave this frame.
if (!chrome || window.parent === window || !launchToken) {
return;
}
let pointerId = null;
const send = (phase, event) => {
window.parent.postMessage(
{
type: WINDOW_DRAG_MESSAGE_TYPE,
homeToken: launchToken,
phase,
clientX: event.clientX,
clientY: event.clientY,
},
"*",
);
};
chrome.addEventListener("pointerdown", (event) => {
if (
event.button !== 0 ||
pointerId !== null ||
event.target.closest("button, input, select, textarea, a, label, form, [role='button']")
) {
return;
}
event.preventDefault();
pointerId = event.pointerId;
chrome.setPointerCapture(pointerId);
send("start", event);
});
chrome.addEventListener("pointermove", (event) => {
if (event.pointerId === pointerId) {
send("move", event);
}
});
const stop = (event) => {
if (event.pointerId !== pointerId) {
return;
}
pointerId = null;
send("end", event);
};
chrome.addEventListener("pointerup", stop);
chrome.addEventListener("pointercancel", stop);
chrome.addEventListener("lostpointercapture", stop);
}

installChromeWindowDrag(document.querySelector(".browser-chrome"));

function deliverPendingHomeBrowserWindowClose(owner, outcome) {
const delivery = pendingHomeWindowCloseDelivery;
const currentOwner = currentRuntimePageOwner();
Expand Down
6 changes: 3 additions & 3 deletions capsules/browser/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<title>ElastOS Browser</title>
<script src="./elastos-theme.js"></script>
<link rel="stylesheet" href="./elastos-ui.css">
<link rel="stylesheet" href="./style.css?v=browser-20261015a" />
<link rel="modulepreload" href="./browser.js?v=browser-20261015a" />
<link rel="stylesheet" href="./style.css?v=browser-20261016a" />
<link rel="modulepreload" href="./browser.js?v=browser-20261017a" />
<link rel="modulepreload" href="./browser-location.js?v=browser-20260523b" />
<link rel="modulepreload" href="./browser-runtime-api.js?v=browser-20260907c" />
<link rel="modulepreload" href="./browser-clipboard.js?v=browser-20260725b" />
Expand Down Expand Up @@ -110,6 +110,6 @@
</section>
</main>

<script type="module" src="./browser.js?v=browser-20261015a"></script>
<script type="module" src="./browser.js?v=browser-20261017a"></script>
</body>
</html>
9 changes: 5 additions & 4 deletions capsules/browser/browser/style.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* Browser chrome — Safari-inspired toolbar under the standard Home title bar.
/* Browser chrome — Safari-inspired unified toolbar.
Shell owns traffic lights (unified-toolbar); menubar owns the app name.
Page stage stays white — content ground, not chrome. */
:root {
--bg: var(--el-bg);
Expand Down Expand Up @@ -61,14 +62,14 @@ select {
overflow: hidden;
}

/* One tool band under the Home title bar. */
/* One tool band under shell lights — pad leading for traffic lights. */
.browser-chrome {
display: grid;
grid-template-columns: auto auto minmax(0, 1fr) auto;
align-items: center;
gap: 8px;
min-height: 52px;
padding: 8px 10px;
padding: 8px 10px 8px var(--window-chrome-safe-leading, 96px);
border-bottom: 0;
background: var(--bg);
}
Expand Down Expand Up @@ -452,7 +453,7 @@ body[data-loading="true"] .browser-address {
.browser-chrome {
min-height: 48px;
gap: 6px;
padding: 6px 8px;
padding: 6px 8px 6px var(--window-chrome-safe-leading, 96px);
}

.browser-address {
Expand Down
12 changes: 11 additions & 1 deletion capsules/home-gui/browser/shell-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,12 @@ export const HOME_GUI_HOST_SELECTORS = Object.freeze([
]);

/* Window chrome modes are presentation-only. Fail closed to standard.
unified-sidebar: split-view apps — lights over the leading column. */
unified-sidebar: split-view apps — lights over the leading column.
unified-toolbar: Browser-style — lights over the tool row; menubar owns the
focused app name. */
export const WINDOW_CHROME_STANDARD = "standard";
export const WINDOW_CHROME_UNIFIED_SIDEBAR = "unified-sidebar";
export const WINDOW_CHROME_UNIFIED_TOOLBAR = "unified-toolbar";

const WINDOW_CHROME_BY_TARGET = {
marketplace: WINDOW_CHROME_UNIFIED_SIDEBAR,
Expand All @@ -433,6 +436,7 @@ const WINDOW_CHROME_BY_TARGET = {
inbox: WINDOW_CHROME_UNIFIED_SIDEBAR,
chat: WINDOW_CHROME_UNIFIED_SIDEBAR,
"chat-room": WINDOW_CHROME_UNIFIED_SIDEBAR,
browser: WINDOW_CHROME_UNIFIED_TOOLBAR,
};

const WINDOW_CHROME_CONTINUOUS_TARGETS = new Set([
Expand All @@ -448,6 +452,9 @@ export function parseWindowChromeMode(value) {
if (value === WINDOW_CHROME_UNIFIED_SIDEBAR) {
return WINDOW_CHROME_UNIFIED_SIDEBAR;
}
if (value === WINDOW_CHROME_UNIFIED_TOOLBAR) {
return WINDOW_CHROME_UNIFIED_TOOLBAR;
}
return WINDOW_CHROME_STANDARD;
}

Expand All @@ -463,11 +470,14 @@ export function applyWindowChrome(windowNode, targetId) {
}
windowNode.classList.remove(
"window-chrome-unified-sidebar",
"window-chrome-unified-toolbar",
"window-chrome-continuous",
);
const mode = windowChromeModeForTarget(targetId);
if (mode === WINDOW_CHROME_UNIFIED_SIDEBAR) {
windowNode.classList.add("window-chrome-unified-sidebar");
} else if (mode === WINDOW_CHROME_UNIFIED_TOOLBAR) {
windowNode.classList.add("window-chrome-unified-toolbar");
} else if (WINDOW_CHROME_CONTINUOUS_TARGETS.has(normalizeText(targetId).toLowerCase())) {
windowNode.classList.add("window-chrome-continuous");
}
Expand Down
135 changes: 135 additions & 0 deletions capsules/home-gui/browser/shell-window-geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
beginShellInteraction,
clamp,
endShellInteraction,
WINDOW_CHROME_UNIFIED_TOOLBAR,
} from "./shell-core.js?v=home-20260813a";
import { isPhone } from "./shell-form-factor.js?v=home-20260813a";
import { registerStageGesture } from "./shell-popovers.js?v=home-20260813a";
Expand Down Expand Up @@ -415,6 +416,140 @@ export function attachWindowDrag(windowNode, handle, focusWindow, onWindowGeomet
handle.addEventListener("pointercancel", stopDrag);
}

export const WINDOW_DRAG_MESSAGE_TYPE = "elastos.home.window-drag/v1";

/** A unified-toolbar capsule draws its own top bar, so a press on an empty
* part of that bar arrives as messages. Only this window's frame can move it:
* the message must come from that frame's WindowProxy with the opaque origin
* and carry the launch token Home gave that frame (`frameHomeToken`), in the
* exact `elastos.home.window-drag/v1` shape. Anything else is ignored.
* Positions are frame-relative and are added to the frame's current place,
* because some engines report screen positions offset or flipped.
* Like the title bar, a drag restores a maximized or snapped window and can
* snap it to a screen edge on release. */
export function attachForwardedWindowDrag(
windowNode,
focusWindow,
onWindowGeometryChange = null,
frameHomeToken = null,
) {
let dragging = null;
const finish = (snapOnRelease = false) => {
if (!dragging) {
return;
}
const snapTarget = snapOnRelease ? dragging.snapTarget : null;
dragging = null;
endShellInteraction();
if (snapTarget) {
applyWindowSnap(windowNode, snapTarget);
focusWindow(windowNode.dataset.windowId);
} else {
hideWindowSnapPreview();
}
if (typeof onWindowGeometryChange === "function") {
onWindowGeometryChange();
}
};
const listener = (event) => {
const data = event.data;
// Capsule frames are sandboxed without allow-same-origin: origin "null".
if (
event.origin !== "null" ||
!data ||
typeof data !== "object" ||
data.type !== WINDOW_DRAG_MESSAGE_TYPE ||
Object.keys(data).sort().join(",") !== "clientX,clientY,homeToken,phase,type" ||
!["start", "move", "end"].includes(data.phase)
) {
return;
}
const frame = windowNode.querySelector(".window-frame");
const homeToken = typeof frameHomeToken === "function" ? frameHomeToken() : "";
if (
windowNode.dataset.windowChromeMode !== WINDOW_CHROME_UNIFIED_TOOLBAR ||
!windowNode.isConnected ||
!frame?.contentWindow ||
event.source !== frame.contentWindow ||
typeof homeToken !== "string" ||
!homeToken ||
data.homeToken !== homeToken
) {
return;
}
if (data.phase === "end") {
finish(true);
return;
}
// A hidden window keeps its place. A window that is maximized, snapped or
// hidden by something else in the middle of a drag stops following.
const special =
windowNode.dataset.maximized === "true" ||
windowNode.dataset.browserMaximized === "true" ||
Boolean(windowNode.dataset.snap);
if (windowNode.classList.contains("hidden") || (dragging && special)) {
finish();
return;
}
if (!Number.isFinite(data.clientX) || !Number.isFinite(data.clientY)) {
return;
}
const frameRect = frame.getBoundingClientRect();
const workspaceRect = desktop.getBoundingClientRect();
const clientX = frameRect.left + data.clientX;
const clientY = frameRect.top + data.clientY;
const pointerX = clientX - workspaceRect.left;
const pointerY = clientY - workspaceRect.top;
if (data.phase === "start") {
hideWindowSnapPreview();
focusWindow(windowNode.dataset.windowId);
// Phone windows fill the stage, as with the title bar.
if (isPhone()) {
return;
}
const bounds = special
? restoreWindowForDrag(windowNode, clientX, clientY)
: normalWindowBounds(windowNode);
if (!dragging) {
beginShellInteraction();
}
dragging = {
offsetX: pointerX - bounds.x,
offsetY: pointerY - bounds.y,
startClientX: clientX,
startClientY: clientY,
snapTarget: null,
};
return;
}
if (data.phase !== "move" || !dragging) {
return;
}
const limits = partialDragBoundsForWindow(windowNode.offsetWidth);
windowNode.style.left = `${safeClamp(pointerX - dragging.offsetX, limits.minX, limits.maxX)}px`;
windowNode.style.top = `${safeClamp(pointerY - dragging.offsetY, limits.minY, limits.maxY)}px`;
const movedDistance = Math.hypot(clientX - dragging.startClientX, clientY - dragging.startClientY);
dragging.snapTarget = movedDistance >= WINDOW_SNAP_ACTIVATION_DISTANCE
? snapTargetForPointer(clientX, clientY)
: null;
showWindowSnapPreview(dragging.snapTarget);
};
// A frame that reloads, navigates or is relaunched mid-drag never sends its
// end, and its old token no longer matches.
const frameLoaded = (event) => {
if (event.target?.classList?.contains("window-frame")) {
finish();
}
};
window.addEventListener("message", listener);
windowNode.addEventListener("load", frameLoaded, true);
return () => {
window.removeEventListener("message", listener);
windowNode.removeEventListener("load", frameLoaded, true);
finish();
};
}

export function attachWindowResize(windowNode, focusWindow, onWindowGeometryChange = null) {
for (const handle of windowNode.querySelectorAll(".window-resize-handle")) {
let resizing = null;
Expand Down
8 changes: 8 additions & 0 deletions capsules/home-gui/browser/shell-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
restoreWindowFromSpecialState,
hideWindowSnapPreview,
attachWindowDrag,
attachForwardedWindowDrag,
attachWindowResize,
} from "./shell-window-geometry.js?v=home-20260813a";
import {
Expand Down Expand Up @@ -969,6 +970,7 @@ function tearDownWindowEntry(entry) {
if (entry.selectionRequest) finishSelectionWindowRequest(entry.selectionRequest, false);
entry.homeNavigation = null;
cleanupFrameAutoFit(entry.node);
entry.node.detachForwardedWindowDrag?.();
shellState.windows.delete(entry.id);
entry.node.remove();
if (entry.fullscreenStage) {
Expand Down Expand Up @@ -1594,6 +1596,12 @@ function createWindow({
toggleWindowMaximize(id);
});
attachWindowDrag(node, handle, focusWindow, persistBrowserSession);
node.detachForwardedWindowDrag = attachForwardedWindowDrag(
node,
focusWindow,
persistBrowserSession,
() => browserLaunchAuthority(node.querySelector(".window-frame")?.dataset.route || "")?.homeToken || "",
);
attachWindowResize(node, focusWindow, persistBrowserSession);

if (maximizeByDefault && shouldOpenMaximizedByDefault()) {
Expand Down
46 changes: 46 additions & 0 deletions capsules/home-gui/browser/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5580,6 +5580,52 @@ body.assistant-space-active #inbox-rail {
height: 100% !important;
}

/* Unified-toolbar chrome (Browser): no window title — menubar owns the name.
Traffic lights sit in the tool-row band; capsule pads
--window-chrome-safe-leading. */
.window.window-chrome-unified-toolbar {
--window-chrome-safe-leading: 96px;
}

.window.window-chrome-unified-toolbar .window-head {
position: absolute;
top: 0;
left: 0;
z-index: 6;
width: 78px;
height: 52px;
min-height: 52px;
margin-bottom: 0;
padding: 0 8px 0 12px;
align-items: center;
border-radius: 12px 0 0 0;
background: transparent;
box-shadow: none;
filter: none;
}

.window.window-chrome-unified-toolbar.window-active .window-head {
filter: none;
}

.window.window-chrome-unified-toolbar .window-head-icon,
.window.window-chrome-unified-toolbar .window-head-title,
.window.window-chrome-unified-toolbar .window-head-balance {
display: none;
}

.window.window-chrome-unified-toolbar .window-head-draggable {
flex: 1 1 auto;
min-width: 28px;
min-height: 28px;
justify-content: flex-start;
align-self: stretch;
}

.window.window-chrome-unified-toolbar .window-body {
height: 100%;
}

/* Continuous standard: titlebar fill matches frame (Wallet / Archive / GBA /
connectors). Soft hairline only — no frosted second band. */
.window.window-chrome-continuous .window-head {
Expand Down
Loading
Loading