The WebBrowser tutorial demonstrates how to create web browser widgets, display pages from the internet, and customize the browser behavior and look using CSS. Also see WebBrowser.js on how to send commands to the browser and monitor its state using JavaScript.
To use a web browser, you need to include the header file for the class:
After we have created and initialized the main application class normally, we can instantiate the web browser widgets. We will create three widgets and set a unique CSS ID for each of them.
We use C++ just to create the browser widgets, we set everything else from a CSS file. In order to show any content, we need to specify a URL for the source attribute. Let's open Youtube on the first browser and also resize it to 1100 x 1010 pixels. This browser will have all basic features enabled, it has an address bar, favicon, back, forward and reload-buttons and a title. It also has touch, virtual keyboard and a resize button on the right-bottom corner.
Open the second browser next to the first one, and open some WebGL content there. Let's make this look like a non-interactive video, so also disable all touch and virtual keyboard just by setting input-flags to none.
We also don't want the browser frame or resize button, only the actual browser contents. Hide all extra:
Now we have a full-featured browser as well as minimal one. Let's do some more customization to the third one. Let's make the browser frame to only include favicon and page title, nothing else. Start by opening html5test.com below the previous browser:
First, hide all buttons:
Favicon and reload buttons are part of the address bar. If we would hide the whole AddressBarWidget, it would also hide the favicon. Instead, just hide the url bar inside AddressBarWidget, remove the white background and instead of taking all available space, minimize it. Now the AddressBarWidget only has the favicon image.
Next set the title to the right side of the favicon by setting depth to 10. The BrowserFrameWidget is using flexbox layout where the depth determines the widget ordering. Also set flex-grow to make sure the title will take all available space.
If you ever want to modify how touch and virtual keyboard works, you need to modify settings in WebBrowserCef::BrowserTouchOperator and WebBrowserCef::BrowserVirtualKeyboardOperator. Here are the default settings:
The browser widget itself acts like any other widget. It can have child widgets and a parent widget, it can be animated and so forth. The C++ source code for the example is shown below.