| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/custom/CustomElementReaction.h" | 5 #include "core/dom/custom/CustomElementReaction.h" |
| 6 | 6 |
| 7 #include "core/dom/custom/CustomElementReactionQueue.h" | 7 #include "core/dom/custom/CustomElementReactionQueue.h" |
| 8 #include "platform/heap/Handle.h" | 8 #include "platform/heap/Handle.h" |
| 9 #include "wtf/Noncopyable.h" | |
| 10 #include <initializer_list> | 9 #include <initializer_list> |
| 11 #include <vector> | 10 #include <vector> |
| 12 | 11 |
| 13 namespace blink { | 12 namespace blink { |
| 14 | 13 |
| 15 class Element; | 14 class Element; |
| 16 | 15 |
| 17 class Command : public GarbageCollectedFinalized<Command> { | 16 class Command : public GarbageCollectedFinalized<Command> { |
| 18 WTF_MAKE_NONCOPYABLE(Command); | 17 DISALLOW_COPY_AND_ASSIGN(Command); |
| 19 public: | 18 public: |
| 20 Command() { } | 19 Command() { } |
| 21 virtual ~Command() { } | 20 virtual ~Command() { } |
| 22 DEFINE_INLINE_VIRTUAL_TRACE() { } | 21 DEFINE_INLINE_VIRTUAL_TRACE() { } |
| 23 virtual void run(Element*) = 0; | 22 virtual void run(Element*) = 0; |
| 24 }; | 23 }; |
| 25 | 24 |
| 26 class Log : public Command { | 25 class Log : public Command { |
| 27 WTF_MAKE_NONCOPYABLE(Log); | 26 DISALLOW_COPY_AND_ASSIGN(Log); |
| 28 public: | 27 public: |
| 29 Log(char what, std::vector<char>& where) : m_what(what), m_where(where) { } | 28 Log(char what, std::vector<char>& where) : m_what(what), m_where(where) { } |
| 30 virtual ~Log() { } | 29 virtual ~Log() { } |
| 31 void run(Element*) override { m_where.push_back(m_what); } | 30 void run(Element*) override { m_where.push_back(m_what); } |
| 32 private: | 31 private: |
| 33 char m_what; | 32 char m_what; |
| 34 std::vector<char>& m_where; | 33 std::vector<char>& m_where; |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 class Recurse : public Command { | 36 class Recurse : public Command { |
| 38 WTF_MAKE_NONCOPYABLE(Recurse); | 37 DISALLOW_COPY_AND_ASSIGN(Recurse); |
| 39 public: | 38 public: |
| 40 Recurse(CustomElementReactionQueue* queue) : m_queue(queue) { } | 39 Recurse(CustomElementReactionQueue* queue) : m_queue(queue) { } |
| 41 virtual ~Recurse() { } | 40 virtual ~Recurse() { } |
| 42 DEFINE_INLINE_VIRTUAL_TRACE() | 41 DEFINE_INLINE_VIRTUAL_TRACE() |
| 43 { | 42 { |
| 44 Command::trace(visitor); | 43 Command::trace(visitor); |
| 45 visitor->trace(m_queue); | 44 visitor->trace(m_queue); |
| 46 } | 45 } |
| 47 void run(Element* element) override { m_queue->invokeReactions(element); } | 46 void run(Element* element) override { m_queue->invokeReactions(element); } |
| 48 private: | 47 private: |
| 49 Member<CustomElementReactionQueue> m_queue; | 48 Member<CustomElementReactionQueue> m_queue; |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 class Enqueue : public Command { | 51 class Enqueue : public Command { |
| 53 WTF_MAKE_NONCOPYABLE(Enqueue); | 52 DISALLOW_COPY_AND_ASSIGN(Enqueue); |
| 54 public: | 53 public: |
| 55 Enqueue(CustomElementReactionQueue* queue, CustomElementReaction* reaction) | 54 Enqueue(CustomElementReactionQueue* queue, CustomElementReaction* reaction) |
| 56 : m_queue(queue) | 55 : m_queue(queue) |
| 57 , m_reaction(reaction) | 56 , m_reaction(reaction) |
| 58 { | 57 { |
| 59 } | 58 } |
| 60 virtual ~Enqueue() { } | 59 virtual ~Enqueue() { } |
| 61 DEFINE_INLINE_VIRTUAL_TRACE() | 60 DEFINE_INLINE_VIRTUAL_TRACE() |
| 62 { | 61 { |
| 63 Command::trace(visitor); | 62 Command::trace(visitor); |
| 64 visitor->trace(m_queue); | 63 visitor->trace(m_queue); |
| 65 visitor->trace(m_reaction); | 64 visitor->trace(m_reaction); |
| 66 } | 65 } |
| 67 void run(Element*) override | 66 void run(Element*) override |
| 68 { | 67 { |
| 69 m_queue->add(m_reaction); | 68 m_queue->add(m_reaction); |
| 70 } | 69 } |
| 71 private: | 70 private: |
| 72 Member<CustomElementReactionQueue> m_queue; | 71 Member<CustomElementReactionQueue> m_queue; |
| 73 Member<CustomElementReaction> m_reaction; | 72 Member<CustomElementReaction> m_reaction; |
| 74 }; | 73 }; |
| 75 | 74 |
| 76 class TestReaction : public CustomElementReaction { | 75 class TestReaction : public CustomElementReaction { |
| 77 WTF_MAKE_NONCOPYABLE(TestReaction); | 76 DISALLOW_COPY_AND_ASSIGN(TestReaction); |
| 78 public: | 77 public: |
| 79 TestReaction(std::initializer_list<Command*> commands) | 78 TestReaction(std::initializer_list<Command*> commands) |
| 80 { | 79 { |
| 81 // TODO(dominicc): Simply pass the initializer list when | 80 // TODO(dominicc): Simply pass the initializer list when |
| 82 // HeapVector supports initializer lists like Vector. | 81 // HeapVector supports initializer lists like Vector. |
| 83 for (auto& command : commands) | 82 for (auto& command : commands) |
| 84 m_commands.append(command); | 83 m_commands.append(command); |
| 85 } | 84 } |
| 86 virtual ~TestReaction() = default; | 85 virtual ~TestReaction() = default; |
| 87 DEFINE_INLINE_VIRTUAL_TRACE() | 86 DEFINE_INLINE_VIRTUAL_TRACE() |
| 88 { | 87 { |
| 89 CustomElementReaction::trace(visitor); | 88 CustomElementReaction::trace(visitor); |
| 90 visitor->trace(m_commands); | 89 visitor->trace(m_commands); |
| 91 } | 90 } |
| 92 void invoke(Element* element) override | 91 void invoke(Element* element) override |
| 93 { | 92 { |
| 94 for (auto& command : m_commands) | 93 for (auto& command : m_commands) |
| 95 command->run(element); | 94 command->run(element); |
| 96 } | 95 } |
| 97 | 96 |
| 98 private: | 97 private: |
| 99 HeapVector<Member<Command>> m_commands; | 98 HeapVector<Member<Command>> m_commands; |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |