mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-09 05:14:24 +00:00
Adding Cocoa test application to test Cocoa embedding wrapper framework. This is not part of the default build.
This commit is contained in:
parent
c3626d9318
commit
4e4eb22081
2457
embedding/tests/cocoaEmbed/CocoaEmbed.pbproj/project.pbxproj
Normal file
2457
embedding/tests/cocoaEmbed/CocoaEmbed.pbproj/project.pbxproj
Normal file
File diff suppressed because it is too large
Load Diff
BIN
embedding/tests/cocoaEmbed/English.lproj/InfoPlist.strings
Normal file
BIN
embedding/tests/cocoaEmbed/English.lproj/InfoPlist.strings
Normal file
Binary file not shown.
13
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/classes.nib
generated
Normal file
13
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/classes.nib
generated
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
IBClasses = (
|
||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||
{
|
||||
ACTIONS = {load = id; };
|
||||
CLASS = MyBrowserView;
|
||||
LANGUAGE = ObjC;
|
||||
OUTLETS = {progress = id; status = id; urlbar = id; };
|
||||
SUPERCLASS = NSView;
|
||||
}
|
||||
);
|
||||
IBVersion = 1;
|
||||
}
|
24
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/info.nib
generated
Normal file
24
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/info.nib
generated
Normal file
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
|
||||
<plist version="0.9">
|
||||
<dict>
|
||||
<key>IBDocumentLocation</key>
|
||||
<string>38 70 356 240 0 0 1024 746 </string>
|
||||
<key>IBFramework Version</key>
|
||||
<string>219.0</string>
|
||||
<key>IBMainMenuLocation</key>
|
||||
<string>69 252 318 44 0 0 1024 746 </string>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5L14</string>
|
||||
<key>IBUserGuides</key>
|
||||
<dict>
|
||||
<key>Window</key>
|
||||
<dict>
|
||||
<key>guideLocations</key>
|
||||
<array/>
|
||||
<key>guidesLocked</key>
|
||||
<string>NO</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
BIN
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/objects.nib
generated
Normal file
BIN
embedding/tests/cocoaEmbed/English.lproj/MainMenu.nib/objects.nib
generated
Normal file
Binary file not shown.
30
embedding/tests/cocoaEmbed/MyBrowserView.h
Normal file
30
embedding/tests/cocoaEmbed/MyBrowserView.h
Normal file
@ -0,0 +1,30 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "NSBrowserView.h"
|
||||
|
||||
@interface MyBrowserView : NSView <NSBrowserListener, NSBrowserContainer>
|
||||
{
|
||||
IBOutlet id urlbar;
|
||||
IBOutlet id status;
|
||||
IBOutlet id progress;
|
||||
NSBrowserView* browserView;
|
||||
NSString* defaultStatus;
|
||||
NSString* loadingStatus;
|
||||
}
|
||||
- (IBAction)load:(id)sender;
|
||||
- (void)awakeFromNib;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// NSBrowserListener messages
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
|
||||
// NSBrowserContainer messages
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
- (NSBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
|
||||
@end
|
154
embedding/tests/cocoaEmbed/MyBrowserView.mm
Normal file
154
embedding/tests/cocoaEmbed/MyBrowserView.mm
Normal file
@ -0,0 +1,154 @@
|
||||
#import "MyBrowserView.h"
|
||||
|
||||
#define DOCUMENT_DONE_STRING @"Document: Done"
|
||||
#define LOADING_STRING @"Loading..."
|
||||
|
||||
@implementation MyBrowserView
|
||||
|
||||
- (IBAction)load:(id)sender
|
||||
{
|
||||
NSString* str = [urlbar stringValue];
|
||||
NSURL* url = [NSURL URLWithString:str];
|
||||
[browserView loadURI:url flags:NSLoadFlagsNone];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
browserView = [[NSBrowserView alloc] initWithFrame:bounds];
|
||||
[self addSubview:browserView];
|
||||
[browserView setContainer:self];
|
||||
[browserView addListener:self];
|
||||
|
||||
defaultStatus = NULL;
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
NSRect bounds = [self bounds];
|
||||
[browserView setFrame:bounds];
|
||||
}
|
||||
|
||||
- (void)onLoadingStarted
|
||||
{
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
defaultStatus = NULL;
|
||||
}
|
||||
|
||||
[progress setIndeterminate:YES];
|
||||
[progress startAnimation:self];
|
||||
|
||||
loadingStatus = LOADING_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
#ifdef DEBUG_vidur
|
||||
printf("Starting to load\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded
|
||||
{
|
||||
[progress setIndeterminate:YES];
|
||||
[progress stopAnimation:self];
|
||||
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
#ifdef DEBUG_vidur
|
||||
printf("Loading completed\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes
|
||||
{
|
||||
if (maxBytes > 0) {
|
||||
BOOL isIndeterminate = [progress isIndeterminate];
|
||||
if (isIndeterminate) {
|
||||
[progress setIndeterminate:NO];
|
||||
}
|
||||
double val = ((double)currentBytes / (double)maxBytes) * 100.0;
|
||||
[progress setDoubleValue:val];
|
||||
#ifdef DEBUG_vidur
|
||||
printf("Progress notification: %f%%\n", val);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocationChange:(NSURL*)url
|
||||
{
|
||||
NSString* spec = [url absoluteString];
|
||||
[urlbar setStringValue:spec];
|
||||
|
||||
#ifdef DEBUG_vidur
|
||||
const char* str = [spec cString];
|
||||
printf("Location changed to: %s\n", str);
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type
|
||||
{
|
||||
if (type == NSStatusTypeScriptDefault) {
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
}
|
||||
defaultStatus = statusString;
|
||||
if (defaultStatus) {
|
||||
[defaultStatus retain];
|
||||
}
|
||||
}
|
||||
else if (!statusString) {
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[status setStringValue:statusString];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
NSString* str = [window title];
|
||||
return str;
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
[window setTitle:title];
|
||||
}
|
||||
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
float dx = dimensions.width - bounds.size.width;
|
||||
float dy = dimensions.height - bounds.size.height;
|
||||
|
||||
NSWindow* window = [self window];
|
||||
NSRect frame = [window frame];
|
||||
frame.size.width += dx;
|
||||
frame.size.height += dy;
|
||||
|
||||
[window setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
- (NSBrowserView*)createBrowserWindow:(unsigned int)mask
|
||||
{
|
||||
// XXX not implemented
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@end
|
6
embedding/tests/cocoaEmbed/main.m
Normal file
6
embedding/tests/cocoaEmbed/main.m
Normal file
@ -0,0 +1,6 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
return NSApplicationMain(argc, argv);
|
||||
}
|
Loading…
Reference in New Issue
Block a user