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:
Marshall Greenblatt 2011-02-02 16:30:24 +00:00
parent 02bd128046
commit af12107c33
3 changed files with 48 additions and 40 deletions

View File

@ -34,13 +34,22 @@
#if defined(__APPLE__) #if defined(__APPLE__)
#include "cef_string.h" #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 #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
// Window handle.
#define cef_window_handle_t void*
// Class representing window information. // Class representing window information.
typedef struct _cef_window_info_t typedef struct _cef_window_info_t
{ {

View File

@ -27,7 +27,7 @@ CefWindowHandle CefBrowserImpl::GetWindowHandle()
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() const { gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() const {
REQUIRE_UIT(); REQUIRE_UIT();
return (NSView*)window_info_.m_View; return window_info_.m_View;
} }
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url) void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
@ -46,7 +46,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
NSWindow* newWnd = nil; 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, gfx::Rect contentRect(window_info_.m_x, window_info_.m_y,
window_info_.m_nWidth, window_info_.m_nHeight); window_info_.m_nWidth, window_info_.m_nHeight);
if (parentView == nil) { if (parentView == nil) {
@ -70,7 +70,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
backing:NSBackingStoreBuffered backing:NSBackingStoreBuffered
defer:NO]; defer:NO];
parentView = [newWnd contentView]; parentView = [newWnd contentView];
window_info_.m_ParentView = (void*)parentView; window_info_.m_ParentView = parentView;
} }
WebPreferences prefs; WebPreferences prefs;
@ -87,7 +87,7 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle(); BrowserWebView* browserView = (BrowserWebView*)webviewhost_->view_handle();
browserView.browser = this; browserView.browser = this;
window_info_.m_View = (void*)browserView; window_info_.m_View = browserView;
Unlock(); Unlock();

View File

@ -262,38 +262,38 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
// during cleanup (ie, a window close from javascript). // during cleanup (ie, a window close from javascript).
[mainWnd setReleasedWhenClosed:NO]; [mainWnd setReleasedWhenClosed:NO];
NSView* contentView = [mainWnd contentView];
// Create the buttons. // Create the buttons.
NSRect button_rect = [[mainWnd contentView] bounds]; NSRect button_rect = [contentView bounds];
button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT + button_rect.origin.y = window_rect.size.height - URLBAR_HEIGHT +
(URLBAR_HEIGHT - BUTTON_HEIGHT) / 2; (URLBAR_HEIGHT - BUTTON_HEIGHT) / 2;
button_rect.size.height = BUTTON_HEIGHT; button_rect.size.height = BUTTON_HEIGHT;
button_rect.origin.x += BUTTON_MARGIN; button_rect.origin.x += BUTTON_MARGIN;
button_rect.size.width = BUTTON_WIDTH; button_rect.size.width = BUTTON_WIDTH;
NSView* content = [mainWnd contentView]; NSButton* button = MakeButton(&button_rect, @"Back", contentView);
NSButton* button = MakeButton(&button_rect, @"Back", content);
[button setTarget:delegate]; [button setTarget:delegate];
[button setAction:@selector(goBack:)]; [button setAction:@selector(goBack:)];
button = MakeButton(&button_rect, @"Forward", content); button = MakeButton(&button_rect, @"Forward", contentView);
[button setTarget:delegate]; [button setTarget:delegate];
[button setAction:@selector(goForward:)]; [button setAction:@selector(goForward:)];
button = MakeButton(&button_rect, @"Reload", content); button = MakeButton(&button_rect, @"Reload", contentView);
[button setTarget:delegate]; [button setTarget:delegate];
[button setAction:@selector(reload:)]; [button setAction:@selector(reload:)];
button = MakeButton(&button_rect, @"Stop", content); button = MakeButton(&button_rect, @"Stop", contentView);
[button setTarget:delegate]; [button setTarget:delegate];
[button setAction:@selector(stopLoading:)]; [button setAction:@selector(stopLoading:)];
// Create the URL text field. // Create the URL text field.
button_rect.origin.x += BUTTON_MARGIN; button_rect.origin.x += BUTTON_MARGIN;
button_rect.size.width = [[mainWnd contentView] bounds].size.width - button_rect.size.width = [contentView bounds].size.width -
button_rect.origin.x - BUTTON_MARGIN; button_rect.origin.x - BUTTON_MARGIN;
NSTextField* editWnd = [[NSTextField alloc] initWithFrame:button_rect]; NSTextField* editWnd = [[NSTextField alloc] initWithFrame:button_rect];
[[mainWnd contentView] addSubview:editWnd]; [contentView addSubview:editWnd];
[editWnd setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; [editWnd setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
[editWnd setTarget:delegate]; [editWnd setTarget:delegate];
[editWnd setAction:@selector(takeURLStringValueFrom:)]; [editWnd setAction:@selector(takeURLStringValueFrom:)];
@ -302,13 +302,12 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
// Create the handler. // Create the handler.
g_handler = new ClientHandler(); g_handler = new ClientHandler();
g_handler->SetMainHwnd(mainWnd); g_handler->SetMainHwnd(contentView);
g_handler->SetEditHwnd(editWnd); g_handler->SetEditHwnd(editWnd);
// Create the browser view. // Create the browser view.
CefWindowInfo window_info; CefWindowInfo window_info;
window_info.SetAsChild((void*)[mainWnd contentView], 0, 0, window_info.SetAsChild(contentView, 0, 0, kWindowWidth, kWindowHeight);
kWindowWidth, kWindowHeight);
CefBrowser::CreateBrowser(window_info, false, g_handler.get(), CefBrowser::CreateBrowser(window_info, false, g_handler.get(),
"http://www.google.com"); "http://www.google.com");
@ -513,7 +512,7 @@ void ClientHandler::SendNotification(NotificationType type)
if(sel == nil) if(sel == nil)
return; return;
NSWindow* window = (NSWindow*)g_handler->GetMainHwnd(); NSWindow* window = [g_handler->GetMainHwnd() window];
NSObject* delegate = [window delegate]; NSObject* delegate = [window delegate];
[delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO]; [delegate performSelectorOnMainThread:sel withObject:nil waitUntilDone:NO];
} }