Commit 2bed8faa authored by ben@chromium.org's avatar ben@chromium.org

Revert 132281 - Add more functionality to WebView.

- Ability for WebContents to be replaced.
- Various focus/destruction observers.
- Hook up to BrowserView, replacing TabContentsContainer.

BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10073014

TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10086026

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132306 0039d316-1c4b-4281-b951-d872f2087c98
parent a3f773fb
...@@ -190,7 +190,7 @@ class AutofillTest : public InProcessBrowserTest { ...@@ -190,7 +190,7 @@ class AutofillTest : public InProcessBrowserTest {
ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(),
VIEW_ID_TAB_CONTAINER)); VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_TAB_CONTAINER)); VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
LOG(WARNING) << "Focusing the first name field."; LOG(WARNING) << "Focusing the first name field.";
bool result = false; bool result = false;
......
...@@ -236,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { ...@@ -236,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) {
ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
ClickOnView(VIEW_ID_TAB_CONTAINER); ClickOnView(VIEW_ID_TAB_CONTAINER);
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
ClickOnView(VIEW_ID_LOCATION_BAR); ClickOnView(VIEW_ID_LOCATION_BAR);
ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
...@@ -254,11 +254,11 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { ...@@ -254,11 +254,11 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) {
gfx::NativeWindow window = browser()->window()->GetNativeHandle(); gfx::NativeWindow window = browser()->window()->GetNativeHandle();
// The focus should be on the Tab contents. // The focus should be on the Tab contents.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Now hide the window, show it again, the focus should not have changed. // Now hide the window, show it again, the focus should not have changed.
ui_test_utils::HideNativeWindow(window); ui_test_utils::HideNativeWindow(window);
ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
browser()->FocusLocationBar(); browser()->FocusLocationBar();
ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
...@@ -347,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { ...@@ -347,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) {
// Activate the tab. // Activate the tab.
browser()->ActivateTabAt(j, true); browser()->ActivateTabAt(j, true);
ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
location_bar_focus_view_id_; location_bar_focus_view_id_;
ASSERT_TRUE(IsViewFocused(vid)); ASSERT_TRUE(IsViewFocused(vid));
} }
...@@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { ...@@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) {
// Try the above, but with ctrl+tab. Since tab normally changes focus, // Try the above, but with ctrl+tab. Since tab normally changes focus,
// this has regressed in the past. Loop through several times to be sure. // this has regressed in the past. Loop through several times to be sure.
for (int j = 0; j < 15; j++) { for (int j = 0; j < 15; j++) {
ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
location_bar_focus_view_id_; location_bar_focus_view_id_;
ASSERT_TRUE(IsViewFocused(vid)); ASSERT_TRUE(IsViewFocused(vid));
...@@ -367,7 +367,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { ...@@ -367,7 +367,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) {
// As above, but with ctrl+shift+tab. // As above, but with ctrl+shift+tab.
browser()->ActivateTabAt(4, true); browser()->ActivateTabAt(4, true);
for (int j = 14; j >= 0; --j) { for (int j = 14; j >= 0; --j) {
ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW :
location_bar_focus_view_id_; location_bar_focus_view_id_;
ASSERT_TRUE(IsViewFocused(vid)); ASSERT_TRUE(IsViewFocused(vid));
...@@ -398,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { ...@@ -398,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) {
browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED);
// Focus should be on the recently opened tab page. // Focus should be on the recently opened tab page.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Select 1st tab, focus should still be on the location-bar. // Select 1st tab, focus should still be on the location-bar.
// (bug http://crbug.com/23296) // (bug http://crbug.com/23296)
...@@ -410,7 +410,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { ...@@ -410,7 +410,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) {
browser()->Find(); browser()->Find();
ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
browser()->ActivateTabAt(1, true); browser()->ActivateTabAt(1, true);
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
browser()->ActivateTabAt(0, true); browser()->ActivateTabAt(0, true);
ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
} }
...@@ -620,7 +620,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { ...@@ -620,7 +620,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
// Focus should be on the page. // Focus should be on the page.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Let's show an interstitial. // Let's show an interstitial.
TestInterstitialPage* interstitial_page = TestInterstitialPage* interstitial_page =
...@@ -743,7 +743,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { ...@@ -743,7 +743,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
// Page should have focus. // Page should have focus.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()-> EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()->
GetView()->HasFocus()); GetView()->HasFocus());
...@@ -758,14 +758,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { ...@@ -758,14 +758,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) {
ui_test_utils::RunMessageLoop(); ui_test_utils::RunMessageLoop();
// The interstitial should have focus now. // The interstitial should have focus now.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
EXPECT_TRUE(interstitial_page->HasFocus()); EXPECT_TRUE(interstitial_page->HasFocus());
// Hide the interstitial. // Hide the interstitial.
interstitial_page->DontProceed(); interstitial_page->DontProceed();
// Focus should be back on the original page. // Focus should be back on the original page.
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
} }
// Make sure Find box can request focus, even when it is already open. // Make sure Find box can request focus, even when it is already open.
...@@ -812,7 +812,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { ...@@ -812,7 +812,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) {
// Set focus to the page. // Set focus to the page.
ClickOnView(VIEW_ID_TAB_CONTAINER); ClickOnView(VIEW_ID_TAB_CONTAINER);
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Now press Ctrl+F again and focus should move to the Find box. // Now press Ctrl+F again and focus should move to the Find box.
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -836,7 +836,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { ...@@ -836,7 +836,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) {
browser()->ShowHistoryTab(); browser()->ShowHistoryTab();
ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
browser()->GetSelectedWebContents())); browser()->GetSelectedWebContents()));
EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Open the new tab, focus should be on the location bar. // Open the new tab, focus should be on the location bar.
browser()->NewTab(); browser()->NewTab();
...@@ -848,7 +848,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { ...@@ -848,7 +848,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) {
browser()->ShowDownloadsTab(); browser()->ShowDownloadsTab();
ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop(
browser()->GetSelectedWebContents())); browser()->GetSelectedWebContents()));
EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Open about:blank, focus should be on the location bar. // Open about:blank, focus should be on the location bar.
browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL),
...@@ -901,7 +901,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { ...@@ -901,7 +901,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) {
// Focus should now be on the tab contents. // Focus should now be on the tab contents.
browser()->ShowDownloadsTab(); browser()->ShowDownloadsTab();
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
} }
// Tests that focus goes where expected when using reload on a crashed tab. // Tests that focus goes where expected when using reload on a crashed tab.
...@@ -924,7 +924,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) { ...@@ -924,7 +924,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_FocusOnReloadCrashedTab) {
// Focus should now be on the tab contents. // Focus should now be on the tab contents.
browser()->ShowDownloadsTab(); browser()->ShowDownloadsTab();
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
} }
} // namespace } // namespace
...@@ -364,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) { ...@@ -364,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { for (size_t i = 0; i < arraysize(kTestNoInput); ++i) {
...@@ -449,7 +449,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { ...@@ -449,7 +449,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
// Press Ctrl+F, which will make the Find box open and request focus. // Press Ctrl+F, which will make the Find box open and request focus.
...@@ -459,11 +459,11 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { ...@@ -459,11 +459,11 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) {
// Press Escape to close the Find box and move the focus back to the web page. // Press Escape to close the Find box and move the focus back to the web page.
ASSERT_TRUE(ui_test_utils::SendKeyPressSync( ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_ESCAPE, false, false, false, false)); browser(), ui::VKEY_ESCAPE, false, false, false, false));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Press Ctrl+F with keydown suppressed shall not open the find box. // Press Ctrl+F with keydown suppressed shall not open the find box.
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ));
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown));
...@@ -495,7 +495,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_CommandKeyEvents) { ...@@ -495,7 +495,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_CommandKeyEvents) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
// Press Cmd+F, which will make the Find box open and request focus. // Press Cmd+F, which will make the Find box open and request focus.
...@@ -505,11 +505,11 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_CommandKeyEvents) { ...@@ -505,11 +505,11 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_CommandKeyEvents) {
// Press Escape to close the Find box and move the focus back to the web page. // Press Escape to close the Find box and move the focus back to the web page.
ASSERT_TRUE(ui_test_utils::SendKeyPressSync( ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
browser(), ui::VKEY_ESCAPE, false, false, false, false)); browser(), ui::VKEY_ESCAPE, false, false, false, false));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Press Cmd+F with keydown suppressed shall not open the find box. // Press Cmd+F with keydown suppressed shall not open the find box.
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdFSuppressKeyDown)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdFSuppressKeyDown));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
} }
#endif #endif
...@@ -597,7 +597,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { ...@@ -597,7 +597,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) {
ui_test_utils::RunAllPendingInMessageLoop(); ui_test_utils::RunAllPendingInMessageLoop();
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
// Make sure no element is focused. // Make sure no element is focused.
...@@ -628,7 +628,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { ...@@ -628,7 +628,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) {
// Move the focus back to the web page. // Move the focus back to the web page.
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Make sure no element is focused. // Make sure no element is focused.
EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L""));
...@@ -639,7 +639,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { ...@@ -639,7 +639,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) {
// a part of the default action of the key event, so it should not be // a part of the default action of the key event, so it should not be
// suppressed at all. // suppressed at all.
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D"));
// Blur the focused element. // Blur the focused element.
...@@ -670,7 +670,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { ...@@ -670,7 +670,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
ASSERT_EQ(1, browser()->tab_count()); ASSERT_EQ(1, browser()->tab_count());
...@@ -708,7 +708,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { ...@@ -708,7 +708,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) {
// Make sure the focus is in the testing page. // Make sure the focus is in the testing page.
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Reserved accelerators can't be suppressed. // Reserved accelerators can't be suppressed.
ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true));
...@@ -768,7 +768,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) { ...@@ -768,7 +768,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
...@@ -805,7 +805,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { ...@@ -805,7 +805,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A"));
...@@ -847,7 +847,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { ...@@ -847,7 +847,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
int tab_index = browser()->active_index(); int tab_index = browser()->active_index();
// Press and release Alt key to focus wrench menu button. // Press and release Alt key to focus wrench menu button.
...@@ -855,15 +855,15 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { ...@@ -855,15 +855,15 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) {
EXPECT_TRUE(IsViewFocused(VIEW_ID_APP_MENU)); EXPECT_TRUE(IsViewFocused(VIEW_ID_APP_MENU));
ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Alt key can be suppressed. // Alt key can be suppressed.
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Ctrl+Alt should have no effect. // Ctrl+Alt should have no effect.
EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
} }
#endif #endif
......
...@@ -1220,7 +1220,8 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, ...@@ -1220,7 +1220,8 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
EXPECT_EQ(1, browser()->active_index()); EXPECT_EQ(1, browser()->active_index());
// The tab contents should have the focus in the second tab. // The tab contents should have the focus in the second tab.
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Go back to the first tab. The focus should not be in the omnibox. // Go back to the first tab. The focus should not be in the omnibox.
browser()->SelectPreviousTab(); browser()->SelectPreviousTab();
......
...@@ -135,7 +135,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { ...@@ -135,7 +135,8 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) {
ASCIIToUTF16("a"), true, false, NULL); ASCIIToUTF16("a"), true, false, NULL);
browser()->GetFindBarController()->EndFindSession( browser()->GetFindBarController()->EndFindSession(
FindBarController::kKeepSelection); FindBarController::kKeepSelection);
EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Focus the location bar, open and close the find box, focus should return to // Focus the location bar, open and close the find box, focus should return to
// the location bar (same as before, just checking that http://crbug.com/23599 // the location bar (same as before, just checking that http://crbug.com/23599
......
...@@ -93,7 +93,6 @@ ...@@ -93,7 +93,6 @@
#include "ui/gfx/sys_color_change_listener.h" #include "ui/gfx/sys_color_change_listener.h"
#include "ui/ui_controls/ui_controls.h" #include "ui/ui_controls/ui_controls.h"
#include "ui/views/controls/single_split_view.h" #include "ui/views/controls/single_split_view.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/events/event.h" #include "ui/views/events/event.h"
#include "ui/views/focus/external_focus_tracker.h" #include "ui/views/focus/external_focus_tracker.h"
#include "ui/views/focus/view_storage.h" #include "ui/views/focus/view_storage.h"
...@@ -1201,7 +1200,7 @@ int BrowserView::GetExtraRenderViewHeight() const { ...@@ -1201,7 +1200,7 @@ int BrowserView::GetExtraRenderViewHeight() const {
} }
void BrowserView::WebContentsFocused(WebContents* contents) { void BrowserView::WebContentsFocused(WebContents* contents) {
contents_container_->OnWebContentsFocused(contents); contents_container_->WebContentsFocused(contents);
} }
void BrowserView::ShowPageInfo(Profile* profile, void BrowserView::ShowPageInfo(Profile* profile,
...@@ -1314,12 +1313,10 @@ void BrowserView::Paste() { ...@@ -1314,12 +1313,10 @@ void BrowserView::Paste() {
} }
void BrowserView::ShowInstant(TabContentsWrapper* preview) { void BrowserView::ShowInstant(TabContentsWrapper* preview) {
if (!preview_container_) { if (!preview_container_)
preview_container_ = new views::WebView(browser_->profile()); preview_container_ = new TabContentsContainer();
preview_container_->set_id(VIEW_ID_TAB_CONTAINER);
}
contents_->SetPreview(preview_container_, preview->web_contents()); contents_->SetPreview(preview_container_, preview->web_contents());
preview_container_->SetWebContents(preview->web_contents()); preview_container_->ChangeWebContents(preview->web_contents());
} }
void BrowserView::HideInstant() { void BrowserView::HideInstant() {
...@@ -1327,7 +1324,7 @@ void BrowserView::HideInstant() { ...@@ -1327,7 +1324,7 @@ void BrowserView::HideInstant() {
return; return;
// The contents must be changed before SetPreview is invoked. // The contents must be changed before SetPreview is invoked.
preview_container_->SetWebContents(NULL); preview_container_->ChangeWebContents(NULL);
contents_->SetPreview(NULL, NULL); contents_->SetPreview(NULL, NULL);
delete preview_container_; delete preview_container_;
preview_container_ = NULL; preview_container_ = NULL;
...@@ -1375,7 +1372,7 @@ LocationBarView* BrowserView::GetLocationBarView() const { ...@@ -1375,7 +1372,7 @@ LocationBarView* BrowserView::GetLocationBarView() const {
} }
views::View* BrowserView::GetTabContentsContainerView() const { views::View* BrowserView::GetTabContentsContainerView() const {
return contents_container_; return contents_container_->GetFocusView();
} }
ToolbarView* BrowserView::GetToolbarView() const { ToolbarView* BrowserView::GetToolbarView() const {
...@@ -1393,7 +1390,7 @@ void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { ...@@ -1393,7 +1390,7 @@ void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) {
// We need to reset the current tab contents to NULL before it gets // We need to reset the current tab contents to NULL before it gets
// freed. This is because the focus manager performs some operations // freed. This is because the focus manager performs some operations
// on the selected TabContents when it is removed. // on the selected TabContents when it is removed.
contents_container_->SetWebContents(NULL); contents_container_->ChangeWebContents(NULL);
infobar_container_->ChangeTabContents(NULL); infobar_container_->ChangeTabContents(NULL);
UpdateDevToolsForContents(NULL); UpdateDevToolsForContents(NULL);
} }
...@@ -1425,9 +1422,9 @@ void BrowserView::TabReplacedAt(TabStripModel* tab_strip_model, ...@@ -1425,9 +1422,9 @@ void BrowserView::TabReplacedAt(TabStripModel* tab_strip_model,
// If 'preview' is becoming active, swap the 'active' and 'preview' and // If 'preview' is becoming active, swap the 'active' and 'preview' and
// delete what was the active. // delete what was the active.
contents_->MakePreviewContentsActiveContents(); contents_->MakePreviewContentsActiveContents();
views::WebView* old_container = contents_container_; TabContentsContainer* old_container = contents_container_;
contents_container_ = preview_container_; contents_container_ = preview_container_;
old_container->SetWebContents(NULL); old_container->ChangeWebContents(NULL);
delete old_container; delete old_container;
preview_container_ = NULL; preview_container_ = NULL;
} }
...@@ -1903,8 +1900,7 @@ void BrowserView::Init() { ...@@ -1903,8 +1900,7 @@ void BrowserView::Init() {
infobar_container_ = new InfoBarContainerView(this); infobar_container_ = new InfoBarContainerView(this);
AddChildView(infobar_container_); AddChildView(infobar_container_);
contents_container_ = new views::WebView(browser_->profile()); contents_container_ = new TabContentsContainer;
contents_container_->set_id(VIEW_ID_TAB_CONTAINER);
contents_ = new ContentsContainer(contents_container_); contents_ = new ContentsContainer(contents_container_);
SkColor bg_color = GetWidget()->GetThemeProvider()-> SkColor bg_color = GetWidget()->GetThemeProvider()->
...@@ -2418,7 +2414,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) { ...@@ -2418,7 +2414,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) {
// we don't want any TabContents to be attached, so that we // we don't want any TabContents to be attached, so that we
// avoid an unnecessary resize and re-layout of a TabContents. // avoid an unnecessary resize and re-layout of a TabContents.
if (change_tab_contents) if (change_tab_contents)
contents_container_->SetWebContents(NULL); contents_container_->ChangeWebContents(NULL);
infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper());
if (bookmark_bar_view_.get()) { if (bookmark_bar_view_.get()) {
bookmark_bar_view_->SetBookmarkBarState( bookmark_bar_view_->SetBookmarkBarState(
...@@ -2427,7 +2423,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) { ...@@ -2427,7 +2423,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) {
} }
UpdateUIForContents(new_contents); UpdateUIForContents(new_contents);
if (change_tab_contents) if (change_tab_contents)
contents_container_->SetWebContents(new_contents->web_contents()); contents_container_->ChangeWebContents(new_contents->web_contents());
UpdateDevToolsForContents(new_contents); UpdateDevToolsForContents(new_contents);
// TODO(beng): This should be called automatically by ChangeWebContents, but I // TODO(beng): This should be called automatically by ChangeWebContents, but I
......
...@@ -67,7 +67,6 @@ namespace views { ...@@ -67,7 +67,6 @@ namespace views {
class AccessiblePaneView; class AccessiblePaneView;
class ExternalFocusTracker; class ExternalFocusTracker;
class Menu; class Menu;
class WebView;
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -614,13 +613,13 @@ class BrowserView : public BrowserWindow, ...@@ -614,13 +613,13 @@ class BrowserView : public BrowserWindow,
InfoBarContainerView* infobar_container_; InfoBarContainerView* infobar_container_;
// The view that contains the selected TabContents. // The view that contains the selected TabContents.
views::WebView* contents_container_; TabContentsContainer* contents_container_;
// The view that contains devtools window for the selected TabContents. // The view that contains devtools window for the selected TabContents.
TabContentsContainer* devtools_container_; TabContentsContainer* devtools_container_;
// The view that contains instant's TabContents. // The view that contains instant's TabContents.
views::WebView* preview_container_; TabContentsContainer* preview_container_;
// The view managing both the contents_container_ and preview_container_. // The view managing both the contents_container_ and preview_container_.
ContentsContainer* contents_; ContentsContainer* contents_;
......
...@@ -5,17 +5,8 @@ ...@@ -5,17 +5,8 @@
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "ipc/ipc_message.h" #include "ipc/ipc_message.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
#include "ui/views/focus/focus_manager.h"
namespace views { namespace views {
...@@ -24,49 +15,21 @@ namespace views { ...@@ -24,49 +15,21 @@ namespace views {
WebView::WebView(content::BrowserContext* browser_context) WebView::WebView(content::BrowserContext* browser_context)
: wcv_holder_(new NativeViewHost), : wcv_holder_(new NativeViewHost),
web_contents_(NULL),
browser_context_(browser_context) { browser_context_(browser_context) {
AddChildView(wcv_holder_); Init();
} }
WebView::~WebView() { WebView::~WebView() {
} }
content::WebContents* WebView::GetWebContents() { ////////////////////////////////////////////////////////////////////////////////
if (!web_contents_) { // WebView, private:
wc_owner_.reset(content::WebContents::Create(browser_context_,
NULL,
MSG_ROUTING_NONE,
NULL,
NULL));
web_contents_ = wc_owner_.get();
web_contents_->SetDelegate(this);
AttachWebContents();
}
return web_contents_;
}
void WebView::SetWebContents(content::WebContents* web_contents) {
if (web_contents == web_contents_)
return;
DetachWebContents();
wc_owner_.reset();
web_contents_ = web_contents;
AttachWebContents();
}
void WebView::SetFastResize(bool fast_resize) {
wcv_holder_->set_fast_resize(fast_resize);
}
void WebView::OnWebContentsFocused(content::WebContents* web_contents) { void WebView::Init() {
DCHECK(web_contents == web_contents_); AddChildView(wcv_holder_);
FocusManager* focus_manager = GetFocusManager(); web_contents_.reset(
if (!focus_manager) { content::WebContents::Create(browser_context_, NULL, MSG_ROUTING_NONE,
NOTREACHED(); NULL, NULL));
return;
}
focus_manager->SetFocusedView(this);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -77,128 +40,8 @@ void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -77,128 +40,8 @@ void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
} }
void WebView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { void WebView::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
if (is_add) if (is_add && child == this)
AttachWebContents();
}
bool WebView::SkipDefaultKeyEventProcessing(const views::KeyEvent& event) {
// Don't look-up accelerators or tab-traversal if we are showing a non-crashed
// TabContents.
// We'll first give the page a chance to process the key events. If it does
// not process them, they'll be returned to us and we'll treat them as
// accelerators then.
return web_contents_ && !web_contents_->IsCrashed();
}
bool WebView::IsFocusable() const {
// We need to be focusable when our contents is not a view hierarchy, as
// clicking on the contents needs to focus us.
return !!web_contents_;
}
void WebView::OnFocus() {
if (web_contents_)
web_contents_->Focus();
}
void WebView::AboutToRequestFocusFromTabTraversal(bool reverse) {
if (web_contents_)
web_contents_->FocusThroughTabTraversal(reverse);
}
void WebView::GetAccessibleState(ui::AccessibleViewState* state) {
state->role = ui::AccessibilityTypes::ROLE_GROUPING;
}
gfx::NativeViewAccessible WebView::GetNativeViewAccessible() {
if (web_contents_) {
content::RenderWidgetHostView* host_view =
web_contents_->GetRenderWidgetHostView();
if (host_view)
return host_view->GetNativeViewAccessible();
}
return View::GetNativeViewAccessible();
}
////////////////////////////////////////////////////////////////////////////////
// WebView, content::NotificationObserver implementation:
void WebView::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED) {
std::pair<content::RenderViewHost*, content::RenderViewHost*>*
switched_details =
content::Details<std::pair<content::RenderViewHost*,
content::RenderViewHost*> >(
details).ptr();
RenderViewHostChanged(switched_details->first,
switched_details->second);
} else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
WebContentsDestroyed(content::Source<content::WebContents>(source).ptr());
} else {
NOTREACHED();
}
}
////////////////////////////////////////////////////////////////////////////////
// WebView, content::WebContentsDelegate implementation:
void WebView::WebContentsFocused(content::WebContents* web_contents) {
DCHECK(wc_owner_.get());
// The WebView is only the delegate of WebContentses it creates itself.
WebContentsFocused(web_contents_);
}
////////////////////////////////////////////////////////////////////////////////
// WebView, private:
void WebView::AttachWebContents() {
// Prevents attachment if the WebView isn't already in a Widget, or it's
// already attached.
if (!GetWidget() || !web_contents_ ||
wcv_holder_->native_view() == web_contents_->GetNativeView()) {
return;
}
if (web_contents_) {
wcv_holder_->Attach(web_contents_->GetNativeView()); wcv_holder_->Attach(web_contents_->GetNativeView());
registrar_.Add(
this,
content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED,
content::Source<content::NavigationController>(
&web_contents_->GetController()));
registrar_.Add(
this,
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(web_contents_));
}
}
void WebView::DetachWebContents() {
if (web_contents_) {
wcv_holder_->Detach();
#if defined(OS_WIN)
// TODO(beng): This should either not be necessary, or be done implicitly by
// NativeViewHostWin on Detach(). As it stands, this is needed
// so that the view of the detached contents knows to tell the
// renderer its been hidden.
ShowWindow(web_contents_->GetNativeView(), SW_HIDE);
#endif
}
registrar_.RemoveAll();
}
void WebView::RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) {
if (GetFocusManager()->GetFocusedView() == this)
web_contents_->Focus();
}
void WebView::WebContentsDestroyed(content::WebContents* web_contents) {
DCHECK(web_contents == web_contents_);
SetWebContents(NULL);
} }
} // namespace views } // namespace views
...@@ -7,82 +7,32 @@ ...@@ -7,82 +7,32 @@
#pragma once #pragma once
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace views { namespace views {
class NativeViewHost; class NativeViewHost;
class VIEWS_EXPORT WebView : public View, class VIEWS_EXPORT WebView : public View {
public content::NotificationObserver,
public content::WebContentsDelegate {
public: public:
explicit WebView(content::BrowserContext* browser_context); explicit WebView(content::BrowserContext* browser_context);
virtual ~WebView(); virtual ~WebView();
// This creates a WebContents if none is yet associated with this WebView. The content::WebContents* web_contents() { return web_contents_.get(); }
// WebView owns this implicitly created WebContents.
content::WebContents* GetWebContents();
// WebView does not assume ownership of WebContents set via this method, only
// those it implicitly creates via GetWebContents() above.
void SetWebContents(content::WebContents* web_contents);
content::WebContents* web_contents() { return web_contents_; }
// Controls how the attached WebContents is resized.
// false = WebContents' views' bounds are updated continuously as the
// WebView's bounds change (default).
// true = WebContents' views' position is updated continuously but its size
// is not (which may result in some clipping or under-painting) until
// a continuous size operation completes. This allows for smoother
// resizing performance during interactive resizes and animations.
void SetFastResize(bool fast_resize);
// Called when the WebContents is focused.
// TODO(beng): This view should become a WebContentsViewObserver when a
// WebContents is attached, and not rely on the delegate to
// forward this notification.
void OnWebContentsFocused(content::WebContents* web_contents);
private: private:
void Init();
// Overridden from View: // Overridden from View:
virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
virtual void ViewHierarchyChanged(bool is_add, virtual void ViewHierarchyChanged(bool is_add,
View* parent, View* parent,
View* child) OVERRIDE; View* child) OVERRIDE;
virtual bool SkipDefaultKeyEventProcessing(
const views::KeyEvent& event) OVERRIDE;
virtual bool IsFocusable() const OVERRIDE;
virtual void OnFocus() OVERRIDE;
virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
// Overridden from content::NotificationObserver:
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
// Overridden from content::WebContentsDelegate:
virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE;
void AttachWebContents();
void DetachWebContents();
void RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host);
void WebContentsDestroyed(content::WebContents* web_contents);
NativeViewHost* wcv_holder_; NativeViewHost* wcv_holder_;
scoped_ptr<content::WebContents> wc_owner_; scoped_ptr<content::WebContents> web_contents_;
content::WebContents* web_contents_;
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
content::NotificationRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(WebView); DISALLOW_COPY_AND_ASSIGN(WebView);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment