Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/ui/views/frame/browser_view.cc

Issue 10073014: Add more functionality to WebView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 void BrowserView::UserChangedTheme() { 1194 void BrowserView::UserChangedTheme() {
1194 frame_->FrameTypeChanged(); 1195 frame_->FrameTypeChanged();
1195 } 1196 }
1196 1197
1197 int BrowserView::GetExtraRenderViewHeight() const { 1198 int BrowserView::GetExtraRenderViewHeight() const {
1198 // Currently this is only used on linux. 1199 // Currently this is only used on linux.
1199 return 0; 1200 return 0;
1200 } 1201 }
1201 1202
1202 void BrowserView::WebContentsFocused(WebContents* contents) { 1203 void BrowserView::WebContentsFocused(WebContents* contents) {
1203 contents_container_->WebContentsFocused(contents); 1204 contents_container_->OnWebContentsFocused(contents);
1204 } 1205 }
1205 1206
1206 void BrowserView::ShowPageInfo(Profile* profile, 1207 void BrowserView::ShowPageInfo(Profile* profile,
1207 const GURL& url, 1208 const GURL& url,
1208 const SSLStatus& ssl, 1209 const SSLStatus& ssl,
1209 bool show_history) { 1210 bool show_history) {
1210 browser::ShowPageInfoBubble(GetLocationBarView()->location_icon_view(), 1211 browser::ShowPageInfoBubble(GetLocationBarView()->location_icon_view(),
1211 profile, url, ssl, show_history); 1212 profile, url, ssl, show_history);
1212 } 1213 }
1213 1214
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_C, 1307 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_C,
1307 true, false, false, false); 1308 true, false, false, false);
1308 } 1309 }
1309 1310
1310 void BrowserView::Paste() { 1311 void BrowserView::Paste() {
1311 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V, 1312 ui_controls::SendKeyPress(GetNativeHandle(), ui::VKEY_V,
1312 true, false, false, false); 1313 true, false, false, false);
1313 } 1314 }
1314 1315
1315 void BrowserView::ShowInstant(TabContentsWrapper* preview) { 1316 void BrowserView::ShowInstant(TabContentsWrapper* preview) {
1316 if (!preview_container_) 1317 if (!preview_container_) {
1317 preview_container_ = new TabContentsContainer(); 1318 preview_container_ = new views::WebView(browser_->profile());
1319 preview_container_->set_id(VIEW_ID_TAB_CONTAINER);
1320 }
1318 contents_->SetPreview(preview_container_, preview->web_contents()); 1321 contents_->SetPreview(preview_container_, preview->web_contents());
1319 preview_container_->ChangeWebContents(preview->web_contents()); 1322 preview_container_->SetWebContents(preview->web_contents());
1320 } 1323 }
1321 1324
1322 void BrowserView::HideInstant() { 1325 void BrowserView::HideInstant() {
1323 if (!preview_container_) 1326 if (!preview_container_)
1324 return; 1327 return;
1325 1328
1326 // The contents must be changed before SetPreview is invoked. 1329 // The contents must be changed before SetPreview is invoked.
1327 preview_container_->ChangeWebContents(NULL); 1330 preview_container_->SetWebContents(NULL);
1328 contents_->SetPreview(NULL, NULL); 1331 contents_->SetPreview(NULL, NULL);
1329 delete preview_container_; 1332 delete preview_container_;
1330 preview_container_ = NULL; 1333 preview_container_ = NULL;
1331 } 1334 }
1332 1335
1333 gfx::Rect BrowserView::GetInstantBounds() { 1336 gfx::Rect BrowserView::GetInstantBounds() {
1334 return contents_->GetPreviewBounds(); 1337 return contents_->GetPreviewBounds();
1335 } 1338 }
1336 1339
1337 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( 1340 WindowOpenDisposition BrowserView::GetDispositionForPopupBounds(
(...skipping 27 matching lines...) Expand all
1365 1368
1366 BookmarkBarView* BrowserView::GetBookmarkBarView() const { 1369 BookmarkBarView* BrowserView::GetBookmarkBarView() const {
1367 return bookmark_bar_view_.get(); 1370 return bookmark_bar_view_.get();
1368 } 1371 }
1369 1372
1370 LocationBarView* BrowserView::GetLocationBarView() const { 1373 LocationBarView* BrowserView::GetLocationBarView() const {
1371 return toolbar_ ? toolbar_->location_bar() : NULL; 1374 return toolbar_ ? toolbar_->location_bar() : NULL;
1372 } 1375 }
1373 1376
1374 views::View* BrowserView::GetTabContentsContainerView() const { 1377 views::View* BrowserView::GetTabContentsContainerView() const {
1375 return contents_container_->GetFocusView(); 1378 return contents_container_;
1376 } 1379 }
1377 1380
1378 ToolbarView* BrowserView::GetToolbarView() const { 1381 ToolbarView* BrowserView::GetToolbarView() const {
1379 return toolbar_; 1382 return toolbar_;
1380 } 1383 }
1381 1384
1382 /////////////////////////////////////////////////////////////////////////////// 1385 ///////////////////////////////////////////////////////////////////////////////
1383 // BrowserView, TabStripModelObserver implementation: 1386 // BrowserView, TabStripModelObserver implementation:
1384 1387
1385 void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { 1388 void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) {
1386 // We use index here rather than comparing |contents| because by this time 1389 // We use index here rather than comparing |contents| because by this time
1387 // the model has already removed |contents| from its list, so 1390 // the model has already removed |contents| from its list, so
1388 // browser_->GetSelectedWebContents() will return NULL or something else. 1391 // browser_->GetSelectedWebContents() will return NULL or something else.
1389 if (index == browser_->active_index()) { 1392 if (index == browser_->active_index()) {
1390 // We need to reset the current tab contents to NULL before it gets 1393 // We need to reset the current tab contents to NULL before it gets
1391 // freed. This is because the focus manager performs some operations 1394 // freed. This is because the focus manager performs some operations
1392 // on the selected TabContents when it is removed. 1395 // on the selected TabContents when it is removed.
1393 contents_container_->ChangeWebContents(NULL); 1396 contents_container_->SetWebContents(NULL);
1394 infobar_container_->ChangeTabContents(NULL); 1397 infobar_container_->ChangeTabContents(NULL);
1395 UpdateDevToolsForContents(NULL); 1398 UpdateDevToolsForContents(NULL);
1396 } 1399 }
1397 } 1400 }
1398 1401
1399 void BrowserView::TabDeactivated(TabContentsWrapper* contents) { 1402 void BrowserView::TabDeactivated(TabContentsWrapper* contents) {
1400 // We do not store the focus when closing the tab to work-around bug 4633. 1403 // We do not store the focus when closing the tab to work-around bug 4633.
1401 // Some reports seem to show that the focus manager and/or focused view can 1404 // Some reports seem to show that the focus manager and/or focused view can
1402 // be garbage at that point, it is not clear why. 1405 // be garbage at that point, it is not clear why.
1403 if (!contents->web_contents()->IsBeingDestroyed()) 1406 if (!contents->web_contents()->IsBeingDestroyed())
(...skipping 11 matching lines...) Expand all
1415 TabContentsWrapper* old_contents, 1418 TabContentsWrapper* old_contents,
1416 TabContentsWrapper* new_contents, 1419 TabContentsWrapper* new_contents,
1417 int index) { 1420 int index) {
1418 if (index != browser_->tabstrip_model()->active_index()) 1421 if (index != browser_->tabstrip_model()->active_index())
1419 return; 1422 return;
1420 1423
1421 if (contents_->preview_web_contents() == new_contents->web_contents()) { 1424 if (contents_->preview_web_contents() == new_contents->web_contents()) {
1422 // If 'preview' is becoming active, swap the 'active' and 'preview' and 1425 // If 'preview' is becoming active, swap the 'active' and 'preview' and
1423 // delete what was the active. 1426 // delete what was the active.
1424 contents_->MakePreviewContentsActiveContents(); 1427 contents_->MakePreviewContentsActiveContents();
1425 TabContentsContainer* old_container = contents_container_; 1428 views::WebView* old_container = contents_container_;
1426 contents_container_ = preview_container_; 1429 contents_container_ = preview_container_;
1427 old_container->ChangeWebContents(NULL); 1430 old_container->SetWebContents(NULL);
1428 delete old_container; 1431 delete old_container;
1429 preview_container_ = NULL; 1432 preview_container_ = NULL;
1430 } 1433 }
1431 // Update the UI for the new contents. 1434 // Update the UI for the new contents.
1432 ProcessTabSelected(new_contents); 1435 ProcessTabSelected(new_contents);
1433 } 1436 }
1434 1437
1435 void BrowserView::TabStripEmpty() { 1438 void BrowserView::TabStripEmpty() {
1436 // Make sure all optional UI is removed before we are destroyed, otherwise 1439 // Make sure all optional UI is removed before we are destroyed, otherwise
1437 // there will be consequences (since our view hierarchy will still have 1440 // there will be consequences (since our view hierarchy will still have
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 1896
1894 LoadAccelerators(); 1897 LoadAccelerators();
1895 1898
1896 InitTabStrip(browser_->tabstrip_model()); 1899 InitTabStrip(browser_->tabstrip_model());
1897 1900
1898 SetToolbar(CreateToolbar()); 1901 SetToolbar(CreateToolbar());
1899 1902
1900 infobar_container_ = new InfoBarContainerView(this); 1903 infobar_container_ = new InfoBarContainerView(this);
1901 AddChildView(infobar_container_); 1904 AddChildView(infobar_container_);
1902 1905
1903 contents_container_ = new TabContentsContainer; 1906 contents_container_ = new views::WebView(browser_->profile());
1907 contents_container_->set_id(VIEW_ID_TAB_CONTAINER);
1904 contents_ = new ContentsContainer(contents_container_); 1908 contents_ = new ContentsContainer(contents_container_);
1905 1909
1906 SkColor bg_color = GetWidget()->GetThemeProvider()-> 1910 SkColor bg_color = GetWidget()->GetThemeProvider()->
1907 GetColor(ThemeService::COLOR_TOOLBAR); 1911 GetColor(ThemeService::COLOR_TOOLBAR);
1908 1912
1909 devtools_container_ = new TabContentsContainer; 1913 devtools_container_ = new TabContentsContainer;
1910 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED); 1914 devtools_container_->set_id(VIEW_ID_DEV_TOOLS_DOCKED);
1911 devtools_container_->SetVisible(false); 1915 devtools_container_->SetVisible(false);
1912 1916
1913 views::View* contents_view = contents_; 1917 views::View* contents_view = contents_;
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
2407 bool change_tab_contents = 2411 bool change_tab_contents =
2408 contents_container_->web_contents() != new_contents->web_contents(); 2412 contents_container_->web_contents() != new_contents->web_contents();
2409 2413
2410 // Update various elements that are interested in knowing the current 2414 // Update various elements that are interested in knowing the current
2411 // TabContents. 2415 // TabContents.
2412 2416
2413 // When we toggle the NTP floating bookmarks bar and/or the info bar, 2417 // When we toggle the NTP floating bookmarks bar and/or the info bar,
2414 // we don't want any TabContents to be attached, so that we 2418 // we don't want any TabContents to be attached, so that we
2415 // avoid an unnecessary resize and re-layout of a TabContents. 2419 // avoid an unnecessary resize and re-layout of a TabContents.
2416 if (change_tab_contents) 2420 if (change_tab_contents)
2417 contents_container_->ChangeWebContents(NULL); 2421 contents_container_->SetWebContents(NULL);
2418 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); 2422 infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper());
2419 if (bookmark_bar_view_.get()) { 2423 if (bookmark_bar_view_.get()) {
2420 bookmark_bar_view_->SetBookmarkBarState( 2424 bookmark_bar_view_->SetBookmarkBarState(
2421 browser_->bookmark_bar_state(), 2425 browser_->bookmark_bar_state(),
2422 BookmarkBar::DONT_ANIMATE_STATE_CHANGE); 2426 BookmarkBar::DONT_ANIMATE_STATE_CHANGE);
2423 } 2427 }
2424 UpdateUIForContents(new_contents); 2428 UpdateUIForContents(new_contents);
2425 if (change_tab_contents) 2429 if (change_tab_contents)
2426 contents_container_->ChangeWebContents(new_contents->web_contents()); 2430 contents_container_->SetWebContents(new_contents->web_contents());
2427 2431
2428 UpdateDevToolsForContents(new_contents); 2432 UpdateDevToolsForContents(new_contents);
2429 // TODO(beng): This should be called automatically by ChangeWebContents, but I 2433 // TODO(beng): This should be called automatically by ChangeWebContents, but I
2430 // am striving for parity now rather than cleanliness. This is 2434 // am striving for parity now rather than cleanliness. This is
2431 // required to make features like Duplicate Tab, Undo Close Tab, 2435 // required to make features like Duplicate Tab, Undo Close Tab,
2432 // etc not result in sad tab. 2436 // etc not result in sad tab.
2433 new_contents->web_contents()->DidBecomeSelected(); 2437 new_contents->web_contents()->DidBecomeSelected();
2434 if (BrowserList::GetLastActive() == browser_ && 2438 if (BrowserList::GetLastActive() == browser_ &&
2435 !browser_->tabstrip_model()->closing_all() && GetWidget()->IsVisible()) { 2439 !browser_->tabstrip_model()->closing_all() && GetWidget()->IsVisible()) {
2436 // We only restore focus if our window is visible, to avoid invoking blur 2440 // 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
2511 return; 2515 return;
2512 2516
2513 PasswordGenerationBubbleView* bubble = 2517 PasswordGenerationBubbleView* bubble =
2514 new PasswordGenerationBubbleView(bounds, 2518 new PasswordGenerationBubbleView(bounds,
2515 this, 2519 this,
2516 web_contents->GetRenderViewHost()); 2520 web_contents->GetRenderViewHost());
2517 views::BubbleDelegateView::CreateBubble(bubble); 2521 views::BubbleDelegateView::CreateBubble(bubble);
2518 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); 2522 bubble->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE);
2519 bubble->Show(); 2523 bubble->Show();
2520 } 2524 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698