mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-11 17:40:46 +01:00
Mac: Use NSView* instead of void* for cef_window_handle_t.
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@183 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
02bd128046
commit
af12107c33
@ -34,13 +34,22 @@
|
||||
#if defined(__APPLE__)
|
||||
#include "cef_string.h"
|
||||
|
||||
// Window handle.
|
||||
#ifdef __cplusplus
|
||||
#ifdef __OBJC__
|
||||
@class NSView;
|
||||
#else
|
||||
class NSView;
|
||||
#endif
|
||||
#define cef_window_handle_t NSView*
|
||||
#else
|
||||
#define cef_window_handle_t void*
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Window handle.
|
||||
#define cef_window_handle_t void*
|
||||
|
||||
// Class representing window information.
|
||||
typedef struct _cef_window_info_t
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ CefWindowHandle CefBrowserImpl::GetWindowHandle()
|
||||
|
||||
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() const {
|
||||
REQUIRE_UIT();
|
||||
return (NSView*)window_info_.m_View;
|
||||
return window_info_.m_View;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
@ -46,7 +46,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
|
||||
NSWindow* newWnd = nil;
|
||||
|
||||
NSView* parentView = (NSView*)window_info_.m_ParentView;
|
||||
NSView* parentView = window_info_.m_ParentView;
|
||||
gfx::Rect contentRect(window_info_.m_x, window_info_.m_y,
|
||||
window_info_.m_nWidth, window_info_.m_nHeight);
|
||||
if (parentView == nil) {
|
||||
@ -70,7 +70,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
parentView = [newWnd contentView];
|
||||
window_info_.m_ParentView = (void*)parentView;
|
||||
window_info_.m_ParentView = parentView;
|
||||
}
|
||||
|
||||
WebPreferences prefs;
|
||||
@ -87,7 +87,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
|
||||
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
|
||||
browserView.browser = this;
|
||||
window_info_.m_View = (void*)browserView;
|
||||
window_info_.m_View = browserView;
|
||||
|
||||
Unlock();
|
||||
|
||||
|
@ -255,66 +255,65 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
defer:NO];
|
||||
[mainWnd setTitle:@"cefclient"];
|
||||
[mainWnd setDelegate:delegate];
|
||||
|
||||
|
||||
// Rely on the window delegate to clean us up rather than immediately
|
||||
// releasing when the window gets closed. We use the delegate to do
|
||||
// everything from the autorelease pool so the window isn't on the stack
|
||||
// during cleanup (ie, a window close from javascript).
|
||||
[mainWnd setReleasedWhenClosed:NO];
|
||||
|
||||
|
||||
NSView* contentView = [mainWnd contentView];
|
||||
|
||||
// Create the buttons.
|
||||
NSRect button_rect = [[mainWnd contentView] bounds];
|
||||
NSRect button_rect = [contentView bounds];
|
||||
button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT +
|
||||
(URLBAR_HEIGHT - BUTTON_HEIGHT) / 2;
|
||||
button_rect.size.height = BUTTON_HEIGHT;
|
||||
button_rect.origin.x += BUTTON_MARGIN;
|
||||
button_rect.size.width = BUTTON_WIDTH;
|
||||
|
||||
NSView* content = [mainWnd contentView];
|
||||
|
||||
NSButton* button = MakeButton(&button_rect, @"Back", content);
|
||||
|
||||
NSButton* button = MakeButton(&button_rect, @"Back", contentView);
|
||||
[button setTarget:delegate];
|
||||
[button setAction:@selector(goBack:)];
|
||||
|
||||
button = MakeButton(&button_rect, @"Forward", content);
|
||||
|
||||
button = MakeButton(&button_rect, @"Forward", contentView);
|
||||
[button setTarget:delegate];
|
||||
[button setAction:@selector(goForward:)];
|
||||
|
||||
button = MakeButton(&button_rect, @"Reload", content);
|
||||
|
||||
button = MakeButton(&button_rect, @"Reload", contentView);
|
||||
[button setTarget:delegate];
|
||||
[button setAction:@selector(reload:)];
|
||||
|
||||
button = MakeButton(&button_rect, @"Stop", content);
|
||||
|
||||
button = MakeButton(&button_rect, @"Stop", contentView);
|
||||
[button setTarget:delegate];
|
||||
[button setAction:@selector(stopLoading:)];
|
||||
|
||||
|
||||
// Create the URL text field.
|
||||
button_rect.origin.x += BUTTON_MARGIN;
|
||||
button_rect.size.width = [[mainWnd contentView] bounds].size.width -
|
||||
button_rect.origin.x - BUTTON_MARGIN;
|
||||
button_rect.size.width = [contentView bounds].size.width -
|
||||
button_rect.origin.x - BUTTON_MARGIN;
|
||||
NSTextField* editWnd = [[NSTextField alloc] initWithFrame:button_rect];
|
||||
[[mainWnd contentView] addSubview:editWnd];
|
||||
[contentView addSubview:editWnd];
|
||||
[editWnd setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
|
||||
[editWnd setTarget:delegate];
|
||||
[editWnd setAction:@selector(takeURLStringValueFrom:)];
|
||||
[[editWnd cell] setWraps:NO];
|
||||
[[editWnd cell] setScrollable:YES];
|
||||
|
||||
|
||||
// Create the handler.
|
||||
g_handler = new ClientHandler();
|
||||
g_handler->SetMainHwnd(mainWnd);
|
||||
g_handler->SetMainHwnd(contentView);
|
||||
g_handler->SetEditHwnd(editWnd);
|
||||
|
||||
|
||||
// Create the browser view.
|
||||
CefWindowInfo window_info;
|
||||
window_info.SetAsChild((void*)[mainWnd contentView], 0, 0,
|
||||
kWindowWidth, kWindowHeight);
|
||||
window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
|
||||
CefBrowser::CreateBrowser(window_info, false, g_handler.get(),
|
||||
"http://www.google.com");
|
||||
|
||||
|
||||
// Show the window.
|
||||
[mainWnd makeKeyAndOrderFront: nil];
|
||||
|
||||
|
||||
// Size the window.
|
||||
NSRect r = [mainWnd contentRectForFrameRect:[mainWnd frame]];
|
||||
r.size.width = kWindowWidth;
|
||||
@ -409,7 +408,7 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
// Shut down CEF.
|
||||
g_handler = NULL;
|
||||
CefShutdown();
|
||||
|
||||
|
||||
[self release];
|
||||
}
|
||||
|
||||
@ -420,24 +419,24 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
// Retrieve the current working directory.
|
||||
getcwd(szWorkingDir, sizeof(szWorkingDir));
|
||||
|
||||
|
||||
// Initialize CEF. This will also create the NSApplication instance.
|
||||
CefSettings settings;
|
||||
CefBrowserSettings browserDefaults;
|
||||
CefInitialize(settings, browserDefaults);
|
||||
|
||||
|
||||
// Initialize tests.
|
||||
InitExtensionTest();
|
||||
InitSchemeTest();
|
||||
|
||||
|
||||
// Create the application delegate and window.
|
||||
NSObject* delegate = [[ClientAppDelegate alloc] init];
|
||||
[delegate performSelectorOnMainThread:@selector(createApp:) withObject:nil
|
||||
waitUntilDone:NO];
|
||||
|
||||
|
||||
// Run the application message loop.
|
||||
[NSApp run];
|
||||
|
||||
|
||||
// Don't put anything below this line because it won't be executed.
|
||||
return 0;
|
||||
}
|
||||
@ -509,11 +508,11 @@ void ClientHandler::SendNotification(NotificationType type)
|
||||
sel = @selector(notifyDownloadError:);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(sel == nil)
|
||||
return;
|
||||
|
||||
NSWindow* window = (NSWindow*)g_handler->GetMainHwnd();
|
||||
|
||||
NSWindow* window = [g_handler->GetMainHwnd() window];
|
||||
NSObject* delegate = [window delegate];
|
||||
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user