Bug 1018504 - (Part 1) Add indicator to show which tab is playing sound. r=mhaigh

--HG--
extra : commitid : 6uFyuLLyATu
extra : rebase_source : 532f6adc6d2d123f2df4ea0ecda652542a8a7c31
This commit is contained in:
Margaret Leibovic 2015-07-31 11:08:26 -07:00
parent 19cd57be63
commit f74e42789d
17 changed files with 114 additions and 15 deletions

View File

@ -934,3 +934,6 @@ pref("dom.serviceWorkers.interception.enabled", true);
// Enable Cardboard VR on mobile, assuming VR at all is enabled
pref("dom.vr.cardboard.enabled", true);
// TODO: Disabled until bug 1190301 is fixed.
pref("browser.tabs.showAudioPlayingIcon", false);

View File

@ -81,6 +81,7 @@ public class Tab {
private ErrorType mErrorType = ErrorType.NONE;
private volatile int mLoadProgress;
private volatile int mRecordingCount;
private volatile boolean mIsAudioPlaying;
private String mMostRecentHomePanel;
private int mHistoryIndex;
@ -906,6 +907,14 @@ public class Tab {
return mRecordingCount > 0;
}
public void setIsAudioPlaying(boolean isAudioPlaying) {
mIsAudioPlaying = isAudioPlaying;
}
public boolean isAudioPlaying() {
return mIsAudioPlaying;
}
public boolean isEditing() {
return mIsEditing;
}

View File

@ -118,7 +118,8 @@ public class Tabs implements GeckoEventListener {
"DesktopMode:Changed",
"Tab:ViewportMetadata",
"Tab:StreamStart",
"Tab:StreamStop");
"Tab:StreamStop",
"Tab:AudioPlayingChange");
}
@ -581,6 +582,9 @@ public class Tabs implements GeckoEventListener {
} else if (event.equals("Tab:StreamStop")) {
tab.setRecording(false);
notifyListeners(tab, TabEvents.RECORDING_CHANGE);
} else if (event.equals("Tab:AudioPlayingChange")) {
tab.setIsAudioPlaying(message.getBoolean("isAudioPlaying"));
notifyListeners(tab, TabEvents.AUDIO_PLAYING_CHANGE);
}
} catch (Exception e) {
@ -641,6 +645,7 @@ public class Tabs implements GeckoEventListener {
BOOKMARK_REMOVED,
READING_LIST_ADDED,
READING_LIST_REMOVED,
AUDIO_PLAYING_CHANGE,
}
public void notifyListeners(Tab tab, TabEvents msg) {

View File

@ -68,6 +68,8 @@
<!ENTITY edit_mode_cancel "Cancel">
<!ENTITY close_tab "Close Tab">
<!ENTITY tab_audio_playing "This tab is playing audio">
<!ENTITY tab_audio_muted "This tab has been muted">
<!ENTITY one_tab "1 tab">
<!-- Localization note (num_tabs2) : Number of tabs is always more than one.
We can't use android plural forms, sadly. See bug #753859. -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

View File

@ -28,6 +28,17 @@
gecko:fadeWidth="30dip"
android:duplicateParentState="true"/>
<org.mozilla.gecko.widget.ThemedImageButton
android:id="@+id/audio_playing"
android:visibility="gone"
android:layout_width="20dip"
android:layout_height="match_parent"
android:layout_marginRight="-15dp"
android:background="@drawable/action_bar_button_inverse"
android:scaleType="center"
android:contentDescription="@string/tab_audio_playing"
android:src="@drawable/tab_audio_playing"/>
<org.mozilla.gecko.widget.ThemedImageButton
android:id="@+id/close"
android:layout_width="40dip"

View File

@ -33,6 +33,14 @@
gecko:fadeWidth="15dp"
android:paddingRight="5dp"/>
<ImageButton android:id="@+id/audio_playing"
android:visibility="gone"
android:layout_width="20dip"
android:layout_height="20dip"
android:background="@drawable/action_bar_button_inverse"
android:scaleType="center"
android:contentDescription="@string/tab_audio_playing"
android:src="@drawable/tab_audio_playing"/>
<!-- Use of baselineAlignBottom only supported from API 11+ - if this needs to work on lower API versions
we'll need to override getBaseLine() and return image height, but we assume this won't happen -->

View File

@ -46,6 +46,15 @@
android:singleLine="true"
android:duplicateParentState="true"/>
<ImageButton android:id="@+id/audio_playing"
android:visibility="gone"
android:layout_width="20dip"
android:layout_height="match_parent"
android:background="@drawable/action_bar_button_inverse"
android:scaleType="center"
android:contentDescription="@string/tab_audio_playing"
android:src="@drawable/tab_audio_playing"/>
<ImageButton android:id="@+id/close"
style="@style/TabsItemClose"
android:layout_width="32dip"

View File

@ -28,19 +28,36 @@
</org.mozilla.gecko.widget.TabThumbnailWrapper>
<TextView android:id="@+id/title"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:paddingTop="4dip"
android:paddingLeft="8dip"
android:paddingRight="4dip"
style="@style/TabLayoutItemTextAppearance"
android:textColor="#FFFFFFFF"
android:textSize="14sp"
android:singleLine="false"
android:maxLines="4"
android:duplicateParentState="true"/>
<LinearLayout android:layout_width="0dip"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1.0"
android:paddingTop="4dip"
android:paddingLeft="8dip"
android:paddingRight="4dip">
<TextView android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1.0"
style="@style/TabLayoutItemTextAppearance"
android:textColor="#FFFFFFFF"
android:textSize="14sp"
android:singleLine="false"
android:maxLines="4"
android:duplicateParentState="true"/>
<ImageButton android:id="@+id/audio_playing"
android:visibility="gone"
android:layout_width="20dip"
android:layout_height="20dip"
android:gravity="bottom"
android:background="@drawable/action_bar_button_inverse"
android:scaleType="center"
android:contentDescription="@string/tab_audio_playing"
android:src="@drawable/tab_audio_playing"/>
</LinearLayout>
<ImageButton android:id="@+id/close"
style="@style/TabsItemClose"

View File

@ -310,6 +310,8 @@
<string name="stop">&stop;</string>
<string name="site_security">&site_security;</string>
<string name="close_tab">&close_tab;</string>
<string name="tab_audio_playing">&tab_audio_playing;</string>
<string name="tab_audio_muted">&tab_audio_muted;</string>
<string name="new_tab_opened">&new_tab_opened;</string>
<string name="new_private_tab_opened">&new_private_tab_opened;</string>
<string name="switch_button_message">&switch_button_message;</string>

View File

@ -124,6 +124,7 @@ public class TabStrip extends ThemedLinearLayout
case TITLE:
case FAVICON:
case RECORDING_CHANGE:
case AUDIO_PLAYING_CHANGE:
tabStripView.updateTab(tab);
break;
}

View File

@ -44,6 +44,7 @@ public class TabStripItemView extends ThemedLinearLayout
private final ImageView faviconView;
private final ThemedTextView titleView;
private final ThemedImageButton closeView;
private final ThemedImageButton audioPlayingView;
private final ResizablePathDrawable backgroundDrawable;
private final Region tabRegion;
@ -100,6 +101,8 @@ public class TabStripItemView extends ThemedLinearLayout
tabs.closeTab(tabs.getTab(id), true);
}
});
audioPlayingView = (ThemedImageButton) findViewById(R.id.audio_playing);
}
@Override
@ -191,6 +194,7 @@ public class TabStripItemView extends ThemedLinearLayout
updateTitle(tab);
updateFavicon(tab.getFavicon());
setPrivateMode(tab.isPrivate());
audioPlayingView.setVisibility(tab.isAudioPlaying() ? View.VISIBLE : View.GONE);
}
private void updateTitle(Tab tab) {

View File

@ -238,6 +238,7 @@ class TabsGridLayout extends GridView
case THUMBNAIL:
case TITLE:
case RECORDING_CHANGE:
case AUDIO_PLAYING_CHANGE:
View view = getChildAt(mTabsAdapter.getPositionForTab(tab) - getFirstVisiblePosition());
if (view == null)
return;

View File

@ -33,6 +33,7 @@ public class TabsLayoutItemView extends LinearLayout
private TextView mTitle;
private ImageView mThumbnail;
private ImageView mCloseButton;
private ImageView mAudioPlayingButton;
private TabThumbnailWrapper mThumbnailWrapper;
public TabsLayoutItemView(Context context, AttributeSet attrs) {
@ -93,6 +94,7 @@ public class TabsLayoutItemView extends LinearLayout
mTitle = (TextView) findViewById(R.id.title);
mThumbnail = (ImageView) findViewById(R.id.thumbnail);
mCloseButton = (ImageView) findViewById(R.id.close);
mAudioPlayingButton = (ImageView) findViewById(R.id.audio_playing);
mThumbnailWrapper = (TabThumbnailWrapper) findViewById(R.id.wrapper);
if (HardwareUtils.isTablet()) {
@ -138,7 +140,7 @@ public class TabsLayoutItemView extends LinearLayout
}
mTitle.setText(tab.getDisplayTitle());
mCloseButton.setTag(this);
mAudioPlayingButton.setVisibility(tab.isAudioPlaying() ? View.VISIBLE : View.GONE);
}
public int getTabId() {

View File

@ -178,6 +178,7 @@ class TabsListLayout extends TwoWayView
case THUMBNAIL:
case TITLE:
case RECORDING_CHANGE:
case AUDIO_PLAYING_CHANGE:
View view = getChildAt(mTabsAdapter.getPositionForTab(tab) - getFirstVisiblePosition());
if (view == null)
return;

View File

@ -3578,6 +3578,8 @@ Tab.prototype = {
this.browser.addEventListener("DOMLinkChanged", this, true);
this.browser.addEventListener("DOMMetaAdded", this, false);
this.browser.addEventListener("DOMTitleChanged", this, true);
this.browser.addEventListener("DOMMediaPlaybackStarted", this, true);
this.browser.addEventListener("DOMMediaPlaybackStopped", this, true);
this.browser.addEventListener("DOMWindowClose", this, true);
this.browser.addEventListener("DOMWillOpenModalDialog", this, true);
this.browser.addEventListener("DOMAutoComplete", this, true);
@ -3760,6 +3762,8 @@ Tab.prototype = {
this.browser.removeEventListener("DOMLinkChanged", this, true);
this.browser.removeEventListener("DOMMetaAdded", this, false);
this.browser.removeEventListener("DOMTitleChanged", this, true);
this.browser.removeEventListener("DOMMediaPlaybackStarted", this, true);
this.browser.removeEventListener("DOMMediaPlaybackStopped", this, true);
this.browser.removeEventListener("DOMWindowClose", this, true);
this.browser.removeEventListener("DOMWillOpenModalDialog", this, true);
this.browser.removeEventListener("DOMAutoComplete", this, true);
@ -4384,6 +4388,26 @@ Tab.prototype = {
break;
}
case "DOMMediaPlaybackStarted":
case "DOMMediaPlaybackStopped": {
if (!Services.prefs.getBoolPref("browser.tabs.showAudioPlayingIcon") ||
!aEvent.isTrusted) {
return;
}
let browser = aEvent.originalTarget;
if (browser != this.browser) {
return;
}
Messaging.sendRequest({
type: "Tab:AudioPlayingChange",
tabID: this.id,
isAudioPlaying: aEvent.type === "DOMMediaPlaybackStarted"
});
return;
}
case "DOMWindowClose": {
if (!aEvent.isTrusted)
return;