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

Unified Diff: chrome/browser/tab_contents/tab_contents.cc

Issue 164547: Mac: make save/open dialogs operate as tab-modal sheets.... Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Painfully (but hopefully correctly) merged ToT. Created 11 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.h ('k') | chrome/browser/tab_contents/tab_contents_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/tab_contents.cc
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 4279332301f67b1bdb30d0a9c8cd2dbf42da5e40..6ae91253e82dcad77d762bd741bda206607e5420 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -247,6 +247,7 @@ TabContents::TabContents(Profile* profile,
encoding_(),
blocked_popups_(NULL),
infobar_delegates_(),
+ tab_modal_count_(0),
find_ui_active_(false),
find_op_aborted_(false),
current_find_request_id_(find_request_id_counter_++),
@@ -342,6 +343,12 @@ TabContents::~TabContents() {
if (window)
window->CloseConstrainedWindow();
}
+ child_windows_.clear(); // Should be unnecessary, strictly speaking.
+ tab_modal_count_ = 0;
+
+ // Notify whomever that things have changed.
+ if (delegate_)
+ delegate_->ChildWindowsChanged(this);
if (blocked_popups_)
blocked_popups_->Destroy();
@@ -813,12 +820,46 @@ void TabContents::ShowPageInfo(const GURL& url,
ConstrainedWindow* TabContents::CreateConstrainedDialog(
ConstrainedWindowDelegate* delegate) {
+ DCHECK(delegate);
+
ConstrainedWindow* window =
ConstrainedWindow::CreateConstrainedDialog(this, delegate);
+ DCHECK(window);
child_windows_.push_back(window);
+
+ // Possibly enter into the fully-tab-modal state.
+ if (window->GetModalityLevel() >= ConstrainedWindow::kModalForTab) {
+ DCHECK(tab_modal_count_ == 0);
+ tab_modal_count_++;
+ }
+
+ // Notify whomever that things have changed.
+ if (delegate_)
+ delegate_->ChildWindowsChanged(this);
+
return window;
}
+ConstrainedWindow::ModalityLevel TabContents::GetTabModalityLevel() {
+ if (constrained_window_count() > 0) {
+ return (tab_modal_count_ > 0) ? ConstrainedWindow::kModalForTab :
+ ConstrainedWindow::kModalForContent;
+ }
+ return ConstrainedWindow::kModalNone;
+}
+
+void TabContents::NotifyChildrenOfPendingEvent(ConstrainedWindow::Event event) {
+ // Make a copy of the list, since child windows may delete themselves from it
+ // (or conceivably worse) while we're iterating through.
+ ConstrainedWindowList children = child_windows_;
+
+ ConstrainedWindowList::iterator it, end;
+ for (it = children.begin(), end = children.end(); it != end; ++it) {
+ if (*it)
+ (*it)->ParentWillDo(event);
+ }
+}
+
void TabContents::AddNewContents(TabContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
@@ -1036,8 +1077,24 @@ void TabContents::OnStartDownload(DownloadItem* download) {
void TabContents::WillClose(ConstrainedWindow* window) {
ConstrainedWindowList::iterator it =
find(child_windows_.begin(), child_windows_.end(), window);
- if (it != child_windows_.end())
+ if (it != child_windows_.end()) {
+ // Possibly move out of fully-tab-modal state.
+ if (window->GetModalityLevel() >= ConstrainedWindow::kModalForTab) {
+ if (tab_modal_count_ > 0)
+ tab_modal_count_--;
+ else
+ NOTREACHED();
+ }
+
+ // Notify whomever that things have changed.
+ if (delegate_)
+ delegate_->ChildWindowsChanged(this);
+
+ // Erase this child from our child-window list.
child_windows_.erase(it);
+ } else {
+ NOTREACHED() << "Did not find child window being removed.";
+ }
}
void TabContents::WillCloseBlockedPopupContainer(
@@ -1416,15 +1473,9 @@ void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
previous_url, current_url))
return;
- // Clear out any child windows since we are leaving this page entirely.
- // We use indices instead of iterators in case CloseWindow does something
- // that may invalidate an iterator.
- int size = static_cast<int>(child_windows_.size());
- for (int i = size - 1; i >= 0; --i) {
- ConstrainedWindow* window = child_windows_[i];
- if (window)
- window->CloseConstrainedWindow();
- }
+ // We inform constrained child windows that we are about to navigate away.
+ // Those which are "content-area" windows should close themselves in response.
+ NotifyChildrenOfPendingEvent(ConstrainedWindow::kEventNavigate);
// Close the popup container.
if (blocked_popups_) {
@@ -2243,9 +2294,14 @@ void TabContents::RunFileChooser(bool multiple_files,
SelectFileDialog::Type dialog_type =
multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
SelectFileDialog::SELECT_OPEN_FILE;
+#if defined(OS_MACOSX)
+ select_file_dialog_->SelectFileInTab(dialog_type, title, default_file, NULL,
+ 0, FILE_PATH_LITERAL(""), this, NULL);
+#else
select_file_dialog_->SelectFile(dialog_type, title, default_file,
NULL, 0, FILE_PATH_LITERAL(""),
view_->GetTopLevelNativeWindow(), NULL);
+#endif
}
void TabContents::RunJavaScriptMessage(
@@ -2569,7 +2625,7 @@ void TabContents::Observe(NotificationType type,
) {
UpdateWebPreferences();
} else {
- NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
+ NOTREACHED() << "unexpected pref change notification " << *pref_name_in;
}
break;
}
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.h ('k') | chrome/browser/tab_contents/tab_contents_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698