Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/dom/CompositorProxy.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ExceptionMessages.h" | |
| 9 #include "bindings/core/v8/ExceptionState.h" | |
| 10 #include "core/dom/ExecutionContext.h" | |
| 11 #include "core/inspector/InspectorNodeIds.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 static struct { | |
| 16 const char* name; | |
| 17 CompositorProxy::Attributes attribute; | |
| 18 } allowedAttributes[] = { | |
|
esprehn
2015/03/25 23:21:48
Lets declare the struct and the usage separately,
sadrul
2015/03/27 17:23:28
Done.
| |
| 19 { "opacity", CompositorProxy::Attributes::OPACITY }, | |
| 20 { "scrolltop", CompositorProxy::Attributes::SCROLL_TOP }, | |
| 21 { "touch", CompositorProxy::Attributes::TOUCH }, | |
| 22 { "transform", CompositorProxy::Attributes::TRANSFORM }, | |
| 23 }; | |
| 24 | |
| 25 CompositorProxy* CompositorProxy::create(ExecutionContext* context, Element* ele ment, Vector<String>& attributeArray, ExceptionState& exceptionState) | |
|
esprehn
2015/03/25 23:21:48
OwnPtr, this leaks when not in Oilpan mode.
| |
| 26 { | |
| 27 if (!context->isDocument()) { | |
| 28 exceptionState.throwTypeError(ExceptionMessages::failedToConstruct("Comp ositorProxy", "Can only be created from the main context.")); | |
| 29 exceptionState.throwIfNeeded(); | |
| 30 return nullptr; | |
| 31 } | |
| 32 | |
| 33 uint32_t attributeFlags = 0; | |
| 34 for (const auto& attribute : attributeArray) { | |
| 35 Attributes currentAttribute = Attributes::NONE; | |
| 36 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) { | |
| 37 if (attribute.lower() == allowedAttributes[i].name) { | |
|
esprehn
2015/03/25 23:21:48
Call .lower() first and then use std::lower_bound
sadrul
2015/03/27 17:23:28
Done.
| |
| 38 currentAttribute = allowedAttributes[i].attribute; | |
| 39 } | |
| 40 } | |
| 41 if (currentAttribute == Attributes::NONE) { | |
| 42 exceptionState.throwTypeError("Unknown attribute'" + attribute + "'" ); | |
| 43 exceptionState.throwIfNeeded(); | |
| 44 return nullptr; | |
| 45 } | |
| 46 attributeFlags |= static_cast<uint32_t>(currentAttribute); | |
| 47 } | |
| 48 | |
| 49 ASSERT(attributeFlags); | |
|
esprehn
2015/03/25 23:21:48
This assert should be in the constructor?
sadrul
2015/03/27 17:23:28
Done.
| |
| 50 return new CompositorProxy(element, attributeFlags); | |
| 51 } | |
| 52 | |
| 53 CompositorProxy* CompositorProxy::create(uint64_t elementId, uint32_t attributeF lags) | |
| 54 { | |
| 55 ASSERT(!isMainThread()); | |
|
esprehn
2015/03/25 23:21:48
Move this assert into the constructor.
sadrul
2015/03/27 17:23:28
Done.
| |
| 56 #ifndef NDEBUG | |
| 57 uint32_t sanityCheckAttributes = attributeFlags; | |
|
esprehn
2015/03/25 23:21:48
This assert block for sanity checking should be in
sadrul
2015/03/27 17:23:28
Done.
| |
| 58 for (unsigned i = 0; i < arraysize(allowedAttributes); ++i) { | |
| 59 sanityCheckAttributes &= ~static_cast<uint32_t>(allowedAttributes[i].att ribute); | |
| 60 } | |
| 61 ASSERT(!sanityCheckAttributes); | |
| 62 #endif | |
| 63 return new CompositorProxy(elementId, attributeFlags); | |
| 64 } | |
| 65 | |
| 66 CompositorProxy::CompositorProxy(Element* element, uint32_t attributeFlags) | |
|
esprehn
2015/03/25 23:21:48
reference
sadrul
2015/03/27 17:23:28
Done.
| |
| 67 : m_elementId(InspectorNodeIds::idForNode(element)) | |
|
esprehn
2015/03/25 23:21:48
We should move InspectorNodeIds into code in a fir
sadrul
2015/03/27 17:23:28
Done. (https://codereview.chromium.org/997073004/)
| |
| 68 , m_attributes(attributeFlags) | |
| 69 { | |
| 70 ASSERT(isMainThread()); | |
| 71 } | |
| 72 | |
| 73 CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t attributeFlags) | |
| 74 : m_elementId(elementId) | |
| 75 , m_attributes(attributeFlags) | |
| 76 { | |
| 77 } | |
| 78 | |
| 79 CompositorProxy::~CompositorProxy() | |
| 80 { | |
| 81 } | |
| 82 | |
| 83 } // namespace blink | |
| OLD | NEW |