| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; | 69 - (void)setAnimationBehavior:(NSWindowAnimationBehavior)newAnimationBehavior; |
| 72 @end | 70 @end |
| 73 | 71 |
| 74 #endif // MAC_OS_X_VERSION_10_7 | 72 #endif // MAC_OS_X_VERSION_10_7 |
| 75 | 73 |
| 76 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, | 74 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, |
| 77 BrowserWindowController* controller) | 75 BrowserWindowController* controller) |
| 78 : browser_(browser), | 76 : browser_(browser), |
| 79 controller_(controller), | 77 controller_(controller), |
| 80 confirm_close_factory_(browser) { | 78 confirm_close_factory_(browser) { |
| 81 registrar_.Add( | |
| 82 this, chrome::NOTIFICATION_SIDEBAR_CHANGED, | |
| 83 content::Source<SidebarManager>(SidebarManager::GetInstance())); | |
| 84 | 79 |
| 85 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); | 80 pref_change_registrar_.Init(browser_->profile()->GetPrefs()); |
| 86 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); | 81 pref_change_registrar_.Add(prefs::kShowBookmarkBar, this); |
| 87 | 82 |
| 88 initial_show_state_ = browser_->GetSavedWindowShowState(); | 83 initial_show_state_ = browser_->GetSavedWindowShowState(); |
| 89 } | 84 } |
| 90 | 85 |
| 91 BrowserWindowCocoa::~BrowserWindowCocoa() { | 86 BrowserWindowCocoa::~BrowserWindowCocoa() { |
| 92 } | 87 } |
| 93 | 88 |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 const content::NotificationSource& source, | 575 const content::NotificationSource& source, |
| 581 const content::NotificationDetails& details) { | 576 const content::NotificationDetails& details) { |
| 582 switch (type) { | 577 switch (type) { |
| 583 case chrome::NOTIFICATION_PREF_CHANGED: { | 578 case chrome::NOTIFICATION_PREF_CHANGED: { |
| 584 const std::string& pref_name = | 579 const std::string& pref_name = |
| 585 *content::Details<std::string>(details).ptr(); | 580 *content::Details<std::string>(details).ptr(); |
| 586 DCHECK(pref_name == prefs::kShowBookmarkBar); | 581 DCHECK(pref_name == prefs::kShowBookmarkBar); |
| 587 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; | 582 [controller_ updateBookmarkBarVisibilityWithAnimation:YES]; |
| 588 break; | 583 break; |
| 589 } | 584 } |
| 590 case chrome::NOTIFICATION_SIDEBAR_CHANGED: | |
| 591 UpdateSidebarForContents( | |
| 592 content::Details<SidebarContainer>(details)->tab_contents()); | |
| 593 break; | |
| 594 default: | 585 default: |
| 595 NOTREACHED(); // we don't ask for anything else! | 586 NOTREACHED(); // we don't ask for anything else! |
| 596 break; | 587 break; |
| 597 } | 588 } |
| 598 } | 589 } |
| 599 | 590 |
| 600 void BrowserWindowCocoa::DestroyBrowser() { | 591 void BrowserWindowCocoa::DestroyBrowser() { |
| 601 [controller_ destroyBrowser]; | 592 [controller_ destroyBrowser]; |
| 602 | 593 |
| 603 // at this point the controller is dead (autoreleased), so | 594 // at this point the controller is dead (autoreleased), so |
| 604 // make sure we don't try to reference it any more. | 595 // make sure we don't try to reference it any more. |
| 605 } | 596 } |
| 606 | 597 |
| 607 NSWindow* BrowserWindowCocoa::window() const { | 598 NSWindow* BrowserWindowCocoa::window() const { |
| 608 return [controller_ window]; | 599 return [controller_ window]; |
| 609 } | 600 } |
| 610 | 601 |
| 611 void BrowserWindowCocoa::UpdateSidebarForContents(TabContents* tab_contents) { | |
| 612 if (tab_contents == browser_->GetSelectedWebContents()) { | |
| 613 [controller_ updateSidebarForContents:tab_contents]; | |
| 614 } | |
| 615 } | |
| 616 | |
| 617 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, | 602 void BrowserWindowCocoa::ShowAvatarBubble(WebContents* web_contents, |
| 618 const gfx::Rect& rect) { | 603 const gfx::Rect& rect) { |
| 619 NSView* view = web_contents->GetNativeView(); | 604 NSView* view = web_contents->GetNativeView(); |
| 620 NSRect bounds = [view bounds]; | 605 NSRect bounds = [view bounds]; |
| 621 NSPoint point; | 606 NSPoint point; |
| 622 point.x = NSMinX(bounds) + rect.right(); | 607 point.x = NSMinX(bounds) + rect.right(); |
| 623 // The view's origin is at the bottom but |rect|'s origin is at the top. | 608 // The view's origin is at the bottom but |rect|'s origin is at the top. |
| 624 point.y = NSMaxY(bounds) - rect.bottom(); | 609 point.y = NSMaxY(bounds) - rect.bottom(); |
| 625 point = [view convertPoint:point toView:nil]; | 610 point = [view convertPoint:point toView:nil]; |
| 626 point = [[view window] convertBaseToScreen:point]; | 611 point = [[view window] convertBaseToScreen:point]; |
| 627 | 612 |
| 628 // |menu| will automatically release itself on close. | 613 // |menu| will automatically release itself on close. |
| 629 AvatarMenuBubbleController* menu = | 614 AvatarMenuBubbleController* menu = |
| 630 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | 615 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
| 631 anchoredAt:point]; | 616 anchoredAt:point]; |
| 632 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | 617 [[menu bubble] setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
| 633 [menu showWindow:nil]; | 618 [menu showWindow:nil]; |
| 634 } | 619 } |
| 635 | 620 |
| 636 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { | 621 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton() { |
| 637 [[controller_ avatarButtonController] showAvatarBubble]; | 622 [[controller_ avatarButtonController] showAvatarBubble]; |
| 638 } | 623 } |
| OLD | NEW |