PDA

View Full Version : How to use WebView to partly show website content (like Web Clip + Dashboard)




spotlite
Feb 18, 2008, 12:30 PM
Hello everyone,

I am using WebView on an application I am developing. A small section of the application is a WebView object. I am having the WebView load a URL, and that is working fine, and as you would expect, it's showing the top-left corner of this website. I want to focus on a very specific area of this website, without having to use scroll bars to move. Very similar to what Web Clip does for Dashboard, but built into my native app. I'm using Xcode + IB + Cocoa.

Is this possible? What would be the best way of doing it? I've looked at the documentation, but have had no luck.

Thank you in advance.



robbieduncan
Feb 18, 2008, 01:18 PM
Put the webview in a NSClipView (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html)?

spotlite
Feb 18, 2008, 10:13 PM
Put the webview in a NSClipView (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html)?

I don't understand how you would use a NSClip to actually have the WebView show something other than the top-left most corner of the website. I want to have the origin be something else on the site, without the need to have scroll bars. If it's possibly to do this by putting it in a NSClip, could you please elaborate on how to do it? Thank you.

robbieduncan
Feb 19, 2008, 02:37 AM
NSClipView does not display scrollbars: that's what an NSScrollView does. NSScrollView uses and embeded NSClipView to clip the whole view for display. This is basically what you want to do.

So I'd:

1) Create an NSClipView (of the size you want)
2) Set the document (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSClipView/setDocumentView:) view to your web view
3) Scroll to point (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSClipView/scrollToPoint:) to set the displayed section of the view to what you want.

spotlite
Feb 19, 2008, 07:48 AM
NSClipView does not display scrollbars: that's what an NSScrollView does. NSScrollView uses and embeded NSClipView to clip the whole view for display. This is basically what you want to do.

So I'd:

1) Create an NSClipView (of the size you want)
2) Set the document (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSClipView/setDocumentView:) view to your web view
3) Scroll to point (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSClipView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSClipView/scrollToPoint:) to set the displayed section of the view to what you want.

Got it! Thanks or your help.