Home | History | Annotate | Download | only in tabs
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
      6 #define CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/strings/string16.h"
     12 
     13 class TabStripModel;
     14 
     15 namespace content {
     16 class WebContents;
     17 }  // namespace content
     18 
     19 namespace gfx {
     20 class Animation;
     21 class Image;
     22 }  // namespace gfx
     23 
     24 // Media state for a tab.  In reality, more than one of these may apply.  See
     25 // comments for GetTabMediaStateForContents() below.
     26 enum TabMediaState {
     27   TAB_MEDIA_STATE_NONE,
     28   TAB_MEDIA_STATE_RECORDING,  // Audio/Video being recorded, consumed by tab.
     29   TAB_MEDIA_STATE_CAPTURING,  // Tab contents being captured.
     30   TAB_MEDIA_STATE_AUDIO_PLAYING,  // Audible audio is playing from the tab.
     31   TAB_MEDIA_STATE_AUDIO_MUTING,  // Tab audio is being muted.
     32 };
     33 
     34 namespace chrome {
     35 
     36 // Logic to determine which components (i.e., close button, favicon, and media
     37 // indicator) of a tab should be shown, given current state.  |capacity|
     38 // specifies how many components can be shown, given available tab width.
     39 //
     40 // Precedence rules for deciding what to show when capacity is insufficient to
     41 // show everything:
     42 //
     43 //   Active tab: Always show the close button, then the media indicator, then
     44 //               the favicon.
     45 //   Inactive tab: Media indicator, then the favicon, then the close button.
     46 //   Pinned tab: Show only the media indicator, or only the favicon
     47 //               (TAB_MEDIA_STATE_NONE).  Never show the close button.
     48 bool ShouldTabShowFavicon(int capacity,
     49                           bool is_pinned_tab,
     50                           bool is_active_tab,
     51                           bool has_favicon,
     52                           TabMediaState media_state);
     53 bool ShouldTabShowMediaIndicator(int capacity,
     54                                  bool is_pinned_tab,
     55                                  bool is_active_tab,
     56                                  bool has_favicon,
     57                                  TabMediaState media_state);
     58 bool ShouldTabShowCloseButton(int capacity,
     59                               bool is_pinned_tab,
     60                               bool is_active_tab);
     61 
     62 // Returns whether the given |contents| is playing audio. We might choose to
     63 // show an audio favicon indicator for this tab.
     64 bool IsPlayingAudio(content::WebContents* contents);
     65 
     66 // Returns the media state to be shown by the tab's media indicator.  When
     67 // multiple states apply (e.g., tab capture with audio playback), the one most
     68 // relevant to user privacy concerns is selected.
     69 TabMediaState GetTabMediaStateForContents(content::WebContents* contents);
     70 
     71 // Returns a cached image, to be shown by the media indicator for the given
     72 // |media_state|.  Uses the global ui::ResourceBundle shared instance.
     73 const gfx::Image& GetTabMediaIndicatorImage(TabMediaState media_state);
     74 
     75 // Returns the cached image, to be shown by the media indicator button for mouse
     76 // hover/pressed, when the indicator is in the given |media_state|.  Uses the
     77 // global ui::ResourceBundle shared instance.
     78 const gfx::Image& GetTabMediaIndicatorAffordanceImage(
     79     TabMediaState media_state);
     80 
     81 // Returns a non-continuous Animation that performs a fade-in or fade-out
     82 // appropriate for the given |next_media_state|.  This is used by the tab media
     83 // indicator to alert the user that recording, tab capture, or audio playback
     84 // has started/stopped.
     85 scoped_ptr<gfx::Animation> CreateTabMediaIndicatorFadeAnimation(
     86     TabMediaState next_media_state);
     87 
     88 // Returns the text to show in a tab's tooltip: The contents |title|, followed
     89 // by a break, followed by a localized string describing the |media_state|.
     90 base::string16 AssembleTabTooltipText(const base::string16& title,
     91                                       TabMediaState media_state);
     92 
     93 // Returns true if the experimental tab audio mute feature is enabled.
     94 bool IsTabAudioMutingFeatureEnabled();
     95 
     96 // Returns true if audio mute can be activated/deactivated for the given
     97 // |contents|.
     98 bool CanToggleAudioMute(content::WebContents* contents);
     99 
    100 // Indicates/Sets whether all audio output from |contents| is muted.
    101 bool IsTabAudioMuted(content::WebContents* contents);
    102 void SetTabAudioMuted(content::WebContents* contents, bool mute);
    103 
    104 // Returns true if the tabs at the |indices| in |tab_strip| are all muted.
    105 bool AreAllTabsMuted(const TabStripModel& tab_strip,
    106                      const std::vector<int>& indices);
    107 
    108 }  // namespace chrome
    109 
    110 #endif  // CHROME_BROWSER_UI_TABS_TAB_UTILS_H_
    111