public static bool ParseDomEventTargetAsGeckoElement(DomEventTarget domEventTarget, out GeckoElement geckoElement) { geckoElement = null; if (domEventTarget == null) { return(false); } geckoElement = domEventTarget.CastToGeckoElement(); return(geckoElement != null); }
private bool DetermineSplitLocation(DomEventTarget target) { var selection = m_blocksDisplayBrowser.Window.Selection; var newOffset = selection.AnchorOffset; if (!m_blocksDisplayBrowser.Visible || target == null) { return(false); } var geckoElement = target.CastToGeckoElement(); var targetElement = geckoElement as GeckoDivElement; if (targetElement == null) { var geckoHtmlElement = geckoElement as GeckoHtmlElement; if (geckoHtmlElement != null) { targetElement = geckoHtmlElement.Parent as GeckoDivElement; if (targetElement == null) { return(false); } if (geckoElement.TagName == "SUP") { if (newOffset != 0) { return(false); } if (!targetElement.InnerHtml.StartsWith(geckoHtmlElement.OuterHtml)) { return(DetermineSplitLocationAtStartOfVerse(targetElement, geckoHtmlElement.InnerHtml)); } } else { newOffset = 0; } } else { return(false); } } int blockIndex; if (targetElement.ClassName == "block") { blockIndex = int.Parse(targetElement.Id); if (newOffset > 0) { // For simplicity, make it so a split at the end of a block is really a split at the start of the following block. if (++blockIndex == m_originalBlocks.Count) { return(false); // Can't split at very end of last verse in last block } newOffset = 0; } else if (blockIndex == 0) { return(false); // Can't split at start of first block. } VerseToSplit = null; // We're actually splitting between blocks of a multi-block quote } else if (targetElement.ClassName == "scripttext") { if (newOffset == 0) { var indexInBlock = targetElement.ParentElement.ChildNodes.IndexOf(targetElement); if (indexInBlock > 0) { return(false); } blockIndex = int.Parse(targetElement.Parent.Id); if (blockIndex == 0) { return(false); // Can't split at start of first block. } VerseToSplit = null; } else { blockIndex = int.Parse(targetElement.Parent.Id); if (blockIndex == m_originalBlocks.Count - 1 && newOffset == selection.AnchorNode.NodeValue.Length) { return(false); // Can't split at very end of last verse in last block } VerseToSplit = targetElement.Id; var childNodes = selection.AnchorNode.ParentNode.ChildNodes; if (childNodes.Length == 3 && selection.AnchorNode.Equals(childNodes[2])) { newOffset += childNodes[0].NodeValue.Length; } } } else { return(false); } BlockToSplit = m_originalBlocks[blockIndex]; CharacterOffsetToSplit = newOffset; return(true); }