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 #ifndef DocumentOrShadowRoot_h | 5 #ifndef DocumentOrShadowRoot_h |
6 #define DocumentOrShadowRoot_h | 6 #define DocumentOrShadowRoot_h |
7 | 7 |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/dom/Fullscreen.h" |
9 #include "core/dom/shadow/ShadowRoot.h" | 10 #include "core/dom/shadow/ShadowRoot.h" |
10 #include "core/frame/UseCounter.h" | 11 #include "core/frame/UseCounter.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 class DocumentOrShadowRoot { | 15 class DocumentOrShadowRoot { |
15 public: | 16 public: |
16 static Element* activeElement(Document& document) | 17 static Element* activeElement(Document& document) |
17 { | 18 { |
18 return document.activeElement(); | 19 return document.activeElement(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // TODO(kochi): Once V0 code is removed, the following non-V1 check is u
nnecessary. | 70 // TODO(kochi): Once V0 code is removed, the following non-V1 check is u
nnecessary. |
70 // After V0 code is removed, we can use the same logic for Document and
ShadowRoot. | 71 // After V0 code is removed, we can use the same logic for Document and
ShadowRoot. |
71 if (!shadowRoot.isV1()) | 72 if (!shadowRoot.isV1()) |
72 return nullptr; | 73 return nullptr; |
73 UseCounter::count(shadowRoot.document(), UseCounter::ShadowRootPointerLo
ckElement); | 74 UseCounter::count(shadowRoot.document(), UseCounter::ShadowRootPointerLo
ckElement); |
74 const Element* target = shadowRoot.document().pointerLockElement(); | 75 const Element* target = shadowRoot.document().pointerLockElement(); |
75 if (!target) | 76 if (!target) |
76 return nullptr; | 77 return nullptr; |
77 return shadowRoot.adjustedElement(*target); | 78 return shadowRoot.adjustedElement(*target); |
78 } | 79 } |
| 80 |
| 81 static Element* currentFullScreenElement(Document& document) |
| 82 { |
| 83 Element* element = Fullscreen::currentFullScreenElementFrom(document); |
| 84 if (!element) |
| 85 return nullptr; |
| 86 |
| 87 // For Shadow DOM V0 compatibility: We allow returning an element in V0
shadow tree, |
| 88 // even though it leaks the Shadow DOM. |
| 89 // TODO(kochi): Once V0 code is removed, the following V0 check is unnec
essary. |
| 90 if (element->isInV0ShadowTree()) { |
| 91 UseCounter::count(document, UseCounter::DocumentFullscreenElementInV
0Shadow); |
| 92 return element; |
| 93 } |
| 94 return document.adjustedElement(*element); |
| 95 } |
| 96 |
| 97 static Element* currentFullScreenElement(ShadowRoot& shadowRoot) |
| 98 { |
| 99 // TODO(kochi): Once V0 code is removed, the following non-V1 check is u
nnecessary. |
| 100 // After V0 code is removed, we can use the same logic for Document and
ShadowRoot. |
| 101 if (!shadowRoot.isV1()) |
| 102 return nullptr; |
| 103 |
| 104 Element* element = Fullscreen::currentFullScreenElementFrom(shadowRoot.d
ocument()); |
| 105 return element ? shadowRoot.adjustedElement(*element) : nullptr; |
| 106 } |
| 107 |
| 108 static Element* fullscreenElement(Document& document) |
| 109 { |
| 110 Element* element = Fullscreen::fullscreenElementFrom(document); |
| 111 if (!element) |
| 112 return nullptr; |
| 113 |
| 114 // For Shadow DOM V0 compatibility: We allow returning an element in V0
shadow tree, |
| 115 // even though it leaks the Shadow DOM. |
| 116 // TODO(kochi): Once V0 code is removed, the following V0 check is unnec
essary. |
| 117 if (element->isInV0ShadowTree()) { |
| 118 UseCounter::count(document, UseCounter::DocumentFullscreenElementInV
0Shadow); |
| 119 return element; |
| 120 } |
| 121 return document.adjustedElement(*element); |
| 122 } |
| 123 |
| 124 static Element* fullscreenElement(ShadowRoot& shadowRoot) |
| 125 { |
| 126 // TODO(kochi): Once V0 code is removed, the following non-V1 check is u
nnecessary. |
| 127 // After V0 code is removed, we can use the same logic for Document and
ShadowRoot. |
| 128 if (!shadowRoot.isV1()) |
| 129 return nullptr; |
| 130 |
| 131 Element* element = Fullscreen::fullscreenElementFrom(shadowRoot.document
()); |
| 132 return element ? shadowRoot.adjustedElement(*element) : nullptr; |
| 133 } |
79 }; | 134 }; |
80 | 135 |
81 } // namespace blink | 136 } // namespace blink |
82 | 137 |
83 #endif // DocumentOrShadowRoot_h | 138 #endif // DocumentOrShadowRoot_h |
OLD | NEW |