Skip to content

Commit f170cd5

Browse files
committed
feat: Added a new tab page on harbor:new url
1 parent 115ffb2 commit f170cd5

7 files changed

Lines changed: 61 additions & 12 deletions

File tree

docs/devlogs/044/44.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
![Logo](https://github.com/tathyagarg/harbor/raw/main/.github/assets/logo.png?raw)
2+
# Changes
3+
---
4+
- [bed7f9b](https://github.com/tathyagarg/harbor/commit/bed7f9b12c88abbd09bfd8ffb97544b141a79d0b): Made tabs in the tab bar clickable to switch between them. There's a *tiny* bug where you can press between tabs and it still switches to a tab, but the gap is so small that I couldn't be bothered to fix it.
5+
- [7e5a03e](https://github.com/tathyagarg/harbor/commit/7e5a03e80033896defe8d8dce3b370c495c030cc): Added support for fetching stylesheets from the `<link>` tag in HTML documents. I'm pretty sure this has a bug that means relative paths won't work. I haven't tested that but I know I didn't implement it, so it probably doesn't work.
6+
- [d8ce0a4](https://github.com/tathyagarg/harbor/commit/d8ce0a4e3d24375a96bf0f9c0be8e5c9b9aa5bf4): Made the tabs in the tab bar resize automatically with the number of tabs open.
7+
- [bb139f9](https://github.com/tathyagarg/harbor/commit/bb139f9bb6278a8c2a1af9dc8d3b6cd2571c392c): Added the basic address bar display that shows the URL of the current page. It doesn't do anything yet, but it's there.
8+
- [491f59b](https://github.com/tathyagarg/harbor/commit/491f59b0e4017c3050ace39e7ad284cc111022bf): Added editing capabilities to the address bar. You can click on it and type, and press enter to navigate to the URL you typed. It doesn't do any error handling or anything, so if you type something that's not a valid URL it will just crash the browser. But it works for valid URLs.
9+
10+
---
11+
# Next Steps
12+
---
13+
1. Add forward and back buttons to the address bar and make them functional.

docs/devlogs/044/44.png

92.4 KB
Loading

harbor/engine/res/pages/tab.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>New Tab</title>
7+
<style>
8+
body {
9+
background-color: #121212;
10+
}
11+
12+
h1 {
13+
color: #ffffff;
14+
}
15+
16+
p {
17+
color: #cccccc;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<h1>Welcome to your new tab!</h1>
23+
<p>This is a custom new tab page.</p>
24+
</body>
25+
</html>

harbor/engine/src/agent.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ impl Agent {
9797
}
9898

9999
pub fn open(&mut self, url: &str) -> Option<Rc<RefCell<Document>>> {
100+
if url.starts_with("harbor:") {
101+
let path = url.trim_start_matches("harbor:").to_string();
102+
103+
match path.as_str() {
104+
"new" => {
105+
let html_content = fs::read_to_string("res/pages/tab.html").unwrap();
106+
let mut stream =
107+
InputStream::new(&html_content.chars().collect::<Vec<char>>()[..]);
108+
109+
let document = Parser::parse_stream(&mut stream);
110+
document
111+
.borrow_mut()
112+
.insert_stylesheet(0, self.ua_stylesheet.clone());
113+
114+
return Some(document);
115+
}
116+
_ => return None,
117+
}
118+
}
119+
100120
let maybe_resolved_url = URL::pure_parse(url.to_string());
101121

102122
if maybe_resolved_url.is_err() {

harbor/engine/src/http/url.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,6 @@ impl URL {
10401040

10411041
input = input.replace("\t", "").replace("\n", "");
10421042

1043-
println!("inp: {}", input);
1044-
10451043
let mut state = state_override.clone().unwrap_or(ParseURLState::SchemeStart);
10461044
let mut buffer = String::new();
10471045
let mut at_sign_seen = false;

harbor/engine/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ fn main() {
170170
agent: Some(Rc::clone(&ua)),
171171
callbacks: None,
172172
initial_url: Some(
173-
"file:///Users/tathyagarg/programming/harbor/assets/html/custom006.html".to_string(),
173+
"file:///Users/tathyagarg/programming/harbor/assets/html/position-demo.html"
174+
.to_string(),
174175
),
175176
};
176177

harbor/engine/src/render/state.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,20 +424,12 @@ impl WindowState {
424424
if bg_color[3] > 0.0 {
425425
render_pass.set_pipeline(&self.fill_render_pipeline);
426426

427-
let window_size = self.window.inner_size();
428-
429-
// let x_pos = (adj_position.0 as f32 / window_size.width as f32) * 2.0 - 1.0;
430-
// let y_pos = 1.0 - (adj_position.1 as f32 / window_size.height as f32) * 2.0;
431-
432427
let (x_pos, y_pos) = adj_position;
433428

434429
let pixel_w = layout_box.content_edges().horizontal() as f32;
435430
let pixel_h = layout_box.content_edges().vertical() as f32;
436431

437-
let width = (pixel_w / window_size.width as f32) * 2.0;
438-
let height = (pixel_h / window_size.height as f32) * 2.0;
439-
440-
let verts = rectangle_at(x_pos as f32, y_pos as f32, width, height, bg_color);
432+
let verts = rectangle_at(x_pos as f32, y_pos as f32, pixel_w, pixel_h, bg_color);
441433

442434
let bg_vertex_buffer =
443435
self.device

0 commit comments

Comments
 (0)