mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-24 07:58:11 +01:00
Mac:
- Add support for popup windows. - Fix select list bugs. - Add additional tests to cefclient. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@182 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
5911e7027c
commit
02bd128046
@ -782,6 +782,17 @@ CefRefPtr<CefBrowserImpl> CefBrowserImpl::UIT_CreatePopupWindow(
|
||||
#if defined(OS_WIN)
|
||||
info.SetAsPopup(NULL, CefString());
|
||||
#endif
|
||||
|
||||
// Default to the size from the popup features.
|
||||
if(features.xSet)
|
||||
info.m_x = features.x;
|
||||
if(features.ySet)
|
||||
info.m_y = features.y;
|
||||
if(features.widthSet)
|
||||
info.m_nWidth = features.width;
|
||||
if(features.heightSet)
|
||||
info.m_nHeight = features.height;
|
||||
|
||||
CefRefPtr<CefHandler> handler = handler_;
|
||||
CefString newUrl = url;
|
||||
|
||||
@ -820,7 +831,10 @@ void CefBrowserImpl::UIT_ClosePopupWidget()
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
// Mac uses a WebPopupMenu for select lists so no closing is necessary.
|
||||
UIT_CloseView(UIT_GetPopupWndHandle());
|
||||
#endif
|
||||
popuphost_ = NULL;
|
||||
}
|
||||
|
||||
|
@ -152,7 +152,7 @@ public:
|
||||
REQUIRE_UIT();
|
||||
return popuphost_->view_handle();
|
||||
}
|
||||
gfx::NativeWindow UIT_GetMainWndHandle() const;
|
||||
gfx::NativeView UIT_GetMainWndHandle() const;
|
||||
|
||||
BrowserNavigationController* UIT_GetNavigationController() {
|
||||
REQUIRE_UIT();
|
||||
|
@ -25,9 +25,9 @@ CefWindowHandle CefBrowserImpl::GetWindowHandle()
|
||||
return window_info_.m_View;
|
||||
}
|
||||
|
||||
gfx::NativeWindow CefBrowserImpl::UIT_GetMainWndHandle() const {
|
||||
gfx::NativeView CefBrowserImpl::UIT_GetMainWndHandle() const {
|
||||
REQUIRE_UIT();
|
||||
return (NSWindow*)window_info_.m_View;
|
||||
return (NSView*)window_info_.m_View;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
@ -44,9 +44,34 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
if (!settings_.developer_tools_disabled)
|
||||
dev_tools_agent_.reset(new BrowserDevToolsAgent());
|
||||
|
||||
NSWindow* newWnd = nil;
|
||||
|
||||
NSView* parentView = (NSView*)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) {
|
||||
// Create a new window.
|
||||
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
||||
NSRect window_rect = {{window_info_.m_x,
|
||||
screen_rect.size.height - window_info_.m_y},
|
||||
{window_info_.m_nWidth, window_info_.m_nHeight}};
|
||||
if (window_rect.size.width == 0)
|
||||
window_rect.size.width = 500;
|
||||
if (window_rect.size.height == 0)
|
||||
window_rect.size.height = 500;
|
||||
contentRect.SetRect(0, 0, window_rect.size.width, window_rect.size.height);
|
||||
|
||||
newWnd = [[NSWindow alloc]
|
||||
initWithContentRect:window_rect
|
||||
styleMask:(NSTitledWindowMask |
|
||||
NSClosableWindowMask |
|
||||
NSMiniaturizableWindowMask |
|
||||
NSResizableWindowMask )
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
parentView = [newWnd contentView];
|
||||
window_info_.m_ParentView = (void*)parentView;
|
||||
}
|
||||
|
||||
WebPreferences prefs;
|
||||
BrowserToWebSettings(settings_, prefs);
|
||||
@ -66,6 +91,11 @@ void CefBrowserImpl::UIT_CreateBrowser(const CefString& url)
|
||||
|
||||
Unlock();
|
||||
|
||||
if (newWnd != nil) {
|
||||
// Show the window.
|
||||
[newWnd makeKeyAndOrderFront: nil];
|
||||
}
|
||||
|
||||
if(handler_.get()) {
|
||||
// Notify the handler that we're done creating the new window
|
||||
handler_->HandleAfterCreated(this);
|
||||
|
@ -245,6 +245,10 @@ class BrowserWebViewDelegate : public WebKit::WebViewClient,
|
||||
|
||||
CefBrowserImpl* GetBrowser() { return browser_; }
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
void SetPopupMenuInfo(const WebKit::WebPopupMenuInfo& info);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
// Default handling of JavaScript messages.
|
||||
void ShowJavaScriptAlert(WebKit::WebFrame* webframe,
|
||||
|
@ -28,7 +28,7 @@ using WebKit::WebWidget;
|
||||
WebWidget* BrowserWebViewDelegate::createPopupMenu(
|
||||
const WebPopupMenuInfo& info) {
|
||||
WebWidget* webwidget = browser_->UIT_CreatePopupWidget();
|
||||
popup_menu_info_.reset(new WebPopupMenuInfo(info));
|
||||
browser_->UIT_GetPopupDelegate()->SetPopupMenuInfo(info);
|
||||
return webwidget;
|
||||
}
|
||||
|
||||
@ -79,7 +79,8 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
|
||||
// (mouse down, keyboard activity) for this, so we calculate the proper
|
||||
// position based on the selected index and provided bounds.
|
||||
WebWidgetHost* popup = browser_->UIT_GetPopupHost();
|
||||
int window_num = [browser_->UIT_GetMainWndHandle() windowNumber];
|
||||
NSWindow* window = [browser_->UIT_GetMainWndHandle() window];
|
||||
int window_num = [window windowNumber];
|
||||
NSEvent* event =
|
||||
webkit_glue::EventWithMenuAction([menu_runner menuItemWasChosen],
|
||||
window_num, item_height,
|
||||
@ -95,6 +96,8 @@ void BrowserWebViewDelegate::show(WebNavigationPolicy policy) {
|
||||
// forward that to WebKit.
|
||||
popup->KeyEvent(event);
|
||||
}
|
||||
|
||||
browser_->UIT_ClosePopupWidget();
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
|
||||
@ -186,6 +189,10 @@ void BrowserWebViewDelegate::DidMovePlugin(
|
||||
|
||||
// Protected methods ----------------------------------------------------------
|
||||
|
||||
void BrowserWebViewDelegate::SetPopupMenuInfo(const WebPopupMenuInfo& info) {
|
||||
popup_menu_info_.reset(new WebPopupMenuInfo(info));
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
||||
WebKit::WebFrame* webframe, const CefString& message) {
|
||||
std::string messageStr(message);
|
||||
|
@ -47,7 +47,11 @@ public:
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefRefPtr<CefHandler>& handler,
|
||||
CefString& url,
|
||||
CefBrowserSettings& settings);
|
||||
CefBrowserSettings& settings)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
// Called on the UI thread after a new window is created. The return value is
|
||||
// currently ignored.
|
||||
|
@ -164,6 +164,14 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
- (IBAction)testJSExecute:(id)sender;
|
||||
- (IBAction)testRequest:(id)sender;
|
||||
- (IBAction)testSchemeHandler:(id)sender;
|
||||
- (IBAction)testPopupWindow:(id)sender;
|
||||
- (IBAction)testAccelerated2DCanvas:(id)sender;
|
||||
- (IBAction)testAcceleratedLayers:(id)sender;
|
||||
- (IBAction)testWebGL:(id)sender;
|
||||
- (IBAction)testHTML5Video:(id)sender;
|
||||
- (IBAction)testZoomIn:(id)sender;
|
||||
- (IBAction)testZoomOut:(id)sender;
|
||||
- (IBAction)testZoomReset:(id)sender;
|
||||
@end
|
||||
|
||||
@implementation ClientAppDelegate
|
||||
@ -203,6 +211,30 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
[testMenu addItemWithTitle:@"Scheme Handler"
|
||||
action:@selector(testSchemeHandler:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Popup Window"
|
||||
action:@selector(testPopupWindow:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Accelerated 2D Canvas"
|
||||
action:@selector(testAccelerated2DCanvas:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Acceledated Layers"
|
||||
action:@selector(testAcceleratedLayers:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"WebGL"
|
||||
action:@selector(testWebGL:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"HTML5 Video"
|
||||
action:@selector(testHTML5Video:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Zoom In"
|
||||
action:@selector(testZoomIn:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Zoom Out"
|
||||
action:@selector(testZoomOut:)
|
||||
keyEquivalent:@""];
|
||||
[testMenu addItemWithTitle:@"Zoom Reset"
|
||||
action:@selector(testZoomReset:)
|
||||
keyEquivalent:@""];
|
||||
[testItem setSubmenu:testMenu];
|
||||
[menubar addItem:testItem];
|
||||
|
||||
@ -325,6 +357,52 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
RunSchemeTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testPopupWindow:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunPopupTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testAccelerated2DCanvas:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAccelerated2DCanvasTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testAcceleratedLayers:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunAcceleratedLayersTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testWebGL:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunWebGLTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testHTML5Video:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd())
|
||||
RunHTML5VideoTest(g_handler->GetBrowser());
|
||||
}
|
||||
|
||||
- (IBAction)testZoomIn:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testZoomOut:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
- (IBAction)testZoomReset:(id)sender {
|
||||
if(g_handler.get() && g_handler->GetBrowserHwnd()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
browser->SetZoomLevel(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Sent by the default notification center immediately before the application
|
||||
// terminates.
|
||||
- (void)applicationWillTerminate:(NSNotification *)aNotification {
|
||||
@ -367,15 +445,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
// ClientHandler implementation
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleBeforeCreated(
|
||||
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
|
||||
CefString& url, CefBrowserSettings& settings)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
@ -399,7 +468,8 @@ CefHandler::RetVal ClientHandler::HandleTitleChange(
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
// Set the frame window title bar
|
||||
NSWindow* window = (NSWindow*)m_MainHwnd;
|
||||
NSView* view = (NSView*)browser->GetWindowHandle();
|
||||
NSWindow* window = [view window];
|
||||
std::string titleStr(title);
|
||||
NSString* str = [NSString stringWithUTF8String:titleStr.c_str()];
|
||||
[window setTitle:str];
|
||||
|
@ -636,27 +636,6 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
// ClientHandler implementation
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleBeforeCreated(
|
||||
CefRefPtr<CefBrowser> parentBrowser, CefWindowInfo& createInfo, bool popup,
|
||||
const CefPopupFeatures& popupFeatures, CefRefPtr<CefHandler>& handler,
|
||||
CefString& url, CefBrowserSettings& settings)
|
||||
{
|
||||
REQUIRE_UI_THREAD();
|
||||
|
||||
if(popup) {
|
||||
if(popupFeatures.xSet)
|
||||
createInfo.m_x = popupFeatures.x;
|
||||
if(popupFeatures.ySet)
|
||||
createInfo.m_y = popupFeatures.y;
|
||||
if(popupFeatures.widthSet)
|
||||
createInfo.m_nWidth = popupFeatures.width;
|
||||
if(popupFeatures.heightSet)
|
||||
createInfo.m_nHeight = popupFeatures.height;
|
||||
}
|
||||
|
||||
return RV_CONTINUE;
|
||||
}
|
||||
|
||||
CefHandler::RetVal ClientHandler::HandleAddressChange(
|
||||
CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,
|
||||
const CefString& url)
|
||||
|
Loading…
x
Reference in New Issue
Block a user