Ejemplo n.º 1
0
        /// <summary>
        /// Inject the CSS into the DOM.  This is preferable over using a regular CSS
        /// file since:
        /// a) It loads synchronously and doesn't force a redraw later.
        /// b) It speeds up loading by not blocking on a separate HTTP transfer.
        /// c) The CSS content may be made dynamic depending on init options.
        /// </summary>
        /// <param name="hasCss">If false, don't inject CSS
        /// (providing CSS becomes the document's responsibility).</param>
        /// <param name="pathToMedia">Path from page to the Blockly media directory.</param>
        public static void inject(bool hasCss, string pathToMedia)
        {
            // Only inject the CSS once.
            if (Css.styleSheet_ != null)
            {
                return;
            }
            // Placeholder for cursor rule.  Must be first rule (index 0).
            var text = ".blocklyDraggable {}\n";

            if (hasCss)
            {
                text += Css.CONTENT.Join("\n");
                if (true /*Blockly.FieldDate != null*/)
                {
                    text += FieldDate.CSS.Join("\n");
                }
            }
            // Strip off any trailing slash (either Unix or Windows).
            Css.mediaPath_ = pathToMedia.Replace(new Regex(@"[\\\/]$"), "");
            text           = text.Replace(new Regex(@"<<<PATH>>>", RegexOptions.Multiline), Css.mediaPath_);
            // Inject CSS tag.
            var cssNode = Document.CreateElement <HTMLStyleElement>("style");

            Document.Head.AppendChild(cssNode);
            var cssTextNode = Document.CreateTextNode(text);

            cssNode.AppendChild(cssTextNode);
            Css.styleSheet_ = cssNode.Sheet;
            Css.setCursor(Css.Cursor.OPEN);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle a mouse-down on bubble's border.
        /// </summary>
        /// <param name="e">Mouse down event.</param>
        private void bubbleMouseDown_(MouseEvent e)
        {
            this.promote_();
            Bubble.unbindDragEvents_();
            if (Core.isRightButton(e))
            {
                // No right-click.
                e.StopPropagation();
                return;
            }
            else if (Core.isTargetInput_(e))
            {
                // When focused on an HTML text input widget, don't trap any events.
                return;
            }
            // Left-click (or middle click)
            Css.setCursor(Css.Cursor.CLOSED);

            this.workspace_.startDrag(e, new goog.math.Coordinate(
                                          this.workspace_.RTL ? -this.relativeLeft_ : this.relativeLeft_,
                                          this.relativeTop_));

            Bubble.onMouseUpWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                 "mouseup", this, new Action <MouseEvent>(Bubble.bubbleMouseUp_));
            Bubble.onMouseMoveWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                   "mousemove", this, new Action <MouseEvent>(this.bubbleMouseMove_));
            Core.hideChaff();
            // This event has been handled.  No need to bubble up to the document.
            e.StopPropagation();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle a mouse-up anywhere on the page.
        /// </summary>
        /// <param name="e">Mouse up event.</param>
        internal static void onMouseUp_(Event e)
        {
            var workspace = Core.getMainWorkspace();

            if (workspace.dragMode_ == Core.DRAG_NONE)
            {
                return;
            }
            Touch.clearTouchIdentifier();
            Css.setCursor(Css.Cursor.OPEN);
            workspace.dragMode_ = Core.DRAG_NONE;
            // Unbind the touch event if it exists.
            if (Touch.onTouchUpWrapper_ != null)
            {
                Core.unbindEvent_(Touch.onTouchUpWrapper_);
                Touch.onTouchUpWrapper_ = null;
            }
            if (Core.onMouseMoveWrapper_ != null)
            {
                Core.unbindEvent_(Core.onMouseMoveWrapper_);
                Core.onMouseMoveWrapper_ = null;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Handle a mouse-down on bubble's resize corner.
        /// </summary>
        /// <param name="e">Mouse down event.</param>
        private void resizeMouseDown_(MouseEvent e)
        {
            this.promote_();
            Bubble.unbindDragEvents_();
            if (Core.isRightButton(e))
            {
                // No right-click.
                e.StopPropagation();
                return;
            }
            // Left-click (or middle click)
            Css.setCursor(Css.Cursor.CLOSED);

            this.workspace_.startDrag(e, new goog.math.Coordinate(
                                          this.workspace_.RTL ? -this.width_ : this.width_, this.height_));

            Bubble.onMouseUpWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                 "mouseup", null, new Action <MouseEvent>(Bubble.bubbleMouseUp_));
            Bubble.onMouseMoveWrapper_ = Core.bindEventWithChecks_(Document.Instance,
                                                                   "mousemove", this, new Action <MouseEvent>(this.resizeMouseMove_));
            Core.hideChaff();
            // This event has been handled.  No need to bubble up to the document.
            e.StopPropagation();
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Handle a mouse-up event while dragging a bubble's border or resize handle.
 /// </summary>
 /// <param name="e">Mouse up event.</param>
 private static void bubbleMouseUp_(MouseEvent e)
 {
     Touch.clearTouchIdentifier();
     Css.setCursor(Css.Cursor.OPEN);
     Bubble.unbindDragEvents_();
 }