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 16 matching lines...) Expand all Loading... |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
29 #include "chrome/browser/ui/browser_tabstrip.h" | 29 #include "chrome/browser/ui/browser_tabstrip.h" |
30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 30 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
31 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" | 31 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_sheet_con
troller.h" |
32 #include "chrome/browser/ui/cocoa/drag_util.h" | 32 #include "chrome/browser/ui/cocoa/drag_util.h" |
33 #import "chrome/browser/ui/cocoa/image_button_cell.h" | 33 #import "chrome/browser/ui/cocoa/image_button_cell.h" |
34 #import "chrome/browser/ui/cocoa/new_tab_button.h" | 34 #import "chrome/browser/ui/cocoa/new_tab_button.h" |
35 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" | 35 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
36 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 36 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
37 #import "chrome/browser/ui/cocoa/tabs/media_indicator_view.h" | 37 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button.h" |
38 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" | 38 #import "chrome/browser/ui/cocoa/tabs/tab_controller.h" |
39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" | 39 #import "chrome/browser/ui/cocoa/tabs/tab_strip_drag_controller.h" |
40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" | 40 #import "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h" |
41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" | 41 #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" |
42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" | 42 #import "chrome/browser/ui/cocoa/tabs/tab_view.h" |
43 #include "chrome/browser/ui/find_bar/find_bar.h" | 43 #include "chrome/browser/ui/find_bar/find_bar.h" |
44 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 44 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
45 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 45 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
46 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 46 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
47 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 47 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 } else if (modifiers & NSShiftKeyMask) { | 817 } else if (modifiers & NSShiftKeyMask) { |
818 tabStripModel_->ExtendSelectionTo(index); | 818 tabStripModel_->ExtendSelectionTo(index); |
819 } else if (modifiers & NSCommandKeyMask) { | 819 } else if (modifiers & NSCommandKeyMask) { |
820 tabStripModel_->ToggleSelectionAt(index); | 820 tabStripModel_->ToggleSelectionAt(index); |
821 } else { | 821 } else { |
822 tabStripModel_->ActivateTabAt(index, true); | 822 tabStripModel_->ActivateTabAt(index, true); |
823 } | 823 } |
824 } | 824 } |
825 } | 825 } |
826 | 826 |
| 827 // Called when the user clicks the tab audio indicator to mute the tab. |
| 828 - (void)toggleMute:(id)sender { |
| 829 DCHECK([sender isKindOfClass:[TabView class]]); |
| 830 NSInteger index = [self modelIndexForTabView:sender]; |
| 831 if (!tabStripModel_->ContainsIndex(index)) |
| 832 return; |
| 833 WebContents* contents = tabStripModel_->GetWebContentsAt(index); |
| 834 chrome::SetTabAudioMuted(contents, !chrome::IsTabAudioMuted(contents)); |
| 835 } |
| 836 |
827 // Called when the user closes a tab. Asks the model to close the tab. |sender| | 837 // Called when the user closes a tab. Asks the model to close the tab. |sender| |
828 // is the TabView that is potentially going away. | 838 // is the TabView that is potentially going away. |
829 - (void)closeTab:(id)sender { | 839 - (void)closeTab:(id)sender { |
830 DCHECK([sender isKindOfClass:[TabView class]]); | 840 DCHECK([sender isKindOfClass:[TabView class]]); |
831 | 841 |
832 // Cancel any pending tab transition. | 842 // Cancel any pending tab transition. |
833 hoverTabSelector_->CancelTabTransition(); | 843 hoverTabSelector_->CancelTabTransition(); |
834 | 844 |
835 if ([hoveredTab_ isEqual:sender]) { | 845 if ([hoveredTab_ isEqual:sender]) { |
836 hoveredTab_ = nil; | 846 hoveredTab_ = nil; |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1609 | 1619 |
1610 // While loading, this function is called repeatedly with the same state. | 1620 // While loading, this function is called repeatedly with the same state. |
1611 // To avoid expensive unnecessary view manipulation, only make changes when | 1621 // To avoid expensive unnecessary view manipulation, only make changes when |
1612 // the state is actually changing. When loading is complete (kTabDone), | 1622 // the state is actually changing. When loading is complete (kTabDone), |
1613 // every call to this function is significant. | 1623 // every call to this function is significant. |
1614 if (newState == kTabDone || oldState != newState || | 1624 if (newState == kTabDone || oldState != newState || |
1615 oldHasIcon != newHasIcon) { | 1625 oldHasIcon != newHasIcon) { |
1616 if (newHasIcon) { | 1626 if (newHasIcon) { |
1617 if (newState == kTabDone) { | 1627 if (newState == kTabDone) { |
1618 [tabController setIconImage:[self iconImageForContents:contents]]; | 1628 [tabController setIconImage:[self iconImageForContents:contents]]; |
1619 const TabMediaState mediaState = | |
1620 chrome::GetTabMediaStateForContents(contents); | |
1621 // Create MediaIndicatorView upon first use. | |
1622 if (mediaState != TAB_MEDIA_STATE_NONE && | |
1623 ![tabController mediaIndicatorView]) { | |
1624 MediaIndicatorView* const mediaIndicatorView = | |
1625 [[[MediaIndicatorView alloc] init] autorelease]; | |
1626 [tabController setMediaIndicatorView:mediaIndicatorView]; | |
1627 } | |
1628 [[tabController mediaIndicatorView] updateIndicator:mediaState]; | |
1629 } else if (newState == kTabCrashed) { | 1629 } else if (newState == kTabCrashed) { |
1630 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; | 1630 [tabController setIconImage:sadFaviconImage withToastAnimation:YES]; |
1631 [[tabController mediaIndicatorView] | |
1632 updateIndicator:TAB_MEDIA_STATE_NONE]; | |
1633 } else { | 1631 } else { |
1634 [tabController setIconImage:throbberImage]; | 1632 [tabController setIconImage:throbberImage]; |
1635 } | 1633 } |
1636 } else { | 1634 } else { |
1637 [tabController setIconImage:nil]; | 1635 [tabController setIconImage:nil]; |
1638 } | 1636 } |
1639 } | 1637 } |
| 1638 |
| 1639 [tabController setMediaState:chrome::GetTabMediaStateForContents(contents)]; |
| 1640 |
| 1641 [tabController updateVisibility]; |
1640 } | 1642 } |
1641 | 1643 |
1642 // Called when a notification is received from the model that the given tab | 1644 // Called when a notification is received from the model that the given tab |
1643 // has been updated. |loading| will be YES when we only want to update the | 1645 // has been updated. |loading| will be YES when we only want to update the |
1644 // throbber state, not anything else about the (partially) loading tab. | 1646 // throbber state, not anything else about the (partially) loading tab. |
1645 - (void)tabChangedWithContents:(content::WebContents*)contents | 1647 - (void)tabChangedWithContents:(content::WebContents*)contents |
1646 atIndex:(NSInteger)modelIndex | 1648 atIndex:(NSInteger)modelIndex |
1647 changeType:(TabStripModelObserver::TabChangeType)change { | 1649 changeType:(TabStripModelObserver::TabChangeType)change { |
1648 // Take closing tabs into account. | 1650 // Take closing tabs into account. |
1649 NSInteger index = [self indexFromModelIndex:modelIndex]; | 1651 NSInteger index = [self indexFromModelIndex:modelIndex]; |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2312 // up the hierarchy to the devtools container view to avoid that. Note that | 2314 // up the hierarchy to the devtools container view to avoid that. Note that |
2313 // the devtools view is always in the hierarchy even if it is not open or it | 2315 // the devtools view is always in the hierarchy even if it is not open or it |
2314 // is detached. | 2316 // is detached. |
2315 NSView* devtools_view = [[[view superview] superview] superview]; | 2317 NSView* devtools_view = [[[view superview] superview] superview]; |
2316 if (devtools_view) { | 2318 if (devtools_view) { |
2317 return [devtools_view convertRect:[devtools_view bounds] toView:nil]; | 2319 return [devtools_view convertRect:[devtools_view bounds] toView:nil]; |
2318 } else { | 2320 } else { |
2319 return [view convertRect:[view bounds] toView:nil]; | 2321 return [view convertRect:[view bounds] toView:nil]; |
2320 } | 2322 } |
2321 } | 2323 } |
OLD | NEW |