Bug 1017560 - Choosing the same language will modify the state of Show Translation button, r=felipe, a=gavin.
authorFlorian Quèze <florian@queze.net>
Wed, 11 Jun 2014 12:15:36 +0200
changeset 207077 011d04986808d73e2d8ef5bb790ad1c3203e89d8
parent 207076 9a6785bfed9bbcae9f7b46f85ff71d56dcea1ecc
child 207078 ee3af593dcb88bb804f9835b5452375a2a191bd6
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfelipe, gavin
bugs1017560
milestone32.0a2
Bug 1017560 - Choosing the same language will modify the state of Show Translation button, r=felipe, a=gavin.
browser/components/translation/Translation.jsm
browser/components/translation/translation-infobar.xml
--- a/browser/components/translation/Translation.jsm
+++ b/browser/components/translation/Translation.jsm
@@ -198,18 +198,18 @@ TranslationUI.prototype = {
 
     return this.showTranslationInfoBar();
   },
 
   receiveMessage: function(msg) {
     switch (msg.name) {
       case "Translation:Finished":
         if (msg.data.success) {
+          this.originalShown = false;
           this.state = Translation.STATE_TRANSLATED;
-          this.originalShown = false;
           this.showURLBarIcon();
 
           // Record the number of characters translated.
           TranslationHealthReport.recordTranslation(msg.data.from, msg.data.to,
                                                     msg.data.characterCount);
         } else {
           this.state = Translation.STATE_ERROR;
         }
--- a/browser/components/translation/translation-infobar.xml
+++ b/browser/components/translation/translation-infobar.xml
@@ -129,16 +129,19 @@
           for (let name of ["OFFER", "TRANSLATING", "TRANSLATED", "ERROR"]) {
             if (Translation["STATE_" + name] == val) {
               stateName = name.toLowerCase();
               break;
             }
           }
           this.setAttribute("state", stateName);
 
+          if (val == Translation.STATE_TRANSLATED)
+            this._handleButtonHiding();
+
           deck.selectedIndex = val;
           ]]>
         </setter>
       </property>
 
       <method name="init">
         <parameter name="aTranslation"/>
         <body>
@@ -167,18 +170,16 @@
             for (let code of Translation.supportedTargetLanguages)
               toLanguage.appendItem(bundle.GetStringFromName(code), code);
 
             if (aTranslation.translatedTo)
               toLanguage.value = aTranslation.translatedTo;
 
             if (aTranslation.state)
               this.state = aTranslation.state;
-
-            this._handleButtonHiding(aTranslation.originalShown);
           ]]>
         </body>
       </method>
 
       <method name="_getAnonElt">
         <parameter name="aAnonId"/>
         <body>
           return document.getAnonymousElementByAttribute(this, "anonid", aAnonId);
@@ -190,47 +191,46 @@
           <![CDATA[
             if (this.state == Translation.STATE_OFFER) {
               this._getAnonElt("fromLanguage").value =
                 this._getAnonElt("detectedLanguage").value;
               this._getAnonElt("toLanguage").value =
                 Translation.defaultTargetLanguage;
             }
 
-            this._handleButtonHiding(false);
             this.translation.translate(this._getAnonElt("fromLanguage").value,
                                        this._getAnonElt("toLanguage").value);
           ]]>
         </body>
       </method>
 
       <method name="_handleButtonHiding">
-        <parameter name="aOriginalShown"/>
         <body>
           <![CDATA[
-            this._getAnonElt("showOriginal").hidden = aOriginalShown;
-            this._getAnonElt("showTranslation").hidden = !aOriginalShown;
+            let originalShown = this.translation.originalShown;
+            this._getAnonElt("showOriginal").hidden = originalShown;
+            this._getAnonElt("showTranslation").hidden = !originalShown;
           ]]>
         </body>
       </method>
 
       <method name="showOriginal">
         <body>
           <![CDATA[
-            this._handleButtonHiding(true);
             this.translation.showOriginalContent();
+            this._handleButtonHiding();
           ]]>
         </body>
       </method>
 
       <method name="showTranslation">
         <body>
           <![CDATA[
-            this._handleButtonHiding(false);
             this.translation.showTranslatedContent();
+            this._handleButtonHiding();
           ]]>
         </body>
       </method>
 
       <method name="optionsShowing">
         <body>
           <![CDATA[
             // Get the source language name.