/*
* Copyright � 2008 Telenor R&I, iLabs. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* For questions regarding the source code, please visit the project's
* website at https://ilabsmobiletoolbox.dev.java.net, use the web forum at
* https://ilabsmobiletoolbox.dev.java.net/servlets/ForumMessageList?forumID=2884
* or consider joining one of the mailing lists (see project's website
* for details). You may also get the latest releases and report issues
* at our sourceforge website http://sourceforge.net/projects/ilabsmobiletool.
*
* For questions regarding this license, please contact iLabs Telenor R&I,
* license@ilabs.mobi, Snar�yveien 30, 1331 Fornebu, Norway or visit
* http://www.iLabs.no for additional information regarding licensing.
*/
package mobi.ilabs.gui.html.parser;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mobi.ilabs.errlog.IMTErrorCodes;
import mobi.ilabs.gui.html.items.HtmlItem;
import mobi.ilabs.gui.html.items.ImageItem;
import mobi.ilabs.gui.html.items.InputItem;
import mobi.ilabs.gui.html.items.LineItem;
import mobi.ilabs.gui.html.items.LinkItem;
import mobi.ilabs.gui.html.items.SelectItem;
import mobi.ilabs.gui.Style;
import mobi.ilabs.html.URLParsing;
import mobi.ilabs.gui.utils.Color;
import mobi.ilabs.gui.utils.GetImage;
import mobi.ilabs.errlog.IMTException;
import mobi.ilabs.gui.html.Credentials;
import mobi.ilabs.gui.html.FontAdjuster;
import mobi.ilabs.gui.html.HtmlForm;
import mobi.ilabs.gui.html.HtmlDocument;
import mobi.ilabs.gui.html.HtmlTags;
import mobi.ilabs.gui.html.HtmlViewListener;
import mobi.ilabs.gui.html.IItemListener;
import mobi.ilabs.gui.html.PasswordManager;
import mobi.ilabs.gui.html.css.CssManager;
import mobi.ilabs.gui.html.css.CssClass;
import mobi.ilabs.gui.html.css.CssTags;
import mobi.ilabs.gui.html.css.HtmlTagWithCss;
import mobi.ilabs.gui.html.items.IFormItem;
import mobi.ilabs.gui.html.plugin.HtmlPluginItem;
import mobi.ilabs.gui.html.items.LinkStyle;
import mobi.ilabs.gui.html.items.HtmlStringItem;
import mobi.ilabs.gui.html.items.TextArea;
import mobi.ilabs.gui.html.plugin.PluginFactory;
import mobi.ilabs.gui.html.plugin.PluginFactoryProvider;
import mobi.ilabs.util.StringUtil;
import mobi.ilabs.util.Tokenizer;
public class HtmlRenderer implements ITagListener {
private HtmlTagWithCss mCurrentTagStyle;
//private LinkStyle mLinkStyle;
private HtmlViewListener mViewListener;
/**The listener who will receive events generated by the HtmlItems*/
private IItemListener mItemListener;
/**
* The document we are rendering.
*/
private HtmlDocument mDocument;
/**
* The css styles defined for the htmlpage we are rendering..
*/
private CssManager mCssStyles;
/**
* The parser we are using for parsing HTML.
*/
HtmlParser mHtmlParser;
/**
* The canvas width in pixels.
*/
private int mCanvasWidth;
/**
* The canvas height in pixels.
*/
private int mCanvasHeight;
/**
* XXX
*/
//private int mCurrentLine;
private int mScreenNr;
/**
* Link information
*/
private String mCurrentLink;
private String mCurrentLinkName;
private String mCurrentLinkId;
private String mCurrentLinkOnClick;
private String mCurrentId; //used for assigning id to text between tags...
/**
* if true, center content.
*/
//private boolean mCenter;
/**
* The x position (in pixels) where a new html item will be placed.
*/
//private int mXpos;
/**
* The y position (in pixels) where a new html item will be placed.
*/
//private int mYpos;
/**
* The current style used to render text.
*/
//private Style mCurrentStyle;
/**
* XXX Used for some hairy color juggling inside onFontTag.
*/
private int mPrevColor;
private HtmlForm mCurrentForm;
private SelectItem mCurrentSelectItem;
private HtmlTag mCurrentOptionTag;
private TextArea mCurrentTextAreaTag;
private HtmlItem mCurrentDivItem;
private HtmlItem mCurrentSpanItem;
private RenderContext mRc;
/**
* maximum height of item on current line.
*/
private int mMaxItemHeight;
/**
* An object that will help us get fonts for various
* headings, and togglable italics and boldface.
*/
private FontAdjuster mFonts;
/**
* Creates a new instance of HtmlRenderer.
*
*
* @param view the view to render into. SBFIXME
* @param width the width we are allowed to render into
* @param height the height we are allowed to render into.
*/
public HtmlRenderer(final HtmlViewListener htmlViewListener, final IItemListener itemListener, final int width, final int height) {
mViewListener = htmlViewListener;
mItemListener = itemListener;
mCanvasWidth = width;
mCanvasHeight = height;
mFonts = new FontAdjuster();
}
/**
* stops the rendering as soon as possible.
*/
public void abort() {
if(mHtmlParser != null) {
mHtmlParser.abort();
}
}
/**
* Main public method that converts an inputStream with HTML to a vector of
* HtmlItem objects.
*
* @param inputStream
* The stream with HTML code.
* @param inPageURL
* The URL where the HTML code comes from.
* @param inListener
* The object that wants status change messages.
* @return A vector of Html Items that holds rendering data to be used when
* painting the page.
* @throws IMTException
* Thrown if there's a problem reading the inputStream
*/
public void renderHTML(final HtmlDocument document, final InputStream inputStream) throws IMTException {
if(mCanvasHeight <=0 || mCanvasWidth <=0) {
throw new IMTException(IMTErrorCodes.INVALID_VIEW_SIZE, "", this, "renderHTML", "Invalid view size");
}
mHtmlParser = new HtmlParser(this);
mDocument = document;
mCssStyles = null;
mRc = new RenderContext();
mRc.setMaxWidth(mCanvasWidth);
Style initialStyle = new Style(Color.black, Color.white, mFonts.getCurrentFont());
LinkStyle linkStyle = new LinkStyle(Color.linkColor, Color.white, Color.linkColor, mFonts.getCurrentFont());
initialStyle.mTransparent = true; //most html elements should be transparent..
mRc.setStyle(initialStyle);
mRc.setLinkStyle(linkStyle);
//set up default css style
mCurrentTagStyle = new HtmlTagWithCss(HtmlTags.BODY);
mCurrentTagStyle.addAttribute(CssTags.background_color, Color.white);
mCurrentTagStyle.addAttribute(CssTags.color, Color.black);
mPrevColor = Color.black;
mMaxItemHeight = 0;
mScreenNr = 0;
mFonts.reset();
mHtmlParser.
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共288个文件
class:147个
java:134个
jad:2个
这是我从ilabs mobile tool中提取出来的OpenMiniBroswer浏览器的源代码,总体上不是很好,一些功能还没有实现,但可以解析CSS等,适合学习。 本来我是要把它封装一个电影浏览软件的,但弄了一下就没有继续弄了,所以工程文件名为SuperMovie1,想改的话大家改一下就可以了。这是一个Eclipse下的工程,解压缩后放到工作区里面,在eclipse里面刷新一下就可以看到工程了,可以直接编译运行,上WAP网站。应该不会有什么问题。 我以前也是一直在网上找j2me的浏览器源码,但感觉不好找,大部分也不是很好,大家喜欢的就下巴,可以作为学习浏览器原理和超文本解析的材料。
资源推荐
资源详情
资源评论
收起资源包目录
手机java浏览器源码 (288个子文件)
HtmlRenderer.class 22KB
HtmlView.class 13KB
HtmlParser.class 12KB
HtmlAudioItem.class 10KB
MarkupElement.class 10KB
WebView.class 10KB
InputItem.class 9KB
HtmlCameraItem.class 7KB
HtmlForm.class 7KB
MarkupReader.class 7KB
CssParser.class 6KB
WindowView.class 6KB
CameraItem.class 6KB
TextItem.class 6KB
TabTopView.class 6KB
SimpleList.class 6KB
HtmlStringItem.class 6KB
HtmlDocument.class 6KB
CssClass.class 5KB
HtmlItem.class 5KB
TabView.class 5KB
MenuView.class 5KB
CookieStore.class 5KB
GetFileStream.class 5KB
CameraController.class 4KB
View.class 4KB
UTF8InputScanner.class 4KB
WebView$2.class 4KB
PasswordManager.class 4KB
SelectItem.class 4KB
HtmlViewListener.class 4KB
GraphicsItem.class 4KB
HtmlCharEncoding.class 4KB
MenuController.class 4KB
TabPanelList.class 4KB
WebViewListener.class 4KB
UTF8SensitiveInputStreamReader.class 4KB
HttpSupport.class 4KB
GetImage.class 4KB
ListView.class 4KB
IMTLogger.class 4KB
HtmlAudioItem$1.class 3KB
HtmlTag.class 3KB
EntityHandling.class 3KB
Style.class 3KB
RenderContext.class 3KB
TextArea.class 3KB
StringUtil.class 3KB
PopupMenu.class 3KB
AbstractIlabsMIDlet.class 3KB
BaseCanvas.class 3KB
MarkupToken.class 3KB
Base64.class 3KB
ImageItem.class 3KB
URLParsing.class 3KB
Clock.class 3KB
IMTError.class 3KB
WebView$1.class 3KB
EnterURLAction.class 3KB
HtmlAudioItem$3.class 3KB
ActionListView.class 2KB
HtmlTags.class 2KB
CssManager.class 2KB
CameraView.class 2KB
CameraItem$1.class 2KB
ViewCanvas.class 2KB
FormItem.class 2KB
HtmlView$1.class 2KB
MenuBar.class 2KB
IMTException.class 2KB
LinkItem.class 2KB
HtmlAudioItem$2.class 2KB
TextItemAction.class 2KB
HtmlView$2.class 2KB
CssTags.class 2KB
WindowController.class 2KB
Utf8StreamReader.class 2KB
Controller.class 2KB
IMTErrorCodes.class 2KB
TitleBar.class 2KB
TabController.class 2KB
URLEncode.class 2KB
DisplayChangeAction.class 2KB
HtmlPluginItem.class 2KB
SMSSender$1.class 2KB
FontAdjuster.class 2KB
HtmlViewController.class 2KB
Scheduler.class 2KB
SmsHandler.class 2KB
CameraController$1.class 2KB
TextView.class 2KB
WidgerTags.class 1KB
Icon.class 1KB
TabTopController.class 1KB
Color.class 1KB
CameraPluginFactory.class 1KB
AudioPluginFactory.class 1KB
ListItem.class 1KB
Action.class 1KB
LineItem.class 1KB
共 288 条
- 1
- 2
- 3
greenlcat
- 粉丝: 7
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页