summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc')
-rw-r--r--chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc281
1 files changed, 213 insertions, 68 deletions
diff --git a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc
index ab44f6ddbd3..ffe39fd95a3 100644
--- a/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc
+++ b/chromium/third_party/blink/renderer/core/inspector/inspector_overlay_agent.cc
@@ -126,7 +126,7 @@ int InspectTool::GetDataResourceId() {
bool InspectTool::HandleInputEvent(LocalFrameView* frame_view,
const WebInputEvent& input_event,
bool* swallow_next_mouse_up) {
- if (input_event.GetType() == WebInputEvent::kGestureTap) {
+ if (input_event.GetType() == WebInputEvent::Type::kGestureTap) {
// We only have a use for gesture tap.
WebGestureEvent transformed_event = TransformWebGestureEvent(
frame_view, static_cast<const WebGestureEvent&>(input_event));
@@ -155,13 +155,13 @@ bool InspectTool::HandleInputEvent(LocalFrameView* frame_view,
bool InspectTool::HandleMouseEvent(const WebMouseEvent& mouse_event,
bool* swallow_next_mouse_up) {
- if (mouse_event.GetType() == WebInputEvent::kMouseMove)
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseMove)
return HandleMouseMove(mouse_event);
- if (mouse_event.GetType() == WebInputEvent::kMouseDown)
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseDown)
return HandleMouseDown(mouse_event, swallow_next_mouse_up);
- if (mouse_event.GetType() == WebInputEvent::kMouseUp)
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseUp)
return HandleMouseUp(mouse_event);
return false;
@@ -196,6 +196,10 @@ bool InspectTool::ForwardEventsToOverlay() {
return true;
}
+bool InspectTool::HideOnMouseMove() {
+ return false;
+}
+
bool InspectTool::HideOnHideHighlight() {
return false;
}
@@ -204,6 +208,34 @@ void InspectTool::Trace(Visitor* visitor) {
visitor->Trace(overlay_);
}
+// Hinge -----------------------------------------------------------------------
+
+Hinge::Hinge(FloatQuad quad,
+ Color content_color,
+ Color outline_color,
+ InspectorOverlayAgent* overlay)
+ : quad_(quad),
+ content_color_(content_color),
+ outline_color_(outline_color),
+ overlay_(overlay) {}
+
+// static
+int Hinge::GetDataResourceId() {
+ // TODO (soxia): In the future, we should make the hinge working properly
+ // with tools using different resources.
+ return IDR_INSPECT_TOOL_HIGHLIGHT_HTML;
+}
+
+void Hinge::Trace(Visitor* visitor) {
+ visitor->Trace(overlay_);
+}
+
+void Hinge::Draw(float scale) {
+ InspectorHighlight highlight(scale);
+ highlight.AppendQuad(quad_, content_color_, outline_color_);
+ overlay_->EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue());
+}
+
// InspectorOverlayAgent -------------------------------------------------------
class InspectorOverlayAgent::InspectorPageOverlayDelegate final
@@ -226,7 +258,7 @@ class InspectorOverlayAgent::InspectorPageOverlayDelegate final
void PaintFrameOverlay(const FrameOverlay& frame_overlay,
GraphicsContext& graphics_context,
const IntSize&) const override {
- if (!overlay_->inspect_tool_)
+ if (!overlay_->IsVisible())
return;
overlay_->PaintOverlayPage();
@@ -329,7 +361,6 @@ InspectorOverlayAgent::InspectorOverlayAgent(
v8_session_(v8_session),
dom_agent_(dom_agent),
swallow_next_mouse_up_(false),
- swallow_next_escape_up_(false),
backend_node_id_to_inspect_(0),
enabled_(&agent_state_, false),
show_ad_highlights_(&agent_state_, false),
@@ -356,6 +387,7 @@ void InspectorOverlayAgent::Trace(Visitor* visitor) {
visitor->Trace(overlay_host_);
visitor->Trace(dom_agent_);
visitor->Trace(inspect_tool_);
+ visitor->Trace(hinge_);
InspectorBaseAgent::Trace(visitor);
}
@@ -592,6 +624,48 @@ Response InspectorOverlayAgent::highlightQuad(
return Response::Success();
}
+Response InspectorOverlayAgent::setShowHinge(
+ protocol::Maybe<protocol::Overlay::HingeConfig> tool_config) {
+ // Hide the hinge when called without a configuration.
+ if (!tool_config.isJust()) {
+ hinge_ = nullptr;
+ if (!inspect_tool_)
+ DisableFrameOverlay();
+ ScheduleUpdate();
+ return Response::Success();
+ }
+
+ // Create a hinge
+ protocol::Overlay::HingeConfig* config = tool_config.fromJust();
+ protocol::DOM::Rect* rect = config->getRect();
+ int x = rect->getX();
+ int y = rect->getY();
+ int width = rect->getWidth();
+ int height = rect->getHeight();
+ if (x < 0 || y < 0 || width < 0 || height < 0)
+ return Response::InvalidParams("Invalid hinge rectangle.");
+
+ // Use default color if a content color is not provided.
+ Color content_color =
+ config->hasContentColor()
+ ? InspectorDOMAgent::ParseColor(config->getContentColor(nullptr))
+ : Color(38, 38, 38);
+ // outlineColor uses a kTransparent default from ParseColor if not provided.
+ Color outline_color =
+ InspectorDOMAgent::ParseColor(config->getOutlineColor(nullptr));
+
+ DCHECK(frame_impl_->GetFrameView() && GetFrame());
+
+ LoadFrameForTool(Hinge::GetDataResourceId());
+ EnsureEnableFrameOverlay();
+ FloatQuad quad(FloatRect(x, y, width, height));
+ hinge_ =
+ MakeGarbageCollected<Hinge>(quad, content_color, outline_color, this);
+ ScheduleUpdate();
+
+ return Response::Success();
+}
+
Response InspectorOverlayAgent::highlightNode(
std::unique_ptr<protocol::Overlay::HighlightConfig>
highlight_inspector_object,
@@ -645,6 +719,7 @@ Response InspectorOverlayAgent::highlightFrame(
Response InspectorOverlayAgent::hideHighlight() {
if (inspect_tool_ && inspect_tool_->HideOnHideHighlight())
PickTheRightTool();
+
return Response::Success();
}
@@ -652,6 +727,7 @@ Response InspectorOverlayAgent::getHighlightObjectForTest(
int node_id,
Maybe<bool> include_distance,
Maybe<bool> include_style,
+ Maybe<String> colorFormat,
std::unique_ptr<protocol::DictionaryValue>* result) {
Node* node = nullptr;
Response response = dom_agent_->AssertNode(node_id, node);
@@ -669,6 +745,18 @@ Response InspectorOverlayAgent::getHighlightObjectForTest(
InspectorHighlightConfig config = InspectorHighlight::DefaultConfig();
config.show_styles = include_style.fromMaybe(false);
+
+ String format = colorFormat.fromMaybe("hex");
+
+ namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum;
+ if (format == ColorFormatEnum::Hsl) {
+ config.color_format = ColorFormat::HSL;
+ } else if (format == ColorFormatEnum::Rgb) {
+ config.color_format = ColorFormat::RGB;
+ } else {
+ config.color_format = ColorFormat::HEX;
+ }
+
InspectorHighlight highlight(node, config, InspectorHighlightContrastInfo(),
true /* append_element_info */,
include_distance.fromMaybe(false),
@@ -711,22 +799,12 @@ void InspectorOverlayAgent::DispatchBufferedTouchEvents() {
WebInputEventResult InspectorOverlayAgent::HandleInputEvent(
const WebInputEvent& input_event) {
- if (input_event.GetType() == WebInputEvent::kMouseUp &&
+ if (input_event.GetType() == WebInputEvent::Type::kMouseUp &&
swallow_next_mouse_up_) {
swallow_next_mouse_up_ = false;
return WebInputEventResult::kHandledSuppressed;
}
- if (input_event.GetType() == WebInputEvent::kKeyUp &&
- swallow_next_escape_up_) {
- const auto& keyboard_event =
- static_cast<const WebKeyboardEvent&>(input_event);
- if (keyboard_event.windows_key_code == VKEY_ESCAPE) {
- swallow_next_escape_up_ = false;
- return WebInputEventResult::kHandledSuppressed;
- }
- }
-
LocalFrame* frame = GetFrame();
if (!frame || !frame->View() || !frame->ContentLayoutObject() ||
!inspect_tool_)
@@ -749,41 +827,41 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEvent(
}
// Exit tool upon unhandled Esc.
- if (input_event.GetType() == WebInputEvent::kRawKeyDown) {
+ if (input_event.GetType() == WebInputEvent::Type::kRawKeyDown) {
const WebKeyboardEvent& keyboard_event =
static_cast<const WebKeyboardEvent&>(input_event);
if (keyboard_event.windows_key_code == VKEY_ESCAPE) {
GetFrontend()->inspectModeCanceled();
- swallow_next_escape_up_ = true;
- return WebInputEventResult::kHandledSuppressed;
+ return WebInputEventResult::kNotHandled;
}
}
+ if (input_event.GetType() == WebInputEvent::Type::kMouseMove &&
+ inspect_tool_->HideOnMouseMove()) {
+ PickTheRightTool();
+ }
+
return WebInputEventResult::kNotHandled;
}
WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay(
const WebInputEvent& input_event) {
- if (input_event.GetType() == WebInputEvent::kGestureTap) {
+ if (input_event.GetType() == WebInputEvent::Type::kGestureTap) {
return OverlayMainFrame()->GetEventHandler().HandleGestureEvent(
static_cast<const WebGestureEvent&>(input_event));
}
if (WebInputEvent::IsMouseEventType(input_event.GetType())) {
WebMouseEvent mouse_event = static_cast<const WebMouseEvent&>(input_event);
- if (mouse_event.GetType() == WebInputEvent::kMouseMove) {
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseMove) {
return OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent(
- mouse_event,
- TransformWebMouseEventVector(frame_impl_->GetFrameView(),
- WebVector<const WebInputEvent*>()),
- TransformWebMouseEventVector(frame_impl_->GetFrameView(),
- WebVector<const WebInputEvent*>()));
+ mouse_event, {}, {});
}
- if (mouse_event.GetType() == WebInputEvent::kMouseDown) {
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseDown) {
return OverlayMainFrame()->GetEventHandler().HandleMousePressEvent(
mouse_event);
}
- if (mouse_event.GetType() == WebInputEvent::kMouseUp) {
+ if (mouse_event.GetType() == WebInputEvent::Type::kMouseUp) {
return OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent(
mouse_event);
}
@@ -801,7 +879,7 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay(
static_cast<const WebKeyboardEvent&>(input_event));
}
- if (input_event.GetType() == WebInputEvent::kMouseWheel) {
+ if (input_event.GetType() == WebInputEvent::Type::kMouseWheel) {
return OverlayMainFrame()->GetEventHandler().HandleWheelEvent(
static_cast<const WebMouseWheelEvent&>(input_event));
}
@@ -810,7 +888,7 @@ WebInputEventResult InspectorOverlayAgent::HandleInputEventInOverlay(
}
void InspectorOverlayAgent::ScheduleUpdate() {
- if (inspect_tool_) {
+ if (IsVisible()) {
GetFrame()->GetPage()->GetChromeClient().ScheduleAnimation(
GetFrame()->View());
}
@@ -841,8 +919,10 @@ void InspectorOverlayAgent::PaintOverlayPage() {
Reset(viewport_size);
- DCHECK(inspect_tool_);
- inspect_tool_->Draw(WindowToViewportScale());
+ if (inspect_tool_)
+ inspect_tool_->Draw(WindowToViewportScale());
+ if (hinge_)
+ hinge_->Draw(WindowToViewportScale());
OverlayMainFrame()->View()->UpdateAllLifecyclePhases(
DocumentUpdateReason::kInspector);
@@ -865,10 +945,20 @@ float InspectorOverlayAgent::WindowToViewportScale() const {
1.0f);
}
-void InspectorOverlayAgent::EnsureOverlayPageCreated() {
- if (overlay_page_)
+void InspectorOverlayAgent::LoadFrameForTool(int data_resource_id) {
+ if (frame_resource_name_ == data_resource_id)
return;
+ frame_resource_name_ = data_resource_id;
+
+ if (overlay_page_) {
+ overlay_page_->WillBeDestroyed();
+ overlay_page_.Clear();
+ overlay_chrome_client_.Clear();
+ overlay_host_->ClearDelegate();
+ overlay_host_.Clear();
+ }
+
ScriptForbiddenScope::AllowUserAgentScript allow_script;
Page::PageClients page_clients;
@@ -905,23 +995,8 @@ void InspectorOverlayAgent::EnsureOverlayPageCreated() {
DEFINE_STATIC_LOCAL(Persistent<LocalFrameClient>, dummy_local_frame_client,
(MakeGarbageCollected<EmptyLocalFrameClient>()));
auto* frame = MakeGarbageCollected<LocalFrame>(
- dummy_local_frame_client, *overlay_page_, nullptr, nullptr, nullptr);
- frame->SetView(MakeGarbageCollected<LocalFrameView>(*frame));
- frame->Init();
- frame->View()->SetCanHaveScrollbars(false);
- frame->View()->SetBaseBackgroundColor(Color::kTransparent);
-}
-
-void InspectorOverlayAgent::LoadFrameForTool() {
- if (frame_resource_name_ == inspect_tool_->GetDataResourceId())
- return;
-
- frame_resource_name_ = inspect_tool_->GetDataResourceId();
-
- DEFINE_STATIC_LOCAL(Persistent<LocalFrameClient>, dummy_local_frame_client,
- (MakeGarbageCollected<EmptyLocalFrameClient>()));
- auto* frame = MakeGarbageCollected<LocalFrame>(
- dummy_local_frame_client, *overlay_page_, nullptr, nullptr, nullptr);
+ dummy_local_frame_client, *overlay_page_, nullptr,
+ base::UnguessableToken::Create(), nullptr, nullptr);
frame->SetView(MakeGarbageCollected<LocalFrameView>(*frame));
frame->Init();
frame->View()->SetCanHaveScrollbars(false);
@@ -1161,9 +1236,31 @@ void InspectorOverlayAgent::PickTheRightTool() {
inspect_tool = MakeGarbageCollected<PausedInDebuggerTool>(
v8_session_, paused_in_debugger_message_.Get());
}
+
SetInspectTool(inspect_tool);
}
+void InspectorOverlayAgent::DisableFrameOverlay() {
+ if (IsVisible() || !frame_overlay_)
+ return;
+
+ frame_overlay_.reset();
+ auto& client = GetFrame()->GetPage()->GetChromeClient();
+ client.SetCursorOverridden(false);
+ client.SetCursor(PointerCursor(), GetFrame());
+
+ if (auto* frame_view = frame_impl_->GetFrameView())
+ frame_view->SetPaintArtifactCompositorNeedsUpdate();
+}
+
+void InspectorOverlayAgent::EnsureEnableFrameOverlay() {
+ if (frame_overlay_)
+ return;
+
+ frame_overlay_ = std::make_unique<FrameOverlay>(
+ GetFrame(), std::make_unique<InspectorPageOverlayDelegate>(*this));
+}
+
void InspectorOverlayAgent::SetInspectTool(InspectTool* inspect_tool) {
LocalFrameView* view = frame_impl_->GetFrameView();
LocalFrame* frame = GetFrame();
@@ -1172,22 +1269,16 @@ void InspectorOverlayAgent::SetInspectTool(InspectTool* inspect_tool) {
if (inspect_tool_)
inspect_tool_->Dispose();
- inspect_tool_ = inspect_tool;
- if (inspect_tool_) {
- EnsureOverlayPageCreated();
- LoadFrameForTool();
- if (!frame_overlay_) {
- frame_overlay_ = std::make_unique<FrameOverlay>(
- GetFrame(), std::make_unique<InspectorPageOverlayDelegate>(*this));
- }
- inspect_tool_->Init(this, GetFrontend());
- } else if (frame_overlay_) {
- frame_overlay_.reset();
- auto& client = GetFrame()->GetPage()->GetChromeClient();
- client.SetCursorOverridden(false);
- client.SetCursor(PointerCursor(), GetFrame());
- if (auto* frame_view = frame_impl_->GetFrameView())
- frame_view->SetPaintArtifactCompositorNeedsUpdate();
+
+ if (inspect_tool) {
+ inspect_tool_ = inspect_tool;
+ LoadFrameForTool(inspect_tool->GetDataResourceId());
+ EnsureEnableFrameOverlay();
+ inspect_tool->Init(this, GetFrontend());
+ } else {
+ inspect_tool_ = nullptr;
+ if (!hinge_)
+ DisableFrameOverlay();
}
ScheduleUpdate();
}
@@ -1201,11 +1292,49 @@ Response InspectorOverlayAgent::HighlightConfigFromInspectorObject(
}
protocol::Overlay::HighlightConfig* config =
highlight_inspector_object.fromJust();
+
+ namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum;
+
+ String format = config->getColorFormat("hex");
+
+ if (format != ColorFormatEnum::Rgb && format != ColorFormatEnum::Hex &&
+ format != ColorFormatEnum::Hsl) {
+ return Response::InvalidParams("Unknown color format");
+ }
+
*out_config = InspectorOverlayAgent::ToHighlightConfig(config);
return Response::Success();
}
// static
+std::unique_ptr<InspectorGridHighlightConfig>
+InspectorOverlayAgent::ToGridHighlightConfig(
+ protocol::Overlay::GridHighlightConfig* config) {
+ if (!config) {
+ return nullptr;
+ }
+ std::unique_ptr<InspectorGridHighlightConfig> highlight_config =
+ std::make_unique<InspectorGridHighlightConfig>();
+ highlight_config->show_grid_extension_lines =
+ config->getShowGridExtensionLines(false);
+ highlight_config->grid_border_dash = config->getGridBorderDash(false);
+ highlight_config->cell_border_dash = config->getCellBorderDash(false);
+ highlight_config->grid_color =
+ InspectorDOMAgent::ParseColor(config->getGridBorderColor(nullptr));
+ highlight_config->cell_color =
+ InspectorDOMAgent::ParseColor(config->getCellBorderColor(nullptr));
+ highlight_config->row_gap_color =
+ InspectorDOMAgent::ParseColor(config->getRowGapColor(nullptr));
+ highlight_config->column_gap_color =
+ InspectorDOMAgent::ParseColor(config->getColumnGapColor(nullptr));
+ highlight_config->row_hatch_color =
+ InspectorDOMAgent::ParseColor(config->getRowHatchColor(nullptr));
+ highlight_config->column_hatch_color =
+ InspectorDOMAgent::ParseColor(config->getColumnHatchColor(nullptr));
+ return highlight_config;
+}
+
+// static
std::unique_ptr<InspectorHighlightConfig>
InspectorOverlayAgent::ToHighlightConfig(
protocol::Overlay::HighlightConfig* config) {
@@ -1231,6 +1360,22 @@ InspectorOverlayAgent::ToHighlightConfig(
InspectorDOMAgent::ParseColor(config->getShapeMarginColor(nullptr));
highlight_config->css_grid =
InspectorDOMAgent::ParseColor(config->getCssGridColor(nullptr));
+
+ namespace ColorFormatEnum = protocol::Overlay::ColorFormatEnum;
+
+ String format = config->getColorFormat("hex");
+
+ if (format == ColorFormatEnum::Hsl) {
+ highlight_config->color_format = ColorFormat::HSL;
+ } else if (format == ColorFormatEnum::Rgb) {
+ highlight_config->color_format = ColorFormat::RGB;
+ } else {
+ highlight_config->color_format = ColorFormat::HEX;
+ }
+
+ highlight_config->grid_highlight_config =
+ InspectorOverlayAgent::ToGridHighlightConfig(
+ config->getGridHighlightConfig(nullptr));
return highlight_config;
}