Commit 7a97b880 authored by Vladimir Levin's avatar Vladimir Levin Committed by Chromium LUCI CQ

devtools: Expose content-visibility locked element info.

DevTools exposes info if the node shown is a locked ancestor instead
of the element itself. This patch adds an additional piece of information
that shows if the highlighted element itself locked and as a result
skips its descendants.

The actual string representation of this will be in a separate patch
in the devtools-frontend repo

R=chrishtr@chromium.org

Bug: 1147510
Change-Id: I6c4dcf8f57eebd40b458f74a73d395daf3442c58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2585144Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: vmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#836255}
parent 21468f43
......@@ -99,6 +99,7 @@ blink_core_sources_inspector = [
"main_thread_debugger.h",
"network_resources_data.cc",
"network_resources_data.h",
"node_content_visibility_state.h",
"request_debug_header_scope.cc",
"request_debug_header_scope.h",
"resolve_node.cc",
......
......@@ -23,6 +23,7 @@
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/inspector/inspector_css_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h"
#include "third_party/blink/renderer/core/inspector/node_content_visibility_state.h"
#include "third_party/blink/renderer/core/layout/hit_test_location.h"
#include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/page/chrome_client.h"
......@@ -98,6 +99,38 @@ Node* HoveredNodeForEvent(LocalFrame* frame,
ignore_pointer_events_none);
}
bool IsSelfLocked(Node* node) {
auto* element = DynamicTo<Element>(node);
if (!element)
return false;
auto* context = element->GetDisplayLockContext();
if (!context)
return false;
return context->IsLocked();
}
NodeContentVisibilityState DetermineSelfContentVisibilityState(Node* node) {
return IsSelfLocked(node) ? NodeContentVisibilityState::kIsLocked
: NodeContentVisibilityState::kNone;
}
std::pair<Node*, NodeContentVisibilityState> DetermineContentVisibilityState(
Node* node) {
DCHECK(node);
std::pair<Node*, NodeContentVisibilityState> result;
if (auto* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node)) {
result.first = locked_ancestor;
result.second = NodeContentVisibilityState::kIsLockedAncestor;
} else {
result.first = node;
result.second = DetermineSelfContentVisibilityState(node);
}
return result;
}
} // namespace
// SearchingForNodeTool --------------------------------------------------------
......@@ -141,7 +174,8 @@ void SearchingForNodeTool::Draw(float scale) {
node->GetDocument().GetFrame();
overlay_->EnsureAXContext(node);
InspectorHighlight highlight(node, *highlight_config_, contrast_info_,
append_element_info, false, is_locked_ancestor_);
append_element_info, false,
content_visibility_state_);
if (event_target_node_) {
highlight.AppendEventTargetQuads(event_target_node_.Get(),
*highlight_config_);
......@@ -189,15 +223,8 @@ bool SearchingForNodeTool::HandleMouseMove(const WebMouseEvent& event) {
if (!node)
return true;
// If |node| is in a display locked subtree, highlight the highest locked
// element instead.
if (Node* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node)) {
node = locked_ancestor;
is_locked_ancestor_ = true;
} else {
is_locked_ancestor_ = false;
}
std::tie(node, content_visibility_state_) =
DetermineContentVisibilityState(node);
if (auto* frame_owner = DynamicTo<HTMLFrameOwnerElement>(node)) {
if (!IsA<LocalFrame>(frame_owner->ContentFrame())) {
......@@ -309,13 +336,8 @@ NodeHighlightTool::NodeHighlightTool(
: InspectTool(overlay, frontend),
selector_list_(selector_list),
highlight_config_(std::move(highlight_config)) {
if (Node* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node)) {
is_locked_ancestor_ = true;
node_ = locked_ancestor;
} else {
node_ = node;
}
std::tie(node_, content_visibility_state_) =
DetermineContentVisibilityState(node);
contrast_info_ = FetchContrast(node_);
}
......@@ -375,10 +397,12 @@ void NodeHighlightTool::DrawMatchingSelector() {
// Skip elements in locked subtrees.
if (DisplayLockUtilities::NearestLockedExclusiveAncestor(*element))
continue;
NodeContentVisibilityState content_visibility_state =
DetermineSelfContentVisibilityState(element);
InspectorHighlight highlight(element, *highlight_config_, contrast_info_,
false /* append_element_info */,
false /* append_distance_info */,
false /* is_locked_ancestor */);
content_visibility_state);
overlay_->EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue());
}
}
......@@ -395,7 +419,7 @@ NodeHighlightTool::GetNodeInspectorHighlightAsJson(
overlay_->EnsureAXContext(node_.Get());
InspectorHighlight highlight(node_.Get(), *highlight_config_, contrast_info_,
append_element_info, append_distance_info,
is_locked_ancestor_);
content_visibility_state_);
return highlight.AsProtocolValue();
}
......@@ -479,12 +503,7 @@ SourceOrderTool::SourceOrderTool(
std::unique_ptr<InspectorSourceOrderConfig> source_order_config)
: InspectTool(overlay, frontend),
source_order_config_(std::move(source_order_config)) {
if (Node* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node)) {
node_ = locked_ancestor;
} else {
node_ = node;
}
node_ = DetermineContentVisibilityState(node).first;
}
String SourceOrderTool::GetOverlayName() {
......@@ -581,12 +600,7 @@ bool NearbyDistanceTool::HandleMouseMove(const WebMouseEvent& event) {
return false;
}
}
// If |node| is in a display locked subtree, highlight the highest locked
// element instead.
if (Node* locked_ancestor =
DisplayLockUtilities::HighestLockedExclusiveAncestor(*node))
node = locked_ancestor;
node = DetermineContentVisibilityState(node).first;
// Store values for the highlight.
hovered_node_ = node;
......@@ -602,10 +616,11 @@ void NearbyDistanceTool::Draw(float scale) {
if (!node)
return;
overlay_->EnsureAXContext(node);
auto content_visibility_state = DetermineSelfContentVisibilityState(node);
InspectorHighlight highlight(
node, InspectorHighlight::DefaultConfig(),
InspectorHighlightContrastInfo(), false /* append_element_info */,
true /* append_distance_info */, false /* is_locked_ancestor */);
true /* append_distance_info */, content_visibility_state);
overlay_->EvaluateInOverlay("drawDistances", highlight.AsProtocolValue());
}
......
......@@ -6,9 +6,11 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_INSPECT_TOOLS_H_
#include <vector>
#include <v8-inspector.h>
#include "base/macros.h"
#include "third_party/blink/renderer/core/inspector/inspector_overlay_agent.h"
#include "third_party/blink/renderer/core/inspector/node_content_visibility_state.h"
namespace blink {
......@@ -42,7 +44,10 @@ class SearchingForNodeTool : public InspectTool {
Member<InspectorDOMAgent> dom_agent_;
bool ua_shadow_;
bool is_locked_ancestor_ = false;
NodeContentVisibilityState content_visibility_state_ =
NodeContentVisibilityState::kNone;
Member<Node> hovered_node_;
Member<Node> event_target_node_;
std::unique_ptr<InspectorHighlightConfig> highlight_config_;
......@@ -97,7 +102,8 @@ class NodeHighlightTool : public InspectTool {
void Trace(Visitor* visitor) const override;
String GetOverlayName() override;
bool is_locked_ancestor_ = false;
NodeContentVisibilityState content_visibility_state_ =
NodeContentVisibilityState::kNone;
Member<Node> node_;
String selector_list_;
std::unique_ptr<InspectorHighlightConfig> highlight_config_;
......
......@@ -20,6 +20,7 @@
#include "third_party/blink/renderer/core/geometry/dom_rect.h"
#include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h"
#include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h"
#include "third_party/blink/renderer/core/inspector/node_content_visibility_state.h"
#include "third_party/blink/renderer/core/inspector/protocol/Overlay.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
......@@ -1465,7 +1466,7 @@ InspectorHighlight::InspectorHighlight(
const InspectorHighlightContrastInfo& node_contrast,
bool append_element_info,
bool append_distance_info,
bool is_locked_ancestor)
NodeContentVisibilityState content_visibility_state)
: InspectorHighlightBase(node),
show_rulers_(highlight_config.show_rulers),
show_extension_lines_(highlight_config.show_extension_lines),
......@@ -1484,12 +1485,22 @@ InspectorHighlight::InspectorHighlight(
highlight_config.contrast_algorithm);
}
if (element_info_ && is_locked_ancestor)
element_info_->setString("isLockedAncestor", "true");
if (element_info_) {
switch (content_visibility_state) {
case NodeContentVisibilityState::kNone:
break;
case NodeContentVisibilityState::kIsLocked:
element_info_->setBoolean("isLocked", true);
break;
case NodeContentVisibilityState::kIsLockedAncestor:
element_info_->setBoolean("isLockedAncestor", true);
break;
}
element_info_->setBoolean("showAccessibilityInfo",
show_accessibility_info_);
}
if (append_distance_info)
AppendDistanceInfo(node);
}
......
......@@ -7,6 +7,7 @@
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/pseudo_element.h"
#include "third_party/blink/renderer/core/inspector/node_content_visibility_state.h"
#include "third_party/blink/renderer/core/inspector/protocol/DOM.h"
#include "third_party/blink/renderer/platform/geometry/float_quad.h"
#include "third_party/blink/renderer/platform/geometry/layout_rect.h"
......@@ -185,7 +186,7 @@ class CORE_EXPORT InspectorHighlight : public InspectorHighlightBase {
const InspectorHighlightContrastInfo&,
bool append_element_info,
bool append_distance_info,
bool is_locked_ancestor);
NodeContentVisibilityState content_visibility_state);
explicit InspectorHighlight(float scale);
~InspectorHighlight();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_NODE_CONTENT_VISIBILITY_STATE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_NODE_CONTENT_VISIBILITY_STATE_H_
// The state of content visibility:
// - kNone means that the node has no content-visibility interactions
// - kIsLocked means that the node is itself locked and is skipping its
// contents. However, the node is not in a subtree of a locked element.
// - kIsLockedAncestor means that the initial node was in a locked subtree
// so we instead are showing this ancestor.
enum class NodeContentVisibilityState { kNone, kIsLocked, kIsLockedAncestor };
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_INSPECTOR_NODE_CONTENT_VISIBILITY_STATE_H_
......@@ -93,6 +93,7 @@ container{
"accessibleName": "",
"accessibleRole": "generic",
"layoutObjectName": "LayoutNGBlockFlow",
"isLocked": true,
"showAccessibilityInfo": true
}
}
......@@ -189,7 +190,7 @@ child{
"accessibleName": "",
"accessibleRole": "generic",
"layoutObjectName": "LayoutNGBlockFlow",
"isLockedAncestor": "true",
"isLockedAncestor": true,
"showAccessibilityInfo": true
}
}
......
......@@ -93,6 +93,7 @@ container{
"accessibleName": "",
"accessibleRole": "generic",
"layoutObjectName": "LayoutGrid",
"isLocked": true,
"showAccessibilityInfo": true
}
}
......@@ -189,7 +190,7 @@ child{
"accessibleName": "",
"accessibleRole": "generic",
"layoutObjectName": "LayoutGrid",
"isLockedAncestor": "true",
"isLockedAncestor": true,
"showAccessibilityInfo": true
}
}
......
......@@ -93,6 +93,7 @@ container{
"accessibleName": "",
"accessibleRole": "",
"layoutObjectName": "LayoutIFrame",
"isLocked": true,
"showAccessibilityInfo": true
}
}
......@@ -189,7 +190,7 @@ child{
"accessibleName": "",
"accessibleRole": "",
"layoutObjectName": "LayoutIFrame",
"isLockedAncestor": "true",
"isLockedAncestor": true,
"showAccessibilityInfo": true
}
}
......
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