diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 18:27:27 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 18:27:27 +0000 |
commit | 03c3b1e4170e845842833ad64cf36676043a357a (patch) | |
tree | 6d215da94ba60e53c6023a5b0ace750bd4a0e3ff | |
parent | 6254686d113f977626e824b02e8cb676556734ec (diff) | |
download | chromium_src-03c3b1e4170e845842833ad64cf36676043a357a.zip chromium_src-03c3b1e4170e845842833ad64cf36676043a357a.tar.gz chromium_src-03c3b1e4170e845842833ad64cf36676043a357a.tar.bz2 |
Implement window state restoration for the views-gtk window.
Allows the window to be resized smaller than its current size by setting a minimum size before initiating the drag.
Fixes a crash in TabContentsViewGtk due to a NULL delegate deref.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/118227
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17641 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/window_sizer.cc | 5 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 1 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 1 | ||||
-rw-r--r-- | views/window/window_gtk.cc | 73 | ||||
-rw-r--r-- | views/window/window_gtk.h | 13 |
6 files changed, 63 insertions, 34 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 5103bc0..d18edbc 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -316,7 +316,9 @@ gboolean TabContentsViewGtk::OnSizeAllocate(GtkWidget* widget, TabContentsViewGtk* view) { int width = allocation->width; int height = allocation->height; - height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); + // |delegate()| can be NULL here during browser teardown. + if (view->tab_contents()->delegate()) + height += view->tab_contents()->delegate()->GetExtraRenderViewHeight(); gfx::Size size(width, height); gtk_container_foreach(GTK_CONTAINER(widget), SetSizeRequest, &size); diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc index a0f9393..74956d2 100644 --- a/chrome/browser/window_sizer.cc +++ b/chrome/browser/window_sizer.cc @@ -111,11 +111,6 @@ void WindowSizer::GetBrowserWindowBounds(const std::wstring& app_name, Browser* browser, gfx::Rect* window_bounds, bool* maximized) { -#if !defined(OS_WIN) && defined(TOOLKIT_VIEWS) - *window_bounds = gfx::Rect(20, 20, 500, 500); - *maximized = false; - return; -#endif const WindowSizer sizer(new DefaultStateProvider(app_name, browser), CreateDefaultMonitorInfoProvider()); sizer.DetermineWindowBounds(specified_bounds, window_bounds, maximized); diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index f1cb67d..b105af8 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -241,7 +241,6 @@ void WidgetGtk::SetBounds(const gfx::Rect& bounds) { // TODO: this may need to set an initial size if not showing. // TODO: need to constrain based on screen size. gtk_window_resize(gtk_window, bounds.width(), bounds.height()); - gtk_window_move(gtk_window, bounds.x(), bounds.y()); } } diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 3fd866b..6bd501e 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -138,6 +138,7 @@ class WidgetGtk : public Widget, public MessageLoopForUI::Observer { static void SetRootViewForWidget(GtkWidget* widget, RootView* root_view); // A set of static signal handlers that bridge + // TODO(beng): alphabetize! static void CallSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); static gboolean CallPaint(GtkWidget* widget, GdkEventExpose* event); static gboolean CallEnterNotify(GtkWidget* widget, GdkEventCrossing* event); diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc index 138fef9..e62fd73 100644 --- a/views/window/window_gtk.cc +++ b/views/window/window_gtk.cc @@ -136,7 +136,6 @@ void WindowGtk::Close() { } if (non_client_view_->CanClose()) { - SaveWindowPosition(); WidgetGtk::Close(); window_closed_ = true; } @@ -272,6 +271,8 @@ gboolean WindowGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { case HTTOPRIGHT: { gfx::Point screen_point(event->x, event->y); View::ConvertPointToScreen(GetRootView(), &screen_point); + // TODO(beng): figure out how to get a good minimum size. + gtk_widget_set_size_request(GetNativeView(), 100, 100); gtk_window_begin_resize_drag(GetNativeWindow(), HitTestCodeToGDKWindowEdge(hittest_code), event->button, screen_point.x(), @@ -285,6 +286,12 @@ gboolean WindowGtk::OnButtonPress(GtkWidget* widget, GdkEventButton* event) { return WidgetGtk::OnButtonPress(widget, event); } +gboolean WindowGtk::OnConfigureEvent(GtkWidget* widget, + GdkEventConfigure* event) { + SaveWindowPosition(); + return FALSE; +} + gboolean WindowGtk::OnMotionNotify(GtkWidget* widget, GdkEventMotion* event) { // Update the cursor for the screen edge. int hittest_code = @@ -310,6 +317,14 @@ void WindowGtk::OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation) { gdk_region_destroy(mask_region); } +gboolean WindowGtk::OnWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event) { + window_state_ = event->new_window_state; + if (!(window_state_ & GDK_WINDOW_STATE_WITHDRAWN)) + SaveWindowPosition(); + return FALSE; +} + //////////////////////////////////////////////////////////////////////////////// // WindowGtk, protected: @@ -335,20 +350,17 @@ void WindowGtk::Init(const gfx::Rect& bounds) { WidgetGtk::Init(NULL, bounds, true); + g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event", + G_CALLBACK(CallConfigureEvent), this); + g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event", + G_CALLBACK(CallWindowStateEvent), this); + // Create the ClientView, add it to the NonClientView and add the // NonClientView to the RootView. This will cause everything to be parented. non_client_view_->set_client_view(window_delegate_->CreateClientView(this)); WidgetGtk::SetContentsView(non_client_view_); UpdateWindowTitle(); - - GtkWindow* gtk_window = GetNativeWindow(); - - g_signal_connect(G_OBJECT(gtk_window), - "window-state-event", - G_CALLBACK(CallWindowStateEvent), - NULL); - SetInitialBounds(bounds); // if (!IsAppWindow()) { @@ -361,6 +373,34 @@ void WindowGtk::Init(const gfx::Rect& bounds) { // ResetWindowRegion(false); } +//////////////////////////////////////////////////////////////////////////////// +// WindowGtk, private: + +// static +gboolean WindowGtk::CallConfigureEvent(GtkWidget* widget, + GdkEventConfigure* event, + WindowGtk* window_gtk) { + return window_gtk->OnConfigureEvent(widget, event); +} + +// static +gboolean WindowGtk::CallWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event, + WindowGtk* window_gtk) { + return window_gtk->OnWindowStateEvent(widget, event); +} + +void WindowGtk::SaveWindowPosition() { + // The delegate may have gone away on us. + if (!window_delegate_) + return; + + bool maximized = window_state_ & GDK_WINDOW_STATE_MAXIMIZED; + gfx::Rect bounds; + WidgetGtk::GetBounds(&bounds, true); + window_delegate_->SaveWindowPlacement(bounds, maximized); +} + void WindowGtk::SetInitialBounds(const gfx::Rect& create_bounds) { gfx::Rect saved_bounds(create_bounds.ToGdkRectangle()); if (window_delegate_->GetSavedWindowBounds(&saved_bounds)) { @@ -380,19 +420,4 @@ void WindowGtk::SizeWindowToDefault() { SetBounds(bounds, NULL); } -void WindowGtk::SaveWindowPosition() { - // The delegate may have gone away on us. - if (!window_delegate_) - return; - - NOTIMPLEMENTED(); -} - -// static -void WindowGtk::CallWindowStateEvent(GtkWidget* widget, - GdkEventWindowState* window_state) { - WindowGtk* window_gtk = GetWindowForNative(widget); - window_gtk->window_state_ = window_state->new_window_state; -} - } // namespace views diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h index 5012718..c996ce5 100644 --- a/views/window/window_gtk.h +++ b/views/window/window_gtk.h @@ -63,8 +63,12 @@ class WindowGtk : public WidgetGtk, public Window { // Overridden from WidgetGtk: virtual gboolean OnButtonPress(GtkWidget* widget, GdkEventButton* event); + virtual gboolean OnConfigureEvent(GtkWidget* widget, + GdkEventConfigure* event); virtual gboolean OnMotionNotify(GtkWidget* widget, GdkEventMotion* event); virtual void OnSizeAllocate(GtkWidget* widget, GtkAllocation* allocation); + virtual gboolean OnWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event); protected: // For the constructor. @@ -77,9 +81,12 @@ class WindowGtk : public WidgetGtk, public Window { void Init(const gfx::Rect& bounds); private: - // Used to track window state changes - static void CallWindowStateEvent(GtkWidget* widget, - GdkEventWindowState* window_state); + static gboolean CallConfigureEvent(GtkWidget* widget, + GdkEventConfigure* event, + WindowGtk* window_gtk); + static gboolean CallWindowStateEvent(GtkWidget* widget, + GdkEventWindowState* event, + WindowGtk* window_gtk); // Asks the delegate if any to save the window's location and size. void SaveWindowPosition(); |