| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/apps/native_app_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/apps/native_app_window_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/message_loop/message_pump_gtk.h" | 10 #include "base/message_loop/message_pump_gtk.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 ui::WindowShowState NativeAppWindowGtk::GetRestoredState() const { | 196 ui::WindowShowState NativeAppWindowGtk::GetRestoredState() const { |
| 197 if (IsMaximized()) | 197 if (IsMaximized()) |
| 198 return ui::SHOW_STATE_MAXIMIZED; | 198 return ui::SHOW_STATE_MAXIMIZED; |
| 199 if (IsFullscreen()) | 199 if (IsFullscreen()) |
| 200 return ui::SHOW_STATE_FULLSCREEN; | 200 return ui::SHOW_STATE_FULLSCREEN; |
| 201 return ui::SHOW_STATE_NORMAL; | 201 return ui::SHOW_STATE_NORMAL; |
| 202 } | 202 } |
| 203 | 203 |
| 204 gfx::Rect NativeAppWindowGtk::GetBounds() const { | 204 gfx::Rect NativeAppWindowGtk::GetBounds() const { |
| 205 gfx::Rect window_bounds = bounds_; | 205 // :GetBounds() is expecting the outer window bounds to be returned (ie. |
| 206 window_bounds.Inset(-GetFrameInsets()); | 206 // including window decorations). The internal |bounds_| is not including them |
| 207 return window_bounds; | 207 // and trying to add the decoration to |bounds_| would require calling |
| 208 // gdk_window_get_frame_extents. The best thing to do is to directly get the |
| 209 // frame bounds and only use the internal value if we can't. |
| 210 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); |
| 211 if (!gdk_window) |
| 212 return bounds_; |
| 213 |
| 214 GdkRectangle window_bounds = {0}; |
| 215 gdk_window_get_frame_extents(gdk_window, &window_bounds); |
| 216 return gfx::Rect(window_bounds.x, window_bounds.y, |
| 217 window_bounds.width, window_bounds.height); |
| 208 } | 218 } |
| 209 | 219 |
| 210 void NativeAppWindowGtk::Show() { | 220 void NativeAppWindowGtk::Show() { |
| 211 gtk_window_present(window_); | 221 gtk_window_present(window_); |
| 212 } | 222 } |
| 213 | 223 |
| 214 void NativeAppWindowGtk::ShowInactive() { | 224 void NativeAppWindowGtk::ShowInactive() { |
| 215 gtk_window_set_focus_on_map(window_, false); | 225 gtk_window_set_focus_on_map(window_, false); |
| 216 gtk_widget_show(GTK_WIDGET(window_)); | 226 gtk_widget_show(GTK_WIDGET(window_)); |
| 217 } | 227 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 287 |
| 278 // Represent the window to keep restoration behavior consistency with Windows | 288 // Represent the window to keep restoration behavior consistency with Windows |
| 279 // platform. | 289 // platform. |
| 280 // TODO(zhchbin): verify whether we need this until http://crbug.com/261013 is | 290 // TODO(zhchbin): verify whether we need this until http://crbug.com/261013 is |
| 281 // fixed. | 291 // fixed. |
| 282 gtk_window_present(window_); | 292 gtk_window_present(window_); |
| 283 } | 293 } |
| 284 | 294 |
| 285 void NativeAppWindowGtk::SetBounds(const gfx::Rect& bounds) { | 295 void NativeAppWindowGtk::SetBounds(const gfx::Rect& bounds) { |
| 286 gfx::Rect content_bounds = bounds; | 296 gfx::Rect content_bounds = bounds; |
| 287 content_bounds.Inset(GetFrameInsets()); | |
| 288 gtk_window_move(window_, content_bounds.x(), content_bounds.y()); | 297 gtk_window_move(window_, content_bounds.x(), content_bounds.y()); |
| 289 if (!resizable_) { | 298 if (!resizable_) { |
| 290 if (frameless_ && | 299 if (frameless_ && |
| 291 gtk_window_util::BoundsMatchMonitorSize(window_, content_bounds)) { | 300 gtk_window_util::BoundsMatchMonitorSize(window_, content_bounds)) { |
| 292 content_bounds.set_height(content_bounds.height() - 1); | 301 content_bounds.set_height(content_bounds.height() - 1); |
| 293 } | 302 } |
| 294 // TODO(jeremya): set_size_request doesn't honor min/max size, so the | 303 // TODO(jeremya): set_size_request doesn't honor min/max size, so the |
| 295 // bounds should be constrained manually. | 304 // bounds should be constrained manually. |
| 296 gtk_widget_set_size_request(GTK_WIDGET(window_), | 305 gtk_widget_set_size_request(GTK_WIDGET(window_), |
| 297 content_bounds.width(), content_bounds.height()); | 306 content_bounds.width(), content_bounds.height()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 313 if (x_event->type == PropertyNotify && | 322 if (x_event->type == PropertyNotify && |
| 314 x_event->xproperty.atom == atom_cache_.GetAtom("_NET_WM_STATE") && | 323 x_event->xproperty.atom == atom_cache_.GetAtom("_NET_WM_STATE") && |
| 315 GTK_WIDGET(window_)->window && | 324 GTK_WIDGET(window_)->window && |
| 316 ui::GetAtomArrayProperty(GDK_WINDOW_XWINDOW(GTK_WIDGET(window_)->window), | 325 ui::GetAtomArrayProperty(GDK_WINDOW_XWINDOW(GTK_WIDGET(window_)->window), |
| 317 "_NET_WM_STATE", | 326 "_NET_WM_STATE", |
| 318 &atom_list)) { | 327 &atom_list)) { |
| 319 std::vector< ::Atom>::iterator it = | 328 std::vector< ::Atom>::iterator it = |
| 320 std::find(atom_list.begin(), | 329 std::find(atom_list.begin(), |
| 321 atom_list.end(), | 330 atom_list.end(), |
| 322 atom_cache_.GetAtom("_NET_WM_STATE_HIDDEN")); | 331 atom_cache_.GetAtom("_NET_WM_STATE_HIDDEN")); |
| 332 |
| 323 state_ = (it != atom_list.end()) ? GDK_WINDOW_STATE_ICONIFIED : | 333 state_ = (it != atom_list.end()) ? GDK_WINDOW_STATE_ICONIFIED : |
| 324 static_cast<GdkWindowState>(state_ & ~GDK_WINDOW_STATE_ICONIFIED); | 334 static_cast<GdkWindowState>(state_ & ~GDK_WINDOW_STATE_ICONIFIED); |
| 325 | 335 |
| 336 // TODO(mlamouri): we don't need to send a change event all the time here. |
| 337 // Only when |state_| has actually changed. |
| 326 shell_window_->OnNativeWindowChanged(); | 338 shell_window_->OnNativeWindowChanged(); |
| 327 } | 339 } |
| 328 | 340 |
| 329 return GDK_FILTER_CONTINUE; | 341 return GDK_FILTER_CONTINUE; |
| 330 } | 342 } |
| 331 | 343 |
| 332 void NativeAppWindowGtk::FlashFrame(bool flash) { | 344 void NativeAppWindowGtk::FlashFrame(bool flash) { |
| 333 gtk_window_set_urgency_hint(window_, flash); | 345 gtk_window_set_urgency_hint(window_, flash); |
| 334 } | 346 } |
| 335 | 347 |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 hints_mask |= GDK_HINT_MAX_SIZE; | 710 hints_mask |= GDK_HINT_MAX_SIZE; |
| 699 } | 711 } |
| 700 if (hints_mask) { | 712 if (hints_mask) { |
| 701 gtk_window_set_geometry_hints( | 713 gtk_window_set_geometry_hints( |
| 702 window_, | 714 window_, |
| 703 GTK_WIDGET(window_), | 715 GTK_WIDGET(window_), |
| 704 &hints, | 716 &hints, |
| 705 static_cast<GdkWindowHints>(hints_mask)); | 717 static_cast<GdkWindowHints>(hints_mask)); |
| 706 } | 718 } |
| 707 } | 719 } |
| OLD | NEW |