| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tabs/tab_strip_controller.h" | 5 #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_navigator.h" | 30 #include "chrome/browser/ui/browser_navigator.h" |
| 31 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
| 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 32 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 33 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 33 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
| 34 #include "chrome/browser/ui/cocoa/drag_util.h" | 34 #include "chrome/browser/ui/cocoa/drag_util.h" |
| 35 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 35 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
| 36 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 36 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
| 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" | 37 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
| 38 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 38 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 39 #import "chrome/browser/ui/cocoa/tabs/tab_audio_indicator_view_mac.h" | |
| 40 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 39 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
| 41 #import "chrome/browser/ui/cocoa/tabs/tab_projecting_image_view.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_projecting_image_view.h" |
| 42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
| 43 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
| 44 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 43 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
| 45 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 44 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
| 46 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 45 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
| 47 #import "chrome/browser/ui/cocoa/tabs/throbbing_image_view.h" | 46 #import "chrome/browser/ui/cocoa/tabs/throbbing_image_view.h" |
| 48 #include "chrome/browser/ui/find_bar/find_bar.h" | 47 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 49 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 48 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1613 if (oldState != newState) | 1612 if (oldState != newState) |
| 1614 [tabController setLoadingState:newState]; | 1613 [tabController setLoadingState:newState]; |
| 1615 | 1614 |
| 1616 // While loading, this function is called repeatedly with the same state. | 1615 // While loading, this function is called repeatedly with the same state. |
| 1617 // To avoid expensive unnecessary view manipulation, only make changes when | 1616 // To avoid expensive unnecessary view manipulation, only make changes when |
| 1618 // the state is actually changing. When loading is complete (kTabDone), | 1617 // the state is actually changing. When loading is complete (kTabDone), |
| 1619 // every call to this function is significant. | 1618 // every call to this function is significant. |
| 1620 if (newState == kTabDone || oldState != newState || | 1619 if (newState == kTabDone || oldState != newState || |
| 1621 oldHasIcon != newHasIcon) { | 1620 oldHasIcon != newHasIcon) { |
| 1622 NSView* iconView = nil; | 1621 NSView* iconView = nil; |
| 1622 NSImageView* audioIndicatorView = nil; |
| 1623 if (newHasIcon) { | 1623 if (newHasIcon) { |
| 1624 if (newState == kTabDone) { | 1624 if (newState == kTabDone) { |
| 1625 NSImageView* imageView = [self iconImageViewForContents:contents]; | 1625 NSImageView* imageView = [self iconImageViewForContents:contents]; |
| 1626 TabAudioIndicatorViewMac* tabAudioIndicatorViewMac = | |
| 1627 base::mac::ObjCCast<TabAudioIndicatorViewMac>( | |
| 1628 [tabController iconView]); | |
| 1629 | 1626 |
| 1630 ui::ThemeProvider* theme = [[tabStripView_ window] themeProvider]; | 1627 ui::ThemeProvider* theme = [[tabStripView_ window] themeProvider]; |
| 1631 if (theme && [tabController projecting]) { | 1628 if (theme && [tabController projecting]) { |
| 1632 NSImage* projectorGlow = | 1629 NSImage* projectorGlow = |
| 1633 theme->GetNSImageNamed(IDR_TAB_CAPTURE_GLOW); | 1630 theme->GetNSImageNamed(IDR_TAB_CAPTURE_GLOW); |
| 1634 NSImage* projector = theme->GetNSImageNamed(IDR_TAB_CAPTURE); | 1631 NSImage* projector = theme->GetNSImageNamed(IDR_TAB_CAPTURE); |
| 1635 | 1632 |
| 1636 NSRect frame = NSMakeRect(0, | 1633 NSRect frame = NSMakeRect(0, |
| 1637 0, | 1634 0, |
| 1638 kProjectingIconWidthAndHeight, | 1635 kProjectingIconWidthAndHeight, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1659 ThrobbingImageView* recordingView = | 1656 ThrobbingImageView* recordingView = |
| 1660 [[[ThrobbingImageView alloc] | 1657 [[[ThrobbingImageView alloc] |
| 1661 initWithFrame:frame | 1658 initWithFrame:frame |
| 1662 backgroundImage:favIconMasked | 1659 backgroundImage:favIconMasked |
| 1663 throbImage:recording | 1660 throbImage:recording |
| 1664 durationMS:kRecordingDurationMs | 1661 durationMS:kRecordingDurationMs |
| 1665 throbPosition:kThrobPositionBottomRight | 1662 throbPosition:kThrobPositionBottomRight |
| 1666 animationContainer:animationContainer_.get()] autorelease]; | 1663 animationContainer:animationContainer_.get()] autorelease]; |
| 1667 | 1664 |
| 1668 iconView = recordingView; | 1665 iconView = recordingView; |
| 1669 } else if (chrome::IsPlayingAudio(contents) || | |
| 1670 [tabAudioIndicatorViewMac isAnimating]) { | |
| 1671 if (!tabAudioIndicatorViewMac) { | |
| 1672 NSRect frame = | |
| 1673 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); | |
| 1674 tabAudioIndicatorViewMac = [[[TabAudioIndicatorViewMac alloc] | |
| 1675 initWithFrame:frame] autorelease]; | |
| 1676 [tabAudioIndicatorViewMac | |
| 1677 setAnimationContainer:animationContainer_.get()]; | |
| 1678 } | |
| 1679 [tabAudioIndicatorViewMac | |
| 1680 setIsPlayingAudio:chrome::IsPlayingAudio(contents)]; | |
| 1681 [tabAudioIndicatorViewMac setBackgroundImage:[imageView image]]; | |
| 1682 iconView = tabAudioIndicatorViewMac; | |
| 1683 } else { | 1666 } else { |
| 1684 iconView = imageView; | 1667 iconView = imageView; |
| 1668 |
| 1669 if (theme && chrome::IsPlayingAudio(contents)) { |
| 1670 NSImage* const image = |
| 1671 theme->GetNSImageNamed(IDR_TAB_AUDIO_INDICATOR); |
| 1672 if (image) { |
| 1673 NSRect frame; |
| 1674 frame.size = [image size]; |
| 1675 audioIndicatorView = |
| 1676 [[[NSImageView alloc] initWithFrame:frame] autorelease]; |
| 1677 [audioIndicatorView setImage:image]; |
| 1678 } |
| 1679 } |
| 1685 } | 1680 } |
| 1686 } else if (newState == kTabCrashed) { | 1681 } else if (newState == kTabCrashed) { |
| 1687 NSImage* oldImage = [[self iconImageViewForContents:contents] image]; | 1682 NSImage* oldImage = [[self iconImageViewForContents:contents] image]; |
| 1688 NSRect frame = | 1683 NSRect frame = |
| 1689 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); | 1684 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); |
| 1690 iconView = [ThrobberView toastThrobberViewWithFrame:frame | 1685 iconView = [ThrobberView toastThrobberViewWithFrame:frame |
| 1691 beforeImage:oldImage | 1686 beforeImage:oldImage |
| 1692 afterImage:sadFaviconImage]; | 1687 afterImage:sadFaviconImage]; |
| 1693 } else { | 1688 } else { |
| 1694 NSRect frame = | 1689 NSRect frame = |
| 1695 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); | 1690 NSMakeRect(0, 0, kIconWidthAndHeight, kIconWidthAndHeight); |
| 1696 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame | 1691 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame |
| 1697 image:throbberImage]; | 1692 image:throbberImage]; |
| 1698 } | 1693 } |
| 1699 } | 1694 } |
| 1700 | 1695 |
| 1701 [tabController setIconView:iconView]; | 1696 [tabController setIconView:iconView]; |
| 1702 if (iconView && ![tabController projecting]) { | 1697 if (iconView && ![tabController projecting]) { |
| 1703 // See the comment above kTabOverlap for why these DCHECKs exist. | 1698 // See the comment above kTabOverlap for why these DCHECKs exist. |
| 1704 DCHECK_GE(NSMinX([iconView frame]), kTabOverlap); | 1699 DCHECK_GE(NSMinX([iconView frame]), kTabOverlap); |
| 1705 // TODO(thakis): Ideally, this would be true too, but it's not true in | 1700 // TODO(thakis): Ideally, this would be true too, but it's not true in |
| 1706 // some tests. | 1701 // some tests. |
| 1707 //DCHECK_LE(NSMaxX([iconView frame]), | 1702 //DCHECK_LE(NSMaxX([iconView frame]), |
| 1708 // NSWidth([[tabController view] frame]) - kTabOverlap); | 1703 // NSWidth([[tabController view] frame]) - kTabOverlap); |
| 1709 } | 1704 } |
| 1705 [tabController setAudioIndicatorView:audioIndicatorView]; |
| 1710 } | 1706 } |
| 1711 } | 1707 } |
| 1712 | 1708 |
| 1713 // Called when a notification is received from the model that the given tab | 1709 // Called when a notification is received from the model that the given tab |
| 1714 // has been updated. |loading| will be YES when we only want to update the | 1710 // has been updated. |loading| will be YES when we only want to update the |
| 1715 // throbber state, not anything else about the (partially) loading tab. | 1711 // throbber state, not anything else about the (partially) loading tab. |
| 1716 - (void)tabChangedWithContents:(content::WebContents*)contents | 1712 - (void)tabChangedWithContents:(content::WebContents*)contents |
| 1717 atIndex:(NSInteger)modelIndex | 1713 atIndex:(NSInteger)modelIndex |
| 1718 changeType:(TabStripModelObserver::TabChangeType)change { | 1714 changeType:(TabStripModelObserver::TabChangeType)change { |
| 1719 // Take closing tabs into account. | 1715 // Take closing tabs into account. |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2309 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { | 2305 NSView* GetSheetParentViewForWebContents(WebContents* web_contents) { |
| 2310 // View hierarchy of the contents view: | 2306 // View hierarchy of the contents view: |
| 2311 // NSView -- switchView, same for all tabs | 2307 // NSView -- switchView, same for all tabs |
| 2312 // +- NSView -- TabContentsController's view | 2308 // +- NSView -- TabContentsController's view |
| 2313 // +- TabContentsViewCocoa | 2309 // +- TabContentsViewCocoa |
| 2314 // | 2310 // |
| 2315 // Changing it? Do not forget to modify | 2311 // Changing it? Do not forget to modify |
| 2316 // -[TabStripController swapInTabAtIndex:] too. | 2312 // -[TabStripController swapInTabAtIndex:] too. |
| 2317 return [web_contents->GetView()->GetNativeView() superview]; | 2313 return [web_contents->GetView()->GetNativeView() superview]; |
| 2318 } | 2314 } |
| OLD | NEW |