Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_controller.mm

Issue 9015022: Replace most of Browser::GetSelectedTabContents calls into Browser::GetSelectedWebContents. I've ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 } 518 }
519 519
520 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window { 520 - (void)removeConstrainedWindow:(ConstrainedWindowMac*)window {
521 [tabStripController_ removeConstrainedWindow:window]; 521 [tabStripController_ removeConstrainedWindow:window];
522 } 522 }
523 523
524 - (BOOL)canAttachConstrainedWindow { 524 - (BOOL)canAttachConstrainedWindow {
525 return ![previewableContentsController_ isShowingPreview]; 525 return ![previewableContentsController_ isShowingPreview];
526 } 526 }
527 527
528 - (void)updateDevToolsForContents:(TabContents*)contents { 528 - (void)updateDevToolsForContents:(WebContents*)contents {
529 [devToolsController_ updateDevToolsForTabContents:contents 529 [devToolsController_ updateDevToolsForWebContents:contents
530 withProfile:browser_->profile()]; 530 withProfile:browser_->profile()];
531 [devToolsController_ ensureContentsVisible]; 531 [devToolsController_ ensureContentsVisible];
532 } 532 }
533 533
534 - (void)setDevToolsDockToRight:(bool)dock_to_right { 534 - (void)setDevToolsDockToRight:(bool)dock_to_right {
535 [devToolsController_ setDockToRight:dock_to_right 535 [devToolsController_ setDockToRight:dock_to_right
536 withProfile:browser_->profile()]; 536 withProfile:browser_->profile()];
537 } 537 }
538 538
539 - (void)updateSidebarForContents:(TabContents*)contents { 539 - (void)updateSidebarForContents:(TabContents*)contents {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 594
595 // TODO(viettrungluu): For some reason, the above doesn't suffice. 595 // TODO(viettrungluu): For some reason, the above doesn't suffice.
596 if ([self isFullscreen]) 596 if ([self isFullscreen])
597 [floatingBarBackingView_ setNeedsDisplay:YES]; // Okay even if nil. 597 [floatingBarBackingView_ setNeedsDisplay:YES]; // Okay even if nil.
598 } 598 }
599 599
600 // Called when we are activated (when we gain focus). 600 // Called when we are activated (when we gain focus).
601 - (void)windowDidBecomeKey:(NSNotification*)notification { 601 - (void)windowDidBecomeKey:(NSNotification*)notification {
602 // We need to activate the controls (in the "WebView"). To do this, get the 602 // We need to activate the controls (in the "WebView"). To do this, get the
603 // selected TabContents's RenderWidgetHostViewMac and tell it to activate. 603 // selected TabContents's RenderWidgetHostViewMac and tell it to activate.
604 if (TabContents* contents = browser_->GetSelectedTabContents()) { 604 if (WebContents* contents = browser_->GetSelectedWebContents()) {
605 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 605 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
606 rwhv->SetActive(true); 606 rwhv->SetActive(true);
607 } 607 }
608 } 608 }
609 609
610 // Called when we are deactivated (when we lose focus). 610 // Called when we are deactivated (when we lose focus).
611 - (void)windowDidResignKey:(NSNotification*)notification { 611 - (void)windowDidResignKey:(NSNotification*)notification {
612 // If our app is still active and we're still the key window, ignore this 612 // If our app is still active and we're still the key window, ignore this
613 // message, since it just means that a menu extra (on the "system status bar") 613 // message, since it just means that a menu extra (on the "system status bar")
614 // was activated; we'll get another |-windowDidResignKey| if we ever really 614 // was activated; we'll get another |-windowDidResignKey| if we ever really
615 // lose key window status. 615 // lose key window status.
616 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) 616 if ([NSApp isActive] && ([NSApp keyWindow] == [self window]))
617 return; 617 return;
618 618
619 // We need to deactivate the controls (in the "WebView"). To do this, get the 619 // We need to deactivate the controls (in the "WebView"). To do this, get the
620 // selected TabContents's RenderWidgetHostView and tell it to deactivate. 620 // selected TabContents's RenderWidgetHostView and tell it to deactivate.
621 if (TabContents* contents = browser_->GetSelectedTabContents()) { 621 if (WebContents* contents = browser_->GetSelectedWebContents()) {
622 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 622 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
623 rwhv->SetActive(false); 623 rwhv->SetActive(false);
624 } 624 }
625 } 625 }
626 626
627 // Called when we have been minimized. 627 // Called when we have been minimized.
628 - (void)windowDidMiniaturize:(NSNotification *)notification { 628 - (void)windowDidMiniaturize:(NSNotification *)notification {
629 [self saveWindowPositionIfNeeded]; 629 [self saveWindowPositionIfNeeded];
630 630
631 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 631 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
632 if (TabContents* contents = browser_->GetSelectedTabContents()) { 632 if (WebContents* contents = browser_->GetSelectedWebContents()) {
633 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 633 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
634 rwhv->SetWindowVisibility(false); 634 rwhv->SetWindowVisibility(false);
635 } 635 }
636 } 636 }
637 637
638 // Called when we have been unminimized. 638 // Called when we have been unminimized.
639 - (void)windowDidDeminiaturize:(NSNotification *)notification { 639 - (void)windowDidDeminiaturize:(NSNotification *)notification {
640 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 640 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
641 if (TabContents* contents = browser_->GetSelectedTabContents()) { 641 if (WebContents* contents = browser_->GetSelectedWebContents()) {
642 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 642 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
643 rwhv->SetWindowVisibility(true); 643 rwhv->SetWindowVisibility(true);
644 } 644 }
645 } 645 }
646 646
647 // Called when the application has been hidden. 647 // Called when the application has been hidden.
648 - (void)applicationDidHide:(NSNotification *)notification { 648 - (void)applicationDidHide:(NSNotification *)notification {
649 // Let the selected RenderWidgetHostView know, so that it can tell plugins 649 // Let the selected RenderWidgetHostView know, so that it can tell plugins
650 // (unless we are minimized, in which case nothing has really changed). 650 // (unless we are minimized, in which case nothing has really changed).
651 if (![[self window] isMiniaturized]) { 651 if (![[self window] isMiniaturized]) {
652 if (TabContents* contents = browser_->GetSelectedTabContents()) { 652 if (WebContents* contents = browser_->GetSelectedWebContents()) {
653 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 653 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
654 rwhv->SetWindowVisibility(false); 654 rwhv->SetWindowVisibility(false);
655 } 655 }
656 } 656 }
657 } 657 }
658 658
659 // Called when the application has been unhidden. 659 // Called when the application has been unhidden.
660 - (void)applicationDidUnhide:(NSNotification *)notification { 660 - (void)applicationDidUnhide:(NSNotification *)notification {
661 // Let the selected RenderWidgetHostView know, so that it can tell plugins 661 // Let the selected RenderWidgetHostView know, so that it can tell plugins
662 // (unless we are minimized, in which case nothing has really changed). 662 // (unless we are minimized, in which case nothing has really changed).
663 if (![[self window] isMiniaturized]) { 663 if (![[self window] isMiniaturized]) {
664 if (TabContents* contents = browser_->GetSelectedTabContents()) { 664 if (WebContents* contents = browser_->GetSelectedWebContents()) {
665 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 665 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
666 rwhv->SetWindowVisibility(true); 666 rwhv->SetWindowVisibility(true);
667 } 667 }
668 } 668 }
669 } 669 }
670 670
671 // Called when the user clicks the zoom button (or selects it from the Window 671 // Called when the user clicks the zoom button (or selects it from the Window
672 // menu) to determine the "standard size" of the window, based on the content 672 // menu) to determine the "standard size" of the window, based on the content
673 // and other factors. If the current size/location differs nontrivally from the 673 // and other factors. If the current size/location differs nontrivally from the
674 // standard size, Cocoa resizes the window to the standard size, and saves the 674 // standard size, Cocoa resizes the window to the standard size, and saves the
(...skipping 24 matching lines...) Expand all
699 } 699 }
700 700
701 // To prevent strange results on portrait displays, the basic minimum zoomed 701 // To prevent strange results on portrait displays, the basic minimum zoomed
702 // width is the larger of: 60% of available width, 60% of available height 702 // width is the larger of: 60% of available width, 60% of available height
703 // (bounded by available width). 703 // (bounded by available width).
704 const CGFloat kProportion = 0.6; 704 const CGFloat kProportion = 0.6;
705 CGFloat zoomedWidth = 705 CGFloat zoomedWidth =
706 std::max(kProportion * frame.size.width, 706 std::max(kProportion * frame.size.width,
707 std::min(kProportion * frame.size.height, frame.size.width)); 707 std::min(kProportion * frame.size.height, frame.size.width));
708 708
709 TabContents* contents = browser_->GetSelectedTabContents(); 709 WebContents* contents = browser_->GetSelectedWebContents();
710 if (contents) { 710 if (contents) {
711 // If the intrinsic width is bigger, then make it the zoomed width. 711 // If the intrinsic width is bigger, then make it the zoomed width.
712 const int kScrollbarWidth = 16; // TODO(viettrungluu): ugh. 712 const int kScrollbarWidth = 16; // TODO(viettrungluu): ugh.
713 TabContentsViewMac* tab_contents_view = 713 TabContentsViewMac* tab_contents_view =
714 static_cast<TabContentsViewMac*>(contents->GetView()); 714 static_cast<TabContentsViewMac*>(contents->GetView());
715 CGFloat intrinsicWidth = static_cast<CGFloat>( 715 CGFloat intrinsicWidth = static_cast<CGFloat>(
716 tab_contents_view->preferred_width() + kScrollbarWidth); 716 tab_contents_view->preferred_width() + kScrollbarWidth);
717 zoomedWidth = std::max(zoomedWidth, 717 zoomedWidth = std::max(zoomedWidth,
718 std::min(intrinsicWidth, frame.size.width)); 718 std::min(intrinsicWidth, frame.size.width));
719 } 719 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 } 959 }
960 960
961 // Update the checked/Unchecked state of items in the encoding menu. 961 // Update the checked/Unchecked state of items in the encoding menu.
962 // On Windows, this logic is part of |EncodingMenuModel| in 962 // On Windows, this logic is part of |EncodingMenuModel| in
963 // browser/ui/views/toolbar_view.h. 963 // browser/ui/views/toolbar_view.h.
964 EncodingMenuController encoding_controller; 964 EncodingMenuController encoding_controller;
965 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) { 965 if (encoding_controller.DoesCommandBelongToEncodingMenu(tag)) {
966 DCHECK(browser_.get()); 966 DCHECK(browser_.get());
967 Profile* profile = browser_->profile(); 967 Profile* profile = browser_->profile();
968 DCHECK(profile); 968 DCHECK(profile);
969 TabContents* current_tab = browser_->GetSelectedTabContents(); 969 WebContents* current_tab = browser_->GetSelectedWebContents();
970 if (!current_tab) { 970 if (!current_tab) {
971 return; 971 return;
972 } 972 }
973 const std::string encoding = current_tab->GetEncoding(); 973 const std::string encoding = current_tab->GetEncoding();
974 974
975 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag); 975 bool toggled = encoding_controller.IsItemChecked(profile, encoding, tag);
976 NSInteger oldState = [item state]; 976 NSInteger oldState = [item state];
977 NSInteger newState = toggled ? NSOnState : NSOffState; 977 NSInteger newState = toggled ? NSOnState : NSOffState;
978 if (oldState != newState) 978 if (oldState != newState)
979 [item setState:newState]; 979 [item setState:newState];
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 - (NSInteger)numberOfTabs { 1455 - (NSInteger)numberOfTabs {
1456 // count() includes pinned tabs. 1456 // count() includes pinned tabs.
1457 return browser_->tabstrip_model()->count(); 1457 return browser_->tabstrip_model()->count();
1458 } 1458 }
1459 1459
1460 - (BOOL)hasLiveTabs { 1460 - (BOOL)hasLiveTabs {
1461 return !browser_->tabstrip_model()->empty(); 1461 return !browser_->tabstrip_model()->empty();
1462 } 1462 }
1463 1463
1464 - (NSString*)activeTabTitle { 1464 - (NSString*)activeTabTitle {
1465 TabContents* contents = browser_->GetSelectedTabContents(); 1465 WebContents* contents = browser_->GetSelectedWebContents();
1466 return base::SysUTF16ToNSString(contents->GetTitle()); 1466 return base::SysUTF16ToNSString(contents->GetTitle());
1467 } 1467 }
1468 1468
1469 - (NSRect)regularWindowFrame { 1469 - (NSRect)regularWindowFrame {
1470 return [self isFullscreen] ? savedRegularWindowFrame_ : 1470 return [self isFullscreen] ? savedRegularWindowFrame_ :
1471 [[self window] frame]; 1471 [[self window] frame];
1472 } 1472 }
1473 1473
1474 // (Override of |TabWindowController| method.) 1474 // (Override of |TabWindowController| method.)
1475 - (BOOL)hasTabStrip { 1475 - (BOOL)hasTabStrip {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 1519
1520 // TabStripControllerDelegate protocol. 1520 // TabStripControllerDelegate protocol.
1521 - (void)onActivateTabWithContents:(TabContents*)contents { 1521 - (void)onActivateTabWithContents:(TabContents*)contents {
1522 // Update various elements that are interested in knowing the current 1522 // Update various elements that are interested in knowing the current
1523 // TabContents. 1523 // TabContents.
1524 1524
1525 // Update all the UI bits. 1525 // Update all the UI bits.
1526 windowShim_->UpdateTitleBar(); 1526 windowShim_->UpdateTitleBar();
1527 1527
1528 [sidebarController_ updateSidebarForTabContents:contents]; 1528 [sidebarController_ updateSidebarForTabContents:contents];
1529 [devToolsController_ updateDevToolsForTabContents:contents 1529 [devToolsController_ updateDevToolsForWebContents:contents
1530 withProfile:browser_->profile()]; 1530 withProfile:browser_->profile()];
1531 1531
1532 // Update the bookmark bar. 1532 // Update the bookmark bar.
1533 // Must do it after sidebar and devtools update, otherwise bookmark bar might 1533 // Must do it after sidebar and devtools update, otherwise bookmark bar might
1534 // call resizeView -> layoutSubviews and cause unnecessary relayout. 1534 // call resizeView -> layoutSubviews and cause unnecessary relayout.
1535 // TODO(viettrungluu): perhaps update to not terminate running animations (if 1535 // TODO(viettrungluu): perhaps update to not terminate running animations (if
1536 // applicable)? 1536 // applicable)?
1537 [self updateBookmarkBarVisibilityWithAnimation:NO]; 1537 [self updateBookmarkBarVisibilityWithAnimation:NO];
1538 1538
1539 TabContentsWrapper* wrapper = 1539 TabContentsWrapper* wrapper =
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1732 - (void)windowDidResize:(NSNotification*)notification { 1732 - (void)windowDidResize:(NSNotification*)notification {
1733 [self saveWindowPositionIfNeeded]; 1733 [self saveWindowPositionIfNeeded];
1734 1734
1735 // Resize (and possibly move) the status bubble. Note that we may get called 1735 // Resize (and possibly move) the status bubble. Note that we may get called
1736 // when the status bubble does not exist. 1736 // when the status bubble does not exist.
1737 if (statusBubble_) { 1737 if (statusBubble_) {
1738 statusBubble_->UpdateSizeAndPosition(); 1738 statusBubble_->UpdateSizeAndPosition();
1739 } 1739 }
1740 1740
1741 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 1741 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
1742 if (TabContents* contents = browser_->GetSelectedTabContents()) { 1742 if (WebContents* contents = browser_->GetSelectedWebContents()) {
1743 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 1743 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
1744 rwhv->WindowFrameChanged(); 1744 rwhv->WindowFrameChanged();
1745 } 1745 }
1746 1746
1747 // The FindBar needs to know its own position to properly detect overlaps 1747 // The FindBar needs to know its own position to properly detect overlaps
1748 // with find results. The position changes whenever the window is resized, 1748 // with find results. The position changes whenever the window is resized,
1749 // and |layoutSubviews| computes the FindBar's position. 1749 // and |layoutSubviews| computes the FindBar's position.
1750 // TODO: calling |layoutSubviews| here is a waste, find a better way to 1750 // TODO: calling |layoutSubviews| here is a waste, find a better way to
1751 // do this. 1751 // do this.
1752 if ([findBarCocoaController_ isFindBarVisible]) 1752 if ([findBarCocoaController_ isFindBarVisible])
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 // |-windowWillMove| is called too early for us to apply our heuristic. (The 1788 // |-windowWillMove| is called too early for us to apply our heuristic. (The
1789 // heuristic we use for detecting window movement is that if |windowTopGrowth_ 1789 // heuristic we use for detecting window movement is that if |windowTopGrowth_
1790 // > 0|, then we should be at the bottom of the work area -- if we're not, 1790 // > 0|, then we should be at the bottom of the work area -- if we're not,
1791 // we've moved. Similarly for the other side.) 1791 // we've moved. Similarly for the other side.)
1792 if (!NSContainsRect(workarea, windowFrame) || 1792 if (!NSContainsRect(workarea, windowFrame) ||
1793 (windowTopGrowth_ > 0 && NSMinY(windowFrame) != NSMinY(workarea)) || 1793 (windowTopGrowth_ > 0 && NSMinY(windowFrame) != NSMinY(workarea)) ||
1794 (windowBottomGrowth_ > 0 && NSMaxY(windowFrame) != NSMaxY(workarea))) 1794 (windowBottomGrowth_ > 0 && NSMaxY(windowFrame) != NSMaxY(workarea)))
1795 [self resetWindowGrowthState]; 1795 [self resetWindowGrowthState];
1796 1796
1797 // Let the selected RenderWidgetHostView know, so that it can tell plugins. 1797 // Let the selected RenderWidgetHostView know, so that it can tell plugins.
1798 if (TabContents* contents = browser_->GetSelectedTabContents()) { 1798 if (WebContents* contents = browser_->GetSelectedWebContents()) {
1799 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView()) 1799 if (RenderWidgetHostView* rwhv = contents->GetRenderWidgetHostView())
1800 rwhv->WindowFrameChanged(); 1800 rwhv->WindowFrameChanged();
1801 } 1801 }
1802 } 1802 }
1803 1803
1804 // Delegate method called when window will be resized; not called for 1804 // Delegate method called when window will be resized; not called for
1805 // |-setFrame:display:|. 1805 // |-setFrame:display:|.
1806 - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize { 1806 - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize {
1807 [self resetWindowGrowthState]; 1807 [self resetWindowGrowthState];
1808 return frameSize; 1808 return frameSize;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2188 2188
2189 - (BOOL)supportsBookmarkBar { 2189 - (BOOL)supportsBookmarkBar {
2190 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2190 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2191 } 2191 }
2192 2192
2193 - (BOOL)isTabbedWindow { 2193 - (BOOL)isTabbedWindow {
2194 return browser_->is_type_tabbed(); 2194 return browser_->is_type_tabbed();
2195 } 2195 }
2196 2196
2197 @end // @implementation BrowserWindowController(WindowType) 2197 @end // @implementation BrowserWindowController(WindowType)
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_controller.h ('k') | chrome/browser/ui/cocoa/browser_window_controller_private.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698