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(LocalFrame* frame) override { | 199 void ScheduleAnimation(LocalFrame* frame) override { |
168 if (overlay_->in_layout_) | 200 if (overlay_->in_layout_) |
169 return; | 201 return; |
170 | 202 |
171 client_->ScheduleAnimation(frame); | 203 client_->ScheduleAnimation(frame); |
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 void InspectorOverlayAgent::Dispose() { |
| 278 show_reloading_blanket_ = false; |
| 279 ClearInternal(); |
| 280 InspectorBaseAgent::Dispose(); |
| 281 } |
| 282 |
| 283 Response InspectorOverlayAgent::enable() { |
| 284 if (!dom_agent_->Enabled()) |
| 285 return Response::Error("DOM should be enabled first"); |
| 286 state_->setBoolean(OverlayAgentState::kEnabled, true); |
| 287 enabled_ = true; |
| 288 if (backend_node_id_to_inspect_) |
| 289 GetFrontend()->inspectNodeRequested(backend_node_id_to_inspect_); |
| 290 backend_node_id_to_inspect_ = 0; |
| 291 return Response::OK(); |
| 292 } |
| 293 |
| 294 Response InspectorOverlayAgent::disable() { |
| 295 state_->setBoolean(OverlayAgentState::kEnabled, false); |
| 296 enabled_ = false; |
| 297 setShowDebugBorders(false); |
| 298 setShowFPSCounter(false); |
| 299 setShowPaintRects(false); |
| 300 setShowScrollBottleneckRects(false); |
| 301 setShowViewportSizeOnResize(false); |
| 302 setPausedInDebuggerMessage(String()); |
| 303 setSuspended(false); |
| 304 SetSearchingForNode(kNotSearching, |
| 305 Maybe<protocol::Overlay::HighlightConfig>()); |
| 306 return Response::OK(); |
| 307 } |
| 308 |
| 309 Response InspectorOverlayAgent::setShowDebugBorders(bool show) { |
| 310 state_->setBoolean(OverlayAgentState::kShowDebugBorders, show); |
| 311 if (show) { |
| 312 Response response = CompositingEnabled(); |
| 313 if (!response.isSuccess()) |
| 314 return response; |
| 315 } |
| 316 frame_impl_->ViewImpl()->SetShowDebugBorders(show); |
| 317 return Response::OK(); |
| 318 } |
| 319 |
| 320 Response InspectorOverlayAgent::setShowFPSCounter(bool show) { |
| 321 state_->setBoolean(OverlayAgentState::kShowFPSCounter, show); |
| 322 if (show) { |
| 323 Response response = CompositingEnabled(); |
| 324 if (!response.isSuccess()) |
| 325 return response; |
| 326 } |
| 327 frame_impl_->ViewImpl()->SetShowFPSCounter(show); |
| 328 return Response::OK(); |
| 329 } |
| 330 |
| 331 Response InspectorOverlayAgent::setShowPaintRects(bool show) { |
| 332 state_->setBoolean(OverlayAgentState::kShowPaintRects, show); |
| 333 if (show) { |
| 334 Response response = CompositingEnabled(); |
| 335 if (!response.isSuccess()) |
| 336 return response; |
| 337 } |
| 338 frame_impl_->ViewImpl()->SetShowPaintRects(show); |
| 339 if (!show && frame_impl_->GetFrameView()) |
| 340 frame_impl_->GetFrameView()->Invalidate(); |
| 341 return Response::OK(); |
| 342 } |
| 343 |
| 344 Response InspectorOverlayAgent::setShowScrollBottleneckRects(bool show) { |
| 345 state_->setBoolean(OverlayAgentState::kShowScrollBottleneckRects, show); |
| 346 if (show) { |
| 347 Response response = CompositingEnabled(); |
| 348 if (!response.isSuccess()) |
| 349 return response; |
| 350 } |
| 351 frame_impl_->ViewImpl()->SetShowScrollBottleneckRects(show); |
| 352 return Response::OK(); |
| 353 } |
| 354 |
| 355 Response InspectorOverlayAgent::setShowViewportSizeOnResize(bool show) { |
| 356 state_->setBoolean(OverlayAgentState::kShowSizeOnResize, show); |
| 357 draw_view_size_ = show; |
| 358 return Response::OK(); |
| 359 } |
| 360 |
| 361 Response InspectorOverlayAgent::setPausedInDebuggerMessage( |
| 362 Maybe<String> message) { |
| 363 String just_message = message.fromMaybe(String()); |
| 364 state_->setString(OverlayAgentState::kPausedInDebuggerMessage, just_message); |
| 365 paused_in_debugger_message_ = just_message; |
| 366 ScheduleUpdate(); |
| 367 return Response::OK(); |
| 368 } |
| 369 |
| 370 Response InspectorOverlayAgent::setSuspended(bool suspended) { |
| 371 state_->setBoolean(OverlayAgentState::kSuspended, suspended); |
| 372 if (suspended && !suspended_ && !show_reloading_blanket_) |
| 373 ClearInternal(); |
| 374 suspended_ = suspended; |
| 375 return Response::OK(); |
| 376 } |
| 377 |
| 378 Response InspectorOverlayAgent::setInspectMode( |
| 379 const String& mode, |
| 380 Maybe<protocol::Overlay::HighlightConfig> highlight_config) { |
| 381 SearchMode search_mode; |
| 382 if (mode == protocol::Overlay::InspectModeEnum::SearchForNode) { |
| 383 search_mode = kSearchingForNormal; |
| 384 } else if (mode == protocol::Overlay::InspectModeEnum::SearchForUAShadowDOM) { |
| 385 search_mode = kSearchingForUAShadow; |
| 386 } else if (mode == protocol::Overlay::InspectModeEnum::None) { |
| 387 search_mode = kNotSearching; |
| 388 } else { |
| 389 return Response::Error( |
| 390 String("Unknown mode \"" + mode + "\" was provided.")); |
| 391 } |
| 392 |
| 393 if (search_mode != kNotSearching) { |
| 394 Response response = dom_agent_->PushDocumentUponHandlelessOperation(); |
| 395 if (!response.isSuccess()) |
| 396 return response; |
| 397 } |
| 398 |
| 399 return SetSearchingForNode(search_mode, std::move(highlight_config)); |
| 400 } |
| 401 |
| 402 Response InspectorOverlayAgent::highlightRect( |
| 403 int x, |
| 404 int y, |
| 405 int width, |
| 406 int height, |
| 407 Maybe<protocol::DOM::RGBA> color, |
| 408 Maybe<protocol::DOM::RGBA> outline_color) { |
| 409 std::unique_ptr<FloatQuad> quad = |
| 410 WTF::WrapUnique(new FloatQuad(FloatRect(x, y, width, height))); |
| 411 InnerHighlightQuad(std::move(quad), std::move(color), |
| 412 std::move(outline_color)); |
| 413 return Response::OK(); |
| 414 } |
| 415 |
| 416 Response InspectorOverlayAgent::highlightQuad( |
| 417 std::unique_ptr<protocol::Array<double>> quad_array, |
| 418 Maybe<protocol::DOM::RGBA> color, |
| 419 Maybe<protocol::DOM::RGBA> outline_color) { |
| 420 std::unique_ptr<FloatQuad> quad = WTF::MakeUnique<FloatQuad>(); |
| 421 if (!ParseQuad(std::move(quad_array), quad.get())) |
| 422 return Response::Error("Invalid Quad format"); |
| 423 InnerHighlightQuad(std::move(quad), std::move(color), |
| 424 std::move(outline_color)); |
| 425 return Response::OK(); |
| 426 } |
| 427 |
| 428 Response InspectorOverlayAgent::highlightNode( |
| 429 std::unique_ptr<protocol::Overlay::HighlightConfig> |
| 430 highlight_inspector_object, |
| 431 Maybe<int> node_id, |
| 432 Maybe<int> backend_node_id, |
| 433 Maybe<String> object_id) { |
| 434 Node* node = nullptr; |
| 435 Response response; |
| 436 if (node_id.isJust()) { |
| 437 response = dom_agent_->AssertNode(node_id.fromJust(), node); |
| 438 } else if (backend_node_id.isJust()) { |
| 439 node = DOMNodeIds::NodeForId(backend_node_id.fromJust()); |
| 440 response = !node ? Response::Error("No node found for given backend id") |
| 441 : Response::OK(); |
| 442 } else if (object_id.isJust()) { |
| 443 response = dom_agent_->NodeForRemoteObjectId(object_id.fromJust(), node); |
| 444 } else { |
| 445 response = Response::Error( |
| 446 "Either nodeId, backendNodeId or objectId must be specified"); |
| 447 } |
| 448 |
| 449 if (!response.isSuccess()) |
| 450 return response; |
| 451 |
| 452 std::unique_ptr<InspectorHighlightConfig> highlight_config; |
| 453 response = HighlightConfigFromInspectorObject( |
| 454 std::move(highlight_inspector_object), &highlight_config); |
| 455 if (!response.isSuccess()) |
| 456 return response; |
| 457 |
| 458 InnerHighlightNode(node, nullptr, *highlight_config, false); |
| 459 return Response::OK(); |
| 460 } |
| 461 |
| 462 Response InspectorOverlayAgent::highlightFrame( |
| 463 const String& frame_id, |
| 464 Maybe<protocol::DOM::RGBA> color, |
| 465 Maybe<protocol::DOM::RGBA> outline_color) { |
| 466 LocalFrame* frame = |
| 467 IdentifiersFactory::FrameById(inspected_frames_, frame_id); |
| 468 // FIXME: Inspector doesn't currently work cross process. |
| 469 if (frame && frame->DeprecatedLocalOwner()) { |
| 470 std::unique_ptr<InspectorHighlightConfig> highlight_config = |
| 471 WTF::MakeUnique<InspectorHighlightConfig>(); |
| 472 highlight_config->show_info = true; // Always show tooltips for frames. |
| 473 highlight_config->content = |
| 474 InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); |
| 475 highlight_config->content_outline = |
| 476 InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); |
| 477 InnerHighlightNode(frame->DeprecatedLocalOwner(), nullptr, |
| 478 *highlight_config, false); |
| 479 } |
| 480 return Response::OK(); |
| 481 } |
| 482 |
| 483 Response InspectorOverlayAgent::hideHighlight() { |
| 484 InnerHideHighlight(); |
| 485 return Response::OK(); |
| 486 } |
| 487 |
| 488 Response InspectorOverlayAgent::getHighlightObjectForTest( |
| 489 int node_id, |
| 490 std::unique_ptr<protocol::DictionaryValue>* result) { |
| 491 Node* node = nullptr; |
| 492 Response response = dom_agent_->AssertNode(node_id, node); |
| 493 if (!response.isSuccess()) |
| 494 return response; |
| 495 InspectorHighlight highlight(node, InspectorHighlight::DefaultConfig(), true); |
| 496 *result = highlight.AsProtocolValue(); |
| 497 return Response::OK(); |
| 498 } |
| 499 |
| 500 void InspectorOverlayAgent::Invalidate() { |
222 if (!page_overlay_) { | 501 if (!page_overlay_) { |
223 page_overlay_ = PageOverlay::Create( | 502 page_overlay_ = PageOverlay::Create( |
224 frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); | 503 frame_impl_, WTF::WrapUnique(new InspectorPageOverlayDelegate(*this))); |
225 } | 504 } |
226 | 505 |
227 page_overlay_->Update(); | 506 page_overlay_->Update(); |
228 } | 507 } |
229 | 508 |
230 void InspectorOverlay::UpdateAllLifecyclePhases() { | 509 void InspectorOverlayAgent::UpdateAllLifecyclePhases() { |
231 if (IsEmpty()) | 510 if (IsEmpty()) |
232 return; | 511 return; |
233 | 512 |
234 AutoReset<bool> scoped(&in_layout_, true); | 513 AutoReset<bool> scoped(&in_layout_, true); |
235 if (needs_update_) { | 514 if (needs_update_) { |
236 needs_update_ = false; | 515 needs_update_ = false; |
237 RebuildOverlayPage(); | 516 RebuildOverlayPage(); |
238 } | 517 } |
239 OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); | 518 OverlayMainFrame()->View()->UpdateAllLifecyclePhases(); |
240 } | 519 } |
241 | 520 |
242 bool InspectorOverlay::HandleInputEvent(const WebInputEvent& input_event) { | 521 bool InspectorOverlayAgent::HandleInputEvent(const WebInputEvent& input_event) { |
243 bool handled = false; | 522 bool handled = false; |
244 | 523 |
245 if (IsEmpty()) | 524 if (IsEmpty()) |
246 return false; | 525 return false; |
247 | 526 |
248 if (input_event.GetType() == WebInputEvent::kGestureTap) { | 527 if (input_event.GetType() == WebInputEvent::kGestureTap) { |
249 // We only have a use for gesture tap. | 528 // We only have a use for gesture tap. |
250 WebGestureEvent transformed_event = TransformWebGestureEvent( | 529 WebGestureEvent transformed_event = TransformWebGestureEvent( |
251 frame_impl_->GetFrameView(), | 530 frame_impl_->GetFrameView(), |
252 static_cast<const WebGestureEvent&>(input_event)); | 531 static_cast<const WebGestureEvent&>(input_event)); |
(...skipping 18 matching lines...) Expand all Loading... |
271 if (handled) | 550 if (handled) |
272 return true; | 551 return true; |
273 | 552 |
274 if (mouse_event.GetType() == WebInputEvent::kMouseMove) { | 553 if (mouse_event.GetType() == WebInputEvent::kMouseMove) { |
275 handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( | 554 handled = OverlayMainFrame()->GetEventHandler().HandleMouseMoveEvent( |
276 mouse_event, TransformWebMouseEventVector( | 555 mouse_event, TransformWebMouseEventVector( |
277 frame_impl_->GetFrameView(), | 556 frame_impl_->GetFrameView(), |
278 std::vector<const WebInputEvent*>())) != | 557 std::vector<const WebInputEvent*>())) != |
279 WebInputEventResult::kNotHandled; | 558 WebInputEventResult::kNotHandled; |
280 } | 559 } |
281 if (mouse_event.GetType() == WebInputEvent::kMouseDown) | 560 if (mouse_event.GetType() == WebInputEvent::kMouseDown) { |
282 handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( | 561 handled = OverlayMainFrame()->GetEventHandler().HandleMousePressEvent( |
283 mouse_event) != WebInputEventResult::kNotHandled; | 562 mouse_event) != WebInputEventResult::kNotHandled; |
284 if (mouse_event.GetType() == WebInputEvent::kMouseUp) | 563 } |
| 564 if (mouse_event.GetType() == WebInputEvent::kMouseUp) { |
285 handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( | 565 handled = OverlayMainFrame()->GetEventHandler().HandleMouseReleaseEvent( |
286 mouse_event) != WebInputEventResult::kNotHandled; | 566 mouse_event) != WebInputEventResult::kNotHandled; |
| 567 } |
287 } | 568 } |
288 | 569 |
289 if (WebInputEvent::IsTouchEventType(input_event.GetType())) { | 570 if (WebInputEvent::IsTouchEventType(input_event.GetType())) { |
290 WebTouchEvent transformed_event = | 571 WebTouchEvent transformed_event = |
291 TransformWebTouchEvent(frame_impl_->GetFrameView(), | 572 TransformWebTouchEvent(frame_impl_->GetFrameView(), |
292 static_cast<const WebTouchEvent&>(input_event)); | 573 static_cast<const WebTouchEvent&>(input_event)); |
293 handled = HandleTouchEvent(transformed_event); | 574 handled = HandleTouchEvent(transformed_event); |
294 if (handled) | 575 if (handled) |
295 return true; | 576 return true; |
296 OverlayMainFrame()->GetEventHandler().HandleTouchEvent( | 577 OverlayMainFrame()->GetEventHandler().HandleTouchEvent( |
297 transformed_event, Vector<WebTouchEvent>()); | 578 transformed_event, Vector<WebTouchEvent>()); |
298 } | 579 } |
299 if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { | 580 if (WebInputEvent::IsKeyboardEventType(input_event.GetType())) { |
300 OverlayMainFrame()->GetEventHandler().KeyEvent( | 581 OverlayMainFrame()->GetEventHandler().KeyEvent( |
301 static_cast<const WebKeyboardEvent&>(input_event)); | 582 static_cast<const WebKeyboardEvent&>(input_event)); |
302 } | 583 } |
303 | 584 |
304 if (input_event.GetType() == WebInputEvent::kMouseWheel) { | 585 if (input_event.GetType() == WebInputEvent::kMouseWheel) { |
305 WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( | 586 WebMouseWheelEvent transformed_event = TransformWebMouseWheelEvent( |
306 frame_impl_->GetFrameView(), | 587 frame_impl_->GetFrameView(), |
307 static_cast<const WebMouseWheelEvent&>(input_event)); | 588 static_cast<const WebMouseWheelEvent&>(input_event)); |
308 handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( | 589 handled = OverlayMainFrame()->GetEventHandler().HandleWheelEvent( |
309 transformed_event) != WebInputEventResult::kNotHandled; | 590 transformed_event) != WebInputEventResult::kNotHandled; |
310 } | 591 } |
311 | 592 |
312 return handled; | 593 return handled; |
313 } | 594 } |
314 | 595 |
315 void InspectorOverlay::SetPausedInDebuggerMessage(const String& message) { | 596 void InspectorOverlayAgent::ShowReloadingBlanket() { |
316 paused_in_debugger_message_ = message; | |
317 ScheduleUpdate(); | |
318 } | |
319 | |
320 void InspectorOverlay::ShowReloadingBlanket() { | |
321 show_reloading_blanket_ = true; | 597 show_reloading_blanket_ = true; |
322 ScheduleUpdate(); | 598 ScheduleUpdate(); |
323 } | 599 } |
324 | 600 |
325 void InspectorOverlay::HideReloadingBlanket() { | 601 void InspectorOverlayAgent::HideReloadingBlanket() { |
326 if (!show_reloading_blanket_) | 602 if (!show_reloading_blanket_) |
327 return; | 603 return; |
328 show_reloading_blanket_ = false; | 604 show_reloading_blanket_ = false; |
329 if (suspended_) | 605 if (suspended_) |
330 ClearInternal(); | 606 ClearInternal(); |
331 else | 607 else |
332 ScheduleUpdate(); | 608 ScheduleUpdate(); |
333 } | 609 } |
334 | 610 |
335 void InspectorOverlay::HideHighlight() { | 611 void InspectorOverlayAgent::InnerHideHighlight() { |
336 highlight_node_.Clear(); | 612 highlight_node_.Clear(); |
337 event_target_node_.Clear(); | 613 event_target_node_.Clear(); |
338 highlight_quad_.reset(); | 614 highlight_quad_.reset(); |
339 ScheduleUpdate(); | 615 ScheduleUpdate(); |
340 } | 616 } |
341 | 617 |
342 void InspectorOverlay::HighlightNode( | 618 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, | 619 Node* node, |
351 Node* event_target, | 620 Node* event_target, |
352 const InspectorHighlightConfig& highlight_config, | 621 const InspectorHighlightConfig& highlight_config, |
353 bool omit_tooltip) { | 622 bool omit_tooltip) { |
354 node_highlight_config_ = highlight_config; | 623 node_highlight_config_ = highlight_config; |
355 highlight_node_ = node; | 624 highlight_node_ = node; |
356 event_target_node_ = event_target; | 625 event_target_node_ = event_target; |
357 omit_tooltip_ = omit_tooltip; | 626 omit_tooltip_ = omit_tooltip; |
358 ScheduleUpdate(); | 627 ScheduleUpdate(); |
359 } | 628 } |
360 | 629 |
361 void InspectorOverlay::SetInspectMode( | 630 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, | 631 std::unique_ptr<FloatQuad> quad, |
377 const InspectorHighlightConfig& highlight_config) { | 632 Maybe<protocol::DOM::RGBA> color, |
378 quad_highlight_config_ = highlight_config; | 633 Maybe<protocol::DOM::RGBA> outline_color) { |
| 634 quad_content_color_ = InspectorDOMAgent::ParseColor(color.fromMaybe(nullptr)); |
| 635 quad_content_outline_color_ = |
| 636 InspectorDOMAgent::ParseColor(outline_color.fromMaybe(nullptr)); |
379 highlight_quad_ = std::move(quad); | 637 highlight_quad_ = std::move(quad); |
380 omit_tooltip_ = false; | 638 omit_tooltip_ = false; |
381 ScheduleUpdate(); | 639 ScheduleUpdate(); |
382 } | 640 } |
383 | 641 |
384 bool InspectorOverlay::IsEmpty() { | 642 bool InspectorOverlayAgent::IsEmpty() { |
385 if (show_reloading_blanket_) | 643 if (show_reloading_blanket_) |
386 return false; | 644 return false; |
387 if (suspended_) | 645 if (suspended_) |
388 return true; | 646 return true; |
389 bool has_visible_elements = highlight_node_ || event_target_node_ || | 647 bool has_visible_elements = highlight_node_ || event_target_node_ || |
390 highlight_quad_ || | 648 highlight_quad_ || |
391 (resize_timer_active_ && draw_view_size_) || | 649 (resize_timer_active_ && draw_view_size_) || |
392 !paused_in_debugger_message_.IsNull(); | 650 !paused_in_debugger_message_.IsNull(); |
393 return !has_visible_elements && | 651 return !has_visible_elements && inspect_mode_ == kNotSearching; |
394 inspect_mode_ == InspectorDOMAgent::kNotSearching; | |
395 } | 652 } |
396 | 653 |
397 void InspectorOverlay::ScheduleUpdate() { | 654 void InspectorOverlayAgent::ScheduleUpdate() { |
398 if (IsEmpty()) { | 655 if (IsEmpty()) { |
399 if (page_overlay_) | 656 if (page_overlay_) |
400 page_overlay_.reset(); | 657 page_overlay_.reset(); |
401 return; | 658 return; |
402 } | 659 } |
403 needs_update_ = true; | 660 needs_update_ = true; |
404 LocalFrame* frame = frame_impl_->GetFrame(); | 661 LocalFrame* frame = frame_impl_->GetFrame(); |
405 if (frame) { | 662 if (frame) { |
406 frame->GetPage()->GetChromeClient().ScheduleAnimation(frame); | 663 frame->GetPage()->GetChromeClient().ScheduleAnimation(frame); |
407 } | 664 } |
408 } | 665 } |
409 | 666 |
410 void InspectorOverlay::RebuildOverlayPage() { | 667 void InspectorOverlayAgent::RebuildOverlayPage() { |
411 FrameView* view = frame_impl_->GetFrameView(); | 668 FrameView* view = frame_impl_->GetFrameView(); |
412 LocalFrame* frame = frame_impl_->GetFrame(); | 669 LocalFrame* frame = frame_impl_->GetFrame(); |
413 if (!view || !frame) | 670 if (!view || !frame) |
414 return; | 671 return; |
415 | 672 |
416 IntRect visible_rect_in_document = | 673 IntRect visible_rect_in_document = |
417 view->GetScrollableArea()->VisibleContentRect(); | 674 view->GetScrollableArea()->VisibleContentRect(); |
418 IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); | 675 IntSize viewport_size = frame->GetPage()->GetVisualViewport().Size(); |
419 OverlayMainFrame()->View()->Resize(viewport_size); | 676 OverlayMainFrame()->View()->Resize(viewport_size); |
420 OverlayPage()->GetVisualViewport().SetSize(viewport_size); | 677 OverlayPage()->GetVisualViewport().SetSize(viewport_size); |
(...skipping 13 matching lines...) Expand all Loading... |
434 | 691 |
435 static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( | 692 static std::unique_ptr<protocol::DictionaryValue> BuildObjectForSize( |
436 const IntSize& size) { | 693 const IntSize& size) { |
437 std::unique_ptr<protocol::DictionaryValue> result = | 694 std::unique_ptr<protocol::DictionaryValue> result = |
438 protocol::DictionaryValue::create(); | 695 protocol::DictionaryValue::create(); |
439 result->setInteger("width", size.Width()); | 696 result->setInteger("width", size.Width()); |
440 result->setInteger("height", size.Height()); | 697 result->setInteger("height", size.Height()); |
441 return result; | 698 return result; |
442 } | 699 } |
443 | 700 |
444 void InspectorOverlay::DrawNodeHighlight() { | 701 void InspectorOverlayAgent::DrawNodeHighlight() { |
445 if (!highlight_node_) | 702 if (!highlight_node_) |
446 return; | 703 return; |
447 | 704 |
448 String selectors = node_highlight_config_.selector_list; | 705 String selectors = node_highlight_config_.selector_list; |
449 StaticElementList* elements = nullptr; | 706 StaticElementList* elements = nullptr; |
450 DummyExceptionStateForTesting exception_state; | 707 DummyExceptionStateForTesting exception_state; |
451 ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); | 708 ContainerNode* query_base = highlight_node_->ContainingShadowRoot(); |
452 if (!query_base) | 709 if (!query_base) |
453 query_base = highlight_node_->ownerDocument(); | 710 query_base = highlight_node_->ownerDocument(); |
454 if (selectors.length()) | 711 if (selectors.length()) { |
455 elements = | 712 elements = |
456 query_base->QuerySelectorAll(AtomicString(selectors), exception_state); | 713 query_base->QuerySelectorAll(AtomicString(selectors), exception_state); |
| 714 } |
457 if (elements && !exception_state.HadException()) { | 715 if (elements && !exception_state.HadException()) { |
458 for (unsigned i = 0; i < elements->length(); ++i) { | 716 for (unsigned i = 0; i < elements->length(); ++i) { |
459 Element* element = elements->item(i); | 717 Element* element = elements->item(i); |
460 InspectorHighlight highlight(element, node_highlight_config_, false); | 718 InspectorHighlight highlight(element, node_highlight_config_, false); |
461 std::unique_ptr<protocol::DictionaryValue> highlight_json = | 719 std::unique_ptr<protocol::DictionaryValue> highlight_json = |
462 highlight.AsProtocolValue(); | 720 highlight.AsProtocolValue(); |
463 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); | 721 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); |
464 } | 722 } |
465 } | 723 } |
466 | 724 |
467 bool append_element_info = | 725 bool append_element_info = |
468 highlight_node_->IsElementNode() && !omit_tooltip_ && | 726 highlight_node_->IsElementNode() && !omit_tooltip_ && |
469 node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && | 727 node_highlight_config_.show_info && highlight_node_->GetLayoutObject() && |
470 highlight_node_->GetDocument().GetFrame(); | 728 highlight_node_->GetDocument().GetFrame(); |
471 InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, | 729 InspectorHighlight highlight(highlight_node_.Get(), node_highlight_config_, |
472 append_element_info); | 730 append_element_info); |
473 if (event_target_node_) | 731 if (event_target_node_) { |
474 highlight.AppendEventTargetQuads(event_target_node_.Get(), | 732 highlight.AppendEventTargetQuads(event_target_node_.Get(), |
475 node_highlight_config_); | 733 node_highlight_config_); |
| 734 } |
476 | 735 |
477 std::unique_ptr<protocol::DictionaryValue> highlight_json = | 736 std::unique_ptr<protocol::DictionaryValue> highlight_json = |
478 highlight.AsProtocolValue(); | 737 highlight.AsProtocolValue(); |
479 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); | 738 EvaluateInOverlay("drawHighlight", std::move(highlight_json)); |
480 } | 739 } |
481 | 740 |
482 void InspectorOverlay::DrawQuadHighlight() { | 741 void InspectorOverlayAgent::DrawQuadHighlight() { |
483 if (!highlight_quad_) | 742 if (!highlight_quad_) |
484 return; | 743 return; |
485 | 744 |
486 InspectorHighlight highlight(WindowToViewportScale()); | 745 InspectorHighlight highlight(WindowToViewportScale()); |
487 highlight.AppendQuad(*highlight_quad_, quad_highlight_config_.content, | 746 highlight.AppendQuad(*highlight_quad_, quad_content_color_, |
488 quad_highlight_config_.content_outline); | 747 quad_content_outline_color_); |
489 EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); | 748 EvaluateInOverlay("drawHighlight", highlight.AsProtocolValue()); |
490 } | 749 } |
491 | 750 |
492 void InspectorOverlay::DrawPausedInDebuggerMessage() { | 751 void InspectorOverlayAgent::DrawPausedInDebuggerMessage() { |
493 if (inspect_mode_ == InspectorDOMAgent::kNotSearching && | 752 if (inspect_mode_ == kNotSearching && !paused_in_debugger_message_.IsNull()) { |
494 !paused_in_debugger_message_.IsNull()) | |
495 EvaluateInOverlay("drawPausedInDebuggerMessage", | 753 EvaluateInOverlay("drawPausedInDebuggerMessage", |
496 paused_in_debugger_message_); | 754 paused_in_debugger_message_); |
| 755 } |
497 } | 756 } |
498 | 757 |
499 void InspectorOverlay::DrawViewSize() { | 758 void InspectorOverlayAgent::DrawViewSize() { |
500 if (resize_timer_active_ && draw_view_size_) | 759 if (resize_timer_active_ && draw_view_size_) |
501 EvaluateInOverlay("drawViewSize", ""); | 760 EvaluateInOverlay("drawViewSize", ""); |
502 } | 761 } |
503 | 762 |
504 float InspectorOverlay::WindowToViewportScale() const { | 763 float InspectorOverlayAgent::WindowToViewportScale() const { |
505 LocalFrame* frame = frame_impl_->GetFrame(); | 764 LocalFrame* frame = frame_impl_->GetFrame(); |
506 if (!frame) | 765 if (!frame) |
507 return 1.0f; | 766 return 1.0f; |
508 return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); | 767 return frame->GetPage()->GetChromeClient().WindowToViewportScalar(1.0f); |
509 } | 768 } |
510 | 769 |
511 Page* InspectorOverlay::OverlayPage() { | 770 Page* InspectorOverlayAgent::OverlayPage() { |
512 if (overlay_page_) | 771 if (overlay_page_) |
513 return overlay_page_.Get(); | 772 return overlay_page_.Get(); |
514 | 773 |
515 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 774 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
516 | 775 |
517 DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, | 776 DEFINE_STATIC_LOCAL(LocalFrameClient, dummy_local_frame_client, |
518 (EmptyLocalFrameClient::Create())); | 777 (EmptyLocalFrameClient::Create())); |
519 Page::PageClients page_clients; | 778 Page::PageClients page_clients; |
520 FillWithEmptyClients(page_clients); | 779 FillWithEmptyClients(page_clients); |
521 DCHECK(!overlay_chrome_client_); | 780 DCHECK(!overlay_chrome_client_); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 EvaluateInOverlay("setPlatform", "windows"); | 840 EvaluateInOverlay("setPlatform", "windows"); |
582 #elif OS(MACOSX) | 841 #elif OS(MACOSX) |
583 EvaluateInOverlay("setPlatform", "mac"); | 842 EvaluateInOverlay("setPlatform", "mac"); |
584 #elif OS(POSIX) | 843 #elif OS(POSIX) |
585 EvaluateInOverlay("setPlatform", "linux"); | 844 EvaluateInOverlay("setPlatform", "linux"); |
586 #endif | 845 #endif |
587 | 846 |
588 return overlay_page_.Get(); | 847 return overlay_page_.Get(); |
589 } | 848 } |
590 | 849 |
591 LocalFrame* InspectorOverlay::OverlayMainFrame() { | 850 LocalFrame* InspectorOverlayAgent::OverlayMainFrame() { |
592 return ToLocalFrame(OverlayPage()->MainFrame()); | 851 return ToLocalFrame(OverlayPage()->MainFrame()); |
593 } | 852 } |
594 | 853 |
595 void InspectorOverlay::Reset(const IntSize& viewport_size, | 854 void InspectorOverlayAgent::Reset(const IntSize& viewport_size, |
596 const IntPoint& document_scroll_offset) { | 855 const IntPoint& document_scroll_offset) { |
597 std::unique_ptr<protocol::DictionaryValue> reset_data = | 856 std::unique_ptr<protocol::DictionaryValue> reset_data = |
598 protocol::DictionaryValue::create(); | 857 protocol::DictionaryValue::create(); |
599 reset_data->setDouble( | 858 reset_data->setDouble( |
600 "deviceScaleFactor", | 859 "deviceScaleFactor", |
601 frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); | 860 frame_impl_->GetFrame()->GetPage()->DeviceScaleFactorDeprecated()); |
602 reset_data->setDouble( | 861 reset_data->setDouble( |
603 "pageScaleFactor", | 862 "pageScaleFactor", |
604 frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); | 863 frame_impl_->GetFrame()->GetPage()->GetVisualViewport().Scale()); |
605 | 864 |
606 IntRect viewport_in_screen = | 865 IntRect viewport_in_screen = |
607 frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( | 866 frame_impl_->GetFrame()->GetPage()->GetChromeClient().ViewportToScreen( |
608 IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); | 867 IntRect(IntPoint(), viewport_size), frame_impl_->GetFrame()->View()); |
609 reset_data->setObject("viewportSize", | 868 reset_data->setObject("viewportSize", |
610 BuildObjectForSize(viewport_in_screen.Size())); | 869 BuildObjectForSize(viewport_in_screen.Size())); |
611 | 870 |
612 // The zoom factor in the overlay frame already has been multiplied by the | 871 // 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. | 872 // window to viewport scale (aka device scale factor), so cancel it. |
614 reset_data->setDouble( | 873 reset_data->setDouble( |
615 "pageZoomFactor", | 874 "pageZoomFactor", |
616 frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); | 875 frame_impl_->GetFrame()->PageZoomFactor() / WindowToViewportScale()); |
617 | 876 |
618 reset_data->setInteger("scrollX", document_scroll_offset.X()); | 877 reset_data->setInteger("scrollX", document_scroll_offset.X()); |
619 reset_data->setInteger("scrollY", document_scroll_offset.Y()); | 878 reset_data->setInteger("scrollY", document_scroll_offset.Y()); |
620 EvaluateInOverlay("reset", std::move(reset_data)); | 879 EvaluateInOverlay("reset", std::move(reset_data)); |
621 } | 880 } |
622 | 881 |
623 void InspectorOverlay::EvaluateInOverlay(const String& method, | 882 void InspectorOverlayAgent::EvaluateInOverlay(const String& method, |
624 const String& argument) { | 883 const String& argument) { |
625 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 884 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
626 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); | 885 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); |
627 command->pushValue(protocol::StringValue::create(method)); | 886 command->pushValue(protocol::StringValue::create(method)); |
628 command->pushValue(protocol::StringValue::create(argument)); | 887 command->pushValue(protocol::StringValue::create(argument)); |
629 ToLocalFrame(OverlayPage()->MainFrame()) | 888 ToLocalFrame(OverlayPage()->MainFrame()) |
630 ->GetScriptController() | 889 ->GetScriptController() |
631 .ExecuteScriptInMainWorld( | 890 .ExecuteScriptInMainWorld( |
632 "dispatch(" + command->serialize() + ")", | 891 "dispatch(" + command->serialize() + ")", |
633 ScriptController::kExecuteScriptWhenScriptsDisabled); | 892 ScriptController::kExecuteScriptWhenScriptsDisabled); |
634 } | 893 } |
635 | 894 |
636 void InspectorOverlay::EvaluateInOverlay( | 895 void InspectorOverlayAgent::EvaluateInOverlay( |
637 const String& method, | 896 const String& method, |
638 std::unique_ptr<protocol::Value> argument) { | 897 std::unique_ptr<protocol::Value> argument) { |
639 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 898 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
640 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); | 899 std::unique_ptr<protocol::ListValue> command = protocol::ListValue::create(); |
641 command->pushValue(protocol::StringValue::create(method)); | 900 command->pushValue(protocol::StringValue::create(method)); |
642 command->pushValue(std::move(argument)); | 901 command->pushValue(std::move(argument)); |
643 ToLocalFrame(OverlayPage()->MainFrame()) | 902 ToLocalFrame(OverlayPage()->MainFrame()) |
644 ->GetScriptController() | 903 ->GetScriptController() |
645 .ExecuteScriptInMainWorld( | 904 .ExecuteScriptInMainWorld( |
646 "dispatch(" + command->serialize() + ")", | 905 "dispatch(" + command->serialize() + ")", |
647 ScriptController::kExecuteScriptWhenScriptsDisabled); | 906 ScriptController::kExecuteScriptWhenScriptsDisabled); |
648 } | 907 } |
649 | 908 |
650 String InspectorOverlay::EvaluateInOverlayForTest(const String& script) { | 909 String InspectorOverlayAgent::EvaluateInOverlayForTest(const String& script) { |
651 ScriptForbiddenScope::AllowUserAgentScript allow_script; | 910 ScriptForbiddenScope::AllowUserAgentScript allow_script; |
652 v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); | 911 v8::HandleScope handle_scope(ToIsolate(OverlayMainFrame())); |
653 v8::Local<v8::Value> string = | 912 v8::Local<v8::Value> string = |
654 ToLocalFrame(OverlayPage()->MainFrame()) | 913 ToLocalFrame(OverlayPage()->MainFrame()) |
655 ->GetScriptController() | 914 ->GetScriptController() |
656 .ExecuteScriptInMainWorldAndReturnValue( | 915 .ExecuteScriptInMainWorldAndReturnValue( |
657 ScriptSourceCode(script), | 916 ScriptSourceCode(script), |
658 ScriptController::kExecuteScriptWhenScriptsDisabled); | 917 ScriptController::kExecuteScriptWhenScriptsDisabled); |
659 return ToCoreStringWithUndefinedOrNullCheck(string); | 918 return ToCoreStringWithUndefinedOrNullCheck(string); |
660 } | 919 } |
661 | 920 |
662 void InspectorOverlay::OnTimer(TimerBase*) { | 921 void InspectorOverlayAgent::OnTimer(TimerBase*) { |
663 resize_timer_active_ = false; | 922 resize_timer_active_ = false; |
664 ScheduleUpdate(); | 923 ScheduleUpdate(); |
665 } | 924 } |
666 | 925 |
667 void InspectorOverlay::ClearInternal() { | 926 void InspectorOverlayAgent::ClearInternal() { |
668 if (overlay_page_) { | 927 if (overlay_page_) { |
669 overlay_page_->WillBeDestroyed(); | 928 overlay_page_->WillBeDestroyed(); |
670 overlay_page_.Clear(); | 929 overlay_page_.Clear(); |
671 overlay_chrome_client_.Clear(); | 930 overlay_chrome_client_.Clear(); |
672 } | 931 } |
673 resize_timer_active_ = false; | 932 resize_timer_active_ = false; |
674 paused_in_debugger_message_ = String(); | 933 paused_in_debugger_message_ = String(); |
675 inspect_mode_ = InspectorDOMAgent::kNotSearching; | 934 inspect_mode_ = kNotSearching; |
676 timer_.Stop(); | 935 timer_.Stop(); |
677 HideHighlight(); | 936 InnerHideHighlight(); |
678 } | 937 } |
679 | 938 |
680 void InspectorOverlay::Clear() { | 939 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_) | 940 if (v8_session_) |
689 v8_session_->resume(); | 941 v8_session_->resume(); |
690 } | 942 } |
691 | 943 |
692 void InspectorOverlay::OverlaySteppedOver() { | 944 void InspectorOverlayAgent::OverlaySteppedOver() { |
693 if (v8_session_) | 945 if (v8_session_) |
694 v8_session_->stepOver(); | 946 v8_session_->stepOver(); |
695 } | 947 } |
696 | 948 |
697 void InspectorOverlay::Suspend() { | 949 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_) { | 950 if (resized && draw_view_size_) { |
710 resize_timer_active_ = true; | 951 resize_timer_active_ = true; |
711 timer_.StartOneShot(1, BLINK_FROM_HERE); | 952 timer_.StartOneShot(1, BLINK_FROM_HERE); |
712 } | 953 } |
713 ScheduleUpdate(); | 954 ScheduleUpdate(); |
714 } | 955 } |
715 | 956 |
716 void InspectorOverlay::SetShowViewportSizeOnResize(bool show) { | 957 bool InspectorOverlayAgent::HandleMouseMove(const WebMouseEvent& event) { |
717 draw_view_size_ = show; | |
718 } | |
719 | |
720 bool InspectorOverlay::HandleMouseMove(const WebMouseEvent& event) { | |
721 if (!ShouldSearchForNode()) | 958 if (!ShouldSearchForNode()) |
722 return false; | 959 return false; |
723 | 960 |
724 LocalFrame* frame = frame_impl_->GetFrame(); | 961 LocalFrame* frame = frame_impl_->GetFrame(); |
725 if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) | 962 if (!frame || !frame->View() || frame->ContentLayoutItem().IsNull()) |
726 return false; | 963 return false; |
727 Node* node = HoveredNodeForEvent( | 964 Node* node = HoveredNodeForEvent( |
728 frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); | 965 frame, event, event.GetModifiers() & WebInputEvent::kShiftKey); |
729 | 966 |
730 // Do not highlight within user agent shadow root unless requested. | 967 // Do not highlight within user agent shadow root unless requested. |
731 if (inspect_mode_ != InspectorDOMAgent::kSearchingForUAShadow) { | 968 if (inspect_mode_ != kSearchingForUAShadow) { |
732 ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); | 969 ShadowRoot* shadow_root = InspectorDOMAgent::UserAgentShadowRoot(node); |
733 if (shadow_root) | 970 if (shadow_root) |
734 node = &shadow_root->host(); | 971 node = &shadow_root->host(); |
735 } | 972 } |
736 | 973 |
737 // Shadow roots don't have boxes - use host element instead. | 974 // Shadow roots don't have boxes - use host element instead. |
738 if (node && node->IsShadowRoot()) | 975 if (node && node->IsShadowRoot()) |
739 node = node->ParentOrShadowHostNode(); | 976 node = node->ParentOrShadowHostNode(); |
740 | 977 |
741 if (!node) | 978 if (!node) |
742 return true; | 979 return true; |
743 | 980 |
744 if (node->IsFrameOwnerElement()) { | 981 if (node->IsFrameOwnerElement()) { |
745 HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); | 982 HTMLFrameOwnerElement* frame_owner = ToHTMLFrameOwnerElement(node); |
746 if (frame_owner->ContentFrame() && | 983 if (frame_owner->ContentFrame() && |
747 !frame_owner->ContentFrame()->IsLocalFrame()) { | 984 !frame_owner->ContentFrame()->IsLocalFrame()) { |
748 // Do not consume event so that remote frame can handle it. | 985 // Do not consume event so that remote frame can handle it. |
749 HideHighlight(); | 986 InnerHideHighlight(); |
750 hovered_node_for_inspect_mode_.Clear(); | 987 hovered_node_for_inspect_mode_.Clear(); |
751 return false; | 988 return false; |
752 } | 989 } |
753 } | 990 } |
754 | 991 |
755 Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) | 992 Node* event_target = (event.GetModifiers() & WebInputEvent::kShiftKey) |
756 ? HoveredNodeForEvent(frame, event, false) | 993 ? HoveredNodeForEvent(frame, event, false) |
757 : nullptr; | 994 : nullptr; |
758 if (event_target == node) | 995 if (event_target == node) |
759 event_target = nullptr; | 996 event_target = nullptr; |
760 | 997 |
761 if (node && inspect_mode_highlight_config_) { | 998 if (node && inspect_mode_highlight_config_) { |
762 hovered_node_for_inspect_mode_ = node; | 999 hovered_node_for_inspect_mode_ = node; |
763 if (dom_agent_) | 1000 NodeHighlightRequested(node); |
764 dom_agent_->NodeHighlightedInOverlay(node); | 1001 bool omit_tooltip = event.GetModifiers() & |
765 HighlightNode(node, event_target, *inspect_mode_highlight_config_, | 1002 (WebInputEvent::kControlKey | WebInputEvent::kMetaKey); |
766 (event.GetModifiers() & | 1003 InnerHighlightNode(node, event_target, *inspect_mode_highlight_config_, |
767 (WebInputEvent::kControlKey | WebInputEvent::kMetaKey))); | 1004 omit_tooltip); |
768 } | 1005 } |
769 return true; | 1006 return true; |
770 } | 1007 } |
771 | 1008 |
772 bool InspectorOverlay::HandleMouseDown() { | 1009 bool InspectorOverlayAgent::HandleMouseDown() { |
773 swallow_next_mouse_up_ = false; | 1010 swallow_next_mouse_up_ = false; |
774 if (!ShouldSearchForNode()) | 1011 if (!ShouldSearchForNode()) |
775 return false; | 1012 return false; |
776 | 1013 |
777 if (hovered_node_for_inspect_mode_) { | 1014 if (hovered_node_for_inspect_mode_) { |
778 swallow_next_mouse_up_ = true; | 1015 swallow_next_mouse_up_ = true; |
779 Inspect(hovered_node_for_inspect_mode_.Get()); | 1016 Inspect(hovered_node_for_inspect_mode_.Get()); |
780 hovered_node_for_inspect_mode_.Clear(); | 1017 hovered_node_for_inspect_mode_.Clear(); |
781 return true; | 1018 return true; |
782 } | 1019 } |
783 return false; | 1020 return false; |
784 } | 1021 } |
785 | 1022 |
786 bool InspectorOverlay::HandleMouseUp() { | 1023 bool InspectorOverlayAgent::HandleMouseUp() { |
787 if (swallow_next_mouse_up_) { | 1024 if (swallow_next_mouse_up_) { |
788 swallow_next_mouse_up_ = false; | 1025 swallow_next_mouse_up_ = false; |
789 return true; | 1026 return true; |
790 } | 1027 } |
791 return false; | 1028 return false; |
792 } | 1029 } |
793 | 1030 |
794 bool InspectorOverlay::HandleGestureEvent(const WebGestureEvent& event) { | 1031 bool InspectorOverlayAgent::HandleGestureEvent(const WebGestureEvent& event) { |
795 if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) | 1032 if (!ShouldSearchForNode() || event.GetType() != WebInputEvent::kGestureTap) |
796 return false; | 1033 return false; |
797 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); | 1034 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); |
798 if (node && inspect_mode_highlight_config_) { | 1035 if (node && inspect_mode_highlight_config_) { |
799 HighlightNode(node, *inspect_mode_highlight_config_, false); | 1036 InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); |
800 Inspect(node); | 1037 Inspect(node); |
801 return true; | 1038 return true; |
802 } | 1039 } |
803 return false; | 1040 return false; |
804 } | 1041 } |
805 | 1042 |
806 bool InspectorOverlay::HandleTouchEvent(const WebTouchEvent& event) { | 1043 bool InspectorOverlayAgent::HandleTouchEvent(const WebTouchEvent& event) { |
807 if (!ShouldSearchForNode()) | 1044 if (!ShouldSearchForNode()) |
808 return false; | 1045 return false; |
809 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); | 1046 Node* node = HoveredNodeForEvent(frame_impl_->GetFrame(), event, false); |
810 if (node && inspect_mode_highlight_config_) { | 1047 if (node && inspect_mode_highlight_config_) { |
811 HighlightNode(node, *inspect_mode_highlight_config_, false); | 1048 InnerHighlightNode(node, nullptr, *inspect_mode_highlight_config_, false); |
812 Inspect(node); | 1049 Inspect(node); |
813 return true; | 1050 return true; |
814 } | 1051 } |
815 return false; | 1052 return false; |
816 } | 1053 } |
817 | 1054 |
818 bool InspectorOverlay::ShouldSearchForNode() { | 1055 Response InspectorOverlayAgent::CompositingEnabled() { |
819 return inspect_mode_ != InspectorDOMAgent::kNotSearching; | 1056 bool main_frame = frame_impl_->ViewImpl() && !frame_impl_->Parent(); |
| 1057 if (!main_frame || !frame_impl_->ViewImpl() |
| 1058 ->GetPage() |
| 1059 ->GetSettings() |
| 1060 .GetAcceleratedCompositingEnabled()) |
| 1061 return Response::Error("Compositing mode is not supported"); |
| 1062 return Response::OK(); |
820 } | 1063 } |
821 | 1064 |
822 void InspectorOverlay::Inspect(Node* node) { | 1065 bool InspectorOverlayAgent::ShouldSearchForNode() { |
823 if (dom_agent_) | 1066 return inspect_mode_ != kNotSearching; |
824 dom_agent_->Inspect(node); | 1067 } |
| 1068 |
| 1069 void InspectorOverlayAgent::Inspect(Node* inspected_node) { |
| 1070 if (!inspected_node) |
| 1071 return; |
| 1072 |
| 1073 Node* node = inspected_node; |
| 1074 while (node && !node->IsElementNode() && !node->IsDocumentNode() && |
| 1075 !node->IsDocumentFragment()) |
| 1076 node = node->ParentOrShadowHostNode(); |
| 1077 if (!node) |
| 1078 return; |
| 1079 |
| 1080 int backend_node_id = DOMNodeIds::IdForNode(node); |
| 1081 if (!enabled_) { |
| 1082 backend_node_id_to_inspect_ = backend_node_id; |
| 1083 return; |
| 1084 } |
| 1085 |
| 1086 GetFrontend()->inspectNodeRequested(backend_node_id); |
| 1087 } |
| 1088 |
| 1089 void InspectorOverlayAgent::NodeHighlightRequested(Node* node) { |
| 1090 if (!enabled_) |
| 1091 return; |
| 1092 |
| 1093 while (node && !node->IsElementNode() && !node->IsDocumentNode() && |
| 1094 !node->IsDocumentFragment()) |
| 1095 node = node->ParentOrShadowHostNode(); |
| 1096 |
| 1097 if (!node) |
| 1098 return; |
| 1099 |
| 1100 int node_id = dom_agent_->PushNodePathToFrontend(node); |
| 1101 GetFrontend()->nodeHighlightRequested(node_id); |
| 1102 } |
| 1103 |
| 1104 Response InspectorOverlayAgent::SetSearchingForNode( |
| 1105 SearchMode search_mode, |
| 1106 Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object) { |
| 1107 if (search_mode == kNotSearching) { |
| 1108 inspect_mode_ = search_mode; |
| 1109 ScheduleUpdate(); |
| 1110 hovered_node_for_inspect_mode_.Clear(); |
| 1111 InnerHideHighlight(); |
| 1112 return Response::OK(); |
| 1113 } |
| 1114 |
| 1115 std::unique_ptr<InspectorHighlightConfig> config; |
| 1116 Response response = HighlightConfigFromInspectorObject( |
| 1117 std::move(highlight_inspector_object), &config); |
| 1118 if (!response.isSuccess()) |
| 1119 return response; |
| 1120 inspect_mode_ = search_mode; |
| 1121 inspect_mode_highlight_config_ = std::move(config); |
| 1122 ScheduleUpdate(); |
| 1123 return Response::OK(); |
| 1124 } |
| 1125 |
| 1126 Response InspectorOverlayAgent::HighlightConfigFromInspectorObject( |
| 1127 Maybe<protocol::Overlay::HighlightConfig> highlight_inspector_object, |
| 1128 std::unique_ptr<InspectorHighlightConfig>* out_config) { |
| 1129 if (!highlight_inspector_object.isJust()) { |
| 1130 return Response::Error( |
| 1131 "Internal error: highlight configuration parameter is missing"); |
| 1132 } |
| 1133 |
| 1134 protocol::Overlay::HighlightConfig* config = |
| 1135 highlight_inspector_object.fromJust(); |
| 1136 std::unique_ptr<InspectorHighlightConfig> highlight_config = |
| 1137 WTF::MakeUnique<InspectorHighlightConfig>(); |
| 1138 highlight_config->show_info = config->getShowInfo(false); |
| 1139 highlight_config->show_rulers = config->getShowRulers(false); |
| 1140 highlight_config->show_extension_lines = config->getShowExtensionLines(false); |
| 1141 highlight_config->display_as_material = config->getDisplayAsMaterial(false); |
| 1142 highlight_config->content = |
| 1143 InspectorDOMAgent::ParseColor(config->getContentColor(nullptr)); |
| 1144 highlight_config->padding = |
| 1145 InspectorDOMAgent::ParseColor(config->getPaddingColor(nullptr)); |
| 1146 highlight_config->border = |
| 1147 InspectorDOMAgent::ParseColor(config->getBorderColor(nullptr)); |
| 1148 highlight_config->margin = |
| 1149 InspectorDOMAgent::ParseColor(config->getMarginColor(nullptr)); |
| 1150 highlight_config->event_target = |
| 1151 InspectorDOMAgent::ParseColor(config->getEventTargetColor(nullptr)); |
| 1152 highlight_config->shape = |
| 1153 InspectorDOMAgent::ParseColor(config->getShapeColor(nullptr)); |
| 1154 highlight_config->shape_margin = |
| 1155 InspectorDOMAgent::ParseColor(config->getShapeMarginColor(nullptr)); |
| 1156 highlight_config->selector_list = config->getSelectorList(""); |
| 1157 |
| 1158 *out_config = std::move(highlight_config); |
| 1159 return Response::OK(); |
825 } | 1160 } |
826 | 1161 |
827 } // namespace blink | 1162 } // namespace blink |
OLD | NEW |