Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 5 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 9 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
| 10 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 (*it)->manager->HostChanged(d ? d->GetWebContentsModalDialogHost() : NULL); | 34 (*it)->manager->HostChanged(d ? d->GetWebContentsModalDialogHost() : NULL); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 void WebContentsModalDialogManager::ShowModalDialog(gfx::NativeWindow dialog) { | 38 void WebContentsModalDialogManager::ShowModalDialog(gfx::NativeWindow dialog) { |
| 39 std::unique_ptr<SingleWebContentsDialogManager> mgr( | 39 std::unique_ptr<SingleWebContentsDialogManager> mgr( |
| 40 CreateNativeWebModalManager(dialog, this)); | 40 CreateNativeWebModalManager(dialog, this)); |
| 41 ShowDialogWithManager(dialog, std::move(mgr)); | 41 ShowDialogWithManager(dialog, std::move(mgr)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 // Shows the modal dialog and records that it has a non clipped display (not | |
| 45 // constrained to bounds of parent window). | |
| 46 void WebContentsModalDialogManager::ShowNonClippedModalDialog( | |
| 47 gfx::NativeWindow dialog) { | |
| 48 nonclipped_child_dialogs_.push_back(dialog); | |
| 49 std::unique_ptr<SingleWebContentsDialogManager> mgr( | |
| 50 CreateNativeWebModalManager(dialog, this)); | |
| 51 ShowDialogWithManager(dialog, std::move(mgr)); | |
| 52 } | |
| 53 | |
| 44 // TODO(gbillock): Maybe "ShowBubbleWithManager"? | 54 // TODO(gbillock): Maybe "ShowBubbleWithManager"? |
| 45 void WebContentsModalDialogManager::ShowDialogWithManager( | 55 void WebContentsModalDialogManager::ShowDialogWithManager( |
| 46 gfx::NativeWindow dialog, | 56 gfx::NativeWindow dialog, |
| 47 std::unique_ptr<SingleWebContentsDialogManager> manager) { | 57 std::unique_ptr<SingleWebContentsDialogManager> manager) { |
| 48 if (delegate_) | 58 if (delegate_) |
| 49 manager->HostChanged(delegate_->GetWebContentsModalDialogHost()); | 59 manager->HostChanged(delegate_->GetWebContentsModalDialogHost()); |
| 50 child_dialogs_.push_back(new DialogState(dialog, std::move(manager))); | 60 child_dialogs_.push_back(new DialogState(dialog, std::move(manager))); |
| 51 | 61 |
| 52 if (child_dialogs_.size() == 1) { | 62 if (child_dialogs_.size() == 1) { |
| 53 BlockWebContentsInteraction(true); | 63 BlockWebContentsInteraction(true); |
| 54 if (delegate_ && delegate_->IsWebContentsVisible(web_contents())) | 64 if (delegate_ && delegate_->IsWebContentsVisible(web_contents())) |
| 55 child_dialogs_.back()->manager->Show(); | 65 child_dialogs_.back()->manager->Show(); |
| 56 } | 66 } |
| 57 } | 67 } |
| 58 | 68 |
| 59 bool WebContentsModalDialogManager::IsDialogActive() const { | 69 bool WebContentsModalDialogManager::IsDialogActive() const { |
| 60 return !child_dialogs_.empty(); | 70 return !child_dialogs_.empty(); |
| 61 } | 71 } |
| 62 | 72 |
| 63 void WebContentsModalDialogManager::FocusTopmostDialog() const { | 73 void WebContentsModalDialogManager::FocusTopmostDialog() const { |
| 64 DCHECK(!child_dialogs_.empty()); | 74 DCHECK(!child_dialogs_.empty()); |
| 65 child_dialogs_.front()->manager->Focus(); | 75 child_dialogs_.front()->manager->Focus(); |
| 66 } | 76 } |
| 67 | 77 |
| 68 content::WebContents* WebContentsModalDialogManager::GetWebContents() const { | 78 content::WebContents* WebContentsModalDialogManager::GetWebContents() const { |
| 69 return web_contents(); | 79 return web_contents(); |
| 70 } | 80 } |
| 71 | 81 |
| 72 void WebContentsModalDialogManager::WillClose(gfx::NativeWindow dialog) { | 82 void WebContentsModalDialogManager::WillClose(gfx::NativeWindow dialog) { |
|
Mike Wittman
2016/08/12 22:51:34
The dialog should be removed from nonclipped_child
rbpotter
2016/08/15 18:03:45
Done.
| |
| 73 WebContentsModalDialogList::iterator dlg = FindDialogState(dialog); | 83 WebContentsModalDialogList::iterator dlg = FindDialogState(dialog); |
| 74 | 84 |
| 75 // The Views tab contents modal dialog calls WillClose twice. Ignore the | 85 // The Views tab contents modal dialog calls WillClose twice. Ignore the |
| 76 // second invocation. | 86 // second invocation. |
| 77 if (dlg == child_dialogs_.end()) | 87 if (dlg == child_dialogs_.end()) |
| 78 return; | 88 return; |
| 79 | 89 |
| 80 bool removed_topmost_dialog = dlg == child_dialogs_.begin(); | 90 bool removed_topmost_dialog = dlg == child_dialogs_.begin(); |
| 81 std::unique_ptr<DialogState> deleter(*dlg); | 91 std::unique_ptr<DialogState> deleter(*dlg); |
| 82 child_dialogs_.erase(dlg); | 92 child_dialogs_.erase(dlg); |
| 83 if (!child_dialogs_.empty() && removed_topmost_dialog && | 93 if (!child_dialogs_.empty() && removed_topmost_dialog && |
| 84 !closing_all_dialogs_) { | 94 !closing_all_dialogs_) { |
| 85 child_dialogs_.front()->manager->Show(); | 95 child_dialogs_.front()->manager->Show(); |
| 86 } | 96 } |
| 87 | 97 |
| 88 BlockWebContentsInteraction(!child_dialogs_.empty()); | 98 BlockWebContentsInteraction(!child_dialogs_.empty()); |
| 89 } | 99 } |
| 90 | 100 |
| 101 bool WebContentsModalDialogManager::IsNonClipped(gfx::NativeWindow dialog) { | |
| 102 NativeWindowDialogList::iterator i; | |
| 103 for (i = nonclipped_child_dialogs_.begin(); | |
| 104 i != nonclipped_child_dialogs_.end(); ++i) { | |
| 105 if ((*i) == dialog) | |
| 106 break; | |
| 107 } | |
| 108 if (i != nonclipped_child_dialogs_.end()) | |
| 109 return true; | |
| 110 return false; | |
| 111 } | |
| 112 | |
| 91 WebContentsModalDialogManager::WebContentsModalDialogManager( | 113 WebContentsModalDialogManager::WebContentsModalDialogManager( |
| 92 content::WebContents* web_contents) | 114 content::WebContents* web_contents) |
| 93 : content::WebContentsObserver(web_contents), | 115 : content::WebContentsObserver(web_contents), |
| 94 delegate_(NULL), | 116 delegate_(NULL), |
| 95 closing_all_dialogs_(false) { | 117 closing_all_dialogs_(false) { |
| 96 } | 118 } |
| 97 | 119 |
| 98 WebContentsModalDialogManager::DialogState::DialogState( | 120 WebContentsModalDialogManager::DialogState::DialogState( |
| 99 gfx::NativeWindow dialog, | 121 gfx::NativeWindow dialog, |
| 100 std::unique_ptr<SingleWebContentsDialogManager> mgr) | 122 std::unique_ptr<SingleWebContentsDialogManager> mgr) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // some of these to close. CloseAllDialogs is async, so it might get called | 197 // some of these to close. CloseAllDialogs is async, so it might get called |
| 176 // twice before it runs. | 198 // twice before it runs. |
| 177 CloseAllDialogs(); | 199 CloseAllDialogs(); |
| 178 } | 200 } |
| 179 | 201 |
| 180 void WebContentsModalDialogManager::DidAttachInterstitialPage() { | 202 void WebContentsModalDialogManager::DidAttachInterstitialPage() { |
| 181 CloseAllDialogs(); | 203 CloseAllDialogs(); |
| 182 } | 204 } |
| 183 | 205 |
| 184 } // namespace web_modal | 206 } // namespace web_modal |
| OLD | NEW |