コード例 #1
0
 public EventRegistration(
     UIElement owner,
     string eventName,
     bool onCapturePhase               = false,
     bool canBubbleNatively            = false,
     HtmlEventFilter?eventFilter       = null,
     HtmlEventExtractor?eventExtractor = null,
     EventArgsParser payloadConverter  = null)
 {
     _owner             = owner;
     _eventName         = eventName;
     _canBubbleNatively = canBubbleNatively;
     _payloadConverter  = payloadConverter;
     if (noRegistrationEventNames.Contains(eventName))
     {
         _subscribeCommand = null;
     }
     else
     {
         _subscribeCommand = () => WindowManagerInterop.RegisterEventOnView(
             _owner.HtmlId,
             eventName,
             onCapturePhase,
             (int)(eventFilter ?? HtmlEventFilter.None),
             (int)(eventExtractor ?? HtmlEventExtractor.None)
             );
     }
 }
コード例 #2
0
        private void HandlePointerEvent(Input.PointerRoutedEventArgs e)
        {
            var(clientSize, offsetSize) = WindowManagerInterop.GetClientViewSize(HtmlId);

            bool hasHorizontalScroll = (offsetSize.Height - clientSize.Height) > 0;
            bool hasVerticalScroll   = (offsetSize.Width - clientSize.Width) > 0;

            if (this.Log().IsEnabled(LogLevel.Debug))
            {
                this.Log().LogDebug($"{HtmlId}: {offsetSize} / {clientSize} / {e.GetCurrentPoint(this)}");
            }

            if (!hasVerticalScroll && !hasHorizontalScroll)
            {
                return;
            }

            // The events coming from the scrollbars are bubbled up
            // to the parents, as those are not (yet) XAML elements.
            // This can cause issues for popups with scrollable content and
            // light dismiss patterns.
            var position = e.GetCurrentPoint(this).Position;
            var isInVerticalScrollbar   = hasVerticalScroll && position.X >= clientSize.Width;
            var isInHorizontalScrollbar = hasHorizontalScroll && position.Y >= clientSize.Height;

            if (isInVerticalScrollbar || isInHorizontalScrollbar)
            {
                e.Handled = true;
            }
        }
コード例 #3
0
            internal static int GetForType(Type type)
            {
                if (!_classNames.TryGetValue(type, out var classNamesRegistrationId))
                {
                    _classNames[type] = classNamesRegistrationId = WindowManagerInterop.RegisterUIElement(type.FullName, GetClassesForType(type).ToArray(), type.Is <FrameworkElement>());
                }

                return(classNamesRegistrationId);
            }
コード例 #4
0
        static partial void StartPartial(ApplicationInitializationCallback callback)
        {
            _startInvoked = true;

            var isHostedMode        = !WebAssemblyRuntime.IsWebAssembly;
            var isLoadEventsEnabled = !FeatureConfiguration.FrameworkElement.WasmUseManagedLoadedUnloaded;

            WindowManagerInterop.Init(isHostedMode, isLoadEventsEnabled);
            Windows.Storage.ApplicationData.Init();

            SynchronizationContext.SetSynchronizationContext(
                new CoreDispatcherSynchronizationContext(CoreDispatcher.Main, CoreDispatcherPriority.Normal)
                );

            callback(new ApplicationInitializationCallbackParams());
        }
コード例 #5
0
        /// <summary>
        /// If corresponding feature flag is enabled, set layout properties as DOM attributes to aid in debugging.
        /// </summary>
        private void UpdateDOMProperties()
        {
            if (FeatureConfiguration.UIElement.AssignDOMXamlProperties && IsLoaded)
            {
                SetXamlProperty(nameof(Margin), Margin);
                SetXamlProperty(nameof(HorizontalAlignment), HorizontalAlignment);
                SetXamlProperty(nameof(VerticalAlignment), VerticalAlignment);
                SetXamlProperty(nameof(Width), Width);
                SetXamlProperty(nameof(Height), Height);
                SetXamlProperty(nameof(MinWidth), MinWidth);
                SetXamlProperty(nameof(MinHeight), MinHeight);
                SetXamlProperty(nameof(MaxWidth), MaxWidth);
                SetXamlProperty(nameof(MaxHeight), MaxHeight);

                void SetXamlProperty(string propertyName, object value)
                {
                    WindowManagerInterop.SetAttribute(HtmlId, "xaml" + propertyName.ToLowerInvariant(), value?.ToString() ?? "[null]");
                }
            }
        }
コード例 #6
0
 /// <summary>
 /// Set one or many CSS styles on a HTML element.
 /// </summary>
 /// <remarks>
 /// The style is using the CSS syntax format, not the DOM syntax.
 /// Ex: for font size, use "font-size", not "fontSize".
 /// </remarks>
 public static void SetCssStyle(this UIElement element, string name, string value)
 {
     WindowManagerInterop.SetStyles(element.HtmlId, new[] { (name, value) });
コード例 #7
0
 public void ScrollTo(double?horizontalOffset, double?verticalOffset, bool disableAnimation)
 => WindowManagerInterop.ScrollTo(HtmlId, horizontalOffset, verticalOffset, disableAnimation);
コード例 #8
0
        internal void SetForeground(object localValue)
        {
            if (_brushSubscription != null)
            {
                _brushSubscription.Disposable = null;
            }

            switch (localValue)
            {
            case SolidColorBrush scb:
                WindowManagerInterop.SetElementColor(HtmlId, scb.ColorWithOpacity);
                break;

            case GradientBrush gradient:
                this.SetStyle(
                    ("background", gradient.ToCssString(this.RenderSize)),
                    ("color", "transparent"),
                    ("background-clip", "text")
                    );
                break;

            case ImageBrush imageBrush:
                _brushSubscription ??= new SerialDisposable();

                _brushSubscription.Disposable = imageBrush.Subscribe(img =>
                {
                    switch (img.Kind)
                    {
                    case ImageDataKind.Empty:
                    case ImageDataKind.Error:
                        this.ResetStyle(
                            "background-color",
                            "background-image",
                            "background-size");
                        this.SetStyle(
                            ("color", "transparent"),
                            ("background-clip", "text"));
                        break;

                    case ImageDataKind.DataUri:
                    case ImageDataKind.Url:
                    default:
                        this.SetStyle(
                            ("color", "transparent"),
                            ("background-clip", "text"),
                            ("background-color", ""),
                            ("background-origin", "content-box"),
                            ("background-position", imageBrush.ToCssPosition()),
                            ("background-size", imageBrush.ToCssBackgroundSize()),
                            ("background-image", "url(" + img.Value + ")")
                            );
                        break;
                    }
                });
                break;

            case AcrylicBrush acrylic:
                acrylic.Apply(this);
                this.SetStyle("background-clip", "text");
                break;

            case UnsetValue uv:

            // TODO: support other foreground types
            default:
                this.ResetStyle("color", "background", "background-clip");
                AcrylicBrush.ResetStyle(this);
                break;
            }
        }
コード例 #9
0
 /// <summary>
 /// Verifies if the current browser supports backdrop filter in CSS.
 /// </summary>
 /// <returns>Value indicating whether backdrop filter is supported.</returns>
 private static bool IsBackdropFilterSupported() =>
 _isBackdropFilterSupported ??= WindowManagerInterop.IsCssFeatureSupported(CssSupportCondition);