OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 #include "chrome/browser/gtk/tab_contents_container_gtk.h" | 62 #include "chrome/browser/gtk/tab_contents_container_gtk.h" |
63 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | 63 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
64 #include "chrome/browser/gtk/task_manager_gtk.h" | 64 #include "chrome/browser/gtk/task_manager_gtk.h" |
65 #include "chrome/browser/gtk/theme_install_bubble_view_gtk.h" | 65 #include "chrome/browser/gtk/theme_install_bubble_view_gtk.h" |
66 #include "chrome/browser/gtk/update_recommended_dialog.h" | 66 #include "chrome/browser/gtk/update_recommended_dialog.h" |
67 #include "chrome/browser/location_bar.h" | 67 #include "chrome/browser/location_bar.h" |
68 #include "chrome/browser/page_info_window.h" | 68 #include "chrome/browser/page_info_window.h" |
69 #include "chrome/browser/prefs/pref_service.h" | 69 #include "chrome/browser/prefs/pref_service.h" |
70 #include "chrome/browser/profile.h" | 70 #include "chrome/browser/profile.h" |
71 #include "chrome/browser/tab_contents/tab_contents.h" | 71 #include "chrome/browser/tab_contents/tab_contents.h" |
| 72 #include "chrome/browser/tab_contents_wrapper.h" |
72 #include "chrome/browser/tab_contents/tab_contents_view.h" | 73 #include "chrome/browser/tab_contents/tab_contents_view.h" |
73 #include "chrome/browser/tabs/tab_strip_model.h" | 74 #include "chrome/browser/tabs/tab_strip_model.h" |
74 #include "chrome/browser/themes/browser_theme_provider.h" | 75 #include "chrome/browser/themes/browser_theme_provider.h" |
75 #include "chrome/browser/ui/browser.h" | 76 #include "chrome/browser/ui/browser.h" |
76 #include "chrome/browser/window_sizer.h" | 77 #include "chrome/browser/window_sizer.h" |
77 #include "chrome/common/chrome_switches.h" | 78 #include "chrome/common/chrome_switches.h" |
78 #include "chrome/common/native_web_keyboard_event.h" | 79 #include "chrome/common/native_web_keyboard_event.h" |
79 #include "chrome/common/notification_service.h" | 80 #include "chrome/common/notification_service.h" |
80 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
81 #include "gfx/rect.h" | 82 #include "gfx/rect.h" |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (ShouldShowWindowIcon()) | 730 if (ShouldShowWindowIcon()) |
730 titlebar_->UpdateTitleAndIcon(); | 731 titlebar_->UpdateTitleAndIcon(); |
731 } | 732 } |
732 | 733 |
733 void BrowserWindowGtk::ShelfVisibilityChanged() { | 734 void BrowserWindowGtk::ShelfVisibilityChanged() { |
734 MaybeShowBookmarkBar(browser_->GetSelectedTabContents(), false); | 735 MaybeShowBookmarkBar(browser_->GetSelectedTabContents(), false); |
735 } | 736 } |
736 | 737 |
737 void BrowserWindowGtk::UpdateDevTools() { | 738 void BrowserWindowGtk::UpdateDevTools() { |
738 UpdateDevToolsForContents( | 739 UpdateDevToolsForContents( |
739 browser_->tabstrip_model()->GetSelectedTabContents()); | 740 browser_->GetSelectedTabContents()); |
740 } | 741 } |
741 | 742 |
742 void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) { | 743 void BrowserWindowGtk::UpdateLoadingAnimations(bool should_animate) { |
743 if (should_animate) { | 744 if (should_animate) { |
744 if (!loading_animation_timer_.IsRunning()) { | 745 if (!loading_animation_timer_.IsRunning()) { |
745 // Loads are happening, and the timer isn't running, so start it. | 746 // Loads are happening, and the timer isn't running, so start it. |
746 loading_animation_timer_.Start( | 747 loading_animation_timer_.Start( |
747 base::TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, | 748 base::TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, |
748 &BrowserWindowGtk::LoadingAnimationCallback); | 749 &BrowserWindowGtk::LoadingAnimationCallback); |
749 } | 750 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 if (!IsFullscreen()) | 830 if (!IsFullscreen()) |
830 GetLocationBar()->FocusLocation(select_all); | 831 GetLocationBar()->FocusLocation(select_all); |
831 } | 832 } |
832 | 833 |
833 void BrowserWindowGtk::UpdateReloadStopState(bool is_loading, bool force) { | 834 void BrowserWindowGtk::UpdateReloadStopState(bool is_loading, bool force) { |
834 toolbar_->GetReloadButton()->ChangeMode( | 835 toolbar_->GetReloadButton()->ChangeMode( |
835 is_loading ? ReloadButtonGtk::MODE_STOP : ReloadButtonGtk::MODE_RELOAD, | 836 is_loading ? ReloadButtonGtk::MODE_STOP : ReloadButtonGtk::MODE_RELOAD, |
836 force); | 837 force); |
837 } | 838 } |
838 | 839 |
839 void BrowserWindowGtk::UpdateToolbar(TabContents* contents, | 840 void BrowserWindowGtk::UpdateToolbar(TabContentsWrapper* contents, |
840 bool should_restore_state) { | 841 bool should_restore_state) { |
841 toolbar_->UpdateTabContents(contents, should_restore_state); | 842 toolbar_->UpdateTabContents(contents->tab_contents(), should_restore_state); |
842 } | 843 } |
843 | 844 |
844 void BrowserWindowGtk::FocusToolbar() { | 845 void BrowserWindowGtk::FocusToolbar() { |
845 NOTIMPLEMENTED(); | 846 NOTIMPLEMENTED(); |
846 } | 847 } |
847 | 848 |
848 void BrowserWindowGtk::FocusAppMenu() { | 849 void BrowserWindowGtk::FocusAppMenu() { |
849 NOTIMPLEMENTED(); | 850 NOTIMPLEMENTED(); |
850 } | 851 } |
851 | 852 |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 NOTREACHED() << "Got pref change notification we didn't register for!"; | 1138 NOTREACHED() << "Got pref change notification we didn't register for!"; |
1138 } | 1139 } |
1139 break; | 1140 break; |
1140 } | 1141 } |
1141 | 1142 |
1142 default: | 1143 default: |
1143 NOTREACHED() << "Got a notification we didn't register for!"; | 1144 NOTREACHED() << "Got a notification we didn't register for!"; |
1144 } | 1145 } |
1145 } | 1146 } |
1146 | 1147 |
1147 void BrowserWindowGtk::TabDetachedAt(TabContents* contents, int index) { | 1148 void BrowserWindowGtk::TabDetachedAt(TabContentsWrapper* contents, int index) { |
1148 // We use index here rather than comparing |contents| because by this time | 1149 // We use index here rather than comparing |contents| because by this time |
1149 // the model has already removed |contents| from its list, so | 1150 // the model has already removed |contents| from its list, so |
1150 // browser_->GetSelectedTabContents() will return NULL or something else. | 1151 // browser_->GetSelectedTabContents() will return NULL or something else. |
1151 if (index == browser_->tabstrip_model()->selected_index()) | 1152 if (index == browser_->tabstrip_model()->selected_index()) |
1152 infobar_container_->ChangeTabContents(NULL); | 1153 infobar_container_->ChangeTabContents(NULL); |
1153 contents_container_->DetachTabContents(contents); | 1154 contents_container_->DetachTabContents(contents->tab_contents()); |
1154 UpdateDevToolsForContents(NULL); | 1155 UpdateDevToolsForContents(NULL); |
1155 } | 1156 } |
1156 | 1157 |
1157 void BrowserWindowGtk::TabSelectedAt(TabContents* old_contents, | 1158 void BrowserWindowGtk::TabSelectedAt(TabContentsWrapper* old_contents, |
1158 TabContents* new_contents, | 1159 TabContentsWrapper* new_contents, |
1159 int index, | 1160 int index, |
1160 bool user_gesture) { | 1161 bool user_gesture) { |
1161 DCHECK(old_contents != new_contents); | 1162 DCHECK(old_contents != new_contents); |
1162 | 1163 |
1163 if (old_contents && !old_contents->is_being_destroyed()) | 1164 if (old_contents && !old_contents->tab_contents()->is_being_destroyed()) |
1164 old_contents->view()->StoreFocus(); | 1165 old_contents->view()->StoreFocus(); |
1165 | 1166 |
1166 // Update various elements that are interested in knowing the current | 1167 // Update various elements that are interested in knowing the current |
1167 // TabContents. | 1168 // TabContents. |
1168 infobar_container_->ChangeTabContents(new_contents); | 1169 infobar_container_->ChangeTabContents(new_contents->tab_contents()); |
1169 contents_container_->SetTabContents(new_contents); | 1170 contents_container_->SetTabContents(new_contents->tab_contents()); |
1170 UpdateDevToolsForContents(new_contents); | 1171 UpdateDevToolsForContents(new_contents->tab_contents()); |
1171 | 1172 |
1172 new_contents->DidBecomeSelected(); | 1173 new_contents->tab_contents()->DidBecomeSelected(); |
1173 // TODO(estade): after we manage browser activation, add a check to make sure | 1174 // TODO(estade): after we manage browser activation, add a check to make sure |
1174 // we are the active browser before calling RestoreFocus(). | 1175 // we are the active browser before calling RestoreFocus(). |
1175 if (!browser_->tabstrip_model()->closing_all()) { | 1176 if (!browser_->tabstrip_model()->closing_all()) { |
1176 new_contents->view()->RestoreFocus(); | 1177 new_contents->view()->RestoreFocus(); |
1177 if (new_contents->find_ui_active()) | 1178 if (new_contents->tab_contents()->find_ui_active()) |
1178 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); | 1179 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); |
1179 } | 1180 } |
1180 | 1181 |
1181 // Update all the UI bits. | 1182 // Update all the UI bits. |
1182 UpdateTitleBar(); | 1183 UpdateTitleBar(); |
1183 UpdateToolbar(new_contents, true); | 1184 UpdateToolbar(new_contents, true); |
1184 UpdateUIForContents(new_contents); | 1185 UpdateUIForContents(new_contents->tab_contents()); |
1185 } | 1186 } |
1186 | 1187 |
1187 void BrowserWindowGtk::TabStripEmpty() { | 1188 void BrowserWindowGtk::TabStripEmpty() { |
1188 UpdateUIForContents(NULL); | 1189 UpdateUIForContents(NULL); |
1189 } | 1190 } |
1190 | 1191 |
1191 void BrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { | 1192 void BrowserWindowGtk::ActiveWindowChanged(GdkWindow* active_window) { |
1192 // Do nothing if we're in the process of closing the browser window. | 1193 // Do nothing if we're in the process of closing the browser window. |
1193 if (!window_) | 1194 if (!window_) |
1194 return; | 1195 return; |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 DCHECK(browser_window != NULL); | 1854 DCHECK(browser_window != NULL); |
1854 return browser_window->ExecuteBrowserCommand(command_id); | 1855 return browser_window->ExecuteBrowserCommand(command_id); |
1855 } | 1856 } |
1856 | 1857 |
1857 // Let the focused widget have first crack at the key event so we don't | 1858 // Let the focused widget have first crack at the key event so we don't |
1858 // override their accelerators. | 1859 // override their accelerators. |
1859 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { | 1860 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { |
1860 // If a widget besides the native view is focused, we have to try to handle | 1861 // If a widget besides the native view is focused, we have to try to handle |
1861 // the custom accelerators before letting it handle them. | 1862 // the custom accelerators before letting it handle them. |
1862 TabContents* current_tab_contents = | 1863 TabContents* current_tab_contents = |
1863 browser()->tabstrip_model()->GetSelectedTabContents(); | 1864 browser()->GetSelectedTabContents(); |
1864 // The current tab might not have a render view if it crashed. | 1865 // The current tab might not have a render view if it crashed. |
1865 if (!current_tab_contents || !current_tab_contents->GetContentNativeView() || | 1866 if (!current_tab_contents || !current_tab_contents->GetContentNativeView() || |
1866 !gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) { | 1867 !gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) { |
1867 int command_id = GetCustomCommandId(event); | 1868 int command_id = GetCustomCommandId(event); |
1868 if (command_id == -1) | 1869 if (command_id == -1) |
1869 command_id = GetPreHandleCommandId(event); | 1870 command_id = GetPreHandleCommandId(event); |
1870 | 1871 |
1871 if (command_id != -1 && ExecuteBrowserCommand(command_id)) | 1872 if (command_id != -1 && ExecuteBrowserCommand(command_id)) |
1872 return TRUE; | 1873 return TRUE; |
1873 | 1874 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 // special-case the ones where the custom frame should be used. These names | 2237 // special-case the ones where the custom frame should be used. These names |
2237 // are taken from the WMs' source code. | 2238 // are taken from the WMs' source code. |
2238 return (wm_name == "Blackbox" || | 2239 return (wm_name == "Blackbox" || |
2239 wm_name == "compiz" || | 2240 wm_name == "compiz" || |
2240 wm_name == "e16" || // Enlightenment DR16 | 2241 wm_name == "e16" || // Enlightenment DR16 |
2241 wm_name == "Metacity" || | 2242 wm_name == "Metacity" || |
2242 wm_name == "Mutter" || | 2243 wm_name == "Mutter" || |
2243 wm_name == "Openbox" || | 2244 wm_name == "Openbox" || |
2244 wm_name == "Xfwm4"); | 2245 wm_name == "Xfwm4"); |
2245 } | 2246 } |
OLD | NEW |