Example #1
0
        /// <summary>
        /// Handles click events on the targets and shows the color picker.
        /// </summary>
        /// <param name="e"> The browser event.</param>
        private void show_(goog.events.BrowserEvent e)
        {
            if (!this.initialized_)
            {
                this.colorPicker_ = this.colorPicker_ == null ? null :
                                    goog.ui.ColorPicker.createSimpleColorGrid(this.getDomHelper());
                this.colorPicker_.setFocusable(this.focusable_);
                this.addChild(this.colorPicker_, true);
                this.getHandler().listen <events.Event>(
                    this.colorPicker_, goog.ui.ColorPicker.EventType.CHANGE,
                    this.onColorPicked_);
                this.initialized_ = true;
            }

            if (this.popup_.isOrWasRecentlyVisible() && this.toggleMode_ &&
                this.lastTarget_ == e.currentTarget)
            {
                this.popup_.setVisible(false);
                return;
            }

            this.lastTarget_ = (HTMLElement)(e.currentTarget);
            this.popup_.setPosition(
                new goog.positioning.AnchoredPosition(
                    this.lastTarget_, this.popupCorner_));
            if (!this.rememberSelection_)
            {
                this.colorPicker_.setSelectedIndex(-1);
            }
            this.popup_.setVisible(true);
            if (this.allowAutoFocus_)
            {
                this.colorPicker_.focus();
            }
        }
Example #2
0
        /// <summary>
        /// Handles blur on the tree.
        /// </summary>
        /// <param name="e">The browser event.</param>
        private void handleBlur_(goog.events.BrowserEvent e)
        {
            this.focused_ = false;
            var el = this.getElement();

            goog.asserts.assert(el != null);
            goog.dom.classlist.remove(el, goog.Css.getCssName("focused"));
        }
Example #3
0
 /// <summary>
 /// Handles key-downs on the document to handle the escape key.
 /// </summary>
 /// <param name="e"> The event object.</param>
 private void onDocumentKeyDown_(goog.events.BrowserEvent e)
 {
     if (e.keyCode == (int)goog.events.KeyCodes.ESC)
     {
         if (this.hide_((Node)e.target))
         {
             // Eat the escape key, but only if this popup was actually closed.
             e.preventDefault();
             e.stopPropagation();
         }
     }
 }
Example #4
0
        /// <summary>
        /// Mouse down handler for the document on capture phase. Used to hide the
        /// popup for auto-hide mode.
        /// </summary>
        /// <param name="e"> The event object.</param>
        private void onDocumentMouseDown_(goog.events.BrowserEvent e)
        {
            var target = (Node)e.target;

            if (!goog.dom.contains(this.element_, target) &&
                !this.isOrWithinAutoHidePartner_(target) &&
                this.isWithinAutoHideRegion_(target) && !this.shouldDebounce_())
            {
                // Mouse click was outside popup and partners, so hide.
                this.hide_(target);
            }
        }
Example #5
0
        /// <summary>
        /// Handles focus on the tree.
        /// </summary>
        /// <param name="e">The browser event.</param>
        private void handleFocus_(goog.events.BrowserEvent e)
        {
            this.focused_ = true;
            var el = this.getElement();

            goog.asserts.assert(el != null);
            goog.dom.classlist.add(el, goog.Css.getCssName("focused"));

            if (this.selectedItem_ != null)
            {
                this.selectedItem_.select();
            }
        }
Example #6
0
        /// <summary>
        /// Handles mousedown events.  Overrides {@link goog.ui.Control#handleMouseDown}
        /// by ensuring that the item on which the user moused down is highlighted.
        /// </summary>
        /// <param name="e">Mouse event to handle.</param>
        public override void handleMouseDown(goog.events.BrowserEvent e)
        {
            base.handleMouseDown(e);

            if (this.isActive())
            {
                // Make sure we move the highlight to the cell on which the user moused
                // down.
                var item = ((PaletteRenderer)this.getRenderer()).getContainingItem(this, (Node)e.target);
                if (item != this.getHighlightedItem())
                {
                    this.setHighlightedItem(item);
                }
            }
        }
Example #7
0
        /// <summary>
        /// Handles navigation keys.
        /// </summary>
        /// <param name="e">The browser event.</param>
        /// <returns>The handled value.</returns>
        public bool handleNavigation(goog.events.BrowserEvent e)
        {
            var handled = false;

            switch ((goog.events.KeyCodes)e.keyCode)
            {
            // Handle ctrl+down, ctrl+up to navigate within typeahead results.
            case goog.events.KeyCodes.DOWN:
            case goog.events.KeyCodes.UP:
                if (e.ctrlKey)
                {
                    this.jumpTo_(
                        (goog.events.KeyCodes)e.keyCode == goog.events.KeyCodes.DOWN ?
                        goog.ui.tree.TypeAhead.Offset.DOWN :
                        goog.ui.tree.TypeAhead.Offset.UP);
                    handled = true;
                }
                break;

            // Remove the last typeahead char.
            case goog.events.KeyCodes.BACKSPACE:
                var length = this.buffer_.Length - 1;
                handled = true;
                if (length > 0)
                {
                    this.buffer_ = this.buffer_.Substring(0, length);
                    this.jumpToLabel_(this.buffer_);
                }
                else if (length == 0)
                {
                    // Clear the last character in typeahead.
                    this.buffer_ = "";
                }
                else
                {
                    handled = false;
                }
                break;

            // Clear typeahead buffer.
            case goog.events.KeyCodes.ESC:
                this.buffer_ = "";
                handled      = true;
                break;
            }

            return(handled);
        }
Example #8
0
            /// <summary>
            /// Handles touch events.
            /// </summary>
            /// <param name="e">The browser event.</param>
            private void handleTouchEvent_(TouchEvent e)
            {
                var be = new goog.events.BrowserEvent(e);

                e.PreventDefault();
                var node = this.getNodeFromEvent_(be);

                if (node != null && e.Type == goog.events.EventType.TOUCHSTART)
                {
                    // Fire asynchronously since onMouseDown takes long enough that the browser
                    // would fire the default mouse event before this method returns.
                    Window.SetTimeout(() => {
                        node.onMouseDown(be);                          // Same behaviour for click and touch.
                    }, 1);
                }
            }
Example #9
0
        /// <summary>
        /// Handles key down on the tree.
        /// </summary>
        /// <param name="e">The browser event.</param>
        /// <returns>The handled value.</returns>
        public bool handleKeyEvent(goog.events.BrowserEvent e)
        {
            var handled = false;

            // Handle typeahead and navigation keystrokes.
            handled = this.typeAhead_.handleNavigation(e) ||
                      (this.selectedItem_ != null && this.selectedItem_.onKeyDown(e)) ||
                      this.typeAhead_.handleTypeAheadChar(e);

            if (handled)
            {
                e.preventDefault();
            }

            return(handled);
        }
Example #10
0
        // Palette event handling.


        /// <summary>
        /// Handles mouseover events.  Overrides {@link goog.ui.Control#handleMouseOver}
        /// by determining which palette item (if any) was moused over, highlighting it,
        /// and un-highlighting any previously-highlighted item.
        /// </summary>
        /// <param name="e">Mouse event to handle.</param>
        public override void handleMouseOver(goog.events.BrowserEvent e)
        {
            base.handleMouseOver(e);

            var item = ((PaletteRenderer)this.getRenderer()).getContainingItem(this, (Node)e.target);

            if (item != null && e.relatedTarget != null && goog.dom.contains(item, (Node)e.relatedTarget))
            {
                // Ignore internal mouse moves.
                return;
            }

            if (item != this.getHighlightedItem())
            {
                this.setHighlightedItem(item);
            }
        }
Example #11
0
        /// <summary>
        /// Handles the character presses.
        /// </summary>
        /// <param name="e">The browser event.</param>
        /// <returns>The handled value.</returns>
        public bool handleTypeAheadChar(goog.events.BrowserEvent e)
        {
            var handled = false;

            if (!e.ctrlKey && !e.altKey)
            {
                // Since goog.structs.Trie.getKeys compares characters during
                // lookup, we should use charCode instead of keyCode where possible.
                // Convert to lowercase, typeahead is case insensitive.
                var ch = Char.ConvertFromUtf32(e.charCode != 0 ? e.charCode : e.keyCode).ToLowerCase();
                if (/*goog.string.isUnicode(ch) &&*/ (ch != " " || this.buffer_ != null))
                {
                    this.buffer_ += ch;
                    handled       = this.jumpToLabel_(this.buffer_);
                }
            }

            return(handled);
        }
Example #12
0
        /// <summary>
        /// Finds the containing node given an event.
        /// </summary>
        /// <param name="e">The browser event.</param>
        /// <returns>The containing node or null if no node is</returns>
        protected BaseNode getNodeFromEvent_(goog.events.BrowserEvent e)
        {
            // find the right node
            var target = (HTMLElement)e.target;

            while (target != null)
            {
                var id = target.Id;
                if (id != null && goog.ui.tree.BaseNode.allNodes.TryGetValue(id, out var node))
                {
                    return(node);
                }
                if (target == this.getElement())
                {
                    break;
                }
                target = (HTMLElement)target.ParentNode;
            }
            return(null);
        }
Example #13
0
        /// <summary>
        /// Handles mouse events.
        /// </summary>
        /// <param name="e">The browser event.</param>
        private void handleMouseEvent_(goog.events.BrowserEvent e)
        {
            goog.log.fine(this.logger_, "Received event " + e.type);
            var node = this.getNodeFromEvent_(e);

            if (node != null)
            {
                switch (e.type)
                {
                case goog.events.EventType.MOUSEDOWN:
                    node.onMouseDown(e);
                    break;

                case goog.events.EventType.CLICK:
                    node.onClick_(e);
                    break;

                case goog.events.EventType.DBLCLICK:
                    node.onDoubleClick_(e);
                    break;
                }
            }
        }
Example #14
0
        /// <summary>
        /// Deactivate handler(IE) and blur handler (other browsers) for document.
        /// Used to hide the popup for auto-hide mode.
        /// </summary>
        /// <param name="e"> The event object.</param>
        private void onDocumentBlur_(goog.events.BrowserEvent e)
        {
            if (!this.enableCrossIframeDismissal_)
            {
                return;
            }

            var doc = goog.dom.getOwnerDocument(this.element_);

            // Ignore blur events if the active element is still inside the popup or if
            // there is no longer an active element.  For example, a widget like a
            // goog.ui.Button might programatically blur itself before losing tabIndex.
            if (Document.ActiveElement != null)
            {
                var activeElement = doc.ActiveElement;
                if (activeElement == null || goog.dom.contains(this.element_, activeElement) ||
                    activeElement.TagName == goog.dom.TagName.BODY)
                {
                    return;
                }

                // Ignore blur events not for the document itself in non-IE browsers.
            }
            else if (e.target != doc)
            {
                return;
            }

            // Debounce the initial focus move.
            if (this.shouldDebounce_())
            {
                return;
            }

            this.hide_();
        }
Example #15
0
        /// <summary>
        /// Handles an event and dispatches it to the correct listeners. This
        /// function is a proxy for the real listener the user specified.
        /// </summary>
        /// <param name="listener">The listener object.</param>
        /// <param name="opt_evt">Optional event object that gets passed in via the
        /// native event handlers.</param>
        /// <returns>Result of the event handler.</returns>
        private static bool handleBrowserEvent_(Bridge.Html5.EventTarget _this, goog.events.Listener listener, Bridge.Html5.Event opt_evt = null)
        {
            if (listener.removed)
            {
                return(true);
            }

            // Synthesize event propagation if the browser does not support W3C
            // event model.
            if (!goog.events.BrowserFeature.HAS_W3C_EVENT_SUPPORT)
            {
                var ieEvent = opt_evt ??
                              ((Bridge.Html5.Event)goog.le.getObjectByName("window.event"));
                var evt = new goog.events.BrowserEvent(ieEvent, _this);
                /** @type {boolean} */
                var retval = true;

                if (goog.events.CAPTURE_SIMULATION_MODE ==
                    goog.events.CaptureSimulationMode.ON)
                {
                    // If we have not marked this event yet, we should perform capture
                    // simulation.
                    if (!goog.events.isMarkedIeEvent_(ieEvent))
                    {
                        goog.events.markIeEvent_(ieEvent);

                        var ancestors = new JsArray <Node>();
                        for (var parent = (Node)evt.currentTarget; parent != null;
                             parent = parent.ParentNode)
                        {
                            ancestors.Push(parent);
                        }

                        // Fire capture listeners.
                        var type = listener.type;
                        for (var i = ancestors.Length - 1; !evt.propagationStopped_ && i >= 0;
                             i--)
                        {
                            evt.currentTarget = ancestors[i];
                            var result =
                                goog.events.fireListeners_(ancestors[i], type, true, evt);
                            retval = retval && result != null;
                        }

                        // Fire bubble listeners.
                        //
                        // We can technically rely on IE to perform bubble event
                        // propagation. However, it turns out that IE fires events in
                        // opposite order of attachEvent registration, which broke
                        // some code and tests that rely on the order. (While W3C DOM
                        // Level 2 Events TR leaves the event ordering unspecified,
                        // modern browsers and W3C DOM Level 3 Events Working Draft
                        // actually specify the order as the registration order.)
                        for (var i = 0; !evt.propagationStopped_ && i < ancestors.Length; i++)
                        {
                            evt.currentTarget = ancestors[i];
                            var result =
                                goog.events.fireListeners_(ancestors[i], type, false, evt);
                            retval = retval && result != null;
                        }
                    }
                }
                else
                {
                    retval = goog.events.fireListener(listener, evt);
                }
                return(retval);
            }

            // Otherwise, simply fire the listener.
            return(goog.events.fireListener(
                       listener, new goog.events.BrowserEvent(opt_evt, _this)));
        }