protected override void AppendChildrenToElement(HtmlElement elm) { foreach (Component child in Children) { // This is very important for performance // We should always try to append an empty child DOM Element // first and then call EnsureRefreshed() where the child fills it child.EnsureDOMElement(); // Make sure the buttons are all floating the right way via CSS. switch (Alignment) { case DataNodeWrapper.LEFTALIGN: Utility.EnsureCSSClassOnElement(child.ElementInternal, "ms-cui-toolbar-button-left"); break; case DataNodeWrapper.CENTERALIGN: Utility.EnsureCSSClassOnElement(child.ElementInternal, "ms-cui-toolbar-button-center"); break; case DataNodeWrapper.RIGHTALIGN: Utility.EnsureCSSClassOnElement(child.ElementInternal, "ms-cui-toolbar-button-right"); break; default: throw new ArgumentOutOfRangeException(Alignment); } elm.AppendChild(child.ElementInternal); child.EnsureRefreshed(); } }
/// <summary> /// Obsolete API will be removed soon /// </summary> /// <param name="evt">The DomEvent that triggered the launch(usually a mouse click)</param> internal bool LaunchContextMenu(HtmlElement targetElement, HtmlEvent evt) { _targetElement = targetElement; _launchPosition = GetMenuPosition(evt); LaunchMenu(null); Menu.FocusOnFirstItem(evt); return true; }
/// <summary> /// Constructor for a Jewel /// </summary> /// <param name="dataUrlBase">The XML data URL</param> /// <param name="version">The version of the XML data</param> /// <param name="lcid">The language code</param> /// <param name="options">The JewelBuildOptions for this Jewel. <see cref="JewelBuildOptions"/></param> /// <param name="elmPlaceholder">The ID for the DOMElement that will enclose this Jewel</param> /// <param name="rootBuildClient">The object using this builder</param> public JewelBuilder(JewelBuildOptions options, HtmlElement elmPlaceholder, IRootBuildClient rootBuildClient) : base(options, elmPlaceholder, rootBuildClient) { if (CUIUtility.IsNullOrUndefined(elmPlaceholder)) throw new ArgumentNullException("Jewel placeholder DOM element is null or undefined."); }
/// <summary> /// Launch this MenuLauncher's Menu at the given position /// </summary> public bool LaunchContextMenuAt(HtmlElement targetElement, int x, int y) { this._x = x; this._y = y; _targetElement = targetElement; LaunchMenu(null); Menu.FocusOnFirstItem(null); return true; }
/// <summary> /// Override to make sure the context menu gets launched in the correct location. /// </summary> protected override void PositionMenu(HtmlElement menu, HtmlElement launcher) { // This should be cleaned up when LaunchContextMenu is removed if (_launchPosition != null) { Menu.ElementInternal.Style.Top = _launchPosition.Y + "px"; Menu.ElementInternal.Style.Left = _launchPosition.X + "px"; Menu.ElementInternal.Style.Position = "absolute"; } else { menu.Style.Top = "0px"; menu.Style.Left = "0px"; Dictionary<string, int> dimensions = GetAllElementDimensions(menu, _targetElement); // set dimensions of the launcher dimensions["launcherLeft"] = _x; dimensions["launcherTop"] = _y; dimensions["launcherWidth"] = 0; dimensions["launcherHeight"] = 0; Root.SetFlyOutCoordinates(menu, dimensions, false); } }
private void RemoveEvents(HtmlElement elmCheckbox, HtmlElement elmLabel) { elmCheckbox.Click -= OnClick; elmCheckbox.Focus -= OnFocus; elmCheckbox.Blur -= OnBlur; elmCheckbox.MouseOver -= OnMouseover; elmCheckbox.MouseOut -= OnMouseout; elmCheckbox.KeyDown -= OnKeyDown; if (!CUIUtility.IsNullOrUndefined(elmLabel)) { elmLabel.Click -= OnLabelClick; elmLabel.KeyDown -= OnKeyDown; elmLabel.MouseOver -= OnMouseover; elmLabel.MouseOut -= OnMouseout; } }
protected override void AppendChildrenToElement(HtmlElement elm) { ListItem listItem; foreach (Component child in Children) { // Put all menu items into a list item for semantics listItem = new ListItem(); listItem.ClassName = "ms-cui-menusection-items"; // This is very important for performance // We should always try to append an empty child DOM Element // first and then call EnsureRefreshed() where the child fills it child.EnsureDOMElement(); listItem.AppendChild(child.ElementInternal); elm.AppendChild(listItem); child.EnsureRefreshed(); } }
private void RemoveEvents(HtmlElement elm, bool isMenu) { elm.Click -= OnClick; elm.Blur -= OnBlur; elm.KeyPress -= OnKeyPress; elm.Focus -= OnTabFocus; if (BrowserUtility.InternetExplorer) { if (isMenu) { elm.MouseEnter -= OnMouseenter; elm.MouseLeave -= OnMouseleave; } else { elm.MouseEnter -= OnFocus; elm.MouseLeave -= OnBlur; } } else { if (isMenu) { elm.MouseOut -= OnMouseout; elm.MouseOver -= OnMouseover; } else { elm.MouseOut -= OnBlur; elm.MouseOver -= OnFocus; } } }
internal bool BeginModal(IModalController controller, HtmlElement _elmTrigger) { if (CUIUtility.IsNullOrUndefined(_modalControllerStack)) _modalControllerStack = new List<IModalController>(); _modalControllerStack.Add(controller); _currentModalController = controller; if (_modal) return false; // This div covers the whole window and will essentially block any elements // behind it from receiving click/mouseover/mouseout events etc. Div modalDiv = ModalDiv; modalDiv.Style.Visibility = "hidden"; Browser.Document.Body.AppendChild(modalDiv); modalDiv.Style.Visibility = "visible"; _modal = true; return true; }
/// <summary> /// Set fyout coordinates given information about the viewing area in the screen, the launching control and the flyout dimensions. /// </summary> /// <param name="flyOut">The flyout to be launched.</param> /// <param name="dimensions">Position information on the screen viewing area, lauching control and flyout.</param> internal void SetFlyOutCoordinates(HtmlElement flyOut, Dictionary<string, int> dimensions, bool horizontal) { // reusable boolean to check whether the dom element must be edited or not bool changed = false; if (CUIUtility.IsNullOrUndefined(flyOut) || CUIUtility.IsNullOrUndefined(dimensions)) { return; } // Create default coordinates int flyOutLeft; int flyOutTop; // Cache dimensions for performance int launcherLeft = dimensions["launcherLeft"]; int launcherTop = dimensions["launcherTop"]; int launcherWidth = dimensions["launcherWidth"]; int launcherHeight = dimensions["launcherHeight"]; int flyOutWidth = dimensions["flyOutWidth"]; int flyOutHeight = dimensions["flyOutHeight"]; int flyOutRealHeight = dimensions["flyOutRealHeight"]; int viewportWidth = dimensions["viewportWidth"]; int viewportHeight = dimensions["viewportHeight"]; int viewableLeft = dimensions["viewableLeft"]; int viewableTop = dimensions["viewableTop"]; bool isLTR = Root.TextDirection == Direction.LTR; bool buttedToRightEdge = false, buttedToLeftEdge = false; string objScrollable = flyOut.GetAttribute("mscui:scrollable"); bool wasScrollable = Utility.IsTrue(objScrollable); if (horizontal) { if (isLTR) { // Left-to-right method flyOutLeft = launcherLeft + launcherWidth; flyOutLeft += 2; // styling: make the borders of the menus align } else // Right-to-left method { flyOutLeft = launcherLeft - flyOutWidth; } flyOutTop = launcherTop; } else { if (isLTR) { // Left-to-right method flyOutLeft = launcherLeft; } else // Right-to-left method { flyOutLeft = launcherLeft + launcherWidth - flyOutWidth; } flyOutTop = launcherTop + launcherHeight; int minWidth = launcherWidth >= 2 ? launcherWidth - 2 : launcherWidth /* borders */; // O14:389872 - flyout should be at least as wide as the launcher if (minWidth > flyOutWidth) flyOutWidth = minWidth; flyOut.Style.MinWidth = minWidth + "px"; } // If the root is fixed positioned, then we need to take scroll offset into account (O14:28297) if (FixedPositioningEnabled) { flyOutTop += viewableTop; flyOutLeft += viewableLeft; } flyOut.Style.Top = flyOutTop + "px"; flyOut.Style.Left = flyOutLeft + "px"; // Horizonal Positioning // If the flyOut can fit in the viewport at all, then try positioning logic if (flyOutWidth <= viewportWidth) { // If the flyOut is too close to the right side of the viewport if (flyOutLeft + flyOutWidth > viewableLeft + viewportWidth) { // If we're positioning horizontally and the flyout can fit // launching the other way, try that if (horizontal && isLTR && (launcherLeft - flyOutWidth) > viewableLeft) { flyOutLeft = launcherLeft - flyOutWidth; } // Otherwise, just align along the edge of the viewport else { flyOutLeft = viewableLeft + viewportWidth - flyOutWidth - 5; buttedToRightEdge = true; } changed = true; } // If the flyOut is too close to the left side of the viewport else if (flyOutLeft < viewableLeft) { // If we're positioning horizontally and the flyout can fit // launching the other way, try that if (horizontal && !isLTR && (launcherLeft + launcherWidth + flyOutWidth) < (viewableLeft + viewportWidth)) { flyOutLeft = launcherLeft + launcherWidth; } // Otherwise, just align along the edge of the viewport else { flyOutLeft = viewableLeft + 5; buttedToLeftEdge = true; } changed = true; } else { changed = false; } } // If the flyOut can't fit into the viewport, just align against the appropriate edge else { if (isLTR) { flyOutLeft = viewableLeft; changed = true; } else // RTL { flyOutLeft = viewableLeft + viewportWidth - flyOutWidth; changed = true; } } // If changed, set the styles accordingly if (changed) { flyOut.Style.Left = flyOutLeft + "px"; changed = false; } // Vertical Positioning (not affected by Text Direction) // If the flyOut is too close to the bottom of the viewport, launch the flyOut upwards // We work with the real height of the flyout's content here so that even if it is // currently scrollable, we can see if it still needs to be scrollable if (flyOutTop + flyOutRealHeight > viewableTop + viewportHeight) { // store initial value and viewableHeight int oldflyOutTop = flyOutTop; int oldflyOutViewableHeight = viewableTop + viewportHeight - flyOutTop; flyOutTop = launcherTop - flyOutRealHeight; if (FixedPositioningEnabled) flyOutTop += viewableTop; int newflyOutViewableHeight = launcherTop; if (!FixedPositioningEnabled) newflyOutViewableHeight -= viewableTop; changed = true; // If launching upwards is worse than before, go back to launching downwards if (newflyOutViewableHeight < flyOutRealHeight) { int flyOutWidthWithScrollbar = flyOutWidth + 22; if (newflyOutViewableHeight < oldflyOutViewableHeight) { flyOutTop = oldflyOutTop; // O14:45827 - Enable scrolling and change the height of the menu to fit in the space available flyOut.Style.MaxHeight = (oldflyOutViewableHeight - 5) + "px"; if (!wasScrollable) { flyOut.Style.OverflowY = "scroll"; flyOut.Style.Width = flyOutWidthWithScrollbar + "px"; } if (buttedToRightEdge && isLTR) { flyOutLeft -= 27; // compensate for the added scrollbar flyOut.Style.Left = flyOutLeft + "px"; } else if (buttedToLeftEdge && !isLTR) { flyOutLeft += 27; // compensate for the added scrollbar flyOut.Style.Left = flyOutLeft + "px"; } changed = false; } else { // Can't fit in either direction, but launching upwards is better // Still need to resize the menu and enable scrolling flyOut.Style.MaxHeight = (newflyOutViewableHeight - 5) + "px"; if (!wasScrollable) { flyOut.Style.OverflowY = "scroll"; flyOut.Style.Width = flyOutWidthWithScrollbar + "px"; } if (buttedToRightEdge && isLTR) { flyOutLeft -= 27; // compensate for the added scrollbar flyOut.Style.Left = flyOutLeft + "px"; } else if (buttedToLeftEdge && !isLTR) { flyOutLeft += 27; // compensate for the added scrollbar flyOut.Style.Left = flyOutLeft + "px"; } } if (!wasScrollable) flyOut.SetAttribute("mscui:scrollable", "true"); } else // fits fine when launching upwards { // Revert auto-scroll styles to default if not needed if (wasScrollable) { flyOut.Style.MaxHeight = "none"; flyOut.Style.OverflowY = "visible"; flyOut.Style.Width = "auto"; flyOut.SetAttribute("mscui:scrollable", "false"); } } } else // fits fine vertically { // Revert auto-scroll styles to default if not needed if (wasScrollable) { flyOut.Style.MaxHeight = "none"; flyOut.Style.OverflowY = "visible"; flyOut.Style.Width = "auto"; flyOut.SetAttribute("mscui:scrollable", "false"); } changed = false; } // If changed, set the styles accordingly if (changed) { flyOut.Style.Top = flyOutTop + "px"; changed = false; } }
/// <summary> /// Position the flyout control horizontally, relative to the launching control and the viewing area on the screen. /// </summary> /// <param name="flyOut">The flyout to be launched.</param> /// <param name="launcher">The element launching the tooltip.</param> internal virtual void PositionFlyOutHorizontal(HtmlElement flyOut, HtmlElement launcher) { UpdateFlyOutPosition(flyOut, launcher, true); }
/// <summary> /// Helper function to append the DOMElements of child Components to the passed in DOMElementInternal. Used in conjunction with RefreshInternal(). /// </summary> /// <seealso cref="RefreshInternal"/> /// <param name="elm">The DOMElement that the child Component's(the children of this Component) DOMElements should be appended to.</param> protected virtual void AppendChildrenToElement(HtmlElement elm) { // The document fragment trick is known to have twice as much // throughput as appending directly to the DOM tree List<HtmlElement> elts = new List<HtmlElement>(); foreach (Component child in _children) { // This is very important for performance // We should always try to append an empty child DOM Element // first and then call EnsureRefreshed() where the child fills it child.EnsureDOMElement(); child.EnsureRefreshed(); elts.Add(child.ElementInternal); } // Now append those elements to the parent foreach (HtmlElement elt in elts) elm.AppendChild(elt); }
/// <summary> /// This can be overriden in components where the outer DOM element /// of the component is not a div tag and/or the outer structure of /// the component is more complex than just one div tag. For example, /// <table/><tbody/><tr/> etc. /// </summary> internal virtual void EnsureDOMElement() { // Make sure that the DOM element for this Component is created if (_elmDOM == null) { _elmDOM = GetElementFromTagName(DOMElementTagName); _elmDOM.ClassName = CssClass; // REVIEW(josefl): do we need these ids only for debug? _elmDOM.Id = Id; } }
/// <summary> /// Called to clean up anything that this component needs to /// Usually releasing event handlers and cleaning up any circular references. /// </summary> public virtual void Dispose() { if (!CUIUtility.IsNullOrUndefined(_children)) { foreach (Component c in _children) c.Dispose(); _children = null; } _parent = null; _root = null; _delayedInitData = null; _delayedInitHandler = null; _delayedInitOptions = null; _elmDOM = null; }
internal static void SetImeMode(HtmlElement e, string mode) { if (!string.IsNullOrEmpty(mode)) e.Style.ImeMode = IsTrue(mode) ? "auto" : "disabled"; }
// REVIEW(josefl): This was copied out of rteutility.cs It would be good if we can // unify these into one low level utility sometime in the future. // This function finds the first applicable parent element of the element type. internal static HtmlElement GetNearestContainingParentElementOfTypes(HtmlElement elem, string[] aTagNames) { int aTagNames_length = aTagNames.Length; if (CUIUtility.IsNullOrUndefined(elem)) { return null; } // check the current element first. for (int i = 0; i < aTagNames_length; i++) { if (string.Compare(elem.TagName.ToLower(), aTagNames[i].ToLower()) == 0) { return elem; } } // walk the parent chain to find the element type of interest. HtmlElement elemParent = (HtmlElement)elem.ParentNode; while (elemParent != null) { for (int i = 0; i < aTagNames_length; i++) { if (string.Compare(elemParent.TagName.ToLower(), aTagNames[i].ToLower()) == 0) { return elemParent; } } elemParent = (HtmlElement)elemParent.ParentNode; } return null; }
/// <summary> /// Position the flyout control vertically, relative to the launching control and the viewing area on the screen. /// </summary> /// <param name="flyOut">The flyout to be launched.</param> /// <param name="launcher">The element launching the tooltip.</param> internal virtual void PositionFlyOut(HtmlElement flyOut, HtmlElement launcher) { UpdateFlyOutPosition(flyOut, launcher, false); }
private string CompareNodes(HtmlElement elm1, HtmlElement elm2) { // Compare the number of attributes // It is more usefull to get an error message with the name of the mismatched attributes // if (elm1.Attributes.Length != elm2.Attributes.Length) // return ConstructCompareErrorMessage(elm1, elm2, "Nodes have different numbers of attributes."); // First compare the Attributes string message = CompareNodeAttributes(elm1, elm2); if (!string.IsNullOrEmpty(message)) return message; message = CompareNodeAttributes(elm2, elm1); if (!string.IsNullOrEmpty(message)) return message; // Now compare number of children if (elm1.ChildNodes.Length != elm2.ChildNodes.Length) return (ConstructCompareErrorMessage(elm1, elm2, "Nodes have different number of children: " + elm1.ChildNodes.Length + " and " + elm2.ChildNodes.Length)); // Now recurse over the children for (int i = 0; i < elm1.ChildNodes.Length; i++) { message = CompareNodes((HtmlElement)elm1.ChildNodes[i], (HtmlElement)elm2.ChildNodes[i]); if (!string.IsNullOrEmpty(message)) return message; } return ""; }
private void UpdateFlyOutPosition(HtmlElement flyOut, HtmlElement launcher, bool horizontal) { if (CUIUtility.IsNullOrUndefined(flyOut) || CUIUtility.IsNullOrUndefined(launcher)) { return; } // Set temporary position on flyOut and get dimensions flyOut.Style.Top = "0px"; flyOut.Style.Left = "0px"; Dictionary<string, int> dimensions = GetAllElementDimensions(flyOut, launcher); SetFlyOutCoordinates(flyOut, dimensions, horizontal); }
private string CompareNodeAttributes(HtmlElement elm1, HtmlElement elm2) { if (CUIUtility.IsNullOrUndefined(elm1.Attributes)) { if (elm1.InnerText != elm2.InnerText) return ConstructCompareErrorMessage(elm1, elm2, "Text node text mismatched."); else return ""; } for (int i = 0; i < elm1.Attributes.Length; i++) { DomAttribute attr1 = elm1.Attributes[i]; DomAttribute attr2 = elm2.Attributes.GetNamedItem(attr1.Name); // For the unselectable attribute, the client rendered ribbon adds this as an asynchronous // task so it does not appear in this attribute collection. if (CUIUtility.IsNullOrUndefined(attr2) && attr1.Name != "unselectable") { // The exceptions to this: // The "_events" attribute is used by Microsoft Ajax to attach events to the DOM node so it will // not be present in the server rendered DOM. if (attr1.Name != "_events") return ConstructCompareErrorMessage(elm1, elm2, "Attribute: \"" + attr1.Name + "\" is only present in one node."); else continue; } else if (attr1.Name == "unselectable") { string field = elm2.GetAttribute("unselectable"); if (string.IsNullOrEmpty(field) || field != attr1.Value) return ConstructCompareErrorMessage(elm1, elm2, "Attribute values for \"unselectable\" does not match."); } if (attr1.Name.ToLower() != attr2.Name.ToLower()) return ConstructCompareErrorMessage(elm1, elm2, "Attributes at index " + i.ToString() + " have different names: \"" + attr1.Name + "\" and \"" + attr2.Name + "\""); if (attr1.Value.Trim() != attr2.Value.Trim()) { // Handle exceptions here // We ignore the oncontextmenu attribute because this one is attached in the client // via a MicrosoftAjax event handler. if (attr1.Name == "oncontextmenu" && !string.IsNullOrEmpty(elm1.ClassName) && elm1.ClassName.IndexOf("ms-cui-ribbon") != -1) { } else if (attr1.Name == "class" && attr1.Value.Replace("ms-cui-disabled", "").Trim() == attr2.Value.Replace("ms-cui-disabled", "").Trim()) { } // Some elements need unique ids to function correctly. If the only difference is "-client" // then we can ignore the issue. else if (attr1.Name == "id" && attr1.Value.Replace("-client", "").Trim() == attr2.Value.Replace("-client", "").Trim()) { } // We ignore the case where images are not the same size because the image sizes // are not set until the <img> tag is actually rendered so one of these will be "0" // because it has not been put into the DOM. else if (elm1.TagName.ToLower() == "img" && (attr1.Name == "height" || attr1.Name == "width")) { } else if (elm1.TagName.ToLower() == "label" && attr1.Name == "for") { } else if (elm1.TagName.ToLower() == "input" && attr1.Name.ToLower() == "maxlength") { } else { return ConstructCompareErrorMessage(elm1, elm2, "Attribute: \"" + attr1.Name + "\" has different values: \"" + attr1.Value + "\" and \"" + attr2.Value + "\""); } } } return ""; }
/// <summary> /// Get all pertinent element dimensions for positioning the tooltip /// </summary> /// <param name="flyOut">The flyOut to be launched. If null, then only get launcher dimensions</param> /// <param name="launcher">The element that is launching the flyOut</param> /// <returns>A dictionary with all the necessary dimensional data to position the flyOut</returns> internal Dictionary<string, int> GetAllElementDimensions(HtmlElement flyOut, HtmlElement launcher) { Dictionary<string, int> d = new Dictionary<string, int>(); if (CUIUtility.IsNullOrUndefined(flyOut) || CUIUtility.IsNullOrUndefined(launcher)) { return d; } // Get dimensions of the launcher d["launcherWidth"] = launcher.OffsetWidth; d["launcherHeight"] = launcher.OffsetHeight; // Get position coordinates for the launcher int top = launcher.OffsetTop, left = launcher.OffsetLeft; if (!CUIUtility.IsNullOrUndefined(launcher.OffsetParent)) { HtmlElement elem = launcher.OffsetParent; for (/*top, left*/; !CUIUtility.IsNullOrUndefined(elem); elem = elem.OffsetParent) { top += elem.OffsetTop; left += elem.OffsetLeft; } } else { top = launcher.OffsetTop; left = launcher.OffsetLeft; } // account for scrolling if (!CUIUtility.IsNullOrUndefined(launcher.ParentNode)) { int scrollTop = 0; int scrollLeft = 0; HtmlElement elem2 = (HtmlElement)launcher.ParentNode; for (/*scrollTop, scrollLeft*/; !CUIUtility.IsNullOrUndefined(elem2) && elem2.TagName.ToLower() != "html"; elem2 = (HtmlElement)elem2.ParentNode) { if (elem2.ScrollTop > 0) { scrollTop += elem2.ScrollTop; } if (elem2.ScrollLeft > 0) { if ((elem2 == Browser.Window.Document.DocumentElement) && BrowserUtility.InternetExplorer7 && Root.TextDirection == Direction.RTL) { // O14: 645034 - IE 7 mis-reports the Document.DocumentElement.ScrollLeft value in RTL layouts scrollLeft += Browser.Document.Body.ScrollLeft; } else { scrollLeft += elem2.ScrollLeft; } } } if (top >= scrollTop) { top -= scrollTop; } if (left >= scrollLeft) { left -= scrollLeft; } } d["launcherTop"] = top; d["launcherLeft"] = left; if (flyOut != null) { // Get dimensions of the flyOut d["flyOutWidth"] = flyOut.OffsetWidth; d["flyOutHeight"] = flyOut.OffsetHeight; d["flyOutRealHeight"] = flyOut.ScrollHeight; // Get dimensions of viewport // IE7, Mozilla, Firefox, Opera, Safari d["viewportWidth"] = Utility.GetViewPortWidth(); d["viewportHeight"] = Utility.GetViewPortHeight(); // Get viewable coordinates of the viewport - Firefox 3 d["viewableTop"] = Browser.Document.DocumentElement.ScrollTop; d["viewableLeft"] = Browser.Document.DocumentElement.ScrollLeft; // IE7, Mozilla, Opera, Safari if (CUIUtility.IsNullOrUndefined(d["viewableTop"])) { JSObject windowObject = (JSObject)(object)Browser.Window; d["viewableTop"] = windowObject.GetField<int>("pageYOffset"); d["viewableLeft"] = windowObject.GetField<int>("pageXOffset"); } if (BrowserUtility.InternetExplorer7 && (Root.TextDirection == Direction.RTL)) { // O14: 645034 - IE 7 mis-reports the Document.DocumentElement.ScrollLeft value in RTL layouts d["viewableLeft"] = Browser.Document.Body.ScrollLeft; } } return d; }
private string ConstructCompareErrorMessage(HtmlElement elm1, HtmlElement elm2, string error) { string message = "COMPARE ERROR: " + error + "\n\n"; message += "Closest Ancestor Id: \"" + GetClosestAncestorIdAndLevel(elm1) + "\"\n\n"; message += "Element1 ClassName: " + elm1.ClassName + "\n"; message += "Element1 InnerHTML: " + elm1.InnerHtml; message += "\n\n\n\n"; message += "Element2 ClassName: " + elm2.ClassName + "\n"; message += "Element2 InnerHTML: " + elm2.InnerHtml; // Give option to enter debugger at point of failure if (Browser.Window.Confirm(message + "\n\nDo you want to debug?")) Debugger.Break(); return message; }
private void RemoveEvents(HtmlElement elmButton, HtmlElement elmItem) { elmItem.MouseOver += OnSelectedItemMouseover; elmItem.MouseOut += OnSelectedItemMouseout; elmButton.Click += OnArrowButtonClick; elmButton.MouseOver += OnArrowButtonFocus; elmButton.MouseOut += OnArrowButtonBlur; elmButton.Focus += OnArrowButtonKeyboardFocus; elmButton.Blur += OnArrowButtonBlur; elmButton.KeyPress += OnArrowButtonKeyPress; }
private string GetClosestAncestorIdAndLevel(HtmlElement elm) { string message = "Found no id in ancestor chain"; int level = 0; while (!CUIUtility.IsNullOrUndefined(elm)) { if (!string.IsNullOrEmpty(elm.Id)) { message = elm.Id + " at level " + level; break; } elm = (HtmlElement)elm.ParentNode; level++; } return message; }
/// <summary> /// Specialized menu positioning method. If this MenuLauncher is in a Menu display mode, use flyout-style sideways menu positioning /// </summary> /// <param name="menu">The DOMElement of the menu to be launched</param> /// <param name="launcher">The DOMElement of the launcher</param> /// <owner alias="JKern" /> protected override void PositionMenu(HtmlElement menu, HtmlElement launcher) { // If not in a menu, use the standard menu positioning logic if (DisplayedComponent.DisplayMode.StartsWith("Menu")) { // If we're in a menu, we want the position the flyout horizontally Root.PositionFlyOutHorizontal(menu, launcher); } else { // If not in a menu, use the standard menu positioning logic base.PositionMenu(menu, launcher); } }
protected internal void StoreElementForDisplayMode(HtmlElement elm, string displayMode) { _cachedDOMElements[displayMode] = elm; }
private void AttachEvents(HtmlElement elmCheckbox, HtmlElement elmLabel) { elmCheckbox.Click += OnClick; elmCheckbox.Focus += OnFocus; elmCheckbox.Blur += OnBlur; elmCheckbox.MouseOver += OnMouseover; elmCheckbox.MouseOut += OnMouseout; elmCheckbox.KeyDown += OnKeyDown; if (!CUIUtility.IsNullOrUndefined(elmLabel)) { elmLabel.Click += OnLabelClick; elmLabel.KeyDown += OnKeyDown; elmLabel.MouseOver += OnMouseover; elmLabel.MouseOut += OnMouseout; } }
/// <summary> /// We need this function because though we have the events on the <td> node, /// they can return a sub node (one of the divs for example) as the event.Target /// This function will find the outer element no mater what element in in /// event.Target. /// </summary> /// <param name="elm"></param> /// <param name="goUp"></param> /// <param name="goDown"></param> /// <returns></returns> private Div GetOuterDiv(HtmlElement elm) { // Walk down until we get to the "A" tag. while (elm.HasChildNodes()) elm = (HtmlElement)elm.ChildNodes[0]; // Now "elm" has the "A" tag in it. We can then get the outer div // from it. return (Div)elm.ParentNode.ParentNode; }
// Travel up DOM tree to find the group id private string FindGroupId(HtmlElement elm) { if (elm.NodeName == "LI") return elm.Id; else return FindGroupId((HtmlElement)elm.ParentNode); }
internal void AddTabTitleDOMElement(HtmlElement tabTitle) { _elmTabTitleContainer.AppendChild(tabTitle); _tabCount++; if (_tabCount == 1) { Utility.EnsureCSSClassOnElement(_elmTabTitleContainer, "ms-cui-oneCtxTab"); } else if (_tabCount == 2) { Utility.RemoveCSSClassFromElement(_elmTabTitleContainer, "ms-cui-oneCtxTab"); } }