Web Sprocket(s) | Lesson 3 - Crafting a window (Part II)
In the previous lesson we have discussed how to create a platform independent Window class and expand it with platform specific (Linux) behaviors. If you missed it, you can read it here.
In this lesson we will connect our window to the application.
First of all we should create our own BrowserMainParts class which will have an important role in the whole browser loop. This will handle all main functionalities for initialization part of the browser. There are several essential methods in this class which have to be implemented. At certain steps - before and after some events - these methods are called from the BrowserMainLoop class. The steps are the followings:
According to these three steps, we will override the following methods in our BrowserMainParts subclass (browser/browser_main_parts.cc).
In PreEarlyInitialization, we initialize the UI input method.
In PreMainMessageLoopRun we initialize and create the window. The window needs a running message-loop to work properly and to be able to deal with the interactions.
In PostMainMessageLoopRun we deinitialize and destroy the window.
At this point we haven’t finished yet. The BrowserMainParts should be connected to the rest of our application.
The next thing what we have to do is to add our own ContentBrowserClient class. The purpose of this class is to provide an API to the embedder in order to participate in the browser logic.
For now we can have only one method which instantiates the browser main parts with specific parameters.
Next, we will add our MainDelegate implementation. You should know that the ContentMain needs a MainDelegate instance, which is passed through its constructor. In the previous tutorial this parameter was set to NULL. Now after implementing MainDelegate we will be able to use an instance of our class instead.
With this code you make MainDelegate responsible for creating the ContentBrowserClient.
Only one thing is remaining. Let’s implement the BasicStartupComplete which is called after the basic startup actions have been completed.
In this method we should initialize the resource bundle. For now a dummy path is used here, because we don’t have any resource files yet. We will replace this in a later lesson.
That’s it! Now, you should be able to see a blank window.
Next time, we will look at some of the Content API’s Contexts.
Stay tuned for the upcoming lesson!
The lesson 3 repository can be found here.