Download presentation
Presentation is loading. Please wait.
Published byJocelyn Sutton Modified over 8 years ago
1
Object structures PicoBrowser by LC
2
PicoBrowser HtmlCanvas PicoBrowserHtmlPlugin HtmlPages User Input MIDle t TextBox A A: openPage(String url); openHtml(String html); paint(Graphics g); //Redisplay the current page. Home(); scroll(int); fetchLink(); prevHyperlink(); nextHyperlink(); // ? Er det forskjell på link og hyperlink? HtmlPlugin is an Interface that is instansiated in PicoBrowser that defines its methods. HtmlPages.Listener is an Interface declared localy in HtmlPages and instantiated in HtmlCanvas that defines the methods. Page is an Inner Class defined in HtmlPages. It does most of the rendering. HtmlPages.Listener Page Prev-list starts with homePage and has pointer currentPage OBJECT DIAGRAM PicoBrowser 20070926
3
Initializing PicoBrowser Pico Brows er Html Canva s 7 1.plugin create 2.canvas create(plugin) 3.pages create 4.listener create 5.cmdListener create 6.urlBox create 7.canvas showPage(url) Html Plugi n 2 1 Html Pages 3 List ene r 4 Com mand Listen er 5 URL TextBo x 6 HtmlCanvas is subclass of Canvas that has height and width data that is passed on to HtmlPages.
4
HtmlCanvas.showPage(url) Pico Brows er Html Canva s 1 2 Html Pages 3 List ene r 4 5 6 1. canvas.showPage(url) 2. htmlPages.openPage(url) 3. self getContentAsStream(url,..) 4. self renderPage(inputStream, url) 5. listener.setStatus(“Loading”); listener.repaint(); 6. nextPage create(prevPage, urlBase) // prevPage null initially 7. nextPage.render(inputStream, urlBase); => see separate diagram for details. 8. listener.setStatus(null); 9. self setCurrentPage(nextPage); 10. self repaint(); -> call to method in superclass Canvas, see separate diagram for details. Input Stream Thread: Page 8 9 1010 7 Html Rende rer 6b6b 7b renderHtml(..) 7c setup pointer showPage(url ) openPage(url ) self getContentAsStream(url,..) renderPage(inputStream, url) setStatus(“Loading”); repaint(); render(inputStream, urlBase) setStatus(null); setCurrentPage(..) repaint() 5b repaint() 9b repaint()
5
Page rendering – no drawing, just layout – actually build HtmlItems vector from Input Stream markup. – HtmlRenderer positions items on page, and all rendering data is stored in HtmlItem objects Page Html Rende rer 1. render(inputStream, url) HtmlRen der. Listener HtmlPag e. Listener 2. renderHtml(inputStream, url); returns items vector, which is set to variable htmlItems (9) 2b 4. treatTokens(inputStream) – holds loop to build items vector Markup Reader 4b items (Vector) of HtmlItems 3. removeAllElements() Input Stream 5+ readToken() 7+ addItem(..) Html Item Html Item Html Item 6+ 8* setStatus(“LoadImage”) * : May or may not be sent 9 HtmlItems hold position, font, color and linenumber info. They referre to either a String, an Image or a HtmlForm object.
6
HtmlCanvas repaint – the actual drawing to the screen. Reads the data in the htmlItems generated by the render process and makes paint/draw calls. Html Pages 1. repaint() as Canvas 2. paint(Grapics g) as HtmlCanvas Html Canva s 3. paint(g) Page 4. paint(g) 2. paint(g) – displays status if not null. 4. If there are HtmlItems: Loops through HtmlItems and gets data which is used when making drawing calls to the Graphics object. items (Vector) of HtmlItems Html Item Html Item Html Item 5+ paintHtmlItme(item, g)
7
HtmlFormScre en HtmlForm HtmlPages HtmlCanv as fields HtmlFormScreen maps HTML forms to MIDP forms. LoginManager reads an input stream and from that creates the Form which is pass on to the HtmlFormScreen. listener LoginManag er FaceBook UI MarkupElement remembered
8
HtmlPag es. Page HtmlRende rer HtmlForm currentForm renderHtml generates the items vector with HtmlItems holding Images, Strings and HtmlForms. An HtmlForm is created when the HtmlRenderer encounters a Form tag. HtmlForm.Items are created when HtmlRenderer calls HtmlForm.addItem(). Depending on paramters to addItem object of the various subclasses of HtmlForm.Item are created. HtmlForm, FormItems, Items, Pages and what else have you... HtmlFor m. Item HtmlFor m. Item HtmlFor m. Item HtmlIte m items vector String Imag e renderHtml(...) returns items vector HtmlForm.Items hold data relevant to the form action. Subclasses: Input, Select, Button, Label, TextArea. HtmlItem holds layout data and a pointer to content such as Image, String or Form. No subclasses of HtmlItem, but if-test in the class with branching depending on what kind of content it holds.
9
Inner Listener Interfaces: HtmlRenderer.Listener setStatus(String message); HtmlPage.Listener setStatus(String message); repaint();
10
About HtmlPlugin: What does HtmlPlugin do? It is an interface with one method: treat(Display display, String url, String contentType). An instance is created in PicoBrowser and referred to there. It is passed as parameter to HtmlCanvas when it is created. HtmlCanvas just pass it on to HtmlPages on creation. HtmlPages stores it in variable plugin. If null is passed in to constructor a DefaultPlugin is created that responds with a not implemented call in the treat-method. HtmlPages.activatePlugin(String url, String contentType) calls the plugin.treat method. activetePlugin is called in the function getContentAsStream(url, contentType) in the case where contentType != text/html.
11
Public static functions in FileUtil that are used: HttpConnection openConnection(final String url) throws IMTException; called in: HtmlForm::doFromAction and Fileutil::getFileStream InputStream getFileStream(final String url, final String authenticationToken) throws CertificateException, IMTException called in: HtmlPages::getContentAsStream, PicoBrowser.HtmlPlugin::treat and (where are these used?) FileUtil::getFile, JadFile::JadFile InputStream getRMSStream(final String name) called in FileUtil::getFileStream String resolveLink(final String link, final String pageURL) called a lot! Feed HTTP, MetaFeed, Feed, HtmlForm, htmlRenderer, FileUtil String resolveURL(final String url) called in FileUtil::resolveLink String getBaseURL(final String pageURL) called in: HtmlForm(), FileUtil::resolveLink, BrowserAccount::getTag String getHostURL(final String pageURL) called in FileUtil::resolveLink and (not in use?) FileUtil::getHost String UTF8andURLEncode(final String str) called in HtmlForm::encodeParameters String URLEncode(final String str) called in HtmlForm::encodeParameters, FileUtil::UTF8andURLEncode void setBrowserHeaders(final HttpConnection con, final String url, final String contentType) throws IMTException called in HtmlForm::doFormAction, Fileutil::getFileStream void setRequestProperty(final HttpConnection httpConnection, final String name, final String val) throws IMTException called in HTTP::post, put, delete, MetaFeed::addAtomFeedList, Feed::load, GoogleMetaFeed::GoogleClientLoginRequest, HtmlForm::doFormAction, FileUtil::openConnection, setBrowserHeaders
12
CertificateException propagation: First line = place where the exception is first cought and rethrown... InputStream FileUtil::getFileStream(final String url, final String authenticationToken) throws CertificateException, IMTException HtmlPages::getContentAsStream – catches exception and checks proxy settings either it then calls itself again or rethrought the certificate exception. run-block in new thread in HtmlPages::openPage cought here and then HtmlPages.Listener::error is called with ITMError with ITM ErrorCode CERTICIATE HTMLCanvas creates the listener in its constructor. P.t. Implementation is an Alert with error info. Is this the right place to do it? The HtmlCanvas is created in the PicoBrowser::startApp function. The Canvas takes user input and asks canvas to paint. PicoBrowser.HtmlPlugin::treat HtmlForm::activatePlugin – catches this exception and re-throughs it. HtmlPages::getContentsAsStream – as above
13
List of displayed pages – as viewed when working with PicoBrowser related classes: HtmlPages has a list of pages, ie HtmlPages.Page are elements in a linked list holding: Page prev; Vaious places there are prev-values referring to Display objects: common.Alerts.ErrorAlert, common.JadFile.DialogScreen, vaious places in MicroBlogger picobrowser.HtmlCanvas, picobrowser.MediaPlayer Set as follows: prev = MIDLetContext.setCurrent(this); There are two ways to change what is displayed tot he user: Change MIDLet display object Change variables in HtmlCanvas.htmlPages and repaint the canvas. Alerts: create std. Alerts and calls “MIDLet.display.”setCurrent(alert); Get message out and a “done” button – when pushed get back to last screen. I guess Midlet.display does the magic with resetting current to the display before the alert.
14
Display change principles (suggestions for...): The user observe changes in what is displayed. This can be new pages and forms or error messages and simple dialog boxes with questions. Problem today: All over the place the global display setting is changed to display stuff to the user. This is done in threads – so there may be several threads changing the global display settings at any one time. NOT GOOD! Suggested principle to avoid this: The MIDLet (or an object it delegats to) is responcible for displaying stuff to the user. To change the display an object may: 1. change the data displayed by the repaint() sequence. 2. throw an exception that is sent back to the MIDLet (can only be done in main thread) 3. sends a message to an error handling object under control of the MIDlet that can report back to the MIDLet (typically done in threads). The MIDLet itself is responcible for showing error messages to the user. No other object may display things on the screen by changing the global display settings of the MIDlet. The MIDLet can deleagte to another object to show error messages, but then its only this object that can do that! Question: how to handle multiple error messages from several threads?
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.