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 "core/dom/CompositorProxy.h" | 5 #include "core/dom/CompositorProxy.h" |
6 | 6 |
7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
9 #include "core/dom/DOMNodeIds.h" | 9 #include "core/dom/DOMNodeIds.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 { | 168 { |
169 return m_compositorMutableProperties & compositorMutablePropertyForName(attr ibuteName); | 169 return m_compositorMutableProperties & compositorMutablePropertyForName(attr ibuteName); |
170 } | 170 } |
171 | 171 |
172 double CompositorProxy::opacity(ExceptionState& exceptionState) const | 172 double CompositorProxy::opacity(ExceptionState& exceptionState) const |
173 { | 173 { |
174 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 174 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
175 return 0.0; | 175 return 0.0; |
176 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio nState)) | 176 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio nState)) |
177 return 0.0; | 177 return 0.0; |
178 return m_opacity; | 178 if (!m_state.get()) |
179 return 0.0; | |
180 return m_state->opacity(); | |
179 } | 181 } |
180 | 182 |
181 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const | 183 double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const |
182 { | 184 { |
183 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 185 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
184 return 0.0; | 186 return 0.0; |
185 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep tionState)) | 187 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep tionState)) |
186 return 0.0; | 188 return 0.0; |
187 return m_scrollLeft; | 189 if (!m_state.get()) |
190 return 0.0; | |
191 return m_state->scrollLeft(); | |
188 } | 192 } |
189 | 193 |
190 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const | 194 double CompositorProxy::scrollTop(ExceptionState& exceptionState) const |
191 { | 195 { |
192 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 196 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
193 return 0.0; | 197 return 0.0; |
194 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except ionState)) | 198 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except ionState)) |
195 return 0.0; | 199 return 0.0; |
196 return m_scrollTop; | 200 if (!m_state.get()) |
201 return 0.0; | |
202 return m_state->scrollTop(); | |
197 } | 203 } |
198 | 204 |
199 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const | 205 DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const |
200 { | 206 { |
201 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 207 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
202 return nullptr; | 208 return nullptr; |
203 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except ionState)) | 209 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except ionState)) |
204 return nullptr; | 210 return nullptr; |
205 return m_transform; | 211 if (!m_state.get()) |
jbroman
2016/06/08 14:59:38
nit: both std::unique_ptr and WTF::OwnPtr have ope
| |
212 return DOMMatrix::create(); | |
213 return DOMMatrix::create(m_state->transform()); | |
206 } | 214 } |
207 | 215 |
208 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) | 216 void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState) |
209 { | 217 { |
210 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 218 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
211 return; | 219 return; |
212 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio nState)) | 220 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kOpacity, exceptio nState)) |
213 return; | 221 return; |
214 m_opacity = std::min(1., std::max(0., opacity)); | 222 if (!m_state.get()) |
215 m_mutatedProperties |= CompositorMutableProperty::kTransform; | 223 return; |
224 | |
225 m_state->setOpacity(std::min(1., std::max(0., opacity))); | |
216 } | 226 } |
217 | 227 |
218 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State) | 228 void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exception State) |
219 { | 229 { |
220 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 230 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
221 return; | 231 return; |
222 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep tionState)) | 232 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollLeft, excep tionState)) |
223 return; | 233 return; |
224 m_scrollLeft = scrollLeft; | 234 if (!m_state.get()) |
225 m_mutatedProperties |= CompositorMutableProperty::kScrollLeft; | 235 return; |
236 m_state->setScrollLeft(scrollLeft); | |
226 } | 237 } |
227 | 238 |
228 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate) | 239 void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionSt ate) |
229 { | 240 { |
230 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 241 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
231 return; | 242 return; |
232 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except ionState)) | 243 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kScrollTop, except ionState)) |
233 return; | 244 return; |
234 m_scrollTop = scrollTop; | 245 if (!m_state.get()) |
235 m_mutatedProperties |= CompositorMutableProperty::kScrollTop; | 246 return; |
247 m_state->setScrollTop(scrollTop); | |
236 } | 248 } |
237 | 249 |
238 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState) | 250 void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& excepti onState) |
239 { | 251 { |
240 if (raiseExceptionIfMutationNotAllowed(exceptionState)) | 252 if (raiseExceptionIfMutationNotAllowed(exceptionState)) |
241 return; | 253 return; |
242 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except ionState)) | 254 if (raiseExceptionIfNotMutable(CompositorMutableProperty::kTransform, except ionState)) |
243 return; | 255 return; |
244 m_transform = transform; | 256 if (!m_state.get()) |
245 m_mutatedProperties |= CompositorMutableProperty::kTransform; | 257 return; |
258 m_state->setTransform(TransformationMatrix::toSkMatrix44(transform->matrix() )); | |
259 } | |
260 | |
261 void CompositorProxy::takeCompositorMutableState(std::unique_ptr<CompositorMutab leState> state) | |
262 { | |
263 m_state = std::move(state); | |
246 } | 264 } |
247 | 265 |
248 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const | 266 bool CompositorProxy::raiseExceptionIfNotMutable(uint32_t property, ExceptionSta te& exceptionState) const |
249 { | 267 { |
250 if (m_connected && (m_compositorMutableProperties & property)) | 268 if (m_connected && (m_compositorMutableProperties & property)) |
251 return false; | 269 return false; |
252 exceptionState.throwDOMException(NoModificationAllowedError, | 270 exceptionState.throwDOMException(NoModificationAllowedError, |
253 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); | 271 m_connected ? "Attempted to mutate non-mutable attribute." : "Attempted to mutate attribute on a disconnected proxy."); |
254 return true; | 272 return true; |
255 } | 273 } |
256 | 274 |
257 void CompositorProxy::disconnect() | 275 void CompositorProxy::disconnect() |
258 { | 276 { |
259 if (!m_connected) | 277 if (!m_connected) |
260 return; | 278 return; |
261 m_connected = false; | 279 m_connected = false; |
262 if (isMainThread()) { | 280 if (isMainThread()) { |
263 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); | 281 decrementCompositorProxiedPropertiesForElement(m_elementId, m_compositor MutableProperties); |
264 } else { | 282 } else { |
265 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); | 283 Platform::current()->mainThread()->getWebTaskRunner()->postTask(BLINK_FR OM_HERE, threadSafeBind(&decrementCompositorProxiedPropertiesForElement, m_eleme ntId, m_compositorMutableProperties)); |
266 if (m_client) | 284 if (m_client) |
267 m_client->unregisterCompositorProxy(this); | 285 m_client->unregisterCompositorProxy(this); |
268 } | 286 } |
269 } | 287 } |
270 | 288 |
271 } // namespace blink | 289 } // namespace blink |
OLD | NEW |