diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 00:46:46 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-25 00:46:46 +0000 |
commit | 0ee508a026ccca02c64da906773a0ebc88048f6c (patch) | |
tree | 0d59a93257a1ddb0e7f1406a57f2070f3664c818 /views/window | |
parent | e09f1e645f7f70759659644520f04e3386ced52a (diff) | |
download | chromium_src-0ee508a026ccca02c64da906773a0ebc88048f6c.zip chromium_src-0ee508a026ccca02c64da906773a0ebc88048f6c.tar.gz chromium_src-0ee508a026ccca02c64da906773a0ebc88048f6c.tar.bz2 |
Implement Window modality in TOOLKIT_VIEWS, and allow windows to be centered over their modal parent or the screen if there is no modal parent. This means child windows don't open at 0,0 anymore.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/159335
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21599 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r-- | views/window/window_gtk.cc | 57 | ||||
-rw-r--r-- | views/window/window_gtk.h | 6 |
2 files changed, 47 insertions, 16 deletions
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 5608cb9..076511e 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -70,6 +70,19 @@ GdkCursorType HitTestCodeToGdkCursorType(int hittest_code) { return GDK_ARROW; } +gfx::Rect GetScreenWorkArea(GdkWindow* window) { + guchar* raw_data = NULL; + gint data_len = 0; + gboolean success = gdk_property_get(gdk_get_default_root_window(), + gdk_atom_intern("_NET_WORKAREA", FALSE), + gdk_atom_intern("CARDINAL", FALSE), + 0, 0xFF, false, NULL, NULL, &data_len, + &raw_data); + DCHECK(success); + glong* data = reinterpret_cast<glong*>(raw_data); + return gfx::Rect(data[0], data[1], data[0] + data[2], data[1] + data[3]); +} + } // namespace namespace views { @@ -83,7 +96,7 @@ Window* Window::CreateChromeWindow(gfx::NativeWindow parent, WindowDelegate* window_delegate) { WindowGtk* window = new WindowGtk(window_delegate); window->GetNonClientView()->SetFrameView(window->CreateFrameViewForWindow()); - window->Init(bounds); + window->Init(parent, bounds); return window; } @@ -339,16 +352,16 @@ WindowGtk::WindowGtk(WindowDelegate* window_delegate) window_delegate_->window_.reset(this); } -void WindowGtk::Init(const gfx::Rect& bounds) { +void WindowGtk::Init(GtkWindow* parent, const gfx::Rect& bounds) { + WidgetGtk::Init(NULL, bounds); + // We call this after initializing our members since our implementations of // assorted WidgetWin functions may be called during initialization. is_modal_ = window_delegate_->IsModal(); - if (is_modal_) { - // TODO(erg): Fix once modality works. - // BecomeModal(); - } - - WidgetGtk::Init(NULL, bounds); + if (is_modal_) + gtk_window_set_modal(GetNativeWindow(), true); + if (parent) + gtk_window_set_transient_for(GetNativeWindow(), parent); g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", G_CALLBACK(CallConfigureEvent), this); @@ -361,7 +374,7 @@ void WindowGtk::Init(const gfx::Rect& bounds) { WidgetGtk::SetContentsView(non_client_view_); UpdateWindowTitle(); - SetInitialBounds(bounds); + SetInitialBounds(parent, bounds); // if (!IsAppWindow()) { // notification_registrar_.Add( @@ -401,22 +414,40 @@ void WindowGtk::SaveWindowPosition() { window_delegate_->SaveWindowPlacement(bounds, maximized); } -void WindowGtk::SetInitialBounds(const gfx::Rect& create_bounds) { +void WindowGtk::SetInitialBounds(GtkWindow* parent, + const gfx::Rect& create_bounds) { gfx::Rect saved_bounds(create_bounds.ToGdkRectangle()); if (window_delegate_->GetSavedWindowBounds(&saved_bounds)) { WidgetGtk::SetBounds(saved_bounds); } else { if (create_bounds.IsEmpty()) { - SizeWindowToDefault(); + SizeWindowToDefault(parent); } else { SetBounds(create_bounds, NULL); } } } -void WindowGtk::SizeWindowToDefault() { +void WindowGtk::SizeWindowToDefault(GtkWindow* parent) { + gfx::Rect center_rect; + + if (parent) { + // We have a parent window, center over it. + gint parent_x = 0; + gint parent_y = 0; + gtk_window_get_position(parent, &parent_x, &parent_y); + gint parent_w = 0; + gint parent_h = 0; + gtk_window_get_size(parent, &parent_w, &parent_h); + center_rect = gfx::Rect(parent_x, parent_y, parent_w, parent_h); + } else { + // We have no parent window, center over the screen. + center_rect = GetScreenWorkArea(GTK_WIDGET(GetNativeWindow())->window); + } gfx::Size size = non_client_view_->GetPreferredSize(); - gfx::Rect bounds(size.width(), size.height()); + gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, + center_rect.y() + (center_rect.height() - size.height()) / 2, + size.width(), size.height()); SetBounds(bounds, NULL); } diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index c996ce5..fb89ff1 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -78,7 +78,7 @@ class WindowGtk : public WidgetGtk, public Window { explicit WindowGtk(WindowDelegate* window_delegate); // Initializes the window to the passed in bounds. - void Init(const gfx::Rect& bounds); + void Init(GtkWindow* parent, const gfx::Rect& bounds); private: static gboolean CallConfigureEvent(GtkWidget* widget, @@ -91,8 +91,8 @@ class WindowGtk : public WidgetGtk, public Window { // Asks the delegate if any to save the window's location and size. void SaveWindowPosition(); - void SetInitialBounds(const gfx::Rect& bounds); - void SizeWindowToDefault(); + void SetInitialBounds(GtkWindow* parent, const gfx::Rect& bounds); + void SizeWindowToDefault(GtkWindow* parent); // Whether or not the window is modal. This comes from the delegate and is // cached at Init time to avoid calling back to the delegate from the |