mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
d33c41ec5d
No need to wrap bool in gcroot Move command line parsing into c# land - can be reused in a few places. Reduce code duplication in OnProcessMessageReceived - kOnFocusedNodeChanged handler Minor changes for code consistency/formatting
104 lines
2.7 KiB
C#
104 lines
2.7 KiB
C#
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace CefSharp
|
|
{
|
|
/// <summary>
|
|
/// Represents a node in the browser's DOM.
|
|
/// </summary>
|
|
public class DomNode : IDomNode
|
|
{
|
|
private readonly IDictionary<string, string> _attributes;
|
|
|
|
public DomNode (string tagName, IDictionary<string, string> attributes)
|
|
{
|
|
TagName = tagName;
|
|
_attributes = attributes;
|
|
}
|
|
|
|
public override string ToString ()
|
|
{
|
|
var sb = new StringBuilder ();
|
|
if (_attributes != null)
|
|
{
|
|
foreach (var pair in _attributes)
|
|
{
|
|
sb.AppendFormat ("{0}{1}:'{2}'", 0 < sb.Length ? ", " : String.Empty, pair.Key, pair.Value);
|
|
}
|
|
}
|
|
|
|
if (!String.IsNullOrWhiteSpace (TagName))
|
|
{
|
|
sb.Insert (0, String.Format ("{0} ", TagName));
|
|
}
|
|
|
|
if (sb.Length < 1)
|
|
{
|
|
return base.ToString ();
|
|
}
|
|
|
|
return sb.ToString ();
|
|
}
|
|
|
|
public string this[string name]
|
|
{
|
|
get
|
|
{
|
|
if (_attributes == null || _attributes.Count < 1 || !_attributes.ContainsKey (name))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return _attributes[name];
|
|
}
|
|
}
|
|
|
|
public string TagName { get; private set; }
|
|
|
|
public ReadOnlyCollection<string> AttributeNames
|
|
{
|
|
get
|
|
{
|
|
if (_attributes == null)
|
|
{
|
|
return new ReadOnlyCollection<string> (new List<string> ());
|
|
}
|
|
|
|
return Array.AsReadOnly<string> (_attributes.Keys.ToArray ());
|
|
}
|
|
}
|
|
|
|
public bool HasAttribute (string attributeName)
|
|
{
|
|
if (_attributes == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return _attributes.ContainsKey (attributeName);
|
|
}
|
|
|
|
public IEnumerator<KeyValuePair<string, string>>GetEnumerator()
|
|
{
|
|
if (_attributes == null)
|
|
{
|
|
return new Dictionary<string, string>().GetEnumerator();
|
|
}
|
|
|
|
return _attributes.GetEnumerator ();
|
|
}
|
|
|
|
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator ();
|
|
}
|
|
}
|
|
}
|