| 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 #ifndef CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ | 5 #ifndef CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ |
| 6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ | 6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "content/public/browser/web_contents_user_data.h" | 13 #include "content/public/browser/web_contents_user_data.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 15 | 15 |
| 16 class TabStripModel; | 16 class TabStripModel; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 class WebContents; | 19 class WebContents; |
| 20 } // namespace content | 20 } // namespace content |
| 21 | 21 |
| 22 namespace gfx { | 22 namespace gfx { |
| 23 class Animation; | 23 class Animation; |
| 24 class Image; | 24 class Image; |
| 25 } // namespace gfx | 25 } // namespace gfx |
| 26 | 26 |
| 27 // Media state for a tab. In reality, more than one of these may apply. See | 27 // Alert state for a tab. In reality, more than one of these may apply. See |
| 28 // comments for GetTabMediaStateForContents() below. | 28 // comments for GetTabAlertStateForContents() below. |
| 29 enum TabMediaState { | 29 enum class TabAlertState { |
| 30 TAB_MEDIA_STATE_NONE, | 30 NONE, |
| 31 TAB_MEDIA_STATE_RECORDING, // Audio/Video being recorded, consumed by tab. | 31 MEDIA_RECORDING, // Audio/Video being recorded, consumed by tab. |
| 32 TAB_MEDIA_STATE_CAPTURING, // Tab contents being captured. | 32 TAB_CAPTURING, // Tab contents being captured. |
| 33 TAB_MEDIA_STATE_AUDIO_PLAYING, // Audible audio is playing from the tab. | 33 AUDIO_PLAYING, // Audible audio is playing from the tab. |
| 34 TAB_MEDIA_STATE_AUDIO_MUTING, // Tab audio is being muted. | 34 AUDIO_MUTING, // Tab audio is being muted. |
| 35 TAB_MEDIA_STATE_BLUETOOTH_CONNECTED, // Tab is connected to a BT Device. | 35 BLUETOOTH_CONNECTED, // Tab is connected to a BT Device. |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 enum TabMutedReason { | 38 enum class TabMutedReason { |
| 39 TAB_MUTED_REASON_NONE, // The tab has never been muted or unmuted. | 39 NONE, // The tab has never been muted or unmuted. |
| 40 TAB_MUTED_REASON_CONTEXT_MENU, // Mute/Unmute chosen from tab context menu. | 40 CONTEXT_MENU, // Mute/Unmute chosen from tab context menu. |
| 41 TAB_MUTED_REASON_AUDIO_INDICATOR, // Mute toggled via tab-strip audio icon. | 41 AUDIO_INDICATOR, // Mute toggled via tab-strip audio icon. |
| 42 TAB_MUTED_REASON_MEDIA_CAPTURE, // Media recording/capture was started. | 42 MEDIA_CAPTURE, // Media recording/capture was started. |
| 43 TAB_MUTED_REASON_EXTENSION, // Mute state changed via extension API. | 43 EXTENSION, // Mute state changed via extension API. |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 enum TabMutedResult { | 46 enum class TabMutedResult { |
| 47 TAB_MUTED_RESULT_SUCCESS, | 47 SUCCESS, |
| 48 TAB_MUTED_RESULT_FAIL_NOT_ENABLED, | 48 FAIL_NOT_ENABLED, |
| 49 TAB_MUTED_RESULT_FAIL_TABCAPTURE, | 49 FAIL_TABCAPTURE, |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 namespace chrome { | 52 namespace chrome { |
| 53 | 53 |
| 54 // Logic to determine which components (i.e., close button, favicon, and media | 54 // Logic to determine which components (i.e., close button, favicon, and alert |
| 55 // indicator) of a tab should be shown, given current state. |capacity| | 55 // indicator) of a tab should be shown, given current state. |capacity| |
| 56 // specifies how many components can be shown, given available tab width. | 56 // specifies how many components can be shown, given available tab width. |
| 57 // | 57 // |
| 58 // Precedence rules for deciding what to show when capacity is insufficient to | 58 // Precedence rules for deciding what to show when capacity is insufficient to |
| 59 // show everything: | 59 // show everything: |
| 60 // | 60 // |
| 61 // Active tab: Always show the close button, then the media indicator, then | 61 // Active tab: Always show the close button, then the alert indicator, then |
| 62 // the favicon. | 62 // the favicon. |
| 63 // Inactive tab: Media indicator, then the favicon, then the close button. | 63 // Inactive tab: Alert indicator, then the favicon, then the close button. |
| 64 // Pinned tab: Show only the media indicator, or only the favicon | 64 // Pinned tab: Show only the alert indicator, or only the favicon |
| 65 // (TAB_MEDIA_STATE_NONE). Never show the close button. | 65 // (TabAlertState::NONE). Never show the close button. |
| 66 bool ShouldTabShowFavicon(int capacity, | 66 bool ShouldTabShowFavicon(int capacity, |
| 67 bool is_pinned_tab, | 67 bool is_pinned_tab, |
| 68 bool is_active_tab, | 68 bool is_active_tab, |
| 69 bool has_favicon, | 69 bool has_favicon, |
| 70 TabMediaState media_state); | 70 TabAlertState alert_state); |
| 71 bool ShouldTabShowMediaIndicator(int capacity, | 71 bool ShouldTabShowAlertIndicator(int capacity, |
| 72 bool is_pinned_tab, | 72 bool is_pinned_tab, |
| 73 bool is_active_tab, | 73 bool is_active_tab, |
| 74 bool has_favicon, | 74 bool has_favicon, |
| 75 TabMediaState media_state); | 75 TabAlertState alert_state); |
| 76 bool ShouldTabShowCloseButton(int capacity, | 76 bool ShouldTabShowCloseButton(int capacity, |
| 77 bool is_pinned_tab, | 77 bool is_pinned_tab, |
| 78 bool is_active_tab); | 78 bool is_active_tab); |
| 79 | 79 |
| 80 // Returns the media state to be shown by the tab's media indicator. When | 80 // Returns the alert state to be shown by the tab's alert indicator. When |
| 81 // multiple states apply (e.g., tab capture with audio playback), the one most | 81 // multiple states apply (e.g., tab capture with audio playback), the one most |
| 82 // relevant to user privacy concerns is selected. | 82 // relevant to user privacy concerns is selected. |
| 83 TabMediaState GetTabMediaStateForContents(content::WebContents* contents); | 83 TabAlertState GetTabAlertStateForContents(content::WebContents* contents); |
| 84 | 84 |
| 85 // Returns a cached image, to be shown by the media indicator for the given | 85 // Returns a cached image, to be shown by the alert indicator for the given |
| 86 // |media_state|. Uses the global ui::ResourceBundle shared instance. | 86 // |alert_state|. Uses the global ui::ResourceBundle shared instance. |
| 87 gfx::Image GetTabMediaIndicatorImage(TabMediaState media_state, | 87 gfx::Image GetTabAlertIndicatorImage(TabAlertState alert_state, |
| 88 SkColor button_color); | 88 SkColor button_color); |
| 89 | 89 |
| 90 // Returns the cached image, to be shown by the media indicator button for mouse | 90 // Returns the cached image, to be shown by the alert indicator button for mouse |
| 91 // hover/pressed, when the indicator is in the given |media_state|. Uses the | 91 // hover/pressed, when the indicator is in the given |alert_state|. Uses the |
| 92 // global ui::ResourceBundle shared instance. | 92 // global ui::ResourceBundle shared instance. |
| 93 gfx::Image GetTabMediaIndicatorAffordanceImage(TabMediaState media_state, | 93 gfx::Image GetTabAlertIndicatorAffordanceImage(TabAlertState alert_state, |
| 94 SkColor button_color); | 94 SkColor button_color); |
| 95 | 95 |
| 96 // Returns a non-continuous Animation that performs a fade-in or fade-out | 96 // Returns a non-continuous Animation that performs a fade-in or fade-out |
| 97 // appropriate for the given |next_media_state|. This is used by the tab media | 97 // appropriate for the given |next_alert_state|. This is used by the tab alert |
| 98 // indicator to alert the user that recording, tab capture, or audio playback | 98 // indicator to alert the user that recording, tab capture, or audio playback |
| 99 // has started/stopped. | 99 // has started/stopped. |
| 100 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation( | 100 scoped_ptr<gfx::Animation> CreateTabAlertIndicatorFadeAnimation( |
| 101 TabMediaState next_media_state); | 101 TabAlertState next_alert_state); |
| 102 | 102 |
| 103 // Returns the text to show in a tab's tooltip: The contents |title|, followed | 103 // Returns the text to show in a tab's tooltip: The contents |title|, followed |
| 104 // by a break, followed by a localized string describing the |media_state|. | 104 // by a break, followed by a localized string describing the |alert_state|. |
| 105 base::string16 AssembleTabTooltipText(const base::string16& title, | 105 base::string16 AssembleTabTooltipText(const base::string16& title, |
| 106 TabMediaState media_state); | 106 TabAlertState alert_state); |
| 107 | 107 |
| 108 // Returns true if experimental audio mute controls (UI or extension API) are | 108 // Returns true if experimental audio mute controls (UI or extension API) are |
| 109 // enabled. Currently, toggling mute from a tab's context menu is the only | 109 // enabled. Currently, toggling mute from a tab's context menu is the only |
| 110 // non-experimental control method. | 110 // non-experimental control method. |
| 111 bool AreExperimentalMuteControlsEnabled(); | 111 bool AreExperimentalMuteControlsEnabled(); |
| 112 | 112 |
| 113 // Returns true if audio mute can be activated/deactivated for the given | 113 // Returns true if audio mute can be activated/deactivated for the given |
| 114 // |contents|. | 114 // |contents|. |
| 115 bool CanToggleAudioMute(content::WebContents* contents); | 115 bool CanToggleAudioMute(content::WebContents* contents); |
| 116 | 116 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 140 // string is returned. | 140 // string is returned. |
| 141 const std::string& GetExtensionIdForMutedTab(content::WebContents* contents); | 141 const std::string& GetExtensionIdForMutedTab(content::WebContents* contents); |
| 142 | 142 |
| 143 // Returns true if the tabs at the |indices| in |tab_strip| are all muted. | 143 // Returns true if the tabs at the |indices| in |tab_strip| are all muted. |
| 144 bool AreAllTabsMuted(const TabStripModel& tab_strip, | 144 bool AreAllTabsMuted(const TabStripModel& tab_strip, |
| 145 const std::vector<int>& indices); | 145 const std::vector<int>& indices); |
| 146 | 146 |
| 147 } // namespace chrome | 147 } // namespace chrome |
| 148 | 148 |
| 149 #endif // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ | 149 #endif // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_ |
| OLD | NEW |