📄 webcorebridge.cpp
字号:
iPart->setShowsFirstResponder(flag);
}
*/
EXPORT_C
void CWebCoreBridge::SetShouldCreateRenderers(TBool aCreateRenderers)
{
iShouldCreateRenderers = aCreateRenderers;
}
EXPORT_C
TBool CWebCoreBridge::ShouldCreateRenderers()
{
return iShouldCreateRenderers;
}
EXPORT_C
TInt CWebCoreBridge::NumPendingOrLoadingRequests()
{
DocumentImpl *doc = iPart->xmlDocImpl();
if (doc)
return KWQNumberOfPendingOrLoadingRequests (doc->docLoader());
return 0;
}
EXPORT_C
TRgb CWebCoreBridge::BodyBackgroundColor()
{
return iPart->BodyBackgroundColor();
}
EXPORT_C
TRgb CWebCoreBridge::SelectionColor()
{
RenderCanvas* root = static_cast<khtml::RenderCanvas *>(iPart->xmlDocImpl()->renderer());
if (root) {
RenderStyle *pseudoStyle = root->getPseudoStyle(RenderStyle::SELECTION);
if (pseudoStyle && pseudoStyle->backgroundColor().isValid()) {
return pseudoStyle->backgroundColor().Rgb();
}
}
return TRgb(0xff,0,0);
// ### NOT IMPLEMENTED selection colors
//return iPart->usesInactiveTextBackgroundColor() ? [NSColor secondarySelectedControlColor] : [NSColor selectedTextBackgroundColor];
}
EXPORT_C
void CWebCoreBridge::AdjustViewSize()
{
KHTMLView *view = iPart->view();
if (view)
view->adjustViewSize();
}
EXPORT_C void CWebCoreBridge::ExecuteScript(const TDesC& aScriptText)
{
NodeImpl* node = iPart->xmlDocImpl()->focusNode();
if (iPart && node)
iPart->executeScript(node,QString::FromDes(aScriptText));
}
// ### NOT IMPLEMENTED accessibility
/*
-(id)accessibilityTree
{
KWQAccObjectCache::enableAccessibility();
if (!iPart || !iPart->xmlDocImpl()) return nil;
RenderCanvas* root = static_cast<khtml::RenderCanvas *>(iPart->xmlDocImpl()->renderer());
if (!root) return nil;
return iPart->xmlDocImpl()->getOrCreateAccObjectCache()->accObject(root);
}
*/
EXPORT_C
void CWebCoreBridge::SetDrawsBackground(TBool aDrawsBackground)
{
if (iPart && iPart->view())
iPart->view()->setTransparent(!aDrawsBackground);
}
EXPORT_C HBufC* CWebCoreBridge::ResolveUrlL(const TDesC &aBaseUrl, const TDesC &aResUrl)
{
QString resource = QString::FromDes(aResUrl);
KURL baseUrl(aBaseUrl);
KURL url(baseUrl,resource,NULL);
QString completeUrl = url.url();
HBufC* newUrl = HBufC::NewL(completeUrl.length() + 1);
TPtr newUrlPtr = newUrl->Des();
newUrlPtr.Copy(completeUrl.Des());
return newUrl;
}
EXPORT_C
CArrayFixFlat<TWebCoreImageCarrier>* CWebCoreBridge::ImagesInRect(TBool visibleOnly)
{
if(!iPart || !iPart->xmlDocImpl() || !iPart->xmlDocImpl()->renderer())
{
return NULL;
}
KHTMLView *view = iPart->view();
QPtrList<khtml::BoxInfo> *boxInfoList = new QPtrList<khtml::BoxInfo>;
int contentsx = view->contentsX(); // view port x position
int contentsy = view->contentsY(); // view port y position
int contentsW = view->contentsWidth(); // width of the content
int contentsH = view->contentsHeight(); // height of the content
int visibleW = view->visibleWidth(); // width of the display
int visibleH = view->visibleHeight(); // height of the display
if (visibleOnly) { // get the rectangle for the visible portion only
QRect viewrect(contentsx, contentsy, visibleW, visibleH);
iPart->xmlDocImpl()->renderer()->getRenderersInRect(*boxInfoList,0,0,viewrect);
}
else {
QRect rt(0,0,contentsW,contentsH);
iPart->xmlDocImpl()->renderer()->getRenderersInRect(*boxInfoList,0,0,rt);
}
//Initialise the WebCoreImageCarrier
CArrayFixFlat<TWebCoreImageCarrier>* imageList =
new CArrayFixFlat<TWebCoreImageCarrier>(10);
for(khtml::BoxInfo *sel = boxInfoList->first();sel;sel = boxInfoList->next())
{
if (sel->renderObject && sel->renderObject->isImage()) {
NodeImpl* node = sel->renderObject->node();
RenderImage *r = static_cast<RenderImage *>(node->renderer());
QPixmap p = r->pixmap();
khtml::CachedImage* ci = r->getImage();
if( !ci ) continue;
TPtrC8 rawData = ci->rawData();
// Check if there is data in the image buffer.
// Broken links do not have data in them
if (rawData.Length() == 0) {
// No data present, so continue
continue;
}
// Check if this image has been retrieved before.
// Image pointer should be the same for similar images
TBool imageExist = false;
for (int i=0; i<imageList->Count();i++)
{
TWebCoreImageCarrier wcImage = imageList->At(i);
if ( rawData == wcImage.RawData()) {
imageExist = true;
break;
}
}
if ( imageExist ) {// do not add to the imageList
continue;
}
// Get the alt text
DOMString alt;
ElementImpl *i = static_cast<ElementImpl*>(node);
if (idFromNode(i) == ID_IMG)
alt = static_cast<HTMLImageElementImpl *>(i)->altText();
// Check if alttext is "Nokia" or "No_save".
// Then do not add the image to the list
const char* str1 = "Nokia";
const char* str2 = "No_Save";
if ( !strcasecmp( alt, str1) || !strcasecmp( alt, str2) )
continue;
DOM::DOMString url = ci->url();
TPtrC ptrUrl((TUint16*)url.unicode(), url.length());
TPtrC altPtr((TUint16*)alt.unicode(), alt.length());
TWebCoreImageCarrier t (rawData,
ptrUrl,
altPtr,
p.mime().Des(),
p.image() ) ;
imageList->AppendL( t );
}
}
boxInfoList->clear();
delete boxInfoList;
return imageList;
}
EXPORT_C
TInt CWebCoreBridge::ImageCount(TBool visibleOnly)
{
// This function is called sometimes whenthe doucment has not rendered.
if(!iPart || !iPart->xmlDocImpl() || !iPart->xmlDocImpl()->renderer())
{
return 0;
}
// Get the renderers for rectangle.
// Get only the image renderers and get the count
// no need for raw data here.
KHTMLView *view = iPart->view();
QPtrList<khtml::BoxInfo> *boxInfoList = new QPtrList<khtml::BoxInfo>;
int contentsx = view->contentsX(); // view port x position
int contentsy = view->contentsY(); // view port y position
int contentsW = view->contentsWidth(); // width of the content
int contentsH = view->contentsHeight(); // height of the content
int visibleW = view->visibleWidth(); // width of the display
int visibleH = view->visibleHeight(); // height of the display
if (visibleOnly) {// get the rectangle for the visible portion only
QRect viewrect(contentsx, contentsy, visibleW, visibleH);
iPart->xmlDocImpl()->renderer()->getRenderersInRect(*boxInfoList,0,0,viewrect);
}
else {
QRect rt(0,0,contentsW,contentsH);
iPart->xmlDocImpl()->renderer()->getRenderersInRect(*boxInfoList,0,0,rt);
}
int numImages = 0;
for(khtml::BoxInfo *sel = boxInfoList->first();sel;sel = boxInfoList->next())
{
if (sel->renderObject && sel->renderObject->isImage()) {
// Check if the images have data in them.
// Sometimes broken links do not have data in them.
// This should not be included
RenderImage *r = static_cast<RenderImage *>(sel->renderObject);
khtml::CachedImage* ci = r->getImage();
if ( ci && ( ci->rawData().Length() > 0 ) ) {
// Get the alt text
DOMString alt;
ElementImpl *i = static_cast<ElementImpl*>(sel->renderObject->node());
if ( i && ( idFromNode(i) == ID_IMG ) )
alt = static_cast<HTMLImageElementImpl *>(i)->altText();
// Check if alttext is "Nokia" or "No_save".
// Then do not count that image
const char* str1 = "Nokia";
const char* str2 = "No_Save";
if ( !strcasecmp( alt, str1) || !strcasecmp( alt, str2) )
continue;
numImages++;
}
}
}
boxInfoList->clear();
delete boxInfoList;
return numImages;
}
EXPORT_C
void CWebCoreBridge::AddToContacts(TPoint& aPoint)
{
if(iPart->xmlDocImpl())
{
// get the current focus node
RenderObject::NodeInfo renderInfo(true, false);
iPart->renderer()->layer()->hitTest(renderInfo, aPoint.iX, aPoint.iY);
NodeImpl *node = renderInfo.innerNode();
NodeImpl *focusNode = node;
for (; focusNode ; focusNode = focusNode->parentNode()) {
if (focusNode->isElementNode() && focusNode->isFocusable()) {
break;
}
}
// is element node
if(focusNode && focusNode->id() == ID_A )
{
ElementImpl *e = static_cast<ElementImpl *>(focusNode);
QString tel;
QString email;
QString telbook;
QString attr = e->getAttribute(ATTR_HREF).string();
if (!attr.isNull() && !attr.isEmpty() )
{
if ( attr.startsWith( KTel ) )
tel = attr.mid(4);
else if( attr.startsWith(KWtaiMC) )
tel = attr.mid(13);
else if( attr.startsWith(KWtaiAP) )
tel = attr.mid(13);
else if( attr.startsWith(KWtaiSD) )
tel = attr.mid(13);
else if ( attr.startsWith( KMailto ) )
{
email = attr.mid(7);
// Find just the email address
int i = email.find('?');
if (i > 0 )
email = email.left(i).stripWhiteSpace();
}
}
attr = e->getAttribute(ATTR_CTI).string();
if (!attr.isNull() && !attr.isEmpty() )
tel = attr;
attr = e->getAttribute(ATTR_EMAIL).string();
if (!attr.isNull() && !attr.isEmpty() )
email = attr;
attr = e->getAttribute(ATTR_TELBOOK).string();
if (!attr.isNull() && !attr.isEmpty() )
telbook = attr;
// Save to phone book
QString url;
QString makeCallUrlPrefix("wtai://wp/ap;");
QChar numberNameSeparator = ';';
int len = makeCallUrlPrefix.length() + 3; // NULL terminator and ';' separators
len += tel.length() + telbook.length() + email.length();
url.reserve(len);
url.append(makeCallUrlPrefix);
url.append(tel);
url.append(numberNameSeparator);
url.append(telbook);
url.append(numberNameSeparator);
url.append(email);
Client().LoadUrl(url.Des(),
KNullDesC, // referrer
EFalse, // reload
ETrue, //userGesture
KNullDesC, //target
EEventNull //triggeringEvent
);
}
}
}
EXPORT_C
CArrayPtr<CWebCorePageDataItem>* CWebCoreBridge::GetPageDataL(TInt aTypeMask)
{
DOM::Document document = iPart->document();
khtml::DocLoader* loader = NULL;
if ( iPart->xmlDocImpl() )
{
loader = iPart->xmlDocImpl()->docLoader();
}
User::LeaveIfNull( loader ); // if loader is null, we don't have a page loaded
CArrayPtr<CWebCorePageDataItem>* itemArray =
new(ELeave) CArrayPtrFlat<CWebCorePageDataItem>(10);
CleanupStack::PushL( itemArray );
CWebCorePageDataItem* dataItem = NULL;
// get page markup document if requested
if(aTypeMask & CWebCorePageDataItem::EMarkup)
{
QString pageMarkupQ = document.toHTML();
dataItem = CWebCorePageDataItem::NewL(CWebCorePageDataItem::EMarkup);
CleanupStack::PushL( dataItem );
dataItem->SetUrlL(iPart->requestedURLString().Des());
dataItem->SetContentTypeL(_L("text/html"));
dataItem->SetCharsetL(_L("ucs-2"));
dataItem->SetDataL( pageMarkupQ.Des() );
itemArray->AppendL(dataItem);
CleanupStack::Pop( dataItem );
}
// get stylesheet documents if requested
if(aTypeMask & CWebCorePageDataItem::EStylesheet)
{
DOM::StyleSheetList sheetList = document.styleSheets();
khtml::CachedCSSStyleSheet* kStyleSheet = NULL;
QString charset("");
for(int m=0; m<sheetList.length(); m++)
{
DOM::StyleSheet dStylesheet = sheetList.item(m);
DOM::DOMString sheetUrl = dStylesheet.href();
if(!sheetUrl.isNull())
{
kStyleSheet = loader->requestStyleSheet(sheetUrl, charset);
dataItem = CWebCorePageDataItem::NewL(CWebCorePageDataItem::EStylesheet);
CleanupStack::PushL( dataItem );
dataItem->SetUrlL(sheetUrl.string().Des());
dataItem->SetContentTypeL(dStylesheet.type().string().Des());
//Charset is required for saved pages.
dataItem->SetCharsetL(_L("ucs-2"));
dataItem->SetDataL(kStyleSheet->sheet().string().Des());
itemArray->AppendL(dataItem );
CleanupStack::Pop( dataItem );
}
}
}
// get script documents if requested
if(aTypeMask & CWebCorePageDataItem::EScript)
{
DOMString scriptStr("script");
DOMString srcStr("src");
//DOMString typeStr("type");
QString charset("");
khtml::CachedScript* kScript = NULL;
DOM::NodeList scriptNodes = document.getElementsByTagName(scriptStr);
for(int n=0; n<scriptNodes.length(); n++)
{
DOM::NamedNodeMap attribs = scriptNodes.item(n).attributes();
DOM::Node srcAttr = attribs.getNamedItem(srcStr);
if(!srcAttr.isNull())
{
DOMString scriptUrl = srcAttr.nodeValue();
kScript = loader->requestScript(scriptUrl, charset);
dataItem = CWebCorePageDataItem::NewL(CWebCorePageDataItem::EScript);
CleanupStack::PushL( dataItem );
dataItem->SetUrlL(scriptUrl.string().Des());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -