Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 #include "grit/generated_resources.h" | 45 #include "grit/generated_resources.h" |
| 46 #include "ui/base/l10n/l10n_util_mac.h" | 46 #include "ui/base/l10n/l10n_util_mac.h" |
| 47 #include "ui/gfx/rect.h" | 47 #include "ui/gfx/rect.h" |
| 48 | 48 |
| 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 49 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 50 BrowserWindowController* controller, | 50 BrowserWindowController* controller, |
| 51 NSWindow* window) | 51 NSWindow* window) |
| 52 : browser_(browser), | 52 : browser_(browser), |
| 53 controller_(controller), | 53 controller_(controller), |
| 54 confirm_close_factory_(browser) { | 54 confirm_close_factory_(browser) { |
| 55 // This pref applies to all windows, so all must watch for it. | 55 // This pref applies to all windows, so all must watch for it. |
|
Peter Kasting
2011/08/10 21:30:15
Nit: Maybe use same comment as browser.cc
| |
| 56 registrar_.Add(this, | 56 registrar_.Add(this, |
| 57 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 57 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
| 58 NotificationService::AllSources()); | 58 NotificationService::AllBrowserContextsAndSources()); |
| 59 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 59 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 60 NotificationService::AllSources()); | 60 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 61 } | 61 } |
| 62 | 62 |
| 63 BrowserWindowCocoa::~BrowserWindowCocoa() { | 63 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void BrowserWindowCocoa::Show() { | 66 void BrowserWindowCocoa::Show() { |
| 67 // The Browser associated with this browser window must become the active | 67 // The Browser associated with this browser window must become the active |
| 68 // browser at the time |Show()| is called. This is the natural behaviour under | 68 // browser at the time |Show()| is called. This is the natural behaviour under |
| 69 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 69 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| 70 // until we return to the runloop. Therefore any calls to | 70 // until we return to the runloop. Therefore any calls to |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 return bridge; | 601 return bridge; |
| 602 } | 602 } |
| 603 | 603 |
| 604 void BrowserWindowCocoa::Observe(int type, | 604 void BrowserWindowCocoa::Observe(int type, |
| 605 const NotificationSource& source, | 605 const NotificationSource& source, |
| 606 const NotificationDetails& details) { | 606 const NotificationDetails& details) { |
| 607 switch (type) { | 607 switch (type) { |
| 608 // Only the key window gets a direct toggle from the menu. | 608 // Only the key window gets a direct toggle from the menu. |
| 609 // Other windows hear about it from the notification. | 609 // Other windows hear about it from the notification. |
| 610 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 610 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: |
| 611 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 611 if (browser_->profile()->IsSameProfile(Source<Profile>(source).ptr())) |
| 612 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | |
| 612 break; | 613 break; |
| 613 case chrome::NOTIFICATION_SIDEBAR_CHANGED: | 614 case chrome::NOTIFICATION_SIDEBAR_CHANGED: |
| 614 UpdateSidebarForContents( | 615 UpdateSidebarForContents( |
| 615 Details<SidebarContainer>(details)->tab_contents()); | 616 Details<SidebarContainer>(details)->tab_contents()); |
| 616 break; | 617 break; |
| 617 default: | 618 default: |
| 618 NOTREACHED(); // we don't ask for anything else! | 619 NOTREACHED(); // we don't ask for anything else! |
| 619 break; | 620 break; |
| 620 } | 621 } |
| 621 } | 622 } |
| 622 | 623 |
| 623 void BrowserWindowCocoa::DestroyBrowser() { | 624 void BrowserWindowCocoa::DestroyBrowser() { |
| 624 [controller_ destroyBrowser]; | 625 [controller_ destroyBrowser]; |
| 625 | 626 |
| 626 // at this point the controller is dead (autoreleased), so | 627 // at this point the controller is dead (autoreleased), so |
| 627 // make sure we don't try to reference it any more. | 628 // make sure we don't try to reference it any more. |
| 628 } | 629 } |
| 629 | 630 |
| 630 NSWindow* BrowserWindowCocoa::window() const { | 631 NSWindow* BrowserWindowCocoa::window() const { |
| 631 return [controller_ window]; | 632 return [controller_ window]; |
| 632 } | 633 } |
| 633 | 634 |
| 634 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | 635 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { |
| 635 if (tab_contents == browser_->GetSelectedTabContents()) { | 636 if (tab_contents == browser_->GetSelectedTabContents()) { |
| 636 [controller_ updateSidebarForContents:tab_contents]; | 637 [controller_ updateSidebarForContents:tab_contents]; |
| 637 } | 638 } |
| 638 } | 639 } |
| OLD | NEW |