| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(LINUX2) |
| 59 #include "chrome/browser/views/panel_controller.h" |
| 59 #include "chrome/browser/views/tabs/tab_overview_types.h" | 60 #include "chrome/browser/views/tabs/tab_overview_types.h" |
| 60 #endif | 61 #endif |
| 61 | 62 |
| 62 namespace { | 63 namespace { |
| 63 | 64 |
| 64 // The number of milliseconds between loading animation frames. | 65 // The number of milliseconds between loading animation frames. |
| 65 const int kLoadingAnimationFrameTimeMs = 30; | 66 const int kLoadingAnimationFrameTimeMs = 30; |
| 66 | 67 |
| 67 const char* kBrowserWindowKey = "__BROWSER_WINDOW_GTK__"; | 68 const char* kBrowserWindowKey = "__BROWSER_WINDOW_GTK__"; |
| 68 | 69 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 | 353 |
| 353 } // namespace | 354 } // namespace |
| 354 | 355 |
| 355 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; | 356 std::map<XID, GtkWindow*> BrowserWindowGtk::xid_map_; |
| 356 | 357 |
| 357 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) | 358 BrowserWindowGtk::BrowserWindowGtk(Browser* browser) |
| 358 : browser_(browser), | 359 : browser_(browser), |
| 359 full_screen_(false), | 360 full_screen_(false), |
| 360 #if defined(LINUX2) | 361 #if defined(LINUX2) |
| 361 drag_active_(false), | 362 drag_active_(false), |
| 363 panel_controller_(NULL), |
| 362 #endif | 364 #endif |
| 363 frame_cursor_(NULL) { | 365 frame_cursor_(NULL) { |
| 364 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, | 366 use_custom_frame_.Init(prefs::kUseCustomChromeFrame, |
| 365 browser_->profile()->GetPrefs(), this); | 367 browser_->profile()->GetPrefs(), this); |
| 366 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); | 368 window_ = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
| 367 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); | 369 g_object_set_data(G_OBJECT(window_), kBrowserWindowKey, this); |
| 368 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | | 370 gtk_widget_add_events(GTK_WIDGET(window_), GDK_BUTTON_PRESS_MASK | |
| 369 GDK_POINTER_MOTION_MASK); | 371 GDK_POINTER_MOTION_MASK); |
| 370 | 372 |
| 371 SetWindowIcon(); | 373 SetWindowIcon(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 IDR_WINDOW_BOTTOM_RIGHT_CORNER); | 451 IDR_WINDOW_BOTTOM_RIGHT_CORNER); |
| 450 } | 452 } |
| 451 | 453 |
| 452 custom_frame_border->RenderToWidget(widget); | 454 custom_frame_border->RenderToWidget(widget); |
| 453 } | 455 } |
| 454 | 456 |
| 455 return FALSE; // Allow subwidgets to paint. | 457 return FALSE; // Allow subwidgets to paint. |
| 456 } | 458 } |
| 457 | 459 |
| 458 void BrowserWindowGtk::Show() { | 460 void BrowserWindowGtk::Show() { |
| 459 gtk_widget_show(GTK_WIDGET(window_)); | |
| 460 | |
| 461 // The Browser associated with this browser window must become the active | 461 // The Browser associated with this browser window must become the active |
| 462 // browser at the time Show() is called. This is the natural behaviour under | 462 // browser at the time Show() is called. This is the natural behaviour under |
| 463 // Windows, but gtk_widget_show won't show the widget (and therefore won't | 463 // Windows, but gtk_widget_show won't show the widget (and therefore won't |
| 464 // call OnFocusIn()) until we return to the runloop. Therefore any calls to | 464 // call OnFocusIn()) until we return to the runloop. Therefore any calls to |
| 465 // BrowserList::GetLastActive() (for example, in bookmark_util), will return | 465 // BrowserList::GetLastActive() (for example, in bookmark_util), will return |
| 466 // the previous browser instead if we don't explicitly set it here. | 466 // the previous browser instead if we don't explicitly set it here. |
| 467 BrowserList::SetLastActive(browser()); | 467 BrowserList::SetLastActive(browser()); |
| 468 | 468 |
| 469 #if defined(LINUX2) | 469 #if defined(LINUX2) |
| 470 TabOverviewTypes::instance()->SetWindowType( | 470 if (browser_->type() == Browser::TYPE_POPUP) { |
| 471 GTK_WIDGET(window_), TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, | 471 panel_controller_ = new PanelController(this); |
| 472 NULL); | 472 } else { |
| 473 TabOverviewTypes::instance()->SetWindowType( |
| 474 GTK_WIDGET(window_), |
| 475 TabOverviewTypes::WINDOW_TYPE_CHROME_TOPLEVEL, |
| 476 NULL); |
| 477 } |
| 473 #endif | 478 #endif |
| 479 |
| 480 gtk_widget_show(GTK_WIDGET(window_)); |
| 474 } | 481 } |
| 475 | 482 |
| 476 void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { | 483 void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { |
| 477 gint x = static_cast<gint>(bounds.x()); | 484 gint x = static_cast<gint>(bounds.x()); |
| 478 gint y = static_cast<gint>(bounds.y()); | 485 gint y = static_cast<gint>(bounds.y()); |
| 479 gint width = static_cast<gint>(bounds.width()); | 486 gint width = static_cast<gint>(bounds.width()); |
| 480 gint height = static_cast<gint>(bounds.height()); | 487 gint height = static_cast<gint>(bounds.height()); |
| 481 | 488 |
| 482 gtk_window_move(window_, x, y); | 489 gtk_window_move(window_, x, y); |
| 483 gtk_window_resize(window_, width, height); | 490 gtk_window_resize(window_, width, height); |
| 484 } | 491 } |
| 485 | 492 |
| 486 void BrowserWindowGtk::Close() { | 493 void BrowserWindowGtk::Close() { |
| 487 // We're already closing. Do nothing. | 494 // We're already closing. Do nothing. |
| 488 if (!window_) | 495 if (!window_) |
| 489 return; | 496 return; |
| 490 | 497 |
| 491 if (!CanClose()) | 498 if (!CanClose()) |
| 492 return; | 499 return; |
| 493 | 500 |
| 494 SaveWindowPosition(); | 501 SaveWindowPosition(); |
| 495 | 502 |
| 496 GtkWidget* window = GTK_WIDGET(window_); | 503 GtkWidget* window = GTK_WIDGET(window_); |
| 497 // To help catch bugs in any event handlers that might get fired during the | 504 // To help catch bugs in any event handlers that might get fired during the |
| 498 // destruction, set window_ to NULL before any handlers will run. | 505 // destruction, set window_ to NULL before any handlers will run. |
| 499 window_ = NULL; | 506 window_ = NULL; |
| 500 gtk_widget_destroy(window); | 507 gtk_widget_destroy(window); |
| 508 |
| 509 #if defined(LINUX2) |
| 510 if (panel_controller_) { |
| 511 panel_controller_->Close(); |
| 512 } |
| 513 #endif |
| 501 } | 514 } |
| 502 | 515 |
| 503 void BrowserWindowGtk::Activate() { | 516 void BrowserWindowGtk::Activate() { |
| 504 gtk_window_present(window_); | 517 gtk_window_present(window_); |
| 505 } | 518 } |
| 506 | 519 |
| 507 bool BrowserWindowGtk::IsActive() const { | 520 bool BrowserWindowGtk::IsActive() const { |
| 508 NOTIMPLEMENTED(); | 521 NOTIMPLEMENTED(); |
| 509 return true; | 522 return true; |
| 510 } | 523 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 526 StatusBubble* BrowserWindowGtk::GetStatusBubble() { | 539 StatusBubble* BrowserWindowGtk::GetStatusBubble() { |
| 527 return status_bubble_.get(); | 540 return status_bubble_.get(); |
| 528 } | 541 } |
| 529 | 542 |
| 530 void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) { | 543 void BrowserWindowGtk::SelectedTabToolbarSizeChanged(bool is_animating) { |
| 531 // On Windows, this is used for a performance optimization. | 544 // On Windows, this is used for a performance optimization. |
| 532 // http://code.google.com/p/chromium/issues/detail?id=12291 | 545 // http://code.google.com/p/chromium/issues/detail?id=12291 |
| 533 } | 546 } |
| 534 | 547 |
| 535 void BrowserWindowGtk::UpdateTitleBar() { | 548 void BrowserWindowGtk::UpdateTitleBar() { |
| 549 #if defined(LINUX2) |
| 550 if (panel_controller_) |
| 551 panel_controller_->UpdateTitleBar(); |
| 552 #endif |
| 553 |
| 536 std::wstring title = browser_->GetCurrentPageTitle(); | 554 std::wstring title = browser_->GetCurrentPageTitle(); |
| 537 gtk_window_set_title(window_, WideToUTF8(title).c_str()); | 555 gtk_window_set_title(window_, WideToUTF8(title).c_str()); |
| 538 if (ShouldShowWindowIcon()) { | 556 if (ShouldShowWindowIcon()) { |
| 539 // TODO(tc): If we're showing a title bar, we should update the app icon. | 557 // TODO(tc): If we're showing a title bar, we should update the app icon. |
| 540 } | 558 } |
| 541 } | 559 } |
| 542 | 560 |
| 543 void BrowserWindowGtk::UpdateDevTools() { | 561 void BrowserWindowGtk::UpdateDevTools() { |
| 544 NOTIMPLEMENTED(); | 562 NOTIMPLEMENTED(); |
| 545 } | 563 } |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 titlebar_.reset(new BrowserTitlebar(this, window_)); | 1013 titlebar_.reset(new BrowserTitlebar(this, window_)); |
| 996 gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_->widget(), FALSE, FALSE, | 1014 gtk_box_pack_start(GTK_BOX(window_vbox), titlebar_->widget(), FALSE, FALSE, |
| 997 0); | 1015 0); |
| 998 | 1016 |
| 999 // The content_vbox_ surrounds the "content": toolbar+bookmarks bar+page. | 1017 // The content_vbox_ surrounds the "content": toolbar+bookmarks bar+page. |
| 1000 content_vbox_ = gtk_vbox_new(FALSE, 0); | 1018 content_vbox_ = gtk_vbox_new(FALSE, 0); |
| 1001 gtk_widget_show(content_vbox_); | 1019 gtk_widget_show(content_vbox_); |
| 1002 | 1020 |
| 1003 toolbar_.reset(new BrowserToolbarGtk(browser_.get(), this)); | 1021 toolbar_.reset(new BrowserToolbarGtk(browser_.get(), this)); |
| 1004 toolbar_->Init(browser_->profile(), window_); | 1022 toolbar_->Init(browser_->profile(), window_); |
| 1005 toolbar_->AddToolbarToBox(content_vbox_); | 1023 bool hide_tools = false; |
| 1024 #if defined(LINUX2) |
| 1025 if (browser_->type() == Browser::TYPE_POPUP) |
| 1026 hide_tools = true; |
| 1027 #endif |
| 1028 |
| 1029 if (!hide_tools) |
| 1030 toolbar_->AddToolbarToBox(content_vbox_); |
| 1006 | 1031 |
| 1007 bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get(), | 1032 bookmark_bar_.reset(new BookmarkBarGtk(browser_->profile(), browser_.get(), |
| 1008 this)); | 1033 this)); |
| 1009 bookmark_bar_->AddBookmarkbarToBox(content_vbox_); | 1034 bookmark_bar_->AddBookmarkbarToBox(content_vbox_); |
| 1010 | 1035 |
| 1011 // This vbox surrounds the render area: find bar, info bars and render view. | 1036 // This vbox surrounds the render area: find bar, info bars and render view. |
| 1012 // The reason is that this area as a whole needs to be grouped in its own | 1037 // The reason is that this area as a whole needs to be grouped in its own |
| 1013 // GdkWindow hierarchy so that animations originating inside it (infobar, | 1038 // GdkWindow hierarchy so that animations originating inside it (infobar, |
| 1014 // download shelf, find bar) are all clipped to that area. This is why | 1039 // download shelf, find bar) are all clipped to that area. This is why |
| 1015 // |render_area_vbox_| is packed in |event_box|. | 1040 // |render_area_vbox_| is packed in |event_box|. |
| 1016 render_area_vbox_ = gtk_vbox_new(FALSE, 0); | 1041 render_area_vbox_ = gtk_vbox_new(FALSE, 0); |
| 1017 infobar_container_.reset(new InfoBarContainerGtk(this)); | 1042 infobar_container_.reset(new InfoBarContainerGtk(this)); |
| 1018 gtk_box_pack_start(GTK_BOX(render_area_vbox_), | 1043 gtk_box_pack_start(GTK_BOX(render_area_vbox_), |
| 1019 infobar_container_->widget(), | 1044 infobar_container_->widget(), |
| 1020 FALSE, FALSE, 0); | 1045 FALSE, FALSE, 0); |
| 1021 | 1046 |
| 1022 status_bubble_.reset(new StatusBubbleGtk()); | 1047 status_bubble_.reset(new StatusBubbleGtk()); |
| 1023 | 1048 |
| 1024 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); | 1049 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); |
| 1025 contents_container_->AddContainerToBox(render_area_vbox_); | 1050 contents_container_->AddContainerToBox(render_area_vbox_); |
| 1026 gtk_widget_show_all(render_area_vbox_); | 1051 gtk_widget_show_all(render_area_vbox_); |
| 1027 | 1052 |
| 1053 #if defined(LINUX2) |
| 1054 if (browser_->type() == Browser::TYPE_POPUP) { |
| 1055 // The window manager needs the min size for popups |
| 1056 gtk_widget_set_size_request( |
| 1057 GTK_WIDGET(window_), bounds_.width(), bounds_.height()); |
| 1058 } |
| 1059 #endif |
| 1060 |
| 1028 // We have to realize the window before we try to apply a window shape mask. | 1061 // We have to realize the window before we try to apply a window shape mask. |
| 1029 gtk_widget_realize(GTK_WIDGET(window_)); | 1062 gtk_widget_realize(GTK_WIDGET(window_)); |
| 1030 state_ = gdk_window_get_state(GTK_WIDGET(window_)->window); | 1063 state_ = gdk_window_get_state(GTK_WIDGET(window_)->window); |
| 1031 // Note that calling this the first time is necessary to get the | 1064 // Note that calling this the first time is necessary to get the |
| 1032 // proper control layout. | 1065 // proper control layout. |
| 1033 UpdateCustomFrame(); | 1066 UpdateCustomFrame(); |
| 1034 | 1067 |
| 1035 GtkWidget* event_box = gtk_event_box_new(); | 1068 GtkWidget* event_box = gtk_event_box_new(); |
| 1036 gtk_container_add(GTK_CONTAINER(event_box), render_area_vbox_); | 1069 gtk_container_add(GTK_CONTAINER(event_box), render_area_vbox_); |
| 1037 gtk_widget_show(event_box); | 1070 gtk_widget_show(event_box); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 *edge = GDK_WINDOW_EDGE_NORTH_EAST; | 1382 *edge = GDK_WINDOW_EDGE_NORTH_EAST; |
| 1350 } else if (y < bounds_.height() - kResizeAreaCornerSize) { | 1383 } else if (y < bounds_.height() - kResizeAreaCornerSize) { |
| 1351 *edge = GDK_WINDOW_EDGE_EAST; | 1384 *edge = GDK_WINDOW_EDGE_EAST; |
| 1352 } else { | 1385 } else { |
| 1353 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; | 1386 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; |
| 1354 } | 1387 } |
| 1355 return true; | 1388 return true; |
| 1356 } | 1389 } |
| 1357 NOTREACHED(); | 1390 NOTREACHED(); |
| 1358 } | 1391 } |
| OLD | NEW |