Commit 1601eee1 authored by Vladimir Levin's avatar Vladimir Levin Committed by Commit Bot

DevTools: Ensure to fetch contrast for the right element in highlight.

In NodeHighlightTool ctor, we may override which node is actually
used, if the node in question is under a content-visibility element
which prevents visibility. When later on we fetch the contrast values
for that node, we should use |node_| as opposed to |node| since at
that time, the two values could be different.

Note that this changes includes leveraging NodeHighlightTool directly
in the getHighlightObjectForTest function, since previously the two
implementations were different. The updated test would now fail without
the |node| -> |node_| switch, but passes with the switch.

R=chrishtr@chromium.org

Fixed: 1090371
Change-Id: Ic98aafaf02818203311bf6a745575a0612612914
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228124Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775172}
parent c5cb00b8
...@@ -286,7 +286,7 @@ NodeHighlightTool::NodeHighlightTool( ...@@ -286,7 +286,7 @@ NodeHighlightTool::NodeHighlightTool(
} else { } else {
node_ = node; node_ = node;
} }
contrast_info_ = FetchContrast(node); contrast_info_ = FetchContrast(node_);
} }
bool NodeHighlightTool::ForwardEventsToOverlay() { bool NodeHighlightTool::ForwardEventsToOverlay() {
...@@ -311,11 +311,10 @@ void NodeHighlightTool::DrawNode() { ...@@ -311,11 +311,10 @@ void NodeHighlightTool::DrawNode() {
highlight_config_->show_info && highlight_config_->show_info &&
node_->GetLayoutObject() && node_->GetLayoutObject() &&
node_->GetDocument().GetFrame(); node_->GetDocument().GetFrame();
InspectorHighlight highlight(node_.Get(), *highlight_config_, contrast_info_, overlay_->EvaluateInOverlay(
append_element_info, false, is_locked_ancestor_); "drawHighlight",
std::unique_ptr<protocol::DictionaryValue> highlight_json = GetNodeInspectorHighlightAsJson(append_element_info,
highlight.AsProtocolValue(); false /* append_distance_info */));
overlay_->EvaluateInOverlay("drawHighlight", std::move(highlight_json));
} }
void NodeHighlightTool::DrawMatchingSelector() { void NodeHighlightTool::DrawMatchingSelector() {
...@@ -348,6 +347,16 @@ void NodeHighlightTool::Trace(Visitor* visitor) const { ...@@ -348,6 +347,16 @@ void NodeHighlightTool::Trace(Visitor* visitor) const {
visitor->Trace(node_); visitor->Trace(node_);
} }
std::unique_ptr<protocol::DictionaryValue>
NodeHighlightTool::GetNodeInspectorHighlightAsJson(
bool append_element_info,
bool append_distance_info) const {
InspectorHighlight highlight(node_.Get(), *highlight_config_, contrast_info_,
append_element_info, append_distance_info,
is_locked_ancestor_);
return highlight.AsProtocolValue();
}
// NearbyDistanceTool ---------------------------------------------------------- // NearbyDistanceTool ----------------------------------------------------------
int NearbyDistanceTool::GetDataResourceId() { int NearbyDistanceTool::GetDataResourceId() {
......
...@@ -73,6 +73,10 @@ class NodeHighlightTool : public InspectTool { ...@@ -73,6 +73,10 @@ class NodeHighlightTool : public InspectTool {
String selector_list, String selector_list,
std::unique_ptr<InspectorHighlightConfig> highlight_config); std::unique_ptr<InspectorHighlightConfig> highlight_config);
std::unique_ptr<protocol::DictionaryValue> GetNodeInspectorHighlightAsJson(
bool append_element_info,
bool append_distance_info) const;
private: private:
bool ForwardEventsToOverlay() override; bool ForwardEventsToOverlay() override;
bool HideOnMouseMove() override; bool HideOnMouseMove() override;
......
...@@ -734,35 +734,23 @@ Response InspectorOverlayAgent::getHighlightObjectForTest( ...@@ -734,35 +734,23 @@ Response InspectorOverlayAgent::getHighlightObjectForTest(
Response response = dom_agent_->AssertNode(node_id, node); Response response = dom_agent_->AssertNode(node_id, node);
if (!response.IsSuccess()) if (!response.IsSuccess())
return response; return response;
bool is_locked_ancestor = false;
// If |node| is in a display locked subtree, highlight the highest locked
// ancestor element instead.
if (Node* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node)) {
node = locked_ancestor;
is_locked_ancestor = true;
}
InspectorHighlightConfig config = InspectorHighlight::DefaultConfig();
config.show_styles = include_style.fromMaybe(false);
auto config = std::make_unique<InspectorHighlightConfig>(
InspectorHighlight::DefaultConfig());
config->show_styles = include_style.fromMaybe(false);
String format = colorFormat.fromMaybe("hex"); String format = colorFormat.fromMaybe("hex");
namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum; namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum;
if (format == ColorFormatEnum::Hsl) { if (format == ColorFormatEnum::Hsl) {
config.color_format = ColorFormat::HSL; config->color_format = ColorFormat::HSL;
} else if (format == ColorFormatEnum::Rgb) { } else if (format == ColorFormatEnum::Rgb) {
config.color_format = ColorFormat::RGB; config->color_format = ColorFormat::RGB;
} else { } else {
config.color_format = ColorFormat::HEX; config->color_format = ColorFormat::HEX;
} }
InspectorHighlight highlight(node, config, InspectorHighlightContrastInfo(), NodeHighlightTool tool(node, "" /* selector_list */, std::move(config));
true /* append_element_info */, *result = tool.GetNodeInspectorHighlightAsJson(
include_distance.fromMaybe(false), true /* append_element_info */, include_distance.fromMaybe(false));
is_locked_ancestor);
*result = highlight.AsProtocolValue();
return Response::Success(); return Response::Success();
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
await TestRunner.showPanel('elements'); await TestRunner.showPanel('elements');
await TestRunner.loadHTML(` await TestRunner.loadHTML(`
<div id="container" style="content-visibility: hidden; contain-intrinsic-size: 10px;"> <div id="container" style="content-visibility: hidden; contain-intrinsic-size: 10px;">
<div id="child" style="width: 50px; height: 50px;"></div> <div id="child" style="width: 50px; height: 50px; background: blue">Text</div>
</div> </div>
`); `);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment