Ejemplo n.º 1
0
        private Size UpdateHtmlForResize(Size newSize, bool isComplete)
        {
            Size targetElementSize = newSize;

            if (_contentSource.ResizeCapabilities != ResizeCapabilities.None)
            {
                SmartContent content = SmartContent;

                //base the new size on target element preferred by the source
                //(apply the difference in size to the last known size of the target element)
                targetElementSize = new Size(
                    Math.Max(1, _initialTargetSize.Width + (newSize.Width - _initialParentSize.Width)),
                    Math.Max(1, _initialTargetSize.Height + (newSize.Height - _initialParentSize.Height))
                    );

                if (_preserveAspectRatio)
                {
                    targetElementSize = Utility.GetScaledMaxSize(_aspectRatio, targetElementSize.Width, targetElementSize.Height);
                }

                //let the resizer know about the new size, and regenerate the content
                if (isComplete)
                {
                    _contentSource.OnResizeComplete(content, targetElementSize);
                }
                else
                {
                    _contentSource.OnResizing(content, targetElementSize);
                }

                //insert the new content into the DOM (TODO: need undo support for this)
                SmartContentInsertionHelper.InsertEditorHtmlIntoElement(_contentSourceContext, _contentSource, content, HTMLElement);

                Invalidate();

                if (_resizedListener != null)
                {
                    _resizedListener(newSize, isComplete);
                }

                EditorContext.DamageServices.AddDamage(EditorContext.MarkupServices.CreateMarkupRange(HTMLElement, false));
            }
            return(targetElementSize);
        }