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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 #include "ui/base/accelerators/accelerator.h" | 86 #include "ui/base/accelerators/accelerator.h" |
87 #include "ui/base/accessibility/accessible_view_state.h" | 87 #include "ui/base/accessibility/accessible_view_state.h" |
88 #include "ui/base/hit_test.h" | 88 #include "ui/base/hit_test.h" |
89 #include "ui/base/l10n/l10n_util.h" | 89 #include "ui/base/l10n/l10n_util.h" |
90 #include "ui/base/resource/resource_bundle.h" | 90 #include "ui/base/resource/resource_bundle.h" |
91 #include "ui/gfx/canvas.h" | 91 #include "ui/gfx/canvas.h" |
92 #include "ui/gfx/color_utils.h" | 92 #include "ui/gfx/color_utils.h" |
93 #include "ui/gfx/sys_color_change_listener.h" | 93 #include "ui/gfx/sys_color_change_listener.h" |
94 #include "ui/ui_controls/ui_controls.h" | 94 #include "ui/ui_controls/ui_controls.h" |
95 #include "ui/views/controls/single_split_view.h" | 95 #include "ui/views/controls/single_split_view.h" |
| 96 #include "ui/views/controls/webview/webview.h" |
96 #include "ui/views/events/event.h" | 97 #include "ui/views/events/event.h" |
97 #include "ui/views/focus/external_focus_tracker.h" | 98 #include "ui/views/focus/external_focus_tracker.h" |
98 #include "ui/views/focus/view_storage.h" | 99 #include "ui/views/focus/view_storage.h" |
99 #include "ui/views/layout/grid_layout.h" | 100 #include "ui/views/layout/grid_layout.h" |
100 #include "ui/views/widget/native_widget.h" | 101 #include "ui/views/widget/native_widget.h" |
101 #include "ui/views/widget/root_view.h" | 102 #include "ui/views/widget/root_view.h" |
102 #include "ui/views/widget/widget.h" | 103 #include "ui/views/widget/widget.h" |
103 #include "ui/views/window/dialog_delegate.h" | 104 #include "ui/views/window/dialog_delegate.h" |
104 | 105 |
105 #if defined(USE_ASH) | 106 #if defined(USE_ASH) |
(...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1192 void BrowserView::UserChangedTheme() { | 1193 void BrowserView::UserChangedTheme() { |
1193 frame_->FrameTypeChanged(); | 1194 frame_->FrameTypeChanged(); |
1194 } | 1195 } |
1195 | 1196 |
1196 int BrowserView::GetExtraRenderViewHeight() const { | 1197 int BrowserView::GetExtraRenderViewHeight() const { |
1197 // Currently this is only used on linux. | 1198 // Currently this is only used on linux. |
1198 return 0; | 1199 return 0; |
1199 } | 1200 } |
1200 | 1201 |
1201 void BrowserView::WebContentsFocused(WebContents* contents) { | 1202 void BrowserView::WebContentsFocused(WebContents* contents) { |
1202 contents_container_->WebContentsFocused(contents); | 1203 contents_container_->OnWebContentsFocused(contents); |
1203 } | 1204 } |
1204 | 1205 |
1205 void BrowserView::ShowPageInfo(Profile* profile, | 1206 void BrowserView::ShowPageInfo(Profile* profile, |
1206 const GURL& url, | 1207 const GURL& url, |
1207 const SSLStatus& ssl, | 1208 const SSLStatus& ssl, |
1208 bool show_history) { | 1209 bool show_history) { |
1209 browser::ShowPageInfoBubble(GetLocationBarView()->location_icon_view(), | 1210 browser::ShowPageInfoBubble(GetLocationBarView()->location_icon_view(), |
1210 profile, url, ssl, show_history); | 1211 profile, url, ssl, show_history); |
1211 } | 1212 } |
1212 | 1213 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 true, false, false, false); | 1307 true, false, false, false); |
1307 } | 1308 } |
1308 | 1309 |
1309 void BrowserView::Paste() { | 1310 void BrowserView::Paste() { |
1310 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V, | 1311 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V, |
1311 true, false, false, false); | 1312 true, false, false, false); |
1312 } | 1313 } |
1313 | 1314 |
1314 void BrowserView::ShowInstant(TabContentsWrapper* preview) { | 1315 void BrowserView::ShowInstant(TabContentsWrapper* preview) { |
1315 if (!preview_container_) | 1316 if (!preview_container_) |
1316 preview_container_ = new TabContentsContainer(); | 1317 preview_container_ = new views::WebView(browser_->profile()); |
1317 contents_->SetPreview(preview_container_, preview->web_contents()); | 1318 contents_->SetPreview(preview_container_, preview->web_contents()); |
1318 preview_container_->ChangeWebContents(preview->web_contents()); | 1319 preview_container_->SetWebContents(preview->web_contents()); |
1319 } | 1320 } |
1320 | 1321 |
1321 void BrowserView::HideInstant() { | 1322 void BrowserView::HideInstant() { |
1322 if (!preview_container_) | 1323 if (!preview_container_) |
1323 return; | 1324 return; |
1324 | 1325 |
1325 // The contents must be changed before SetPreview is invoked. | 1326 // The contents must be changed before SetPreview is invoked. |
1326 preview_container_->ChangeWebContents(NULL); | 1327 preview_container_->SetWebContents(NULL); |
1327 contents_->SetPreview(NULL, NULL); | 1328 contents_->SetPreview(NULL, NULL); |
1328 delete preview_container_; | 1329 delete preview_container_; |
1329 preview_container_ = NULL; | 1330 preview_container_ = NULL; |
1330 } | 1331 } |
1331 | 1332 |
1332 gfx::Rect BrowserView::GetInstantBounds() { | 1333 gfx::Rect BrowserView::GetInstantBounds() { |
1333 return contents_->GetPreviewBounds(); | 1334 return contents_->GetPreviewBounds(); |
1334 } | 1335 } |
1335 | 1336 |
1336 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( | 1337 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( |
(...skipping 27 matching lines...) Expand all Loading... |
1364 | 1365 |
1365 BookmarkBarView* BrowserView::GetBookmarkBarView() const { | 1366 BookmarkBarView* BrowserView::GetBookmarkBarView() const { |
1366 return bookmark_bar_view_.get(); | 1367 return bookmark_bar_view_.get(); |
1367 } | 1368 } |
1368 | 1369 |
1369 LocationBarView* BrowserView::GetLocationBarView() const { | 1370 LocationBarView* BrowserView::GetLocationBarView() const { |
1370 return toolbar_ ? toolbar_->location_bar() : NULL; | 1371 return toolbar_ ? toolbar_->location_bar() : NULL; |
1371 } | 1372 } |
1372 | 1373 |
1373 views::View* BrowserView::GetTabContentsContainerView() const { | 1374 views::View* BrowserView::GetTabContentsContainerView() const { |
1374 return contents_container_->GetFocusView(); | 1375 return contents_container_; |
1375 } | 1376 } |
1376 | 1377 |
1377 ToolbarView* BrowserView::GetToolbarView() const { | 1378 ToolbarView* BrowserView::GetToolbarView() const { |
1378 return toolbar_; | 1379 return toolbar_; |
1379 } | 1380 } |
1380 | 1381 |
1381 /////////////////////////////////////////////////////////////////////////////// | 1382 /////////////////////////////////////////////////////////////////////////////// |
1382 // BrowserView, TabStripModelObserver implementation: | 1383 // BrowserView, TabStripModelObserver implementation: |
1383 | 1384 |
1384 void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { | 1385 void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { |
1385 // We use index here rather than comparing |contents| because by this time | 1386 // We use index here rather than comparing |contents| because by this time |
1386 // the model has already removed |contents| from its list, so | 1387 // the model has already removed |contents| from its list, so |
1387 // browser_->GetSelectedWebContents() will return NULL or something else. | 1388 // browser_->GetSelectedWebContents() will return NULL or something else. |
1388 if (index == browser_->active_index()) { | 1389 if (index == browser_->active_index()) { |
1389 // We need to reset the current tab contents to NULL before it gets | 1390 // We need to reset the current tab contents to NULL before it gets |
1390 // freed. This is because the focus manager performs some operations | 1391 // freed. This is because the focus manager performs some operations |
1391 // on the selected TabContents when it is removed. | 1392 // on the selected TabContents when it is removed. |
1392 contents_container_->ChangeWebContents(NULL); | 1393 contents_container_->SetWebContents(NULL); |
1393 infobar_container_->ChangeTabContents(NULL); | 1394 infobar_container_->ChangeTabContents(NULL); |
1394 UpdateDevToolsForContents(NULL); | 1395 UpdateDevToolsForContents(NULL); |
1395 } | 1396 } |
1396 } | 1397 } |
1397 | 1398 |
1398 void BrowserView::TabDeactivated(TabContentsWrapper* contents) { | 1399 void BrowserView::TabDeactivated(TabContentsWrapper* contents) { |
1399 // We do not store the focus when closing the tab to work-around bug 4633. | 1400 // We do not store the focus when closing the tab to work-around bug 4633. |
1400 // Some reports seem to show that the focus manager and/or focused view can | 1401 // Some reports seem to show that the focus manager and/or focused view can |
1401 // be garbage at that point, it is not clear why. | 1402 // be garbage at that point, it is not clear why. |
1402 if (!contents->web_contents()->IsBeingDestroyed()) | 1403 if (!contents->web_contents()->IsBeingDestroyed()) |
(...skipping 11 matching lines...) Expand all Loading... |
1414 TabContentsWrapper* old_contents, | 1415 TabContentsWrapper* old_contents, |
1415 TabContentsWrapper* new_contents, | 1416 TabContentsWrapper* new_contents, |
1416 int index) { | 1417 int index) { |
1417 if (index != browser_->tabstrip_model()->active_index()) | 1418 if (index != browser_->tabstrip_model()->active_index()) |
1418 return; | 1419 return; |
1419 | 1420 |
1420 if (contents_->preview_web_contents() == new_contents->web_contents()) { | 1421 if (contents_->preview_web_contents() == new_contents->web_contents()) { |
1421 // If 'preview' is becoming active, swap the 'active' and 'preview' and | 1422 // If 'preview' is becoming active, swap the 'active' and 'preview' and |
1422 // delete what was the active. | 1423 // delete what was the active. |
1423 contents_->MakePreviewContentsActiveContents(); | 1424 contents_->MakePreviewContentsActiveContents(); |
1424 TabContentsContainer* old_container = contents_container_; | 1425 views::WebView* old_container = contents_container_; |
1425 contents_container_ = preview_container_; | 1426 contents_container_ = preview_container_; |
1426 old_container->ChangeWebContents(NULL); | 1427 old_container->SetWebContents(NULL); |
1427 delete old_container; | 1428 delete old_container; |
1428 preview_container_ = NULL; | 1429 preview_container_ = NULL; |
1429 } | 1430 } |
1430 // Update the UI for the new contents. | 1431 // Update the UI for the new contents. |
1431 ProcessTabSelected(new_contents); | 1432 ProcessTabSelected(new_contents); |
1432 } | 1433 } |
1433 | 1434 |
1434 void BrowserView::TabStripEmpty() { | 1435 void BrowserView::TabStripEmpty() { |
1435 // Make sure all optional UI is removed before we are destroyed, otherwise | 1436 // Make sure all optional UI is removed before we are destroyed, otherwise |
1436 // there will be consequences (since our view hierarchy will still have | 1437 // there will be consequences (since our view hierarchy will still have |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 | 1882 |
1882 LoadAccelerators(); | 1883 LoadAccelerators(); |
1883 | 1884 |
1884 InitTabStrip(browser_->tabstrip_model()); | 1885 InitTabStrip(browser_->tabstrip_model()); |
1885 | 1886 |
1886 SetToolbar(CreateToolbar()); | 1887 SetToolbar(CreateToolbar()); |
1887 | 1888 |
1888 infobar_container_ = new InfoBarContainerView(this); | 1889 infobar_container_ = new InfoBarContainerView(this); |
1889 AddChildView(infobar_container_); | 1890 AddChildView(infobar_container_); |
1890 | 1891 |
1891 contents_container_ = new TabContentsContainer; | 1892 contents_container_ = new views::WebView(browser_->profile()); |
1892 contents_ = new ContentsContainer(contents_container_); | 1893 contents_ = new ContentsContainer(contents_container_); |
1893 | 1894 |
1894 SkColor bg_color = GetWidget()->GetThemeProvider()-> | 1895 SkColor bg_color = GetWidget()->GetThemeProvider()-> |
1895 GetColor(ThemeService::COLOR_TOOLBAR); | 1896 GetColor(ThemeService::COLOR_TOOLBAR); |
1896 | 1897 |
1897 devtools_container_ = new TabContentsContainer; | 1898 devtools_container_ = new TabContentsContainer; |
1898 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); | 1899 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); |
1899 devtools_container_->SetVisible(false); | 1900 devtools_container_->SetVisible(false); |
1900 | 1901 |
1901 views::View* contents_view = contents_; | 1902 views::View* contents_view = contents_; |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2395 bool change_tab_contents = | 2396 bool change_tab_contents = |
2396 contents_container_->web_contents() != new_contents->web_contents(); | 2397 contents_container_->web_contents() != new_contents->web_contents(); |
2397 | 2398 |
2398 // Update various elements that are interested in knowing the current | 2399 // Update various elements that are interested in knowing the current |
2399 // TabContents. | 2400 // TabContents. |
2400 | 2401 |
2401 // When we toggle the NTP floating bookmarks bar and/or the info bar, | 2402 // When we toggle the NTP floating bookmarks bar and/or the info bar, |
2402 // we don't want any TabContents to be attached, so that we | 2403 // we don't want any TabContents to be attached, so that we |
2403 // avoid an unnecessary resize and re-layout of a TabContents. | 2404 // avoid an unnecessary resize and re-layout of a TabContents. |
2404 if (change_tab_contents) | 2405 if (change_tab_contents) |
2405 contents_container_->ChangeWebContents(NULL); | 2406 contents_container_->SetWebContents(NULL); |
2406 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); | 2407 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); |
2407 if (bookmark_bar_view_.get()) { | 2408 if (bookmark_bar_view_.get()) { |
2408 bookmark_bar_view_->SetBookmarkBarState( | 2409 bookmark_bar_view_->SetBookmarkBarState( |
2409 browser_->bookmark_bar_state(), | 2410 browser_->bookmark_bar_state(), |
2410 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); | 2411 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); |
2411 } | 2412 } |
2412 UpdateUIForContents(new_contents); | 2413 UpdateUIForContents(new_contents); |
2413 if (change_tab_contents) | 2414 if (change_tab_contents) |
2414 contents_container_->ChangeWebContents(new_contents->web_contents()); | 2415 contents_container_->SetWebContents(new_contents->web_contents()); |
2415 | 2416 |
2416 UpdateDevToolsForContents(new_contents); | 2417 UpdateDevToolsForContents(new_contents); |
2417 // TODO(beng): This should be called automatically by ChangeWebContents, but I | 2418 // TODO(beng): This should be called automatically by ChangeWebContents, but I |
2418 // am striving for parity now rather than cleanliness. This is | 2419 // am striving for parity now rather than cleanliness. This is |
2419 // required to make features like Duplicate Tab, Undo Close Tab, | 2420 // required to make features like Duplicate Tab, Undo Close Tab, |
2420 // etc not result in sad tab. | 2421 // etc not result in sad tab. |
2421 new_contents->web_contents()->DidBecomeSelected(); | 2422 new_contents->web_contents()->DidBecomeSelected(); |
2422 if (BrowserList::GetLastActive() == browser_ && | 2423 if (BrowserList::GetLastActive() == browser_ && |
2423 !browser_->tabstrip_model()->closing_all() && GetWidget()->IsVisible()) { | 2424 !browser_->tabstrip_model()->closing_all() && GetWidget()->IsVisible()) { |
2424 // We only restore focus if our window is visible, to avoid invoking blur | 2425 // We only restore focus if our window is visible, to avoid invoking blur |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2499 return; | 2500 return; |
2500 | 2501 |
2501 PasswordGenerationBubbleView* bubble = | 2502 PasswordGenerationBubbleView* bubble = |
2502 new PasswordGenerationBubbleView(bounds, | 2503 new PasswordGenerationBubbleView(bounds, |
2503 this, | 2504 this, |
2504 web_contents->GetRenderViewHost()); | 2505 web_contents->GetRenderViewHost()); |
2505 views::BubbleDelegateView::CreateBubble(bubble); | 2506 views::BubbleDelegateView::CreateBubble(bubble); |
2506 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 2507 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
2507 bubble->Show(); | 2508 bubble->Show(); |
2508 } | 2509 } |
OLD | NEW |