OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/panels/panel_browser_window_gtk.h" | 5 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" |
6 | 6 |
7 #include "chrome/browser/ui/panels/panel.h" | 7 #include "chrome/browser/ui/panels/panel.h" |
8 #include "chrome/browser/ui/panels/panel_manager.h" | 8 #include "chrome/browser/ui/panels/panel_manager.h" |
9 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" | 9 #include "chrome/browser/ui/panels/panel_mouse_watcher.h" |
10 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" | 10 #include "chrome/browser/ui/panels/panel_settings_menu_model.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 PanelBrowserWindowGtk::PanelBrowserWindowGtk(Browser* browser, | 21 PanelBrowserWindowGtk::PanelBrowserWindowGtk(Browser* browser, |
22 Panel* panel, | 22 Panel* panel, |
23 const gfx::Rect& bounds) | 23 const gfx::Rect& bounds) |
24 : BrowserWindowGtk(browser), | 24 : BrowserWindowGtk(browser), |
25 last_mouse_down_(NULL), | 25 last_mouse_down_(NULL), |
26 drag_widget_(NULL), | 26 drag_widget_(NULL), |
27 destroy_drag_widget_factory_(this), | 27 destroy_drag_widget_factory_(this), |
28 drag_end_factory_(this), | 28 drag_end_factory_(this), |
29 panel_(panel), | 29 panel_(panel), |
30 bounds_(bounds), | 30 bounds_(bounds), |
31 restored_height_(bounds.height()) { | 31 restored_height_(bounds.height()), |
| 32 non_client_area_size_known_(false) { |
32 } | 33 } |
33 | 34 |
34 PanelBrowserWindowGtk::~PanelBrowserWindowGtk() { | 35 PanelBrowserWindowGtk::~PanelBrowserWindowGtk() { |
35 if (drag_widget_) { | 36 if (drag_widget_) { |
36 // Terminate the grab if we have it. We could do this using any widget, | 37 // Terminate the grab if we have it. We could do this using any widget, |
37 // |drag_widget_| is just convenient. | 38 // |drag_widget_| is just convenient. |
38 gtk_grab_add(drag_widget_); | 39 gtk_grab_add(drag_widget_); |
39 gtk_grab_remove(drag_widget_); | 40 gtk_grab_remove(drag_widget_); |
40 DestroyDragWidget(); | 41 DestroyDragWidget(); |
41 } | 42 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 93 } |
93 | 94 |
94 void PanelBrowserWindowGtk::SetGeometryHints() { | 95 void PanelBrowserWindowGtk::SetGeometryHints() { |
95 // Set minimum height the window can be set to. | 96 // Set minimum height the window can be set to. |
96 GdkGeometry hints; | 97 GdkGeometry hints; |
97 hints.min_height = PanelManager::minimized_panel_height(); | 98 hints.min_height = PanelManager::minimized_panel_height(); |
98 hints.min_width = panel_->min_size().width(); | 99 hints.min_width = panel_->min_size().width(); |
99 gtk_window_set_geometry_hints( | 100 gtk_window_set_geometry_hints( |
100 window(), GTK_WIDGET(window()), &hints, GDK_HINT_MIN_SIZE); | 101 window(), GTK_WIDGET(window()), &hints, GDK_HINT_MIN_SIZE); |
101 | 102 |
102 SetBoundsImpl(bounds_, true); | 103 SetBoundsImpl(bounds_, true); // Force a move to set the initial position. |
103 } | 104 } |
104 | 105 |
105 void PanelBrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { | 106 void PanelBrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { |
106 // This should never be called. | 107 // This should never be called. |
107 DLOG(WARNING) << "Unexpected call to PanelBrowserWindowGtk::SetBounds()"; | 108 DLOG(WARNING) << "Unexpected call to PanelBrowserWindowGtk::SetBounds()"; |
108 } | 109 } |
109 | 110 |
| 111 void PanelBrowserWindowGtk::OnSizeChanged(int width, int height) { |
| 112 BrowserWindowGtk::OnSizeChanged(width, height); |
| 113 |
| 114 if (!non_client_area_size_known_) { |
| 115 non_client_area_size_known_ = true; |
| 116 panel_->OnNonClientExtentAvailable(); |
| 117 } |
| 118 } |
| 119 |
110 bool PanelBrowserWindowGtk::UseCustomFrame() { | 120 bool PanelBrowserWindowGtk::UseCustomFrame() { |
111 // We always use custom frame for panels. | 121 // We always use custom frame for panels. |
112 return TRUE; | 122 return TRUE; |
113 } | 123 } |
114 | 124 |
115 void PanelBrowserWindowGtk::ShowSettingsMenu(GtkWidget* widget, | 125 void PanelBrowserWindowGtk::ShowSettingsMenu(GtkWidget* widget, |
116 GdkEventButton* event) { | 126 GdkEventButton* event) { |
117 if (!settings_menu_.get()) { | 127 if (!settings_menu_.get()) { |
118 settings_menu_model_.reset(new PanelSettingsMenuModel(panel_.get())); | 128 settings_menu_model_.reset(new PanelSettingsMenuModel(panel_.get())); |
119 settings_menu_.reset(new MenuGtk(this, settings_menu_model_.get())); | 129 settings_menu_.reset(new MenuGtk(this, settings_menu_model_.get())); |
120 } | 130 } |
121 settings_menu_->PopupForWidget(widget, event->button, event->time); | 131 settings_menu_->PopupForWidget(widget, event->button, event->time); |
122 } | 132 } |
123 | 133 |
124 void PanelBrowserWindowGtk::ShowPanel() { | 134 void PanelBrowserWindowGtk::ShowPanel() { |
125 Show(); | 135 Show(); |
126 } | 136 } |
127 | 137 |
128 void PanelBrowserWindowGtk::ShowPanelInactive() { | 138 void PanelBrowserWindowGtk::ShowPanelInactive() { |
129 ShowInactive(); | 139 ShowInactive(); |
130 } | 140 } |
131 | 141 |
132 gfx::Rect PanelBrowserWindowGtk::GetPanelBounds() const { | 142 gfx::Rect PanelBrowserWindowGtk::GetPanelBounds() const { |
133 return bounds_; | 143 return bounds_; |
134 } | 144 } |
135 | 145 |
136 void PanelBrowserWindowGtk::SetPanelBounds(const gfx::Rect& bounds) { | 146 void PanelBrowserWindowGtk::SetPanelBounds(const gfx::Rect& bounds) { |
137 if (bounds != bounds_) | 147 if (bounds != bounds_) |
138 SetBoundsImpl(bounds, true); | 148 SetBoundsImpl(bounds, false); // Only move if necessary. |
139 } | 149 } |
140 | 150 |
141 void PanelBrowserWindowGtk::OnPanelExpansionStateChanged( | 151 void PanelBrowserWindowGtk::OnPanelExpansionStateChanged( |
142 Panel::ExpansionState expansion_state) { | 152 Panel::ExpansionState expansion_state) { |
143 // TODO(prasadt): This is very similar to what we do for windows. Look into | 153 // TODO(prasadt): This is very similar to what we do for windows. Look into |
144 // sharing this implementation across platforms. | 154 // sharing this implementation across platforms. |
145 int height; | 155 int height; |
146 switch (expansion_state) { | 156 switch (expansion_state) { |
147 case Panel::EXPANDED: | 157 case Panel::EXPANDED: |
148 height = restored_height_; | 158 height = restored_height_; |
(...skipping 10 matching lines...) Expand all Loading... |
159 NOTREACHED(); | 169 NOTREACHED(); |
160 height = restored_height_; | 170 height = restored_height_; |
161 break; | 171 break; |
162 } | 172 } |
163 | 173 |
164 gfx::Rect bounds = bounds_; | 174 gfx::Rect bounds = bounds_; |
165 int bottom = panel_->manager()->GetBottomPositionForExpansionState( | 175 int bottom = panel_->manager()->GetBottomPositionForExpansionState( |
166 expansion_state); | 176 expansion_state); |
167 bounds.set_y(bottom - height); | 177 bounds.set_y(bottom - height); |
168 bounds.set_height(height); | 178 bounds.set_height(height); |
169 | 179 SetBoundsImpl(bounds, false); // Only move if necessary. |
170 // Do not move the window when expansion state changes. Just change the size. | |
171 // Because of GDK_GRAVITY_SOUTH_EAST gravity, the window will stay docked to | |
172 // the bottom. | |
173 SetBoundsImpl(bounds, false); | |
174 } | 180 } |
175 | 181 |
176 bool PanelBrowserWindowGtk::ShouldBringUpPanelTitlebar(int mouse_x, | 182 bool PanelBrowserWindowGtk::ShouldBringUpPanelTitlebar(int mouse_x, |
177 int mouse_y) const { | 183 int mouse_y) const { |
178 return bounds_.x() <= mouse_x && mouse_x <= bounds_.right() && | 184 return bounds_.x() <= mouse_x && mouse_x <= bounds_.right() && |
179 mouse_y >= bounds_.y(); | 185 mouse_y >= bounds_.y(); |
180 } | 186 } |
181 | 187 |
182 void PanelBrowserWindowGtk::ClosePanel() { | 188 void PanelBrowserWindowGtk::ClosePanel() { |
183 Close(); | 189 Close(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 250 |
245 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { | 251 Browser* PanelBrowserWindowGtk::GetPanelBrowser() const { |
246 return browser(); | 252 return browser(); |
247 } | 253 } |
248 | 254 |
249 void PanelBrowserWindowGtk::DestroyPanelBrowser() { | 255 void PanelBrowserWindowGtk::DestroyPanelBrowser() { |
250 DestroyBrowser(); | 256 DestroyBrowser(); |
251 } | 257 } |
252 | 258 |
253 gfx::Size PanelBrowserWindowGtk::GetNonClientAreaExtent() const { | 259 gfx::Size PanelBrowserWindowGtk::GetNonClientAreaExtent() const { |
254 NOTIMPLEMENTED(); | 260 return GetNonClientFrameSize(); |
255 return gfx::Size(); | |
256 } | 261 } |
257 | 262 |
258 int PanelBrowserWindowGtk::GetRestoredHeight() const { | 263 int PanelBrowserWindowGtk::GetRestoredHeight() const { |
259 NOTIMPLEMENTED(); | 264 return restored_height_; |
260 return 0; | |
261 } | 265 } |
262 | 266 |
263 void PanelBrowserWindowGtk::SetRestoredHeight(int height) { | 267 void PanelBrowserWindowGtk::SetRestoredHeight(int height) { |
264 NOTIMPLEMENTED(); | 268 restored_height_ = height; |
265 } | 269 } |
266 | 270 |
267 void PanelBrowserWindowGtk::SetBoundsImpl(const gfx::Rect& bounds, bool move) { | 271 void PanelBrowserWindowGtk::SetBoundsImpl(const gfx::Rect& bounds, |
| 272 bool force_move) { |
| 273 // Only move if required by caller, or if bottom right corner will change. |
| 274 // Panels use window gravity of GDK_GRAVITY_SOUTH_EAST which means the |
| 275 // window is anchored to the bottom right corner on resize, making it |
| 276 // unnecessary to move the window if the bottom right corner is unchanged. |
| 277 bool move = force_move || bounds.right() != bounds_.right() || |
| 278 bounds.bottom() != bounds_.bottom(); |
| 279 |
268 bounds_ = bounds; | 280 bounds_ = bounds; |
269 if (move) | 281 if (move) |
270 gtk_window_move(window_, bounds.x(), bounds.y()); | 282 gtk_window_move(window_, bounds.x(), bounds.y()); |
271 gtk_window_resize(window(), bounds.width(), bounds.height()); | 283 gtk_window_resize(window(), bounds.width(), bounds.height()); |
272 } | 284 } |
273 | 285 |
274 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { | 286 void PanelBrowserWindowGtk::WillProcessEvent(GdkEvent* event) { |
275 // Nothing to do. | 287 // Nothing to do. |
276 } | 288 } |
277 | 289 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 518 |
507 void NativePanelTestingGtk::SetMousePositionForMinimizeRestore( | 519 void NativePanelTestingGtk::SetMousePositionForMinimizeRestore( |
508 const gfx::Point& hover_point) { | 520 const gfx::Point& hover_point) { |
509 PanelMouseWatcher::GetInstance()->HandleMouseMovement(hover_point); | 521 PanelMouseWatcher::GetInstance()->HandleMouseMovement(hover_point); |
510 MessageLoopForUI::current()->RunAllPending(); | 522 MessageLoopForUI::current()->RunAllPending(); |
511 } | 523 } |
512 | 524 |
513 int NativePanelTestingGtk::TitleOnlyHeight() const { | 525 int NativePanelTestingGtk::TitleOnlyHeight() const { |
514 return panel_browser_window_gtk_->TitleOnlyHeight(); | 526 return panel_browser_window_gtk_->TitleOnlyHeight(); |
515 } | 527 } |
OLD | NEW |