// Copyright © 2020 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. namespace CefSharp.DevTools.CSS { using System.Linq; /// /// This domain exposes CSS read/write operations. All CSS objects (stylesheets, rules, and styles) /// have an associated `id` used in subsequent operations on the related object. Each object type has /// a specific `id` structure, and those are not interchangeable between objects of different kinds. /// CSS objects can be loaded using the `get*ForNode()` calls (which accept a DOM node id). A client /// can also keep track of stylesheets via the `styleSheetAdded`/`styleSheetRemoved` events and /// subsequently load the required stylesheet contents using the `getStyleSheet[Text]()` methods. /// public partial class CSS : DevToolsDomainBase { private CefSharp.DevTools.IDevToolsClient _client; public CSS(CefSharp.DevTools.IDevToolsClient client) { _client = (client); } partial void ValidateAddRule(string styleSheetId, string ruleText, CefSharp.DevTools.CSS.SourceRange location); /// /// Inserts a new rule with the given `ruleText` in a stylesheet with given `styleSheetId`, at the /// position specified by `location`. /// /// The css style sheet identifier where a new rule should be inserted. /// The text of a new rule. /// Text position of a new rule in the target style sheet. /// returns System.Threading.Tasks.Task<AddRuleResponse> public async System.Threading.Tasks.Task AddRuleAsync(string styleSheetId, string ruleText, CefSharp.DevTools.CSS.SourceRange location) { ValidateAddRule(styleSheetId, ruleText, location); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); dict.Add("ruleText", ruleText); dict.Add("location", location.ToDictionary()); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.addRule", dict); return methodResult.DeserializeJson(); } partial void ValidateCollectClassNames(string styleSheetId); /// /// Returns all class names from specified stylesheet. /// /// styleSheetId /// returns System.Threading.Tasks.Task<CollectClassNamesResponse> public async System.Threading.Tasks.Task CollectClassNamesAsync(string styleSheetId) { ValidateCollectClassNames(styleSheetId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.collectClassNames", dict); return methodResult.DeserializeJson(); } partial void ValidateCreateStyleSheet(string frameId); /// /// Creates a new special "via-inspector" stylesheet in the frame with given `frameId`. /// /// Identifier of the frame where "via-inspector" stylesheet should be created. /// returns System.Threading.Tasks.Task<CreateStyleSheetResponse> public async System.Threading.Tasks.Task CreateStyleSheetAsync(string frameId) { ValidateCreateStyleSheet(frameId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("frameId", frameId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.createStyleSheet", dict); return methodResult.DeserializeJson(); } /// /// Disables the CSS agent for the given page. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task DisableAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.disable", dict); return methodResult; } /// /// Enables the CSS agent for the given page. Clients should not assume that the CSS agent has been /// enabled until the result of this command is received. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task EnableAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.enable", dict); return methodResult; } partial void ValidateForcePseudoState(int nodeId, string[] forcedPseudoClasses); /// /// Ensures that the given node will have specified pseudo-classes whenever its style is computed by /// the browser. /// /// The element id for which to force the pseudo state. /// Element pseudo classes to force when computing the element's style. /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task ForcePseudoStateAsync(int nodeId, string[] forcedPseudoClasses) { ValidateForcePseudoState(nodeId, forcedPseudoClasses); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); dict.Add("forcedPseudoClasses", forcedPseudoClasses); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.forcePseudoState", dict); return methodResult; } partial void ValidateGetBackgroundColors(int nodeId); /// /// GetBackgroundColors /// /// Id of the node to get background colors for. /// returns System.Threading.Tasks.Task<GetBackgroundColorsResponse> public async System.Threading.Tasks.Task GetBackgroundColorsAsync(int nodeId) { ValidateGetBackgroundColors(nodeId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getBackgroundColors", dict); return methodResult.DeserializeJson(); } partial void ValidateGetComputedStyleForNode(int nodeId); /// /// Returns the computed style for a DOM node identified by `nodeId`. /// /// nodeId /// returns System.Threading.Tasks.Task<GetComputedStyleForNodeResponse> public async System.Threading.Tasks.Task GetComputedStyleForNodeAsync(int nodeId) { ValidateGetComputedStyleForNode(nodeId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getComputedStyleForNode", dict); return methodResult.DeserializeJson(); } partial void ValidateGetInlineStylesForNode(int nodeId); /// /// Returns the styles defined inline (explicitly in the "style" attribute and implicitly, using DOM /// attributes) for a DOM node identified by `nodeId`. /// /// nodeId /// returns System.Threading.Tasks.Task<GetInlineStylesForNodeResponse> public async System.Threading.Tasks.Task GetInlineStylesForNodeAsync(int nodeId) { ValidateGetInlineStylesForNode(nodeId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getInlineStylesForNode", dict); return methodResult.DeserializeJson(); } partial void ValidateGetMatchedStylesForNode(int nodeId); /// /// Returns requested styles for a DOM node identified by `nodeId`. /// /// nodeId /// returns System.Threading.Tasks.Task<GetMatchedStylesForNodeResponse> public async System.Threading.Tasks.Task GetMatchedStylesForNodeAsync(int nodeId) { ValidateGetMatchedStylesForNode(nodeId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getMatchedStylesForNode", dict); return methodResult.DeserializeJson(); } /// /// Returns all media queries parsed by the rendering engine. /// /// returns System.Threading.Tasks.Task<GetMediaQueriesResponse> public async System.Threading.Tasks.Task GetMediaQueriesAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getMediaQueries", dict); return methodResult.DeserializeJson(); } partial void ValidateGetPlatformFontsForNode(int nodeId); /// /// Requests information about platform fonts which we used to render child TextNodes in the given /// node. /// /// nodeId /// returns System.Threading.Tasks.Task<GetPlatformFontsForNodeResponse> public async System.Threading.Tasks.Task GetPlatformFontsForNodeAsync(int nodeId) { ValidateGetPlatformFontsForNode(nodeId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getPlatformFontsForNode", dict); return methodResult.DeserializeJson(); } partial void ValidateGetStyleSheetText(string styleSheetId); /// /// Returns the current textual content for a stylesheet. /// /// styleSheetId /// returns System.Threading.Tasks.Task<GetStyleSheetTextResponse> public async System.Threading.Tasks.Task GetStyleSheetTextAsync(string styleSheetId) { ValidateGetStyleSheetText(styleSheetId); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.getStyleSheetText", dict); return methodResult.DeserializeJson(); } partial void ValidateSetEffectivePropertyValueForNode(int nodeId, string propertyName, string value); /// /// Find a rule with the given active property for the given node and set the new value for this /// property /// /// The element id for which to set property. /// propertyName /// value /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task SetEffectivePropertyValueForNodeAsync(int nodeId, string propertyName, string value) { ValidateSetEffectivePropertyValueForNode(nodeId, propertyName, value); var dict = new System.Collections.Generic.Dictionary(); dict.Add("nodeId", nodeId); dict.Add("propertyName", propertyName); dict.Add("value", value); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setEffectivePropertyValueForNode", dict); return methodResult; } partial void ValidateSetKeyframeKey(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string keyText); /// /// Modifies the keyframe rule key text. /// /// styleSheetId /// range /// keyText /// returns System.Threading.Tasks.Task<SetKeyframeKeyResponse> public async System.Threading.Tasks.Task SetKeyframeKeyAsync(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string keyText) { ValidateSetKeyframeKey(styleSheetId, range, keyText); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); dict.Add("range", range.ToDictionary()); dict.Add("keyText", keyText); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setKeyframeKey", dict); return methodResult.DeserializeJson(); } partial void ValidateSetMediaText(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string text); /// /// Modifies the rule selector. /// /// styleSheetId /// range /// text /// returns System.Threading.Tasks.Task<SetMediaTextResponse> public async System.Threading.Tasks.Task SetMediaTextAsync(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string text) { ValidateSetMediaText(styleSheetId, range, text); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); dict.Add("range", range.ToDictionary()); dict.Add("text", text); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setMediaText", dict); return methodResult.DeserializeJson(); } partial void ValidateSetRuleSelector(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string selector); /// /// Modifies the rule selector. /// /// styleSheetId /// range /// selector /// returns System.Threading.Tasks.Task<SetRuleSelectorResponse> public async System.Threading.Tasks.Task SetRuleSelectorAsync(string styleSheetId, CefSharp.DevTools.CSS.SourceRange range, string selector) { ValidateSetRuleSelector(styleSheetId, range, selector); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); dict.Add("range", range.ToDictionary()); dict.Add("selector", selector); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setRuleSelector", dict); return methodResult.DeserializeJson(); } partial void ValidateSetStyleSheetText(string styleSheetId, string text); /// /// Sets the new stylesheet text. /// /// styleSheetId /// text /// returns System.Threading.Tasks.Task<SetStyleSheetTextResponse> public async System.Threading.Tasks.Task SetStyleSheetTextAsync(string styleSheetId, string text) { ValidateSetStyleSheetText(styleSheetId, text); var dict = new System.Collections.Generic.Dictionary(); dict.Add("styleSheetId", styleSheetId); dict.Add("text", text); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setStyleSheetText", dict); return methodResult.DeserializeJson(); } partial void ValidateSetStyleTexts(System.Collections.Generic.IList edits); /// /// Applies specified style edits one after another in the given order. /// /// edits /// returns System.Threading.Tasks.Task<SetStyleTextsResponse> public async System.Threading.Tasks.Task SetStyleTextsAsync(System.Collections.Generic.IList edits) { ValidateSetStyleTexts(edits); var dict = new System.Collections.Generic.Dictionary(); dict.Add("edits", edits.Select(x => x.ToDictionary())); var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.setStyleTexts", dict); return methodResult.DeserializeJson(); } /// /// Enables the selector recording. /// /// returns System.Threading.Tasks.Task<DevToolsMethodResponse> public async System.Threading.Tasks.Task StartRuleUsageTrackingAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.startRuleUsageTracking", dict); return methodResult; } /// /// Stop tracking rule usage and return the list of rules that were used since last call to /// `takeCoverageDelta` (or since start of coverage instrumentation) /// /// returns System.Threading.Tasks.Task<StopRuleUsageTrackingResponse> public async System.Threading.Tasks.Task StopRuleUsageTrackingAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.stopRuleUsageTracking", dict); return methodResult.DeserializeJson(); } /// /// Obtain list of rules that became used since last call to this method (or since start of coverage /// instrumentation) /// /// returns System.Threading.Tasks.Task<TakeCoverageDeltaResponse> public async System.Threading.Tasks.Task TakeCoverageDeltaAsync() { System.Collections.Generic.Dictionary dict = null; var methodResult = await _client.ExecuteDevToolsMethodAsync("CSS.takeCoverageDelta", dict); return methodResult.DeserializeJson(); } } }