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 |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "web/InspectorOverlayImpl.h" | 30 #include "web/InspectorOverlayImpl.h" |
31 | 31 |
32 #include "bindings/core/v8/ScriptController.h" | 32 #include "bindings/core/v8/ScriptController.h" |
33 #include "bindings/core/v8/V8InspectorOverlayHost.h" | 33 #include "bindings/core/v8/V8InspectorOverlayHost.h" |
34 #include "core/dom/Node.h" | 34 #include "core/dom/Node.h" |
35 #include "core/frame/FrameHost.h" | 35 #include "core/frame/FrameHost.h" |
36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
37 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
38 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
39 #include "core/input/EventHandler.h" | 39 #include "core/input/EventHandler.h" |
| 40 #include "core/inspector/InspectorDebuggerAgent.h" |
40 #include "core/inspector/InspectorOverlayHost.h" | 41 #include "core/inspector/InspectorOverlayHost.h" |
41 #include "core/inspector/LayoutEditor.h" | 42 #include "core/inspector/LayoutEditor.h" |
42 #include "core/loader/EmptyClients.h" | 43 #include "core/loader/EmptyClients.h" |
43 #include "core/loader/FrameLoadRequest.h" | 44 #include "core/loader/FrameLoadRequest.h" |
44 #include "core/page/ChromeClient.h" | 45 #include "core/page/ChromeClient.h" |
45 #include "core/page/Page.h" | 46 #include "core/page/Page.h" |
46 #include "platform/JSONValues.h" | 47 #include "platform/JSONValues.h" |
47 #include "platform/ScriptForbiddenScope.h" | 48 #include "platform/ScriptForbiddenScope.h" |
48 #include "platform/graphics/GraphicsContext.h" | 49 #include "platform/graphics/GraphicsContext.h" |
49 #include "public/platform/Platform.h" | 50 #include "public/platform/Platform.h" |
50 #include "public/platform/WebData.h" | 51 #include "public/platform/WebData.h" |
51 #include "web/PageOverlay.h" | 52 #include "web/PageOverlay.h" |
52 #include "web/WebGraphicsContextImpl.h" | 53 #include "web/WebGraphicsContextImpl.h" |
53 #include "web/WebInputEventConversion.h" | 54 #include "web/WebInputEventConversion.h" |
54 #include "web/WebLocalFrameImpl.h" | 55 #include "web/WebLocalFrameImpl.h" |
55 #include "web/WebViewImpl.h" | 56 #include "web/WebViewImpl.h" |
56 #include <v8.h> | 57 #include <v8.h> |
57 | 58 |
58 namespace blink { | 59 namespace blink { |
59 | 60 |
60 namespace { | |
61 | |
62 class InspectorOverlayStub : public NoBaseWillBeGarbageCollectedFinalized<Inspec
torOverlayStub>, public InspectorOverlay { | |
63 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(InspectorOverlayStub); | |
64 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(InspectorOverlayStub); | |
65 public: | |
66 InspectorOverlayStub() { } | |
67 DECLARE_TRACE(); | |
68 | |
69 // InspectorOverlay implementation. | |
70 void update() override { } | |
71 void setPausedInDebuggerMessage(const String*) override { } | |
72 void setInspectModeEnabled(bool) override { } | |
73 void hideHighlight() override { } | |
74 void highlightNode(Node*, Node* eventTarget, const InspectorHighlightConfig&
, bool omitTooltip) override { } | |
75 void highlightQuad(PassOwnPtr<FloatQuad>, const InspectorHighlightConfig&) o
verride { } | |
76 void showAndHideViewSize(bool showGrid) override { } | |
77 void setListener(InspectorOverlay::Listener* listener) override { } | |
78 void suspendUpdates() override { } | |
79 void resumeUpdates() override { } | |
80 void clear() override { } | |
81 void setLayoutEditor(PassOwnPtrWillBeRawPtr<LayoutEditor>) override { } | |
82 }; | |
83 | |
84 DEFINE_TRACE(InspectorOverlayStub) | |
85 { | |
86 InspectorOverlay::trace(visitor); | |
87 } | |
88 | |
89 } // anonymous namespace | |
90 | |
91 class InspectorOverlayImpl::InspectorPageOverlayDelegate final : public PageOver
lay::Delegate { | 61 class InspectorOverlayImpl::InspectorPageOverlayDelegate final : public PageOver
lay::Delegate { |
92 public: | 62 public: |
93 explicit InspectorPageOverlayDelegate(InspectorOverlayImpl& overlay) | 63 explicit InspectorPageOverlayDelegate(InspectorOverlayImpl& overlay) |
94 : m_overlay(&overlay) | 64 : m_overlay(&overlay) |
95 { } | 65 { } |
96 | 66 |
97 DEFINE_INLINE_VIRTUAL_TRACE() | 67 DEFINE_INLINE_VIRTUAL_TRACE() |
98 { | 68 { |
99 visitor->trace(m_overlay); | 69 visitor->trace(m_overlay); |
100 PageOverlay::Delegate::trace(visitor); | 70 PageOverlay::Delegate::trace(visitor); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlayImpl& ove
rlay) | 127 InspectorOverlayChromeClient(ChromeClient& client, InspectorOverlayImpl& ove
rlay) |
158 : m_client(&client) | 128 : m_client(&client) |
159 , m_overlay(&overlay) | 129 , m_overlay(&overlay) |
160 { } | 130 { } |
161 | 131 |
162 RawPtrWillBeMember<ChromeClient> m_client; | 132 RawPtrWillBeMember<ChromeClient> m_client; |
163 RawPtrWillBeMember<InspectorOverlayImpl> m_overlay; | 133 RawPtrWillBeMember<InspectorOverlayImpl> m_overlay; |
164 }; | 134 }; |
165 | 135 |
166 | 136 |
167 // static | |
168 PassOwnPtrWillBeRawPtr<InspectorOverlay> InspectorOverlayImpl::createEmpty() | |
169 { | |
170 return adoptPtrWillBeNoop(new InspectorOverlayStub()); | |
171 } | |
172 | |
173 InspectorOverlayImpl::InspectorOverlayImpl(WebViewImpl* webViewImpl) | 137 InspectorOverlayImpl::InspectorOverlayImpl(WebViewImpl* webViewImpl) |
174 : m_webViewImpl(webViewImpl) | 138 : m_webViewImpl(webViewImpl) |
175 , m_inspectModeEnabled(false) | 139 , m_inspectModeEnabled(false) |
176 , m_overlayHost(InspectorOverlayHost::create()) | 140 , m_overlayHost(InspectorOverlayHost::create()) |
177 , m_drawViewSize(false) | 141 , m_drawViewSize(false) |
178 , m_drawViewSizeWithGrid(false) | 142 , m_drawViewSizeWithGrid(false) |
| 143 , m_resizeTimerActive(false) |
179 , m_omitTooltip(false) | 144 , m_omitTooltip(false) |
180 , m_timer(this, &InspectorOverlayImpl::onTimer) | 145 , m_timer(this, &InspectorOverlayImpl::onTimer) |
181 , m_suspendCount(0) | 146 , m_suspendCount(0) |
182 , m_inLayout(false) | 147 , m_inLayout(false) |
183 , m_needsUpdate(false) | 148 , m_needsUpdate(false) |
184 { | 149 { |
185 m_overlayHost->setDebuggerListener(this); | 150 m_overlayHost->setDebuggerListener(this); |
186 } | 151 } |
187 | 152 |
188 InspectorOverlayImpl::~InspectorOverlayImpl() | 153 InspectorOverlayImpl::~InspectorOverlayImpl() |
189 { | 154 { |
190 ASSERT(!m_overlayPage); | 155 ASSERT(!m_overlayPage); |
191 } | 156 } |
192 | 157 |
193 DEFINE_TRACE(InspectorOverlayImpl) | 158 DEFINE_TRACE(InspectorOverlayImpl) |
194 { | 159 { |
195 visitor->trace(m_highlightNode); | 160 visitor->trace(m_highlightNode); |
196 visitor->trace(m_eventTargetNode); | 161 visitor->trace(m_eventTargetNode); |
197 visitor->trace(m_overlayPage); | 162 visitor->trace(m_overlayPage); |
198 visitor->trace(m_overlayChromeClient); | 163 visitor->trace(m_overlayChromeClient); |
199 visitor->trace(m_overlayHost); | 164 visitor->trace(m_overlayHost); |
200 visitor->trace(m_listener); | |
201 visitor->trace(m_layoutEditor); | 165 visitor->trace(m_layoutEditor); |
202 InspectorOverlay::trace(visitor); | 166 } |
| 167 |
| 168 void InspectorOverlayImpl::init(InspectorCSSAgent* cssAgent, InspectorDebuggerAg
ent* debuggerAgent) |
| 169 { |
| 170 m_layoutEditor = LayoutEditor::create(cssAgent); |
| 171 // TODO(dgozman): overlay should be a listener, not layout editor. |
| 172 m_overlayHost->setLayoutEditorListener(m_layoutEditor.get()); |
| 173 m_debuggerAgent = debuggerAgent; |
203 } | 174 } |
204 | 175 |
205 void InspectorOverlayImpl::invalidate() | 176 void InspectorOverlayImpl::invalidate() |
206 { | 177 { |
207 if (!m_pageOverlay) | 178 if (!m_pageOverlay) |
208 m_pageOverlay = PageOverlay::create(m_webViewImpl, new InspectorPageOver
layDelegate(*this)); | 179 m_pageOverlay = PageOverlay::create(m_webViewImpl, new InspectorPageOver
layDelegate(*this)); |
209 | 180 |
210 m_pageOverlay->update(); | 181 m_pageOverlay->update(); |
211 } | 182 } |
212 | 183 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 261 } |
291 | 262 |
292 void InspectorOverlayImpl::highlightQuad(PassOwnPtr<FloatQuad> quad, const Inspe
ctorHighlightConfig& highlightConfig) | 263 void InspectorOverlayImpl::highlightQuad(PassOwnPtr<FloatQuad> quad, const Inspe
ctorHighlightConfig& highlightConfig) |
293 { | 264 { |
294 m_quadHighlightConfig = highlightConfig; | 265 m_quadHighlightConfig = highlightConfig; |
295 m_highlightQuad = quad; | 266 m_highlightQuad = quad; |
296 m_omitTooltip = false; | 267 m_omitTooltip = false; |
297 update(); | 268 update(); |
298 } | 269 } |
299 | 270 |
300 void InspectorOverlayImpl::showAndHideViewSize(bool showGrid) | |
301 { | |
302 m_drawViewSize = true; | |
303 m_drawViewSizeWithGrid = showGrid; | |
304 update(); | |
305 m_timer.startOneShot(1, FROM_HERE); | |
306 } | |
307 | |
308 bool InspectorOverlayImpl::isEmpty() | 271 bool InspectorOverlayImpl::isEmpty() |
309 { | 272 { |
310 if (m_suspendCount) | 273 if (m_suspendCount) |
311 return true; | 274 return true; |
312 bool hasAlwaysVisibleElements = m_highlightNode || m_eventTargetNode || m_hi
ghlightQuad || m_drawViewSize; | 275 bool hasAlwaysVisibleElements = m_highlightNode || m_eventTargetNode || m_hi
ghlightQuad || (m_resizeTimerActive && m_drawViewSize); |
313 bool hasInvisibleInInspectModeElements = !m_pausedInDebuggerMessage.isNull()
; | 276 bool hasInvisibleInInspectModeElements = !m_pausedInDebuggerMessage.isNull()
; |
314 return !(hasAlwaysVisibleElements || (hasInvisibleInInspectModeElements && !
m_inspectModeEnabled)); | 277 return !(hasAlwaysVisibleElements || (hasInvisibleInInspectModeElements && !
m_inspectModeEnabled)); |
315 } | 278 } |
316 | 279 |
317 void InspectorOverlayImpl::update() | 280 void InspectorOverlayImpl::update() |
318 { | 281 { |
319 if (isEmpty()) { | 282 if (isEmpty()) { |
320 if (m_pageOverlay) | 283 if (m_pageOverlay) |
321 m_pageOverlay.clear(); | 284 m_pageOverlay.clear(); |
322 return; | 285 return; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 } | 344 } |
382 | 345 |
383 void InspectorOverlayImpl::drawPausedInDebuggerMessage() | 346 void InspectorOverlayImpl::drawPausedInDebuggerMessage() |
384 { | 347 { |
385 if (!m_pausedInDebuggerMessage.isNull()) | 348 if (!m_pausedInDebuggerMessage.isNull()) |
386 evaluateInOverlay("drawPausedInDebuggerMessage", m_pausedInDebuggerMessa
ge); | 349 evaluateInOverlay("drawPausedInDebuggerMessage", m_pausedInDebuggerMessa
ge); |
387 } | 350 } |
388 | 351 |
389 void InspectorOverlayImpl::drawViewSize() | 352 void InspectorOverlayImpl::drawViewSize() |
390 { | 353 { |
391 if (m_drawViewSize) | 354 if (m_resizeTimerActive && m_drawViewSize) |
392 evaluateInOverlay("drawViewSize", m_drawViewSizeWithGrid ? "true" : "fal
se"); | 355 evaluateInOverlay("drawViewSize", m_drawViewSizeWithGrid ? "true" : "fal
se"); |
393 } | 356 } |
394 | 357 |
395 Page* InspectorOverlayImpl::overlayPage() | 358 Page* InspectorOverlayImpl::overlayPage() |
396 { | 359 { |
397 if (m_overlayPage) | 360 if (m_overlayPage) |
398 return m_overlayPage.get(); | 361 return m_overlayPage.get(); |
399 | 362 |
400 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 363 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
401 | 364 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 { | 448 { |
486 ScriptForbiddenScope::AllowUserAgentScript allowScript; | 449 ScriptForbiddenScope::AllowUserAgentScript allowScript; |
487 RefPtr<JSONArray> command = JSONArray::create(); | 450 RefPtr<JSONArray> command = JSONArray::create(); |
488 command->pushString(method); | 451 command->pushString(method); |
489 command->pushValue(argument); | 452 command->pushValue(argument); |
490 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); | 453 toLocalFrame(overlayPage()->mainFrame())->script().executeScriptInMainWorld(
"dispatch(" + command->toJSONString() + ")", ScriptController::ExecuteScriptWhen
ScriptsDisabled); |
491 } | 454 } |
492 | 455 |
493 void InspectorOverlayImpl::onTimer(Timer<InspectorOverlayImpl>*) | 456 void InspectorOverlayImpl::onTimer(Timer<InspectorOverlayImpl>*) |
494 { | 457 { |
495 m_drawViewSize = false; | 458 m_resizeTimerActive = false; |
496 update(); | 459 update(); |
497 } | 460 } |
498 | 461 |
499 void InspectorOverlayImpl::clear() | 462 void InspectorOverlayImpl::clear() |
500 { | 463 { |
501 if (m_overlayPage) { | 464 if (m_overlayPage) { |
502 m_overlayPage->willBeDestroyed(); | 465 m_overlayPage->willBeDestroyed(); |
503 m_overlayPage.clear(); | 466 m_overlayPage.clear(); |
504 m_overlayChromeClient.clear(); | 467 m_overlayChromeClient.clear(); |
505 } | 468 } |
506 m_drawViewSize = false; | 469 m_resizeTimerActive = false; |
507 m_pausedInDebuggerMessage = String(); | 470 m_pausedInDebuggerMessage = String(); |
508 m_inspectModeEnabled = false; | 471 m_inspectModeEnabled = false; |
509 m_timer.stop(); | 472 m_timer.stop(); |
510 hideHighlight(); | 473 hideHighlight(); |
511 } | 474 } |
512 | 475 |
513 void InspectorOverlayImpl::overlayResumed() | 476 void InspectorOverlayImpl::overlayResumed() |
514 { | 477 { |
515 if (m_listener) | 478 if (m_debuggerAgent) { |
516 m_listener->overlayResumed(); | 479 ErrorString error; |
| 480 m_debuggerAgent->resume(&error); |
| 481 } |
517 } | 482 } |
518 | 483 |
519 void InspectorOverlayImpl::overlaySteppedOver() | 484 void InspectorOverlayImpl::overlaySteppedOver() |
520 { | 485 { |
521 if (m_listener) | 486 if (m_debuggerAgent) { |
522 m_listener->overlaySteppedOver(); | 487 ErrorString error; |
| 488 m_debuggerAgent->stepOver(&error); |
| 489 } |
523 } | 490 } |
524 | 491 |
525 void InspectorOverlayImpl::suspendUpdates() | 492 void InspectorOverlayImpl::profilingStarted() |
526 { | 493 { |
527 if (!m_suspendCount++) | 494 if (!m_suspendCount++) |
528 clear(); | 495 clear(); |
529 } | 496 } |
530 | 497 |
531 void InspectorOverlayImpl::resumeUpdates() | 498 void InspectorOverlayImpl::profilingStopped() |
532 { | 499 { |
533 --m_suspendCount; | 500 --m_suspendCount; |
534 } | 501 } |
535 | 502 |
536 void InspectorOverlayImpl::setLayoutEditor(PassOwnPtrWillBeRawPtr<LayoutEditor>
layoutEditor) | 503 void InspectorOverlayImpl::pageLayoutInvalidated(bool resized) |
537 { | 504 { |
538 m_layoutEditor = layoutEditor; | 505 if (resized && m_drawViewSize) { |
539 m_overlayHost->setLayoutEditorListener(m_layoutEditor.get()); | 506 m_resizeTimerActive = true; |
| 507 m_timer.startOneShot(1, FROM_HERE); |
| 508 } |
| 509 update(); |
| 510 } |
| 511 |
| 512 void InspectorOverlayImpl::setShowViewportSizeOnResize(bool show, bool showGrid) |
| 513 { |
| 514 m_drawViewSize = show; |
| 515 m_drawViewSizeWithGrid = showGrid; |
540 } | 516 } |
541 | 517 |
542 } // namespace blink | 518 } // namespace blink |
OLD | NEW |