Exemple #1
0
        protected override void OnResizeStart(Size size, bool preserveAspectRatio)
        {
            _resizeUndo = EditorContext.CreateUndoUnit();
            base.OnResizeStart(size, preserveAspectRatio);

            // save references
            _initialParentSize   = size;
            _preserveAspectRatio = preserveAspectRatio;

            // initialize smart content
            string contentSourceId;
            string contentId;

            ContentSourceManager.ParseContainingElementId(HTMLElement.id, out contentSourceId, out contentId);

            // clone the smart content for resizing so that settings changes made during the resize
            //operation are undoable
            String       newContentId = Guid.NewGuid().ToString();
            SmartContent content      = (SmartContent)_contentSourceContext.CloneSmartContent(contentId, newContentId);

            if (content == null)
            {
                Trace.WriteLine("Could not clone smart content for resize.");
                return;
            }

            HTMLElement.id = ContentSourceManager.MakeContainingElementId(contentSourceId, newContentId);

            // call sizer
            ResizeOptions resizeOptions = new ResizeOptions();

            _contentSource.OnResizeStart(content, resizeOptions);

            // determine the target size
            IHTMLElement targetSizeElement = GetResizeTargetElement(resizeOptions.ResizeableElementId);

            _initialTargetSize = new Size(targetSizeElement.offsetWidth, targetSizeElement.offsetHeight);
            // Account for areas of the smart content that are not being scaled when preserving aspect ratio.
            // For example, in YouTube plugin, label text below the image.
            UpdateResizerAspectRatioOffset(_initialParentSize - _initialTargetSize);

            // determine the aspect ratio
            if (resizeOptions.AspectRatio > 0)
            {
                _aspectRatio = resizeOptions.AspectRatio;
            }
            else
            {
                _aspectRatio = ((double)_initialTargetSize.Width) / _initialTargetSize.Height;
            }
        }
Exemple #2
0
        /// <summary>
        /// Clones active smart content contained in the provided HTML, and disables unknown smart content.
        /// </summary>
        public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext)
        {
            StringBuilder output = new StringBuilder();

            ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate();
            SimpleHtmlParser p = new SimpleHtmlParser(html);

            for (Element el; null != (el = p.Next());)
            {
                if (predicate.IsMatch(el))
                {
                    BeginTag bt     = el as BeginTag;
                    Attr     idAttr = bt.GetAttribute("id");

                    String contentSourceId, contentItemId;
                    ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId);
                    ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId);
                    if (smartContent != null)
                    {
                        String newId = Guid.NewGuid().ToString();
                        sourceContext.CloneSmartContent(contentItemId, newId);

                        if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId))
                        {
                            IExtensionData extensionData = sourceContext.FindExtentsionData(newId);
                            Debug.Assert(extensionData != null);

                            // Since we just made a new id for the smart content just about to be inserted
                            // we want to give it a chance to get a callback because its callback might have happened while
                            // it was on the clipboard(in the event of cut).  This means the refreshable content manager doesnt know
                            // to watch out for this smart content on paste, it only knows to look out for who created it.   Thus
                            // we just force the callback, and if it didnt need it, nothing will happen.
                            if (extensionData.RefreshCallBack == null)
                            {
                                extensionData.RefreshCallBack = DateTime.UtcNow;
                            }
                        }


                        idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId);
                    }
                    else
                    {
                        ContentSourceManager.RemoveSmartContentAttributes(bt);
                    }
                }
                output.Append(el.ToString());
            }
            return(output.ToString());
        }
        /// <summary>
        /// Clones active smart content contained in the provided HTML, and disables unknown smart content.
        /// </summary>
        public static string PrepareSmartContentHtmlForEditorInsertion(string html, IContentSourceSidebarContext sourceContext)
        {
            StringBuilder output = new StringBuilder();
            ContentSourceManager.SmartContentPredicate predicate = new ContentSourceManager.SmartContentPredicate();
            SimpleHtmlParser p = new SimpleHtmlParser(html);
            for (Element el; null != (el = p.Next());)
            {
                if (predicate.IsMatch(el))
                {
                    BeginTag bt = el as BeginTag;
                    Attr idAttr = bt.GetAttribute("id");

                    String contentSourceId, contentItemId;
                    ContentSourceManager.ParseContainingElementId(idAttr.Value, out contentSourceId, out contentItemId);
                    ISmartContent smartContent = sourceContext.FindSmartContent(contentItemId);
                    if (smartContent != null)
                    {
                        String newId = Guid.NewGuid().ToString();
                        sourceContext.CloneSmartContent(contentItemId, newId);

                        if (RefreshableContentManager.ContentSourcesWithRefreshableContent.Contains(contentSourceId))
                        {
                            IExtensionData extensionData = sourceContext.FindExtentsionData(newId);
                            Debug.Assert(extensionData != null);

                            // Since we just made a new id for the smart content just about to be inserted
                            // we want to give it a chance to get a callback because its callback might have happened while
                            // it was on the clipboard(in the event of cut).  This means the refreshable content manager doesnt know
                            // to watch out for this smart content on paste, it only knows to look out for who created it.   Thus
                            // we just force the callback, and if it didnt need it, nothing will happen.
                            if (extensionData.RefreshCallBack == null)
                            {
                                extensionData.RefreshCallBack = DateTime.UtcNow;
                            }
                        }

                        idAttr.Value = ContentSourceManager.MakeContainingElementId(contentSourceId, newId);
                    }
                    else
                    {
                        ContentSourceManager.RemoveSmartContentAttributes(bt);
                    }
                }
                output.Append(el.ToString());
            }
            return output.ToString();
        }