OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/browser_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <string> | 10 #include <string> |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 titlebar_->UpdateTitleAndIcon(); | 800 titlebar_->UpdateTitleAndIcon(); |
801 } | 801 } |
802 | 802 |
803 void BrowserWindowGtk::BookmarkBarStateChanged( | 803 void BrowserWindowGtk::BookmarkBarStateChanged( |
804 BookmarkBar::AnimateChangeType change_type) { | 804 BookmarkBar::AnimateChangeType change_type) { |
805 MaybeShowBookmarkBar(change_type == BookmarkBar::ANIMATE_STATE_CHANGE); | 805 MaybeShowBookmarkBar(change_type == BookmarkBar::ANIMATE_STATE_CHANGE); |
806 } | 806 } |
807 | 807 |
808 void BrowserWindowGtk::UpdateDevTools() { | 808 void BrowserWindowGtk::UpdateDevTools() { |
809 UpdateDevToolsForContents( | 809 UpdateDevToolsForContents( |
810 browser_->GetSelectedTabContents()); | 810 browser_->GetSelectedWebContents()); |
811 } | 811 } |
812 | 812 |
813 void BrowserWindowGtk::SetDevToolsDockSide(DevToolsDockSide side) | 813 void BrowserWindowGtk::SetDevToolsDockSide(DevToolsDockSide side) |
814 { | 814 { |
815 if (devtools_dock_side_ == side) | 815 if (devtools_dock_side_ == side) |
816 return; | 816 return; |
817 | 817 |
818 if (contents_split_) { | 818 if (contents_split_) { |
819 HideDevToolsContainer(); | 819 HideDevToolsContainer(); |
820 devtools_dock_side_ = side; | 820 devtools_dock_side_ = side; |
(...skipping 23 matching lines...) Expand all Loading... |
844 void BrowserWindowGtk::LoadingAnimationCallback() { | 844 void BrowserWindowGtk::LoadingAnimationCallback() { |
845 if (browser_->is_type_tabbed()) { | 845 if (browser_->is_type_tabbed()) { |
846 // Loading animations are shown in the tab for tabbed windows. We check the | 846 // Loading animations are shown in the tab for tabbed windows. We check the |
847 // browser type instead of calling IsTabStripVisible() because the latter | 847 // browser type instead of calling IsTabStripVisible() because the latter |
848 // will return false for fullscreen windows, but we still need to update | 848 // will return false for fullscreen windows, but we still need to update |
849 // their animations (so that when they come out of fullscreen mode they'll | 849 // their animations (so that when they come out of fullscreen mode they'll |
850 // be correct). | 850 // be correct). |
851 tabstrip_->UpdateLoadingAnimations(); | 851 tabstrip_->UpdateLoadingAnimations(); |
852 } else if (ShouldShowWindowIcon()) { | 852 } else if (ShouldShowWindowIcon()) { |
853 // ... or in the window icon area for popups and app windows. | 853 // ... or in the window icon area for popups and app windows. |
854 TabContents* tab_contents = browser_->GetSelectedTabContents(); | 854 WebContents* web_contents = browser_->GetSelectedTabContents(); |
855 // GetSelectedTabContents can return NULL for example under Purify when | 855 // GetSelectedTabContents can return NULL for example under Purify when |
856 // the animations are running slowly and this function is called on | 856 // the animations are running slowly and this function is called on |
857 // a timer through LoadingAnimationCallback. | 857 // a timer through LoadingAnimationCallback. |
858 titlebar_->UpdateThrobber(tab_contents); | 858 titlebar_->UpdateThrobber(web_contents); |
859 } | 859 } |
860 } | 860 } |
861 | 861 |
862 void BrowserWindowGtk::SetStarredState(bool is_starred) { | 862 void BrowserWindowGtk::SetStarredState(bool is_starred) { |
863 toolbar_->GetLocationBarView()->SetStarred(is_starred); | 863 toolbar_->GetLocationBarView()->SetStarred(is_starred); |
864 } | 864 } |
865 | 865 |
866 gfx::Rect BrowserWindowGtk::GetRestoredBounds() const { | 866 gfx::Rect BrowserWindowGtk::GetRestoredBounds() const { |
867 return restored_bounds_; | 867 return restored_bounds_; |
868 } | 868 } |
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 } | 1258 } |
1259 | 1259 |
1260 default: | 1260 default: |
1261 NOTREACHED() << "Got a notification we didn't register for!"; | 1261 NOTREACHED() << "Got a notification we didn't register for!"; |
1262 } | 1262 } |
1263 } | 1263 } |
1264 | 1264 |
1265 void BrowserWindowGtk::TabDetachedAt(TabContentsWrapper* contents, int index) { | 1265 void BrowserWindowGtk::TabDetachedAt(TabContentsWrapper* contents, int index) { |
1266 // We use index here rather than comparing |contents| because by this time | 1266 // We use index here rather than comparing |contents| because by this time |
1267 // the model has already removed |contents| from its list, so | 1267 // the model has already removed |contents| from its list, so |
1268 // browser_->GetSelectedTabContents() will return NULL or something else. | 1268 // browser_->GetSelectedWebContents() will return NULL or something else. |
1269 if (index == browser_->tabstrip_model()->active_index()) { | 1269 if (index == browser_->tabstrip_model()->active_index()) { |
1270 infobar_container_->ChangeTabContents(NULL); | 1270 infobar_container_->ChangeTabContents(NULL); |
1271 UpdateDevToolsForContents(NULL); | 1271 UpdateDevToolsForContents(NULL); |
1272 } | 1272 } |
1273 contents_container_->DetachTab(contents); | 1273 contents_container_->DetachTab(contents); |
1274 } | 1274 } |
1275 | 1275 |
1276 void BrowserWindowGtk::ActiveTabChanged(TabContentsWrapper* old_contents, | 1276 void BrowserWindowGtk::ActiveTabChanged(TabContentsWrapper* old_contents, |
1277 TabContentsWrapper* new_contents, | 1277 TabContentsWrapper* new_contents, |
1278 int index, | 1278 int index, |
1279 bool user_gesture) { | 1279 bool user_gesture) { |
1280 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::ActiveTabChanged"); | 1280 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::ActiveTabChanged"); |
1281 if (old_contents && !old_contents->tab_contents()->IsBeingDestroyed()) | 1281 if (old_contents && !old_contents->tab_contents()->IsBeingDestroyed()) |
1282 old_contents->tab_contents()->GetView()->StoreFocus(); | 1282 old_contents->tab_contents()->GetView()->StoreFocus(); |
1283 | 1283 |
1284 // Update various elements that are interested in knowing the current | 1284 // Update various elements that are interested in knowing the current |
1285 // TabContents. | 1285 // TabContents. |
1286 UpdateDevToolsForContents(new_contents->tab_contents()); | 1286 UpdateDevToolsForContents(new_contents->web_contents()); |
1287 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); | 1287 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); |
1288 contents_container_->SetTab(new_contents); | 1288 contents_container_->SetTab(new_contents); |
1289 | 1289 |
1290 new_contents->tab_contents()->DidBecomeSelected(); | 1290 new_contents->tab_contents()->DidBecomeSelected(); |
1291 // TODO(estade): after we manage browser activation, add a check to make sure | 1291 // TODO(estade): after we manage browser activation, add a check to make sure |
1292 // we are the active browser before calling RestoreFocus(). | 1292 // we are the active browser before calling RestoreFocus(). |
1293 if (!browser_->tabstrip_model()->closing_all()) { | 1293 if (!browser_->tabstrip_model()->closing_all()) { |
1294 new_contents->tab_contents()->GetView()->RestoreFocus(); | 1294 new_contents->tab_contents()->GetView()->RestoreFocus(); |
1295 if (new_contents->find_tab_helper()->find_ui_active()) | 1295 if (new_contents->find_tab_helper()->find_ui_active()) |
1296 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); | 1296 browser_->GetFindBarController()->find_bar()->SetFocusAndSelection(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1363 state = BookmarkBar::HIDDEN; | 1363 state = BookmarkBar::HIDDEN; |
1364 | 1364 |
1365 toolbar_->UpdateForBookmarkBarVisibility(state == BookmarkBar::DETACHED); | 1365 toolbar_->UpdateForBookmarkBarVisibility(state == BookmarkBar::DETACHED); |
1366 PlaceBookmarkBar(state == BookmarkBar::DETACHED); | 1366 PlaceBookmarkBar(state == BookmarkBar::DETACHED); |
1367 bookmark_bar_->SetBookmarkBarState( | 1367 bookmark_bar_->SetBookmarkBarState( |
1368 state, | 1368 state, |
1369 animate ? BookmarkBar::ANIMATE_STATE_CHANGE : | 1369 animate ? BookmarkBar::ANIMATE_STATE_CHANGE : |
1370 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 1370 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
1371 } | 1371 } |
1372 | 1372 |
1373 void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { | 1373 void BrowserWindowGtk::UpdateDevToolsForContents(WebContents* contents) { |
1374 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::UpdateDevToolsForContents"); | 1374 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::UpdateDevToolsForContents"); |
1375 TabContentsWrapper* old_devtools = devtools_container_->tab(); | 1375 TabContentsWrapper* old_devtools = devtools_container_->tab(); |
1376 TabContentsWrapper* devtools_contents = contents ? | 1376 TabContentsWrapper* devtools_contents = contents ? |
1377 DevToolsWindow::GetDevToolsContents(contents) : NULL; | 1377 DevToolsWindow::GetDevToolsContents(contents) : NULL; |
1378 if (old_devtools == devtools_contents) | 1378 if (old_devtools == devtools_contents) |
1379 return; | 1379 return; |
1380 | 1380 |
1381 if (old_devtools) | 1381 if (old_devtools) |
1382 devtools_container_->DetachTab(old_devtools); | 1382 devtools_container_->DetachTab(old_devtools); |
1383 | 1383 |
1384 devtools_container_->SetTab(devtools_contents); | 1384 devtools_container_->SetTab(devtools_contents); |
1385 if (devtools_contents) { | 1385 if (devtools_contents) { |
1386 // TabContentsViewGtk::WasShown is not called when tab contents is shown by | 1386 // TabContentsViewGtk::WasShown is not called when tab contents is shown by |
1387 // anything other than user selecting a Tab. | 1387 // anything other than user selecting a Tab. |
1388 // See TabContentsViewViews::OnWindowPosChanged for reference on how it | 1388 // See TabContentsViewViews::OnWindowPosChanged for reference on how it |
1389 // should be implemented. | 1389 // should be implemented. |
1390 devtools_contents->tab_contents()->ShowContents(); | 1390 devtools_contents->web_contents()->ShowContents(); |
1391 } | 1391 } |
1392 | 1392 |
1393 bool should_show = old_devtools == NULL && devtools_contents != NULL; | 1393 bool should_show = old_devtools == NULL && devtools_contents != NULL; |
1394 bool should_hide = old_devtools != NULL && devtools_contents == NULL; | 1394 bool should_hide = old_devtools != NULL && devtools_contents == NULL; |
1395 | 1395 |
1396 if (should_show) | 1396 if (should_show) |
1397 ShowDevToolsContainer(); | 1397 ShowDevToolsContainer(); |
1398 else if (should_hide) | 1398 else if (should_hide) |
1399 HideDevToolsContainer(); | 1399 HideDevToolsContainer(); |
1400 } | 1400 } |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2123 GetBrowserWindowForNativeWindow(GTK_WINDOW(acceleratable)); | 2123 GetBrowserWindowForNativeWindow(GTK_WINDOW(acceleratable)); |
2124 DCHECK(browser_window != NULL); | 2124 DCHECK(browser_window != NULL); |
2125 return browser_window->browser()->ExecuteCommandIfEnabled(command_id); | 2125 return browser_window->browser()->ExecuteCommandIfEnabled(command_id); |
2126 } | 2126 } |
2127 | 2127 |
2128 // Let the focused widget have first crack at the key event so we don't | 2128 // Let the focused widget have first crack at the key event so we don't |
2129 // override their accelerators. | 2129 // override their accelerators. |
2130 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { | 2130 gboolean BrowserWindowGtk::OnKeyPress(GtkWidget* widget, GdkEventKey* event) { |
2131 // If a widget besides the native view is focused, we have to try to handle | 2131 // If a widget besides the native view is focused, we have to try to handle |
2132 // the custom accelerators before letting it handle them. | 2132 // the custom accelerators before letting it handle them. |
2133 TabContents* current_tab_contents = | 2133 WebContents* current_web_contents = |
2134 browser()->GetSelectedTabContents(); | 2134 browser()->GetSelectedWebContents(); |
2135 // The current tab might not have a render view if it crashed. | 2135 // The current tab might not have a render view if it crashed. |
2136 if (!current_tab_contents || !current_tab_contents->GetContentNativeView() || | 2136 if (!current_web_contents || !current_web_contents->GetContentNativeView() || |
2137 !gtk_widget_is_focus(current_tab_contents->GetContentNativeView())) { | 2137 !gtk_widget_is_focus(current_web_contents->GetContentNativeView())) { |
2138 int command_id = GetCustomCommandId(event); | 2138 int command_id = GetCustomCommandId(event); |
2139 if (command_id == -1) | 2139 if (command_id == -1) |
2140 command_id = GetPreHandleCommandId(event); | 2140 command_id = GetPreHandleCommandId(event); |
2141 | 2141 |
2142 if (command_id != -1 && browser_->ExecuteCommandIfEnabled(command_id)) | 2142 if (command_id != -1 && browser_->ExecuteCommandIfEnabled(command_id)) |
2143 return TRUE; | 2143 return TRUE; |
2144 | 2144 |
2145 // Propagate the key event to child widget first, so we don't override their | 2145 // Propagate the key event to child widget first, so we don't override their |
2146 // accelerators. | 2146 // accelerators. |
2147 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) { | 2147 if (!gtk_window_propagate_key_event(GTK_WINDOW(widget), event)) { |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2515 wm_type == ui::WM_OPENBOX || | 2515 wm_type == ui::WM_OPENBOX || |
2516 wm_type == ui::WM_XFWM4); | 2516 wm_type == ui::WM_XFWM4); |
2517 } | 2517 } |
2518 | 2518 |
2519 // static | 2519 // static |
2520 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2520 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2521 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2521 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2522 browser_window_gtk->Init(); | 2522 browser_window_gtk->Init(); |
2523 return browser_window_gtk; | 2523 return browser_window_gtk; |
2524 } | 2524 } |
OLD | NEW |