| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "chrome/browser/location_bar.h" | 48 #include "chrome/browser/location_bar.h" |
| 49 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | 49 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" |
| 50 #include "chrome/browser/tab_contents/tab_contents.h" | 50 #include "chrome/browser/tab_contents/tab_contents.h" |
| 51 #include "chrome/browser/tab_contents/tab_contents_view.h" | 51 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 52 #include "chrome/common/notification_service.h" | 52 #include "chrome/common/notification_service.h" |
| 53 #include "chrome/common/pref_names.h" | 53 #include "chrome/common/pref_names.h" |
| 54 #include "chrome/common/pref_service.h" | 54 #include "chrome/common/pref_service.h" |
| 55 #include "grit/app_resources.h" | 55 #include "grit/app_resources.h" |
| 56 #include "grit/theme_resources.h" | 56 #include "grit/theme_resources.h" |
| 57 | 57 |
| 58 #if defined(LINUX2) | 58 #if defined(OS_CHROMEOS) |
| 59 #include "chrome/browser/views/panel_controller.h" | 59 #include "chrome/browser/views/panel_controller.h" |
| 60 #include "chrome/browser/views/tabs/tab_overview_types.h" | 60 #include "chrome/browser/views/tabs/tab_overview_types.h" |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 // The number of milliseconds between loading animation frames. | 65 // The number of milliseconds between loading animation frames. |
| 66 const int kLoadingAnimationFrameTimeMs = 30; | 66 const int kLoadingAnimationFrameTimeMs = 30; |
| 67 | 67 |
| 68 const char* kBrowserWindowKey = "__BROWSER_WINDOW_GTK__"; | 68 const char* kBrowserWindowKey = "__BROWSER_WINDOW_GTK__"; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 { GDK_d, IDC_STAR, GDK_CONTROL_MASK }, | 214 { GDK_d, IDC_STAR, GDK_CONTROL_MASK }, |
| 215 { XF86XK_AddFavorite, IDC_STAR, GdkModifierType(0) }, | 215 { XF86XK_AddFavorite, IDC_STAR, GdkModifierType(0) }, |
| 216 { XF86XK_Favorites, IDC_SHOW_BOOKMARK_BAR, GdkModifierType(0) }, | 216 { XF86XK_Favorites, IDC_SHOW_BOOKMARK_BAR, GdkModifierType(0) }, |
| 217 { XF86XK_History, IDC_SHOW_HISTORY, GdkModifierType(0) }, | 217 { XF86XK_History, IDC_SHOW_HISTORY, GdkModifierType(0) }, |
| 218 { GDK_o, IDC_OPEN_FILE, GDK_CONTROL_MASK }, | 218 { GDK_o, IDC_OPEN_FILE, GDK_CONTROL_MASK }, |
| 219 { GDK_F11, IDC_FULLSCREEN, GdkModifierType(0) }, | 219 { GDK_F11, IDC_FULLSCREEN, GdkModifierType(0) }, |
| 220 { GDK_u, IDC_VIEW_SOURCE, GDK_CONTROL_MASK }, | 220 { GDK_u, IDC_VIEW_SOURCE, GDK_CONTROL_MASK }, |
| 221 { GDK_p, IDC_PRINT, GDK_CONTROL_MASK }, | 221 { GDK_p, IDC_PRINT, GDK_CONTROL_MASK }, |
| 222 { GDK_Escape, IDC_TASK_MANAGER, GDK_SHIFT_MASK }, | 222 { GDK_Escape, IDC_TASK_MANAGER, GDK_SHIFT_MASK }, |
| 223 | 223 |
| 224 #if defined(LINUX2) | 224 #if defined(OS_CHROMEOS) |
| 225 { GDK_f, IDC_FULLSCREEN, | 225 { GDK_f, IDC_FULLSCREEN, |
| 226 GdkModifierType(GDK_CONTROL_MASK | GDK_MOD1_MASK) }, | 226 GdkModifierType(GDK_CONTROL_MASK | GDK_MOD1_MASK) }, |
| 227 { GDK_Delete, IDC_TASK_MANAGER, | 227 { GDK_Delete, IDC_TASK_MANAGER, |
| 228 GdkModifierType(GDK_CONTROL_MASK | GDK_MOD1_MASK) }, | 228 GdkModifierType(GDK_CONTROL_MASK | GDK_MOD1_MASK) }, |
| 229 { GDK_comma, IDC_CONTROL_PANEL, GdkModifierType(GDK_CONTROL_MASK) }, | 229 { GDK_comma, IDC_CONTROL_PANEL, GdkModifierType(GDK_CONTROL_MASK) }, |
| 230 #endif | 230 #endif |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 int GetCommandId(guint accel_key, GdkModifierType modifier) { | 233 int GetCommandId(guint accel_key, GdkModifierType modifier) { |
| 234 // Bug 9806: If capslock is on, we will get a capital letter as accel_key. | 234 // Bug 9806: If capslock is on, we will get a capital letter as accel_key. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 return GDK_LAST_CURSOR; | 359 return GDK_LAST_CURSOR; |
| 360 } | 360 } |
| 361 | 361 |
| 362 } // namespace | 362 } // namespace |
| 363 | 363 |
| 364 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; | 364 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; |
| 365 | 365 |
| 366 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) | 366 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) |
| 367 : browser_(browser), | 367 : browser_(browser), |
| 368 full_screen_(false), | 368 full_screen_(false), |
| 369 #if defined(LINUX2) | 369 #if defined(OS_CHROMEOS) |
| 370 drag_active_(false), | 370 drag_active_(false), |
| 371 panel_controller_(NULL), | 371 panel_controller_(NULL), |
| 372 #endif | 372 #endif |
| 373 frame_cursor_(NULL) { | 373 frame_cursor_(NULL) { |
| 374 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, | 374 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, |
| 375 browser_->profile()->GetPrefs(), this); | 375 browser_->profile()->GetPrefs(), this); |
| 376 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 376 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 377 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); | 377 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); |
| 378 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | | 378 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | |
| 379 GDK_POINTER_MOTION_MASK); | 379 GDK_POINTER_MOTION_MASK); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 467 |
| 468 void BrowserWindowGtk::Show() { | 468 void BrowserWindowGtk::Show() { |
| 469 // The Browser associated with this browser window must become the active | 469 // The Browser associated with this browser window must become the active |
| 470 // browser at the time Show() is called. This is the natural behaviour under | 470 // browser at the time Show() is called. This is the natural behaviour under |
| 471 // Windows, but gtk_widget_show won't show the widget (and therefore won't | 471 // Windows, but gtk_widget_show won't show the widget (and therefore won't |
| 472 // call OnFocusIn()) until we return to the runloop. Therefore any calls to | 472 // call OnFocusIn()) until we return to the runloop. Therefore any calls to |
| 473 // BrowserList::GetLastActive() (for example, in bookmark_util), will return | 473 // BrowserList::GetLastActive() (for example, in bookmark_util), will return |
| 474 // the previous browser instead if we don't explicitly set it here. | 474 // the previous browser instead if we don't explicitly set it here. |
| 475 BrowserList::SetLastActive(browser()); | 475 BrowserList::SetLastActive(browser()); |
| 476 | 476 |
| 477 #if defined(LINUX2) | 477 #if defined(OS_CHROMEOS) |
| 478 if (browser_->type() == Browser::TYPE_POPUP) { | 478 if (browser_->type() == Browser::TYPE_POPUP) { |
| 479 panel_controller_ = new PanelController(this); | 479 panel_controller_ = new PanelController(this); |
| 480 } else { | 480 } else { |
| 481 TabOverviewTypes::instance()->SetWindowType( | 481 TabOverviewTypes::instance()->SetWindowType( |
| 482 GTK_WIDGET(window_), | 482 GTK_WIDGET(window_), |
| 483 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, | 483 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, |
| 484 NULL); | 484 NULL); |
| 485 } | 485 } |
| 486 #endif | 486 #endif |
| 487 | 487 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 507 return; | 507 return; |
| 508 | 508 |
| 509 SaveWindowPosition(); | 509 SaveWindowPosition(); |
| 510 | 510 |
| 511 GtkWidget* window = GTK_WIDGET(window_); | 511 GtkWidget* window = GTK_WIDGET(window_); |
| 512 // To help catch bugs in any event handlers that might get fired during the | 512 // To help catch bugs in any event handlers that might get fired during the |
| 513 // destruction, set window_ to NULL before any handlers will run. | 513 // destruction, set window_ to NULL before any handlers will run. |
| 514 window_ = NULL; | 514 window_ = NULL; |
| 515 gtk_widget_destroy(window); | 515 gtk_widget_destroy(window); |
| 516 | 516 |
| 517 #if defined(LINUX2) | 517 #if defined(OS_CHROMEOS) |
| 518 if (panel_controller_) { | 518 if (panel_controller_) { |
| 519 panel_controller_->Close(); | 519 panel_controller_->Close(); |
| 520 } | 520 } |
| 521 #endif | 521 #endif |
| 522 } | 522 } |
| 523 | 523 |
| 524 void BrowserWindowGtk::Activate() { | 524 void BrowserWindowGtk::Activate() { |
| 525 gtk_window_present(window_); | 525 gtk_window_present(window_); |
| 526 } | 526 } |
| 527 | 527 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 547 StatusBubble* BrowserWindowGtk::GetStatusBubble() { | 547 StatusBubble* BrowserWindowGtk::GetStatusBubble() { |
| 548 return status_bubble_.get(); | 548 return status_bubble_.get(); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) { | 551 void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) { |
| 552 // On Windows, this is used for a performance optimization. | 552 // On Windows, this is used for a performance optimization. |
| 553 // http://code.google.com/p/chromium/issues/detail?id=12291 | 553 // http://code.google.com/p/chromium/issues/detail?id=12291 |
| 554 } | 554 } |
| 555 | 555 |
| 556 void BrowserWindowGtk::UpdateTitleBar() { | 556 void BrowserWindowGtk::UpdateTitleBar() { |
| 557 #if defined(LINUX2) | 557 #if defined(OS_CHROMEOS) |
| 558 if (panel_controller_) | 558 if (panel_controller_) |
| 559 panel_controller_->UpdateTitleBar(); | 559 panel_controller_->UpdateTitleBar(); |
| 560 #endif | 560 #endif |
| 561 | 561 |
| 562 std::wstring title = browser_->GetCurrentPageTitle(); | 562 std::wstring title = browser_->GetCurrentPageTitle(); |
| 563 gtk_window_set_title(window_, WideToUTF8(title).c_str()); | 563 gtk_window_set_title(window_, WideToUTF8(title).c_str()); |
| 564 if (ShouldShowWindowIcon()) { | 564 if (ShouldShowWindowIcon()) { |
| 565 // TODO(tc): If we're showing a title bar, we should update the app icon. | 565 // TODO(tc): If we're showing a title bar, we should update the app icon. |
| 566 } | 566 } |
| 567 } | 567 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 } | 873 } |
| 874 | 874 |
| 875 void BrowserWindowGtk::OnStateChanged(GdkWindowState state) { | 875 void BrowserWindowGtk::OnStateChanged(GdkWindowState state) { |
| 876 state_ = state; | 876 state_ = state; |
| 877 | 877 |
| 878 UpdateWindowShape(bounds_.width(), bounds_.height()); | 878 UpdateWindowShape(bounds_.width(), bounds_.height()); |
| 879 SaveWindowPosition(); | 879 SaveWindowPosition(); |
| 880 } | 880 } |
| 881 | 881 |
| 882 bool BrowserWindowGtk::CanClose() const { | 882 bool BrowserWindowGtk::CanClose() const { |
| 883 #if defined(LINUX2) | 883 #if defined(OS_CHROMEOS) |
| 884 if (drag_active_) | 884 if (drag_active_) |
| 885 return false; | 885 return false; |
| 886 #endif | 886 #endif |
| 887 | 887 |
| 888 // You cannot close a frame for which there is an active originating drag | 888 // You cannot close a frame for which there is an active originating drag |
| 889 // session. | 889 // session. |
| 890 if (tabstrip_->IsDragSessionActive()) | 890 if (tabstrip_->IsDragSessionActive()) |
| 891 return false; | 891 return false; |
| 892 | 892 |
| 893 // Give beforeunload handlers the chance to cancel the close before we hide | 893 // Give beforeunload handlers the chance to cancel the close before we hide |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 gtk_box_pack_start(GTK_BOX(render_area_vbox_), | 1047 gtk_box_pack_start(GTK_BOX(render_area_vbox_), |
| 1048 infobar_container_->widget(), | 1048 infobar_container_->widget(), |
| 1049 FALSE, FALSE, 0); | 1049 FALSE, FALSE, 0); |
| 1050 | 1050 |
| 1051 status_bubble_.reset(new StatusBubbleGtk(browser_->profile())); | 1051 status_bubble_.reset(new StatusBubbleGtk(browser_->profile())); |
| 1052 | 1052 |
| 1053 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); | 1053 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); |
| 1054 contents_container_->AddContainerToBox(render_area_vbox_); | 1054 contents_container_->AddContainerToBox(render_area_vbox_); |
| 1055 gtk_widget_show_all(render_area_vbox_); | 1055 gtk_widget_show_all(render_area_vbox_); |
| 1056 | 1056 |
| 1057 #if defined(LINUX2) | 1057 #if defined(OS_CHROMEOS) |
| 1058 if (browser_->type() == Browser::TYPE_POPUP) { | 1058 if (browser_->type() == Browser::TYPE_POPUP) { |
| 1059 toolbar_->Hide(); | 1059 toolbar_->Hide(); |
| 1060 // The window manager needs the min size for popups | 1060 // The window manager needs the min size for popups |
| 1061 gtk_widget_set_size_request( | 1061 gtk_widget_set_size_request( |
| 1062 GTK_WIDGET(window_), bounds_.width(), bounds_.height()); | 1062 GTK_WIDGET(window_), bounds_.width(), bounds_.height()); |
| 1063 } | 1063 } |
| 1064 #endif | 1064 #endif |
| 1065 | 1065 |
| 1066 // We have to realize the window before we try to apply a window shape mask. | 1066 // We have to realize the window before we try to apply a window shape mask. |
| 1067 gtk_widget_realize(GTK_WIDGET(window_)); | 1067 gtk_widget_realize(GTK_WIDGET(window_)); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1391 *edge = GDK_WINDOW_EDGE_NORTH_EAST; | 1391 *edge = GDK_WINDOW_EDGE_NORTH_EAST; |
| 1392 } else if (y < bounds_.height() - kResizeAreaCornerSize) { | 1392 } else if (y < bounds_.height() - kResizeAreaCornerSize) { |
| 1393 *edge = GDK_WINDOW_EDGE_EAST; | 1393 *edge = GDK_WINDOW_EDGE_EAST; |
| 1394 } else { | 1394 } else { |
| 1395 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; | 1395 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; |
| 1396 } | 1396 } |
| 1397 return true; | 1397 return true; |
| 1398 } | 1398 } |
| 1399 NOTREACHED(); | 1399 NOTREACHED(); |
| 1400 } | 1400 } |
| OLD | NEW |