Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 | 6 |
| 7 #include "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/idle_timer.h" | 10 #include "base/idle_timer.h" |
| (...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 return TAB_TEAROFF_ACTION | (tab_count() > 1 ? TAB_MOVE_ACTION : 0); | 1496 return TAB_TEAROFF_ACTION | (tab_count() > 1 ? TAB_MOVE_ACTION : 0); |
| 1497 } | 1497 } |
| 1498 | 1498 |
| 1499 TabContents* Browser::CreateTabContentsForURL( | 1499 TabContents* Browser::CreateTabContentsForURL( |
| 1500 const GURL& url, const GURL& referrer, Profile* profile, | 1500 const GURL& url, const GURL& referrer, Profile* profile, |
| 1501 PageTransition::Type transition, bool defer_load, | 1501 PageTransition::Type transition, bool defer_load, |
| 1502 SiteInstance* instance) const { | 1502 SiteInstance* instance) const { |
| 1503 TabContents* contents = new TabContents(profile, instance, | 1503 TabContents* contents = new TabContents(profile, instance, |
| 1504 MSG_ROUTING_NONE, NULL); | 1504 MSG_ROUTING_NONE, NULL); |
| 1505 | 1505 |
| 1506 // Ensure that the new TabContentsView begins at the same size as the | |
| 1507 // previous TabContentsView if it existed. Otherwise, the initial WebKit | |
| 1508 // layout will be performed based on a width of 0 pixels, causing a | |
| 1509 // very long, narrow, inaccurate layout. Because some scripts on pages (as | |
| 1510 // well as WebKit's anchor link location calculation) are run on the initial | |
| 1511 // layout and not recalculated later, we need to ensure the first layout is | |
| 1512 // performed with sane view dimensions even when we're opening a new | |
| 1513 // background tab. | |
| 1514 if (TabContents* old_contents = tabstrip_model_.GetSelectedTabContents()) | |
| 1515 contents->view()->SizeContents(old_contents->view()->GetContainerSize()); | |
|
Nate Chapin
2009/08/13 18:56:54
My impression (and this could be entirely wrong) w
| |
| 1516 | |
| 1517 if (!defer_load) { | 1506 if (!defer_load) { |
| 1518 // Load the initial URL before adding the new tab contents to the tab strip | 1507 // Load the initial URL before adding the new tab contents to the tab strip |
| 1519 // so that the tab contents has navigation state. | 1508 // so that the tab contents has navigation state. |
| 1520 contents->controller().LoadURL(url, referrer, transition); | 1509 contents->controller().LoadURL(url, referrer, transition); |
| 1521 } | 1510 } |
| 1522 | 1511 |
| 1523 return contents; | 1512 return contents; |
| 1524 } | 1513 } |
| 1525 | 1514 |
| 1526 bool Browser::CanDuplicateContentsAt(int index) { | 1515 bool Browser::CanDuplicateContentsAt(int index) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1824 } | 1813 } |
| 1825 | 1814 |
| 1826 if (disposition == NEW_POPUP) { | 1815 if (disposition == NEW_POPUP) { |
| 1827 BuildPopupWindow(source, new_contents, initial_pos); | 1816 BuildPopupWindow(source, new_contents, initial_pos); |
| 1828 } else if (disposition == NEW_WINDOW) { | 1817 } else if (disposition == NEW_WINDOW) { |
| 1829 Browser* browser = Browser::Create(profile_); | 1818 Browser* browser = Browser::Create(profile_); |
| 1830 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, | 1819 browser->AddNewContents(source, new_contents, NEW_FOREGROUND_TAB, |
| 1831 initial_pos, user_gesture); | 1820 initial_pos, user_gesture); |
| 1832 browser->window()->Show(); | 1821 browser->window()->Show(); |
| 1833 } else if (disposition != SUPPRESS_OPEN) { | 1822 } else if (disposition != SUPPRESS_OPEN) { |
| 1834 // Ensure that the new TabContentsView begins at the same size as the | |
| 1835 // previous TabContentsView if it existed. Otherwise, the initial WebKit | |
| 1836 // layout will be performed based on a width of 0 pixels, causing a | |
| 1837 // very long, narrow, inaccurate layout. Because some scripts on pages (as | |
| 1838 // well as WebKit's anchor link location calculation) are run on the | |
| 1839 // initial layout and not recalculated later, we need to ensure the first | |
| 1840 // layout is performed with sane view dimensions even when we're opening a | |
| 1841 // new background tab. | |
| 1842 if (TabContents* old_contents = tabstrip_model_.GetSelectedTabContents()) { | |
| 1843 new_contents->view()->SizeContents( | |
| 1844 old_contents->view()->GetContainerSize()); | |
| 1845 } | |
| 1846 tabstrip_model_.AddTabContents(new_contents, -1, false, | 1823 tabstrip_model_.AddTabContents(new_contents, -1, false, |
| 1847 PageTransition::LINK, | 1824 PageTransition::LINK, |
| 1848 disposition == NEW_FOREGROUND_TAB); | 1825 disposition == NEW_FOREGROUND_TAB); |
| 1849 } | 1826 } |
| 1850 } | 1827 } |
| 1851 | 1828 |
| 1852 void Browser::ActivateContents(TabContents* contents) { | 1829 void Browser::ActivateContents(TabContents* contents) { |
| 1853 tabstrip_model_.SelectTabContentsAt( | 1830 tabstrip_model_.SelectTabContentsAt( |
| 1854 tabstrip_model_.GetIndexOfTabContents(contents), false); | 1831 tabstrip_model_.GetIndexOfTabContents(contents), false); |
| 1855 window_->Activate(); | 1832 window_->Activate(); |
| (...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2807 /////////////////////////////////////////////////////////////////////////////// | 2784 /////////////////////////////////////////////////////////////////////////////// |
| 2808 // BrowserToolbarModel (private): | 2785 // BrowserToolbarModel (private): |
| 2809 | 2786 |
| 2810 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { | 2787 NavigationController* Browser::BrowserToolbarModel::GetNavigationController() { |
| 2811 // This |current_tab| can be NULL during the initialization of the | 2788 // This |current_tab| can be NULL during the initialization of the |
| 2812 // toolbar during window creation (i.e. before any tabs have been added | 2789 // toolbar during window creation (i.e. before any tabs have been added |
| 2813 // to the window). | 2790 // to the window). |
| 2814 TabContents* current_tab = browser_->GetSelectedTabContents(); | 2791 TabContents* current_tab = browser_->GetSelectedTabContents(); |
| 2815 return current_tab ? ¤t_tab->controller() : NULL; | 2792 return current_tab ? ¤t_tab->controller() : NULL; |
| 2816 } | 2793 } |
| OLD | NEW |