mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-22 06:57:42 +01:00
Mac: Reduce resource usage on SetWindowVisibility(false) and fix delivery of application hide/unhide notifications (issue #1369)
git-svn-id: https://chromiumembedded.googlecode.com/svn/branches/2062@1831 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
41d14270d6
commit
e83c8bde80
@ -64,15 +64,40 @@
|
||||
@interface CefWindowDelegate : NSObject <NSWindowDelegate> {
|
||||
@private
|
||||
CefBrowserHostImpl* browser_; // weak
|
||||
NSWindow* window_;
|
||||
}
|
||||
|
||||
@property (nonatomic, assign) CefBrowserHostImpl* browser;
|
||||
|
||||
- (id)initWithWindow:(NSWindow*)window andBrowser:(CefBrowserHostImpl*)browser;
|
||||
@end
|
||||
|
||||
@implementation CefWindowDelegate
|
||||
|
||||
@synthesize browser = browser_;
|
||||
- (id)initWithWindow:(NSWindow*)window andBrowser:(CefBrowserHostImpl*)browser {
|
||||
if (self = [super init]) {
|
||||
window_ = window;
|
||||
browser_ = browser;
|
||||
|
||||
[window_ setDelegate:self];
|
||||
|
||||
// Register for application hide/unhide notifications.
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(applicationDidHide:)
|
||||
name:NSApplicationDidHideNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(applicationDidUnhide:)
|
||||
name:NSApplicationDidUnhideNotification
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
// Called when we are activated (when we gain focus).
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
@ -101,7 +126,7 @@
|
||||
// Called when the application has been hidden.
|
||||
- (void)applicationDidHide:(NSNotification *)notification {
|
||||
// If the window is miniaturized then nothing has really changed.
|
||||
if (![[notification object] isMiniaturized]) {
|
||||
if (![window_ isMiniaturized]) {
|
||||
if (browser_)
|
||||
browser_->SetWindowVisibility(false);
|
||||
}
|
||||
@ -110,7 +135,7 @@
|
||||
// Called when the application has been unhidden.
|
||||
- (void)applicationDidUnhide:(NSNotification *)notification {
|
||||
// If the window is miniaturized then nothing has really changed.
|
||||
if (![[notification object] isMiniaturized]) {
|
||||
if (![window_ isMiniaturized]) {
|
||||
if (browser_)
|
||||
browser_->SetWindowVisibility(true);
|
||||
}
|
||||
@ -365,10 +390,6 @@ bool CefBrowserHostImpl::PlatformCreateWindow() {
|
||||
contentRect.size.width = window_rect.size.width;
|
||||
contentRect.size.height = window_rect.size.height;
|
||||
|
||||
// Create the delegate for control and browser window events.
|
||||
CefWindowDelegate* delegate = [[CefWindowDelegate alloc] init];
|
||||
delegate.browser = this;
|
||||
|
||||
newWnd = [[UnderlayOpenGLHostingWindow alloc]
|
||||
initWithContentRect:window_rect
|
||||
styleMask:(NSTitledWindowMask |
|
||||
@ -378,7 +399,10 @@ bool CefBrowserHostImpl::PlatformCreateWindow() {
|
||||
NSUnifiedTitleAndToolbarWindowMask )
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
[newWnd setDelegate:delegate];
|
||||
|
||||
// Create the delegate for control and browser window events.
|
||||
[[CefWindowDelegate alloc] initWithWindow:newWnd andBrowser:this];
|
||||
|
||||
parentView = [newWnd contentView];
|
||||
window_info_.parent_view = parentView;
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ void CefRenderWidgetHostViewOSR::SetTakesFocusOnlyOnMouseDown(bool flag) {
|
||||
}
|
||||
|
||||
void CefRenderWidgetHostViewOSR::SetWindowVisibility(bool visible) {
|
||||
if (visible)
|
||||
WasShown();
|
||||
else
|
||||
WasHidden();
|
||||
}
|
||||
|
||||
void CefRenderWidgetHostViewOSR::WindowFrameChanged() {
|
||||
|
@ -129,7 +129,11 @@ const int kWindowHeight = 600;
|
||||
|
||||
// Receives notifications from controls and the browser window. Will delete
|
||||
// itself when done.
|
||||
@interface ClientWindowDelegate : NSObject <NSWindowDelegate>
|
||||
@interface ClientWindowDelegate : NSObject <NSWindowDelegate> {
|
||||
@private
|
||||
NSWindow* window_;
|
||||
}
|
||||
- (id)initWithWindow:(NSWindow*)window;
|
||||
- (IBAction)goBack:(id)sender;
|
||||
- (IBAction)goForward:(id)sender;
|
||||
- (IBAction)reload:(id)sender;
|
||||
@ -143,6 +147,32 @@ const int kWindowHeight = 600;
|
||||
|
||||
@implementation ClientWindowDelegate
|
||||
|
||||
- (id)initWithWindow:(NSWindow*)window {
|
||||
if (self = [super init]) {
|
||||
window_ = window;
|
||||
[window_ setDelegate:self];
|
||||
|
||||
// Register for application hide/unhide notifications.
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(applicationDidHide:)
|
||||
name:NSApplicationDidHideNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver:self
|
||||
selector:@selector(applicationDidUnhide:)
|
||||
name:NSApplicationDidUnhideNotification
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)goBack:(id)sender {
|
||||
if (g_handler.get() && g_handler->GetBrowserId())
|
||||
g_handler->GetBrowser()->GoBack();
|
||||
@ -258,7 +288,7 @@ const int kWindowHeight = 600;
|
||||
// Called when the application has been hidden.
|
||||
- (void)applicationDidHide:(NSNotification *)notification {
|
||||
// If the window is miniaturized then nothing has really changed.
|
||||
if (![[notification object] isMiniaturized]) {
|
||||
if (![window_ isMiniaturized]) {
|
||||
if (g_handler.get()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
if (browser.get())
|
||||
@ -270,7 +300,7 @@ const int kWindowHeight = 600;
|
||||
// Called when the application has been unhidden.
|
||||
- (void)applicationDidUnhide:(NSNotification *)notification {
|
||||
// If the window is miniaturized then nothing has really changed.
|
||||
if (![[notification object] isMiniaturized]) {
|
||||
if (![window_ isMiniaturized]) {
|
||||
if (g_handler.get()) {
|
||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||
if (browser.get())
|
||||
@ -382,9 +412,6 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
[testItem setSubmenu:testMenu];
|
||||
[menubar addItem:testItem];
|
||||
|
||||
// Create the delegate for control and browser window events.
|
||||
ClientWindowDelegate* delegate = [[ClientWindowDelegate alloc] init];
|
||||
|
||||
// Create the main application window.
|
||||
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
||||
NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
|
||||
@ -398,7 +425,10 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:NO];
|
||||
[mainWnd setTitle:@"cefclient"];
|
||||
[mainWnd setDelegate:delegate];
|
||||
|
||||
// Create the delegate for control and browser window events.
|
||||
ClientWindowDelegate* delegate =
|
||||
[[ClientWindowDelegate alloc] initWithWindow:mainWnd];
|
||||
|
||||
// Rely on the window delegate to clean us up rather than immediately
|
||||
// releasing when the window gets closed. We use the delegate to do
|
||||
|
Loading…
x
Reference in New Issue
Block a user