OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/clean/chrome/browser/ui/overlays/overlay_queue.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
10 #error "This file requires ARC support." | |
11 #endif | |
12 | |
13 OverlayQueue::OverlayQueue() | |
14 : overlays_([[NSMutableArray<BrowserCoordinator*> alloc] init]) {} | |
15 | |
16 OverlayQueue::~OverlayQueue() { | |
17 CancelOverlays(); | |
18 } | |
19 | |
20 void OverlayQueue::AddObserver(OverlayQueueObserver* observer) { | |
21 observers_.AddObserver(observer); | |
22 } | |
23 | |
24 void OverlayQueue::RemoveObserver(OverlayQueueObserver* observer) { | |
25 observers_.RemoveObserver(observer); | |
26 } | |
27 | |
28 void OverlayQueue::OverlayWasStopped(BrowserCoordinator* overlay_coordinator) { | |
29 DCHECK(overlay_coordinator); | |
30 DCHECK_EQ(GetFirstOverlay(), overlay_coordinator); | |
31 DCHECK(showing_overlay_); | |
32 [overlays_ removeObjectAtIndex:0]; | |
33 showing_overlay_ = false; | |
34 for (auto& observer : observers_) | |
35 observer.OverlayQueueDidStopVisibleOverlay(this); | |
36 } | |
37 | |
38 void OverlayQueue::ReplaceVisibleOverlay( | |
39 BrowserCoordinator* overlay_coordinator) { | |
40 DCHECK(overlay_coordinator); | |
41 DCHECK(IsShowingOverlay()); | |
42 DCHECK_GE([overlays_ count], 1U); | |
43 // Add the overlay after the currently displayed overlay and notify observers | |
44 // before stopping the current overlay. | |
45 for (auto& observer : observers_) | |
46 observer.OverlayQueueWillReplaceVisibleOverlay(this); | |
47 [overlays_ insertObject:overlay_coordinator atIndex:1]; | |
48 overlay_coordinator.queue = this; | |
49 BrowserCoordinator* visible_overlay = GetFirstOverlay(); | |
50 [visible_overlay cancelOverlay]; | |
51 [visible_overlay stop]; | |
52 } | |
53 | |
54 bool OverlayQueue::HasQueuedOverlays() const { | |
55 return GetCount() > 0U; | |
56 } | |
57 | |
58 bool OverlayQueue::IsShowingOverlay() const { | |
59 return showing_overlay_; | |
60 } | |
61 | |
62 void OverlayQueue::CancelOverlays() { | |
63 // Cancel all overlays in the queue. | |
64 for (BrowserCoordinator* overlay_coordinator in overlays_) { | |
marq (ping after 24h)
2017/06/21 09:41:53
Braceless loops are okay, but be consistent with t
kkhorimoto
2017/06/23 06:11:16
If we need to add a newline after the loop, going
| |
65 [overlay_coordinator cancelOverlay]; | |
66 } | |
67 for (auto& observer : observers_) | |
68 observer.OverlayQueueDidCancelOverlays(this); | |
69 // Stop the visible overlay before emptying the queue. | |
70 [GetFirstOverlay() stop]; | |
71 [overlays_ removeAllObjects]; | |
72 } | |
73 | |
74 web::WebState* OverlayQueue::GetWebState() const { | |
75 return nullptr; | |
76 } | |
77 | |
78 void OverlayQueue::AddOverlay(BrowserCoordinator* overlay_coordinator) { | |
79 // Add the overlay coordinator to the queue, then notify observers. | |
80 DCHECK(overlay_coordinator); | |
81 [overlays_ addObject:overlay_coordinator]; | |
82 overlay_coordinator.queue = this; | |
83 for (auto& observer : observers_) | |
84 observer.OverlayQueueDidAddOverlay(this); | |
85 } | |
86 | |
87 NSUInteger OverlayQueue::GetCount() const { | |
88 return [overlays_ count]; | |
89 } | |
90 | |
91 BrowserCoordinator* OverlayQueue::GetFirstOverlay() { | |
92 return HasQueuedOverlays() ? [overlays_ firstObject] : nil; | |
93 } | |
94 | |
95 void OverlayQueue::OverlayWasStarted() { | |
96 showing_overlay_ = true; | |
97 } | |
OLD | NEW |