OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "web/InspectorEmulationAgent.h" | 5 #include "web/InspectorEmulationAgent.h" |
6 | 6 |
7 #include "core/frame/FrameHost.h" | 7 #include "core/frame/FrameHost.h" |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/frame/Settings.h" | 9 #include "core/frame/Settings.h" |
10 #include "core/page/Page.h" | 10 #include "core/page/Page.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 PassOwnPtrWillBeRawPtr<InspectorEmulationAgent> InspectorEmulationAgent::create(
WebLocalFrameImpl* webLocalFrameImpl, Client* client) | 24 PassOwnPtrWillBeRawPtr<InspectorEmulationAgent> InspectorEmulationAgent::create(
WebLocalFrameImpl* webLocalFrameImpl, Client* client) |
25 { | 25 { |
26 return adoptPtrWillBeNoop(new InspectorEmulationAgent(webLocalFrameImpl, cli
ent)); | 26 return adoptPtrWillBeNoop(new InspectorEmulationAgent(webLocalFrameImpl, cli
ent)); |
27 } | 27 } |
28 | 28 |
29 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram
eImpl, Client* client) | 29 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram
eImpl, Client* client) |
30 : InspectorBaseAgent<InspectorEmulationAgent, InspectorFrontend::Emulation>(
"Emulation") | 30 : InspectorBaseAgent<InspectorEmulationAgent, InspectorFrontend::Emulation>(
"Emulation") |
31 , m_webLocalFrameImpl(webLocalFrameImpl) | 31 , m_webLocalFrameImpl(webLocalFrameImpl) |
32 , m_client(client) | 32 , m_client(client) |
33 { | 33 { |
34 webViewImpl()->devToolsEmulator()->setEmulationAgent(this); | |
35 } | 34 } |
36 | 35 |
37 InspectorEmulationAgent::~InspectorEmulationAgent() | 36 InspectorEmulationAgent::~InspectorEmulationAgent() |
38 { | 37 { |
39 } | 38 } |
40 | 39 |
41 WebViewImpl* InspectorEmulationAgent::webViewImpl() | 40 WebViewImpl* InspectorEmulationAgent::webViewImpl() |
42 { | 41 { |
43 return m_webLocalFrameImpl->viewImpl(); | 42 return m_webLocalFrameImpl->viewImpl(); |
44 } | 43 } |
45 | 44 |
46 void InspectorEmulationAgent::restore() | 45 void InspectorEmulationAgent::restore() |
47 { | 46 { |
48 ErrorString error; | 47 ErrorString error; |
49 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt
ate::scriptExecutionDisabled, false)); | 48 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt
ate::scriptExecutionDisabled, false)); |
50 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat
e::touchEventEmulationEnabled, false), nullptr); | 49 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat
e::touchEventEmulationEnabled, false), nullptr); |
51 String emulatedMedia; | 50 String emulatedMedia; |
52 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); | 51 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); |
53 setEmulatedMedia(&error, emulatedMedia); | 52 setEmulatedMedia(&error, emulatedMedia); |
54 } | 53 } |
55 | 54 |
56 void InspectorEmulationAgent::disable(ErrorString*) | 55 void InspectorEmulationAgent::disable(ErrorString*) |
57 { | 56 { |
58 ErrorString error; | 57 ErrorString error; |
59 setScriptExecutionDisabled(&error, false); | 58 setScriptExecutionDisabled(&error, false); |
60 setTouchEmulationEnabled(&error, false, nullptr); | 59 setTouchEmulationEnabled(&error, false, nullptr); |
61 setEmulatedMedia(&error, String()); | 60 setEmulatedMedia(&error, String()); |
62 } | 61 } |
63 | 62 |
64 void InspectorEmulationAgent::discardAgent() | |
65 { | |
66 webViewImpl()->devToolsEmulator()->setEmulationAgent(nullptr); | |
67 } | |
68 | |
69 void InspectorEmulationAgent::didCommitLoadForLocalFrame(LocalFrame* frame) | |
70 { | |
71 if (frame == m_webLocalFrameImpl->frame()) | |
72 viewportChanged(); | |
73 } | |
74 | |
75 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) | 63 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) |
76 { | 64 { |
77 webViewImpl()->resetScaleStateImmediately(); | 65 webViewImpl()->resetScaleStateImmediately(); |
78 } | 66 } |
79 | 67 |
80 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF
actor) | 68 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF
actor) |
81 { | 69 { |
82 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); | 70 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); |
83 } | 71 } |
84 | 72 |
(...skipping 13 matching lines...) Expand all Loading... |
98 { | 86 { |
99 m_state->setString(EmulationAgentState::emulatedMedia, media); | 87 m_state->setString(EmulationAgentState::emulatedMedia, media); |
100 webViewImpl()->page()->settings().setMediaTypeOverride(media); | 88 webViewImpl()->page()->settings().setMediaTypeOverride(media); |
101 } | 89 } |
102 | 90 |
103 void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, double throttli
ngRate) | 91 void InspectorEmulationAgent::setCPUThrottlingRate(ErrorString*, double throttli
ngRate) |
104 { | 92 { |
105 m_client->setCPUThrottlingRate(throttlingRate); | 93 m_client->setCPUThrottlingRate(throttlingRate); |
106 } | 94 } |
107 | 95 |
108 void InspectorEmulationAgent::viewportChanged() | |
109 { | |
110 if (!webViewImpl()->devToolsEmulator()->deviceEmulationEnabled() || !fronten
d()) | |
111 return; | |
112 | |
113 FrameView* view = m_webLocalFrameImpl->frameView(); | |
114 if (!view) | |
115 return; | |
116 | |
117 IntSize contentsSize = view->contentsSize(); | |
118 FloatPoint scrollOffset; | |
119 scrollOffset = FloatPoint(view->scrollableArea()->visibleContentRectDouble()
.location()); | |
120 | |
121 RefPtr<TypeBuilder::Emulation::Viewport> viewport = TypeBuilder::Emulation::
Viewport::create() | |
122 .setScrollX(scrollOffset.x()) | |
123 .setScrollY(scrollOffset.y()) | |
124 .setContentsWidth(contentsSize.width()) | |
125 .setContentsHeight(contentsSize.height()) | |
126 .setPageScaleFactor(webViewImpl()->page()->pageScaleFactor()) | |
127 .setMinimumPageScaleFactor(webViewImpl()->minimumPageScaleFactor()) | |
128 .setMaximumPageScaleFactor(webViewImpl()->maximumPageScaleFactor()); | |
129 frontend()->viewportChanged(viewport); | |
130 } | |
131 | |
132 DEFINE_TRACE(InspectorEmulationAgent) | 96 DEFINE_TRACE(InspectorEmulationAgent) |
133 { | 97 { |
134 visitor->trace(m_webLocalFrameImpl); | 98 visitor->trace(m_webLocalFrameImpl); |
135 InspectorBaseAgent::trace(visitor); | 99 InspectorBaseAgent::trace(visitor); |
136 } | 100 } |
137 | 101 |
138 } // namespace blink | 102 } // namespace blink |
OLD | NEW |