OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/browser_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 2262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 } | 2273 } |
2274 | 2274 |
2275 // Show / hide container if necessary. | 2275 // Show / hide container if necessary. |
2276 bool should_hide = devtools_window_ && !new_devtools_window; | 2276 bool should_hide = devtools_window_ && !new_devtools_window; |
2277 bool should_show = new_devtools_window && !devtools_window_; | 2277 bool should_show = new_devtools_window && !devtools_window_; |
2278 | 2278 |
2279 if (should_hide) | 2279 if (should_hide) |
2280 HideDevToolsContainer(); | 2280 HideDevToolsContainer(); |
2281 | 2281 |
2282 devtools_window_ = new_devtools_window; | 2282 devtools_window_ = new_devtools_window; |
2283 contents_insets_ = devtools_window_ ? devtools_window_->GetContentsInsets() : | 2283 contents_resizing_strategy_ = devtools_window_ ? |
2284 gfx::Insets(); | 2284 devtools_window_->GetContentsResizingStrategy() : |
| 2285 DevToolsContentsResizingStrategy(); |
2285 | 2286 |
2286 if (should_show) | 2287 if (should_show) |
2287 ShowDevToolsContainer(); | 2288 ShowDevToolsContainer(); |
2288 | 2289 |
2289 gtk_widget_queue_resize(devtools_floating_container_); | 2290 gtk_widget_queue_resize(devtools_floating_container_); |
2290 gtk_widget_queue_draw(devtools_floating_container_); | 2291 gtk_widget_queue_draw(devtools_floating_container_); |
2291 } | 2292 } |
2292 | 2293 |
2293 void BrowserWindowGtk::ShowDevToolsContainer() { | 2294 void BrowserWindowGtk::ShowDevToolsContainer() { |
2294 // Move devtools below contents. | 2295 // Move devtools below contents. |
2295 GdkWindow* const devtools_gdk_window = | 2296 GdkWindow* const devtools_gdk_window = |
2296 gtk_widget_get_window(devtools_container_->widget()); | 2297 gtk_widget_get_window(devtools_container_->widget()); |
2297 if (devtools_gdk_window) | 2298 if (devtools_gdk_window) |
2298 gdk_window_lower(devtools_gdk_window); | 2299 gdk_window_lower(devtools_gdk_window); |
2299 } | 2300 } |
2300 | 2301 |
2301 void BrowserWindowGtk::HideDevToolsContainer() { | 2302 void BrowserWindowGtk::HideDevToolsContainer() { |
2302 // This method is left intentionally blank. | 2303 // This method is left intentionally blank. |
2303 } | 2304 } |
2304 | 2305 |
2305 // static | 2306 // static |
2306 void BrowserWindowGtk::OnDevToolsContainerSetFloatingPosition( | 2307 void BrowserWindowGtk::OnDevToolsContainerSetFloatingPosition( |
2307 GtkFloatingContainer* container, GtkAllocation* allocation, | 2308 GtkFloatingContainer* container, GtkAllocation* allocation, |
2308 BrowserWindowGtk* browser_window) { | 2309 BrowserWindowGtk* browser_window) { |
2309 gfx::Insets insets = browser_window->contents_insets_; | 2310 GtkAllocation contents_allocation; |
| 2311 gtk_widget_get_allocation(browser_window->contents_container_->widget(), |
| 2312 &contents_allocation); |
2310 | 2313 |
2311 int contents_width = std::max(0, allocation->width - insets.width()); | 2314 gfx::Size container_size(allocation->width, allocation->height); |
2312 int contents_height = std::max(0, allocation->height - insets.height()); | 2315 gfx::Rect old_devtools_bounds(0, 0, allocation->width, allocation->height); |
2313 int contents_x = std::min(insets.left(), allocation->width); | 2316 gfx::Rect old_contents_bounds(contents_allocation.x, contents_allocation.y, |
2314 int contents_y = std::min(insets.top(), allocation->height); | 2317 contents_allocation.width, contents_allocation.height); |
| 2318 gfx::Rect new_devtools_bounds; |
| 2319 gfx::Rect new_contents_bounds; |
| 2320 |
| 2321 browser_window->contents_resizing_strategy_.Apply(container_size, |
| 2322 old_devtools_bounds, old_contents_bounds, |
| 2323 &new_devtools_bounds, &new_contents_bounds); |
2315 | 2324 |
2316 gtk_widget_set_size_request(browser_window->contents_container_->widget(), | 2325 gtk_widget_set_size_request(browser_window->contents_container_->widget(), |
2317 contents_width, contents_height); | 2326 new_contents_bounds.width(), new_contents_bounds.height()); |
2318 | 2327 |
2319 GValue value = { 0, }; | 2328 GValue value = { 0, }; |
2320 g_value_init(&value, G_TYPE_INT); | 2329 g_value_init(&value, G_TYPE_INT); |
2321 g_value_set_int(&value, contents_x); | 2330 g_value_set_int(&value, new_contents_bounds.x()); |
2322 gtk_container_child_set_property(GTK_CONTAINER(container), | 2331 gtk_container_child_set_property(GTK_CONTAINER(container), |
2323 browser_window->contents_container_->widget(), "x", &value); | 2332 browser_window->contents_container_->widget(), "x", &value); |
2324 g_value_set_int(&value, contents_y); | 2333 g_value_set_int(&value, new_contents_bounds.y()); |
2325 gtk_container_child_set_property(GTK_CONTAINER(container), | 2334 gtk_container_child_set_property(GTK_CONTAINER(container), |
2326 browser_window->contents_container_->widget(), "y", &value); | 2335 browser_window->contents_container_->widget(), "y", &value); |
2327 g_value_unset(&value); | 2336 g_value_unset(&value); |
2328 } | 2337 } |
2329 | 2338 |
2330 void BrowserWindowGtk::OnUseCustomChromeFrameChanged() { | 2339 void BrowserWindowGtk::OnUseCustomChromeFrameChanged() { |
2331 UpdateCustomFrame(); | 2340 UpdateCustomFrame(); |
2332 ui::SetHideTitlebarWhenMaximizedProperty( | 2341 ui::SetHideTitlebarWhenMaximizedProperty( |
2333 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window_)), | 2342 ui::GetX11WindowFromGtkWidget(GTK_WIDGET(window_)), |
2334 UseCustomFrame() ? ui::HIDE_TITLEBAR_WHEN_MAXIMIZED : | 2343 UseCustomFrame() ? ui::HIDE_TITLEBAR_WHEN_MAXIMIZED : |
(...skipping 26 matching lines...) Expand all Loading... |
2361 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2370 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2362 browser_window_gtk->Init(); | 2371 browser_window_gtk->Init(); |
2363 return browser_window_gtk; | 2372 return browser_window_gtk; |
2364 } | 2373 } |
2365 | 2374 |
2366 // static | 2375 // static |
2367 chrome::HostDesktopType BrowserWindow::AdjustHostDesktopType( | 2376 chrome::HostDesktopType BrowserWindow::AdjustHostDesktopType( |
2368 chrome::HostDesktopType desktop_type) { | 2377 chrome::HostDesktopType desktop_type) { |
2369 return desktop_type; | 2378 return desktop_type; |
2370 } | 2379 } |
OLD | NEW |