| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/frame/browser_view.h" | 5 #include "chrome/browser/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 #include "chrome/browser/tab_contents/match_preview.h" | 36 #include "chrome/browser/tab_contents/match_preview.h" |
| 37 #include "chrome/browser/tab_contents/tab_contents.h" | 37 #include "chrome/browser/tab_contents/tab_contents.h" |
| 38 #include "chrome/browser/tab_contents/tab_contents_view.h" | 38 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 39 #include "chrome/browser/themes/browser_theme_provider.h" | 39 #include "chrome/browser/themes/browser_theme_provider.h" |
| 40 #include "chrome/browser/view_ids.h" | 40 #include "chrome/browser/view_ids.h" |
| 41 #include "chrome/browser/views/accessible_view_helper.h" | 41 #include "chrome/browser/views/accessible_view_helper.h" |
| 42 #include "chrome/browser/views/bookmark_bar_view.h" | 42 #include "chrome/browser/views/bookmark_bar_view.h" |
| 43 #include "chrome/browser/views/browser_dialogs.h" | 43 #include "chrome/browser/views/browser_dialogs.h" |
| 44 #include "chrome/browser/views/download_shelf_view.h" | 44 #include "chrome/browser/views/download_shelf_view.h" |
| 45 #include "chrome/browser/views/frame/browser_view_layout.h" | 45 #include "chrome/browser/views/frame/browser_view_layout.h" |
| 46 #include "chrome/browser/views/frame/contents_container.h" |
| 46 #include "chrome/browser/views/fullscreen_exit_bubble.h" | 47 #include "chrome/browser/views/fullscreen_exit_bubble.h" |
| 47 #include "chrome/browser/views/status_bubble_views.h" | 48 #include "chrome/browser/views/status_bubble_views.h" |
| 48 #include "chrome/browser/views/tab_contents/tab_contents_container.h" | 49 #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
| 49 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h" | 50 #include "chrome/browser/views/tabs/browser_tab_strip_controller.h" |
| 50 #include "chrome/browser/views/tabs/side_tab_strip.h" | 51 #include "chrome/browser/views/tabs/side_tab_strip.h" |
| 51 #include "chrome/browser/views/theme_install_bubble_view.h" | 52 #include "chrome/browser/views/theme_install_bubble_view.h" |
| 52 #include "chrome/browser/views/toolbar_view.h" | 53 #include "chrome/browser/views/toolbar_view.h" |
| 53 #include "chrome/browser/views/update_recommended_message_box.h" | 54 #include "chrome/browser/views/update_recommended_message_box.h" |
| 54 #include "chrome/browser/window_sizer.h" | 55 #include "chrome/browser/window_sizer.h" |
| 55 #include "chrome/browser/wrench_menu_model.h" | 56 #include "chrome/browser/wrench_menu_model.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 profile ? profile : browser->profile(), | 129 profile ? profile : browser->profile(), |
| 129 Browser::TYPE_NORMAL, true); | 130 Browser::TYPE_NORMAL, true); |
| 130 if (normal_browser && normal_browser->window()) | 131 if (normal_browser && normal_browser->window()) |
| 131 return normal_browser->window()->GetNativeHandle(); | 132 return normal_browser->window()->GetNativeHandle(); |
| 132 } | 133 } |
| 133 | 134 |
| 134 return browser->window()->GetNativeHandle(); | 135 return browser->window()->GetNativeHandle(); |
| 135 } | 136 } |
| 136 #endif // defined(OS_CHROMEOS) | 137 #endif // defined(OS_CHROMEOS) |
| 137 | 138 |
| 138 // ContentsContainer is responsible for managing the TabContents views. | |
| 139 // ContentsContainer has up to two children: one for the currently active | |
| 140 // TabContents and one for the match preview TabContents. | |
| 141 class BrowserView::ContentsContainer : public views::View { | |
| 142 public: | |
| 143 ContentsContainer(BrowserView* browser_view, views::View* active) | |
| 144 : browser_view_(browser_view), | |
| 145 active_(active), | |
| 146 preview_(NULL) { | |
| 147 AddChildView(active_); | |
| 148 } | |
| 149 | |
| 150 // Makes the preview view the active view and nulls out the old active view. | |
| 151 // It's assumed the caller will delete or remove the old active view | |
| 152 // separately. | |
| 153 void MakePreviewContentsActiveContents() { | |
| 154 active_ = preview_; | |
| 155 preview_ = NULL; | |
| 156 Layout(); | |
| 157 } | |
| 158 | |
| 159 // Sets the preview view. This does not delete the old. | |
| 160 void SetPreview(views::View* preview) { | |
| 161 if (preview == preview_) | |
| 162 return; | |
| 163 | |
| 164 if (preview_) | |
| 165 RemoveChildView(preview_); | |
| 166 preview_ = preview; | |
| 167 if (preview_) | |
| 168 AddChildView(preview_); | |
| 169 | |
| 170 Layout(); | |
| 171 } | |
| 172 | |
| 173 virtual void Layout() { | |
| 174 // The active view always gets the full bounds. | |
| 175 active_->SetBounds(0, 0, width(), height()); | |
| 176 | |
| 177 if (preview_) { | |
| 178 // The preview view gets the full width and is positioned beneath the | |
| 179 // bottom of the autocompleted popup. | |
| 180 int max_autocomplete_y = browser_view_->toolbar()->location_bar()-> | |
| 181 location_entry()->model()->popup_model()->view()->GetMaxYCoordinate(); | |
| 182 gfx::Point screen_origin; | |
| 183 views::View::ConvertPointToScreen(this, &screen_origin); | |
| 184 DCHECK_GT(max_autocomplete_y, screen_origin.y()); | |
| 185 int preview_origin = max_autocomplete_y - screen_origin.y(); | |
| 186 if (preview_origin < height()) { | |
| 187 preview_->SetBounds(0, preview_origin, width(), | |
| 188 height() - preview_origin); | |
| 189 } else { | |
| 190 preview_->SetBounds(0, 0, 0, 0); | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 // Need to invoke views::View in case any views whose bounds didn't change | |
| 195 // still need a layout. | |
| 196 views::View::Layout(); | |
| 197 } | |
| 198 | |
| 199 private: | |
| 200 BrowserView* browser_view_; | |
| 201 views::View* active_; | |
| 202 views::View* preview_; | |
| 203 | |
| 204 DISALLOW_COPY_AND_ASSIGN(ContentsContainer); | |
| 205 }; | |
| 206 | |
| 207 /////////////////////////////////////////////////////////////////////////////// | 139 /////////////////////////////////////////////////////////////////////////////// |
| 208 // BookmarkExtensionBackground, private: | 140 // BookmarkExtensionBackground, private: |
| 209 // This object serves as the views::Background object which is used to layout | 141 // This object serves as the views::Background object which is used to layout |
| 210 // and paint the bookmark bar. | 142 // and paint the bookmark bar. |
| 211 class BookmarkExtensionBackground : public views::Background { | 143 class BookmarkExtensionBackground : public views::Background { |
| 212 public: | 144 public: |
| 213 explicit BookmarkExtensionBackground(BrowserView* browser_view, | 145 explicit BookmarkExtensionBackground(BrowserView* browser_view, |
| 214 DetachableToolbarView* host_view, | 146 DetachableToolbarView* host_view, |
| 215 Browser* browser); | 147 Browser* browser); |
| 216 | 148 |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1415 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V, | 1347 ui_controls::SendKeyPress(GetNativeHandle(), app::VKEY_V, |
| 1416 false, false, false, true); | 1348 false, false, false, true); |
| 1417 } | 1349 } |
| 1418 #endif | 1350 #endif |
| 1419 | 1351 |
| 1420 void BrowserView::ToggleTabStripMode() { | 1352 void BrowserView::ToggleTabStripMode() { |
| 1421 InitTabStrip(browser_->tabstrip_model()); | 1353 InitTabStrip(browser_->tabstrip_model()); |
| 1422 frame_->TabStripDisplayModeChanged(); | 1354 frame_->TabStripDisplayModeChanged(); |
| 1423 } | 1355 } |
| 1424 | 1356 |
| 1357 void BrowserView::ShowMatchPreview() { |
| 1358 if (!preview_container_) |
| 1359 preview_container_ = new TabContentsContainer(); |
| 1360 TabContents* preview_tab_contents = |
| 1361 browser_->match_preview()->preview_contents(); |
| 1362 contents_->SetPreview(preview_container_, preview_tab_contents); |
| 1363 preview_container_->ChangeTabContents(preview_tab_contents); |
| 1364 } |
| 1365 |
| 1366 void BrowserView::HideMatchPreview() { |
| 1367 if (!preview_container_) |
| 1368 return; |
| 1369 |
| 1370 // The contents must be changed before SetPreview is invoked. |
| 1371 preview_container_->ChangeTabContents(NULL); |
| 1372 contents_->SetPreview(NULL, NULL); |
| 1373 delete preview_container_; |
| 1374 preview_container_ = NULL; |
| 1375 } |
| 1376 |
| 1425 /////////////////////////////////////////////////////////////////////////////// | 1377 /////////////////////////////////////////////////////////////////////////////// |
| 1426 // BrowserView, BrowserWindowTesting implementation: | 1378 // BrowserView, BrowserWindowTesting implementation: |
| 1427 | 1379 |
| 1428 BookmarkBarView* BrowserView::GetBookmarkBarView() const { | 1380 BookmarkBarView* BrowserView::GetBookmarkBarView() const { |
| 1429 return bookmark_bar_view_.get(); | 1381 return bookmark_bar_view_.get(); |
| 1430 } | 1382 } |
| 1431 | 1383 |
| 1432 LocationBarView* BrowserView::GetLocationBarView() const { | 1384 LocationBarView* BrowserView::GetLocationBarView() const { |
| 1433 return toolbar_->location_bar(); | 1385 return toolbar_->location_bar(); |
| 1434 } | 1386 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1454 const NotificationSource& source, | 1406 const NotificationSource& source, |
| 1455 const NotificationDetails& details) { | 1407 const NotificationDetails& details) { |
| 1456 switch (type.value) { | 1408 switch (type.value) { |
| 1457 case NotificationType::PREF_CHANGED: | 1409 case NotificationType::PREF_CHANGED: |
| 1458 if (*Details<std::string>(details).ptr() == prefs::kShowBookmarkBar && | 1410 if (*Details<std::string>(details).ptr() == prefs::kShowBookmarkBar && |
| 1459 MaybeShowBookmarkBar(browser_->GetSelectedTabContents())) { | 1411 MaybeShowBookmarkBar(browser_->GetSelectedTabContents())) { |
| 1460 Layout(); | 1412 Layout(); |
| 1461 } | 1413 } |
| 1462 break; | 1414 break; |
| 1463 | 1415 |
| 1464 case NotificationType::MATCH_PREVIEW_TAB_CONTENTS_CREATED: | |
| 1465 if (Source<TabContents>(source).ptr() == | |
| 1466 browser_->GetSelectedTabContents()) { | |
| 1467 ShowMatchPreview(); | |
| 1468 } | |
| 1469 break; | |
| 1470 | |
| 1471 case NotificationType::TAB_CONTENTS_DESTROYED: { | |
| 1472 if (MatchPreview::IsEnabled()) { | |
| 1473 TabContents* selected_contents = browser_->GetSelectedTabContents(); | |
| 1474 if (selected_contents && | |
| 1475 selected_contents->match_preview()->preview_contents() == | |
| 1476 Source<TabContents>(source).ptr()) { | |
| 1477 HideMatchPreview(); | |
| 1478 } | |
| 1479 } | |
| 1480 break; | |
| 1481 } | |
| 1482 | |
| 1483 case NotificationType::SIDEBAR_CHANGED: | 1416 case NotificationType::SIDEBAR_CHANGED: |
| 1484 if (Details<SidebarContainer>(details)->tab_contents() == | 1417 if (Details<SidebarContainer>(details)->tab_contents() == |
| 1485 browser_->GetSelectedTabContents()) { | 1418 browser_->GetSelectedTabContents()) { |
| 1486 UpdateSidebar(); | 1419 UpdateSidebar(); |
| 1487 } | 1420 } |
| 1488 break; | 1421 break; |
| 1489 | 1422 |
| 1490 default: | 1423 default: |
| 1491 NOTREACHED() << "Got a notification we didn't register for!"; | 1424 NOTREACHED() << "Got a notification we didn't register for!"; |
| 1492 break; | 1425 break; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 | 1909 |
| 1977 if (AeroPeekManager::Enabled()) { | 1910 if (AeroPeekManager::Enabled()) { |
| 1978 aeropeek_manager_.reset(new AeroPeekManager( | 1911 aeropeek_manager_.reset(new AeroPeekManager( |
| 1979 frame_->GetWindow()->GetNativeWindow())); | 1912 frame_->GetWindow()->GetNativeWindow())); |
| 1980 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); | 1913 browser_->tabstrip_model()->AddObserver(aeropeek_manager_.get()); |
| 1981 } | 1914 } |
| 1982 #endif | 1915 #endif |
| 1983 | 1916 |
| 1984 // We're now initialized and ready to process Layout requests. | 1917 // We're now initialized and ready to process Layout requests. |
| 1985 ignore_layout_ = false; | 1918 ignore_layout_ = false; |
| 1986 | |
| 1987 registrar_.Add(this, | |
| 1988 NotificationType::MATCH_PREVIEW_TAB_CONTENTS_CREATED, | |
| 1989 NotificationService::AllSources()); | |
| 1990 registrar_.Add(this, | |
| 1991 NotificationType::TAB_CONTENTS_DESTROYED, | |
| 1992 NotificationService::AllSources()); | |
| 1993 } | 1919 } |
| 1994 | 1920 |
| 1995 #if defined(OS_WIN) | 1921 #if defined(OS_WIN) |
| 1996 void BrowserView::InitSystemMenu() { | 1922 void BrowserView::InitSystemMenu() { |
| 1997 system_menu_contents_.reset(new views::SystemMenuModel(this)); | 1923 system_menu_contents_.reset(new views::SystemMenuModel(this)); |
| 1998 // We add the menu items in reverse order so that insertion_index never needs | 1924 // We add the menu items in reverse order so that insertion_index never needs |
| 1999 // to change. | 1925 // to change. |
| 2000 if (IsBrowserTypeNormal()) | 1926 if (IsBrowserTypeNormal()) |
| 2001 BuildSystemMenuForBrowserWindow(); | 1927 BuildSystemMenuForBrowserWindow(); |
| 2002 else | 1928 else |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2465 ticker_.Start(); | 2391 ticker_.Start(); |
| 2466 | 2392 |
| 2467 pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, | 2393 pref_service->SetInteger(prefs::kPluginMessageResponseTimeout, |
| 2468 plugin_message_response_timeout); | 2394 plugin_message_response_timeout); |
| 2469 pref_service->SetInteger(prefs::kHungPluginDetectFrequency, | 2395 pref_service->SetInteger(prefs::kHungPluginDetectFrequency, |
| 2470 hung_plugin_detect_freq); | 2396 hung_plugin_detect_freq); |
| 2471 } | 2397 } |
| 2472 #endif | 2398 #endif |
| 2473 } | 2399 } |
| 2474 | 2400 |
| 2475 void BrowserView::ShowMatchPreview() { | |
| 2476 if (!preview_container_) | |
| 2477 preview_container_ = new TabContentsContainer(); | |
| 2478 contents_->SetPreview(preview_container_); | |
| 2479 preview_container_->ChangeTabContents( | |
| 2480 browser_->GetSelectedTabContents()->match_preview()->preview_contents()); | |
| 2481 } | |
| 2482 | |
| 2483 void BrowserView::HideMatchPreview() { | |
| 2484 if (!preview_container_) | |
| 2485 return; | |
| 2486 | |
| 2487 // The contents must be changed before SetPreview is invoked. | |
| 2488 preview_container_->ChangeTabContents(NULL); | |
| 2489 contents_->SetPreview(NULL); | |
| 2490 delete preview_container_; | |
| 2491 preview_container_ = NULL; | |
| 2492 } | |
| 2493 | |
| 2494 void BrowserView::ProcessTabSelected(TabContents* new_contents, | 2401 void BrowserView::ProcessTabSelected(TabContents* new_contents, |
| 2495 bool change_tab_contents) { | 2402 bool change_tab_contents) { |
| 2496 // Update various elements that are interested in knowing the current | 2403 // Update various elements that are interested in knowing the current |
| 2497 // TabContents. | 2404 // TabContents. |
| 2498 | 2405 |
| 2499 // When we toggle the NTP floating bookmarks bar and/or the info bar, | 2406 // When we toggle the NTP floating bookmarks bar and/or the info bar, |
| 2500 // we don't want any TabContents to be attached, so that we | 2407 // we don't want any TabContents to be attached, so that we |
| 2501 // avoid an unnecessary resize and re-layout of a TabContents. | 2408 // avoid an unnecessary resize and re-layout of a TabContents. |
| 2502 if (change_tab_contents) | 2409 if (change_tab_contents) |
| 2503 contents_container_->ChangeTabContents(NULL); | 2410 contents_container_->ChangeTabContents(NULL); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); | 2445 SetAccessibleName(l10n_util::GetString(IDS_PRODUCT_NAME)); |
| 2539 | 2446 |
| 2540 return view; | 2447 return view; |
| 2541 } | 2448 } |
| 2542 #endif | 2449 #endif |
| 2543 | 2450 |
| 2544 // static | 2451 // static |
| 2545 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { | 2452 FindBar* BrowserWindow::CreateFindBar(Browser* browser) { |
| 2546 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); | 2453 return browser::CreateFindBar(static_cast<BrowserView*>(browser->window())); |
| 2547 } | 2454 } |
| OLD | NEW |