| 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 "chrome/browser/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
| 9 | 9 |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 } | 371 } |
| 372 return GDK_LAST_CURSOR; | 372 return GDK_LAST_CURSOR; |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace | 375 } // namespace |
| 376 | 376 |
| 377 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; | 377 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; |
| 378 | 378 |
| 379 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) | 379 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) |
| 380 : browser_(browser), | 380 : browser_(browser), |
| 381 full_screen_(false), | |
| 382 #if defined(OS_CHROMEOS) | 381 #if defined(OS_CHROMEOS) |
| 383 drag_active_(false), | 382 drag_active_(false), |
| 384 panel_controller_(NULL), | 383 panel_controller_(NULL), |
| 385 #endif | 384 #endif |
| 386 frame_cursor_(NULL), | 385 frame_cursor_(NULL), |
| 387 is_active_(true) { | 386 is_active_(true) { |
| 388 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, | 387 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, |
| 389 browser_->profile()->GetPrefs(), this); | 388 browser_->profile()->GetPrefs(), this); |
| 390 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 389 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 391 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); | 390 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 639 |
| 641 gfx::Rect BrowserWindowGtk::GetNormalBounds() const { | 640 gfx::Rect BrowserWindowGtk::GetNormalBounds() const { |
| 642 return bounds_; | 641 return bounds_; |
| 643 } | 642 } |
| 644 | 643 |
| 645 bool BrowserWindowGtk::IsMaximized() const { | 644 bool BrowserWindowGtk::IsMaximized() const { |
| 646 return (state_ & GDK_WINDOW_STATE_MAXIMIZED); | 645 return (state_ & GDK_WINDOW_STATE_MAXIMIZED); |
| 647 } | 646 } |
| 648 | 647 |
| 649 void BrowserWindowGtk::SetFullscreen(bool fullscreen) { | 648 void BrowserWindowGtk::SetFullscreen(bool fullscreen) { |
| 650 full_screen_ = fullscreen; | 649 // gtk_window_(un)fullscreen asks the window manager to toggle the EWMH |
| 651 UpdateCustomFrame(); | 650 // for fullscreen windows. Not all window managers support this. |
| 652 | |
| 653 if (fullscreen) { | 651 if (fullscreen) { |
| 654 // These four balanced by ShowSupportedWindowFeatures(). | |
| 655 toolbar_->Hide(); | |
| 656 tabstrip_->Hide(); | |
| 657 bookmark_bar_->Hide(false); | |
| 658 extension_shelf_->Hide(); | |
| 659 | |
| 660 gtk_window_fullscreen(window_); | 652 gtk_window_fullscreen(window_); |
| 661 } else { | 653 } else { |
| 662 ShowSupportedWindowFeatures(); | |
| 663 | |
| 664 gtk_window_unfullscreen(window_); | 654 gtk_window_unfullscreen(window_); |
| 665 } | 655 } |
| 666 } | 656 } |
| 667 | 657 |
| 668 bool BrowserWindowGtk::IsFullscreen() const { | 658 bool BrowserWindowGtk::IsFullscreen() const { |
| 669 return full_screen_; | 659 return (state_ & GDK_WINDOW_STATE_FULLSCREEN); |
| 670 } | 660 } |
| 671 | 661 |
| 672 LocationBar* BrowserWindowGtk::GetLocationBar() const { | 662 LocationBar* BrowserWindowGtk::GetLocationBar() const { |
| 673 return toolbar_->GetLocationBar(); | 663 return toolbar_->GetLocationBar(); |
| 674 } | 664 } |
| 675 | 665 |
| 676 void BrowserWindowGtk::SetFocusToLocationBar() { | 666 void BrowserWindowGtk::SetFocusToLocationBar() { |
| 677 GetLocationBar()->FocusLocation(); | 667 GetLocationBar()->FocusLocation(); |
| 678 } | 668 } |
| 679 | 669 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 } | 879 } |
| 890 | 880 |
| 891 void BrowserWindowGtk::TabStripEmpty() { | 881 void BrowserWindowGtk::TabStripEmpty() { |
| 892 UpdateUIForContents(NULL); | 882 UpdateUIForContents(NULL); |
| 893 } | 883 } |
| 894 | 884 |
| 895 void BrowserWindowGtk::MaybeShowBookmarkBar(TabContents* contents, | 885 void BrowserWindowGtk::MaybeShowBookmarkBar(TabContents* contents, |
| 896 bool animate) { | 886 bool animate) { |
| 897 // Don't change the visibility state when the browser is full screen or if | 887 // Don't change the visibility state when the browser is full screen or if |
| 898 // the bookmark bar isn't supported. | 888 // the bookmark bar isn't supported. |
| 899 if (full_screen_ || !IsBookmarkBarSupported()) | 889 if (IsFullscreen() || !IsBookmarkBarSupported()) |
| 900 return; | 890 return; |
| 901 | 891 |
| 902 bool show_bar = false; | 892 bool show_bar = false; |
| 903 | 893 |
| 904 if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) | 894 if (browser_->SupportsWindowFeature(Browser::FEATURE_BOOKMARKBAR) |
| 905 && contents) { | 895 && contents) { |
| 906 bookmark_bar_->SetProfile(contents->profile()); | 896 bookmark_bar_->SetProfile(contents->profile()); |
| 907 bookmark_bar_->SetPageNavigator(contents); | 897 bookmark_bar_->SetPageNavigator(contents); |
| 908 show_bar = true; | 898 show_bar = true; |
| 909 } | 899 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 | 953 |
| 964 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) { | 954 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) { |
| 965 if (bounds_.size() != bounds.size()) | 955 if (bounds_.size() != bounds.size()) |
| 966 OnSizeChanged(bounds.width(), bounds.height()); | 956 OnSizeChanged(bounds.width(), bounds.height()); |
| 967 | 957 |
| 968 bounds_ = bounds; | 958 bounds_ = bounds; |
| 969 SaveWindowPosition(); | 959 SaveWindowPosition(); |
| 970 } | 960 } |
| 971 | 961 |
| 972 void BrowserWindowGtk::OnStateChanged(GdkWindowState state) { | 962 void BrowserWindowGtk::OnStateChanged(GdkWindowState state) { |
| 963 // If we care about more than full screen changes, we should pass through |
| 964 // |changed_mask| from GdkEventWindowState. |
| 965 bool fullscreen_state_changed = (state_ & GDK_WINDOW_STATE_FULLSCREEN) != |
| 966 (state & GDK_WINDOW_STATE_FULLSCREEN); |
| 967 |
| 973 state_ = state; | 968 state_ = state; |
| 974 | 969 |
| 970 if (fullscreen_state_changed) { |
| 971 if (state & GDK_WINDOW_STATE_FULLSCREEN) { |
| 972 UpdateCustomFrame(); |
| 973 toolbar_->Hide(); |
| 974 tabstrip_->Hide(); |
| 975 bookmark_bar_->Hide(false); |
| 976 extension_shelf_->Hide(); |
| 977 } else { |
| 978 UpdateCustomFrame(); |
| 979 ShowSupportedWindowFeatures(); |
| 980 } |
| 981 } |
| 982 |
| 975 UpdateWindowShape(bounds_.width(), bounds_.height()); | 983 UpdateWindowShape(bounds_.width(), bounds_.height()); |
| 976 SaveWindowPosition(); | 984 SaveWindowPosition(); |
| 977 } | 985 } |
| 978 | 986 |
| 979 bool BrowserWindowGtk::CanClose() const { | 987 bool BrowserWindowGtk::CanClose() const { |
| 980 #if defined(OS_CHROMEOS) | 988 #if defined(OS_CHROMEOS) |
| 981 if (drag_active_) | 989 if (drag_active_) |
| 982 return false; | 990 return false; |
| 983 #endif | 991 #endif |
| 984 | 992 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 SkColorGetG(frame_color), SkColorGetB(frame_color)); | 1218 SkColorGetG(frame_color), SkColorGetB(frame_color)); |
| 1211 gtk_widget_modify_bg(GTK_WIDGET(window_), GTK_STATE_NORMAL, | 1219 gtk_widget_modify_bg(GTK_WIDGET(window_), GTK_STATE_NORMAL, |
| 1212 &frame_color_gdk); | 1220 &frame_color_gdk); |
| 1213 } | 1221 } |
| 1214 | 1222 |
| 1215 void BrowserWindowGtk::OnSizeChanged(int width, int height) { | 1223 void BrowserWindowGtk::OnSizeChanged(int width, int height) { |
| 1216 UpdateWindowShape(width, height); | 1224 UpdateWindowShape(width, height); |
| 1217 } | 1225 } |
| 1218 | 1226 |
| 1219 void BrowserWindowGtk::UpdateWindowShape(int width, int height) { | 1227 void BrowserWindowGtk::UpdateWindowShape(int width, int height) { |
| 1220 if (use_custom_frame_.GetValue() && !full_screen_ && !IsMaximized()) { | 1228 if (use_custom_frame_.GetValue() && !IsFullscreen() && !IsMaximized()) { |
| 1221 // Make the top corners rounded. We set a mask that includes most of the | 1229 // Make the top corners rounded. We set a mask that includes most of the |
| 1222 // window except for a few pixels in the top two corners. | 1230 // window except for a few pixels in the top two corners. |
| 1223 GdkRectangle top_rect = { 3, 0, width - 6, 1 }; | 1231 GdkRectangle top_rect = { 3, 0, width - 6, 1 }; |
| 1224 GdkRectangle mid_rect = { 1, 1, width - 2, 2 }; | 1232 GdkRectangle mid_rect = { 1, 1, width - 2, 2 }; |
| 1225 GdkRectangle bot_rect = { 0, 3, width, height - 3 }; | 1233 GdkRectangle bot_rect = { 0, 3, width, height - 3 }; |
| 1226 GdkRegion* mask = gdk_region_rectangle(&top_rect); | 1234 GdkRegion* mask = gdk_region_rectangle(&top_rect); |
| 1227 gdk_region_union_with_rect(mask, &mid_rect); | 1235 gdk_region_union_with_rect(mask, &mid_rect); |
| 1228 gdk_region_union_with_rect(mask, &bot_rect); | 1236 gdk_region_union_with_rect(mask, &bot_rect); |
| 1229 gdk_window_shape_combine_region(GTK_WIDGET(window_)->window, mask, 0, 0); | 1237 gdk_window_shape_combine_region(GTK_WIDGET(window_)->window, mask, 0, 0); |
| 1230 gdk_region_destroy(mask); | 1238 gdk_region_destroy(mask); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1256 gtk_accel_group_connect( | 1264 gtk_accel_group_connect( |
| 1257 accel_group, | 1265 accel_group, |
| 1258 kAcceleratorMap[i].keyval, | 1266 kAcceleratorMap[i].keyval, |
| 1259 kAcceleratorMap[i].modifier_type, | 1267 kAcceleratorMap[i].modifier_type, |
| 1260 GtkAccelFlags(0), | 1268 GtkAccelFlags(0), |
| 1261 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); | 1269 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
| 1262 } | 1270 } |
| 1263 } | 1271 } |
| 1264 | 1272 |
| 1265 void BrowserWindowGtk::UpdateCustomFrame() { | 1273 void BrowserWindowGtk::UpdateCustomFrame() { |
| 1266 bool enable = use_custom_frame_.GetValue() && !full_screen_; | 1274 bool enable = use_custom_frame_.GetValue() && !IsFullscreen(); |
| 1267 gtk_window_set_decorated(window_, !enable); | 1275 gtk_window_set_decorated(window_, !use_custom_frame_.GetValue()); |
| 1268 titlebar_->UpdateCustomFrame(enable); | 1276 titlebar_->UpdateCustomFrame(enable); |
| 1269 UpdateWindowShape(bounds_.width(), bounds_.height()); | 1277 UpdateWindowShape(bounds_.width(), bounds_.height()); |
| 1270 } | 1278 } |
| 1271 | 1279 |
| 1272 void BrowserWindowGtk::SaveWindowPosition() { | 1280 void BrowserWindowGtk::SaveWindowPosition() { |
| 1281 // Don't save the window position if it's in full screen mode because we |
| 1282 // don't want to restart the browser in full screen mode. |
| 1283 if (IsFullscreen()) |
| 1284 return; |
| 1285 |
| 1273 // Browser::SaveWindowPlacement is used for session restore. | 1286 // Browser::SaveWindowPlacement is used for session restore. |
| 1274 if (browser_->ShouldSaveWindowPlacement()) | 1287 if (browser_->ShouldSaveWindowPlacement()) |
| 1275 browser_->SaveWindowPlacement(bounds_, IsMaximized()); | 1288 browser_->SaveWindowPlacement(bounds_, IsMaximized()); |
| 1276 | 1289 |
| 1277 // We also need to save the placement for startup. | 1290 // We also need to save the placement for startup. |
| 1278 // This is a web of calls between views and delegates on Windows, but the | 1291 // This is a web of calls between views and delegates on Windows, but the |
| 1279 // crux of the logic follows. See also cocoa/browser_window_controller.mm. | 1292 // crux of the logic follows. See also cocoa/browser_window_controller.mm. |
| 1280 if (!g_browser_process->local_state()) | 1293 if (!g_browser_process->local_state()) |
| 1281 return; | 1294 return; |
| 1282 | 1295 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 *edge = GDK_WINDOW_EDGE_NORTH_EAST; | 1532 *edge = GDK_WINDOW_EDGE_NORTH_EAST; |
| 1520 } else if (y < bounds_.height() - kResizeAreaCornerSize) { | 1533 } else if (y < bounds_.height() - kResizeAreaCornerSize) { |
| 1521 *edge = GDK_WINDOW_EDGE_EAST; | 1534 *edge = GDK_WINDOW_EDGE_EAST; |
| 1522 } else { | 1535 } else { |
| 1523 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; | 1536 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; |
| 1524 } | 1537 } |
| 1525 return true; | 1538 return true; |
| 1526 } | 1539 } |
| 1527 NOTREACHED(); | 1540 NOTREACHED(); |
| 1528 } | 1541 } |
| OLD | NEW |