| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 atom_cache_(base::MessagePumpGtk::GetDefaultXDisplay(), kAtomsToCache), | 54 atom_cache_(base::MessagePumpGtk::GetDefaultXDisplay(), kAtomsToCache), |
| 55 is_x_event_listened_(false) { | 55 is_x_event_listened_(false) { |
| 56 Observe(web_contents()); | 56 Observe(web_contents()); |
| 57 | 57 |
| 58 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 58 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 59 | 59 |
| 60 gfx::NativeView native_view = | 60 gfx::NativeView native_view = |
| 61 web_contents()->GetView()->GetNativeView(); | 61 web_contents()->GetView()->GetNativeView(); |
| 62 gtk_container_add(GTK_CONTAINER(window_), native_view); | 62 gtk_container_add(GTK_CONTAINER(window_), native_view); |
| 63 | 63 |
| 64 if (params.bounds.x() != INT_MIN && params.bounds.y() != INT_MIN) | 64 gfx::Insets frame_insets = GetFrameInsets(); |
| 65 gtk_window_move(window_, params.bounds.x(), params.bounds.y()); | 65 gfx::Rect initial_bounds = params.GetInitialWindowBounds(frame_insets); |
| 66 |
| 67 typedef apps::AppWindow::BoundsSpecification BoundsSpecification; |
| 68 if (initial_bounds.x() != BoundsSpecification::kUnspecifiedPosition && |
| 69 initial_bounds.y() != BoundsSpecification::kUnspecifiedPosition) { |
| 70 gtk_window_move(window_, initial_bounds.x(), initial_bounds.y()); |
| 71 } |
| 66 | 72 |
| 67 // This is done to avoid a WM "feature" where setting the window size to | 73 // This is done to avoid a WM "feature" where setting the window size to |
| 68 // the monitor size causes the WM to set the EWMH for full screen mode. | 74 // the monitor size causes the WM to set the EWMH for full screen mode. |
| 69 int win_height = params.bounds.height(); | 75 int win_height = initial_bounds.height(); |
| 70 if (frameless_ && | 76 if (frameless_ && |
| 71 gtk_window_util::BoundsMatchMonitorSize(window_, params.bounds)) { | 77 gtk_window_util::BoundsMatchMonitorSize(window_, initial_bounds)) { |
| 72 win_height -= 1; | 78 win_height -= 1; |
| 73 } | 79 } |
| 74 gtk_window_set_default_size(window_, params.bounds.width(), win_height); | 80 gtk_window_set_default_size(window_, initial_bounds.width(), win_height); |
| 75 | 81 |
| 76 resizable_ = params.resizable; | 82 resizable_ = params.resizable; |
| 77 if (!resizable_) { | 83 if (!resizable_) { |
| 78 // If the window doesn't have a size request when we set resizable to | 84 // If the window doesn't have a size request when we set resizable to |
| 79 // false, GTK will shrink the window to 1x1px. | 85 // false, GTK will shrink the window to 1x1px. |
| 80 gtk_widget_set_size_request(GTK_WIDGET(window_), | 86 gtk_widget_set_size_request(GTK_WIDGET(window_), |
| 81 params.bounds.width(), win_height); | 87 initial_bounds.width(), win_height); |
| 82 gtk_window_set_resizable(window_, FALSE); | 88 gtk_window_set_resizable(window_, FALSE); |
| 83 } | 89 } |
| 84 | 90 |
| 85 // make sure bounds_ and restored_bounds_ have correct values until we | 91 // make sure bounds_ and restored_bounds_ have correct values until we |
| 86 // get our first configure-event | 92 // get our first configure-event |
| 87 bounds_ = restored_bounds_ = params.bounds; | 93 bounds_ = restored_bounds_ = initial_bounds; |
| 88 gint x, y; | 94 gint x, y; |
| 89 gtk_window_get_position(window_, &x, &y); | 95 gtk_window_get_position(window_, &x, &y); |
| 90 bounds_.set_origin(gfx::Point(x, y)); | 96 bounds_.set_origin(gfx::Point(x, y)); |
| 91 | 97 |
| 92 // Hide titlebar when {frame: 'none'} specified on AppWindow.. | 98 // Hide titlebar when {frame: 'none'} specified on AppWindow.. |
| 93 if (frameless_) | 99 if (frameless_) |
| 94 gtk_window_set_decorated(window_, false); | 100 gtk_window_set_decorated(window_, false); |
| 95 | 101 |
| 96 if (always_on_top_) | 102 if (always_on_top_) |
| 97 gtk_window_set_keep_above(window_, TRUE); | 103 gtk_window_set_keep_above(window_, TRUE); |
| 98 | 104 |
| 99 size_constraints_.set_minimum_size(params.minimum_size); | 105 size_constraints_.set_minimum_size( |
| 100 size_constraints_.set_maximum_size(params.maximum_size); | 106 params.GetContentMinimumSize(frame_insets)); |
| 101 UpdateWindowMinMaxSize(); | 107 size_constraints_.set_maximum_size( |
| 108 params.GetContentMaximumSize(frame_insets)); |
| 109 UpdateContentMinMaxSize(); |
| 102 | 110 |
| 103 // In some (older) versions of compiz, raising top-level windows when they | 111 // In some (older) versions of compiz, raising top-level windows when they |
| 104 // are partially off-screen causes them to get snapped back on screen, not | 112 // are partially off-screen causes them to get snapped back on screen, not |
| 105 // always even on the current virtual desktop. If we are running under | 113 // always even on the current virtual desktop. If we are running under |
| 106 // compiz, suppress such raises, as they are not necessary in compiz anyway. | 114 // compiz, suppress such raises, as they are not necessary in compiz anyway. |
| 107 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | 115 if (ui::GuessWindowManager() == ui::WM_COMPIZ) |
| 108 suppress_window_raise_ = true; | 116 suppress_window_raise_ = true; |
| 109 | 117 |
| 110 gtk_window_set_title(window_, extension()->name().c_str()); | 118 gtk_window_set_title(window_, extension()->name().c_str()); |
| 111 | 119 |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (!(state_ & GDK_WINDOW_STATE_MAXIMIZED)) { | 480 if (!(state_ & GDK_WINDOW_STATE_MAXIMIZED)) { |
| 473 gtk_window_maximize(window_); | 481 gtk_window_maximize(window_); |
| 474 } else { | 482 } else { |
| 475 maximize_pending_ = false; | 483 maximize_pending_ = false; |
| 476 if (!resizable_) | 484 if (!resizable_) |
| 477 gtk_window_set_resizable(window_, FALSE); | 485 gtk_window_set_resizable(window_, FALSE); |
| 478 } | 486 } |
| 479 } | 487 } |
| 480 } | 488 } |
| 481 | 489 |
| 482 void NativeAppWindowGtk::UpdateWindowMinMaxSize() { | 490 void NativeAppWindowGtk::UpdateContentMinMaxSize() { |
| 483 GdkGeometry hints; | 491 GdkGeometry hints; |
| 484 int hints_mask = 0; | 492 int hints_mask = 0; |
| 485 if (size_constraints_.HasMinimumSize()) { | 493 if (size_constraints_.HasMinimumSize()) { |
| 486 gfx::Size min_size = size_constraints_.GetMinimumSize(); | 494 gfx::Size min_size = size_constraints_.GetMinimumSize(); |
| 487 hints.min_height = min_size.height(); | 495 hints.min_height = min_size.height(); |
| 488 hints.min_width = min_size.width(); | 496 hints.min_width = min_size.width(); |
| 489 hints_mask |= GDK_HINT_MIN_SIZE; | 497 hints_mask |= GDK_HINT_MIN_SIZE; |
| 490 } | 498 } |
| 491 if (size_constraints_.HasMaximumSize()) { | 499 if (size_constraints_.HasMaximumSize()) { |
| 492 gfx::Size max_size = size_constraints_.GetMaximumSize(); | 500 gfx::Size max_size = size_constraints_.GetMaximumSize(); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 } | 740 } |
| 733 | 741 |
| 734 void NativeAppWindowGtk::HideWithApp() {} | 742 void NativeAppWindowGtk::HideWithApp() {} |
| 735 void NativeAppWindowGtk::ShowWithApp() {} | 743 void NativeAppWindowGtk::ShowWithApp() {} |
| 736 | 744 |
| 737 void NativeAppWindowGtk::UpdateShelfMenu() { | 745 void NativeAppWindowGtk::UpdateShelfMenu() { |
| 738 // TODO(tmdiep): To be implemented for GTK. | 746 // TODO(tmdiep): To be implemented for GTK. |
| 739 NOTIMPLEMENTED(); | 747 NOTIMPLEMENTED(); |
| 740 } | 748 } |
| 741 | 749 |
| 742 gfx::Size NativeAppWindowGtk::GetMinimumSize() const { | 750 gfx::Size NativeAppWindowGtk::GetContentMinimumSize() const { |
| 743 return size_constraints_.GetMinimumSize(); | 751 return size_constraints_.GetMinimumSize(); |
| 744 } | 752 } |
| 745 | 753 |
| 746 void NativeAppWindowGtk::SetMinimumSize(const gfx::Size& size) { | 754 void NativeAppWindowGtk::SetContentMinimumSize(const gfx::Size& size) { |
| 747 size_constraints_.set_minimum_size(size); | 755 size_constraints_.set_minimum_size(size); |
| 748 UpdateWindowMinMaxSize(); | 756 UpdateContentMinMaxSize(); |
| 749 } | 757 } |
| 750 | 758 |
| 751 gfx::Size NativeAppWindowGtk::GetMaximumSize() const { | 759 gfx::Size NativeAppWindowGtk::GetContentMaximumSize() const { |
| 752 return size_constraints_.GetMaximumSize(); | 760 return size_constraints_.GetMaximumSize(); |
| 753 } | 761 } |
| 754 | 762 |
| 755 void NativeAppWindowGtk::SetMaximumSize(const gfx::Size& size) { | 763 void NativeAppWindowGtk::SetContentMaximumSize(const gfx::Size& size) { |
| 756 size_constraints_.set_maximum_size(size); | 764 size_constraints_.set_maximum_size(size); |
| 757 UpdateWindowMinMaxSize(); | 765 UpdateContentMinMaxSize(); |
| 758 } | 766 } |
| OLD | NEW |