| 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" |
| 11 #include "app/theme_provider.h" | 11 #include "app/theme_provider.h" |
| 12 #include "base/base_paths_linux.h" | 12 #include "base/base_paths_linux.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/gfx/gtk_util.h" | 14 #include "base/gfx/gtk_util.h" |
| 15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
| 18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "chrome/app/chrome_dll_resource.h" | 21 #include "chrome/app/chrome_dll_resource.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_utils.h" | 22 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 23 #include "chrome/browser/browser.h" | 23 #include "chrome/browser/browser.h" |
| 24 #include "chrome/browser/browser_list.h" | 24 #include "chrome/browser/browser_list.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/browser_theme_provider.h" | 26 #include "chrome/browser/browser_theme_provider.h" |
| 27 #include "chrome/browser/debugger/devtools_window.h" |
| 27 #include "chrome/browser/download/download_item_model.h" | 28 #include "chrome/browser/download/download_item_model.h" |
| 28 #include "chrome/browser/download/download_manager.h" | 29 #include "chrome/browser/download/download_manager.h" |
| 29 #include "chrome/browser/gtk/about_chrome_dialog.h" | 30 #include "chrome/browser/gtk/about_chrome_dialog.h" |
| 30 #include "chrome/browser/gtk/active_window_watcher.h" | 31 #include "chrome/browser/gtk/active_window_watcher.h" |
| 31 #include "chrome/browser/gtk/bookmark_bar_gtk.h" | 32 #include "chrome/browser/gtk/bookmark_bar_gtk.h" |
| 32 #include "chrome/browser/gtk/bookmark_manager_gtk.h" | 33 #include "chrome/browser/gtk/bookmark_manager_gtk.h" |
| 33 #include "chrome/browser/gtk/browser_titlebar.h" | 34 #include "chrome/browser/gtk/browser_titlebar.h" |
| 34 #include "chrome/browser/gtk/browser_toolbar_gtk.h" | 35 #include "chrome/browser/gtk/browser_toolbar_gtk.h" |
| 35 #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" | 36 #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" |
| 36 #include "chrome/browser/gtk/download_shelf_gtk.h" | 37 #include "chrome/browser/gtk/download_shelf_gtk.h" |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 #endif | 581 #endif |
| 581 | 582 |
| 582 string16 title = browser_->GetCurrentPageTitle(); | 583 string16 title = browser_->GetCurrentPageTitle(); |
| 583 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); | 584 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); |
| 584 if (ShouldShowWindowIcon()) { | 585 if (ShouldShowWindowIcon()) { |
| 585 // TODO(tc): If we're showing a title bar, we should update the app icon. | 586 // TODO(tc): If we're showing a title bar, we should update the app icon. |
| 586 } | 587 } |
| 587 } | 588 } |
| 588 | 589 |
| 589 void BrowserWindowGtk::UpdateDevTools() { | 590 void BrowserWindowGtk::UpdateDevTools() { |
| 590 NOTIMPLEMENTED(); | 591 UpdateDevToolsForContents( |
| 592 browser_->tabstrip_model()->GetSelectedTabContents()); |
| 591 } | 593 } |
| 592 | 594 |
| 593 void BrowserWindowGtk::FocusDevTools() { | 595 void BrowserWindowGtk::FocusDevTools() { |
| 594 NOTIMPLEMENTED(); | 596 NOTIMPLEMENTED(); |
| 595 } | 597 } |
| 596 | 598 |
| 597 void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) { | 599 void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) { |
| 598 if (should_animate) { | 600 if (should_animate) { |
| 599 if (!loading_animation_timer_.IsRunning()) { | 601 if (!loading_animation_timer_.IsRunning()) { |
| 600 // Loads are happening, and the timer isn't running, so start it. | 602 // Loads are happening, and the timer isn't running, so start it. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 829 } | 831 } |
| 830 } | 832 } |
| 831 | 833 |
| 832 void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) { | 834 void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) { |
| 833 // We use index here rather than comparing |contents| because by this time | 835 // We use index here rather than comparing |contents| because by this time |
| 834 // the model has already removed |contents| from its list, so | 836 // the model has already removed |contents| from its list, so |
| 835 // browser_->GetSelectedTabContents() will return NULL or something else. | 837 // browser_->GetSelectedTabContents() will return NULL or something else. |
| 836 if (index == browser_->tabstrip_model()->selected_index()) | 838 if (index == browser_->tabstrip_model()->selected_index()) |
| 837 infobar_container_->ChangeTabContents(NULL); | 839 infobar_container_->ChangeTabContents(NULL); |
| 838 contents_container_->DetachTabContents(contents); | 840 contents_container_->DetachTabContents(contents); |
| 841 UpdateDevToolsForContents(NULL); |
| 839 } | 842 } |
| 840 | 843 |
| 841 // TODO(estade): this function should probably be unforked from the BrowserView | 844 // TODO(estade): this function should probably be unforked from the BrowserView |
| 842 // function of the same name by having a shared partial BrowserWindow | 845 // function of the same name by having a shared partial BrowserWindow |
| 843 // implementation. | 846 // implementation. |
| 844 void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents, | 847 void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents, |
| 845 TabContents* new_contents, | 848 TabContents* new_contents, |
| 846 int index, | 849 int index, |
| 847 bool user_gesture) { | 850 bool user_gesture) { |
| 848 DCHECK(old_contents != new_contents); | 851 DCHECK(old_contents != new_contents); |
| 849 | 852 |
| 850 if (old_contents && !old_contents->is_being_destroyed()) | 853 if (old_contents && !old_contents->is_being_destroyed()) |
| 851 old_contents->view()->StoreFocus(); | 854 old_contents->view()->StoreFocus(); |
| 852 | 855 |
| 853 // Update various elements that are interested in knowing the current | 856 // Update various elements that are interested in knowing the current |
| 854 // TabContents. | 857 // TabContents. |
| 855 infobar_container_->ChangeTabContents(new_contents); | 858 infobar_container_->ChangeTabContents(new_contents); |
| 856 contents_container_->SetTabContents(new_contents); | 859 contents_container_->SetTabContents(new_contents); |
| 860 UpdateDevToolsForContents(new_contents); |
| 857 | 861 |
| 858 new_contents->DidBecomeSelected(); | 862 new_contents->DidBecomeSelected(); |
| 859 // TODO(estade): after we manage browser activation, add a check to make sure | 863 // TODO(estade): after we manage browser activation, add a check to make sure |
| 860 // we are the active browser before calling RestoreFocus(). | 864 // we are the active browser before calling RestoreFocus(). |
| 861 if (!browser_->tabstrip_model()->closing_all()) | 865 if (!browser_->tabstrip_model()->closing_all()) |
| 862 new_contents->view()->RestoreFocus(); | 866 new_contents->view()->RestoreFocus(); |
| 863 | 867 |
| 864 // Update all the UI bits. | 868 // Update all the UI bits. |
| 865 UpdateTitleBar(); | 869 UpdateTitleBar(); |
| 866 toolbar_->SetProfile(new_contents->profile()); | 870 toolbar_->SetProfile(new_contents->profile()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 893 show_bar = prefs->GetBoolean(prefs::kShowBookmarkBar); | 897 show_bar = prefs->GetBoolean(prefs::kShowBookmarkBar); |
| 894 } | 898 } |
| 895 | 899 |
| 896 if (show_bar) { | 900 if (show_bar) { |
| 897 bookmark_bar_->Show(animate); | 901 bookmark_bar_->Show(animate); |
| 898 } else { | 902 } else { |
| 899 bookmark_bar_->Hide(animate); | 903 bookmark_bar_->Hide(animate); |
| 900 } | 904 } |
| 901 } | 905 } |
| 902 | 906 |
| 907 void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { |
| 908 TabContents* old_devtools = devtools_container_->GetTabContents(); |
| 909 if (old_devtools) |
| 910 devtools_container_->DetachTabContents(old_devtools); |
| 911 |
| 912 TabContents* devtools_contents = contents ? |
| 913 DevToolsWindow::GetDevToolsContents(contents) : NULL; |
| 914 devtools_container_->SetTabContents(devtools_contents); |
| 915 if (devtools_contents) { |
| 916 // TabContentsViewGtk::WasShown is not called when tab contents is shown by |
| 917 // anything other than user selecting a Tab. |
| 918 // See TabContentsViewWin::OnWindowPosChanged for reference on how it should |
| 919 // be implemented. |
| 920 devtools_contents->ShowContents(); |
| 921 } |
| 922 |
| 923 if (devtools_contents) { |
| 924 gtk_widget_show(devtools_container_->widget()); |
| 925 } else { |
| 926 gtk_widget_hide(devtools_container_->widget()); |
| 927 } |
| 928 } |
| 929 |
| 903 void BrowserWindowGtk::UpdateUIForContents(TabContents* contents) { | 930 void BrowserWindowGtk::UpdateUIForContents(TabContents* contents) { |
| 904 MaybeShowBookmarkBar(contents, false); | 931 MaybeShowBookmarkBar(contents, false); |
| 905 } | 932 } |
| 906 | 933 |
| 907 void BrowserWindowGtk::DestroyBrowser() { | 934 void BrowserWindowGtk::DestroyBrowser() { |
| 908 browser_.reset(); | 935 browser_.reset(); |
| 909 } | 936 } |
| 910 | 937 |
| 911 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) { | 938 void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) { |
| 912 if (bounds_.size() != bounds.size()) | 939 if (bounds_.size() != bounds.size()) |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 // |render_area_vbox_| is packed in |event_box|. | 1115 // |render_area_vbox_| is packed in |event_box|. |
| 1089 render_area_vbox_ = gtk_vbox_new(FALSE, 0); | 1116 render_area_vbox_ = gtk_vbox_new(FALSE, 0); |
| 1090 infobar_container_.reset(new InfoBarContainerGtk(this)); | 1117 infobar_container_.reset(new InfoBarContainerGtk(this)); |
| 1091 gtk_box_pack_start(GTK_BOX(render_area_vbox_), | 1118 gtk_box_pack_start(GTK_BOX(render_area_vbox_), |
| 1092 infobar_container_->widget(), | 1119 infobar_container_->widget(), |
| 1093 FALSE, FALSE, 0); | 1120 FALSE, FALSE, 0); |
| 1094 | 1121 |
| 1095 status_bubble_.reset(new StatusBubbleGtk(browser_->profile())); | 1122 status_bubble_.reset(new StatusBubbleGtk(browser_->profile())); |
| 1096 | 1123 |
| 1097 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); | 1124 contents_container_.reset(new TabContentsContainerGtk(status_bubble_.get())); |
| 1098 contents_container_->AddContainerToBox(render_area_vbox_); | 1125 devtools_container_.reset(new TabContentsContainerGtk(NULL)); |
| 1126 contents_split_ = gtk_vpaned_new(); |
| 1127 gtk_paned_pack1(GTK_PANED(contents_split_), contents_container_->widget(), |
| 1128 TRUE, TRUE); |
| 1129 gtk_paned_pack2(GTK_PANED(contents_split_), devtools_container_->widget(), |
| 1130 FALSE, TRUE); |
| 1131 gtk_box_pack_start(GTK_BOX(render_area_vbox_), contents_split_, TRUE, TRUE, |
| 1132 0); |
| 1133 gtk_paned_set_position(GTK_PANED(contents_split_), 400); |
| 1099 gtk_widget_show_all(render_area_vbox_); | 1134 gtk_widget_show_all(render_area_vbox_); |
| 1135 gtk_widget_hide(devtools_container_->widget()); |
| 1100 | 1136 |
| 1101 #if defined(OS_CHROMEOS) | 1137 #if defined(OS_CHROMEOS) |
| 1102 if (browser_->type() == Browser::TYPE_POPUP) { | 1138 if (browser_->type() == Browser::TYPE_POPUP) { |
| 1103 toolbar_->Hide(); | 1139 toolbar_->Hide(); |
| 1104 // The window manager needs the min size for popups | 1140 // The window manager needs the min size for popups |
| 1105 gtk_widget_set_size_request( | 1141 gtk_widget_set_size_request( |
| 1106 GTK_WIDGET(window_), bounds_.width(), bounds_.height()); | 1142 GTK_WIDGET(window_), bounds_.width(), bounds_.height()); |
| 1107 } | 1143 } |
| 1108 #endif | 1144 #endif |
| 1109 | 1145 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1444 *edge = GDK_WINDOW_EDGE_NORTH_EAST; | 1480 *edge = GDK_WINDOW_EDGE_NORTH_EAST; |
| 1445 } else if (y < bounds_.height() - kResizeAreaCornerSize) { | 1481 } else if (y < bounds_.height() - kResizeAreaCornerSize) { |
| 1446 *edge = GDK_WINDOW_EDGE_EAST; | 1482 *edge = GDK_WINDOW_EDGE_EAST; |
| 1447 } else { | 1483 } else { |
| 1448 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; | 1484 *edge = GDK_WINDOW_EDGE_SOUTH_EAST; |
| 1449 } | 1485 } |
| 1450 return true; | 1486 return true; |
| 1451 } | 1487 } |
| 1452 NOTREACHED(); | 1488 NOTREACHED(); |
| 1453 } | 1489 } |
| OLD | NEW |