Git Product home page Git Product logo

rust-minibrowser's Introduction

rust-minibrowser

mini-browser written in rust

The point of this project is to prove we can build a web-browser in just a few thousand lines of code, provided we don't care about:

  • speed
  • implementing the full specs
  • error handling
  • javascript

currently the project is less than 10k lines of Rust code, and probably a quarter of the code is unit tests.

The other point of this project is to teach myself Rust.

So far the mini-browser can:

  • parse CSS files (not the full spec yet)
  • parse HTML files (not the full spec yet)
  • layout a page with simple block and simple inline layout
  • render with the properties for display, color, background-color, border-color, padding, margin, border-width.
  • load HTML and CSS over the network or from a local file
  • load and render images (JPG and PNG)

It does not yet, but will soon:

  • handle nested inline styles (spans, em, strong, etc.)
  • handle clicking on links (a)

This project is derived from the excellent Rust browser tutorial by Matt Brubeck. The original only got as far as block layout with backgrounds. I've added inline layout with text drawing.

How it works

This project is a simplified version of what goes on in real browsers.

  • First it fetches and downloads the HTML page
  • parse the HTML page into a tree of Node objects.
  • next it scans the HTML page for any style elements which would contain CSS
  • it parses the CSS into a Stylesheet object
  • with the Node tree and Stylesheet in hand, it processes them in the style module to produce a style tree. This does all of the matching of nodes to the styles in the stylesheet.
  • next the styled tree is processed to produce a layout tree.
  • call layout on the layout tree to produce a render tree
  • draw the render tree on the screen

LOC & dependencies

The source is currently 6000 lines, which is mostly Rust (4180) code. About a quarter of that is unit tests. While the app written from scratch it does have some third party dependencies.

  • serde_json for parsing JSON config files
  • pom: parser lib used to write the CSS & HTML parsers
  • reqwest: for making network requests to HTTP servers
  • image: for parsing JPG and PNG images
  • url: for parsing URLs
  • lazy_static: for lazy init of the list of css colors
  • cgmath for matrix math
  • glium for opengl and making windows
  • glium-glyph for text rendering

rust-minibrowser's People

Contributors

joshmarinacci avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.