| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/speech/tts_controller.h" | 32 #include "chrome/browser/speech/tts_controller.h" |
| 33 #include "chrome/browser/themes/theme_properties.h" | 33 #include "chrome/browser/themes/theme_properties.h" |
| 34 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 34 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
| 35 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 35 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
| 36 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" | 36 #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| 37 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_command_controller.h" | 38 #include "chrome/browser/ui/browser_command_controller.h" |
| 39 #include "chrome/browser/ui/browser_commands.h" | 39 #include "chrome/browser/ui/browser_commands.h" |
| 40 #include "chrome/browser/ui/browser_dialogs.h" | 40 #include "chrome/browser/ui/browser_dialogs.h" |
| 41 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
| 42 #include "chrome/browser/ui/browser_instant_controller.h" | |
| 43 #include "chrome/browser/ui/browser_list.h" | 42 #include "chrome/browser/ui/browser_list.h" |
| 44 #include "chrome/browser/ui/browser_window_state.h" | 43 #include "chrome/browser/ui/browser_window_state.h" |
| 45 #include "chrome/browser/ui/ntp_background_util.h" | 44 #include "chrome/browser/ui/ntp_background_util.h" |
| 46 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 45 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 47 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" | 46 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" |
| 48 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 47 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
| 49 #include "chrome/browser/ui/search/search.h" | 48 #include "chrome/browser/ui/search/search.h" |
| 50 #include "chrome/browser/ui/search/search_delegate.h" | 49 #include "chrome/browser/ui/search/search_delegate.h" |
| 51 #include "chrome/browser/ui/search/search_model.h" | 50 #include "chrome/browser/ui/search/search_model.h" |
| 52 #include "chrome/browser/ui/search/search_ui.h" | 51 #include "chrome/browser/ui/search/search_ui.h" |
| 53 #include "chrome/browser/ui/tabs/tab_menu_model.h" | 52 #include "chrome/browser/ui/tabs/tab_menu_model.h" |
| 54 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 53 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 55 #include "chrome/browser/ui/view_ids.h" | 54 #include "chrome/browser/ui/view_ids.h" |
| 56 #include "chrome/browser/ui/views/accelerator_table.h" | 55 #include "chrome/browser/ui/views/accelerator_table.h" |
| 57 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" | 56 #include "chrome/browser/ui/views/accessibility/invert_bubble_view.h" |
| 58 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" | 57 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h" |
| 59 #include "chrome/browser/ui/views/avatar_menu_button.h" | 58 #include "chrome/browser/ui/views/avatar_menu_button.h" |
| 60 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 59 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 61 #include "chrome/browser/ui/views/browser_dialogs.h" | 60 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 62 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" | 61 #include "chrome/browser/ui/views/download/download_in_progress_dialog_view.h" |
| 63 #include "chrome/browser/ui/views/download/download_shelf_view.h" | 62 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
| 64 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 63 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
| 65 #include "chrome/browser/ui/views/frame/contents_container.h" | 64 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 66 #include "chrome/browser/ui/views/frame/instant_preview_controller_views.h" | 65 #include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" |
| 67 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" | 66 #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" |
| 68 #include "chrome/browser/ui/views/immersive_mode_controller.h" | 67 #include "chrome/browser/ui/views/immersive_mode_controller.h" |
| 69 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 68 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 70 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 69 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 71 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 70 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| 72 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 71 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
| 73 #include "chrome/browser/ui/views/password_generation_bubble_view.h" | 72 #include "chrome/browser/ui/views/password_generation_bubble_view.h" |
| 74 #include "chrome/browser/ui/views/status_bubble_views.h" | 73 #include "chrome/browser/ui/views/status_bubble_views.h" |
| 75 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" | 74 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" |
| 76 #include "chrome/browser/ui/views/tabs/tab.h" | 75 #include "chrome/browser/ui/views/tabs/tab.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 BrowserView::~BrowserView() { | 376 BrowserView::~BrowserView() { |
| 378 #if defined(USE_ASH) | 377 #if defined(USE_ASH) |
| 379 // Destroy BrowserLauncherItemController early on as it listens to the | 378 // Destroy BrowserLauncherItemController early on as it listens to the |
| 380 // TabstripModel, which is destroyed by the browser. | 379 // TabstripModel, which is destroyed by the browser. |
| 381 launcher_item_controller_.reset(); | 380 launcher_item_controller_.reset(); |
| 382 #endif | 381 #endif |
| 383 | 382 |
| 384 // Immersive mode may need to reparent views before they are removed/deleted. | 383 // Immersive mode may need to reparent views before they are removed/deleted. |
| 385 immersive_mode_controller_.reset(); | 384 immersive_mode_controller_.reset(); |
| 386 | 385 |
| 387 preview_controller_.reset(); | 386 overlay_controller_.reset(); |
| 388 | 387 |
| 389 browser_->tab_strip_model()->RemoveObserver(this); | 388 browser_->tab_strip_model()->RemoveObserver(this); |
| 390 | 389 |
| 391 #if defined(OS_WIN) && !defined(USE_AURA) | 390 #if defined(OS_WIN) && !defined(USE_AURA) |
| 392 // Stop hung plugin monitoring. | 391 // Stop hung plugin monitoring. |
| 393 ticker_.Stop(); | 392 ticker_.Stop(); |
| 394 ticker_.UnregisterTickHandler(&hung_window_detector_); | 393 ticker_.UnregisterTickHandler(&hung_window_detector_); |
| 395 | 394 |
| 396 // Terminate the jumplist (must be called before browser_->profile() is | 395 // Terminate the jumplist (must be called before browser_->profile() is |
| 397 // destroyed. | 396 // destroyed. |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 } | 690 } |
| 692 if (MaybeShowBookmarkBar(GetActiveWebContents())) | 691 if (MaybeShowBookmarkBar(GetActiveWebContents())) |
| 693 Layout(); | 692 Layout(); |
| 694 } | 693 } |
| 695 | 694 |
| 696 void BrowserView::UpdateDevTools() { | 695 void BrowserView::UpdateDevTools() { |
| 697 UpdateDevToolsForContents(GetActiveWebContents()); | 696 UpdateDevToolsForContents(GetActiveWebContents()); |
| 698 Layout(); | 697 Layout(); |
| 699 } | 698 } |
| 700 | 699 |
| 701 | |
| 702 void BrowserView::UpdateLoadingAnimations(bool should_animate) { | 700 void BrowserView::UpdateLoadingAnimations(bool should_animate) { |
| 703 if (should_animate) { | 701 if (should_animate) { |
| 704 if (!loading_animation_timer_.IsRunning()) { | 702 if (!loading_animation_timer_.IsRunning()) { |
| 705 // Loads are happening, and the timer isn't running, so start it. | 703 // Loads are happening, and the timer isn't running, so start it. |
| 706 last_animation_time_ = base::TimeTicks::Now(); | 704 last_animation_time_ = base::TimeTicks::Now(); |
| 707 loading_animation_timer_.Start(FROM_HERE, | 705 loading_animation_timer_.Start(FROM_HERE, |
| 708 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, | 706 TimeDelta::FromMilliseconds(kLoadingAnimationFrameTimeMs), this, |
| 709 &BrowserView::LoadingAnimationCallback); | 707 &BrowserView::LoadingAnimationCallback); |
| 710 } | 708 } |
| 711 } else { | 709 } else { |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 } | 1200 } |
| 1203 | 1201 |
| 1204 int BrowserView::GetExtraRenderViewHeight() const { | 1202 int BrowserView::GetExtraRenderViewHeight() const { |
| 1205 // Currently this is only used on linux. | 1203 // Currently this is only used on linux. |
| 1206 return 0; | 1204 return 0; |
| 1207 } | 1205 } |
| 1208 | 1206 |
| 1209 void BrowserView::WebContentsFocused(WebContents* contents) { | 1207 void BrowserView::WebContentsFocused(WebContents* contents) { |
| 1210 if (contents_container_->GetWebContents() == contents) | 1208 if (contents_container_->GetWebContents() == contents) |
| 1211 contents_container_->OnWebContentsFocused(contents); | 1209 contents_container_->OnWebContentsFocused(contents); |
| 1212 else if (contents_->preview_web_contents() == contents) | 1210 else if (contents_->overlay_web_contents() == contents) |
| 1213 preview_controller_->preview()->OnWebContentsFocused(contents); | 1211 overlay_controller_->overlay()->OnWebContentsFocused(contents); |
| 1214 else | 1212 else |
| 1215 devtools_container_->OnWebContentsFocused(contents); | 1213 devtools_container_->OnWebContentsFocused(contents); |
| 1216 } | 1214 } |
| 1217 | 1215 |
| 1218 void BrowserView::ShowWebsiteSettings(Profile* profile, | 1216 void BrowserView::ShowWebsiteSettings(Profile* profile, |
| 1219 content::WebContents* web_contents, | 1217 content::WebContents* web_contents, |
| 1220 const GURL& url, | 1218 const GURL& url, |
| 1221 const content::SSLStatus& ssl, | 1219 const content::SSLStatus& ssl, |
| 1222 bool show_history) { | 1220 bool show_history) { |
| 1223 WebsiteSettingsPopupView::ShowPopup( | 1221 WebsiteSettingsPopupView::ShowPopup( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1346 | 1344 |
| 1347 void BrowserView::Paste() { | 1345 void BrowserView::Paste() { |
| 1348 DoCutCopyPaste(&content::RenderWidgetHost::Paste, | 1346 DoCutCopyPaste(&content::RenderWidgetHost::Paste, |
| 1349 #if defined(OS_WIN) | 1347 #if defined(OS_WIN) |
| 1350 WM_PASTE, | 1348 WM_PASTE, |
| 1351 #endif | 1349 #endif |
| 1352 IDS_APP_PASTE); | 1350 IDS_APP_PASTE); |
| 1353 } | 1351 } |
| 1354 | 1352 |
| 1355 gfx::Rect BrowserView::GetInstantBounds() { | 1353 gfx::Rect BrowserView::GetInstantBounds() { |
| 1356 return contents_->GetPreviewBounds(); | 1354 return contents_->GetOverlayBounds(); |
| 1357 } | 1355 } |
| 1358 | 1356 |
| 1359 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( | 1357 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( |
| 1360 const gfx::Rect& bounds) { | 1358 const gfx::Rect& bounds) { |
| 1361 #if defined(OS_WIN) | 1359 #if defined(OS_WIN) |
| 1362 // If we are in Win8's single window Metro mode, we can't allow popup windows. | 1360 // If we are in Win8's single window Metro mode, we can't allow popup windows. |
| 1363 return win8::IsSingleWindowMetroMode() ? NEW_BACKGROUND_TAB : NEW_POPUP; | 1361 return win8::IsSingleWindowMetroMode() ? NEW_BACKGROUND_TAB : NEW_POPUP; |
| 1364 #else | 1362 #else |
| 1365 return NEW_POPUP; | 1363 return NEW_POPUP; |
| 1366 #endif | 1364 #endif |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 if (!contents->IsBeingDestroyed()) | 1415 if (!contents->IsBeingDestroyed()) |
| 1418 contents->GetView()->StoreFocus(); | 1416 contents->GetView()->StoreFocus(); |
| 1419 } | 1417 } |
| 1420 | 1418 |
| 1421 void BrowserView::ActiveTabChanged(content::WebContents* old_contents, | 1419 void BrowserView::ActiveTabChanged(content::WebContents* old_contents, |
| 1422 content::WebContents* new_contents, | 1420 content::WebContents* new_contents, |
| 1423 int index, | 1421 int index, |
| 1424 bool user_gesture) { | 1422 bool user_gesture) { |
| 1425 DCHECK(new_contents); | 1423 DCHECK(new_contents); |
| 1426 | 1424 |
| 1427 // See if the Instant preview is being activated (committed). | 1425 // See if the Instant overlay is being activated (committed). |
| 1428 if (contents_->preview_web_contents() == new_contents) { | 1426 if (contents_->overlay_web_contents() == new_contents) { |
| 1429 contents_->MakePreviewContentsActiveContents(); | 1427 contents_->MakeOverlayContentsActiveContents(); |
| 1430 views::WebView* old_container = contents_container_; | 1428 views::WebView* old_container = contents_container_; |
| 1431 contents_container_ = preview_controller_->release_preview(); | 1429 contents_container_ = overlay_controller_->release_overlay(); |
| 1432 old_container->SetWebContents(NULL); | 1430 old_container->SetWebContents(NULL); |
| 1433 delete old_container; | 1431 delete old_container; |
| 1434 } | 1432 } |
| 1435 | 1433 |
| 1436 // If |contents_container_| already has the correct WebContents, we can save | 1434 // If |contents_container_| already has the correct WebContents, we can save |
| 1437 // some work. This also prevents extra events from being reported by the | 1435 // some work. This also prevents extra events from being reported by the |
| 1438 // Visibility API under Windows, as ChangeWebContents will briefly hide | 1436 // Visibility API under Windows, as ChangeWebContents will briefly hide |
| 1439 // the WebContents window. | 1437 // the WebContents window. |
| 1440 bool change_tab_contents = | 1438 bool change_tab_contents = |
| 1441 contents_container_->web_contents() != new_contents; | 1439 contents_container_->web_contents() != new_contents; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1454 bookmark_bar_view_->SetBookmarkBarState( | 1452 bookmark_bar_view_->SetBookmarkBarState( |
| 1455 browser_->bookmark_bar_state(), | 1453 browser_->bookmark_bar_state(), |
| 1456 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 1454 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
| 1457 } | 1455 } |
| 1458 UpdateUIForContents(new_contents); | 1456 UpdateUIForContents(new_contents); |
| 1459 | 1457 |
| 1460 // Layout for DevTools _before_ setting the main WebContents to avoid | 1458 // Layout for DevTools _before_ setting the main WebContents to avoid |
| 1461 // toggling the size of the main WebContents. | 1459 // toggling the size of the main WebContents. |
| 1462 UpdateDevToolsForContents(new_contents); | 1460 UpdateDevToolsForContents(new_contents); |
| 1463 | 1461 |
| 1464 if (change_tab_contents) { | 1462 if (change_tab_contents) |
| 1465 contents_container_->SetWebContents(new_contents); | 1463 contents_container_->SetWebContents(new_contents); |
| 1466 contents_->MaybeStackPreviewAtTop(); | |
| 1467 } | |
| 1468 | 1464 |
| 1469 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && | 1465 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && |
| 1470 GetWidget()->IsVisible()) { | 1466 GetWidget()->IsVisible()) { |
| 1471 // We only restore focus if our window is visible, to avoid invoking blur | 1467 // We only restore focus if our window is visible, to avoid invoking blur |
| 1472 // handlers when we are eventually shown. | 1468 // handlers when we are eventually shown. |
| 1473 new_contents->GetView()->RestoreFocus(); | 1469 new_contents->GetView()->RestoreFocus(); |
| 1474 } | 1470 } |
| 1475 | 1471 |
| 1476 // Update all the UI bits. | 1472 // Update all the UI bits. |
| 1477 UpdateTitleBar(); | 1473 UpdateTitleBar(); |
| 1478 | 1474 |
| 1479 // Like the preview layer and the bookmark bar layer, the immersive mode | 1475 // Like the overlay layer and the bookmark bar layer, the immersive mode |
| 1480 // reveal view's layer may need to live above the web contents. | 1476 // reveal view's layer may need to live above the web contents. |
| 1481 MaybeStackImmersiveRevealAtTop(); | 1477 MaybeStackImmersiveRevealAtTop(); |
| 1482 | 1478 |
| 1483 // No need to update Toolbar because it's already updated in | 1479 // No need to update Toolbar because it's already updated in |
| 1484 // browser.cc. | 1480 // browser.cc. |
| 1485 } | 1481 } |
| 1486 | 1482 |
| 1487 void BrowserView::TabStripEmpty() { | 1483 void BrowserView::TabStripEmpty() { |
| 1488 // Make sure all optional UI is removed before we are destroyed, otherwise | 1484 // Make sure all optional UI is removed before we are destroyed, otherwise |
| 1489 // there will be consequences (since our view hierarchy will still have | 1485 // there will be consequences (since our view hierarchy will still have |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1969 AddChildViewAt(infobar_container_, kInfoBarIndex); | 1965 AddChildViewAt(infobar_container_, kInfoBarIndex); |
| 1970 | 1966 |
| 1971 contents_container_ = new views::WebView(browser_->profile()); | 1967 contents_container_ = new views::WebView(browser_->profile()); |
| 1972 contents_container_->set_id(VIEW_ID_TAB_CONTAINER); | 1968 contents_container_->set_id(VIEW_ID_TAB_CONTAINER); |
| 1973 contents_ = new ContentsContainer(contents_container_); | 1969 contents_ = new ContentsContainer(contents_container_); |
| 1974 | 1970 |
| 1975 toolbar_ = new ToolbarView(browser_.get()); | 1971 toolbar_ = new ToolbarView(browser_.get()); |
| 1976 AddChildViewAt(toolbar_, kToolbarIndex); | 1972 AddChildViewAt(toolbar_, kToolbarIndex); |
| 1977 toolbar_->Init(); | 1973 toolbar_->Init(); |
| 1978 | 1974 |
| 1979 preview_controller_.reset( | 1975 overlay_controller_.reset( |
| 1980 new InstantPreviewControllerViews(browser(), contents_)); | 1976 new InstantOverlayControllerViews(browser(), contents_)); |
| 1981 | 1977 |
| 1982 SkColor bg_color = GetWidget()->GetThemeProvider()-> | 1978 SkColor bg_color = GetWidget()->GetThemeProvider()-> |
| 1983 GetColor(ThemeProperties::COLOR_TOOLBAR); | 1979 GetColor(ThemeProperties::COLOR_TOOLBAR); |
| 1984 | 1980 |
| 1985 devtools_container_ = new views::WebView(browser_->profile()); | 1981 devtools_container_ = new views::WebView(browser_->profile()); |
| 1986 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); | 1982 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); |
| 1987 devtools_container_->SetVisible(false); | 1983 devtools_container_->SetVisible(false); |
| 1988 | 1984 |
| 1989 views::View* contents_view = contents_; | 1985 views::View* contents_view = contents_; |
| 1990 | 1986 |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2629 | 2625 |
| 2630 Browser* modal_browser = | 2626 Browser* modal_browser = |
| 2631 chrome::FindBrowserWithWebContents(active_dialog->web_contents()); | 2627 chrome::FindBrowserWithWebContents(active_dialog->web_contents()); |
| 2632 if (modal_browser && (browser_ != modal_browser)) { | 2628 if (modal_browser && (browser_ != modal_browser)) { |
| 2633 modal_browser->window()->FlashFrame(true); | 2629 modal_browser->window()->FlashFrame(true); |
| 2634 modal_browser->window()->Activate(); | 2630 modal_browser->window()->Activate(); |
| 2635 } | 2631 } |
| 2636 | 2632 |
| 2637 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); | 2633 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); |
| 2638 } | 2634 } |
| OLD | NEW |