summaryrefslogtreecommitdiffstats
path: root/views/window
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 18:27:27 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-04 18:27:27 +0000
commit03c3b1e4170e845842833ad64cf36676043a357a (patch)
tree6d215da94ba60e53c6023a5b0ace750bd4a0e3ff /views/window
parent6254686d113f977626e824b02e8cb676556734ec (diff)
downloadchromium_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
Diffstat (limited to 'views/window')
-rw-r--r--views/window/window_gtk.cc73
-rw-r--r--views/window/window_gtk.h13
2 files changed, 59 insertions, 27 deletions
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();