Ejemplo n.º 1
0
        internal void OnTextWrappingChanged(TextWrapping tw)
        {
            if (INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                switch (tw)
                {
                case TextWrapping.NoWrap:
                    INTERNAL_HtmlDomManager.GetDomElementStyleForModification(_contentEditableDiv).whiteSpace = "nowrap";
                    break;

                case TextWrapping.Wrap:
                    INTERNAL_HtmlDomManager.GetDomElementStyleForModification(_contentEditableDiv).whiteSpace = "pre-wrap";
                    //todo: once we find how to make the note work, apply the same thing to the TextBlock.
                    //Note: the following line would be useful to break the words when they are too long without spaces.
                    //      unfortunately, it only works in chrome.
                    //      The other browsers have wordBreak = "break-all" but that doesn't take into account the spaces to break the string.
                    //          it means it will break words in two when it could have gone to the next line before starting the word that overflows in the line.
                    //INTERNAL_HtmlDomManager.GetDomElementStyleForModification(textBox._contentEditableDiv).wordBreak = "break-word";
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 internal void OnVerticalScrollBarVisibilityChanged(ScrollBarVisibility scrollVisibility)
 {
     if (INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
     {
         string value = ScrollBarVisibilityToHtmlString(scrollVisibility);
         if (value != null)
         {
             INTERNAL_HtmlDomManager.GetDomElementStyleForModification(_contentEditableDiv).overflowY = value;
         }
     }
 }
Ejemplo n.º 3
0
        internal void OnMaxLengthChanged(int maxLength)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) &&
                INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                if (!IsRunningInJavaScript())
                {
                    //--- SIMULATOR ONLY: ---
                    // Set the "data-maxlength" property (that we have made up) so that the "keydown" JavaScript event can retrieve this value:
                    INTERNAL_HtmlDomManager.ExecuteJavaScript($@"
var element = document.getElementByIdSafe(""{((INTERNAL_HtmlDomElementReference)_contentEditableDiv).UniqueIdentifier}"");
element.setAttribute(""data-maxlength"", ""{maxLength}"");");
                }
            }
        }
Ejemplo n.º 4
0
        internal void OnAcceptsReturnChanged(bool acceptsReturn)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) &&
                INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                if (!IsRunningInJavaScript())
                {
                    //--- SIMULATOR ONLY: ---
                    // Set the "data-accepts-return" property (that we have invented) so that the "keydown" JavaScript event can retrieve this value:
                    INTERNAL_HtmlDomManager.ExecuteJavaScript($@"
var element = document.getElementByIdSafe(""{((INTERNAL_HtmlDomElementReference)_contentEditableDiv).UniqueIdentifier}"");
element.setAttribute(""data-acceptsreturn"", ""{acceptsReturn.ToString().ToLower()}"");");
                }
            }
        }
Ejemplo n.º 5
0
        protected internal void SetPointerAbsolutePosition(object jsEventArg, Window window)
        {
            if (Interop.IsRunningInTheSimulator)
            {
                _pointerAbsoluteX = Convert.ToDouble(Interop.ExecuteJavaScript("$0.pageX", jsEventArg));
                _pointerAbsoluteY = Convert.ToDouble(Interop.ExecuteJavaScript("$0.pageY", jsEventArg));
            }
            else
            {
                dynamic jsEventArgDynamic = (dynamic)jsEventArg;
                if (INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(jsEventArgDynamic.pageX))
                {
                    _pointerAbsoluteX = (double)jsEventArgDynamic.pageX;
                    _pointerAbsoluteY = (double)jsEventArgDynamic.pageY;
                }
                else if (jsEventArgDynamic.touches.length != 0) //Chrome for Android uses different ways to access the pointer's position.
                {
                    _pointerAbsoluteX = (double)jsEventArgDynamic.touches[0].pageX;
                    _pointerAbsoluteY = (double)jsEventArgDynamic.touches[0].pageY;
                }
                else //this is for the PointerRelease event on Chrome for Android
                {
                    _pointerAbsoluteX = (double)jsEventArgDynamic.changedTouches[0].pageX;
                    _pointerAbsoluteY = (double)jsEventArgDynamic.changedTouches[0].pageY;
                }
            }

            //---------------------------------------
            // Adjust the absolute coordinates to take into account the fact that the XAML Window is not necessary un the top-left corner of the HTML page:
            //---------------------------------------
            if (window != null)
            {
                // Get the XAML Window root position relative to the page:
                object windowRootDomElement       = window.INTERNAL_OuterDomElement;
                object windowBoundingClientRect   = Interop.ExecuteJavaScript("$0.getBoundingClientRect()", windowRootDomElement);
                object pageBodyBoundingClientRect = Interop.ExecuteJavaScript("document.body.getBoundingClientRect()"); // This is to take into account the scrolling.
                double windowRootLeft             = Convert.ToDouble(Interop.ExecuteJavaScript("$0.left - $1.left", windowBoundingClientRect, pageBodyBoundingClientRect));
                double windowRootTop = Convert.ToDouble(Interop.ExecuteJavaScript("$0.top - $1.top", windowBoundingClientRect, pageBodyBoundingClientRect));

                // Substract the XAML Window position, to get the pointer position relative to the XAML Window root:
                _pointerAbsoluteX = _pointerAbsoluteX - windowRootLeft;
                _pointerAbsoluteY = _pointerAbsoluteY - windowRootTop;
            }
        }
Ejemplo n.º 6
0
        internal void OnIsReadOnlyChanged(bool isReadOnly)
        {
            if (INTERNAL_VisualTreeManager.IsElementInVisualTree(this) &&
                INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(_contentEditableDiv))
            {
                OpenSilver.Interop.ExecuteJavaScriptAsync(
                    "$0.setAttribute(\"contentEditable\", $1);",
                    _contentEditableDiv, (!isReadOnly).ToString().ToLower()
                    );

                if (!IsRunningInJavaScript())
                {
                    //--- SIMULATOR ONLY: ---
                    INTERNAL_HtmlDomManager.ExecuteJavaScript($@"
var element = document.getElementByIdSafe(""{((INTERNAL_HtmlDomElementReference)_contentEditableDiv).UniqueIdentifier}"");
element.setAttribute(""data-isreadonly"",""{isReadOnly.ToString().ToLower()}"");");
                }
            }
        }
Ejemplo n.º 7
0
        protected internal void SetPointerAbsolutePosition(object jsEventArg, Window window)
        {
            if (CSHTML5.Interop.IsRunningInTheSimulator)
            {
                // Hack to improve the Simulator performance by making only one interop call rather than two:
                string concatenated             = Convert.ToString(CSHTML5.Interop.ExecuteJavaScript("$0.pageX + '|' + $0.pageY", jsEventArg));
                int    sepIndex                 = concatenated.IndexOf('|');
                string pointerAbsoluteXAsString = concatenated.Substring(0, sepIndex);
                string pointerAbsoluteYAsString = concatenated.Substring(sepIndex + 1);
                _pointerAbsoluteX = double.Parse(pointerAbsoluteXAsString, CultureInfo.InvariantCulture); //todo: verify that the locale is OK. I think that JS by default always produces numbers in invariant culture (with "." separator).
                _pointerAbsoluteY = double.Parse(pointerAbsoluteYAsString, CultureInfo.InvariantCulture); //todo: read note above
            }
            else
            {
                dynamic jsEventArgDynamic = (dynamic)jsEventArg;
                //todo - removeJSIL: once we stop supporting the JSIL version, remove the bools like the following and put the thing directly in the if (3x in this method for now).
                bool isArgsPageXDefined = INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(jsEventArgDynamic.pageX); // Using a temporary variable to conatin the tests's result (this line and the following) because in JSIL, trying to do both tests in the if results in an UntranslatableMethod for some reason.
                bool isArgsPageXNotNull = isArgsPageXDefined;
                if (isArgsPageXDefined)                                                                          //Note: apparently, JSIL is really bad at translating things like "bool isArgsPageXNotNull = isArgsPageXDefined && (jsEventArgDynamic.pageX != 0) and ends up commiting seppuku by trying to cast 0 to a boolean.
                {
                    isArgsPageXNotNull = jsEventArgDynamic.pageX != 0;
                }
                if (isArgsPageXNotNull)
                {
                    _pointerAbsoluteX = (double)jsEventArgDynamic.pageX;
                    _pointerAbsoluteY = (double)jsEventArgDynamic.pageY;
                }
                else
                {
                    bool isArgsTouchesDefined  = INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(jsEventArgDynamic.touches); // Using a temporary variable to conatin the tests's result (this line and the following) because in JSIL, trying to do both tests in the if results in an UntranslatableMethod for some reason.
                    bool isArgsTouchesNotEmpty = isArgsTouchesDefined;
                    if (isArgsTouchesDefined)
                    {
                        isArgsTouchesNotEmpty = jsEventArgDynamic.touches.length != 0;
                    }
                    if (isArgsTouchesNotEmpty) //Chrome for Android uses different ways to access the pointer's position.
                    {
                        _pointerAbsoluteX = (double)jsEventArgDynamic.touches[0].pageX;
                        _pointerAbsoluteY = (double)jsEventArgDynamic.touches[0].pageY;
                    }
                    else
                    {
                        bool isArgsChangedTouchesDefined  = INTERNAL_HtmlDomManager.IsNotUndefinedOrNull(jsEventArgDynamic.changedTouches); // Using a temporary variable to conatin the tests's result (this line and the following) because in JSIL, trying to do both tests in the if results in an UntranslatableMethod for some reason.
                        bool isArgsChangedTouchesNotEmpty = isArgsChangedTouchesDefined;
                        if (isArgsChangedTouchesDefined)
                        {
                            isArgsChangedTouchesNotEmpty = jsEventArgDynamic.changedTouches.length != 0;
                        }
                        if (isArgsChangedTouchesNotEmpty) //this is for the PointerRelease event on Chrome for Android
                        {
                            _pointerAbsoluteX = (double)jsEventArgDynamic.changedTouches[0].pageX;
                            _pointerAbsoluteY = (double)jsEventArgDynamic.changedTouches[0].pageY;
                        }
                        else
                        {
                            _pointerAbsoluteX = 0d;
                            _pointerAbsoluteY = 0d;
                        }
                    }
                }
            }

            //---------------------------------------
            // Adjust the absolute coordinates to take into account the fact that the XAML Window is not necessary un the top-left corner of the HTML page:
            //---------------------------------------
            if (window != null)
            {
                // Get the XAML Window root position relative to the page:
                object windowRootDomElement       = window.INTERNAL_OuterDomElement;
                object windowBoundingClientRect   = CSHTML5.Interop.ExecuteJavaScript("$0.getBoundingClientRect()", windowRootDomElement);
                object pageBodyBoundingClientRect = CSHTML5.Interop.ExecuteJavaScript("document.body.getBoundingClientRect()"); // This is to take into account the scrolling.

                double windowRootLeft;
                double windowRootTop;

                // Hack to improve the Simulator performance by making only one interop call rather than two:
                string concatenated = CSHTML5.Interop.ExecuteJavaScript("($0.left - $1.left) + '|' + ($0.top - $1.top)", windowBoundingClientRect, pageBodyBoundingClientRect).ToString();
                int    sepIndex     = concatenated.IndexOf('|');
                if (sepIndex > -1)
                {
                    string windowRootLeftAsString = concatenated.Substring(0, sepIndex);
                    string windowRootTopAsString  = concatenated.Substring(sepIndex + 1);
#if BRIDGE
                    windowRootLeft = double.Parse(windowRootLeftAsString, global::System.Globalization.CultureInfo.InvariantCulture); //todo: verify that the locale is OK. I think that JS by default always produces numbers in invariant culture (with "." separator).
                    windowRootTop  = double.Parse(windowRootTopAsString, global::System.Globalization.CultureInfo.InvariantCulture);  //todo: read note above
#else
                    //JSIL doesn't have a double.Parse with localization:
                    windowRootLeft = double.Parse(windowRootLeftAsString); //todo: verify that the locale is OK. I think that JS by default always produces numbers in invariant culture (with "." separator).
                    windowRootTop  = double.Parse(windowRootTopAsString);  //todo: read note above
#endif
                }
                else
                {
                    windowRootLeft = Double.NaN;
                    windowRootTop  = Double.NaN;
                }

                // Substract the XAML Window position, to get the pointer position relative to the XAML Window root:
                _pointerAbsoluteX = _pointerAbsoluteX - windowRootLeft;
                _pointerAbsoluteY = _pointerAbsoluteY - windowRootTop;
            }
        }