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/trunk@1830 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
082845619c
commit
fa5aa5fe4e
|
@ -64,15 +64,40 @@
|
||||||
@interface CefWindowDelegate : NSObject <NSWindowDelegate> {
|
@interface CefWindowDelegate : NSObject <NSWindowDelegate> {
|
||||||
@private
|
@private
|
||||||
CefBrowserHostImpl* browser_; // weak
|
CefBrowserHostImpl* browser_; // weak
|
||||||
|
NSWindow* window_;
|
||||||
}
|
}
|
||||||
|
- (id)initWithWindow:(NSWindow*)window andBrowser:(CefBrowserHostImpl*)browser;
|
||||||
@property (nonatomic, assign) CefBrowserHostImpl* browser;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CefWindowDelegate
|
@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).
|
// Called when we are activated (when we gain focus).
|
||||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||||
|
@ -101,7 +126,7 @@
|
||||||
// Called when the application has been hidden.
|
// Called when the application has been hidden.
|
||||||
- (void)applicationDidHide:(NSNotification *)notification {
|
- (void)applicationDidHide:(NSNotification *)notification {
|
||||||
// If the window is miniaturized then nothing has really changed.
|
// If the window is miniaturized then nothing has really changed.
|
||||||
if (![[notification object] isMiniaturized]) {
|
if (![window_ isMiniaturized]) {
|
||||||
if (browser_)
|
if (browser_)
|
||||||
browser_->SetWindowVisibility(false);
|
browser_->SetWindowVisibility(false);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +135,7 @@
|
||||||
// Called when the application has been unhidden.
|
// Called when the application has been unhidden.
|
||||||
- (void)applicationDidUnhide:(NSNotification *)notification {
|
- (void)applicationDidUnhide:(NSNotification *)notification {
|
||||||
// If the window is miniaturized then nothing has really changed.
|
// If the window is miniaturized then nothing has really changed.
|
||||||
if (![[notification object] isMiniaturized]) {
|
if (![window_ isMiniaturized]) {
|
||||||
if (browser_)
|
if (browser_)
|
||||||
browser_->SetWindowVisibility(true);
|
browser_->SetWindowVisibility(true);
|
||||||
}
|
}
|
||||||
|
@ -365,10 +390,6 @@ bool CefBrowserHostImpl::PlatformCreateWindow() {
|
||||||
contentRect.size.width = window_rect.size.width;
|
contentRect.size.width = window_rect.size.width;
|
||||||
contentRect.size.height = window_rect.size.height;
|
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]
|
newWnd = [[UnderlayOpenGLHostingWindow alloc]
|
||||||
initWithContentRect:window_rect
|
initWithContentRect:window_rect
|
||||||
styleMask:(NSTitledWindowMask |
|
styleMask:(NSTitledWindowMask |
|
||||||
|
@ -378,7 +399,10 @@ bool CefBrowserHostImpl::PlatformCreateWindow() {
|
||||||
NSUnifiedTitleAndToolbarWindowMask )
|
NSUnifiedTitleAndToolbarWindowMask )
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
[newWnd setDelegate:delegate];
|
|
||||||
|
// Create the delegate for control and browser window events.
|
||||||
|
[[CefWindowDelegate alloc] initWithWindow:newWnd andBrowser:this];
|
||||||
|
|
||||||
parentView = [newWnd contentView];
|
parentView = [newWnd contentView];
|
||||||
window_info_.parent_view = parentView;
|
window_info_.parent_view = parentView;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,10 @@ void CefRenderWidgetHostViewOSR::SetTakesFocusOnlyOnMouseDown(bool flag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRenderWidgetHostViewOSR::SetWindowVisibility(bool visible) {
|
void CefRenderWidgetHostViewOSR::SetWindowVisibility(bool visible) {
|
||||||
|
if (visible)
|
||||||
|
WasShown();
|
||||||
|
else
|
||||||
|
WasHidden();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CefRenderWidgetHostViewOSR::WindowFrameChanged() {
|
void CefRenderWidgetHostViewOSR::WindowFrameChanged() {
|
||||||
|
|
|
@ -129,7 +129,11 @@ const int kWindowHeight = 600;
|
||||||
|
|
||||||
// Receives notifications from controls and the browser window. Will delete
|
// Receives notifications from controls and the browser window. Will delete
|
||||||
// itself when done.
|
// itself when done.
|
||||||
@interface ClientWindowDelegate : NSObject <NSWindowDelegate>
|
@interface ClientWindowDelegate : NSObject <NSWindowDelegate> {
|
||||||
|
@private
|
||||||
|
NSWindow* window_;
|
||||||
|
}
|
||||||
|
- (id)initWithWindow:(NSWindow*)window;
|
||||||
- (IBAction)goBack:(id)sender;
|
- (IBAction)goBack:(id)sender;
|
||||||
- (IBAction)goForward:(id)sender;
|
- (IBAction)goForward:(id)sender;
|
||||||
- (IBAction)reload:(id)sender;
|
- (IBAction)reload:(id)sender;
|
||||||
|
@ -143,6 +147,32 @@ const int kWindowHeight = 600;
|
||||||
|
|
||||||
@implementation ClientWindowDelegate
|
@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 {
|
- (IBAction)goBack:(id)sender {
|
||||||
if (g_handler.get() && g_handler->GetBrowserId())
|
if (g_handler.get() && g_handler->GetBrowserId())
|
||||||
g_handler->GetBrowser()->GoBack();
|
g_handler->GetBrowser()->GoBack();
|
||||||
|
@ -258,7 +288,7 @@ const int kWindowHeight = 600;
|
||||||
// Called when the application has been hidden.
|
// Called when the application has been hidden.
|
||||||
- (void)applicationDidHide:(NSNotification *)notification {
|
- (void)applicationDidHide:(NSNotification *)notification {
|
||||||
// If the window is miniaturized then nothing has really changed.
|
// If the window is miniaturized then nothing has really changed.
|
||||||
if (![[notification object] isMiniaturized]) {
|
if (![window_ isMiniaturized]) {
|
||||||
if (g_handler.get()) {
|
if (g_handler.get()) {
|
||||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||||
if (browser.get())
|
if (browser.get())
|
||||||
|
@ -270,7 +300,7 @@ const int kWindowHeight = 600;
|
||||||
// Called when the application has been unhidden.
|
// Called when the application has been unhidden.
|
||||||
- (void)applicationDidUnhide:(NSNotification *)notification {
|
- (void)applicationDidUnhide:(NSNotification *)notification {
|
||||||
// If the window is miniaturized then nothing has really changed.
|
// If the window is miniaturized then nothing has really changed.
|
||||||
if (![[notification object] isMiniaturized]) {
|
if (![window_ isMiniaturized]) {
|
||||||
if (g_handler.get()) {
|
if (g_handler.get()) {
|
||||||
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
|
||||||
if (browser.get())
|
if (browser.get())
|
||||||
|
@ -382,9 +412,6 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||||
[testItem setSubmenu:testMenu];
|
[testItem setSubmenu:testMenu];
|
||||||
[menubar addItem:testItem];
|
[menubar addItem:testItem];
|
||||||
|
|
||||||
// Create the delegate for control and browser window events.
|
|
||||||
ClientWindowDelegate* delegate = [[ClientWindowDelegate alloc] init];
|
|
||||||
|
|
||||||
// Create the main application window.
|
// Create the main application window.
|
||||||
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
NSRect screen_rect = [[NSScreen mainScreen] visibleFrame];
|
||||||
NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
|
NSRect window_rect = { {0, screen_rect.size.height - kWindowHeight},
|
||||||
|
@ -398,7 +425,10 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) {
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
[mainWnd setTitle:@"cefclient"];
|
[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
|
// Rely on the window delegate to clean us up rather than immediately
|
||||||
// releasing when the window gets closed. We use the delegate to do
|
// releasing when the window gets closed. We use the delegate to do
|
||||||
|
|
Loading…
Reference in New Issue