/*
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
 */

#import "common.h"
#import "com_sun_glass_ui_Applet.h"

#import "GlassApplet.h"
#import "GlassMacros.h"

#import <Webkit/Webkit.h>

/*
 * Class:     com_sun_glass_ui_Applet
 * Method:    _setView
 * Signature: (JJ)V
 */
JNIEXPORT void JNICALL Java_com_sun_glass_ui_Applet__1setView
(JNIEnv *env, jobject japplet, jlong jplugin, jlong jview)
{
    GLASS_POOL_ENTER;
	//NSLog(@"ENTER Java_com_sun_glass_ui_Applet__1setView");
	{
		NSView <WebPlugInViewFactory> *sparkle = (NSView <WebPlugInViewFactory> *)jlong_to_ptr(jplugin);
		//NSLog(@"	sparkle: %@", sparkle);
		NSView *view = (NSView *)jlong_to_ptr(jview);
		//NSLog(@"	view: %@", view);
		NSView *hostView = [view superview];
		//NSLog(@"	hostView: %@", hostView);
		
		[hostView setFrameSize:[sparkle frame].size];
		[sparkle addSubview:hostView];
		
		//NSLog(@"		view frame: %.2f,%.2f %.2fx%.2f", [view frame].origin.x, [view frame].origin.y, [view frame].size.width, [view frame].size.height);
		//NSLog(@"		view bounds: %.2f,%.2f %.2fx%.2f", [view bounds].origin.x, [view bounds].origin.y, [view bounds].size.width, [view bounds].size.height);
		//NSLog(@"		hostView frame: %.2f,%.2f %.2fx%.2f", [hostView frame].origin.x, [hostView frame].origin.y, [hostView frame].size.width, [hostView frame].size.height);
		//NSLog(@"		hostView bounds: %.2f,%.2f %.2fx%.2f", [hostView bounds].origin.x, [hostView bounds].origin.y, [hostView bounds].size.width, [hostView bounds].size.height);
		//NSLog(@"		sparkle frame: %.2f,%.2f %.2fx%.2f", [sparkle frame].origin.x, [sparkle frame].origin.y, [sparkle frame].size.width, [sparkle frame].size.height);
		//NSLog(@"		sparkle bounds: %.2f,%.2f %.2fx%.2f", [sparkle bounds].origin.x, [sparkle bounds].origin.y, [sparkle bounds].size.width, [sparkle bounds].size.height);
	}
	//NSLog(@"EXIT Java_com_sun_glass_ui_Applet__1setView");
    GLASS_POOL_EXIT;
	GLASS_CHECK_EXCEPTION(env);
}
