Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: third_party/WebKit/Source/core/dom/Fullscreen.cpp

Issue 2565183002: Add a nextLocalAncestor helper for Fullscreen (Closed)
Patch Set: early return Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All
7 * rights reserved. 7 * rights reserved.
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/) 9 * (http://www.torchmobile.com/)
10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 10 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 187 }
188 188
189 Event* createEvent(const AtomicString& type, EventTarget& target) { 189 Event* createEvent(const AtomicString& type, EventTarget& target) {
190 EventInit initializer; 190 EventInit initializer;
191 initializer.setBubbles(isPrefixed(type)); 191 initializer.setBubbles(isPrefixed(type));
192 Event* event = Event::create(type, initializer); 192 Event* event = Event::create(type, initializer);
193 event->setTarget(&target); 193 event->setTarget(&target);
194 return event; 194 return event;
195 } 195 }
196 196
197 // Walks the frame tree and returns the first local ancestor frame, if any.
198 LocalFrame* nextLocalAncestor(Frame& frame) {
199 Frame* parent = frame.tree().parent();
200 if (!parent)
201 return nullptr;
202 if (parent->isLocalFrame())
203 return toLocalFrame(parent);
204 return nextLocalAncestor(*parent);
205 }
206
207 // Walks the document's frame tree and returns the document of the first local
208 // ancestor frame, if any.
209 Document* nextLocalAncestor(Document& document) {
210 LocalFrame* frame = document.frame();
211 if (!frame)
212 return nullptr;
213 LocalFrame* next = nextLocalAncestor(*document.frame());
214 if (!next)
215 return nullptr;
216 DCHECK(next->document());
217 return next->document();
218 }
219
197 // Helper to walk the ancestor chain and return the Document of the topmost 220 // Helper to walk the ancestor chain and return the Document of the topmost
198 // local ancestor frame. Note that this is not the same as the topmost frame's 221 // local ancestor frame. Note that this is not the same as the topmost frame's
199 // Document, which might be unavailable in OOPIF scenarios. For example, with 222 // Document, which might be unavailable in OOPIF scenarios. For example, with
200 // OOPIFs, when called on the bottom frame's Document in a A-B-C-B hierarchy in 223 // OOPIFs, when called on the bottom frame's Document in a A-B-C-B hierarchy in
201 // process B, this will skip remote frame C and return this frame: A-[B]-C-B. 224 // process B, this will skip remote frame C and return this frame: A-[B]-C-B.
202 Document& topmostLocalAncestor(Document& document) { 225 Document& topmostLocalAncestor(Document& document) {
203 Document* topmost = &document; 226 if (Document* next = nextLocalAncestor(document))
204 Frame* frame = document.frame(); 227 return topmostLocalAncestor(*next);
205 while (frame) { 228 return document;
206 frame = frame->tree().parent();
207 if (frame && frame->isLocalFrame())
208 topmost = toLocalFrame(frame)->document();
209 }
210 return *topmost;
211 } 229 }
212 230
213 // Helper to find the browsing context container in |doc| that embeds the 231 // Helper to find the browsing context container in |doc| that embeds the
214 // |descendant| Document, possibly through multiple levels of nesting. This 232 // |descendant| Document, possibly through multiple levels of nesting. This
215 // works even in OOPIF scenarios like A-B-A, where there may be remote frames 233 // works even in OOPIF scenarios like A-B-A, where there may be remote frames
216 // in between |doc| and |descendant|. 234 // in between |doc| and |descendant|.
217 HTMLFrameOwnerElement* findContainerForDescendant(const Document& doc, 235 HTMLFrameOwnerElement* findContainerForDescendant(const Document& doc,
218 const Document& descendant) { 236 const Document& descendant) {
219 Frame* frame = descendant.frame(); 237 Frame* frame = descendant.frame();
220 while (frame->tree().parent() != doc.frame()) 238 while (frame->tree().parent() != doc.frame())
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // 394 //
377 // For OOPIF scenarios, |docs| will only contain documents for local 395 // For OOPIF scenarios, |docs| will only contain documents for local
378 // ancestors, and remote ancestors will be processed in their 396 // ancestors, and remote ancestors will be processed in their
379 // respective processes. This preserves the spec's event firing order 397 // respective processes. This preserves the spec's event firing order
380 // for local ancestors, but not for remote ancestors. However, that 398 // for local ancestors, but not for remote ancestors. However, that
381 // difference shouldn't be observable in practice: a fullscreenchange 399 // difference shouldn't be observable in practice: a fullscreenchange
382 // event handler would need to postMessage a frame in another renderer 400 // event handler would need to postMessage a frame in another renderer
383 // process, where the message should be queued up and processed after 401 // process, where the message should be queued up and processed after
384 // the IPC that dispatches fullscreenchange. 402 // the IPC that dispatches fullscreenchange.
385 HeapDeque<Member<Document>> docs; 403 HeapDeque<Member<Document>> docs;
386 404 for (Document* doc = &document; doc; doc = nextLocalAncestor(*doc))
387 docs.prepend(&document); 405 docs.prepend(doc);
388 for (Frame* frame = document.frame()->tree().parent(); frame;
389 frame = frame->tree().parent()) {
390 if (frame->isLocalFrame())
391 docs.prepend(toLocalFrame(frame)->document());
392 }
393 406
394 // 4. For each document in docs, run these substeps: 407 // 4. For each document in docs, run these substeps:
395 HeapDeque<Member<Document>>::iterator current = docs.begin(), 408 HeapDeque<Member<Document>>::iterator current = docs.begin(),
396 following = docs.begin(); 409 following = docs.begin();
397 410
398 do { 411 do {
399 ++following; 412 ++following;
400 413
401 // 1. Let following document be the document after document in docs, or 414 // 1. Let following document be the document after document in docs, or
402 // null if there is no such document. 415 // null if there is no such document.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 547
535 // 3. If doc's fullscreen element stack is empty and doc's browsing context 548 // 3. If doc's fullscreen element stack is empty and doc's browsing context
536 // has a browsing context container, set doc to that browsing context 549 // has a browsing context container, set doc to that browsing context
537 // container's node document. 550 // container's node document.
538 // 551 //
539 // OOPIF: If browsing context container's document is in another 552 // OOPIF: If browsing context container's document is in another
540 // process, keep moving up the ancestor chain and looking for a 553 // process, keep moving up the ancestor chain and looking for a
541 // browsing context container with a local document. 554 // browsing context container with a local document.
542 // TODO(alexmos): Deal with nested fullscreen cases, see 555 // TODO(alexmos): Deal with nested fullscreen cases, see
543 // https://crbug.com/617369. 556 // https://crbug.com/617369.
544 if (!newTop) { 557 if (!newTop)
545 Frame* frame = currentDoc->frame()->tree().parent(); 558 currentDoc = nextLocalAncestor(*currentDoc);
alexmos 2016/12/12 17:18:03 Doesn't this need a "continue" to match the old be
foolip 2016/12/12 17:27:44 Oh my, good catch. Will see why no tests fail beca
foolip 2016/12/12 22:34:09 I wrote a test and updated the description. The te
546 while (frame && frame->isRemoteFrame())
547 frame = frame->tree().parent();
548 if (frame) {
549 currentDoc = toLocalFrame(frame)->document();
550 continue;
551 }
552 }
553 559
554 // 4. Otherwise, set doc to null. 560 // 4. Otherwise, set doc to null.
555 currentDoc = nullptr; 561 currentDoc = nullptr;
556 } 562 }
557 563
558 // 6. Return, and run the remaining steps asynchronously. 564 // 6. Return, and run the remaining steps asynchronously.
559 // 7. Optionally, perform some animation. 565 // 7. Optionally, perform some animation.
560 566
561 // Only exit fullscreen mode if the fullscreen element stack is empty. 567 // Only exit fullscreen mode if the fullscreen element stack is empty.
562 if (!newTop) { 568 if (!newTop) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 DEFINE_TRACE(Fullscreen) { 818 DEFINE_TRACE(Fullscreen) {
813 visitor->trace(m_pendingFullscreenElement); 819 visitor->trace(m_pendingFullscreenElement);
814 visitor->trace(m_fullscreenElementStack); 820 visitor->trace(m_fullscreenElementStack);
815 visitor->trace(m_currentFullScreenElement); 821 visitor->trace(m_currentFullScreenElement);
816 visitor->trace(m_eventQueue); 822 visitor->trace(m_eventQueue);
817 Supplement<Document>::trace(visitor); 823 Supplement<Document>::trace(visitor);
818 ContextLifecycleObserver::trace(visitor); 824 ContextLifecycleObserver::trace(visitor);
819 } 825 }
820 826
821 } // namespace blink 827 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698