Commit 6d5aac01 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Remove OverlayPresenter from OverlayPresentationContext interface

The OverlayPresenter passed as an argument for the
OverlayPresentationContext API was not used by the implementation.  This
CL decouples the presentation context interface from OverlayPresenter.

Bug: none
Change-Id: Iefa20303f6b38d22240fb9f29f0c3ec6675cb55a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2069257
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#745167}
parent d02f6478
......@@ -160,7 +160,7 @@ void OverlayPresenterImpl::SetActiveWebState(
} else {
// For WebState activations, the overlay UI for the previously active
// WebState should be hidden, as it may be shown again upon reactivating.
presentation_context_->HideOverlayUI(this, previously_active_request);
presentation_context_->HideOverlayUI(previously_active_request);
}
}
......@@ -193,8 +193,9 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() {
// Overlays cannot be presented if one is already presented.
DCHECK(!presenting_);
// Overlays cannot be shown without a presentation context.
if (!presentation_context_)
// Overlays cannot be shown without a presentation context or if the
// presentation context is already showing overlay UI.
if (!presentation_context_ || presentation_context_->IsShowingOverlayUI())
return;
// No presentation is necessary if there is no active reqeust or the context
......@@ -219,9 +220,8 @@ void OverlayPresenterImpl::PresentOverlayForActiveRequest() {
OverlayDismissalCallback dismissal_callback = base::BindOnce(
&OverlayPresenterImpl::OverlayWasDismissed, weak_factory_.GetWeakPtr(),
presentation_context_, request, GetActiveQueue()->GetWeakPtr());
presentation_context_->ShowOverlayUI(this, request,
std::move(presentation_callback),
std::move(dismissal_callback));
presentation_context_->ShowOverlayUI(
request, std::move(presentation_callback), std::move(dismissal_callback));
}
void OverlayPresenterImpl::OverlayWasPresented(
......@@ -286,7 +286,7 @@ void OverlayPresenterImpl::OverlayWasDismissed(
void OverlayPresenterImpl::CancelOverlayUIForRequest(OverlayRequest* request) {
if (!presentation_context_ || !request)
return;
presentation_context_->CancelOverlayUI(this, request);
presentation_context_->CancelOverlayUI(request);
}
void OverlayPresenterImpl::CancelAllOverlayUI() {
......@@ -372,7 +372,7 @@ void OverlayPresenterImpl::RequestAddedToQueue(OverlayRequestQueueImpl* queue,
presented_request_ && queue->size() > 1 &&
queue->GetRequest(/*index=*/1) == presented_request_;
if (should_dismiss_for_inserted_request)
presentation_context_->HideOverlayUI(this, presented_request_);
presentation_context_->HideOverlayUI(presented_request_);
}
void OverlayPresenterImpl::OverlayRequestQueueDestroyed(
......@@ -392,7 +392,7 @@ void OverlayPresenterImpl::
OverlayRequest* request = GetActiveRequest();
if (presenting_ &&
!presentation_context->CanShowUIForRequest(request, capabilities)) {
presentation_context_->HideOverlayUI(this, GetActiveRequest());
presentation_context_->HideOverlayUI(GetActiveRequest());
}
}
......
......@@ -8,11 +8,10 @@
#include "ios/chrome/browser/overlays/public/overlay_dismissal_callback.h"
#include "ios/chrome/browser/overlays/public/overlay_presentation_callback.h"
class OverlayPresenter;
class OverlayRequest;
class OverlayPresentationContextObserver;
// Object that handles presenting the overlay UI for OverlayPresenter.
// Object that handles presenting the overlay UI for OverlayRequests.
class OverlayPresentationContext {
public:
OverlayPresentationContext() = default;
......@@ -49,31 +48,32 @@ class OverlayPresentationContext {
// |request| with its current presentation capabilities.
virtual bool CanShowUIForRequest(OverlayRequest* request) const = 0;
// Called by |presenter| to show the overlay UI for |request|.
// |presentation_callback| must be called when the UI is finished being
// presented. |dismissal_callback| must be stored and called whenever the UI
// is finished being dismissed for user interaction, hiding, or cancellation.
// Must only be called when CanShowUIForRequest() returns true for |request|.
virtual void ShowOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request,
// Whether overlay UI is currently shown in the context.
virtual bool IsShowingOverlayUI() const = 0;
// Called to show the overlay UI for |request|. |presentation_callback| must
// be called when the UI is finished being presented. |dismissal_callback|
// must be stored and called whenever the UI is finished being dismissed for
// user interaction, hiding, or cancellation. Must only be called when:
// - IsShowingOverlayUI() returns false, and
// - CanShowUIForRequest() returns true for |request|.
virtual void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) = 0;
// Called by |presenter| to hide the overlay UI for |request|. Hidden
// overlays may be shown again, so they should be kept in memory or
// serialized so that the state can be restored if shown again. When hiding
// an overlay, the presented UI must be dismissed, and the overlay's
// dismissal callback must must be executed upon the dismissal's completion.
// Must only be called when |request| is displayed within the context.
virtual void HideOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) = 0;
// Called to hide the overlay UI for |request|. Hidden overlays may be shown
// again, so they should be kept in memory or serialized so that the state can
// be restored if shown again. When hiding an overlay, the presented UI must
// be dismissed, and the overlay's dismissal callback must must be executed
// upon the dismissal's completion. Must only be called when |request| is
// displayed within the context.
virtual void HideOverlayUI(OverlayRequest* request) = 0;
// Called by |presenter| to cancel the overlay UI for |request|. If the UI
// is presented, it should be dismissed and the dismissal callback should be
// executed upon the dismissal's completion. Otherwise, any state
// corresponding to any hidden overlays should be cleaned up.
virtual void CancelOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) = 0;
// Called to cancel the overlay UI for |request|. If the UI is presented, it
// should be dismissed and the dismissal callback should be executed upon the
// dismissal's completion. Otherwise, any state corresponding to any hidden
// overlays should be cleaned up.
virtual void CancelOverlayUI(OverlayRequest* request) = 0;
};
#endif // IOS_CHROME_BROWSER_OVERLAYS_PUBLIC_OVERLAY_PRESENTATION_CONTEXT_H_
......@@ -75,11 +75,20 @@ bool FakeOverlayPresentationContext::CanShowUIForRequest(
bool FakeOverlayPresentationContext::CanShowUIForRequest(
OverlayRequest* request) const {
return CanShowUIForRequest(request, capabilities_);
return CanShowUIForRequest(request, capabilities_) && !IsShowingOverlayUI();
}
bool FakeOverlayPresentationContext::IsShowingOverlayUI() const {
for (auto& request_ui_state_pair : states_) {
if (request_ui_state_pair.second.presentation_state ==
PresentationState::kPresented) {
return true;
}
}
return false;
}
void FakeOverlayPresentationContext::ShowOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request,
OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) {
......@@ -89,13 +98,11 @@ void FakeOverlayPresentationContext::ShowOverlayUI(
std::move(presentation_callback).Run();
}
void FakeOverlayPresentationContext::HideOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) {
void FakeOverlayPresentationContext::HideOverlayUI(OverlayRequest* request) {
SimulateDismissalForRequest(request, OverlayDismissalReason::kHiding);
}
void FakeOverlayPresentationContext::CancelOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request) {
FakeUIState& state = states_[request];
if (state.presentation_state == PresentationState::kPresented) {
......
......@@ -47,14 +47,12 @@ class FakeOverlayPresentationContext : public OverlayPresentationContext {
OverlayRequest* request,
UIPresentationCapabilities capabilities) const override;
bool CanShowUIForRequest(OverlayRequest* request) const override;
void ShowOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request,
bool IsShowingOverlayUI() const override;
void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) override;
void HideOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
void CancelOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
void HideOverlayUI(OverlayRequest* request) override;
void CancelOverlayUI(OverlayRequest* request) override;
private:
// Struct used to store state for the fake presentation context.
......
......@@ -68,14 +68,12 @@ class OverlayPresentationContextImpl : public OverlayPresentationContext {
OverlayRequest* request,
UIPresentationCapabilities capabilities) const override;
bool CanShowUIForRequest(OverlayRequest* request) const override;
void ShowOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request,
bool IsShowingOverlayUI() const override;
void ShowOverlayUI(OverlayRequest* request,
OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) override;
void HideOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
void CancelOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) override;
void HideOverlayUI(OverlayRequest* request) override;
void CancelOverlayUI(OverlayRequest* request) override;
private:
OverlayPresentationContextImpl(Browser* browser, OverlayModality modality);
......
......@@ -110,12 +110,16 @@ bool OverlayPresentationContextImpl::CanShowUIForRequest(
return CanShowUIForRequest(request, GetPresentationCapabilities());
}
bool OverlayPresentationContextImpl::IsShowingOverlayUI() const {
return !!request_;
}
void OverlayPresentationContextImpl::ShowOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request,
OverlayPresentationCallback presentation_callback,
OverlayDismissalCallback dismissal_callback) {
DCHECK_EQ(presenter_, presenter);
DCHECK(!IsShowingOverlayUI());
DCHECK(CanShowUIForRequest(request));
// Create the UI state for |request| if necessary.
if (!GetRequestUIState(request))
states_[request] = std::make_unique<OverlayRequestUIState>(request);
......@@ -125,9 +129,8 @@ void OverlayPresentationContextImpl::ShowOverlayUI(
SetRequest(request);
}
void OverlayPresentationContextImpl::HideOverlayUI(OverlayPresenter* presenter,
OverlayRequest* request) {
DCHECK_EQ(presenter_, presenter);
void OverlayPresentationContextImpl::HideOverlayUI(OverlayRequest* request) {
DCHECK(CanShowUIForRequest(request));
DCHECK_EQ(request_, request);
DCHECK(CanShowUIForRequest(request));
......@@ -140,10 +143,8 @@ void OverlayPresentationContextImpl::HideOverlayUI(OverlayPresenter* presenter,
}
void OverlayPresentationContextImpl::CancelOverlayUI(
OverlayPresenter* presenter,
OverlayRequest* request) {
DCHECK_EQ(presenter_, presenter);
DCHECK(CanShowUIForRequest(request));
// No cleanup required if there is no UI state for |request|. This can
// occur when cancelling an OverlayRequest whose UI has never been
// presented.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment