OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 1399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1410 // Some reports seem to show that the focus manager and/or focused view can | 1410 // Some reports seem to show that the focus manager and/or focused view can |
1411 // be garbage at that point, it is not clear why. | 1411 // be garbage at that point, it is not clear why. |
1412 if (!contents->in_destructor()) | 1412 if (!contents->in_destructor()) |
1413 contents->web_contents()->GetView()->StoreFocus(); | 1413 contents->web_contents()->GetView()->StoreFocus(); |
1414 } | 1414 } |
1415 | 1415 |
1416 void BrowserView::ActiveTabChanged(TabContents* old_contents, | 1416 void BrowserView::ActiveTabChanged(TabContents* old_contents, |
1417 TabContents* new_contents, | 1417 TabContents* new_contents, |
1418 int index, | 1418 int index, |
1419 bool user_gesture) { | 1419 bool user_gesture) { |
1420 ProcessTabSelected(new_contents); | 1420 DCHECK(new_contents); |
1421 } | |
1422 | 1421 |
1423 void BrowserView::TabReplacedAt(TabStripModel* tab_strip_model, | 1422 // See if the Instant preview is being activated (committed). |
1424 TabContents* old_contents, | |
1425 TabContents* new_contents, | |
1426 int index) { | |
1427 if (index != browser_->tab_strip_model()->active_index()) | |
1428 return; | |
1429 | |
1430 if (contents_->preview_web_contents() == new_contents->web_contents()) { | 1423 if (contents_->preview_web_contents() == new_contents->web_contents()) { |
1431 if (search_view_controller_.get()) | 1424 if (search_view_controller_.get()) |
1432 search_view_controller_->WillCommitInstant(); | 1425 search_view_controller_->WillCommitInstant(); |
1433 // If 'preview' is becoming active, swap the 'active' and 'preview' and | |
1434 // delete what was the active. | |
1435 contents_->MakePreviewContentsActiveContents(); | 1426 contents_->MakePreviewContentsActiveContents(); |
1436 views::WebView* old_container = contents_container_; | 1427 views::WebView* old_container = contents_container_; |
1437 contents_container_ = preview_controller_->release_preview_container(); | 1428 contents_container_ = preview_controller_->release_preview_container(); |
1438 old_container->SetWebContents(NULL); | 1429 old_container->SetWebContents(NULL); |
1439 delete old_container; | 1430 delete old_container; |
1440 } | 1431 } |
1441 // Update the UI for the new contents. | 1432 |
1442 ProcessTabSelected(new_contents); | 1433 // If |contents_container_| already has the correct WebContents, we can save |
| 1434 // some work. This also prevents extra events from being reported by the |
| 1435 // Visibility API under Windows, as ChangeWebContents will briefly hide |
| 1436 // the WebContents window. |
| 1437 bool change_tab_contents = |
| 1438 contents_container_->web_contents() != new_contents->web_contents(); |
| 1439 |
| 1440 // Update various elements that are interested in knowing the current |
| 1441 // WebContents. |
| 1442 |
| 1443 // When we toggle the NTP floating bookmarks bar and/or the info bar, |
| 1444 // we don't want any WebContents to be attached, so that we |
| 1445 // avoid an unnecessary resize and re-layout of a WebContents. |
| 1446 // This also applies to the |search_view_controller_| logic, as it can |
| 1447 // reparent the |contents_container_|. |
| 1448 if (change_tab_contents) |
| 1449 contents_container_->SetWebContents(NULL); |
| 1450 InfoBarTabHelper* new_infobar_tab_helper = |
| 1451 InfoBarTabHelper::FromWebContents(new_contents->web_contents()); |
| 1452 // Hide infobars when showing Instant Extended suggestions. |
| 1453 infobar_container_->ChangeTabContents( |
| 1454 (chrome::search::IsInstantExtendedAPIEnabled(browser()->profile()) && |
| 1455 browser()->search_model()->mode().is_search_suggestions()) ? |
| 1456 NULL : new_infobar_tab_helper); |
| 1457 if (bookmark_bar_view_.get()) { |
| 1458 bookmark_bar_view_->SetBookmarkBarState( |
| 1459 browser_->bookmark_bar_state(), |
| 1460 BookmarkBar::DONT_ANIMATE_STATE_CHANGE, |
| 1461 browser_->search_model()->mode()); |
| 1462 } |
| 1463 UpdateUIForContents(new_contents); |
| 1464 |
| 1465 // |change_tab_contents| can mean same WebContents but different TabContents, |
| 1466 // so let SearchViewController decide how it would handle |new_contents|. |
| 1467 if (search_view_controller_.get()) |
| 1468 search_view_controller_->SetTabContents(new_contents); |
| 1469 |
| 1470 // Layout for DevTools _before_ setting the main WebContents to avoid |
| 1471 // toggling the size of the main WebContents. |
| 1472 UpdateDevToolsForContents(new_contents); |
| 1473 |
| 1474 if (change_tab_contents) |
| 1475 contents_container_->SetWebContents(new_contents->web_contents()); |
| 1476 |
| 1477 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && |
| 1478 GetWidget()->IsVisible()) { |
| 1479 // We only restore focus if our window is visible, to avoid invoking blur |
| 1480 // handlers when we are eventually shown. |
| 1481 new_contents->web_contents()->GetView()->RestoreFocus(); |
| 1482 } |
| 1483 |
| 1484 // Update all the UI bits. |
| 1485 UpdateTitleBar(); |
| 1486 |
| 1487 // Restacking needs to happen after other UI updates. This restores special |
| 1488 // "widget" stacking that governs the SearchViewController's NTP "content" |
| 1489 // area. |
| 1490 RestackLocationBarContainer(); |
| 1491 |
| 1492 // No need to update Toolbar because it's already updated in |
| 1493 // browser.cc. |
1443 } | 1494 } |
1444 | 1495 |
1445 void BrowserView::TabStripEmpty() { | 1496 void BrowserView::TabStripEmpty() { |
1446 // Make sure all optional UI is removed before we are destroyed, otherwise | 1497 // Make sure all optional UI is removed before we are destroyed, otherwise |
1447 // there will be consequences (since our view hierarchy will still have | 1498 // there will be consequences (since our view hierarchy will still have |
1448 // references to freed views). | 1499 // references to freed views). |
1449 UpdateUIForContents(NULL); | 1500 UpdateUIForContents(NULL); |
1450 } | 1501 } |
1451 | 1502 |
1452 /////////////////////////////////////////////////////////////////////////////// | 1503 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2450 else if (key_code == ui::VKEY_K) | 2501 else if (key_code == ui::VKEY_K) |
2451 content::RecordAction(UserMetricsAction("Accel_FocusSearch_K")); | 2502 content::RecordAction(UserMetricsAction("Accel_FocusSearch_K")); |
2452 break; | 2503 break; |
2453 default: | 2504 default: |
2454 // Do nothing. | 2505 // Do nothing. |
2455 break; | 2506 break; |
2456 } | 2507 } |
2457 #endif | 2508 #endif |
2458 } | 2509 } |
2459 | 2510 |
2460 void BrowserView::ProcessTabSelected(TabContents* new_contents) { | |
2461 // If |contents_container_| already has the correct WebContents, we can save | |
2462 // some work. This also prevents extra events from being reported by the | |
2463 // Visibility API under Windows, as ChangeWebContents will briefly hide | |
2464 // the WebContents window. | |
2465 DCHECK(new_contents); | |
2466 bool change_tab_contents = | |
2467 contents_container_->web_contents() != new_contents->web_contents(); | |
2468 | |
2469 // Update various elements that are interested in knowing the current | |
2470 // WebContents. | |
2471 | |
2472 // When we toggle the NTP floating bookmarks bar and/or the info bar, | |
2473 // we don't want any WebContents to be attached, so that we | |
2474 // avoid an unnecessary resize and re-layout of a WebContents. | |
2475 // This also applies to the |search_view_controller_| logic, as it can | |
2476 // reparent the |contents_container_|. | |
2477 if (change_tab_contents) | |
2478 contents_container_->SetWebContents(NULL); | |
2479 InfoBarTabHelper* new_infobar_tab_helper = | |
2480 InfoBarTabHelper::FromWebContents(new_contents->web_contents()); | |
2481 // Hide infobars when showing Instant Extended suggestions. | |
2482 infobar_container_->ChangeTabContents( | |
2483 (chrome::search::IsInstantExtendedAPIEnabled(browser()->profile()) && | |
2484 browser()->search_model()->mode().is_search_suggestions()) ? | |
2485 NULL : new_infobar_tab_helper); | |
2486 if (bookmark_bar_view_.get()) { | |
2487 bookmark_bar_view_->SetBookmarkBarState( | |
2488 browser_->bookmark_bar_state(), | |
2489 BookmarkBar::DONT_ANIMATE_STATE_CHANGE, | |
2490 browser_->search_model()->mode()); | |
2491 } | |
2492 UpdateUIForContents(new_contents); | |
2493 | |
2494 // |change_tab_contents| can mean same WebContents but different TabContents, | |
2495 // so let SearchViewController decide how it would handle |new_contents|. | |
2496 if (search_view_controller_.get()) | |
2497 search_view_controller_->SetTabContents(new_contents); | |
2498 | |
2499 // Layout for DevTools _before_ setting the main WebContents to avoid | |
2500 // toggling the size of the main WebContents. | |
2501 UpdateDevToolsForContents(new_contents); | |
2502 | |
2503 if (change_tab_contents) | |
2504 contents_container_->SetWebContents(new_contents->web_contents()); | |
2505 | |
2506 if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && | |
2507 GetWidget()->IsVisible()) { | |
2508 // We only restore focus if our window is visible, to avoid invoking blur | |
2509 // handlers when we are eventually shown. | |
2510 new_contents->web_contents()->GetView()->RestoreFocus(); | |
2511 } | |
2512 | |
2513 // Update all the UI bits. | |
2514 UpdateTitleBar(); | |
2515 | |
2516 // Restacking needs to happen after other UI updates. This restores special | |
2517 // "widget" stacking that governs the SearchViewController's NTP "content" | |
2518 // area. | |
2519 RestackLocationBarContainer(); | |
2520 | |
2521 // No need to update Toolbar because it's already updated in | |
2522 // browser.cc. | |
2523 } | |
2524 | |
2525 gfx::Size BrowserView::GetResizeCornerSize() const { | 2511 gfx::Size BrowserView::GetResizeCornerSize() const { |
2526 return ResizeCorner::GetSize(); | 2512 return ResizeCorner::GetSize(); |
2527 } | 2513 } |
2528 | 2514 |
2529 void BrowserView::ModeChanged(const chrome::search::Mode& old_mode, | 2515 void BrowserView::ModeChanged(const chrome::search::Mode& old_mode, |
2530 const chrome::search::Mode& new_mode) { | 2516 const chrome::search::Mode& new_mode) { |
2531 // Hide infobars when showing Instant Extended suggestions and when moving | 2517 // Hide infobars when showing Instant Extended suggestions and when moving |
2532 // from SUGGESTIONS to DEFAULT which happens when a URL is selected or typed | 2518 // from SUGGESTIONS to DEFAULT which happens when a URL is selected or typed |
2533 // from the NTP. Moving to DEFAULT will replace the infobars with those of the | 2519 // from the NTP. Moving to DEFAULT will replace the infobars with those of the |
2534 // new tab contents, therefore we avoid the showing the current infobars for | 2520 // new tab contents, therefore we avoid the showing the current infobars for |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2654 | 2640 |
2655 Browser* modal_browser = | 2641 Browser* modal_browser = |
2656 browser::FindBrowserWithWebContents(active_dialog->web_contents()); | 2642 browser::FindBrowserWithWebContents(active_dialog->web_contents()); |
2657 if (modal_browser && (browser_ != modal_browser)) { | 2643 if (modal_browser && (browser_ != modal_browser)) { |
2658 modal_browser->window()->FlashFrame(true); | 2644 modal_browser->window()->FlashFrame(true); |
2659 modal_browser->window()->Activate(); | 2645 modal_browser->window()->Activate(); |
2660 } | 2646 } |
2661 | 2647 |
2662 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); | 2648 AppModalDialogQueue::GetInstance()->ActivateModalDialog(); |
2663 } | 2649 } |
OLD | NEW |