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 #ifndef IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_OVERLAY_SCHEDULER_H_ |
| 6 #define IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_OVERLAY_SCHEDULER_H_ |
| 7 |
| 8 #include <Foundation/Foundation.h> |
| 9 #include <list> |
| 10 |
| 11 #import "ios/chrome/browser/web_state_list/web_state_list_observer.h" |
| 12 #import "ios/clean/chrome/browser/ui/overlays/overlay_queue_observer.h" |
| 13 #import "ios/shared/chrome/browser/ui/browser_list/browser_user_data.h" |
| 14 |
| 15 @class BrowserCoordinator; |
| 16 @protocol OverlayPresentationCommands; |
| 17 @protocol TabGridCommands; |
| 18 |
| 19 namespace web { |
| 20 class WebState; |
| 21 } |
| 22 |
| 23 // An object that manages scheduling when overlays from various OverlayQueues |
| 24 // can be started. If an OverlayQueue requires a WebState's content area to be |
| 25 // visible, this class will update the WebStateLists's active WebState. |
| 26 class OverlayScheduler : public BrowserUserData<OverlayScheduler>, |
| 27 public OverlayQueueObserver, |
| 28 public WebStateListObserver { |
| 29 public: |
| 30 ~OverlayScheduler() override; |
| 31 |
| 32 // Starts or stops observing |browser_|'s WebStateList and OverlayQueues. |
| 33 void StartObservingBrowser(); |
| 34 void StopObservingBrowser(); |
| 35 |
| 36 // Whether a scheduled overlay is currently being shown. |
| 37 bool IsShowingOverlay() const; |
| 38 |
| 39 // Replaces the currently visible overlay with |overlay_coordinator|. |
| 40 void ReplaceVisibleOverlay(BrowserCoordinator* overlay_coordinator); |
| 41 |
| 42 // Cancels all scheduled overlays and empties overlay queues. |
| 43 void CancelOverlays(); |
| 44 |
| 45 private: |
| 46 friend class BrowserUserData<OverlayScheduler>; |
| 47 // The Browser for which this object is scheduling overlays. |
| 48 Browser* browser_; |
| 49 // Whether the sheduler is currently observing |browser_|'s WebStateList and |
| 50 // OverlayQueues. |
| 51 bool observing_; |
| 52 // The OverlayQueues that have queued overlays. After an overlay is stopped, |
| 53 // the first queue is popped and the first ovelay in the next queue is |
| 54 // started. |
| 55 std::list<OverlayQueue*> overlay_queues_; |
| 56 |
| 57 // Private constructor used by factory method. |
| 58 explicit OverlayScheduler(Browser* browser); |
| 59 |
| 60 // OverlayQueueObserver: |
| 61 void OverlayQueueDidAddOverlay(OverlayQueue* queue) override; |
| 62 void OverlayQueueWillReplaceVisibleOverlay(OverlayQueue* queue) override; |
| 63 void OverlayQueueDidStopVisibleOverlay(OverlayQueue* queue) override; |
| 64 void OverlayQueueDidCancelOverlays(OverlayQueue* queue) override; |
| 65 |
| 66 // WebStateListObserver: |
| 67 void WebStateInsertedAt(WebStateList* web_state_list, |
| 68 web::WebState* web_state, |
| 69 int index) override; |
| 70 void WebStateDetachedAt(WebStateList* web_state_list, |
| 71 web::WebState* web_state, |
| 72 int index) override; |
| 73 |
| 74 // Attempts to show the next queued overlay. |
| 75 void TryToStartNextOverlay(); |
| 76 // Starts observing |web_state_list|. Also starts observing the OverlayQueue |
| 77 // for each WebState in the list. |
| 78 void StartObservingWebStateList(WebStateList* web_state_list); |
| 79 // Stops observing |web_state_list| and the OverlayQueues for each WebState in |
| 80 // the list. Also cancels any queues overlays. |
| 81 void StopObservingWebStateList(WebStateList* web_state_list); |
| 82 // Lazily creates an OverlayQueue for |web_state| and starts observing it. |
| 83 void StartObservingQueueForWebState(web::WebState* web_state); |
| 84 // Cancels the overlays in |web_state|'s OverlayQueue and stops observing it. |
| 85 void StopObservingQueueForWebState(web::WebState* web_state); |
| 86 }; |
| 87 |
| 88 #endif // IOS_CLEAN_CHROME_BROWSER_UI_OVERLAYS_OVERLAY_SCHEDULER_H_ |
OLD | NEW |