📄 canvasitem.js
字号:
// place the Canvas over the cell for the item // figure out the spacer's coordinates within the form var containerHandle = this.containerWidget.getClipHandle(), spacerParent = isc.Element.get(this.getID() + "_spacerParent"), left = isc.Element._getLeftOffsetFromElement(spacerParent, containerHandle), top = isc.Element._getTopOffsetFromElement(spacerParent, containerHandle); // this.logWarn("placing Canvas at: " + [left, top]); // place the Canvas on top of that cell canvas.moveTo(left, top); if (canvas.visibility == isc.Canvas.HIDDEN) { canvas.show(); } if (!delayed && isc.Browser.isMac && isc.Browser.isMoz && left == 0 && top == 0) { isc.Timer.setTimeout({target:this, methodName:"_delayedPlaceCanvas"}, 0); } }, _delayedPlaceCanvas : function () { this.placeCanvas(true); }, cleared : function () { // when a canvasItem gets cleared, ensure the canvas is cleared too if (this.canvas && this.canvas.isDrawn()) this.canvas.clear(); }, // ensure the canvas floats in the right place if the item is moved moved : function () { if (this.isDrawn()) this.placeCanvas(); }, // Sizing // --------------------------------------------------------------------------------------- checkCanvasOverflow : function () { return this.sizeCanvas(true); }, sizeCanvas : function (firstResizePass) { var canvas = this.canvas; // if we can't overflow in the height direction, we don't need to do anything on the // first sizing pass if (firstResizePass && !(canvas.overflow == isc.Canvas.VISIBLE || canvas.overflow == isc.Canvas.CLIP_H)) { this.logDebug("ignoring first pass, can't overflow", "canvasItemSizing"); return; } // get the sizes specified by layout policy var policyWidth = this.getInnerWidth(), policyHeight = this.getInnerHeight(), resizeWidth, resizeHeight; // we feed the specified height (whether it appears on the Canvas or CanvasItem) to // TableResizePolicy; if we give it a pixel size it will feed that back. If we give it // a variable size (percent or "*"), that size will be incorporated into sizing the row // as a whole and we'll get the row height back. resizeHeight = policyHeight; // TableResizePolicy doesn't consider the specified width of items when determining // column widths. Hence only apply the width if our width is unset or "*" var specifiedWidth = canvas._userWidth || this.width; resizeWidth = (specifiedWidth == null || specifiedWidth == "*" ? policyWidth : specifiedWidth); // if width is not increasing past the current overflowed size, don't try to reduce the // height of an height-overflowed Canvas to less than the overflowed size, because // there's no reason to expect it to shrink (unless it's dirty, in which case we assume // it might change size) if (!canvas.isDirty() && (resizeWidth == null || resizeWidth <= canvas.getVisibleWidth()) && canvas.getHeight() < canvas.getVisibleHeight() && resizeHeight <= canvas.getVisibleHeight()) { this.logDebug("not applying height: " + resizeHeight + " to overflowed Canvas with height: " + canvas.getVisibleHeight(), "canvasItemSizing"); resizeHeight = null; } if (!isc.isA.Number(resizeWidth)) resizeWidth = null; if (!isc.isA.Number(resizeHeight)) resizeHeight = null; this._resizingCanvas = true; canvas.resizeTo(resizeWidth, resizeHeight); this._resizingCanvas = false; this.logDebug("this._size: " + this._size + ", policy size: " + [policyWidth, policyHeight] + ", specifiedSize: " + [specifiedWidth, canvas._userHeight || this.height] + ", Resized Canvas to: " + [resizeWidth, resizeHeight], "canvasItemSizing"); // draw or redraw the Canvas so we get an accurate size if (!canvas.isDrawn()) canvas.draw(); else canvas.redrawIfDirty("CanvasItem getting new size"); var width = canvas.getVisibleWidth(), height = canvas.getVisibleHeight(); this.logDebug("visible size of embedded Canvas: " + [width, height], "canvasItemSizing"); // if the Canvas overflows in the height direction, set this as a minimum if (!firstResizePass) this.minHeight = null; else this.minHeight = height > canvas.getHeight() ? height : null; // policyHeight is the space allocated to the row(s) this Canvas spans. If we've // exceeded the space that table sizing policy allocated to our row(s), the policy will // need to be rerun, in order to reallocate space among other items that can flex. // Note: doesn't matter if we've exceeded width; our width isn't taken into account by // the policy. // Note: doesn't matter whether the Canvas has actually overflowed it's own specified // size, which might be much smaller; eg a button next to a TextArea doesn't need to be // as tall as the TextArea. if (height > policyHeight) return true; }, // Rather than embedding HTML for the canvas into the form, we write out a spacer of the // appropriate size, and float the Canvas over it. getElementHTML : function (value) { var canvas = this.canvas; // size the Canvas to the final size determined by the resize policy this.sizeCanvas(); // Ensure that the canvas has it's tab index written out as specified this._setElementTabIndex(this.getGlobalTabIndex()); return "<SPAN style='padding:0px;margin:0px;' ID='" + this.getID() + "_spacerParent'>" + isc.Canvas.spacerHTML(canvas.getVisibleWidth(), canvas.getVisibleHeight()) + "</SPAN>"; }, _applyHandlersToElement : function () { this._setUpIconEventHandlers(); }, // return specified widths (which can be %s or *s), whether they appear on the Canvas or // CanvasItem, to be fed to the table resize policy. If there is no specified size, feed // the layout policy our default height. getHeight : function (reportOverflowedSize) { var canvas = this.canvas; if (reportOverflowedSize) { var visibleHeight = canvas.getVisibleHeight(); if (visibleHeight > canvas.getHeight()) return visibleHeight; } return this.canvas._userHeight || this.height || this.canvas.defaultHeight; }, getWidth : function () { return this.canvas._userWidth || this.width || this.canvas.defaultWidth; }, // if the Canvas is resized by the user or programmatically outside of CanvasItem's layout // code, canvasResized : function (deltaX, deltaY, reason) { if (this._resizingCanvas) return; var canvas = this.canvas, newWidth = canvas.getWidth(), newHeight = canvas.getHeight(); if (!canvas.isDrawn()) return; if (reason != "overflow") { if (deltaX != null && deltaX != 0) canvas._userWidth = newWidth; if (deltaY != null && deltaY != 0) canvas._userHeight = newHeight; } this.logDebug("canvas resized: new specified sizes: " + [newWidth, newHeight], "canvasItemSizing"); // redraw to change size this.redraw(); }, // override 'updateDisabled()' to disable the canvas updateDisabled : function () { this.Super("updateDisabled", arguments); this.canvas.setDisabled(this.isDisabled()); }, // Override _setElementTabIndex() to update the tabindex of the canvas (and avoid redrawing // the form) _setElementTabIndex : function (index) { this._setCanvasTabIndex(index); }, _setCanvasTabIndex : function (index) { var canvas = this.canvas; if (canvas) { // clears any pointers to prev/next in auto-tab-order canvas._removeFromAutoTabOrder(); // use the internal method so we don't hit the user-specified tabIndex ceiling canvas._setTabIndex(index, false); } }, // Override focusInItem / blurFocusItem to actually put focus into the canvas focusInItem : function () { if (this.canvas) this.canvas.focus(); return this.Super("focusInItem", arguments); }, blurItem : function () { if (this.canvas) this.canvas.blur(); return this.Super("blurItem", arguments); } });
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -