Commit graph

25 commits

Author SHA1 Message Date
Benedikt Willi
a65aaac61b Enhance DOM graph visualization to support PNG images and improve legend display 2026-01-13 14:24:00 +01:00
Benedikt Willi
ce5dbff562 Enhance DOM graph visualization and image handling
- Implement PNG rendering for DOM graphs, with fallback to DOT format.
- Add support for max-width constraints in image layout based on CSS styles.
- Introduce caching mechanisms for image loading, including tracking failed and pending loads.
- Update HTML parser to handle void elements correctly.
- Modify template rendering to support PNG graph files.
2026-01-13 14:23:45 +01:00
Benedikt Willi
8c2d360515 This commit introduces several enhancements to the browser rendering engine. Key changes include the ability to handle link clicks, improved link detection, and enhanced color parsing for proper rendering of styled links. The following modifications are included:
- **Link Detection and Navigation**: Added functionality to detect if a mouse click falls within a link area. If a link is clicked, the browser now navigates to the corresponding URL while logging the action. This also includes handling relative URLs based on the current page context.

- **Line Layout Enhancements**: The `LayoutLine` class now includes optional attributes for color and href, allowing links to maintain their designated colors in the rendered output.

- **Color Parsing**: Implemented a new `_parse_color` method in the `RenderPipeline` class to convert various color formats (hex and named colors) to Skia-compatible values. This ensures that default link colors are correctly applied and that extremely light colors are rendered as black for visibility.

- **Rendering Links**: During the rendering process, links in the text layout are now rendered with their specified colors, and an underline is drawn under links to indicate interactivity.

- **Document Layout Updates**: The document parsing system has been updated to extract link information correctly while preserving text hierarchy.

- **Tests**: A comprehensive suite of tests has been added, including tests for link parsing, layout characteristics, styling application, and default color handling for links.
2026-01-13 13:06:20 +01:00
Benedikt Willi
762dd22e31 Implement image loading and rendering support in Bowser browser
This commit introduces support for loading and rendering images in the Bowser web browser, enhancing the rendering engine to handle various image sources. Key changes include:

- Updated README.md to reflect the new milestone status and added features for image support.
- Added `ImageLayout` class to manage image layout and loading.
- Implemented synchronous and asynchronous image loading in `src/network/images.py`, including caching mechanisms.
- Expanded the DOM parsing capabilities in `DocumentLayout` to handle `<img>` tags and manage their layout directives.
- Created a new `DrawImage` command in the rendering pipeline, which handles the drawing of both loaded images and placeholders for unloaded images.
- Introduced a task queue for managing asynchronous image loads, ensuring UI remains responsive during image fetching.
- Added unit tests for image loading, layout management, and the async task queue to ensure robust functionality and prevent regressions.
2026-01-12 17:36:14 +01:00
Benedikt Willi
2380f7be31 Enhance font handling and layout rendering by supporting font-family in layout lines, improving CSS rule parsing for multi-selectors, and updating start page styles to include emoji support. 2026-01-12 16:05:14 +01:00
Benedikt Willi
ae5913be2e Implement CSS parsing, selector matching, and style resolution
- Added a comprehensive CSS parser with support for tag, class, and ID selectors.
- Implemented property declaration parsing and inline style handling.
- Introduced a Selector class for specificity calculation and matching against HTML elements.
- Created a CSSRule class to represent individual CSS rules.
- Developed a StyleResolver class to compute final styles for elements, considering cascade and inheritance.
- Added integration tests for CSS parsing and style application in HTML documents.
- Updated HTML parser to retain <style> tags for CSS extraction.
- Enhanced tests for CSS parsing, inline styles, and computed styles.
2026-01-12 11:41:18 +01:00
Benedikt Willi
c9ef5e5c44 Refactor test files to remove unnecessary imports and improve readability
- Removed unused imports from various test files to streamline code.
- Cleaned up whitespace in test cases for better consistency.
- Updated dependency management in `uv.lock` to reflect changes in optional dependencies.
- Ensured all tests maintain functionality while enhancing clarity and organization.
2026-01-12 10:22:34 +01:00
Benedikt Willi
4b3ba9144d Removed old documentation files 2026-01-12 09:16:23 +01:00
Benedikt Willi
99a3a4c145 Implement render pipeline for layout and painting, enhancing document rendering and debug capabilities 2026-01-11 23:54:50 +01:00
Benedikt Willi
21e779d281 Add comprehensive tests for layout and rendering components, enhancing coverage for layout lines, blocks, and document structures 2026-01-11 23:41:20 +01:00
Benedikt Willi
8d2fd3b16e Enhance layout and rendering features with new document and block layout implementations 2026-01-11 23:34:27 +01:00
Benedikt Willi
39b03bf9cc Enable debug mode in Chrome when the --debug flag is set and add detailed rendering profiling 2026-01-11 23:17:23 +01:00
Benedikt Willi
e5e281dfc2 Add profiling and layout caching to improve rendering performance 2026-01-11 23:02:52 +01:00
Benedikt Willi
c2533a33c0 Add FPS tracking and character-level text selection as well as enhancements in debug mode 2026-01-11 22:47:42 +01:00
Benedikt Willi
cc9b1157be Enhance DOM rendering and selection features with debug mode support 2026-01-11 22:35:56 +01:00
Benedikt Willi
3838aa17af Add DOM Visualization Feature with Integrated Browser Support
- Introduced a new feature to visualize the Document Object Model (DOM) tree of the loaded web page.
- Implemented keyboard shortcut (Ctrl+Shift+D) for generating and displaying the DOM graph.
- Added core implementation files:
  - src/debug/dom_graph.py: Handles generation and rendering of graphs in DOT and SVG formats.
- Created templates and documentation for the new feature, including:
  - docs/DOM_VISUALIZATION.md: Overview and usage instructions.
  - docs/DOM_GRAPH_UX.md: User experience design documentation.
- Allowed the visualization to open in a new browser tab instead of an external viewer.
- Enhanced visual representation through color coding of different HTML elements.
- Implemented comprehensive tests for graph generation and page rendering.
- Updated README.md to include usage instructions for DOM visualization.
- Included test_holder.html as an example test page.
- Modified various components in the browser to integrate tab management and enhance the graphical rendering experience.
2026-01-10 00:19:21 +01:00
Benedikt Willi
d3119f0b10 Add automatic HTTPS protocol assumption for URLs
Feature: Smart protocol handling
- If no protocol is provided, assume https://
- URLs like 'example.com' become 'https://example.com'
- 'example.com/path' becomes 'https://example.com/path'
- Special 'about:' URLs are preserved as-is

Implementation:
- Added _normalize_url() method to Browser class
- Checks for '://' in URL to detect existing protocol
- Strips whitespace from URLs
- Applied in both new_tab() and navigate_to() methods
- Supports all URL formats (subdomains, ports, paths, queries)

URL Normalization Logic:
1. Strip leading/trailing whitespace
2. Check if URL already has a protocol ('://')
3. Check for special about: URLs
4. Otherwise prepend 'https://'

Examples:
- 'example.com' → 'https://example.com'
- 'https://example.com' → 'https://example.com' (unchanged)
- 'about:startpage' → 'about:startpage' (unchanged)
- 'www.example.com:8080' → 'https://www.example.com:8080'
- 'localhost:3000' → 'https://localhost:3000'

Tests added (10 test cases):
- test_normalize_url_with_https
- test_normalize_url_with_http
- test_normalize_url_without_protocol
- test_normalize_url_with_path
- test_normalize_url_with_about
- test_normalize_url_strips_whitespace
- test_normalize_url_with_query_string
- test_normalize_url_with_subdomain
- test_normalize_url_with_port
- test_normalize_url_localhost

Existing tests still passing (15/15)
2026-01-09 14:52:05 +01:00
Benedikt Willi
cb6103ce04 Reimplement tab bar from scratch with simplified, working design
Simplified tab bar implementation:
- Remove complex CSS provider logic that was causing issues
- Simple box-based layout with tab label + close button per tab
- Direct button click handlers with tab reference stored on widget
- Much simpler and more reliable event handling

Tab bar features:
- Each tab shown as: [tab label button] [close button ✕]
- Active tab highlighted with suggested-action style
- Inactive tabs use flat style for cleaner look
- Close button is small and flat (36px width)
- New tab button with + symbol (48px width)

Event handling:
- _on_tab_clicked: Activates the clicked tab
- _on_close_clicked: Closes the clicked tab
- _on_new_tab_clicked: Opens new tab to about:startpage
- Tab reference stored directly on button widget for easy access

Benefits:
- Much simpler codebase
- No complex CSS provider per widget
- Reliable event handling
- Easy to debug and maintain
- No style context issues

All tests passing (15/15)
2026-01-09 14:36:49 +01:00
Benedikt Willi
a9d52e49c8 Improve tab bar visual integration with modern browser-like styling
Enhanced tab widget design:
- Unified tab widget with integrated close button (no visual separation)
- Close button on the right with rounded right corners
- Tab button with rounded left corners for seamless integration
- Custom CSS styling for professional appearance
- Hover effects: close button highlights in warning color
- Tab highlights as suggested-action when active

Visual improvements:
- Tabs have rounded corners (4px radius)
- Proper borders matching theme colors
- Better padding and spacing
- Flat buttons by default except active tab
- Close button marked with ✕ instead of ×
- Better visual feedback on hover

UX improvements:
- Tooltips on all buttons (tab URL, close tab, new tab)
- Small square close button (32px) for easy clicking
- Active tab uses blue suggested-action styling
- Tabs show full URL on hover
- New tab uses about:startpage instead of example.com

CSS styling:
- Theme-aware colors using @view_bg_color, @borders, @warning_color
- Proper border-radius on tab and close button
- Visual separation between tab and close button
- Hover state for better feedback

All tests passing (15/15)
2026-01-09 14:34:48 +01:00
Benedikt Willi
3bad301bcc Refactor browser chrome to use libadwaita for modern GNOME UI
Benefits of libadwaita:
- Modern, polished UI following GNOME Human Interface Guidelines
- Professional HeaderBar with proper navigation button grouping
- Better visual hierarchy and spacing
- Consistent with modern GNOME applications
- Built on GTK 4, same foundation as before

Changes:
- Replace Gtk.ApplicationWindow with Adw.ApplicationWindow
- Use Gtk.HeaderBar for professional top bar with navigation buttons
- Improve address bar presentation (placeholder text, better sizing)
- Add CSS classes for consistent styling (linked, suggested-action, toolbar)
- Better tooltip support for navigation buttons
- Add visual frame around tabs bar
- Improved status bar styling with toolbar class
- Adw.init() called during window creation

UI Improvements:
- Navigation buttons (Back/Forward/Reload) now grouped with linked styling
- Go button highlighted with suggested-action styling
- Address bar uses placeholder text instead of default value
- Better spacing and margins throughout
- More professional appearance overall

All tests passing (23/23 in core modules)
2026-01-09 14:31:55 +01:00
Benedikt Willi
fab66d1528 Implement Jinja2 templates for startpage and error pages
Features:
- Add Jinja2 template engine for page rendering
- Create startpage with Bowser branding and version info
- Create error page templates for 404, 500, and network errors
- Support for about:startpage special URL
- Custom error message support in templates
- Graceful fallback rendering if template fails
- Browser now starts with startpage when no URL provided

Templates:
- assets/pages/startpage.html - Beautiful purple gradient intro page
- assets/pages/error_404.html - Pink gradient 404 error page
- assets/pages/error_500.html - Red gradient 500 error page
- assets/pages/error_network.html - Orange gradient network error page

Code:
- src/templates.py - Template rendering utilities with Jinja2
- Updated main.py to use startpage as default
- Updated Frame.load() to handle about: URLs and render errors with templates
- Added 7 comprehensive template tests

All 62 core tests passing (excluding GTK-dependent tests)
2026-01-09 14:24:01 +01:00
Benedikt Willi
283dae295c Implement HTTP redirect following
- Support for 301, 302, 303, 307, 308 redirects
- Automatic Location header following
- Relative URL resolution for redirects
- Max redirect limit (default 10) to prevent infinite loops
- 303 (See Other) automatically changes method to GET
- 4 new unit tests for redirect functionality
- All 73 tests passing
2026-01-09 14:11:46 +01:00
Benedikt Willi
ae6fcbfab4 Add comprehensive test suite with pytest
- Add tests for URL parsing, cookies, HTML/CSS parsing
- Add tests for browser/tab management and history
- Add tests for layout and rendering components
- Configure pytest with coverage reporting
- Add test documentation and runner commands
- All 54 tests passing
2026-01-09 13:37:21 +01:00
Benedikt Willi
f1e4957e70 Initial commit: Setup Bowser educational web browser
- Added README.md with project description, building instructions, and development milestones.
- Created the project structure with directories for source code, assets, and tests.
- Implemented a basic entry point in main.py with argument parsing and logging configuration.
- Developed preliminary browser orchestration in browser.py, including tab management and navigation.
- Established a GTK-based UI framework in chrome.py, integrating key UI components including the address bar and navigation buttons.
- Incorporated HTTP request handling in http.py, with enhanced logging of requests and responses.
- Added initial assets: logo and images for browser UI.
- Configured dependencies in pyproject.toml for development and runtime environments.
- Initialized version control with uv.lock for dependency management.
2026-01-09 13:31:48 +01:00
Benedikt Willi
b0e693e50c Initial bowser project scaffold 2026-01-09 12:20:46 +01:00