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(); |
tmdiep
2014/03/04 03:13:14
The initial window bounds is broken on GTK because
benwells
2014/03/05 02:33:30
Is it more broken with your change? I'm wondering
tmdiep
2014/03/05 03:06:47
It's not significantly broken. Existing apps will
| |
65 gtk_window_move(window_, params.bounds.x(), params.bounds.y()); | 65 gfx::Rect initial_bounds = params.GetInitialWindowBounds(frame_insets); |
66 | |
67 if (initial_bounds.x() != INT_MIN && initial_bounds.y() != INT_MIN) | |
benwells
2014/03/05 02:33:30
Isn't there a constant you should be using instead
| |
68 gtk_window_move(window_, initial_bounds.x(), initial_bounds.y()); | |
66 | 69 |
67 // This is done to avoid a WM "feature" where setting the window size to | 70 // 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. | 71 // the monitor size causes the WM to set the EWMH for full screen mode. |
69 int win_height = params.bounds.height(); | 72 int win_height = initial_bounds.height(); |
70 if (frameless_ && | 73 if (frameless_ && |
71 gtk_window_util::BoundsMatchMonitorSize(window_, params.bounds)) { | 74 gtk_window_util::BoundsMatchMonitorSize(window_, initial_bounds)) { |
72 win_height -= 1; | 75 win_height -= 1; |
73 } | 76 } |
74 gtk_window_set_default_size(window_, params.bounds.width(), win_height); | 77 gtk_window_set_default_size(window_, initial_bounds.width(), win_height); |
75 | 78 |
76 resizable_ = params.resizable; | 79 resizable_ = params.resizable; |
77 if (!resizable_) { | 80 if (!resizable_) { |
78 // If the window doesn't have a size request when we set resizable to | 81 // If the window doesn't have a size request when we set resizable to |
79 // false, GTK will shrink the window to 1x1px. | 82 // false, GTK will shrink the window to 1x1px. |
80 gtk_widget_set_size_request(GTK_WIDGET(window_), | 83 gtk_widget_set_size_request(GTK_WIDGET(window_), |
81 params.bounds.width(), win_height); | 84 initial_bounds.width(), win_height); |
82 gtk_window_set_resizable(window_, FALSE); | 85 gtk_window_set_resizable(window_, FALSE); |
83 } | 86 } |
84 | 87 |
85 // make sure bounds_ and restored_bounds_ have correct values until we | 88 // make sure bounds_ and restored_bounds_ have correct values until we |
86 // get our first configure-event | 89 // get our first configure-event |
87 bounds_ = restored_bounds_ = params.bounds; | 90 bounds_ = restored_bounds_ = initial_bounds; |
88 gint x, y; | 91 gint x, y; |
89 gtk_window_get_position(window_, &x, &y); | 92 gtk_window_get_position(window_, &x, &y); |
90 bounds_.set_origin(gfx::Point(x, y)); | 93 bounds_.set_origin(gfx::Point(x, y)); |
91 | 94 |
92 // Hide titlebar when {frame: 'none'} specified on AppWindow.. | 95 // Hide titlebar when {frame: 'none'} specified on AppWindow.. |
93 if (frameless_) | 96 if (frameless_) |
94 gtk_window_set_decorated(window_, false); | 97 gtk_window_set_decorated(window_, false); |
95 | 98 |
96 if (always_on_top_) | 99 if (always_on_top_) |
97 gtk_window_set_keep_above(window_, TRUE); | 100 gtk_window_set_keep_above(window_, TRUE); |
98 | 101 |
99 size_constraints_.set_minimum_size(params.minimum_size); | 102 size_constraints_.set_minimum_size( |
100 size_constraints_.set_maximum_size(params.maximum_size); | 103 params.GetContentMinimumSize(frame_insets)); |
101 UpdateWindowMinMaxSize(); | 104 size_constraints_.set_maximum_size( |
105 params.GetContentMaximumSize(frame_insets)); | |
106 UpdateContentMinMaxSize(); | |
102 | 107 |
103 // In some (older) versions of compiz, raising top-level windows when they | 108 // 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 | 109 // 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 | 110 // 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. | 111 // compiz, suppress such raises, as they are not necessary in compiz anyway. |
107 if (ui::GuessWindowManager() == ui::WM_COMPIZ) | 112 if (ui::GuessWindowManager() == ui::WM_COMPIZ) |
108 suppress_window_raise_ = true; | 113 suppress_window_raise_ = true; |
109 | 114 |
110 gtk_window_set_title(window_, extension()->name().c_str()); | 115 gtk_window_set_title(window_, extension()->name().c_str()); |
111 | 116 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 if (!(state_ & GDK_WINDOW_STATE_MAXIMIZED)) { | 477 if (!(state_ & GDK_WINDOW_STATE_MAXIMIZED)) { |
473 gtk_window_maximize(window_); | 478 gtk_window_maximize(window_); |
474 } else { | 479 } else { |
475 maximize_pending_ = false; | 480 maximize_pending_ = false; |
476 if (!resizable_) | 481 if (!resizable_) |
477 gtk_window_set_resizable(window_, FALSE); | 482 gtk_window_set_resizable(window_, FALSE); |
478 } | 483 } |
479 } | 484 } |
480 } | 485 } |
481 | 486 |
482 void NativeAppWindowGtk::UpdateWindowMinMaxSize() { | 487 void NativeAppWindowGtk::UpdateContentMinMaxSize() { |
483 GdkGeometry hints; | 488 GdkGeometry hints; |
484 int hints_mask = 0; | 489 int hints_mask = 0; |
485 if (size_constraints_.HasMinimumSize()) { | 490 if (size_constraints_.HasMinimumSize()) { |
486 gfx::Size min_size = size_constraints_.GetMinimumSize(); | 491 gfx::Size min_size = size_constraints_.GetMinimumSize(); |
487 hints.min_height = min_size.height(); | 492 hints.min_height = min_size.height(); |
488 hints.min_width = min_size.width(); | 493 hints.min_width = min_size.width(); |
489 hints_mask |= GDK_HINT_MIN_SIZE; | 494 hints_mask |= GDK_HINT_MIN_SIZE; |
490 } | 495 } |
491 if (size_constraints_.HasMaximumSize()) { | 496 if (size_constraints_.HasMaximumSize()) { |
492 gfx::Size max_size = size_constraints_.GetMaximumSize(); | 497 gfx::Size max_size = size_constraints_.GetMaximumSize(); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
732 } | 737 } |
733 | 738 |
734 void NativeAppWindowGtk::HideWithApp() {} | 739 void NativeAppWindowGtk::HideWithApp() {} |
735 void NativeAppWindowGtk::ShowWithApp() {} | 740 void NativeAppWindowGtk::ShowWithApp() {} |
736 | 741 |
737 void NativeAppWindowGtk::UpdateShelfMenu() { | 742 void NativeAppWindowGtk::UpdateShelfMenu() { |
738 // TODO(tmdiep): To be implemented for GTK. | 743 // TODO(tmdiep): To be implemented for GTK. |
739 NOTIMPLEMENTED(); | 744 NOTIMPLEMENTED(); |
740 } | 745 } |
741 | 746 |
742 gfx::Size NativeAppWindowGtk::GetMinimumSize() const { | 747 gfx::Size NativeAppWindowGtk::GetContentMinimumSize() const { |
743 return size_constraints_.GetMinimumSize(); | 748 return size_constraints_.GetMinimumSize(); |
744 } | 749 } |
745 | 750 |
746 void NativeAppWindowGtk::SetMinimumSize(const gfx::Size& size) { | 751 void NativeAppWindowGtk::SetContentMinimumSize(const gfx::Size& size) { |
747 size_constraints_.set_minimum_size(size); | 752 size_constraints_.set_minimum_size(size); |
748 UpdateWindowMinMaxSize(); | 753 UpdateContentMinMaxSize(); |
749 } | 754 } |
750 | 755 |
751 gfx::Size NativeAppWindowGtk::GetMaximumSize() const { | 756 gfx::Size NativeAppWindowGtk::GetContentMaximumSize() const { |
752 return size_constraints_.GetMaximumSize(); | 757 return size_constraints_.GetMaximumSize(); |
753 } | 758 } |
754 | 759 |
755 void NativeAppWindowGtk::SetMaximumSize(const gfx::Size& size) { | 760 void NativeAppWindowGtk::SetContentMaximumSize(const gfx::Size& size) { |
756 size_constraints_.set_maximum_size(size); | 761 size_constraints_.set_maximum_size(size); |
757 UpdateWindowMinMaxSize(); | 762 UpdateContentMinMaxSize(); |
758 } | 763 } |
OLD | NEW |