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