44 */
55'use strict' ;
66
7+ // Perceptual diffing mode
8+ var PDIFF_MODE = {
9+ OFF : 0 ,
10+ BBOX : 1 ,
11+ PIXELS : 2
12+ } ;
13+
714// Webdiff application root.
815var makeRoot = function ( filePairs , initiallySelectedIndex ) {
916 return React . createClass ( {
@@ -15,7 +22,7 @@ var makeRoot = function(filePairs, initiallySelectedIndex) {
1522 mixins : [ ReactRouter . Navigation , ReactRouter . State ] ,
1623 getInitialState : ( ) => ( {
1724 imageDiffMode : 'side-by-side' ,
18- showPerceptualDiffBox : false
25+ pdiffMode : PDIFF_MODE . OFF
1926 } ) ,
2027 getDefaultProps : function ( ) {
2128 return { filePairs, initiallySelectedIndex} ;
@@ -31,26 +38,28 @@ var makeRoot = function(filePairs, initiallySelectedIndex) {
3138 changeImageDiffModeHandler : function ( mode ) {
3239 this . setState ( { imageDiffMode : mode } ) ;
3340 } ,
34- changeShowPerceptualDiffBox : function ( shouldShow ) {
35- this . setState ( { showPerceptualDiffBox : shouldShow } ) ;
41+ changePdiffMode : function ( pdiffMode ) {
42+ this . setState ( { pdiffMode } ) ;
3643 } ,
37- computePerceptualDiff : function ( ) {
44+ computePerceptualDiffBox : function ( ) {
3845 var fp = this . props . filePairs [ this . getIndex ( ) ] ;
39- computePerceptualDiff ( '/a/image/' + fp . a , '/b/image/' + fp . b )
40- . then ( ( diffData ) => {
41- fp . diffData = diffData ;
42- this . forceUpdate ( ) ; // tell react about this change
43- } )
44- . catch ( function ( reason ) {
45- console . error ( reason ) ;
46- } ) ;
46+ if ( ! fp . is_image_diff || ! isSameSizeImagePair ( fp ) ) return ;
47+ $ . getJSON ( `/pdiffbbox/${ this . getIndex ( ) } ` )
48+ . done ( bbox => {
49+ if ( ! fp . diffData ) fp . diffData = { } ;
50+ fp . diffData . diffBounds = bbox ;
51+ this . forceUpdate ( ) ; // tell react about this change
52+ } ) . fail ( error => {
53+ console . error ( error ) ;
54+ } ) ;
4755 } ,
4856 render : function ( ) {
4957 var idx = this . getIndex ( ) ,
5058 filePair = this . props . filePairs [ idx ] ;
5159
52- if ( this . state . showPerceptualDiffBox && ! filePair . diffData ) {
53- this . computePerceptualDiff ( ) ;
60+ if ( this . state . pdiffMode == PDIFF_MODE . BBOX && ! filePair . diffData ) {
61+ // XXX this might shoot off unnecessary XHRs--use a Promise!
62+ this . computePerceptualDiffBox ( ) ;
5463 }
5564
5665 return (
@@ -60,9 +69,9 @@ var makeRoot = function(filePairs, initiallySelectedIndex) {
6069 fileChangeHandler = { this . selectIndex } />
6170 < DiffView filePair = { filePair }
6271 imageDiffMode = { this . state . imageDiffMode }
63- showPerceptualDiffBox = { this . state . showPerceptualDiffBox }
72+ pdiffMode = { this . state . pdiffMode }
6473 changeImageDiffModeHandler = { this . changeImageDiffModeHandler }
65- changeShowPerceptualDiffBox = { this . changeShowPerceptualDiffBox } />
74+ changePdiffMode = { this . changePdiffMode } />
6675 </ div >
6776 ) ;
6877 } ,
@@ -84,7 +93,7 @@ var makeRoot = function(filePairs, initiallySelectedIndex) {
8493 this . setState ( { imageDiffMode : 'blink' } ) ;
8594 } else if ( e . keyCode == 80 ) { // p
8695 this . setState ( {
87- showPerceptualDiffBox : ! this . state . showPerceptualDiffBox
96+ pdiffMode : ( this . state . pdiffMode + 1 ) % 3
8897 } ) ;
8998 }
9099 } ) ;
@@ -230,9 +239,9 @@ var DiffView = React.createClass({
230239 propTypes : {
231240 filePair : React . PropTypes . object . isRequired ,
232241 imageDiffMode : React . PropTypes . oneOf ( IMAGE_DIFF_MODES ) . isRequired ,
233- showPerceptualDiffBox : React . PropTypes . bool ,
242+ pdiffMode : React . PropTypes . number ,
234243 changeImageDiffModeHandler : React . PropTypes . func . isRequired ,
235- changeShowPerceptualDiffBox : React . PropTypes . func . isRequired
244+ changePdiffMode : React . PropTypes . func . isRequired
236245 } ,
237246 render : function ( ) {
238247 if ( this . props . filePair . is_image_diff ) {
@@ -249,8 +258,11 @@ var NoChanges = React.createClass({
249258 filePair : React . PropTypes . object . isRequired
250259 } ,
251260 render : function ( ) {
252- if ( this . props . filePair . no_changes ) {
253- return < div className = "no-changes" > (No Changes)</ div > ;
261+ var fp = this . props . filePair ;
262+ if ( fp . no_changes ) {
263+ return < div className = "no-changes" > (File content is identical)</ div > ;
264+ } else if ( fp . is_image_diff && fp . are_same_pixels ) {
265+ return < div className = "no-changes" > Pixels are the same, though file content differs (perhaps the headers are different?)</ div > ;
254266 } else {
255267 return null ;
256268 }
0 commit comments