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 #ifndef DisplayItemClient_h | 5 #ifndef DisplayItemClient_h |
6 #define DisplayItemClient_h | 6 #define DisplayItemClient_h |
7 | 7 |
8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
9 #include "platform/heap/Heap.h" | |
10 #include "wtf/text/WTFString.h" | 9 #include "wtf/text/WTFString.h" |
11 | 10 |
12 namespace blink { | 11 namespace blink { |
13 | 12 |
14 class DisplayItemClientInternalVoid; | 13 class PLATFORM_EXPORT DisplayItemClient { |
pdr.
2015/12/05 21:39:19
Lets add a comment about what this class is for.
Xianzhu
2015/12/07 17:14:01
Added an one-line comment.
I think we can address
| |
15 using DisplayItemClient = const DisplayItemClientInternalVoid*; | 14 public: |
15 virtual ~DisplayItemClient() { } | |
16 | 16 |
17 inline DisplayItemClient toDisplayItemClient(const void* object) { return static _cast<DisplayItemClient>(object); } | 17 virtual String debugName() const = 0; |
pdr.
2015/12/05 21:39:19
I think we have a potential diamond inheritance is
Xianzhu
2015/12/07 17:14:01
It seems that the compilers allow multiple inherit
| |
18 }; | |
18 | 19 |
19 // Used to pass DisplayItemClient and debugName() (called only when needed) from | 20 inline bool operator==(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 == &client2; } |
20 // core/layout module etc. to platform/paint module. | 21 inline bool operator!=(const DisplayItemClient& client1, const DisplayItemClient & client2) { return &client1 != &client2; } |
21 // The instance must not out-live the object. Long-time reference to a client mu st | |
22 // use DisplayItemClient. | |
23 class PLATFORM_EXPORT DisplayItemClientWrapper final { | |
24 DISALLOW_NEW(); // Allow allocated in stack or in another object only. | |
25 public: | |
26 template <typename T> | |
27 DisplayItemClientWrapper(const T& object) | |
28 : m_displayItemClient(object.displayItemClient()) | |
29 , m_object(reinterpret_cast<const GenericClass&>(object)) | |
30 , m_debugNameInvoker(&invokeDebugName<T>) | |
31 { } | |
32 | |
33 DisplayItemClientWrapper(const DisplayItemClientWrapper& other) | |
34 : m_displayItemClient(other.m_displayItemClient) | |
35 , m_object(other.m_object) | |
36 , m_debugNameInvoker(other.m_debugNameInvoker) | |
37 { } | |
38 | |
39 DisplayItemClient displayItemClient() const { return m_displayItemClient; } | |
40 String debugName() const { return m_debugNameInvoker(m_object); } | |
41 | |
42 private: | |
43 DisplayItemClientWrapper& operator=(const DisplayItemClientWrapper&) = delet e; | |
44 | |
45 class GenericClass; | |
46 template <typename T> | |
47 static String invokeDebugName(const GenericClass& object) { return reinterpr et_cast<const T&>(object).debugName(); } | |
48 | |
49 DisplayItemClient m_displayItemClient; | |
50 const GenericClass& m_object; | |
51 using DebugNameInvoker = String(*)(const GenericClass&); | |
52 DebugNameInvoker m_debugNameInvoker; | |
53 }; | |
54 | 22 |
55 } | 23 } |
56 | 24 |
57 #endif // DisplayItemClient_h | 25 #endif // DisplayItemClient_h |
OLD | NEW |