PDA

View Full Version : Carbon's HTML rendering library not showing images




syl22-00
May 30, 2011, 09:18 PM
Hi,

I am working on porting an old program that uses an embedded browser using the HTML Rendering library from Carbon. I am migrating it from codewarrior to Xcode, using the 10.4 SDK. The HTML page is displayed correctly, including links but images don't show up. I can see the alt content, and dimensions are properly set with the width and height fields.

I am doing the initialization with:

OSErr err = HRNewReference(m_HRRef, kHRRendererHTML32Type,
GetWindowPort((WindowRef) m_pWindow));

And then I open my local HTML file with:

err = HRGoToFSRef(m_HRRef, &f, false, false);

My images are also stored locally but just do not appear, it was working fine previously on my ppc only codewarrior compilation.

I tried with web pages on Internet with HRGoToURL, and I tried replacing my pictures src fields with http:// or file:// links to images, in jpg, gif and png, always with the same result.

Are you aware of any issue like this? I know I could, and probably should, migrate to WebKit but that would me more involved.

Sylvain



kainjow
May 30, 2011, 09:27 PM
Those functions were deprecated in 10.4, so I wouldn't be surprised to hear it's not working in 10.6.

Same thing for QuickDraw, and I've seen issues with that on 10.6.

I know I could, and probably should, migrate to WebKit but that would me more involved.

Accessing the WebKit From Carbon Applications (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/CarbonApps.html)

Looks pretty simple to me :)

syl22-00
May 31, 2011, 02:05 AM
Accessing the WebKit From Carbon Applications (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/DisplayWebContent/Tasks/CarbonApps.html)

Looks pretty simple to me :)

Thank you.

Yes it does not look too complicated to me, however, I can't get the Cocoa view in my Carbon app. WebView and WebFrame are both defined in WebView.h and I am getting plenty of conflicts when I try to include that file. I am reading about Cocoa-Carbon integration, but getting either deprecated material or things relevant to the 10.5+ SDK, and I am using the 10.4 SDK (I have to).

kainjow
May 31, 2011, 12:58 PM
If you're using code from the sample LoadURL function, that needs to be compiled in a separate Objective-C file (with .m extension).

syl22-00
Jun 1, 2011, 05:29 AM
If you're using code from the sample LoadURL function, that needs to be compiled in a separate Objective-C file (with .m extension).

Thank you Kainjow for your help. I have never used Objective-C before.

So I added a new empty file to my project, called loadurl.m, added the code inside and tried to import a few header files (such as WebKit/WebView.h), I always get errors related to objc.h.

I found that gcc is called with -x c++, but File Type is set to sourcecode.c.obj. Am I doing something wrong?

Thanks a lot for your patience

Sylvain

kainjow
Jun 1, 2011, 09:07 PM
Where do the errors originate? Usually if errors are coming from within a framework's header, the build window will show the file in your code where the #include/#import originated.

Can you post the code for the .h/.m files? Which version of Xcode are you using?

syl22-00
Jun 3, 2011, 04:28 AM
Where do the errors originate? Usually if errors are coming from within a framework's header, the build window will show the file in your code where the #include/#import originated.

Can you post the code for the .h/.m files? Which version of Xcode are you using?

I found that in my project, I was forcing files to be compiled in C++, that's why it could not compile my objective-c file although is was sourcecode-objc type. The problem is that when I changed my project to compile files depending on their type, I am getting thousand of errors in my own code (or the code I should make my own). It might be because my .h files are all set as c header files, I am trying to change them as c++ header files without much success so far...

Madd the Sane
Jun 7, 2011, 01:12 PM
If you were compiling the source code using C++, compile them using Objective C++. That might help.

syl22-00
Jun 10, 2011, 05:42 AM
Thank you Madd and Kainjow,

I finally managed to have things working... well I can't see the web page yet, but it is just a matter of getting to know how to use the webkit API as the app compiles and links successfully.

In case it can help other people, here were the issues:

. My app was set to be compiled in C++, so even .m files would be compiled in c++. After changing "Compile source as" from "C++" to "according to file type", I would then have thousand of error because of my precompiled headers being compiled in C. The solution was to include the header files inside a "#if defined __cplusplus". Apparently the reason is that the compiler will attempt to compile the precompiled header both in C and C++, and you don't want them to be compiled in C.

. In the header file for the loadURL function, you need a extern "C" directive if compiled in C++ because C++ would mangle the names, not objective C.

So here are the .h and .m files:

loadurl.h:
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C extern
#import <Carbon/Carbon.h>
#import <webkit/WebView.h>
#endif

EXTERN_C void LoadURL( HIViewRef inView, CFURLRef inURL );

loadurl.m:
#import <webkit/webkit.h>
#import <webkit/HIWebView.h>
#import "loadurl.h"

void LoadURL( HIViewRef inView, CFURLRef inURL )
{
WebView* nativeView;
NSURLRequest* request;
WebFrame* mainFrame;

nativeView = HIWebViewGetWebView( inView ); // get the Cocoa view

// Use Objective-C calls to load the actual content
request = [NSURLRequest requestWithURL:(NSURL*)inURL];
mainFrame = [nativeView mainFrame];
[mainFrame loadRequest:request];
}