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" |
11 #include "platform/geometry/DoubleRect.h" | 11 #include "platform/geometry/DoubleRect.h" |
12 #include "public/platform/WebViewScheduler.h" | 12 #include "public/platform/WebViewScheduler.h" |
13 #include "web/DevToolsEmulator.h" | 13 #include "web/DevToolsEmulator.h" |
14 #include "web/WebLocalFrameImpl.h" | 14 #include "web/WebLocalFrameImpl.h" |
15 #include "web/WebViewImpl.h" | 15 #include "web/WebViewImpl.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 namespace { | |
20 static const double kMaxScale = 10.0; | |
21 } // namespace | |
22 | |
19 namespace EmulationAgentState { | 23 namespace EmulationAgentState { |
24 static const char scrollAndScaleOverrideEnabled[] = "scrollAndScaleOverrideEnabl ed"; | |
25 static const char framePositionXOverride[] = "framePositionXOverride"; | |
26 static const char framePositionYOverride[] = "framePositionYOverride"; | |
27 static const char visualViewportPositionXOverride[] = "visualViewportPositionXOv erride"; | |
28 static const char visualViewportPositionYOverride[] = "visualViewportPositionYOv erride"; | |
29 static const char pageScaleOverride[] = "pageScaleOverride"; | |
20 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; | 30 static const char scriptExecutionDisabled[] = "scriptExecutionDisabled"; |
21 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; | 31 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; |
22 static const char emulatedMedia[] = "emulatedMedia"; | 32 static const char emulatedMedia[] = "emulatedMedia"; |
23 } | 33 } |
24 | 34 |
25 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) | 35 InspectorEmulationAgent* InspectorEmulationAgent::create(WebLocalFrameImpl* webL ocalFrameImpl, Client* client) |
26 { | 36 { |
27 return new InspectorEmulationAgent(webLocalFrameImpl, client); | 37 return new InspectorEmulationAgent(webLocalFrameImpl, client); |
28 } | 38 } |
29 | 39 |
30 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) | 40 InspectorEmulationAgent::InspectorEmulationAgent(WebLocalFrameImpl* webLocalFram eImpl, Client* client) |
31 : m_webLocalFrameImpl(webLocalFrameImpl) | 41 : m_webLocalFrameImpl(webLocalFrameImpl) |
32 , m_client(client) | 42 , m_client(client) |
33 { | 43 { |
34 } | 44 } |
35 | 45 |
36 InspectorEmulationAgent::~InspectorEmulationAgent() | 46 InspectorEmulationAgent::~InspectorEmulationAgent() |
37 { | 47 { |
38 } | 48 } |
39 | 49 |
40 WebViewImpl* InspectorEmulationAgent::webViewImpl() | 50 WebViewImpl* InspectorEmulationAgent::webViewImpl() |
41 { | 51 { |
42 return m_webLocalFrameImpl->viewImpl(); | 52 return m_webLocalFrameImpl->viewImpl(); |
43 } | 53 } |
44 | 54 |
45 void InspectorEmulationAgent::restore() | 55 void InspectorEmulationAgent::restore() |
46 { | 56 { |
47 ErrorString error; | 57 ErrorString error; |
58 if (m_state->booleanProperty(EmulationAgentState::scrollAndScaleOverrideEnab led, false)) { | |
dgozman
2016/07/21 20:54:09
if (!m_state....)
Eric Seckler
2016/07/22 14:44:48
Whoops, thanks for spotting :)
| |
59 clearScrollAndScaleOverride(&error); | |
60 } else { | |
61 setScrollAndScaleOverride( | |
62 &error, | |
63 m_state->integerProperty(EmulationAgentState::framePositionXOverride , -1), | |
64 m_state->integerProperty(EmulationAgentState::framePositionYOverride , -1), | |
65 m_state->doubleProperty(EmulationAgentState::visualViewportPositionX Override, -1), | |
66 m_state->doubleProperty(EmulationAgentState::visualViewportPositionY Override, -1), | |
67 m_state->doubleProperty(EmulationAgentState::pageScaleOverride, 0)); | |
68 } | |
48 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false)); | 69 setScriptExecutionDisabled(&error, m_state->booleanProperty(EmulationAgentSt ate::scriptExecutionDisabled, false)); |
49 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>()); | 70 setTouchEmulationEnabled(&error, m_state->booleanProperty(EmulationAgentStat e::touchEventEmulationEnabled, false), protocol::Maybe<String>()); |
50 String16 emulatedMedia; | 71 String16 emulatedMedia; |
51 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); | 72 m_state->getString(EmulationAgentState::emulatedMedia, &emulatedMedia); |
52 setEmulatedMedia(&error, emulatedMedia); | 73 setEmulatedMedia(&error, emulatedMedia); |
53 } | 74 } |
54 | 75 |
55 void InspectorEmulationAgent::disable(ErrorString*) | 76 void InspectorEmulationAgent::disable(ErrorString*) |
56 { | 77 { |
57 ErrorString error; | 78 ErrorString error; |
79 clearScrollAndScaleOverride(&error); | |
58 setScriptExecutionDisabled(&error, false); | 80 setScriptExecutionDisabled(&error, false); |
59 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); | 81 setTouchEmulationEnabled(&error, false, protocol::Maybe<String>()); |
60 setEmulatedMedia(&error, String()); | 82 setEmulatedMedia(&error, String()); |
61 } | 83 } |
62 | 84 |
85 void InspectorEmulationAgent::setScrollAndScaleOverride(ErrorString* errorString , const Maybe<int>& scrollPositionX, const Maybe<int>& scrollPositionY, const Ma ybe<double>& visualViewportPositionX, const Maybe<double>& visualViewportPositio nY, const Maybe<double>& visualViewportScale) | |
86 { | |
87 if ((scrollPositionX.isJust() && scrollPositionX.fromJust() < 0 && scrollPos itionX.fromJust() != -1) | |
88 || (scrollPositionY.isJust() && scrollPositionY.fromJust() < 0 && scroll PositionY.fromJust() != -1)) { | |
89 *errorString = "Scroll position coordinates must be non-negative or -1 ( disabled)"; | |
dgozman
2016/07/21 20:54:09
Let's not treat -1 as disabled. We have "optional"
Eric Seckler
2016/07/22 14:44:48
Done. I was conflicted about this, too, since allo
| |
90 return; | |
91 } | |
92 | |
93 if ((visualViewportPositionX.isJust() && visualViewportPositionX.fromJust() < 0 && visualViewportPositionX.fromJust() != -1) | |
94 || (visualViewportPositionY.isJust() && visualViewportPositionY.fromJust () < 0 && visualViewportPositionY.fromJust() != -1)) { | |
95 *errorString = "Visual viewport position coordinates must be non-negativ e or -1 (disabled)"; | |
96 return; | |
97 } | |
98 | |
99 if (visualViewportScale.isJust() && (visualViewportScale.fromJust() < 0 || v isualViewportScale.fromJust() > kMaxScale)) { | |
100 *errorString = "Scale must be positive and not greater than " + Decimal: :fromDouble(kMaxScale).toString() + " or 0 (disabled)"; | |
101 } | |
102 | |
103 setScrollAndScaleOverride( | |
104 scrollPositionX.fromMaybe(-1), | |
105 scrollPositionY.fromMaybe(-1), | |
106 visualViewportPositionX.fromMaybe(-1), | |
107 visualViewportPositionY.fromMaybe(-1), | |
108 visualViewportScale.fromMaybe(0)); | |
109 } | |
110 | |
111 void InspectorEmulationAgent::setScrollAndScaleOverride(int framePositionX, int framePositionY, double visualViewportPositionX, double visualViewportPositionY, double pageScale) | |
112 { | |
113 m_state->setBoolean(EmulationAgentState::scrollAndScaleOverrideEnabled, true ); | |
114 m_state->setInteger(EmulationAgentState::framePositionXOverride, framePositi onX); | |
115 m_state->setInteger(EmulationAgentState::framePositionYOverride, framePositi onY); | |
116 m_state->setDouble(EmulationAgentState::visualViewportPositionXOverride, vis ualViewportPositionX); | |
117 m_state->setDouble(EmulationAgentState::visualViewportPositionYOverride, vis ualViewportPositionY); | |
118 m_state->setDouble(EmulationAgentState::pageScaleOverride, pageScale); | |
119 | |
120 webViewImpl()->setScrollAndScaleOverride( | |
121 IntPoint(framePositionX, framePositionY), | |
122 FloatPoint(visualViewportPositionX, visualViewportPositionY), | |
123 pageScale); | |
124 } | |
125 | |
126 void InspectorEmulationAgent::clearScrollAndScaleOverride(ErrorString*) | |
127 { | |
128 m_state->setBoolean(EmulationAgentState::scrollAndScaleOverrideEnabled, fals e); | |
129 webViewImpl()->clearScrollAndScaleOverride(); | |
130 } | |
131 | |
63 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) | 132 void InspectorEmulationAgent::resetPageScaleFactor(ErrorString*) |
64 { | 133 { |
65 webViewImpl()->resetScaleStateImmediately(); | 134 webViewImpl()->resetScaleStateImmediately(); |
66 } | 135 } |
67 | 136 |
68 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor) | 137 void InspectorEmulationAgent::setPageScaleFactor(ErrorString*, double pageScaleF actor) |
69 { | 138 { |
70 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); | 139 webViewImpl()->setPageScaleFactor(static_cast<float>(pageScaleFactor)); |
71 } | 140 } |
72 | 141 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 } | 176 } |
108 } | 177 } |
109 | 178 |
110 DEFINE_TRACE(InspectorEmulationAgent) | 179 DEFINE_TRACE(InspectorEmulationAgent) |
111 { | 180 { |
112 visitor->trace(m_webLocalFrameImpl); | 181 visitor->trace(m_webLocalFrameImpl); |
113 InspectorBaseAgent::trace(visitor); | 182 InspectorBaseAgent::trace(visitor); |
114 } | 183 } |
115 | 184 |
116 } // namespace blink | 185 } // namespace blink |
OLD | NEW |