[webkit-help] npapi resize problems
Tim Prepscius
timprepscius at gmail.com
Tue May 25 04:10:53 PDT 2010
Greetings again,
So now I have a different but related problem.
Now that plugin placement is correct all of the time, I'm trying to
get the clipping correct. And it isn't, and in a similarly
frustrating way.
So in the partial examples I've found strewn about the web, it seems
like you should be able to use the clipping rectangle as given, and
apply it directly (will after creating a region) to the
AGL_CLIP_REGION
like about so:
RgnHandle rgn = ::NewRgn();
SetRectRgn (rgn, m_iClip[0], m_iClip[1], m_iClip[2], m_iClip[3]);
aglSetInteger(m_pkAglContext, AGL_CLIP_REGION, (const GLint*)rgn);
DisposeRgn (rgn);
if (!aglEnable(m_pkAglContext, AGL_CLIP_REGION))
{
FatalErrorMessage("Cannot enable AGL_CLIP_REGION.");
}
BUT:
It this clipping region on safari osx is always ~54 pixels vertically
off. Which is also the height of the menu frame on top of the window.
So this makes me think I need to find out what that top part of the
window's height is, so I can subtract it out of this clipping
rectangle.
But how??
Any hints anyone?
-tim
On 5/24/10, Tim Prepscius <timprepscius at gmail.com> wrote:
> okay even more information:
>
> I found this post:
> http://stackoverflow.com/questions/1770415/firefox-cocoa-plugin
>
> NP_CGContext* npContext = currentInstance->window.window;
>
> NSWindow* browserWindow = [[[NSWindow alloc]
> initWithWindowRef:npContext->window] autorelease];
>
> int y = [browserWindow frame].size.height -
> (clipRect.bottom - clipRect.top) - currentInstance->window.y;
>
> ....
>
> so for kicks I pulled the values of browserWindow frame size height.
>
> and they "stay correct" after resize..
> hmmm..
>
> so I guess I can put in a hack to use this instead of the port bounds...
> I wonder if there is a way to do this without using Cocoa.
>
> ????
>
> -tim
>
> On 5/24/10, Tim Prepscius <timprepscius at gmail.com> wrote:
>> So just a little bit more information..
>>
>> The change in math is coming from:
>> GetPortBounds( )
>>
>> which after the resize is 50 pixels greater vertically. hhhmmmm...
>>
>> GetPortBounds of
>> CGrafPtr pkPort = aglGetDrawable(m_pkAglContext);
>>
>> which was:
>> m_pkAglContext = aglCreateContext(pkPixelFormat,0); and
>> if (!aglSetDrawable(m_pkAglContext,m_pkAglDrawable)
>>
>> m_pkAglDrawable = (AGLDrawable)GetWindowPort(pkWindow);
>>
>> and pkWindow refers back to that currentInstance->window.window
>>
>> --
>>
>> hmmmmmmmmmmmm
>>
>> ...
>>
>> So it seems to me that.
>>
>> The context is correctly associated with the drawable, which is the
>> window
>> The NP_SetWindow is sending in the correct window.x window.y clip
>>
>> But somewhere during the recomputation of layout during resize, the
>> window port is resized so as not to include the title bar.
>>
>>
>> Does this sound correct?
>>
>> If it is correct, I see three possible solutions, both of which I am
>> not sure how I would implement.
>>
>> Solution #1. Find the correct variable to subtract out of this
>> GetPortBounds. I have no idea.. Any thoughts? This is obviously the
>> correct solution.
>>
>> Solution #2: Manufacture a resize event and send it to the window.
>> Always subtract some hacked constant from GetPortBounds.
>>
>> Solution #3: Catch the resize event for the window. Thereafter,
>> subtract out some hacked value.
>>
>>
>> Any thoughts? Hints.. Especially to solution #1? Is there a better
>> way. Is this possible in pure carbon? I really really am not looking
>> forward to obj-c.
>>
>> -tim
>>
>> On 5/24/10, Tim Prepscius <timprepscius at gmail.com> wrote:
>>> Greetings,
>>>
>>> I'm not really sure if this is the appropriate place to pose this
>>> question.
>>> Anyway, here goes:
>>>
>>> I've developed an opengl plugin for firefox/safari/chrome under
>>> win32/osx.
>>>
>>> Within OSX, using Safari my plugin exhibits incorrect vertical
>>> placement behavior after the browser window is resized.
>>>
>>> In detail:
>>> 1. I start the browser and go to the plugin test page.
>>> 2. Plugin starts fine, is correctly placed.. (I made a surrounding div
>>> so I can see placement problems)
>>>
>>> [ NPP_SetWindow is called, I look at the window.x window.y
>>> window.width window.height
>>> I also look at the clipping rectange ]
>>>
>>> 3. I scroll the window. the plugin maintains its appropriate
>>> relative position.
>>>
>>> [NPP_SetWindow is called, I can see the window.y changing correctly ]
>>>
>>> 4. I resize the window by only one pixel horizontally (it doesn't
>>> matter how much or in what direction)
>>>
>>> The window.x window.y window.width window.height change appropriately.
>>> In this case the X variable might change by 1 pixel width by 1 or
>>> something like that.
>>>
>>> *** however *** the plugin now draws at the wrong vertical position.
>>> The number of pixels off the plugin draws is equal to the number of
>>> pixels of the top "url + buttons" area.
>>>
>>> -------------------
>>>
>>> So, I'm searching for the correct vertical placement variable to
>>> add/subtract from window.y but have not found it.
>>>
>>> I've tried also looking at that CGContext, and working backwards from
>>> there, but it doesn't give me any different information.
>>>
>>> I think I need to somehow get some attribute of that window, to see if
>>> there is an additional offset, but I'm not sure which one.
>>>
>>> -------------
>>>
>>> Any hints?
>>>
>>> -tim
>>>
>>>
>>> :::::::::::::::::::::::::::::::::
>>>
>>> // Called to update a plugin instances's NPWindow
>>> NPError NPP_SetWindow(NPP instance, NPWindow* window)
>>> {
>>> fprintf (stderr, "NP_SetWindow called!!!\n");
>>>
>>> if(instance == NULL)
>>> return NPERR_INVALID_INSTANCE_ERROR;
>>>
>>> if(window == NULL)
>>> return NPERR_GENERIC_ERROR;
>>>
>>> PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
>>>
>>> currentInstance->window = *window;
>>>
>>> NP_CGContext *context =
>>> ((NP_CGContext*)(currentInstance->window.window));
>>>
>>> fprintf (stderr, "%d %d %d %d - %d %d %d %d",
>>> currentInstance->window.x, currentInstance->window.y,
>>> currentInstance->window.width, currentInstance->window.height,
>>> currentInstance->window.clipRect.left,
>>> currentInstance->window.clipRect.top,
>>> currentInstance->window.clipRect.right,
>>> currentInstance->window.clipRect.bottom
>>> );
>>>
>>> CGContextRef cgContext =
>>> ((NP_CGContext*)(currentInstance->window.window))->context;
>>> CGRect rect = CGRectMake(0,0,1,1);
>>> CGRect userRect = CGContextConvertRectToUserSpace (cgContext, rect);
>>> fprintf(stderr, "userspace %f %f %f %f", userRect.origin.x,
>>> userRect.origin.y, userRect.size.width, userRect.size.height);
>>>
>>> CGRect deviceRect = CGContextConvertRectToDeviceSpace (cgContext,
>>> rect);
>>> fprintf(stderr, "devicespace %f %f %f %f", deviceRect.origin.x,
>>> deviceRect.origin.y, deviceRect.size.width, deviceRect.size.height);
>>>
>>>
>>> if (!currentInstance->initialized && context)
>>> {
>>> currentInstance->initialized = true;
>>>
>>> StartInstance(context->window,currentInstance->argc,currentInstance->argn,currentInstance->argv);
>>> UpdatePositionWidthHeight (context->window,
>>> currentInstance->window.x, currentInstance->window.y,
>>> currentInstance->window.width, currentInstance->window.height);
>>> }
>>> else
>>> {
>>> UpdatePositionWidthHeight (context->window,
>>> currentInstance->window.x, currentInstance->window.y,
>>> currentInstance->window.width, currentInstance->window.height);
>>> }
>>>
>>> return NPERR_NO_ERROR;
>>> }
>>> :::::::::::::::::::::::::::
>>>
>>
>
More information about the webkit-help
mailing list