OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
14 * its contributors may be used to endorse or promote products derived | 14 * its contributors may be used to endorse or promote products derived |
15 * from this software without specific prior written permission. | 15 * from this software without specific prior written permission. |
16 * | 16 * |
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 | 28 |
29 #include "web/InspectorOverlay.h" | 29 #include "web/InspectorOverlayAgent.h" |
30 | 30 |
31 #include <memory> | 31 #include <memory> |
32 | 32 |
33 #include "bindings/core/v8/ScriptController.h" | 33 #include "bindings/core/v8/ScriptController.h" |
34 #include "bindings/core/v8/ScriptSourceCode.h" | 34 #include "bindings/core/v8/ScriptSourceCode.h" |
35 #include "bindings/core/v8/V8Binding.h" | 35 #include "bindings/core/v8/V8Binding.h" |
36 #include "bindings/core/v8/V8InspectorOverlayHost.h" | 36 #include "bindings/core/v8/V8InspectorOverlayHost.h" |
| 37 #include "core/dom/DOMNodeIds.h" |
37 #include "core/dom/Node.h" | 38 #include "core/dom/Node.h" |
38 #include "core/dom/StaticNodeList.h" | 39 #include "core/dom/StaticNodeList.h" |
39 #include "core/dom/TaskRunnerHelper.h" | 40 #include "core/dom/TaskRunnerHelper.h" |
40 #include "core/frame/FrameView.h" | 41 #include "core/frame/FrameView.h" |
41 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
42 #include "core/frame/LocalFrameClient.h" | 43 #include "core/frame/LocalFrameClient.h" |
43 #include "core/frame/Settings.h" | 44 #include "core/frame/Settings.h" |
44 #include "core/frame/VisualViewport.h" | 45 #include "core/frame/VisualViewport.h" |
45 #include "core/html/HTMLFrameOwnerElement.h" | 46 #include "core/html/HTMLFrameOwnerElement.h" |
46 #include "core/input/EventHandler.h" | 47 #include "core/input/EventHandler.h" |
| 48 #include "core/inspector/IdentifiersFactory.h" |
| 49 #include "core/inspector/InspectedFrames.h" |
| 50 #include "core/inspector/InspectorDOMAgent.h" |
47 #include "core/inspector/InspectorOverlayHost.h" | 51 #include "core/inspector/InspectorOverlayHost.h" |
48 #include "core/layout/api/LayoutViewItem.h" | 52 #include "core/layout/api/LayoutViewItem.h" |
49 #include "core/loader/EmptyClients.h" | 53 #include "core/loader/EmptyClients.h" |
50 #include "core/loader/FrameLoadRequest.h" | 54 #include "core/loader/FrameLoadRequest.h" |
51 #include "core/page/ChromeClient.h" | 55 #include "core/page/ChromeClient.h" |
52 #include "core/page/Page.h" | 56 #include "core/page/Page.h" |
53 #include "platform/ScriptForbiddenScope.h" | 57 #include "platform/ScriptForbiddenScope.h" |
54 #include "platform/graphics/Color.h" | 58 #include "platform/graphics/Color.h" |
55 #include "platform/graphics/GraphicsContext.h" | 59 #include "platform/graphics/GraphicsContext.h" |
56 #include "platform/graphics/paint/CullRect.h" | 60 #include "platform/graphics/paint/CullRect.h" |
57 #include "platform/wtf/AutoReset.h" | 61 #include "platform/wtf/AutoReset.h" |
58 #include "public/platform/Platform.h" | 62 #include "public/platform/Platform.h" |
59 #include "public/platform/WebData.h" | 63 #include "public/platform/WebData.h" |
60 #include "v8/include/v8.h" | 64 #include "v8/include/v8.h" |
61 #include "web/ChromeClientImpl.h" | 65 #include "web/ChromeClientImpl.h" |
62 #include "web/PageOverlay.h" | 66 #include "web/PageOverlay.h" |
63 #include "web/WebInputEventConversion.h" | 67 #include "web/WebInputEventConversion.h" |
64 #include "web/WebLocalFrameImpl.h" | 68 #include "web/WebLocalFrameImpl.h" |
| 69 #include "web/WebViewImpl.h" |
65 | 70 |
66 namespace blink { | 71 namespace blink { |
67 | 72 |
| 73 using protocol::Maybe; |
| 74 using protocol::Response; |
| 75 |
68 namespace { | 76 namespace { |
69 | 77 |
| 78 namespace OverlayAgentState { |
| 79 static const char kEnabled[] = "enabled"; |
| 80 static const char kShowDebugBorders[] = "showDebugBorders"; |
| 81 static const char kShowFPSCounter[] = "showFPSCounter"; |
| 82 static const char kShowPaintRects[] = "showPaintRects"; |
| 83 static const char kShowScrollBottleneckRects[] = "showScrollBottleneckRects"; |
| 84 static const char kShowSizeOnResize[] = "showSizeOnResize"; |
| 85 static const char kSuspended[] = "suspended"; |
| 86 static const char kPausedInDebuggerMessage[] = "pausedInDebuggerMessage"; |
| 87 } |
| 88 |
70 Node* HoveredNodeForPoint(LocalFrame* frame, | 89 Node* HoveredNodeForPoint(LocalFrame* frame, |
71 const IntPoint& point_in_root_frame, | 90 const IntPoint& point_in_root_frame, |
72 bool ignore_pointer_events_none) { | 91 bool ignore_pointer_events_none) { |
73 HitTestRequest::HitTestRequestType hit_type = | 92 HitTestRequest::HitTestRequestType hit_type = |
74 HitTestRequest::kMove | HitTestRequest::kReadOnly | | 93 HitTestRequest::kMove | HitTestRequest::kReadOnly | |
75 HitTestRequest::kAllowChildFrameContent; | 94 HitTestRequest::kAllowChildFrameContent; |
76 if (ignore_pointer_events_none) | 95 if (ignore_pointer_events_none) |
77 hit_type |= HitTestRequest::kIgnorePointerEventsNone; | 96 hit_type |= HitTestRequest::kIgnorePointerEventsNone; |
78 HitTestRequest request(hit_type); | 97 HitTestRequest request(hit_type); |
79 HitTestResult result(request, | 98 HitTestResult result(request, |
(...skipping 23 matching lines...) Expand all Loading... |
103 | 122 |
104 Node* HoveredNodeForEvent(LocalFrame* frame, | 123 Node* HoveredNodeForEvent(LocalFrame* frame, |
105 const WebTouchEvent& event, | 124 const WebTouchEvent& event, |
106 bool ignore_pointer_events_none) { | 125 bool ignore_pointer_events_none) { |
107 if (!event.touches_length) | 126 if (!event.touches_length) |
108 return nullptr; | 127 return nullptr; |
109 WebTouchPoint transformed_point = event.TouchPointInRootFrame(0); | 128 WebTouchPoint transformed_point = event.TouchPointInRootFrame(0); |
110 return HoveredNodeForPoint(frame, RoundedIntPoint(transformed_point.position), | 129 return HoveredNodeForPoint(frame, RoundedIntPoint(transformed_point.position), |
111 ignore_pointer_events_none); | 130 ignore_pointer_events_none); |
112 } | 131 } |
| 132 |
| 133 bool ParseQuad(std::unique_ptr<protocol::Array<double>> quad_array, |
| 134 FloatQuad* quad) { |
| 135 const size_t kCoordinatesInQuad = 8; |
| 136 if (!quad_array || quad_array->length() != kCoordinatesInQuad) |
| 137 return false; |
| 138 quad->SetP1(FloatPoint(quad_array->get(0), quad_array->get(1))); |
| 139 quad->SetP2(FloatPoint(quad_array->get(2), quad_array->get(3))); |
| 140 quad->SetP3(FloatPoint(quad_array->get(4), quad_array->get(5))); |
| 141 quad->SetP4(FloatPoint(quad_array->get(6), quad_array->get(7))); |
| 142 return true; |
| 143 } |
| 144 |
113 } // namespace | 145 } // namespace |
114 | 146 |
115 class InspectorOverlay::InspectorPageOverlayDelegate final | 147 class InspectorOverlayAgent::InspectorPageOverlayDelegate final |
116 : public PageOverlay::Delegate { | 148 : public PageOverlay::Delegate { |
117 public: | 149 public: |
118 explicit InspectorPageOverlayDelegate(InspectorOverlay& overlay) | 150 explicit InspectorPageOverlayDelegate(InspectorOverlayAgent& overlay) |
119 : overlay_(&overlay) {} | 151 : overlay_(&overlay) {} |
120 | 152 |
121 void PaintPageOverlay(const PageOverlay&, | 153 void PaintPageOverlay(const PageOverlay&, |
122 GraphicsContext& graphics_context, | 154 GraphicsContext& graphics_context, |
123 const WebSize& web_view_size) const override { | 155 const WebSize& web_view_size) const override { |
124 if (overlay_->IsEmpty()) | 156 if (overlay_->IsEmpty()) |
125 return; | 157 return; |
126 | 158 |
127 FrameView* view = overlay_->OverlayMainFrame()->View(); | 159 FrameView* view = overlay_->OverlayMainFrame()->View(); |
128 DCHECK(!view->NeedsLayout()); | 160 DCHECK(!view->NeedsLayout()); |
129 view->Paint(graphics_context, | 161 view->Paint(graphics_context, |
130 CullRect(IntRect(0, 0, view->Width(), view->Height()))); | 162 CullRect(IntRect(0, 0, view->Width(), view->Height()))); |
131 } | 163 } |
132 | 164 |
133 private: | 165 private: |
134 Persistent<InspectorOverlay> overlay_; | 166 Persistent<InspectorOverlayAgent> overlay_; |
135 }; | 167 }; |
136 | 168 |
137 class InspectorOverlay::InspectorOverlayChromeClient final | 169 class InspectorOverlayAgent::InspectorOverlayChromeClient final |
138 : public EmptyChromeClient { | 170 : public EmptyChromeClient { |
139 public: | 171 public: |
140 static InspectorOverlayChromeClient* Create(ChromeClient& client, | 172 static InspectorOverlayChromeClient* Create(ChromeClient& client, |
141 InspectorOverlay& overlay) { | 173 InspectorOverlayAgent& overlay) { |
142 return new InspectorOverlayChromeClient(client, overlay); | 174 return new InspectorOverlayChromeClient(client, overlay); |
143 } | 175 } |
144 | 176 |
145 DEFINE_INLINE_VIRTUAL_TRACE() { | 177 DEFINE_INLINE_VIRTUAL_TRACE() { |
146 visitor->Trace(client_); | 178 visitor->Trace(client_); |
147 visitor->Trace(overlay_); | 179 visitor->Trace(overlay_); |
148 EmptyChromeClient::Trace(visitor); | 180 EmptyChromeClient::Trace(visitor); |
149 } | 181 } |
150 | 182 |
151 void SetCursor(const Cursor& cursor, LocalFrame* local_root) override { | 183 void SetCursor(const Cursor& cursor, LocalFrame* local_root) override { |
(...skipping 13 matching lines...) Expand all Loading... |
165 void InvalidateRect(const IntRect&) override { overlay_->Invalidate(); } | 197 void InvalidateRect(const IntRect&) override { overlay_->Invalidate(); } |
166 | 198 |
167 void ScheduleAnimation(FrameViewBase* frame_view_base) override { | 199 void ScheduleAnimation(FrameViewBase* frame_view_base) override { |
168 if (overlay_->in_layout_) | 200 if (overlay_->in_layout_) |
169 return; | 201 return; |
170 | 202 |
171 client_->ScheduleAnimation(frame_view_base); | 203 client_->ScheduleAnimation(frame_view_base); |
172 } | 204 } |
173 | 205 |
174 private: | 206 private: |
175 InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlay& overlay) | 207 InspectorOverlayChromeClient(ChromeClient& client, |
| 208 InspectorOverlayAgent& overlay) |
176 : client_(&client), overlay_(&overlay) {} | 209 : client_(&client), overlay_(&overlay) {} |
177 | 210 |
178 Member<ChromeClient> client_; | 211 Member<ChromeClient> client_; |
179 Member<InspectorOverlay> overlay_; | 212 Member<InspectorOverlayAgent> overlay_; |
180 }; | 213 }; |
181 | 214 |
182 InspectorOverlay::InspectorOverlay(WebLocalFrameImpl* frame_impl) | 215 InspectorOverlayAgent::InspectorOverlayAgent( |
| 216 WebLocalFrameImpl* frame_impl, |
| 217 InspectedFrames* inspected_frames, |
| 218 v8_inspector::V8InspectorSession* v8_session, |
| 219 InspectorDOMAgent* dom_agent) |
183 : frame_impl_(frame_impl), | 220 : frame_impl_(frame_impl), |
184 overlay_host_(InspectorOverlayHost::Create()), | 221 inspected_frames_(inspected_frames), |
| 222 enabled_(false), |
| 223 overlay_host_(new InspectorOverlayHost(this)), |
185 draw_view_size_(false), | 224 draw_view_size_(false), |
186 resize_timer_active_(false), | 225 resize_timer_active_(false), |
187 omit_tooltip_(false), | 226 omit_tooltip_(false), |
188 timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, | 227 timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, |
189 frame_impl->GetFrame()), | 228 frame_impl->GetFrame()), |
190 this, | 229 this, |
191 &InspectorOverlay::OnTimer), | 230 &InspectorOverlayAgent::OnTimer), |
192 suspended_(false), | 231 suspended_(false), |
193 show_reloading_blanket_(false), | 232 show_reloading_blanket_(false), |
194 in_layout_(false), | 233 in_layout_(false), |
195 needs_update_(false), | 234 needs_update_(false), |
| 235 v8_session_(v8_session), |
| 236 dom_agent_(dom_agent), |
196 swallow_next_mouse_up_(false), | 237 swallow_next_mouse_up_(false), |
197 inspect_mode_(InspectorDOMAgent::kNotSearching) {} | 238 inspect_mode_(kNotSearching), |
| 239 backend_node_id_to_inspect_(0) {} |
198 | 240 |
199 InspectorOverlay::~InspectorOverlay() { | 241 InspectorOverlayAgent::~InspectorOverlayAgent() { |
200 DCHECK(!overlay_page_); | 242 DCHECK(!overlay_page_); |
201 } | 243 } |
202 | 244 |
203 DEFINE_TRACE(InspectorOverlay) { | 245 DEFINE_TRACE(InspectorOverlayAgent) { |
204 visitor->Trace(frame_impl_); | 246 visitor->Trace(frame_impl_); |
| 247 visitor->Trace(inspected_frames_); |
205 visitor->Trace(highlight_node_); | 248 visitor->Trace(highlight_node_); |
206 visitor->Trace(event_target_node_); | 249 visitor->Trace(event_target_node_); |
207 visitor->Trace(overlay_page_); | 250 visitor->Trace(overlay_page_); |
208 visitor->Trace(overlay_chrome_client_); | 251 visitor->Trace(overlay_chrome_client_); |
209 visitor->Trace(overlay_host_); | 252 visitor->Trace(overlay_host_); |
210 visitor->Trace(dom_agent_); | 253 visitor->Trace(dom_agent_); |
211 visitor->Trace(hovered_node_for_inspect_mode_); | 254 visitor->Trace(hovered_node_for_inspect_mode_); |
212 } | 255 InspectorBaseAgent::Trace(visitor); |
213 | 256 } |
214 void InspectorOverlay::Init(v8_inspector::V8InspectorSession* v8_session, | 257 |
215 InspectorDOMAgent* dom_agent) { | 258 void InspectorOverlayAgent::Restore() { |
216 v8_session_ = v8_session; | 259 if (state_->booleanProperty(OverlayAgentState::kEnabled, false)) |
217 dom_agent_ = dom_agent; | 260 enabled_ = true; |
218 overlay_host_->SetListener(this); | 261 setShowDebugBorders( |
219 } | 262 state_->booleanProperty(OverlayAgentState::kShowDebugBorders, false)); |
220 | 263 setShowFPSCounter( |
221 void InspectorOverlay::Invalidate() { | 264 state_->booleanProperty(OverlayAgentState::kShowFPSCounter, false)); |
| 265 setShowPaintRects( |
| 266 state_->booleanProperty(OverlayAgentState::kShowPaintRects, false)); |
| 267 setShowScrollBottleneckRects(state_->booleanProperty( |
| 268 OverlayAgentState::kShowScrollBottleneckRects, false)); |
| 269 setShowViewportSizeOnResize( |
| 270 state_->booleanProperty(OverlayAgentState::kShowSizeOnResize, false)); |
| 271 String message; |
| 272 state_->getString(OverlayAgentState::kPausedInDebuggerMessage, &message); |
| 273 setPausedInDebuggerMessage(message); |
| 274 setSuspended(state_->booleanProperty(OverlayAgentState::kSuspended, false)); |
| 275 } |
| 276 |
| 277 Response InspectorOverlayAgent::enable() { |
| 278 if (!dom_agent_->Enabled()) |
| 279 return Response::Error("DOM should be enabled first"); |
| 280 state_->setBoolean(OverlayAgentState::kEnabled, true); |
| 281 enabled_ = true; |
| 282 if (backend_node_id_to_inspect_) |
| 283 GetFrontend()->inspectNodeRequested(backend_node_id_to_inspect_); |
| 284 backend_node_id_to_inspect_ = 0; |
| 285 return Response::OK(); |
| 286 } |
| 287 |
| 288 Response InspectorOverlayAgent::disable() { |
| 289 state_->setBoolean(OverlayAgentState::kEnabled, false); |
| 290 enabled_ = false; |
| 291 setShowDebugBorders(false); |
| 292 setShowFPSCounter(false); |
| 293 setShowPaintRects(false); |
| 294 setShowScrollBottleneckRects(false); |
| 295 setShowViewportSizeOnResize(false); |
| 296 setPausedInDebuggerMessage(String()); |
| 297 setSuspended(false); |
| 298 SetSearchingForNode(kNotSearching, |
| 299 Maybe<protocol::Overlay::HighlightConfig>()); |
| 300 return Response::OK(); |
| 301 } |
| 302 |
| 303 Response InspectorOverlayAgent::setShowDebugBorders(bool show) { |
| 304 state_->setBoolean(OverlayAgentState::kShowDebugBorders, show); |
| 305 if (show) { |
| 306 Response response = CompositingEnabled(); |
| 307 if (!response.isSuccess()) |
| 308 return response; |
| 309 } |
| 310 frame_impl_->ViewImpl()->SetShowDebugBorders(show); |
| 311 return Response::OK(); |
| 312 } |
| 313 |
| 314 Response InspectorOverlayAgent::setShowFPSCounter(bool show) { |
| 315 state_->setBoolean(OverlayAgentState::kShowFPSCounter, show); |
| 316 if (show) { |
| 317 Response response = CompositingEnabled(); |
| 318 if (!response.isSuccess()) |
| 319 return response; |
| 320 } |
| 321 frame_impl_->ViewImpl()->SetShowFPSCounter(show); |
| 322 return Response::OK(); |
| 323 } |
| 324 |
| 325 Response InspectorOverlayAgent::setShowPaintRects(bool show) { |
| 326 state_->setBoolean(OverlayAgentState::kShowPaintRects, show); |
| 327 if (show) { |
| 328 Response response = CompositingEnabled(); |
| 329 if (!response.isSuccess()) |
| 330 return response; |
| 331 } |
| 332 frame_impl_->ViewImpl()->SetShowPaintRects(show); |
| 333 if (!show && frame_impl_->GetFrameView()) |
| 334 frame_impl_->GetFrameView()->Invalidate(); |
| 335 return Response::OK(); |
| 336 } |
| 337 |
| 338 Response InspectorOverlayAgent::setShowScrollBottleneckRects(bool show) { |
| 339 state_->setBoolean(OverlayAgentState::kShowScrollBottleneckRects, show); |
| 340 if (show) { |
| 341 Response response = CompositingEnabled(); |
| 342 if (!response.isSuccess()) |
| 343 return response; |
| 344 } |
| 345 frame_impl_->ViewImpl()->SetShowScrollBottleneckRects(show); |
| 346 return Response::OK(); |
| 347 } |
| 348 |
| 349 Response InspectorOverlayAgent::setShowViewportSizeOnResize(bool show) { |
| 350 state_->setBoolean(OverlayAgentState::kShowSizeOnResize, show); |
| 351 draw_view_size_ = show; |
| 352 return Response::OK(); |
| 353 } |
| 354 |
| 355 Response InspectorOverlayAgent::setPausedInDebuggerMessage( |
| 356 Maybe<String> message) { |
| 357 String just_message = message.fromMaybe(String()); |
| 358 state_->setString(OverlayAgentState::kPausedInDebuggerMessage, just_message); |
| 359 paused_in_debugger_message_ = just_message; |
| 360 ScheduleUpdate(); |
| 361 return Response::OK(); |
| 362 } |
| 363 |
| 364 Response InspectorOverlayAgent::setSuspended(bool suspended) { |
| 365 state_->setBoolean(OverlayAgentState::kSuspended, suspended); |
| 366 if (suspended && !suspended_ && !show_reloading_blanket_) |
| 367 ClearInternal(); |
| 368 suspended_ = suspended; |
| 369 return Response::OK(); |
| 370 } |
| 371 |
| 372 Response InspectorOverlayAgent::setInspectMode( |
| 373 const String& mode, |
| 374 Maybe<protocol::Overlay::HighlightConfig> highlight_config) { |
| 375 SearchMode search_mode; |
| 376 if (mode == protocol::Overlay::InspectModeEnum::SearchForNode) { |
| 377 search_mode = kSearchingForNormal; |
| 378 } else if (mode == protocol::Overlay::InspectModeEnum::SearchForUAShadowDOM) { |
| 379 search_mode = kSearchingForUAShadow; |
| 380 } else if (mode == protocol::Overlay::InspectModeEnum::None) { |
| 381 search_mode = kNotSearching; |
| 382 } else { |
| 383 return Response::Error( |
| 384 String("Unknown mode \"" + mode + "\" was provided.")); |
| 385 } |
| 386 |
| 387 if (search_mode != kNotSearching) { |
| 388 Response response = dom_agent_->PushDocumentUponHandlelessOperation(); |
| 389 if (!response.isSuccess()) |
| 390 return response; |
| 391 } |
| 392 |
| 393 return SetSearchingForNode(search_mode, std::move(highlight_config)); |
| 394 } |
| 395 |
| 396 Response InspectorOverlayAgent::highlightRect( |
| 397 int x, |
| 398 int y, |
| 399 int width, |
| 400 int height, |
| 401 Maybe<protocol::DOM::RGBA> color, |
| 402 Maybe<protocol::DOM::RGBA> outline_color) { |
| 403 std::unique_ptr<FloatQuad> quad = |
| 404 WTF::WrapUnique(new FloatQuad(FloatRect(x, y, width, height))); |
| 405 InnerHighlightQuad(std::move(quad), std::move(color), |
| 406 std::move(outline_color)); |
| 407 return Response::OK(); |
| 408 } |
| 409 |
| 410 Response InspectorOverlayAgent::highlightQuad( |
| 411 std::unique_ptr<protocol::Array<double>> quad_array, |
| 412 Maybe<protocol::DOM::RGBA> color, |
| 413 Maybe<protocol::DOM::RGBA> outline_color) { |
| 414 std::unique_ptr<FloatQuad> quad = WTF::MakeUnique<FloatQuad>(); |
| 415 if (!ParseQuad(std::move(quad_array), quad.get())) |
| 416 return Response::Error("Invalid Quad format"); |
| 417 InnerHighlightQuad(std::move(quad), std::move(color), |
| 418 std::move(outline_color)); |
| 419 return Response::OK(); |
| 420 } |
| 421 |
| 422 Response InspectorOverlayAgent::highlightNode( |
| 423 std::unique_ptr<protocol::Overlay::HighlightConfig> |
| 424 highlight_inspector_object, |
| 425 Maybe<int> node_id, |
| 426 Maybe<int> backend_node_id, |
| 427 Maybe<String> object_id) { |
| 428 Node* node = nullptr; |
| 429 Response response; |
| 430 if (node_id.isJust()) { |
| 431 response = dom_agent_->AssertNode(node_id.fromJust(), node); |
| 432 } else if (backend_node_id.isJust()) { |
| 433 node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); |
| 434 response = !node ? Response::Error("No node found for given backend id") |
| 435 : Response::OK(); |
| 436 } else if (object_id.isJust()) { |
| 437 response = dom_agent_->NodeForRemoteId(object_id.fromJust(), node); |
| 438 } else { |
| 439 response = Response::Error( |
| 440 "Either nodeId, backendNodeId or objectId must be specified"); |
| 441 } |
| 442 |
| 443 if (!response.isSuccess()) |
| 444 return response; |
| 445 |
| 446 std::unique_ptr<InspectorHighlightConfig> highlight_config; |
| 447 response = HighlightConfigFromInspectorObject( |
| 448 std::move(highlight_inspector_object), &highlight_config); |
| 449 if (!response.isSuccess()) |
| 450 return response; |
| 451 |
| 452 InnerHighlightNode(node, nullptr, *highlight_config, false); |
| 453 return Response::OK(); |
| 454 } |
| 455 |
| 456 Response InspectorOverlayAgent::highlightFrame( |
| 457 const String& frame_id, |
| 458 Maybe<protocol::DOM::RGBA> color, |
| 459 Maybe<protocol::DOM::RGBA> outline_color) { |
| 460 LocalFrame* frame = |
| 461 IdentifiersFactory::FrameById(inspected_frames_, frame_id); |
| 462 // FIXME: Inspector doesn't currently work cross process. |
| 463 if (frame && frame->DeprecatedLocalOwner()) { |
| 464 std::unique_ptr<InspectorHighlightConfig> highlight_config = |
| 465 WTF::MakeUnique<InspectorHighlightConfig>(); |
| 466 highlight_config->show_info = true; // Always show tooltips for frames. |
| 467 highlight_config->content = |
| 468 InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); |
| 469 highlight_config->content_outline = |
| 470 InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); |
| 471 InnerHighlightNode(frame->DeprecatedLocalOwner(), nullptr, |
| 472 *highlight_config, false); |
| 473 } |
| 474 return Response::OK(); |
| 475 } |
| 476 |
| 477 Response InspectorOverlayAgent::hideHighlight() { |
| 478 InnerHideHighlight(); |
| 479 return Response::OK(); |
| 480 } |
| 481 |
| 482 Response InspectorOverlayAgent::getHighlightObjectForTest( |
| 483 int node_id, |
| 484 std::unique_ptr<protocol::DictionaryValue>* result) { |
| 485 Node* node = nullptr; |
| 486 Response response = dom_agent_->AssertNode(node_id, node); |
| 487 if (!response.isSuccess()) |
| 488 return response; |
| 489 InspectorHighlight highlight(node, InspectorHighlight::DefaultConfig(), true); |
| 490 *result = highlight.AsProtocolValue(); |
| 491 return Response::OK(); |
| 492 } |
| 493 |
| 494 void InspectorOverlayAgent::Invalidate() { |
222 if (!page_overlay_) { | 495 if (!page_overlay_) { |
223 page_overlay_ = PageOverlay::Create( | 496 page_overlay_ = PageOverlay::Create( |
224 frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); | 497 frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); |
225 } | 498 } |
226 | 499 |
227 page_overlay_->Update(); | 500 page_overlay_->Update(); |
228 } | 501 } |
229 | 502 |
230 void InspectorOverlay::UpdateAllLifecyclePhases() { | 503 void InspectorOverlayAgent::UpdateAllLifecyclePhases() { |
231 if (IsEmpty()) | 504 if (IsEmpty()) |
232 return; | 505 return; |
233 | 506 |
234 AutoReset<bool> scoped(&in_layout_, true); | 507 AutoReset<bool> scoped(&in_layout_, true); |
235 if (needs_update_) { | 508 if (needs_update_) { |
236 needs_update_ = false; | 509 needs_update_ = false; |
237 RebuildOverlayPage(); | 510 RebuildOverlayPage(); |
238 } | 511 } |
239 OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); | 512 OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); |
240 } | 513 } |
241 | 514 |
242 bool InspectorOverlay::HandleInputEvent(const WebInputEvent& input_event) { | 515 bool InspectorOverlayAgent::HandleInputEvent(const WebInputEvent& input_event) { |
243 bool handled = false; | 516 bool handled = false; |
244 | 517 |
245 if (IsEmpty()) | 518 if (IsEmpty()) |
246 return false; | 519 return false; |
247 | 520 |
248 if (input_event.GetType() == WebInputEvent::kGestureTap) { | 521 if (input_event.GetType() == WebInputEvent::kGestureTap) { |
249 // We only have a use for gesture tap. | 522 // We only have a use for gesture tap. |
250 WebGestureEvent transformed_event = TransformWebGestureEvent( | 523 WebGestureEvent transformed_event = TransformWebGestureEvent( |
251 frame_impl_->GetFrameView(), | 524 frame_impl_->GetFrameView(), |
252 static_cast<const WebGestureEvent&>(input_event)); | 525 static_cast<const WebGestureEvent&>(input_event)); |
(...skipping 18 matching lines...) Expand all Loading... |
271 if (handled) | 544 if (handled) |
272 return true; | 545 return true; |
273 | 546 |
274 if (mouse_event.GetType() == WebInputEvent::kMouseMove) { | 547 if (mouse_event.GetType() == WebInputEvent::kMouseMove) { |
275 handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( | 548 handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( |
276 mouse_event, TransformWebMouseEventVector( | 549 mouse_event, TransformWebMouseEventVector( |
277 frame_impl_->GetFrameView(), | 550 frame_impl_->GetFrameView(), |
278 std::vector<const WebInputEvent*>())) != | 551 std::vector<const WebInputEvent*>())) != |
279 WebInputEventResult::kNotHandled; | 552 WebInputEventResult::kNotHandled; |
280 } | 553 } |
281 if (mouse_event.GetType() == WebInputEvent::kMouseDown) | 554 if (mouse_event.GetType() == WebInputEvent::kMouseDown) { |
282 handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( | 555 handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( |
283 mouse_event) != WebInputEventResult::kNotHandled; | 556 mouse_event) != WebInputEventResult::kNotHandled; |
284 if (mouse_event.GetType() == WebInputEvent::kMouseUp) | 557 } |
| 558 if (mouse_event.GetType() == WebInputEvent::kMouseUp) { |
285 handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( | 559 handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( |
286 mouse_event) != WebInputEventResult::kNotHandled; | 560 mouse_event) != WebInputEventResult::kNotHandled; |
| 561 } |
287 } | 562 } |
288 | 563 |
289 if (WebInputEvent::IsTouchEventType(input_event.GetType())) { | 564 if (WebInputEvent::IsTouchEventType(input_event.GetType())) { |
290 WebTouchEvent transformed_event = | 565 WebTouchEvent transformed_event = |
291 TransformWebTouchEvent(frame_impl_->GetFrameView(), | 566 TransformWebTouchEvent(frame_impl_->GetFrameView(), |
292 static_cast<const WebTouchEvent&>(input_event)); | 567 static_cast<const WebTouchEvent&>(input_event)); |
293 handled = HandleTouchEvent(transformed_event); | 568 handled = HandleTouchEvent(transformed_event); |
294 if (handled) | 569 if (handled) |
295 return true; | 570 return true; |
296 OverlayMainFrame()->GetEventHandler().HandleTouchEvent( | 571 OverlayMainFrame()->GetEventHandler().HandleTouchEvent( |
297 transformed_event, Vector<WebTouchEvent>()); | 572 transformed_event, Vector<WebTouchEvent>()); |
298 } | 573 } |
299 if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { | 574 if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { |
300 OverlayMainFrame()->GetEventHandler().KeyEvent( | 575 OverlayMainFrame()->GetEventHandler().KeyEvent( |
301 static_cast<const WebKeyboardEvent&>(input_event)); | 576 static_cast<const WebKeyboardEvent&>(input_event)); |
302 } | 577 } |
303 | 578 |
304 if (input_event.GetType() == WebInputEvent::kMouseWheel) { | 579 if (input_event.GetType() == WebInputEvent::kMouseWheel) { |
305 WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( | 580 WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( |
306 frame_impl_->GetFrameView(), | 581 frame_impl_->GetFrameView(), |
307 static_cast<const WebMouseWheelEvent&>(input_event)); | 582 static_cast<const WebMouseWheelEvent&>(input_event)); |
308 handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( | 583 handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( |
309 transformed_event) != WebInputEventResult::kNotHandled; | 584 transformed_event) != WebInputEventResult::kNotHandled; |
310 } | 585 } |
311 | 586 |
312 return handled; | 587 return handled; |
313 } | 588 } |
314 | 589 |
315 void InspectorOverlay::SetPausedInDebuggerMessage(const String& message) { | 590 void InspectorOverlayAgent::ShowReloadingBlanket() { |
316 paused_in_debugger_message_ = message; | |
317 ScheduleUpdate(); | |
318 } | |
319 | |
320 void InspectorOverlay::ShowReloadingBlanket() { | |
321 show_reloading_blanket_ = true; | 591 show_reloading_blanket_ = true; |
322 ScheduleUpdate(); | 592 ScheduleUpdate(); |
323 } | 593 } |
324 | 594 |
325 void InspectorOverlay::HideReloadingBlanket() { | 595 void InspectorOverlayAgent::HideReloadingBlanket() { |
326 if (!show_reloading_blanket_) | 596 if (!show_reloading_blanket_) |
327 return; | 597 return; |
328 show_reloading_blanket_ = false; | 598 show_reloading_blanket_ = false; |
329 if (suspended_) | 599 if (suspended_) |
330 ClearInternal(); | 600 ClearInternal(); |
331 else | 601 else |
332 ScheduleUpdate(); | 602 ScheduleUpdate(); |
333 } | 603 } |
334 | 604 |
335 void InspectorOverlay::HideHighlight() { | 605 void InspectorOverlayAgent::InnerHideHighlight() { |
336 highlight_node_.Clear(); | 606 highlight_node_.Clear(); |
337 event_target_node_.Clear(); | 607 event_target_node_.Clear(); |
338 highlight_quad_.reset(); | 608 highlight_quad_.reset(); |
339 ScheduleUpdate(); | 609 ScheduleUpdate(); |
340 } | 610 } |
341 | 611 |
342 void InspectorOverlay::HighlightNode( | 612 void InspectorOverlayAgent::InnerHighlightNode( |
343 Node* node, | |
344 const InspectorHighlightConfig& highlight_config, | |
345 bool omit_tooltip) { | |
346 HighlightNode(node, nullptr, highlight_config, omit_tooltip); | |
347 } | |
348 | |
349 void InspectorOverlay::HighlightNode( | |
350 Node* node, | 613 Node* node, |
351 Node* event_target, | 614 Node* event_target, |
352 const InspectorHighlightConfig& highlight_config, | 615 const InspectorHighlightConfig& highlight_config, |
353 bool omit_tooltip) { | 616 bool omit_tooltip) { |
354 node_highlight_config_ = highlight_config; | 617 node_highlight_config_ = highlight_config; |
355 highlight_node_ = node; | 618 highlight_node_ = node; |
356 event_target_node_ = event_target; | 619 event_target_node_ = event_target; |
357 omit_tooltip_ = omit_tooltip; | 620 omit_tooltip_ = omit_tooltip; |
358 ScheduleUpdate(); | 621 ScheduleUpdate(); |
359 } | 622 } |
360 | 623 |
361 void InspectorOverlay::SetInspectMode( | 624 void InspectorOverlayAgent::InnerHighlightQuad( |
362 InspectorDOMAgent::SearchMode search_mode, | |
363 std::unique_ptr<InspectorHighlightConfig> highlight_config) { | |
364 inspect_mode_ = search_mode; | |
365 ScheduleUpdate(); | |
366 | |
367 if (search_mode != InspectorDOMAgent::kNotSearching) { | |
368 inspect_mode_highlight_config_ = std::move(highlight_config); | |
369 } else { | |
370 hovered_node_for_inspect_mode_.Clear(); | |
371 HideHighlight(); | |
372 } | |
373 } | |
374 | |
375 void InspectorOverlay::HighlightQuad( | |
376 std::unique_ptr<FloatQuad> quad, | 625 std::unique_ptr<FloatQuad> quad, |
377 const InspectorHighlightConfig& highlight_config) { | 626 Maybe<protocol::DOM::RGBA> color, |
378 quad_highlight_config_ = highlight_config; | 627 Maybe<protocol::DOM::RGBA> outline_color) { |
| 628 quad_content_color_ = InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); |
| 629 quad_content_outline_color_ = |
| 630 InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); |
379 highlight_quad_ = std::move(quad); | 631 highlight_quad_ = std::move(quad); |
380 omit_tooltip_ = false; | 632 omit_tooltip_ = false; |
381 ScheduleUpdate(); | 633 ScheduleUpdate(); |
382 } | 634 } |
383 | 635 |
384 bool InspectorOverlay::IsEmpty() { | 636 bool InspectorOverlayAgent::IsEmpty() { |
385 if (show_reloading_blanket_) | 637 if (show_reloading_blanket_) |
386 return false; | 638 return false; |
387 if (suspended_) | 639 if (suspended_) |
388 return true; | 640 return true; |
389 bool has_visible_elements = highlight_node_ || event_target_node_ || | 641 bool has_visible_elements = highlight_node_ || event_target_node_ || |
390 highlight_quad_ || | 642 highlight_quad_ || |
391 (resize_timer_active_ && draw_view_size_) || | 643 (resize_timer_active_ && draw_view_size_) || |
392 !paused_in_debugger_message_.IsNull(); | 644 !paused_in_debugger_message_.IsNull(); |
393 return !has_visible_elements && | 645 return !has_visible_elements && inspect_mode_ == kNotSearching; |
394 inspect_mode_ == InspectorDOMAgent::kNotSearching; | |
395 } | 646 } |
396 | 647 |
397 void InspectorOverlay::ScheduleUpdate() { | 648 void InspectorOverlayAgent::ScheduleUpdate() { |
398 if (IsEmpty()) { | 649 if (IsEmpty()) { |
399 if (page_overlay_) | 650 if (page_overlay_) |
400 page_overlay_.reset(); | 651 page_overlay_.reset(); |
401 return; | 652 return; |
402 } | 653 } |
403 needs_update_ = true; | 654 needs_update_ = true; |
404 FrameView* view = frame_impl_->GetFrameView(); | 655 FrameView* view = frame_impl_->GetFrameView(); |
405 LocalFrame* frame = frame_impl_->GetFrame(); | 656 LocalFrame* frame = frame_impl_->GetFrame(); |
406 if (view && frame) | 657 if (view && frame) |
407 frame->GetPage()->GetChromeClient().ScheduleAnimation(view); | 658 frame->GetPage()->GetChromeClient().ScheduleAnimation(view); |
408 } | 659 } |
409 | 660 |
410 void InspectorOverlay::RebuildOverlayPage() { | 661 void InspectorOverlayAgent::RebuildOverlayPage() { |
411 FrameView* view = frame_impl_->GetFrameView(); | 662 FrameView* view = frame_impl_->GetFrameView(); |
412 LocalFrame* frame = frame_impl_->GetFrame(); | 663 LocalFrame* frame = frame_impl_->GetFrame(); |
413 if (!view || !frame) | 664 if (!view || !frame) |
414 return; | 665 return; |
415 | 666 |
416 IntRect visible_rect_in_document = | 667 IntRect visible_rect_in_document = |
417 view->GetScrollableArea()->VisibleContentRect(); | 668 view->GetScrollableArea()->VisibleContentRect(); |
418 IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); | 669 IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); |
419 OverlayMainFrame()->View()->Resize(viewport_size); | 670 OverlayMainFrame()->View()->Resize(viewport_size); |
420 OverlayPage()->GetVisualViewport().SetSize(viewport_size); | 671 OverlayPage()->GetVisualViewport().SetSize(viewport_size); |
(...skipping 13 matching lines...) Expand all Loading... |
434 | 685 |
435 static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( | 686 static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( |
436 const IntSize& size) { | 687 const IntSize& size) { |
437 std::unique_ptr<protocol::DictionaryValue> result = | 688 std::unique_ptr<protocol::DictionaryValue> result = |
438 protocol::DictionaryValue::create(); | 689 protocol::DictionaryValue::create(); |
439 result->setInteger("width", size.Width()); | 690 result->setInteger("width", size.Width()); |
440 result->setInteger("height", size.Height()); | 691 result->setInteger("height", size.Height()); |
441 return result; | 692 return result; |
442 } | 693 } |
443 | 694 |
444 void InspectorOverlay::DrawNodeHighlight() { | 695 void InspectorOverlayAgent::DrawNodeHighlight() { |
445 if (!highlight_node_) | 696 if (!highlight_node_) |
446 return; | 697 return; |
447 | 698 |
448 String selectors = node_highlight_config_.selector_list; | 699 String selectors = node_highlight_config_.selector_list; |
449 StaticElementList* elements = nullptr; | 700 StaticElementList* elements = nullptr; |
450 DummyExceptionStateForTesting exception_state; | 701 DummyExceptionStateForTesting exception_state; |
451 ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); | 702 ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); |
452 if (!query_base) | 703 if (!query_base) |
453 query_base = highlight_node_->ownerDocument(); | 704 query_base = highlight_node_->ownerDocument(); |
454 if (selectors.length()) | 705 if (selectors.length()) { |
455 elements = | 706 elements = |
456 query_base->QuerySelectorAll(AtomicString(selectors), exception_state); | 707 query_base->QuerySelectorAll(AtomicString(selectors), exception_state); |
| 708 } |
457 if (elements && !exception_state.HadException()) { | 709 if (elements && !exception_state.HadException()) { |
458 for (unsigned i = 0; i < elements->length(); ++i) { | 710 for (unsigned i = 0; i < elements->length(); ++i) { |
459 Element* element = elements->item(i); | 711 Element* element = elements->item(i); |
460 InspectorHighlight highlight(element, node_highlight_config_, false); | 712 InspectorHighlight highlight(element, node_highlight_config_, false); |
461 std::unique_ptr<protocol::DictionaryValue> highlight_json = | 713 std::unique_ptr<protocol::DictionaryValue> highlight_json = |
462 highlight.AsProtocolValue(); | 714 highlight.AsProtocolValue(); |
463 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); | 715 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); |
464 } | 716 } |
465 } | 717 } |
466 | 718 |
467 bool append_element_info = | 719 bool append_element_info = |
468 highlight_node_->IsElementNode() && !omit_tooltip_ && | 720 highlight_node_->IsElementNode() && !omit_tooltip_ && |
469 node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && | 721 node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && |
470 highlight_node_->GetDocument().GetFrame(); | 722 highlight_node_->GetDocument().GetFrame(); |
471 InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, | 723 InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, |
472 append_element_info); | 724 append_element_info); |
473 if (event_target_node_) | 725 if (event_target_node_) { |
474 highlight.AppendEventTargetQuads(event_target_node_.Get(), | 726 highlight.AppendEventTargetQuads(event_target_node_.Get(), |
475 node_highlight_config_); | 727 node_highlight_config_); |
| 728 } |
476 | 729 |
477 std::unique_ptr<protocol::DictionaryValue> highlight_json = | 730 std::unique_ptr<protocol::DictionaryValue> highlight_json = |
478 highlight.AsProtocolValue(); | 731 highlight.AsProtocolValue(); |
479 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); | 732 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); |
480 } | 733 } |
481 | 734 |
482 void InspectorOverlay::DrawQuadHighlight() { | 735 void InspectorOverlayAgent::DrawQuadHighlight() { |
483 if (!highlight_quad_) | 736 if (!highlight_quad_) |
484 return; | 737 return; |
485 | 738 |
486 InspectorHighlight highlight(WindowToViewportScale()); | 739 InspectorHighlight highlight(WindowToViewportScale()); |
487 highlight.AppendQuad(*highlight_quad_, quad_highlight_config_.content, | 740 highlight.AppendQuad(*highlight_quad_, quad_content_color_, |
488 quad_highlight_config_.content_outline); | 741 quad_content_outline_color_); |
489 EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); | 742 EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); |
490 } | 743 } |
491 | 744 |
492 void InspectorOverlay::DrawPausedInDebuggerMessage() { | 745 void InspectorOverlayAgent::DrawPausedInDebuggerMessage() { |
493 if (inspect_mode_ == InspectorDOMAgent::kNotSearching && | 746 if (inspect_mode_ == kNotSearching && !paused_in_debugger_message_.IsNull()) { |
494 !paused_in_debugger_message_.IsNull()) | |
495 EvaluateInOverlay("drawPausedInDebuggerMessage", | 747 EvaluateInOverlay("drawPausedInDebuggerMessage", |
496 paused_in_debugger_message_); | 748 paused_in_debugger_message_); |
| 749 } |
497 } | 750 } |
498 | 751 |
499 void InspectorOverlay::DrawViewSize() { | 752 void InspectorOverlayAgent::DrawViewSize() { |
500 if (resize_timer_active_ && draw_view_size_) | 753 if (resize_timer_active_ && draw_view_size_) |
501 EvaluateInOverlay("drawViewSize", ""); | 754 EvaluateInOverlay("drawViewSize", ""); |
502 } | 755 } |
503 | 756 |
504 float InspectorOverlay::WindowToViewportScale() const { | 757 float InspectorOverlayAgent::WindowToViewportScale() const { |
505 LocalFrame* frame = frame_impl_->GetFrame(); | 758 LocalFrame* frame = frame_impl_->GetFrame(); |
506 if (!frame) | 759 if (!frame) |
507 return 1.0f; | 760 return 1.0f; |
508 return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); | 761 return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); |
509 } | 762 } |
510 | 763 |
511 Page* InspectorOverlay::OverlayPage() { | 764 Page* InspectorOverlayAgent::OverlayPage() { |
512 if (overlay_page_) | 765 if (overlay_page_) |
513 return overlay_page_.Get(); | 766 return overlay_page_.Get(); |
514 | 767 |
515 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 768 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
516 | 769 |
517 DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, | 770 DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, |
518 (EmptyLocalFrameClient::Create())); | 771 (EmptyLocalFrameClient::Create())); |
519 Page::PageClients page_clients; | 772 Page::PageClients page_clients; |
520 FillWithEmptyClients(page_clients); | 773 FillWithEmptyClients(page_clients); |
521 DCHECK(!overlay_chrome_client_); | 774 DCHECK(!overlay_chrome_client_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 EvaluateInOverlay("setPlatform", "windows"); | 834 EvaluateInOverlay("setPlatform", "windows"); |
582 #elif OS(MACOSX) | 835 #elif OS(MACOSX) |
583 EvaluateInOverlay("setPlatform", "mac"); | 836 EvaluateInOverlay("setPlatform", "mac"); |
584 #elif OS(POSIX) | 837 #elif OS(POSIX) |
585 EvaluateInOverlay("setPlatform", "linux"); | 838 EvaluateInOverlay("setPlatform", "linux"); |
586 #endif | 839 #endif |
587 | 840 |
588 return overlay_page_.Get(); | 841 return overlay_page_.Get(); |
589 } | 842 } |
590 | 843 |
591 LocalFrame* InspectorOverlay::OverlayMainFrame() { | 844 LocalFrame* InspectorOverlayAgent::OverlayMainFrame() { |
592 return ToLocalFrame(OverlayPage()->MainFrame()); | 845 return ToLocalFrame(OverlayPage()->MainFrame()); |
593 } | 846 } |
594 | 847 |
595 void InspectorOverlay::Reset(const IntSize& viewport_size, | 848 void InspectorOverlayAgent::Reset(const IntSize& viewport_size, |
596 const IntPoint& document_scroll_offset) { | 849 const IntPoint& document_scroll_offset) { |
597 std::unique_ptr<protocol::DictionaryValue> reset_data = | 850 std::unique_ptr<protocol::DictionaryValue> reset_data = |
598 protocol::DictionaryValue::create(); | 851 protocol::DictionaryValue::create(); |
599 reset_data->setDouble( | 852 reset_data->setDouble( |
600 "deviceScaleFactor", | 853 "deviceScaleFactor", |
601 frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); | 854 frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); |
602 reset_data->setDouble( | 855 reset_data->setDouble( |
603 "pageScaleFactor", | 856 "pageScaleFactor", |
604 frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); | 857 frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); |
605 | 858 |
606 IntRect viewport_in_screen = | 859 IntRect viewport_in_screen = |
607 frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( | 860 frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( |
608 IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); | 861 IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); |
609 reset_data->setObject("viewportSize", | 862 reset_data->setObject("viewportSize", |
610 BuildObjectForSize(viewport_in_screen.Size())); | 863 BuildObjectForSize(viewport_in_screen.Size())); |
611 | 864 |
612 // The zoom factor in the overlay frame already has been multiplied by the | 865 // The zoom factor in the overlay frame already has been multiplied by the |
613 // window to viewport scale (aka device scale factor), so cancel it. | 866 // window to viewport scale (aka device scale factor), so cancel it. |
614 reset_data->setDouble( | 867 reset_data->setDouble( |
615 "pageZoomFactor", | 868 "pageZoomFactor", |
616 frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); | 869 frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); |
617 | 870 |
618 reset_data->setInteger("scrollX", document_scroll_offset.X()); | 871 reset_data->setInteger("scrollX", document_scroll_offset.X()); |
619 reset_data->setInteger("scrollY", document_scroll_offset.Y()); | 872 reset_data->setInteger("scrollY", document_scroll_offset.Y()); |
620 EvaluateInOverlay("reset", std::move(reset_data)); | 873 EvaluateInOverlay("reset", std::move(reset_data)); |
621 } | 874 } |
622 | 875 |
623 void InspectorOverlay::EvaluateInOverlay(const String& method, | 876 void InspectorOverlayAgent::EvaluateInOverlay(const String& method, |
624 const String& argument) { | 877 const String& argument) { |
625 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 878 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
626 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); | 879 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); |
627 command->pushValue(protocol::StringValue::create(method)); | 880 command->pushValue(protocol::StringValue::create(method)); |
628 command->pushValue(protocol::StringValue::create(argument)); | 881 command->pushValue(protocol::StringValue::create(argument)); |
629 ToLocalFrame(OverlayPage()->MainFrame()) | 882 ToLocalFrame(OverlayPage()->MainFrame()) |
630 ->GetScriptController() | 883 ->GetScriptController() |
631 .ExecuteScriptInMainWorld( | 884 .ExecuteScriptInMainWorld( |
632 "dispatch(" + command->serialize() + ")", | 885 "dispatch(" + command->serialize() + ")", |
633 ScriptController::kExecuteScriptWhenScriptsDisabled); | 886 ScriptController::kExecuteScriptWhenScriptsDisabled); |
634 } | 887 } |
635 | 888 |
636 void InspectorOverlay::EvaluateInOverlay( | 889 void InspectorOverlayAgent::EvaluateInOverlay( |
637 const String& method, | 890 const String& method, |
638 std::unique_ptr<protocol::Value> argument) { | 891 std::unique_ptr<protocol::Value> argument) { |
639 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 892 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
640 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); | 893 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); |
641 command->pushValue(protocol::StringValue::create(method)); | 894 command->pushValue(protocol::StringValue::create(method)); |
642 command->pushValue(std::move(argument)); | 895 command->pushValue(std::move(argument)); |
643 ToLocalFrame(OverlayPage()->MainFrame()) | 896 ToLocalFrame(OverlayPage()->MainFrame()) |
644 ->GetScriptController() | 897 ->GetScriptController() |
645 .ExecuteScriptInMainWorld( | 898 .ExecuteScriptInMainWorld( |
646 "dispatch(" + command->serialize() + ")", | 899 "dispatch(" + command->serialize() + ")", |
647 ScriptController::kExecuteScriptWhenScriptsDisabled); | 900 ScriptController::kExecuteScriptWhenScriptsDisabled); |
648 } | 901 } |
649 | 902 |
650 String InspectorOverlay::EvaluateInOverlayForTest(const String& script) { | 903 String InspectorOverlayAgent::EvaluateInOverlayForTest(const String& script) { |
651 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 904 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
652 v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); | 905 v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); |
653 v8::Local<v8::Value> string = | 906 v8::Local<v8::Value> string = |
654 ToLocalFrame(OverlayPage()->MainFrame()) | 907 ToLocalFrame(OverlayPage()->MainFrame()) |
655 ->GetScriptController() | 908 ->GetScriptController() |
656 .ExecuteScriptInMainWorldAndReturnValue( | 909 .ExecuteScriptInMainWorldAndReturnValue( |
657 ScriptSourceCode(script), | 910 ScriptSourceCode(script), |
658 ScriptController::kExecuteScriptWhenScriptsDisabled); | 911 ScriptController::kExecuteScriptWhenScriptsDisabled); |
659 return ToCoreStringWithUndefinedOrNullCheck(string); | 912 return ToCoreStringWithUndefinedOrNullCheck(string); |
660 } | 913 } |
661 | 914 |
662 void InspectorOverlay::OnTimer(TimerBase*) { | 915 void InspectorOverlayAgent::OnTimer(TimerBase*) { |
663 resize_timer_active_ = false; | 916 resize_timer_active_ = false; |
664 ScheduleUpdate(); | 917 ScheduleUpdate(); |
665 } | 918 } |
666 | 919 |
667 void InspectorOverlay::ClearInternal() { | 920 void InspectorOverlayAgent::ClearInternal() { |
668 if (overlay_page_) { | 921 if (overlay_page_) { |
669 overlay_page_->WillBeDestroyed(); | 922 overlay_page_->WillBeDestroyed(); |
670 overlay_page_.Clear(); | 923 overlay_page_.Clear(); |
671 overlay_chrome_client_.Clear(); | 924 overlay_chrome_client_.Clear(); |
672 } | 925 } |
673 resize_timer_active_ = false; | 926 resize_timer_active_ = false; |
674 paused_in_debugger_message_ = String(); | 927 paused_in_debugger_message_ = String(); |
675 inspect_mode_ = InspectorDOMAgent::kNotSearching; | 928 inspect_mode_ = kNotSearching; |
676 timer_.Stop(); | 929 timer_.Stop(); |
677 HideHighlight(); | 930 InnerHideHighlight(); |
678 } | 931 } |
679 | 932 |
680 void InspectorOverlay::Clear() { | 933 void InspectorOverlayAgent::OverlayResumed() { |
681 ClearInternal(); | |
682 v8_session_ = nullptr; | |
683 dom_agent_.Clear(); | |
684 overlay_host_->SetListener(nullptr); | |
685 } | |
686 | |
687 void InspectorOverlay::OverlayResumed() { | |
688 if (v8_session_) | 934 if (v8_session_) |
689 v8_session_->resume(); | 935 v8_session_->resume(); |
690 } | 936 } |
691 | 937 |
692 void InspectorOverlay::OverlaySteppedOver() { | 938 void InspectorOverlayAgent::OverlaySteppedOver() { |
693 if (v8_session_) | 939 if (v8_session_) |
694 v8_session_->stepOver(); | 940 v8_session_->stepOver(); |
695 } | 941 } |
696 | 942 |
697 void InspectorOverlay::Suspend() { | 943 void InspectorOverlayAgent::PageLayoutInvalidated(bool resized) { |
698 if (!suspended_) { | |
699 suspended_ = true; | |
700 ClearInternal(); | |
701 } | |
702 } | |
703 | |
704 void InspectorOverlay::Resume() { | |
705 suspended_ = false; | |
706 } | |
707 | |
708 void InspectorOverlay::PageLayoutInvalidated(bool resized) { | |
709 if (resized && draw_view_size_) { | 944 if (resized && draw_view_size_) { |
710 resize_timer_active_ = true; | 945 resize_timer_active_ = true; |
711 timer_.StartOneShot(1, BLINK_FROM_HERE); | 946 timer_.StartOneShot(1, BLINK_FROM_HERE); |
712 } | 947 } |
713 ScheduleUpdate(); | 948 ScheduleUpdate(); |
714 } | 949 } |
715 | 950 |
716 void InspectorOverlay::SetShowViewportSizeOnResize(bool show) { | 951 bool InspectorOverlayAgent::HandleMouseMove(const WebMouseEvent& event) { |
717 draw_view_size_ = show; | |
718 } | |
719 | |
720 bool InspectorOverlay::HandleMouseMove(const WebMouseEvent& event) { | |
721 if (!ShouldSearchForNode()) | 952 if (!ShouldSearchForNode()) |
722 return false; | 953 return false; |
723 | 954 |
724 LocalFrame* frame = frame_impl_->GetFrame(); | 955 LocalFrame* frame = frame_impl_->GetFrame(); |
725 if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) | 956 if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) |
726 return false; | 957 return false; |
727 Node* node = HoveredNodeForEvent( | 958 Node* node = HoveredNodeForEvent( |
728 frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); | 959 frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); |
729 | 960 |
730 // Do not highlight within user agent shadow root unless requested. | 961 // Do not highlight within user agent shadow root unless requested. |
731 if (inspect_mode_ != InspectorDOMAgent::kSearchingForUAShadow) { | 962 if (inspect_mode_ != kSearchingForUAShadow) { |
732 ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); | 963 ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); |
733 if (shadow_root) | 964 if (shadow_root) |
734 node = &shadow_root->host(); | 965 node = &shadow_root->host(); |
735 } | 966 } |
736 | 967 |
737 // Shadow roots don't have boxes - use host element instead. | 968 // Shadow roots don't have boxes - use host element instead. |
738 if (node && node->IsShadowRoot()) | 969 if (node && node->IsShadowRoot()) |
739 node = node->ParentOrShadowHostNode(); | 970 node = node->ParentOrShadowHostNode(); |
740 | 971 |
741 if (!node) | 972 if (!node) |
742 return true; | 973 return true; |
743 | 974 |
744 if (node->IsFrameOwnerElement()) { | 975 if (node->IsFrameOwnerElement()) { |
745 HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); | 976 HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); |
746 if (frame_owner->ContentFrame() && | 977 if (frame_owner->ContentFrame() && |
747 !frame_owner->ContentFrame()->IsLocalFrame()) { | 978 !frame_owner->ContentFrame()->IsLocalFrame()) { |
748 // Do not consume event so that remote frame can handle it. | 979 // Do not consume event so that remote frame can handle it. |
749 HideHighlight(); | 980 InnerHideHighlight(); |
750 hovered_node_for_inspect_mode_.Clear(); | 981 hovered_node_for_inspect_mode_.Clear(); |
751 return false; | 982 return false; |
752 } | 983 } |
753 } | 984 } |
754 | 985 |
755 Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) | 986 Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) |
756 ? HoveredNodeForEvent(frame, event, false) | 987 ? HoveredNodeForEvent(frame, event, false) |
757 : nullptr; | 988 : nullptr; |
758 if (event_target == node) | 989 if (event_target == node) |
759 event_target = nullptr; | 990 event_target = nullptr; |
760 | 991 |
761 if (node && inspect_mode_highlight_config_) { | 992 if (node && inspect_mode_highlight_config_) { |
762 hovered_node_for_inspect_mode_ = node; | 993 hovered_node_for_inspect_mode_ = node; |
763 if (dom_agent_) | 994 NodeHighlightRequested(node); |
764 dom_agent_->NodeHighlightedInOverlay(node); | 995 bool omit_tooltip = event.GetModifiers() & |
765 HighlightNode(node, event_target, *inspect_mode_highlight_config_, | 996 (WebInputEvent::kControlKey | WebInputEvent::kMetaKey); |
766 (event.GetModifiers() & | 997 InnerHighlightNode(node, event_target, *inspect_mode_highlight_config_, |
767 (WebInputEvent::kControlKey | WebInputEvent::kMetaKey))); | 998 omit_tooltip); |
768 } | 999 } |
769 return true; | 1000 return true; |
770 } | 1001 } |
771 | 1002 |
772 bool InspectorOverlay::HandleMouseDown() { | 1003 bool InspectorOverlayAgent::HandleMouseDown() { |
773 swallow_next_mouse_up_ = false; | 1004 swallow_next_mouse_up_ = false; |
774 if (!ShouldSearchForNode()) | 1005 if (!ShouldSearchForNode()) |
775 return false; | 1006 return false; |
776 | 1007 |
777 if (hovered_node_for_inspect_mode_) { | 1008 if (hovered_node_for_inspect_mode_) { |
778 swallow_next_mouse_up_ = true; | 1009 swallow_next_mouse_up_ = true; |
779 Inspect(hovered_node_for_inspect_mode_.Get()); | 1010 Inspect(hovered_node_for_inspect_mode_.Get()); |
780 hovered_node_for_inspect_mode_.Clear(); | 1011 hovered_node_for_inspect_mode_.Clear(); |
781 return true; | 1012 return true; |
782 } | 1013 } |
783 return false; | 1014 return false; |
784 } | 1015 } |
785 | 1016 |
786 bool InspectorOverlay::HandleMouseUp() { | 1017 bool InspectorOverlayAgent::HandleMouseUp() { |
787 if (swallow_next_mouse_up_) { | 1018 if (swallow_next_mouse_up_) { |
788 swallow_next_mouse_up_ = false; | 1019 swallow_next_mouse_up_ = false; |
789 return true; | 1020 return true; |
790 } | 1021 } |
791 return false; | 1022 return false; |
792 } | 1023 } |
793 | 1024 |
794 bool InspectorOverlay::HandleGestureEvent(const WebGestureEvent& event) { | 1025 bool InspectorOverlayAgent::HandleGestureEvent(const WebGestureEvent& event) { |
795 if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) | 1026 if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) |
796 return false; | 1027 return false; |
797 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); | 1028 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); |
798 if (node && inspect_mode_highlight_config_) { | 1029 if (node && inspect_mode_highlight_config_) { |
799 HighlightNode(node, *inspect_mode_highlight_config_, false); | 1030 InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); |
800 Inspect(node); | 1031 Inspect(node); |
801 return true; | 1032 return true; |
802 } | 1033 } |
803 return false; | 1034 return false; |
804 } | 1035 } |
805 | 1036 |
806 bool InspectorOverlay::HandleTouchEvent(const WebTouchEvent& event) { | 1037 bool InspectorOverlayAgent::HandleTouchEvent(const WebTouchEvent& event) { |
807 if (!ShouldSearchForNode()) | 1038 if (!ShouldSearchForNode()) |
808 return false; | 1039 return false; |
809 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); | 1040 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); |
810 if (node && inspect_mode_highlight_config_) { | 1041 if (node && inspect_mode_highlight_config_) { |
811 HighlightNode(node, *inspect_mode_highlight_config_, false); | 1042 InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); |
812 Inspect(node); | 1043 Inspect(node); |
813 return true; | 1044 return true; |
814 } | 1045 } |
815 return false; | 1046 return false; |
816 } | 1047 } |
817 | 1048 |
818 bool InspectorOverlay::ShouldSearchForNode() { | 1049 Response InspectorOverlayAgent::CompositingEnabled() { |
819 return inspect_mode_ != InspectorDOMAgent::kNotSearching; | 1050 bool main_frame = frame_impl_->ViewImpl() && !frame_impl_->Parent(); |
| 1051 if (!main_frame || !frame_impl_->ViewImpl() |
| 1052 ->GetPage() |
| 1053 ->GetSettings() |
| 1054 .GetAcceleratedCompositingEnabled()) |
| 1055 return Response::Error("Compositing mode is not supported"); |
| 1056 return Response::OK(); |
820 } | 1057 } |
821 | 1058 |
822 void InspectorOverlay::Inspect(Node* node) { | 1059 bool InspectorOverlayAgent::ShouldSearchForNode() { |
823 if (dom_agent_) | 1060 return inspect_mode_ != kNotSearching; |
824 dom_agent_->Inspect(node); | 1061 } |
| 1062 |
| 1063 void InspectorOverlayAgent::Inspect(Node* inspected_node) { |
| 1064 if (!inspected_node) |
| 1065 return; |
| 1066 |
| 1067 Node* node = inspected_node; |
| 1068 while (node && !node->IsElementNode() && !node->IsDocumentNode() && |
| 1069 !node->IsDocumentFragment()) |
| 1070 node = node->ParentOrShadowHostNode(); |
| 1071 if (!node) |
| 1072 return; |
| 1073 |
| 1074 int backend_node_id = DOMNodeIds::IdForNode(node); |
| 1075 if (!enabled_) { |
| 1076 backend_node_id_to_inspect_ = backend_node_id; |
| 1077 return; |
| 1078 } |
| 1079 |
| 1080 GetFrontend()->inspectNodeRequested(backend_node_id); |
| 1081 } |
| 1082 |
| 1083 void InspectorOverlayAgent::NodeHighlightRequested(Node* node) { |
| 1084 if (!enabled_) |
| 1085 return; |
| 1086 |
| 1087 while (node && !node->IsElementNode() && !node->IsDocumentNode() && |
| 1088 !node->IsDocumentFragment()) |
| 1089 node = node->ParentOrShadowHostNode(); |
| 1090 |
| 1091 if (!node) |
| 1092 return; |
| 1093 |
| 1094 int node_id = dom_agent_->PushNodePathToFrontend(node); |
| 1095 GetFrontend()->nodeHighlightRequested(node_id); |
| 1096 } |
| 1097 |
| 1098 Response InspectorOverlayAgent::SetSearchingForNode( |
| 1099 SearchMode search_mode, |
| 1100 Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object) { |
| 1101 if (search_mode == kNotSearching) { |
| 1102 inspect_mode_ = search_mode; |
| 1103 ScheduleUpdate(); |
| 1104 hovered_node_for_inspect_mode_.Clear(); |
| 1105 InnerHideHighlight(); |
| 1106 return Response::OK(); |
| 1107 } |
| 1108 |
| 1109 std::unique_ptr<InspectorHighlightConfig> config; |
| 1110 Response response = HighlightConfigFromInspectorObject( |
| 1111 std::move(highlight_inspector_object), &config); |
| 1112 if (!response.isSuccess()) |
| 1113 return response; |
| 1114 inspect_mode_ = search_mode; |
| 1115 inspect_mode_highlight_config_ = std::move(config); |
| 1116 ScheduleUpdate(); |
| 1117 return Response::OK(); |
| 1118 } |
| 1119 |
| 1120 Response InspectorOverlayAgent::HighlightConfigFromInspectorObject( |
| 1121 Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object, |
| 1122 std::unique_ptr<InspectorHighlightConfig>* out_config) { |
| 1123 if (!highlight_inspector_object.isJust()) { |
| 1124 return Response::Error( |
| 1125 "Internal error: highlight configuration parameter is missing"); |
| 1126 } |
| 1127 |
| 1128 protocol::Overlay::HighlightConfig* config = |
| 1129 highlight_inspector_object.fromJust(); |
| 1130 std::unique_ptr<InspectorHighlightConfig> highlight_config = |
| 1131 WTF::MakeUnique<InspectorHighlightConfig>(); |
| 1132 highlight_config->show_info = config->getShowInfo(false); |
| 1133 highlight_config->show_rulers = config->getShowRulers(false); |
| 1134 highlight_config->show_extension_lines = config->getShowExtensionLines(false); |
| 1135 highlight_config->display_as_material = config->getDisplayAsMaterial(false); |
| 1136 highlight_config->content = |
| 1137 InspectorDOMAgent::ParseColor(config->getContentColor(nullptr)); |
| 1138 highlight_config->padding = |
| 1139 InspectorDOMAgent::ParseColor(config->getPaddingColor(nullptr)); |
| 1140 highlight_config->border = |
| 1141 InspectorDOMAgent::ParseColor(config->getBorderColor(nullptr)); |
| 1142 highlight_config->margin = |
| 1143 InspectorDOMAgent::ParseColor(config->getMarginColor(nullptr)); |
| 1144 highlight_config->event_target = |
| 1145 InspectorDOMAgent::ParseColor(config->getEventTargetColor(nullptr)); |
| 1146 highlight_config->shape = |
| 1147 InspectorDOMAgent::ParseColor(config->getShapeColor(nullptr)); |
| 1148 highlight_config->shape_margin = |
| 1149 InspectorDOMAgent::ParseColor(config->getShapeMarginColor(nullptr)); |
| 1150 highlight_config->selector_list = config->getSelectorList(""); |
| 1151 |
| 1152 *out_config = std::move(highlight_config); |
| 1153 return Response::OK(); |
825 } | 1154 } |
826 | 1155 |
827 } // namespace blink | 1156 } // namespace blink |
OLD | NEW |