| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "views/window/window_gtk.h" | 5 #include "views/window/window_gtk.h" |
| 6 | 6 |
| 7 #include "app/gfx/path.h" | 7 #include "app/gfx/path.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
| 10 #include "views/screen.h" |
| 10 #include "views/widget/root_view.h" | 11 #include "views/widget/root_view.h" |
| 11 #include "views/window/custom_frame_view.h" | 12 #include "views/window/custom_frame_view.h" |
| 12 #include "views/window/hit_test.h" | 13 #include "views/window/hit_test.h" |
| 13 #include "views/window/non_client_view.h" | 14 #include "views/window/non_client_view.h" |
| 14 #include "views/window/window_delegate.h" | 15 #include "views/window/window_delegate.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 // Converts a Windows-style hit test result code into a GDK window edge. | 19 // Converts a Windows-style hit test result code into a GDK window edge. |
| 19 GdkWindowEdge HitTestCodeToGDKWindowEdge(int hittest_code) { | 20 GdkWindowEdge HitTestCodeToGDKWindowEdge(int hittest_code) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return GDK_TOP_LEFT_CORNER; | 64 return GDK_TOP_LEFT_CORNER; |
| 64 case HTTOPRIGHT: | 65 case HTTOPRIGHT: |
| 65 return GDK_TOP_RIGHT_CORNER; | 66 return GDK_TOP_RIGHT_CORNER; |
| 66 default: | 67 default: |
| 67 break; | 68 break; |
| 68 } | 69 } |
| 69 // Default to something defaultish. | 70 // Default to something defaultish. |
| 70 return GDK_ARROW; | 71 return GDK_ARROW; |
| 71 } | 72 } |
| 72 | 73 |
| 73 gfx::Rect GetScreenWorkArea(GdkWindow* window) { | |
| 74 guchar* raw_data = NULL; | |
| 75 gint data_len = 0; | |
| 76 gboolean success = gdk_property_get(gdk_get_default_root_window(), | |
| 77 gdk_atom_intern("_NET_WORKAREA", FALSE), | |
| 78 gdk_atom_intern("CARDINAL", FALSE), | |
| 79 0, 0xFF, false, NULL, NULL, &data_len, | |
| 80 &raw_data); | |
| 81 DCHECK(success); | |
| 82 glong* data = reinterpret_cast<glong*>(raw_data); | |
| 83 return gfx::Rect(data[0], data[1], data[0] + data[2], data[1] + data[3]); | |
| 84 } | |
| 85 | |
| 86 } // namespace | 74 } // namespace |
| 87 | 75 |
| 88 namespace views { | 76 namespace views { |
| 89 | 77 |
| 90 WindowGtk::~WindowGtk() { | 78 WindowGtk::~WindowGtk() { |
| 91 } | 79 } |
| 92 | 80 |
| 93 // static | 81 // static |
| 94 Window* Window::CreateChromeWindow(gfx::NativeWindow parent, | 82 Window* Window::CreateChromeWindow(gfx::NativeWindow parent, |
| 95 const gfx::Rect& bounds, | 83 const gfx::Rect& bounds, |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 // We have a parent window, center over it. | 423 // We have a parent window, center over it. |
| 436 gint parent_x = 0; | 424 gint parent_x = 0; |
| 437 gint parent_y = 0; | 425 gint parent_y = 0; |
| 438 gtk_window_get_position(parent, &parent_x, &parent_y); | 426 gtk_window_get_position(parent, &parent_x, &parent_y); |
| 439 gint parent_w = 0; | 427 gint parent_w = 0; |
| 440 gint parent_h = 0; | 428 gint parent_h = 0; |
| 441 gtk_window_get_size(parent, &parent_w, &parent_h); | 429 gtk_window_get_size(parent, &parent_w, &parent_h); |
| 442 center_rect = gfx::Rect(parent_x, parent_y, parent_w, parent_h); | 430 center_rect = gfx::Rect(parent_x, parent_y, parent_w, parent_h); |
| 443 } else { | 431 } else { |
| 444 // We have no parent window, center over the screen. | 432 // We have no parent window, center over the screen. |
| 445 center_rect = GetScreenWorkArea(GTK_WIDGET(GetNativeWindow())->window); | 433 center_rect = Screen::GetMonitorWorkAreaNearestWindow(GetNativeWindow()); |
| 446 } | 434 } |
| 447 gfx::Size size = non_client_view_->GetPreferredSize(); | 435 gfx::Size size = non_client_view_->GetPreferredSize(); |
| 448 gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, | 436 gfx::Rect bounds(center_rect.x() + (center_rect.width() - size.width()) / 2, |
| 449 center_rect.y() + (center_rect.height() - size.height()) / 2, | 437 center_rect.y() + (center_rect.height() - size.height()) / 2, |
| 450 size.width(), size.height()); | 438 size.width(), size.height()); |
| 451 SetBounds(bounds, NULL); | 439 SetBounds(bounds, NULL); |
| 452 } | 440 } |
| 453 | 441 |
| 454 } // namespace views | 442 } // namespace views |
| OLD | NEW |