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> |
11 | 11 |
12 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/trace_event.h" |
14 #include "base/environment.h" | 15 #include "base/environment.h" |
15 #include "base/i18n/file_util_icu.h" | 16 #include "base/i18n/file_util_icu.h" |
16 #include "base/logging.h" | 17 #include "base/logging.h" |
17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
19 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
20 #include "base/nix/xdg_util.h" | 21 #include "base/nix/xdg_util.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/string_util.h" | 23 #include "base/string_util.h" |
23 #include "base/time.h" | 24 #include "base/time.h" |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 402 |
402 ConnectAccelerators(); | 403 ConnectAccelerators(); |
403 | 404 |
404 // Set the initial background color of widgets. | 405 // Set the initial background color of widgets. |
405 SetBackgroundColor(); | 406 SetBackgroundColor(); |
406 HideUnsupportedWindowFeatures(); | 407 HideUnsupportedWindowFeatures(); |
407 } | 408 } |
408 | 409 |
409 gboolean BrowserWindowGtk::OnCustomFrameExpose(GtkWidget* widget, | 410 gboolean BrowserWindowGtk::OnCustomFrameExpose(GtkWidget* widget, |
410 GdkEventExpose* event) { | 411 GdkEventExpose* event) { |
| 412 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::OnCustomFrameExpose"); |
| 413 |
411 // Draw the default background. | 414 // Draw the default background. |
412 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 415 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
413 gdk_cairo_rectangle(cr, &event->area); | 416 gdk_cairo_rectangle(cr, &event->area); |
414 cairo_clip(cr); | 417 cairo_clip(cr); |
415 | 418 |
416 if (UsingCustomPopupFrame()) { | 419 if (UsingCustomPopupFrame()) { |
417 DrawPopupFrame(cr, widget, event); | 420 DrawPopupFrame(cr, widget, event); |
418 } else { | 421 } else { |
419 DrawCustomFrame(cr, widget, event); | 422 DrawCustomFrame(cr, widget, event); |
420 } | 423 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 StatusBubble* BrowserWindowGtk::GetStatusBubble() { | 775 StatusBubble* BrowserWindowGtk::GetStatusBubble() { |
773 return status_bubble_.get(); | 776 return status_bubble_.get(); |
774 } | 777 } |
775 | 778 |
776 void BrowserWindowGtk::ToolbarSizeChanged(bool is_animating) { | 779 void BrowserWindowGtk::ToolbarSizeChanged(bool is_animating) { |
777 // On Windows, this is used for a performance optimization. | 780 // On Windows, this is used for a performance optimization. |
778 // http://code.google.com/p/chromium/issues/detail?id=12291 | 781 // http://code.google.com/p/chromium/issues/detail?id=12291 |
779 } | 782 } |
780 | 783 |
781 void BrowserWindowGtk::UpdateTitleBar() { | 784 void BrowserWindowGtk::UpdateTitleBar() { |
| 785 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::UpdateTitleBar"); |
782 string16 title = browser_->GetWindowTitleForCurrentTab(); | 786 string16 title = browser_->GetWindowTitleForCurrentTab(); |
783 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); | 787 gtk_window_set_title(window_, UTF16ToUTF8(title).c_str()); |
784 if (ShouldShowWindowIcon()) | 788 if (ShouldShowWindowIcon()) |
785 titlebar_->UpdateTitleAndIcon(); | 789 titlebar_->UpdateTitleAndIcon(); |
786 } | 790 } |
787 | 791 |
788 void BrowserWindowGtk::BookmarkBarStateChanged( | 792 void BrowserWindowGtk::BookmarkBarStateChanged( |
789 BookmarkBar::AnimateChangeType change_type) { | 793 BookmarkBar::AnimateChangeType change_type) { |
790 MaybeShowBookmarkBar(change_type == BookmarkBar::ANIMATE_STATE_CHANGE); | 794 MaybeShowBookmarkBar(change_type == BookmarkBar::ANIMATE_STATE_CHANGE); |
791 } | 795 } |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 } | 930 } |
927 | 931 |
928 void BrowserWindowGtk::UpdateReloadStopState(bool is_loading, bool force) { | 932 void BrowserWindowGtk::UpdateReloadStopState(bool is_loading, bool force) { |
929 toolbar_->GetReloadButton()->ChangeMode( | 933 toolbar_->GetReloadButton()->ChangeMode( |
930 is_loading ? ReloadButtonGtk::MODE_STOP : ReloadButtonGtk::MODE_RELOAD, | 934 is_loading ? ReloadButtonGtk::MODE_STOP : ReloadButtonGtk::MODE_RELOAD, |
931 force); | 935 force); |
932 } | 936 } |
933 | 937 |
934 void BrowserWindowGtk::UpdateToolbar(TabContentsWrapper* contents, | 938 void BrowserWindowGtk::UpdateToolbar(TabContentsWrapper* contents, |
935 bool should_restore_state) { | 939 bool should_restore_state) { |
| 940 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::UpdateToolbar"); |
936 toolbar_->UpdateTabContents(contents->tab_contents(), should_restore_state); | 941 toolbar_->UpdateTabContents(contents->tab_contents(), should_restore_state); |
937 } | 942 } |
938 | 943 |
939 void BrowserWindowGtk::FocusToolbar() { | 944 void BrowserWindowGtk::FocusToolbar() { |
940 NOTIMPLEMENTED(); | 945 NOTIMPLEMENTED(); |
941 } | 946 } |
942 | 947 |
943 void BrowserWindowGtk::FocusAppMenu() { | 948 void BrowserWindowGtk::FocusAppMenu() { |
944 NOTIMPLEMENTED(); | 949 NOTIMPLEMENTED(); |
945 } | 950 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 infobar_container_->ChangeTabContents(NULL); | 1251 infobar_container_->ChangeTabContents(NULL); |
1247 UpdateDevToolsForContents(NULL); | 1252 UpdateDevToolsForContents(NULL); |
1248 } | 1253 } |
1249 contents_container_->DetachTab(contents); | 1254 contents_container_->DetachTab(contents); |
1250 } | 1255 } |
1251 | 1256 |
1252 void BrowserWindowGtk::ActiveTabChanged(TabContentsWrapper* old_contents, | 1257 void BrowserWindowGtk::ActiveTabChanged(TabContentsWrapper* old_contents, |
1253 TabContentsWrapper* new_contents, | 1258 TabContentsWrapper* new_contents, |
1254 int index, | 1259 int index, |
1255 bool user_gesture) { | 1260 bool user_gesture) { |
| 1261 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::ActiveTabChanged"); |
1256 if (old_contents && !old_contents->tab_contents()->is_being_destroyed()) | 1262 if (old_contents && !old_contents->tab_contents()->is_being_destroyed()) |
1257 old_contents->view()->StoreFocus(); | 1263 old_contents->view()->StoreFocus(); |
1258 | 1264 |
1259 // Update various elements that are interested in knowing the current | 1265 // Update various elements that are interested in knowing the current |
1260 // TabContents. | 1266 // TabContents. |
1261 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); | 1267 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); |
1262 contents_container_->SetTab(new_contents); | 1268 contents_container_->SetTab(new_contents); |
1263 UpdateDevToolsForContents(new_contents->tab_contents()); | 1269 UpdateDevToolsForContents(new_contents->tab_contents()); |
1264 | 1270 |
1265 new_contents->tab_contents()->DidBecomeSelected(); | 1271 new_contents->tab_contents()->DidBecomeSelected(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 if (x) { | 1323 if (x) { |
1318 // This is a views specific call that made its way into the interface. We | 1324 // This is a views specific call that made its way into the interface. We |
1319 // go through GetXPositionOfLocationIcon() since we need widget relativity. | 1325 // go through GetXPositionOfLocationIcon() since we need widget relativity. |
1320 *x = 0; | 1326 *x = 0; |
1321 NOTREACHED(); | 1327 NOTREACHED(); |
1322 } | 1328 } |
1323 return true; | 1329 return true; |
1324 } | 1330 } |
1325 | 1331 |
1326 void BrowserWindowGtk::MaybeShowBookmarkBar(bool animate) { | 1332 void BrowserWindowGtk::MaybeShowBookmarkBar(bool animate) { |
| 1333 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::MaybeShowBookmarkBar"); |
1327 if (!IsBookmarkBarSupported()) | 1334 if (!IsBookmarkBarSupported()) |
1328 return; | 1335 return; |
1329 | 1336 |
1330 TabContentsWrapper* tab = GetDisplayedTab(); | 1337 TabContentsWrapper* tab = GetDisplayedTab(); |
1331 | 1338 |
1332 if (tab) | 1339 if (tab) |
1333 bookmark_bar_->SetPageNavigator(browser_.get()); | 1340 bookmark_bar_->SetPageNavigator(browser_.get()); |
1334 | 1341 |
1335 BookmarkBar::State state = browser_->bookmark_bar_state(); | 1342 BookmarkBar::State state = browser_->bookmark_bar_state(); |
1336 if (contents_container_->HasPreview() && state == BookmarkBar::DETACHED) | 1343 if (contents_container_->HasPreview() && state == BookmarkBar::DETACHED) |
1337 state = BookmarkBar::HIDDEN; | 1344 state = BookmarkBar::HIDDEN; |
1338 | 1345 |
1339 toolbar_->UpdateForBookmarkBarVisibility(state == BookmarkBar::DETACHED); | 1346 toolbar_->UpdateForBookmarkBarVisibility(state == BookmarkBar::DETACHED); |
1340 PlaceBookmarkBar(state == BookmarkBar::DETACHED); | 1347 PlaceBookmarkBar(state == BookmarkBar::DETACHED); |
1341 bookmark_bar_->SetBookmarkBarState( | 1348 bookmark_bar_->SetBookmarkBarState( |
1342 state, | 1349 state, |
1343 animate ? BookmarkBar::ANIMATE_STATE_CHANGE : | 1350 animate ? BookmarkBar::ANIMATE_STATE_CHANGE : |
1344 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 1351 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
1345 } | 1352 } |
1346 | 1353 |
1347 void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { | 1354 void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { |
| 1355 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::UpdateDevToolsForContents"); |
1348 TabContentsWrapper* old_devtools = devtools_container_->tab(); | 1356 TabContentsWrapper* old_devtools = devtools_container_->tab(); |
1349 TabContentsWrapper* devtools_contents = contents ? | 1357 TabContentsWrapper* devtools_contents = contents ? |
1350 DevToolsWindow::GetDevToolsContents(contents) : NULL; | 1358 DevToolsWindow::GetDevToolsContents(contents) : NULL; |
1351 if (old_devtools == devtools_contents) | 1359 if (old_devtools == devtools_contents) |
1352 return; | 1360 return; |
1353 | 1361 |
1354 if (old_devtools) | 1362 if (old_devtools) |
1355 devtools_container_->DetachTab(old_devtools); | 1363 devtools_container_->DetachTab(old_devtools); |
1356 | 1364 |
1357 devtools_container_->SetTab(devtools_contents); | 1365 devtools_container_->SetTab(devtools_contents); |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1995 } | 2003 } |
1996 | 2004 |
1997 void BrowserWindowGtk::OnLocationIconSizeAllocate(GtkWidget* sender, | 2005 void BrowserWindowGtk::OnLocationIconSizeAllocate(GtkWidget* sender, |
1998 GtkAllocation* allocation) { | 2006 GtkAllocation* allocation) { |
1999 // The position of the arrow may have changed, so we'll have to redraw it. | 2007 // The position of the arrow may have changed, so we'll have to redraw it. |
2000 InvalidateInfoBarBits(); | 2008 InvalidateInfoBarBits(); |
2001 } | 2009 } |
2002 | 2010 |
2003 gboolean BrowserWindowGtk::OnExposeDrawInfobarBits(GtkWidget* sender, | 2011 gboolean BrowserWindowGtk::OnExposeDrawInfobarBits(GtkWidget* sender, |
2004 GdkEventExpose* expose) { | 2012 GdkEventExpose* expose) { |
| 2013 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::OnExposeDrawInfobarBits"); |
2005 // Maybe draw infobars | 2014 // Maybe draw infobars |
2006 infobar_container_->PaintInfobarBitsOn(sender, expose, NULL); | 2015 infobar_container_->PaintInfobarBitsOn(sender, expose, NULL); |
2007 | 2016 |
2008 return FALSE; | 2017 return FALSE; |
2009 } | 2018 } |
2010 | 2019 |
2011 gboolean BrowserWindowGtk::OnBookmarkBarExpose(GtkWidget* sender, | 2020 gboolean BrowserWindowGtk::OnBookmarkBarExpose(GtkWidget* sender, |
2012 GdkEventExpose* expose) { | 2021 GdkEventExpose* expose) { |
2013 if (browser_->bookmark_bar_state() == BookmarkBar::DETACHED) | 2022 if (browser_->bookmark_bar_state() == BookmarkBar::DETACHED) |
2014 return FALSE; | 2023 return FALSE; |
2015 | 2024 |
2016 return OnExposeDrawInfobarBits(sender, expose); | 2025 return OnExposeDrawInfobarBits(sender, expose); |
2017 } | 2026 } |
2018 | 2027 |
2019 void BrowserWindowGtk::OnBookmarkBarSizeAllocate(GtkWidget* sender, | 2028 void BrowserWindowGtk::OnBookmarkBarSizeAllocate(GtkWidget* sender, |
2020 GtkAllocation* allocation) { | 2029 GtkAllocation* allocation) { |
| 2030 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::OnBookmarkBarSizeAllocate"); |
2021 // The size of the bookmark bar affects how the infobar arrow is drawn on | 2031 // The size of the bookmark bar affects how the infobar arrow is drawn on |
2022 // the toolbar. | 2032 // the toolbar. |
2023 if (infobar_container_->ContainsInfobars()) | 2033 if (infobar_container_->ContainsInfobars()) |
2024 InvalidateInfoBarBits(); | 2034 InvalidateInfoBarBits(); |
2025 | 2035 |
2026 // Pass the new size to our infobar container. | 2036 // Pass the new size to our infobar container. |
2027 int arrow_size = InfoBar::kDefaultArrowTargetHeight; | 2037 int arrow_size = InfoBar::kDefaultArrowTargetHeight; |
2028 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) | 2038 if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) |
2029 arrow_size += allocation->height; | 2039 arrow_size += allocation->height; |
2030 infobar_container_->SetMaxTopArrowHeight(arrow_size); | 2040 infobar_container_->SetMaxTopArrowHeight(arrow_size); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 GdkScreen* screen = gtk_window_get_screen(window_); | 2380 GdkScreen* screen = gtk_window_get_screen(window_); |
2371 gint monitor_num = gdk_screen_get_monitor_at_window(screen, | 2381 gint monitor_num = gdk_screen_get_monitor_at_window(screen, |
2372 gtk_widget_get_window(GTK_WIDGET(window_))); | 2382 gtk_widget_get_window(GTK_WIDGET(window_))); |
2373 | 2383 |
2374 GdkRectangle monitor_size; | 2384 GdkRectangle monitor_size; |
2375 gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor_size); | 2385 gdk_screen_get_monitor_geometry(screen, monitor_num, &monitor_size); |
2376 return bounds_.size() == gfx::Size(monitor_size.width, monitor_size.height); | 2386 return bounds_.size() == gfx::Size(monitor_size.width, monitor_size.height); |
2377 } | 2387 } |
2378 | 2388 |
2379 void BrowserWindowGtk::PlaceBookmarkBar(bool is_floating) { | 2389 void BrowserWindowGtk::PlaceBookmarkBar(bool is_floating) { |
| 2390 TRACE_EVENT0("ui::gtk", "BrowserWindowGtk::PlaceBookmarkBar"); |
| 2391 |
2380 GtkWidget* target_parent = NULL; | 2392 GtkWidget* target_parent = NULL; |
2381 if (!is_floating) { | 2393 if (!is_floating) { |
2382 // Place the bookmark bar at the end of |window_vbox_|; this happens after | 2394 // Place the bookmark bar at the end of |window_vbox_|; this happens after |
2383 // we have placed the render area at the end of |window_vbox_| so we will | 2395 // we have placed the render area at the end of |window_vbox_| so we will |
2384 // be above the render area. | 2396 // be above the render area. |
2385 target_parent = window_vbox_; | 2397 target_parent = window_vbox_; |
2386 } else { | 2398 } else { |
2387 // Place the bookmark bar at the end of the render area; this happens after | 2399 // Place the bookmark bar at the end of the render area; this happens after |
2388 // the tab contents container has been placed there so we will be | 2400 // the tab contents container has been placed there so we will be |
2389 // above the webpage (in terms of y). | 2401 // above the webpage (in terms of y). |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 wm_type == ui::WM_OPENBOX || | 2443 wm_type == ui::WM_OPENBOX || |
2432 wm_type == ui::WM_XFWM4); | 2444 wm_type == ui::WM_XFWM4); |
2433 } | 2445 } |
2434 | 2446 |
2435 // static | 2447 // static |
2436 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2448 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2437 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2449 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2438 browser_window_gtk->Init(); | 2450 browser_window_gtk->Init(); |
2439 return browser_window_gtk; | 2451 return browser_window_gtk; |
2440 } | 2452 } |
OLD | NEW |