aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/ui/splitpane.js
blob: f4a480deb1b0dc71da3cb0176c25fb6df092af00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
// Copyright 2007 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview  Class for splitting two areas with draggable control for
 * changing size.
 *
 * The DOM that is created (or that can be decorated) looks like this:
 * <div class='goog-splitpane'>
 *   <div class='goog-splitpane-first-container'></div>
 *   <div class='goog-splitpane-second-container'></div>
 *   <div class='goog-splitpane-handle'></div>
 * </div>
 *
 * The content to be split goes in the first and second DIVs, the third one
 * is for managing (and styling) the splitter handle.
 *
 * @see ../demos/splitpane.html
 */


goog.provide('goog.ui.SplitPane');
goog.provide('goog.ui.SplitPane.Orientation');

goog.require('goog.dom');
goog.require('goog.dom.classes');
goog.require('goog.events.EventType');
goog.require('goog.fx.Dragger');
goog.require('goog.fx.Dragger.EventType');
goog.require('goog.math.Rect');
goog.require('goog.math.Size');
goog.require('goog.style');
goog.require('goog.ui.Component');
goog.require('goog.ui.Component.EventType');
goog.require('goog.userAgent');



/**
 * A left/right up/down Container SplitPane.
 * Create SplitPane with two goog.ui.Component opjects to split.
 * TODO(user): Support minimum splitpane size.
 * TODO(user): Allow component change/orientation after init.
 * TODO(user): Support hiding either side of handle (plus handle).
 * TODO(user): Look at setBorderBoxSize fixes and revist borderwidth code.
 *
 * @param {goog.ui.Component} firstComponent Left or Top component.
 * @param {goog.ui.Component} secondComponent Right or Bottom component.
 * @param {goog.ui.SplitPane.Orientation} orientation SplitPane orientation.
 * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
 * @extends {goog.ui.Component}
 * @constructor
 */
goog.ui.SplitPane = function(firstComponent, secondComponent, orientation,
    opt_domHelper) {
  goog.base(this, opt_domHelper);

  /**
   * The orientation of the containers.
   * @type {goog.ui.SplitPane.Orientation}
   * @private
   */
  this.orientation_ = orientation;

  /**
   * The left/top component.
   * @type {goog.ui.Component}
   * @private
   */
  this.firstComponent_ = firstComponent;
  this.addChild(firstComponent);

  /**
   * The right/bottom component.
   * @type {goog.ui.Component}
   * @private
   */
  this.secondComponent_ = secondComponent;
  this.addChild(secondComponent);
};
goog.inherits(goog.ui.SplitPane, goog.ui.Component);


/**
 * Events.
 * @enum {string}
 */
goog.ui.SplitPane.EventType = {

  /**
   * Dispatched after handle drag.
   */
  HANDLE_DRAG: 'handle_drag',

  /**
   * Dispatched after handle drag end.
   */
  HANDLE_DRAG_END: 'handle_drag_end'
};


/**
 * CSS class names for splitpane outer container.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.CLASS_NAME_ = goog.getCssName('goog-splitpane');


/**
 * CSS class name for first splitpane container.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.FIRST_CONTAINER_CLASS_NAME_ =
    goog.getCssName('goog-splitpane-first-container');


/**
 * CSS class name for second splitpane container.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.SECOND_CONTAINER_CLASS_NAME_ =
    goog.getCssName('goog-splitpane-second-container');


/**
 * CSS class name for the splitpane handle.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.HANDLE_CLASS_NAME_ = goog.getCssName('goog-splitpane-handle');


/**
 * CSS class name for the splitpane handle in horizontal orientation.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_ =
    goog.getCssName('goog-splitpane-handle-horizontal');


/**
 * CSS class name for the splitpane handle in horizontal orientation.
 * @type {string}
 * @private
 */
goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_ =
    goog.getCssName('goog-splitpane-handle-vertical');


/**
  * The dragger to move the drag handle.
  * @type {goog.fx.Dragger?}
  * @private
  */
goog.ui.SplitPane.prototype.splitDragger_ = null;


/**
 * The left/top component dom container.
 * @type {Element}
 * @private
 */
goog.ui.SplitPane.prototype.firstComponentContainer_ = null;


/**
 * The right/bottom component dom container.
 * @type {Element}
 * @private
 */
goog.ui.SplitPane.prototype.secondComponentContainer_ = null;


/**
 * The size (width or height) of the splitpane handle, default = 5.
 * @type {number}
 * @private
 */
goog.ui.SplitPane.prototype.handleSize_ = 5;


/**
 * The initial size (width or height) of the left or top component.
 * @type {?number}
 * @private
 */
goog.ui.SplitPane.prototype.initialSize_ = null;


/**
 * The saved size (width or height) of the left or top component on a
 * double-click (snap).
 * This needs to be saved so it can be restored after another double-click.
 * @type {?number}
 * @private
 */
goog.ui.SplitPane.prototype.savedSnapSize_ = null;


/**
 * The first component size, so we don't change it on a window resize.
 * @type {?number}
 * @private
 */
goog.ui.SplitPane.prototype.firstComponentSize_ = null;


/**
 * If we resize as they user moves the handle (default = true).
 * @type {boolean}
 * @private
 */
goog.ui.SplitPane.prototype.continuousResize_ = true;


/**
 * Iframe overlay to prevent iframes from grabbing events.
 * @type {Element}
 * @private
 */
goog.ui.SplitPane.prototype.iframeOverlay_ = null;


/**
 * Z indices for iframe overlay and splitter handle.
 * @enum {number}
 * @private
 */
goog.ui.SplitPane.IframeOverlayIndex_ = {
  HIDDEN: -1,
  OVERLAY: 1,
  SPLITTER_HANDLE: 2
};


/**
* Orientation values for the splitpane.
* @enum {string}
*/
goog.ui.SplitPane.Orientation = {

  /**
   * Horizontal orientation means splitter moves right-left.
   */
  HORIZONTAL: 'horizontal',

  /**
   * Vertical orientation means splitter moves up-down.
   */
  VERTICAL: 'vertical'
};


/**
 * Create the DOM node & text node needed for the splitpane.
 * @override
 */
goog.ui.SplitPane.prototype.createDom = function() {
  var dom = this.getDomHelper();

  // Create the components.
  var firstContainer = dom.createDom('div',
      goog.ui.SplitPane.FIRST_CONTAINER_CLASS_NAME_);
  var secondContainer = dom.createDom('div',
      goog.ui.SplitPane.SECOND_CONTAINER_CLASS_NAME_);
  var splitterHandle = dom.createDom('div',
      goog.ui.SplitPane.HANDLE_CLASS_NAME_);

  // Create the primary element, a DIV that holds the two containers and handle.
  this.setElementInternal(dom.createDom('div', goog.ui.SplitPane.CLASS_NAME_,
      firstContainer, secondContainer, splitterHandle));

  this.firstComponentContainer_ = firstContainer;
  this.secondComponentContainer_ = secondContainer;
  this.splitpaneHandle_ = splitterHandle;
  this.setUpHandle_();

  this.finishSetup_();
};


/**
 * Determines if a given element can be decorated by this type of component.
 * @param {Element} element Element to decorate.
 * @return {boolean} True if the element can be decorated, false otherwise.
 * @override
 */
goog.ui.SplitPane.prototype.canDecorate = function(element) {
  var className = goog.ui.SplitPane.FIRST_CONTAINER_CLASS_NAME_;
  var firstContainer = this.getElementToDecorate_(element, className);
  if (!firstContainer) {
    return false;
  }
  // Since we have this component, save it so we don't have to get it
  // again in decorateInternal.  Same w/other components.
  this.firstComponentContainer_ = firstContainer;

  className = goog.ui.SplitPane.SECOND_CONTAINER_CLASS_NAME_;
  var secondContainer = this.getElementToDecorate_(element, className);

  if (!secondContainer) {
    return false;
  }
  this.secondComponentContainer_ = secondContainer;

  className = goog.ui.SplitPane.HANDLE_CLASS_NAME_;
  var splitpaneHandle = this.getElementToDecorate_(element, className);
  if (!splitpaneHandle) {
    return false;
  }
  this.splitpaneHandle_ = splitpaneHandle;

  // We found all the components we're looking for, so return true.
  return true;
};


/**
 * Obtains the element to be decorated by class name. If multiple such elements
 * are found, preference is given to those directly attached to the specified
 * root element.
 * @param {Element} rootElement The root element from which to retrieve the
 *     element to be decorated.
 * @param {!string} className The target class name.
 * @return {Element} The element to decorate.
 * @private
 */
goog.ui.SplitPane.prototype.getElementToDecorate_ = function(rootElement,
    className) {

  // Decorate the root element's children, if available.
  var childElements = goog.dom.getChildren(rootElement);
  for (var i = 0; i < childElements.length; i++) {
    var childElement = childElements[i];
    if (goog.dom.classes.has(childElement, className)) {
      return childElement;
    }
  }

  // Default to the first descendent element with the correct class.
  return goog.dom.getElementsByTagNameAndClass(
      null, className, rootElement)[0];
};


/**
 * Decorates the given HTML element as a SplitPane.  Overrides {@link
 * goog.ui.Component#decorateInternal}.  Considered protected.
 * @param {Element} element Element (SplitPane div) to decorate.
 * @protected
 * @override
 */
goog.ui.SplitPane.prototype.decorateInternal = function(element) {
  goog.base(this, 'decorateInternal', element);

  this.setUpHandle_();

  var elSize = goog.style.getBorderBoxSize(element);
  this.setSize(new goog.math.Size(elSize.width, elSize.height));

  this.finishSetup_();
};


/**
 * Parent the passed in components to the split containers.  Call their
 * createDom methods if necessary.
 * @private
 */
goog.ui.SplitPane.prototype.finishSetup_ = function() {
  var dom = this.getDomHelper();

  if (!this.firstComponent_.getElement()) {
    this.firstComponent_.createDom();
  }

  dom.appendChild(this.firstComponentContainer_,
      this.firstComponent_.getElement());

  if (!this.secondComponent_.getElement()) {
    this.secondComponent_.createDom();
  }

  dom.appendChild(this.secondComponentContainer_,
      this.secondComponent_.getElement());

  this.splitDragger_ = new goog.fx.Dragger(this.splitpaneHandle_,
      this.splitpaneHandle_);

  this.firstComponentContainer_.style.position = 'absolute';
  this.secondComponentContainer_.style.position = 'absolute';
  var handleStyle = this.splitpaneHandle_.style;
  handleStyle.position = 'absolute';
  handleStyle.overflow = 'hidden';
  handleStyle.zIndex =
      goog.ui.SplitPane.IframeOverlayIndex_.SPLITTER_HANDLE;
};


/**
 * Setup all events and do an initial resize.
 * @override
 */
goog.ui.SplitPane.prototype.enterDocument = function() {
  goog.base(this, 'enterDocument');

  // If position is not set in the inline style of the element, it is not
  // possible to get the element's real CSS position until the element is in
  // the document.
  // When position:relative is set in the CSS and the element is not in the
  // document, Safari, Chrome, and Opera always return the empty string; while
  // IE always return "static".
  // Do the final check to see if element's position is set as "relative",
  // "absolute" or "fixed".
  var element = this.getElement();
  if (goog.style.getComputedPosition(element) == 'static') {
    element.style.position = 'relative';
  }

  this.getHandler().
      listen(this.splitpaneHandle_, goog.events.EventType.DBLCLICK,
          this.handleDoubleClick_).
      listen(this.splitDragger_, goog.fx.Dragger.EventType.START,
          this.handleDragStart_).
      listen(this.splitDragger_, goog.fx.Dragger.EventType.DRAG,
          this.handleDrag_).
      listen(this.splitDragger_, goog.fx.Dragger.EventType.END,
          this.handleDragEnd_);

  this.setFirstComponentSize(this.initialSize_);
};


/**
 * Sets the initial size of the left or top component.
 * @param {number} size The size in Pixels of the container.
 */
goog.ui.SplitPane.prototype.setInitialSize = function(size) {
  this.initialSize_ = size;
};


/**
 * Sets the SplitPane handle size.
 * TODO(user): Make sure this works after initialization.
 * @param {number} size The size of the handle in pixels.
 */
goog.ui.SplitPane.prototype.setHandleSize = function(size) {
  this.handleSize_ = size;
};


/**
 * Sets whether we resize on handle drag.
 * @param {boolean} continuous The continuous resize value.
 */
goog.ui.SplitPane.prototype.setContinuousResize = function(continuous) {
  this.continuousResize_ = continuous;
};


/**
 * Returns whether the orientation for the split pane is vertical
 * or not.
 * @return {boolean} True if the orientation is vertical, false otherwise.
 */
goog.ui.SplitPane.prototype.isVertical = function() {
  return this.orientation_ == goog.ui.SplitPane.Orientation.VERTICAL;
};


/**
 * Initializes the handle by assigning the correct height/width and adding
 * the correct class as per the orientation.
 * @private
 */
goog.ui.SplitPane.prototype.setUpHandle_ = function() {
  if (this.isVertical()) {
    this.splitpaneHandle_.style.height = this.handleSize_ + 'px';
    goog.dom.classes.add(this.splitpaneHandle_,
        goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_);
  } else {
    this.splitpaneHandle_.style.width = this.handleSize_ + 'px';
    goog.dom.classes.add(this.splitpaneHandle_,
        goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_);
  }
};


/**
 * Sets the orientation class for the split pane handle.
 * @protected
 */
goog.ui.SplitPane.prototype.setOrientationClassForHandle = function() {
  if (this.isVertical()) {
    goog.dom.classes.swap(this.splitpaneHandle_,
                          goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_,
                          goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_);
  } else {
    goog.dom.classes.swap(this.splitpaneHandle_,
                          goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_,
                          goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_);
  }
};


/**
 * Sets the orientation of the split pane.
 * @param {goog.ui.SplitPane.Orientation} orientation SplitPane orientation.
 */
goog.ui.SplitPane.prototype.setOrientation = function(orientation) {
  if (this.orientation_ != orientation) {
    this.orientation_ = orientation;
    var isVertical = this.isVertical();

    // If the split pane is already in document, then the positions and sizes
    // need to be adjusted.
    if (this.isInDocument()) {
      this.setOrientationClassForHandle();
      // TODO(user): Should handleSize_ and initialSize_ also be adjusted ?
      if (goog.isNumber(this.firstComponentSize_)) {
        var splitpaneSize = goog.style.getBorderBoxSize(this.getElement());
        var ratio = isVertical ? splitpaneSize.height / splitpaneSize.width :
            splitpaneSize.width / splitpaneSize.height;
        // TODO(user): Fix the behaviour for the case when the handle is
        // placed on either of  the edges of the split pane. Also, similar
        // behaviour is present in {@link #setSize}. Probably need to modify
        // {@link #setFirstComponentSize}.
        this.setFirstComponentSize(this.firstComponentSize_ * ratio);
      } else {
        this.setFirstComponentSize();
      }
    }
  }
};


/**
 * Gets the orientation of the split pane.
 * @return {goog.ui.SplitPane.Orientation} The orientation.
 */
goog.ui.SplitPane.prototype.getOrientation = function() {
  return this.orientation_;
};


/**
 * Move and resize a container.  The sizing changes the BorderBoxSize.
 * @param {Element} element The element to move and size.
 * @param {goog.math.Rect} rect The top, left, width and height to change to.
 * @private
 */
goog.ui.SplitPane.prototype.moveAndSize_ = function(element, rect) {

  goog.style.setPosition(element, rect.left, rect.top);
  // TODO(user): Add a goog.math.Size.max call for below.
  goog.style.setBorderBoxSize(element,
      new goog.math.Size(Math.max(rect.width, 0), Math.max(rect.height, 0)));
};


/**
 * @return {?number} The size of the left/top component.
 */
goog.ui.SplitPane.prototype.getFirstComponentSize = function() {
  return this.firstComponentSize_;
};


/**
 * Set the size of the left/top component, and resize the other component based
 * on that size and handle size.
 * @param {?number=} opt_size The size of the top or left, in pixels.
 */
goog.ui.SplitPane.prototype.setFirstComponentSize = function(opt_size) {
  var top = 0, left = 0;
  var splitpaneSize = goog.style.getBorderBoxSize(this.getElement());

  var isVertical = this.isVertical();
  // Figure out first component size; it's either passed in, taken from the
  // saved size, or is half of the total size.
  var firstComponentSize = goog.isNumber(opt_size) ? opt_size :
      goog.isNumber(this.firstComponentSize_) ? this.firstComponentSize_ :
      Math.floor((isVertical ? splitpaneSize.height : splitpaneSize.width) / 2);
  this.firstComponentSize_ = firstComponentSize;

  var firstComponentWidth;
  var firstComponentHeight;
  var secondComponentWidth;
  var secondComponentHeight;
  var handleWidth;
  var handleHeight;
  var secondComponentLeft;
  var secondComponentTop;
  var handleLeft;
  var handleTop;

  if (isVertical) {

    // Width for the handle and the first and second components will be the
    // width of the split pane. The height for the first component will be
    // the calculated first component size. The height for the second component
    // will be the  total height minus the heights of the first component and
    // the handle.
    firstComponentHeight = firstComponentSize;
    firstComponentWidth = splitpaneSize.width;
    handleWidth = splitpaneSize.width;
    handleHeight = this.handleSize_;
    secondComponentHeight = splitpaneSize.height - firstComponentHeight -
        handleHeight;
    secondComponentWidth = splitpaneSize.width;
    handleTop = top + firstComponentHeight;
    handleLeft = left;
    secondComponentTop = handleTop + handleHeight;
    secondComponentLeft = left;
  } else {

    // Height for the handle and the first and second components will be the
    // height of the split pane. The width for the first component will be
    // the calculated first component size. The width for the second component
    // will be the  total width minus the widths of the first component and
    // the handle.
    firstComponentWidth = firstComponentSize;
    firstComponentHeight = splitpaneSize.height;
    handleWidth = this.handleSize_;
    handleHeight = splitpaneSize.height;
    secondComponentWidth = splitpaneSize.width - firstComponentWidth -
        handleWidth;
    secondComponentHeight = splitpaneSize.height;
    handleLeft = left + firstComponentWidth;
    handleTop = top;
    secondComponentLeft = handleLeft + handleWidth;
    secondComponentTop = top;
  }

  // Now move and size the containers.
  this.moveAndSize_(this.firstComponentContainer_,
      new goog.math.Rect(left, top, firstComponentWidth, firstComponentHeight));

  if (typeof this.firstComponent_.resize == 'function') {
    this.firstComponent_.resize(new goog.math.Size(
        firstComponentWidth, firstComponentHeight));
  }

  this.moveAndSize_(this.splitpaneHandle_, new goog.math.Rect(handleLeft,
      handleTop, handleWidth, handleHeight));

  this.moveAndSize_(this.secondComponentContainer_,
      new goog.math.Rect(secondComponentLeft, secondComponentTop,
          secondComponentWidth, secondComponentHeight));

  if (typeof this.secondComponent_.resize == 'function') {
    this.secondComponent_.resize(new goog.math.Size(secondComponentWidth,
        secondComponentHeight));
  }
  // Fire a CHANGE event.
  this.dispatchEvent(goog.ui.Component.EventType.CHANGE);
};


/**
 * Dummy object to work around compiler warning.
 * TODO(arv): Fix compiler or refactor to not depend on resize()
 * @private
 * @type {Object}
 */
goog.ui.SplitPane.resizeWarningWorkaround_ = {
  /**
   * @param {goog.math.Size} size The new size.
   */
  resize: function(size) {}
};


/**
  * Set the size of the splitpane.  This is usually called by the controlling
  * application.  This will set the SplitPane BorderBoxSize.
  * @param {goog.math.Size} size The size to set the splitpane.
  */
goog.ui.SplitPane.prototype.setSize = function(size) {
  goog.style.setBorderBoxSize(this.getElement(), size);
  if (this.iframeOverlay_) {
    goog.style.setBorderBoxSize(this.iframeOverlay_, size);
  }
  this.setFirstComponentSize();
};


/**
 * Snap the container to the left or top on a Double-click.
 * @private
 */
goog.ui.SplitPane.prototype.snapIt_ = function() {
  var handlePos = goog.style.getRelativePosition(this.splitpaneHandle_,
      this.firstComponentContainer_);
  var firstBorderBoxSize =
      goog.style.getBorderBoxSize(this.firstComponentContainer_);
  var firstContentBoxSize =
      goog.style.getContentBoxSize(this.firstComponentContainer_);

  var isVertical = this.isVertical();

  // Where do we snap the handle (what size to make the component) and what
  // is the current handle position.
  var snapSize;
  var handlePosition;
  if (isVertical) {
    snapSize = firstBorderBoxSize.height - firstContentBoxSize.height;
    handlePosition = handlePos.y;
  } else {
    snapSize = firstBorderBoxSize.width - firstContentBoxSize.width;
    handlePosition = handlePos.x;
  }

  if (snapSize == handlePosition) {
    // This means we're 'unsnapping', set it back to where it was.
    this.setFirstComponentSize(this.savedSnapSize_);
  } else {
    // This means we're 'snapping', set the size to snapSize, and hide the
    // first component.
    if (isVertical) {
      this.savedSnapSize_ = goog.style.getBorderBoxSize(
          this.firstComponentContainer_).height;
    } else {
      this.savedSnapSize_ = goog.style.getBorderBoxSize(
          this.firstComponentContainer_).width;
    }
    this.setFirstComponentSize(snapSize);
  }
};


/**
 * Handle the start drag event - set up the dragger.
 * @param {goog.events.Event} e The event.
 * @private
 */
goog.ui.SplitPane.prototype.handleDragStart_ = function(e) {

  // Setup iframe overlay to prevent iframes from grabbing events.
  if (!this.iframeOverlay_) {
    // Create the overlay.
    var cssStyles = 'position: relative';

    if (goog.userAgent.IE) {
      // IE doesn't look at this div unless it has a background, so we'll
      // put one on, but make it opaque.
      cssStyles += ';background-color: #000;filter: Alpha(Opacity=0)';
    }
    this.iframeOverlay_ =
        this.getDomHelper().createDom('div', {'style': cssStyles});

    this.getDomHelper().appendChild(this.getElement(), this.iframeOverlay_);
  }
  this.iframeOverlay_.style.zIndex =
      goog.ui.SplitPane.IframeOverlayIndex_.OVERLAY;

  goog.style.setBorderBoxSize(this.iframeOverlay_,
      goog.style.getBorderBoxSize(this.getElement()));

  var pos = goog.style.getPosition(this.firstComponentContainer_);

  // For the size of the limiting box, we add the container content box sizes
  // so that if the handle is placed all the way to the end or the start, the
  // border doesn't exceed the total size. For position, we add the difference
  // between the border box and content box sizes of the first container to the
  // position of the first container. The start position should be such that
  // there is no overlap of borders.
  var limitWidth = 0;
  var limitHeight = 0;
  var limitx = pos.x;
  var limity = pos.y;
  var firstBorderBoxSize =
      goog.style.getBorderBoxSize(this.firstComponentContainer_);
  var firstContentBoxSize =
      goog.style.getContentBoxSize(this.firstComponentContainer_);
  var secondContentBoxSize =
      goog.style.getContentBoxSize(this.secondComponentContainer_);
  if (this.isVertical()) {
    limitHeight = firstContentBoxSize.height + secondContentBoxSize.height;
    limity += firstBorderBoxSize.height - firstContentBoxSize.height;
  } else {
    limitWidth = firstContentBoxSize.width + secondContentBoxSize.width;
    limitx += firstBorderBoxSize.width - firstContentBoxSize.width;
  }
  var limits = new goog.math.Rect(limitx, limity, limitWidth, limitHeight);
  this.splitDragger_.setLimits(limits);
};


/**
 * Find the location relative to the splitpane.
 * @param {number} left The x location relative to the window.
 * @return {number} The relative x location.
 * @private
 */
goog.ui.SplitPane.prototype.getRelativeLeft_ = function(left) {
  return left - goog.style.getPosition(this.firstComponentContainer_).x;
};


/**
 * Find the location relative to the splitpane.
 * @param {number} top The y location relative to the window.
 * @return {number} The relative y location.
 * @private
 */
goog.ui.SplitPane.prototype.getRelativeTop_ = function(top) {
  return top - goog.style.getPosition(this.firstComponentContainer_).y;
};


/**
 * Handle the drag event. Move the containers.
 * @param {goog.events.Event} e The event.
 * @private
 */
goog.ui.SplitPane.prototype.handleDrag_ = function(e) {
  if (this.continuousResize_) {
    if (this.isVertical()) {
      var top = this.getRelativeTop_(e.top);
      this.setFirstComponentSize(top);
    } else {
      var left = this.getRelativeLeft_(e.left);
      this.setFirstComponentSize(left);
    }
    this.dispatchEvent(goog.ui.SplitPane.EventType.HANDLE_DRAG);
  }
};


/**
 * Handle the drag end event. If we're not doing continuous resize,
 * resize the component.  If we're doing continuous resize, the component
 * is already the correct size.
 * @param {goog.events.Event} e The event.
 * @private
 */
goog.ui.SplitPane.prototype.handleDragEnd_ = function(e) {
  // Push iframe overlay down.
  this.iframeOverlay_.style.zIndex =
      goog.ui.SplitPane.IframeOverlayIndex_.HIDDEN;
  if (!this.continuousResize_) {
    if (this.isVertical()) {
      var top = this.getRelativeTop_(e.top);
      this.setFirstComponentSize(top);
    } else {
      var left = this.getRelativeLeft_(e.left);
      this.setFirstComponentSize(left);
    }
  }

  this.dispatchEvent(goog.ui.SplitPane.EventType.HANDLE_DRAG_END);
};


/**
 * Handle the Double-click. Call the snapIt method which snaps the container
 * to the top or left.
 * @param {goog.events.Event} e The event.
 * @private
 */
goog.ui.SplitPane.prototype.handleDoubleClick_ = function(e) {
  this.snapIt_();
};


/** @override */
goog.ui.SplitPane.prototype.disposeInternal = function() {
  goog.base(this, 'disposeInternal');

  this.splitDragger_.dispose();
  this.splitDragger_ = null;

  goog.dom.removeNode(this.iframeOverlay_);
  this.iframeOverlay_ = null;
};