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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "chrome/browser/ui/cocoa/task_manager_mac.h" | 36 #include "chrome/browser/ui/cocoa/task_manager_mac.h" |
| 37 #import "chrome/browser/ui/cocoa/theme_install_bubble_view.h" | 37 #import "chrome/browser/ui/cocoa/theme_install_bubble_view.h" |
| 38 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 38 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
| 39 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 39 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 40 #include "chrome/browser/ui/webui/task_manager_dialog.h" | 40 #include "chrome/browser/ui/webui/task_manager_dialog.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
| 45 #include "content/common/native_web_keyboard_event.h" | 45 #include "content/common/native_web_keyboard_event.h" |
| 46 #include "content/common/notification_details.h" | |
| 46 #include "content/common/notification_service.h" | 47 #include "content/common/notification_service.h" |
| 47 #include "grit/chromium_strings.h" | 48 #include "grit/chromium_strings.h" |
| 48 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 49 #include "ui/base/l10n/l10n_util_mac.h" | 50 #include "ui/base/l10n/l10n_util_mac.h" |
| 50 #include "ui/gfx/rect.h" | 51 #include "ui/gfx/rect.h" |
| 51 | 52 |
| 52 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 53 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 53 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 54 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 54 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 55 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 55 | 56 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 67 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; | 68 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; |
| 68 @end | 69 @end |
| 69 | 70 |
| 70 #endif // MAC_OS_X_VERSION_10_7 | 71 #endif // MAC_OS_X_VERSION_10_7 |
| 71 | 72 |
| 72 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 73 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 73 BrowserWindowController* controller) | 74 BrowserWindowController* controller) |
| 74 : browser_(browser), | 75 : browser_(browser), |
| 75 controller_(controller), | 76 controller_(controller), |
| 76 confirm_close_factory_(browser) { | 77 confirm_close_factory_(browser) { |
| 77 // Listen for bookmark bar visibility changes and set the initial state; we | |
| 78 // need to listen to all profiles because of normal profile/incognito issues. | |
| 79 registrar_.Add(this, | |
| 80 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | |
| 81 NotificationService::AllBrowserContextsAndSources()); | |
| 82 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | 78 registrar_.Add(this, chrome::NOTIFICATION_SIDEBAR_CHANGED, |
| 83 Source<SidebarManager>(SidebarManager::GetInstance())); | 79 Source<SidebarManager>(SidebarManager::GetInstance())); |
| 84 | 80 |
| 81 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); | |
| 82 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | |
| 83 | |
| 85 initial_show_state_ = browser_->GetSavedWindowShowState(); | 84 initial_show_state_ = browser_->GetSavedWindowShowState(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 BrowserWindowCocoa::~BrowserWindowCocoa() { | 87 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 89 } | 88 } |
| 90 | 89 |
| 91 void BrowserWindowCocoa::Show() { | 90 void BrowserWindowCocoa::Show() { |
| 92 // The Browser associated with this browser window must become the active | 91 // The Browser associated with this browser window must become the active |
| 93 // browser at the time |Show()| is called. This is the natural behaviour under | 92 // browser at the time |Show()| is called. This is the natural behaviour under |
| 94 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| | 93 // Windows, but |-makeKeyAndOrderFront:| won't send |-windowDidBecomeMain:| |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 // BrowserWindow object. | 550 // BrowserWindow object. |
| 552 FindBarBridge* bridge = new FindBarBridge(); | 551 FindBarBridge* bridge = new FindBarBridge(); |
| 553 AddFindBar(bridge->find_bar_cocoa_controller()); | 552 AddFindBar(bridge->find_bar_cocoa_controller()); |
| 554 return bridge; | 553 return bridge; |
| 555 } | 554 } |
| 556 | 555 |
| 557 void BrowserWindowCocoa::Observe(int type, | 556 void BrowserWindowCocoa::Observe(int type, |
| 558 const NotificationSource& source, | 557 const NotificationSource& source, |
| 559 const NotificationDetails& details) { | 558 const NotificationDetails& details) { |
| 560 switch (type) { | 559 switch (type) { |
| 561 // Only the key window gets a direct toggle from the menu. | 560 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 562 // Other windows hear about it from the notification. | 561 const std::string& pref_name = *Details<std::string>(details).ptr(); |
| 563 case chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 562 if (pref_name == prefs::kShowBookmarkBar) |
|
Miranda Callahan
2011/10/06 21:10:21
Maybe change this if statement to just a DCHECK(pr
Joao da Silva
2011/10/07 09:12:31
Done.
| |
| 564 if (browser_->profile()->IsSameProfile(Source<Profile>(source).ptr())) | |
| 565 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 563 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
| 564 else | |
| 565 NOTREACHED(); | |
| 566 break; | 566 break; |
| 567 } | |
| 567 case chrome::NOTIFICATION_SIDEBAR_CHANGED: | 568 case chrome::NOTIFICATION_SIDEBAR_CHANGED: |
| 568 UpdateSidebarForContents( | 569 UpdateSidebarForContents( |
| 569 Details<SidebarContainer>(details)->tab_contents()); | 570 Details<SidebarContainer>(details)->tab_contents()); |
| 570 break; | 571 break; |
| 571 default: | 572 default: |
| 572 NOTREACHED(); // we don't ask for anything else! | 573 NOTREACHED(); // we don't ask for anything else! |
| 573 break; | 574 break; |
| 574 } | 575 } |
| 575 } | 576 } |
| 576 | 577 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 597 NSPoint point = NSMakePoint(rect.right(), rect.bottom()); | 598 NSPoint point = NSMakePoint(rect.right(), rect.bottom()); |
| 598 point = [view convertPoint:point toView:nil]; | 599 point = [view convertPoint:point toView:nil]; |
| 599 point = [[view window] convertBaseToScreen:point]; | 600 point = [[view window] convertBaseToScreen:point]; |
| 600 | 601 |
| 601 // |menu| will automatically release itself on close. | 602 // |menu| will automatically release itself on close. |
| 602 AvatarMenuBubbleController* menu = | 603 AvatarMenuBubbleController* menu = |
| 603 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | 604 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
| 604 anchoredAt:point]; | 605 anchoredAt:point]; |
| 605 [menu showWindow:nil]; | 606 [menu showWindow:nil]; |
| 606 } | 607 } |
| OLD | NEW |