| 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" |
| 11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 #include "chrome/browser/download/download_shelf.h" | 14 #include "chrome/browser/download/download_shelf.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/sidebar/sidebar_container.h" | |
| 18 #include "chrome/browser/sidebar/sidebar_manager.h" | |
| 19 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 21 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" | 19 #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
| 22 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" | 20 #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
| 23 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" | 21 #import "chrome/browser/ui/cocoa/browser/edit_search_engine_cocoa_controller.h" |
| 24 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 22 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 25 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 23 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 26 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 24 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 27 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h" | 25 #import "chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.h" |
| 28 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" | 26 #import "chrome/browser/ui/cocoa/download/download_shelf_controller.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; | 66 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; |
| 69 @end | 67 @end |
| 70 | 68 |
| 71 #endif // MAC_OS_X_VERSION_10_7 | 69 #endif // MAC_OS_X_VERSION_10_7 |
| 72 | 70 |
| 73 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 71 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 74 BrowserWindowController* controller) | 72 BrowserWindowController* controller) |
| 75 : browser_(browser), | 73 : browser_(browser), |
| 76 controller_(controller), | 74 controller_(controller), |
| 77 confirm_close_factory_(browser) { | 75 confirm_close_factory_(browser) { |
| 78 registrar_.Add( | |
| 79 this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | |
| 80 content::Source<SidebarManager>(SidebarManager::GetInstance())); | |
| 81 | 76 |
| 82 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); | 77 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); |
| 83 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 78 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 84 | 79 |
| 85 initial_show_state_ = browser_->GetSavedWindowShowState(); | 80 initial_show_state_ = browser_->GetSavedWindowShowState(); |
| 86 } | 81 } |
| 87 | 82 |
| 88 BrowserWindowCocoa::~BrowserWindowCocoa() { | 83 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 89 } | 84 } |
| 90 | 85 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 const content::NotificationSource& source, | 568 const content::NotificationSource& source, |
| 574 const content::NotificationDetails& details) { | 569 const content::NotificationDetails& details) { |
| 575 switch (type) { | 570 switch (type) { |
| 576 case chrome::NOTIFICATION_PREF_CHANGED: { | 571 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 577 const std::string& pref_name = | 572 const std::string& pref_name = |
| 578 *content::Details<std::string>(details).ptr(); | 573 *content::Details<std::string>(details).ptr(); |
| 579 DCHECK(pref_name == prefs::kShowBookmarkBar); | 574 DCHECK(pref_name == prefs::kShowBookmarkBar); |
| 580 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 575 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
| 581 break; | 576 break; |
| 582 } | 577 } |
| 583 case chrome::NOTIFICATION_SIDEBAR_CHANGED: | |
| 584 UpdateSidebarForContents( | |
| 585 content::Details<SidebarContainer>(details)->tab_contents()); | |
| 586 break; | |
| 587 default: | 578 default: |
| 588 NOTREACHED(); // we don't ask for anything else! | 579 NOTREACHED(); // we don't ask for anything else! |
| 589 break; | 580 break; |
| 590 } | 581 } |
| 591 } | 582 } |
| 592 | 583 |
| 593 void BrowserWindowCocoa::DestroyBrowser() { | 584 void BrowserWindowCocoa::DestroyBrowser() { |
| 594 [controller_ destroyBrowser]; | 585 [controller_ destroyBrowser]; |
| 595 | 586 |
| 596 // at this point the controller is dead (autoreleased), so | 587 // at this point the controller is dead (autoreleased), so |
| 597 // make sure we don't try to reference it any more. | 588 // make sure we don't try to reference it any more. |
| 598 } | 589 } |
| 599 | 590 |
| 600 NSWindow* BrowserWindowCocoa::window() const { | 591 NSWindow* BrowserWindowCocoa::window() const { |
| 601 return [controller_ window]; | 592 return [controller_ window]; |
| 602 } | 593 } |
| 603 | 594 |
| 604 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | |
| 605 if (tab_contents == browser_->GetSelectedTabContents()) { | |
| 606 [controller_ updateSidebarForContents:tab_contents]; | |
| 607 } | |
| 608 } | |
| 609 | |
| 610 void BrowserWindowCocoa::ShowAvatarBubble(TabContents* tab_contents, | 595 void BrowserWindowCocoa::ShowAvatarBubble(TabContents* tab_contents, |
| 611 const gfx::Rect& rect) { | 596 const gfx::Rect& rect) { |
| 612 NSView* view = tab_contents->GetNativeView(); | 597 NSView* view = tab_contents->GetNativeView(); |
| 613 NSRect bounds = [view bounds]; | 598 NSRect bounds = [view bounds]; |
| 614 NSPoint point; | 599 NSPoint point; |
| 615 point.x = NSMinX(bounds) + rect.right(); | 600 point.x = NSMinX(bounds) + rect.right(); |
| 616 // The view's origin is at the bottom but |rect|'s origin is at the top. | 601 // The view's origin is at the bottom but |rect|'s origin is at the top. |
| 617 point.y = NSMaxY(bounds) - rect.bottom(); | 602 point.y = NSMaxY(bounds) - rect.bottom(); |
| 618 point = [view convertPoint:point toView:nil]; | 603 point = [view convertPoint:point toView:nil]; |
| 619 point = [[view window] convertBaseToScreen:point]; | 604 point = [[view window] convertBaseToScreen:point]; |
| 620 | 605 |
| 621 // |menu| will automatically release itself on close. | 606 // |menu| will automatically release itself on close. |
| 622 AvatarMenuBubbleController* menu = | 607 AvatarMenuBubbleController* menu = |
| 623 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | 608 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
| 624 anchoredAt:point]; | 609 anchoredAt:point]; |
| 625 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | 610 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
| 626 [menu showWindow:nil]; | 611 [menu showWindow:nil]; |
| 627 } | 612 } |
| 628 | 613 |
| 629 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { | 614 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { |
| 630 [[controller_ avatarButtonController] showAvatarBubble]; | 615 [[controller_ avatarButtonController] showAvatarBubble]; |
| 631 } | 616 } |
| OLD | NEW |