Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Unified Diff: Source/core/dom/CompositorProxy.cpp

Issue 1025893002: compositor-worker: Add mutable attributes to CompositorProxy. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/CompositorProxy.h ('k') | Source/core/dom/CompositorProxy.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/CompositorProxy.cpp
diff --git a/Source/core/dom/CompositorProxy.cpp b/Source/core/dom/CompositorProxy.cpp
index 7c346997c79c0e9b869c97a8afd73d2fc85ba667..f656b9c65e8563d7dfbbfc6f96e5640fb5c10f06 100644
--- a/Source/core/dom/CompositorProxy.cpp
+++ b/Source/core/dom/CompositorProxy.cpp
@@ -8,6 +8,7 @@
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
#include "core/dom/DOMNodeIds.h"
+#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
namespace blink {
@@ -46,6 +47,30 @@ static CompositorProxy::Attributes attributeFlagForName(const String& attributeN
return attributeFlag;
}
+static bool isControlThread()
+{
+ return !isMainThread();
+}
+
+static bool isCallingCompositorFrameCallback()
+{
+ // TODO(sad): Check that the requestCompositorFrame callbacks are currently being called.
+ return true;
+}
+
+static bool raiseExceptionIfMutationNotAllowed(ExceptionState& exceptionState)
+{
+ if (!isControlThread()) {
+ exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mutate a proxy attribute from the main page.");
+ return true;
+ }
+ if (!isCallingCompositorFrameCallback()) {
+ exceptionState.throwDOMException(NoModificationAllowedError, "Cannot mutate a proxy attribute outside of a requestCompositorFrame callback.");
+ return true;
+ }
+ return false;
+}
+
static uint32_t attributesBitfieldFromNames(const Vector<String>& attributeArray)
{
uint32_t attributesBitfield = 0;
@@ -95,7 +120,7 @@ CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags)
: m_elementId(elementId)
, m_bitfieldsSupported(attributeFlags)
{
- ASSERT(!isMainThread());
+ ASSERT(isControlThread());
ASSERT(sanityCheckAttributeFlags(m_bitfieldsSupported));
}
@@ -108,4 +133,88 @@ bool CompositorProxy::supports(const String& attributeName) const
return !!(m_bitfieldsSupported & static_cast<uint32_t>(attributeFlagForName(attributeName)));
}
+double CompositorProxy::opacity(ExceptionState& exceptionState) const
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return 0.0;
+ if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
+ return 0.0;
+ return m_opacity;
+}
+
+double CompositorProxy::scrollLeft(ExceptionState& exceptionState) const
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return 0.0;
+ if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
+ return 0.0;
+ return m_scrollLeft;
+}
+
+double CompositorProxy::scrollTop(ExceptionState& exceptionState) const
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return 0.0;
+ if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
+ return 0.0;
+ return m_scrollTop;
+}
+
+DOMMatrix* CompositorProxy::transform(ExceptionState& exceptionState) const
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return nullptr;
+ if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
+ return nullptr;
+ return m_transform;
+}
+
+void CompositorProxy::setOpacity(double opacity, ExceptionState& exceptionState)
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return;
+ if (raiseExceptionIfNotMutable(Attributes::OPACITY, exceptionState))
+ return;
+ m_opacity = std::min(1., std::max(0., opacity));
+ m_mutatedAttributes |= static_cast<uint32_t>(Attributes::OPACITY);
+}
+
+void CompositorProxy::setScrollLeft(double scrollLeft, ExceptionState& exceptionState)
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return;
+ if (raiseExceptionIfNotMutable(Attributes::SCROLL_LEFT, exceptionState))
+ return;
+ m_scrollLeft = scrollLeft;
+ m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_LEFT);
+}
+
+void CompositorProxy::setScrollTop(double scrollTop, ExceptionState& exceptionState)
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return;
+ if (raiseExceptionIfNotMutable(Attributes::SCROLL_TOP, exceptionState))
+ return;
+ m_scrollTop = scrollTop;
+ m_mutatedAttributes |= static_cast<uint32_t>(Attributes::SCROLL_TOP);
+}
+
+void CompositorProxy::setTransform(DOMMatrix* transform, ExceptionState& exceptionState)
+{
+ if (raiseExceptionIfMutationNotAllowed(exceptionState))
+ return;
+ if (raiseExceptionIfNotMutable(Attributes::TRANSFORM, exceptionState))
+ return;
+ m_transform = transform;
+ m_mutatedAttributes |= static_cast<uint32_t>(Attributes::TRANSFORM);
+}
+
+bool CompositorProxy::raiseExceptionIfNotMutable(Attributes attribute, ExceptionState& exceptionState) const
+{
+ if (m_bitfieldsSupported & static_cast<uint32_t>(attribute))
+ return false;
+ exceptionState.throwDOMException(NoModificationAllowedError, "Attempted to mutate non-mutable attribute.");
+ return true;
+}
+
} // namespace blink
« no previous file with comments | « Source/core/dom/CompositorProxy.h ('k') | Source/core/dom/CompositorProxy.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698