123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918 |
- goog.provide('goog.ui.SplitPane');
- goog.provide('goog.ui.SplitPane.Orientation');
- goog.require('goog.asserts');
- goog.require('goog.dom');
- goog.require('goog.dom.TagName');
- goog.require('goog.dom.classlist');
- goog.require('goog.events.EventType');
- goog.require('goog.fx.Dragger');
- goog.require('goog.math.Rect');
- goog.require('goog.math.Size');
- goog.require('goog.style');
- goog.require('goog.ui.Component');
- goog.require('goog.userAgent');
- goog.ui.SplitPane = function(
- firstComponent, secondComponent, orientation, opt_domHelper) {
- goog.ui.SplitPane.base(this, 'constructor', opt_domHelper);
-
- this.orientation_ = orientation;
-
- this.firstComponent_ = firstComponent;
- this.addChild(firstComponent);
-
- this.secondComponent_ = secondComponent;
- this.addChild(secondComponent);
-
- this.splitpaneHandle_ = null;
- };
- goog.inherits(goog.ui.SplitPane, goog.ui.Component);
- goog.tagUnsealableClass(goog.ui.SplitPane);
- goog.ui.SplitPane.EventType = {
-
- HANDLE_DRAG: 'handle_drag',
-
- HANDLE_DRAG_END: 'handle_drag_end',
-
- HANDLE_SNAP: 'handle_snap'
- };
- goog.ui.SplitPane.CLASS_NAME_ = goog.getCssName('goog-splitpane');
- goog.ui.SplitPane.FIRST_CONTAINER_CLASS_NAME_ =
- goog.getCssName('goog-splitpane-first-container');
- goog.ui.SplitPane.SECOND_CONTAINER_CLASS_NAME_ =
- goog.getCssName('goog-splitpane-second-container');
- goog.ui.SplitPane.HANDLE_CLASS_NAME_ = goog.getCssName('goog-splitpane-handle');
- goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_ =
- goog.getCssName('goog-splitpane-handle-horizontal');
- goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_ =
- goog.getCssName('goog-splitpane-handle-vertical');
- goog.ui.SplitPane.prototype.splitDragger_ = null;
- goog.ui.SplitPane.prototype.firstComponentContainer_ = null;
- goog.ui.SplitPane.prototype.secondComponentContainer_ = null;
- goog.ui.SplitPane.prototype.handleSize_ = 5;
- goog.ui.SplitPane.prototype.initialSize_ = null;
- goog.ui.SplitPane.prototype.savedSnapSize_ = null;
- goog.ui.SplitPane.prototype.firstComponentSize_ = null;
- goog.ui.SplitPane.prototype.continuousResize_ = true;
- goog.ui.SplitPane.prototype.iframeOverlay_ = null;
- goog.ui.SplitPane.IframeOverlayIndex_ = {
- HIDDEN: -1,
- OVERLAY: 1,
- SPLITTER_HANDLE: 2
- };
- goog.ui.SplitPane.Orientation = {
-
- HORIZONTAL: 'horizontal',
-
- VERTICAL: 'vertical'
- };
- goog.ui.SplitPane.prototype.createDom = function() {
- var dom = this.getDomHelper();
-
- var firstContainer = dom.createDom(
- goog.dom.TagName.DIV, goog.ui.SplitPane.FIRST_CONTAINER_CLASS_NAME_);
- var secondContainer = dom.createDom(
- goog.dom.TagName.DIV, goog.ui.SplitPane.SECOND_CONTAINER_CLASS_NAME_);
- var splitterHandle =
- dom.createDom(goog.dom.TagName.DIV, goog.ui.SplitPane.HANDLE_CLASS_NAME_);
-
- this.setElementInternal(
- dom.createDom(
- goog.dom.TagName.DIV, goog.ui.SplitPane.CLASS_NAME_, firstContainer,
- secondContainer, splitterHandle));
- this.firstComponentContainer_ = firstContainer;
- this.secondComponentContainer_ = secondContainer;
- this.splitpaneHandle_ = splitterHandle;
- this.setUpHandle_();
- this.finishSetup_();
- };
- 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;
- }
-
-
- 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;
-
- return true;
- };
- goog.ui.SplitPane.prototype.getElementToDecorate_ = function(
- rootElement, className) {
-
- var childElements = goog.dom.getChildren(rootElement);
- for (var i = 0; i < childElements.length; i++) {
- var childElement = goog.asserts.assertElement(childElements[i]);
- if (goog.dom.classlist.contains(childElement, className)) {
- return childElement;
- }
- }
-
- return goog.dom.getElementsByTagNameAndClass(null, className, rootElement)[0];
- };
- goog.ui.SplitPane.prototype.decorateInternal = function(element) {
- goog.ui.SplitPane.base(this, 'decorateInternal', element);
- this.setUpHandle_();
- var elSize = goog.style.getBorderBoxSize(element);
- this.setSize(new goog.math.Size(elSize.width, elSize.height));
- this.finishSetup_();
- };
- 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;
- };
- goog.ui.SplitPane.prototype.enterDocument = function() {
- goog.ui.SplitPane.base(this, 'enterDocument');
-
-
-
-
-
-
-
-
- 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_);
- };
- goog.ui.SplitPane.prototype.setInitialSize = function(size) {
- this.initialSize_ = size;
- };
- goog.ui.SplitPane.prototype.setHandleSize = function(size) {
- this.handleSize_ = size;
- };
- goog.ui.SplitPane.prototype.setContinuousResize = function(continuous) {
- this.continuousResize_ = continuous;
- };
- goog.ui.SplitPane.prototype.isVertical = function() {
- return this.orientation_ == goog.ui.SplitPane.Orientation.VERTICAL;
- };
- goog.ui.SplitPane.prototype.setUpHandle_ = function() {
- if (this.isVertical()) {
- this.splitpaneHandle_.style.height = this.handleSize_ + 'px';
- goog.dom.classlist.add(
- this.splitpaneHandle_, goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_);
- } else {
- this.splitpaneHandle_.style.width = this.handleSize_ + 'px';
- goog.dom.classlist.add(
- this.splitpaneHandle_, goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_);
- }
- };
- goog.ui.SplitPane.prototype.setOrientationClassForHandle = function() {
- goog.asserts.assert(this.splitpaneHandle_);
- if (this.isVertical()) {
- goog.dom.classlist.swap(
- this.splitpaneHandle_, goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_,
- goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_);
- } else {
- goog.dom.classlist.swap(
- this.splitpaneHandle_, goog.ui.SplitPane.HANDLE_CLASS_NAME_VERTICAL_,
- goog.ui.SplitPane.HANDLE_CLASS_NAME_HORIZONTAL_);
- }
- };
- goog.ui.SplitPane.prototype.setOrientation = function(orientation) {
- if (this.orientation_ != orientation) {
- this.orientation_ = orientation;
- var isVertical = this.isVertical();
-
-
- if (this.isInDocument()) {
- this.setOrientationClassForHandle();
-
- if (goog.isNumber(this.firstComponentSize_)) {
- var splitpaneSize = goog.style.getBorderBoxSize(this.getElement());
- var ratio = isVertical ? splitpaneSize.height / splitpaneSize.width :
- splitpaneSize.width / splitpaneSize.height;
-
-
-
-
- this.setFirstComponentSize(this.firstComponentSize_ * ratio);
- } else {
- this.setFirstComponentSize();
- }
- }
- }
- };
- goog.ui.SplitPane.prototype.getOrientation = function() {
- return this.orientation_;
- };
- goog.ui.SplitPane.prototype.moveAndSize_ = function(element, rect) {
- goog.style.setPosition(element, rect.left, rect.top);
-
- goog.style.setBorderBoxSize(
- element,
- new goog.math.Size(Math.max(rect.width, 0), Math.max(rect.height, 0)));
- };
- goog.ui.SplitPane.prototype.getFirstComponentSize = function() {
- return this.firstComponentSize_;
- };
- goog.ui.SplitPane.prototype.setFirstComponentSize = function(opt_size) {
- this.setFirstComponentSize_(
- goog.style.getBorderBoxSize(this.getElement()), opt_size);
- };
- goog.ui.SplitPane.prototype.setFirstComponentSize_ = function(
- splitpaneSize, opt_size) {
- var top = 0, left = 0;
- var isVertical = this.isVertical();
-
-
- 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) {
-
-
-
-
-
- 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 {
-
-
-
-
-
- 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;
- }
-
- 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));
- }
-
- this.dispatchEvent(goog.ui.Component.EventType.CHANGE);
- };
- goog.ui.SplitPane.prototype.setSize = function(size, opt_firstComponentSize) {
- goog.style.setBorderBoxSize(this.getElement(), size);
- if (this.iframeOverlay_) {
- goog.style.setBorderBoxSize(this.iframeOverlay_, size);
- }
- this.setFirstComponentSize_(size, opt_firstComponentSize);
- };
- 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();
-
-
- 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.setFirstComponentSize(this.savedSnapSize_);
- } else {
-
-
- if (isVertical) {
- this.savedSnapSize_ =
- goog.style.getBorderBoxSize(this.firstComponentContainer_).height;
- } else {
- this.savedSnapSize_ =
- goog.style.getBorderBoxSize(this.firstComponentContainer_).width;
- }
- this.setFirstComponentSize(snapSize);
- }
-
- this.dispatchEvent(goog.ui.SplitPane.EventType.HANDLE_SNAP);
- };
- goog.ui.SplitPane.prototype.handleDragStart_ = function(e) {
-
- if (!this.iframeOverlay_) {
-
- var cssStyles = 'position: relative';
- if (goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('10')) {
-
-
- cssStyles += ';background-color: #000;filter: Alpha(Opacity=0)';
- }
- this.iframeOverlay_ = this.getDomHelper().createDom(
- goog.dom.TagName.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_);
-
-
-
-
-
-
- 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);
- };
- goog.ui.SplitPane.prototype.getRelativeLeft_ = function(left) {
- return left - goog.style.getPosition(this.firstComponentContainer_).x;
- };
- goog.ui.SplitPane.prototype.getRelativeTop_ = function(top) {
- return top - goog.style.getPosition(this.firstComponentContainer_).y;
- };
- 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);
- }
- };
- goog.ui.SplitPane.prototype.handleDragEnd_ = function(e) {
-
- 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);
- };
- goog.ui.SplitPane.prototype.handleDoubleClick_ = function(e) {
- this.snapIt_();
- };
- goog.ui.SplitPane.prototype.disposeInternal = function() {
- goog.dispose(this.splitDragger_);
- this.splitDragger_ = null;
- goog.dom.removeNode(this.iframeOverlay_);
- this.iframeOverlay_ = null;
- goog.ui.SplitPane.base(this, 'disposeInternal');
- };
|