summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/cocoa/html_dialog_window_controller.mm14
-rw-r--r--chrome/browser/ui/gtk/html_dialog_gtk.cc23
-rw-r--r--chrome/browser/ui/gtk/html_dialog_gtk.h1
-rw-r--r--chrome/browser/ui/views/html_dialog_view.cc34
-rw-r--r--chrome/browser/ui/views/html_dialog_view.h2
-rw-r--r--chrome/browser/ui/webui/html_dialog_ui.cc8
-rw-r--r--chrome/browser/ui/webui/html_dialog_ui.h7
-rw-r--r--chrome/browser/ui/webui/task_manager/task_manager_dialog.cc20
-rw-r--r--ui/views/widget/widget.cc4
-rw-r--r--ui/views/widget/widget.h3
10 files changed, 101 insertions, 15 deletions
diff --git a/chrome/browser/ui/cocoa/html_dialog_window_controller.mm b/chrome/browser/ui/cocoa/html_dialog_window_controller.mm
index feffdf9..a0b847b 100644
--- a/chrome/browser/ui/cocoa/html_dialog_window_controller.mm
+++ b/chrome/browser/ui/cocoa/html_dialog_window_controller.mm
@@ -51,6 +51,7 @@ public:
virtual void GetWebUIMessageHandlers(
std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE;
virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
+ virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE;
virtual std::string GetDialogArgs() const OVERRIDE;
virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
virtual void OnCloseContents(WebContents* source,
@@ -179,11 +180,18 @@ void HtmlDialogWindowDelegateBridge::GetWebUIMessageHandlers(
}
void HtmlDialogWindowDelegateBridge::GetDialogSize(gfx::Size* size) const {
- if (delegate_) {
+ if (delegate_)
delegate_->GetDialogSize(size);
- } else {
+ else
+ *size = gfx::Size();
+}
+
+void HtmlDialogWindowDelegateBridge::GetMinimumDialogSize(
+ gfx::Size* size) const {
+ if (delegate_)
+ delegate_->GetMinimumDialogSize(size);
+ else
*size = gfx::Size();
- }
}
std::string HtmlDialogWindowDelegateBridge::GetDialogArgs() const {
diff --git a/chrome/browser/ui/gtk/html_dialog_gtk.cc b/chrome/browser/ui/gtk/html_dialog_gtk.cc
index 4fa270f..f9e3b61 100644
--- a/chrome/browser/ui/gtk/html_dialog_gtk.cc
+++ b/chrome/browser/ui/gtk/html_dialog_gtk.cc
@@ -114,6 +114,13 @@ void HtmlDialogGtk::GetDialogSize(gfx::Size* size) const {
*size = gfx::Size();
}
+void HtmlDialogGtk::GetMinimumDialogSize(gfx::Size* size) const {
+ if (delegate_)
+ delegate_->GetMinimumDialogSize(size);
+ else
+ *size = gfx::Size();
+}
+
std::string HtmlDialogGtk::GetDialogArgs() const {
if (delegate_)
return delegate_->GetDialogArgs();
@@ -245,10 +252,18 @@ gfx::NativeWindow HtmlDialogGtk::InitDialog() {
gfx::Size dialog_size;
delegate_->GetDialogSize(&dialog_size);
-
- gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_->widget()),
- dialog_size.width(),
- dialog_size.height());
+ if (!dialog_size.IsEmpty()) {
+ gtk_window_set_default_size(GTK_WINDOW(dialog_),
+ dialog_size.width(),
+ dialog_size.height());
+ }
+ gfx::Size minimum_dialog_size;
+ delegate_->GetMinimumDialogSize(&minimum_dialog_size);
+ if (!minimum_dialog_size.IsEmpty()) {
+ gtk_widget_set_size_request(GTK_WIDGET(tab_contents_container_->widget()),
+ minimum_dialog_size.width(),
+ minimum_dialog_size.height());
+ }
gtk_widget_show_all(dialog_);
diff --git a/chrome/browser/ui/gtk/html_dialog_gtk.h b/chrome/browser/ui/gtk/html_dialog_gtk.h
index bbcf957..892164a 100644
--- a/chrome/browser/ui/gtk/html_dialog_gtk.h
+++ b/chrome/browser/ui/gtk/html_dialog_gtk.h
@@ -44,6 +44,7 @@ class HtmlDialogGtk : public HtmlDialogTabContentsDelegate,
virtual void GetWebUIMessageHandlers(
std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
+ virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE;
virtual std::string GetDialogArgs() const OVERRIDE;
virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
virtual void OnCloseContents(content::WebContents* source,
diff --git a/chrome/browser/ui/views/html_dialog_view.cc b/chrome/browser/ui/views/html_dialog_view.cc
index 329e7c6..9bb341c 100644
--- a/chrome/browser/ui/views/html_dialog_view.cc
+++ b/chrome/browser/ui/views/html_dialog_view.cc
@@ -72,7 +72,7 @@ HtmlDialogView::~HtmlDialogView() {
gfx::Size HtmlDialogView::GetPreferredSize() {
gfx::Size out;
if (delegate_)
- delegate_->GetDialogSize(&out);
+ delegate_->GetMinimumDialogSize(&out);
return out;
}
@@ -109,6 +109,12 @@ string16 HtmlDialogView::GetWindowTitle() const {
return string16();
}
+std::string HtmlDialogView::GetWindowName() const {
+ if (delegate_)
+ return delegate_->GetDialogName();
+ return std::string();
+}
+
void HtmlDialogView::WindowClosing() {
// If we still have a delegate that means we haven't notified it of the
// dialog closing. This happens if the user clicks the Close button on the
@@ -167,6 +173,11 @@ void HtmlDialogView::GetDialogSize(gfx::Size* size) const {
delegate_->GetDialogSize(size);
}
+void HtmlDialogView::GetMinimumDialogSize(gfx::Size* size) const {
+ if (delegate_)
+ delegate_->GetMinimumDialogSize(size);
+}
+
std::string HtmlDialogView::GetDialogArgs() const {
if (delegate_)
return delegate_->GetDialogArgs();
@@ -176,15 +187,17 @@ std::string HtmlDialogView::GetDialogArgs() const {
void HtmlDialogView::OnDialogClosed(const std::string& json_retval) {
HtmlDialogTabContentsDelegate::Detach();
if (delegate_) {
- HtmlDialogUIDelegate* dialog_delegate = delegate_;
- delegate_ = NULL; // We will not communicate further with the delegate.
-
// Store the dialog content area size.
- dialog_delegate->StoreDialogSize(GetContentsBounds().size());
+ delegate_->StoreDialogSize(GetContentsBounds().size());
+ }
+
+ if (GetWidget())
+ GetWidget()->Close();
- dialog_delegate->OnDialogClosed(json_retval);
+ if (delegate_) {
+ delegate_->OnDialogClosed(json_retval);
+ delegate_ = NULL; // We will not communicate further with the delegate.
}
- GetWidget()->Close();
}
void HtmlDialogView::OnCloseContents(WebContents* source,
@@ -284,6 +297,13 @@ void HtmlDialogView::InitDialog() {
web_contents->GetPropertyBag(), this);
tab_watcher_.reset(new TabRenderWatcher(web_contents, this));
+ if (delegate_) {
+ gfx::Size out;
+ delegate_->GetDialogSize(&out);
+ if (!out.IsEmpty() && GetWidget())
+ GetWidget()->CenterWindow(out);
+ }
+
DOMView::LoadURL(GetDialogContentURL());
}
diff --git a/chrome/browser/ui/views/html_dialog_view.h b/chrome/browser/ui/views/html_dialog_view.h
index 690dc4d..57bb8f4 100644
--- a/chrome/browser/ui/views/html_dialog_view.h
+++ b/chrome/browser/ui/views/html_dialog_view.h
@@ -61,6 +61,7 @@ class HtmlDialogView
virtual bool CanResize() const OVERRIDE;
virtual ui::ModalType GetModalType() const OVERRIDE;
virtual string16 GetWindowTitle() const OVERRIDE;
+ virtual std::string GetWindowName() const OVERRIDE;
virtual void WindowClosing() OVERRIDE;
virtual views::View* GetContentsView() OVERRIDE;
virtual views::View* GetInitiallyFocusedView() OVERRIDE;
@@ -75,6 +76,7 @@ class HtmlDialogView
virtual void GetWebUIMessageHandlers(
std::vector<content::WebUIMessageHandler*>* handlers) const OVERRIDE;
virtual void GetDialogSize(gfx::Size* size) const OVERRIDE;
+ virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE;
virtual std::string GetDialogArgs() const OVERRIDE;
virtual void OnDialogClosed(const std::string& json_retval) OVERRIDE;
virtual void OnCloseContents(content::WebContents* source,
diff --git a/chrome/browser/ui/webui/html_dialog_ui.cc b/chrome/browser/ui/webui/html_dialog_ui.cc
index 5f47087..1b0dcf6 100644
--- a/chrome/browser/ui/webui/html_dialog_ui.cc
+++ b/chrome/browser/ui/webui/html_dialog_ui.cc
@@ -104,6 +104,14 @@ ExternalHtmlDialogUI::ExternalHtmlDialogUI(content::WebUI* web_ui)
ExternalHtmlDialogUI::~ExternalHtmlDialogUI() {
}
+std::string HtmlDialogUIDelegate::GetDialogName() const {
+ return std::string();
+}
+
+void HtmlDialogUIDelegate::GetMinimumDialogSize(gfx::Size* size) const {
+ GetDialogSize(size);
+}
+
bool HtmlDialogUIDelegate::HandleContextMenu(
const content::ContextMenuParams& params) {
return false;
diff --git a/chrome/browser/ui/webui/html_dialog_ui.h b/chrome/browser/ui/webui/html_dialog_ui.h
index 5af2892..21dc9ab 100644
--- a/chrome/browser/ui/webui/html_dialog_ui.h
+++ b/chrome/browser/ui/webui/html_dialog_ui.h
@@ -41,6 +41,10 @@ class HtmlDialogUIDelegate {
// Returns the title of the dialog.
virtual string16 GetDialogTitle() const = 0;
+ // Returns the dialog's name identifier. Used to identify this dialog for
+ // state restoration.
+ virtual std::string GetDialogName() const;
+
// Get the HTML file path for the content to load in the dialog.
virtual GURL GetDialogContentURL() const = 0;
@@ -54,6 +58,9 @@ class HtmlDialogUIDelegate {
// Get the size of the dialog.
virtual void GetDialogSize(gfx::Size* size) const = 0;
+ // Get the size of the dialog.
+ virtual void GetMinimumDialogSize(gfx::Size* size) const;
+
// Gets the JSON string input to use when showing the dialog.
virtual std::string GetDialogArgs() const = 0;
diff --git a/chrome/browser/ui/webui/task_manager/task_manager_dialog.cc b/chrome/browser/ui/webui/task_manager/task_manager_dialog.cc
index f5be574..23e0401 100644
--- a/chrome/browser/ui/webui/task_manager/task_manager_dialog.cc
+++ b/chrome/browser/ui/webui/task_manager/task_manager_dialog.cc
@@ -29,6 +29,14 @@
#include "ui/views/widget/widget.h"
#endif
+namespace {
+
+// The minimum size of task manager window in px.
+const int kMinimumTaskManagerWidth = 640;
+const int kMinimumTaskManagerHeight = 480;
+
+} // namespace
+
using content::BrowserThread;
using content::WebContents;
using content::WebUIMessageHandler;
@@ -53,6 +61,9 @@ class TaskManagerDialogImpl : public HtmlDialogUIDelegate {
virtual string16 GetDialogTitle() const OVERRIDE {
return l10n_util::GetStringUTF16(IDS_TASK_MANAGER_TITLE);
}
+ virtual std::string GetDialogName() const OVERRIDE {
+ return prefs::kTaskManagerWindowPlacement;
+ }
virtual GURL GetDialogContentURL() const OVERRIDE {
std::string url_string(chrome::kChromeUITaskManagerURL);
url_string += "?";
@@ -68,6 +79,7 @@ class TaskManagerDialogImpl : public HtmlDialogUIDelegate {
std::vector<WebUIMessageHandler*>* handlers) const OVERRIDE {
}
virtual void GetDialogSize(gfx::Size* size) const OVERRIDE {
+#if !defined(TOOLKIT_VIEWS)
// If dialog's bounds are previously saved, use them.
if (g_browser_process->local_state()) {
const DictionaryValue* placement_pref =
@@ -83,7 +95,11 @@ class TaskManagerDialogImpl : public HtmlDialogUIDelegate {
}
// Otherwise set default size.
- size->SetSize(640, 480);
+ size->SetSize(kMinimumTaskManagerWidth, kMinimumTaskManagerHeight);
+#endif
+ }
+ virtual void GetMinimumDialogSize(gfx::Size* size) const OVERRIDE {
+ size->SetSize(kMinimumTaskManagerWidth, kMinimumTaskManagerHeight);
}
virtual std::string GetDialogArgs() const OVERRIDE {
return std::string();
@@ -102,6 +118,7 @@ class TaskManagerDialogImpl : public HtmlDialogUIDelegate {
const content::ContextMenuParams& params) OVERRIDE {
return true;
}
+#if !defined(TOOLKIT_VIEWS)
virtual void StoreDialogSize(const gfx::Size& dialog_size) OVERRIDE {
// Store the dialog's bounds so that it can be restored with the same bounds
// the next time it's opened.
@@ -113,6 +130,7 @@ class TaskManagerDialogImpl : public HtmlDialogUIDelegate {
placement_pref->SetInteger("height", dialog_size.height());
}
}
+#endif
private:
void ShowDialog(bool is_background_page_mode);
diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc
index 6ffedc3..72a207c 100644
--- a/ui/views/widget/widget.cc
+++ b/ui/views/widget/widget.cc
@@ -452,6 +452,10 @@ void Widget::SetSize(const gfx::Size& size) {
native_widget_->SetSize(size);
}
+void Widget::CenterWindow(const gfx::Size& size) {
+ native_widget_->CenterWindow(size);
+}
+
void Widget::SetBoundsConstrained(const gfx::Rect& bounds) {
gfx::Rect work_area =
gfx::Screen::GetMonitorWorkAreaNearestPoint(bounds.origin());
diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h
index e33bb83..968c038 100644
--- a/ui/views/widget/widget.h
+++ b/ui/views/widget/widget.h
@@ -316,6 +316,9 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate,
void SetBounds(const gfx::Rect& bounds);
void SetSize(const gfx::Size& size);
+ // Sizes the window to the specified size and centerizes it.
+ void CenterWindow(const gfx::Size& size);
+
// Like SetBounds(), but ensures the Widget is fully visible on screen,
// resizing and/or repositioning as necessary. This is only useful for
// non-child widgets.