diff options
19 files changed, 276 insertions, 95 deletions
diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index a18540d..e8bc30f 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -190,7 +190,7 @@ class AutofillTest : public InProcessBrowserTest { ASSERT_NO_FATAL_FAILURE(ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER)); ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), - VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + VIEW_ID_TAB_CONTAINER)); LOG(WARNING) << "Focusing the first name field."; bool result = false; diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 8f58d4d..635c021 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -236,7 +236,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); ClickOnView(VIEW_ID_TAB_CONTAINER); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ClickOnView(VIEW_ID_LOCATION_BAR); ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); @@ -254,11 +254,11 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_BrowsersRememberFocus) { gfx::NativeWindow window = browser()->window()->GetNativeHandle(); // The focus should be on the Tab contents. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Now hide the window, show it again, the focus should not have changed. ui_test_utils::HideNativeWindow(window); ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); browser()->FocusLocationBar(); ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); @@ -347,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { // Activate the tab. browser()->ActivateTabAt(j, true); - ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : + ViewID vid = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : location_bar_focus_view_id_; ASSERT_TRUE(IsViewFocused(vid)); } @@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { // 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. for (int j = 0; j < 15; j++) { - ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : + ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : location_bar_focus_view_id_; ASSERT_TRUE(IsViewFocused(vid)); @@ -367,7 +367,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabsRememberFocus) { // As above, but with ctrl+shift+tab. browser()->ActivateTabAt(4, true); for (int j = 14; j >= 0; --j) { - ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER_FOCUS_VIEW : + ViewID vid = kFocusPage[i][j % 5] ? VIEW_ID_TAB_CONTAINER : location_bar_focus_view_id_; ASSERT_TRUE(IsViewFocused(vid)); @@ -398,7 +398,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); // Focus should be on the recently opened tab page. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Select 1st tab, focus should still be on the location-bar. // (bug http://crbug.com/23296) @@ -410,7 +410,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_TabsRememberFocusFindInPage) { browser()->Find(); ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); browser()->ActivateTabAt(1, true); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); browser()->ActivateTabAt(0, true); ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); } @@ -620,7 +620,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, MAYBE_FocusTraversalOnInterstitial) { ui_test_utils::NavigateToURL(browser(), url); // Focus should be on the page. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Let's show an interstitial. TestInterstitialPage* interstitial_page = @@ -743,7 +743,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { ui_test_utils::NavigateToURL(browser(), url); // Page should have focus. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(browser()->GetSelectedWebContents()->GetRenderViewHost()-> GetView()->HasFocus()); @@ -758,14 +758,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, InterstitialFocus) { ui_test_utils::RunMessageLoop(); // The interstitial should have focus now. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(interstitial_page->HasFocus()); // Hide the interstitial. interstitial_page->DontProceed(); // Focus should be back on the original page. - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); } // Make sure Find box can request focus, even when it is already open. @@ -812,7 +812,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { // Set focus to the page. ClickOnView(VIEW_ID_TAB_CONTAINER); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Now press Ctrl+F again and focus should move to the Find box. #if defined(OS_MACOSX) @@ -836,7 +836,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { browser()->ShowHistoryTab(); ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( browser()->GetSelectedWebContents())); - EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Open the new tab, focus should be on the location bar. browser()->NewTab(); @@ -848,7 +848,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, DISABLED_TabInitialFocus) { browser()->ShowDownloadsTab(); ASSERT_NO_FATAL_FAILURE(ui_test_utils::WaitForLoadStop( browser()->GetSelectedWebContents())); - EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + EXPECT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Open about:blank, focus should be on the location bar. browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), @@ -901,7 +901,7 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusOnReload) { // Focus should now be on the tab contents. browser()->ShowDownloadsTab(); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); } // 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) { // Focus should now be on the tab contents. browser()->ShowDownloadsTab(); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); } } // namespace diff --git a/chrome/browser/browser_keyevents_browsertest.cc b/chrome/browser/browser_keyevents_browsertest.cc index 5cac985..ca40d13 100644 --- a/chrome/browser/browser_keyevents_browsertest.cc +++ b/chrome/browser/browser_keyevents_browsertest.cc @@ -364,7 +364,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, NormalKeyEvents) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); for (size_t i = 0; i < arraysize(kTestNoInput); ++i) { @@ -449,7 +449,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, CtrlKeyEvents) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); // Press Ctrl+F, which will make the Find box open and request focus. @@ -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. ASSERT_TRUE(ui_test_utils::SendKeyPressSync( browser(), ui::VKEY_ESCAPE, false, false, false, false)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Press Ctrl+F with keydown suppressed shall not open the find box. EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlFSuppressKeyDown)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZ)); EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlZSuppressKeyDown)); @@ -495,7 +495,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, DISABLED_CommandKeyEvents) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); // 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) { // Press Escape to close the Find box and move the focus back to the web page. ASSERT_TRUE(ui_test_utils::SendKeyPressSync( browser(), ui::VKEY_ESCAPE, false, false, false, false)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Press Cmd+F with keydown suppressed shall not open the find box. EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCmdFSuppressKeyDown)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); } #endif @@ -597,7 +597,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { ui_test_utils::RunAllPendingInMessageLoop(); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); // Make sure no element is focused. @@ -628,7 +628,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, AccessKeys) { // Move the focus back to the web page. ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Make sure no element is focused. EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"")); @@ -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 // suppressed at all. EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAccessDSuppress)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); EXPECT_NO_FATAL_FAILURE(CheckFocusedElement(tab_index, L"D")); // Blur the focused element. @@ -670,7 +670,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); ASSERT_EQ(1, browser()->tab_count()); @@ -708,7 +708,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, MAYBE_ReservedAccelerators) { // Make sure the focus is in the testing page. ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Reserved accelerators can't be suppressed. ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); @@ -767,7 +767,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, EditorKeyBindings) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); @@ -804,7 +804,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, PageUpDownKeys) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); ASSERT_NO_FATAL_FAILURE(SetFocusedElement(tab_index, L"A")); @@ -846,7 +846,7 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { ui_test_utils::NavigateToURL(browser(), url); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); int tab_index = browser()->active_index(); // Press and release Alt key to focus wrench menu button. @@ -854,15 +854,15 @@ IN_PROC_BROWSER_TEST_F(BrowserKeyEventsTest, FocusMenuBarByAltKey) { EXPECT_TRUE(IsViewFocused(VIEW_ID_APP_MENU)); ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Alt key can be suppressed. EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); // Ctrl+Alt should have no effect. EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); - ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); } #endif diff --git a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm index 8599093..69e7a64 100644 --- a/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm +++ b/chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.mm @@ -115,7 +115,7 @@ class SpellCheckRenderViewObserver : public content::RenderViewHostObserver { if (self) { renderWidgetHost_ = renderWidgetHost; NSView* nativeView = renderWidgetHost_->GetView()->GetNativeView(); - view_id_util::SetID(nativeView, VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); + view_id_util::SetID(nativeView, VIEW_ID_TAB_CONTAINER); if (renderWidgetHost_->IsRenderView()) { spellingObserver_.reset( diff --git a/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h b/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h index 6147a27..6cb4ec4 100644 --- a/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h +++ b/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h @@ -34,8 +34,6 @@ class ChromeWebContentsViewDelegateMac virtual content::WebDragDestDelegate* GetDragDestDelegate() OVERRIDE; virtual void ShowContextMenu( const content::ContextMenuParams& params) OVERRIDE; - virtual void NativeViewCreated(NSView* view) OVERRIDE; - virtual void NativeViewDestroyed(NSView* view) OVERRIDE; private: // The context menu. Callbacks are asynchronous so we need to keep it around. diff --git a/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.mm b/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.mm index 57749bc..5e7102b 100644 --- a/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.mm +++ b/chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.mm @@ -7,7 +7,6 @@ #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" -#import "chrome/browser/ui/cocoa/view_id_util.h" #include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/web_contents.h" @@ -59,11 +58,3 @@ void ChromeWebContentsViewDelegateMac::ShowContextMenu( web_contents_->GetContentNativeView())); context_menu_->Init(); } - -void ChromeWebContentsViewDelegateMac::NativeViewCreated(NSView* view) { - view_id_util::SetID(view, VIEW_ID_TAB_CONTAINER); -} - -void ChromeWebContentsViewDelegateMac::NativeViewDestroyed(NSView* view) { - view_id_util::UnsetID(view); -} diff --git a/chrome/browser/ui/browser_navigator_browsertest.cc b/chrome/browser/ui/browser_navigator_browsertest.cc index d15f0250..8cb0709 100644 --- a/chrome/browser/ui/browser_navigator_browsertest.cc +++ b/chrome/browser/ui/browser_navigator_browsertest.cc @@ -1220,8 +1220,7 @@ IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, EXPECT_EQ(1, browser()->active_index()); // The tab contents should have the focus in the second tab. - EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), - VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); // Go back to the first tab. The focus should not be in the omnibox. browser()->SelectPreviousTab(); diff --git a/chrome/browser/ui/gtk/tab_contents_container_gtk.cc b/chrome/browser/ui/gtk/tab_contents_container_gtk.cc index 2a4ab83..965bd4e 100644 --- a/chrome/browser/ui/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/ui/gtk/tab_contents_container_gtk.cc @@ -212,10 +212,8 @@ gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, // ViewIDUtil::Delegate implementation GtkWidget* TabContentsContainerGtk::GetWidgetForViewID(ViewID view_id) { - if (view_id == VIEW_ID_TAB_CONTAINER || - view_id == VIEW_ID_TAB_CONTAINER_FOCUS_VIEW) { + if (view_id == VIEW_ID_TAB_CONTAINER) return widget(); - } return NULL; } diff --git a/chrome/browser/ui/gtk/view_id_util.cc b/chrome/browser/ui/gtk/view_id_util.cc index c9ad81d..0f5a217 100644 --- a/chrome/browser/ui/gtk/view_id_util.cc +++ b/chrome/browser/ui/gtk/view_id_util.cc @@ -113,7 +113,6 @@ const char* GetNameFromID(ViewID id) { // These are never hit because the tab container uses the delegate to // set its ID. case VIEW_ID_TAB_CONTAINER: - case VIEW_ID_TAB_CONTAINER_FOCUS_VIEW: default: NOTREACHED() << "If you added a new VIEW_ID, please provide " "a name for the widget."; diff --git a/chrome/browser/ui/view_ids.h b/chrome/browser/ui/view_ids.h index 005d2b4..c032c63 100644 --- a/chrome/browser/ui/view_ids.h +++ b/chrome/browser/ui/view_ids.h @@ -60,7 +60,6 @@ enum ViewID { // Tab Container window. VIEW_ID_TAB_CONTAINER, - VIEW_ID_TAB_CONTAINER_FOCUS_VIEW, // Docked dev tools. VIEW_ID_DEV_TOOLS_DOCKED, diff --git a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc index fb1eaad..7764bcf 100644 --- a/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc +++ b/chrome/browser/ui/views/find_bar_host_interactive_uitest.cc @@ -135,8 +135,7 @@ IN_PROC_BROWSER_TEST_F(FindInPageTest, FocusRestore) { ASCIIToUTF16("a"), true, false, NULL); browser()->GetFindBarController()->EndFindSession( FindBarController::kKeepSelection); - EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), - VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); + EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); // 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 diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 4cd7d2d5c..ee1850d 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -93,6 +93,7 @@ #include "ui/gfx/sys_color_change_listener.h" #include "ui/ui_controls/ui_controls.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/focus/external_focus_tracker.h" #include "ui/views/focus/view_storage.h" @@ -1200,7 +1201,7 @@ int BrowserView::GetExtraRenderViewHeight() const { } void BrowserView::WebContentsFocused(WebContents* contents) { - contents_container_->WebContentsFocused(contents); + contents_container_->OnWebContentsFocused(contents); } void BrowserView::ShowPageInfo(Profile* profile, @@ -1313,10 +1314,12 @@ void BrowserView::Paste() { } void BrowserView::ShowInstant(TabContentsWrapper* preview) { - if (!preview_container_) - preview_container_ = new TabContentsContainer(); + if (!preview_container_) { + preview_container_ = new views::WebView(browser_->profile()); + preview_container_->set_id(VIEW_ID_TAB_CONTAINER); + } contents_->SetPreview(preview_container_, preview->web_contents()); - preview_container_->ChangeWebContents(preview->web_contents()); + preview_container_->SetWebContents(preview->web_contents()); } void BrowserView::HideInstant() { @@ -1324,7 +1327,7 @@ void BrowserView::HideInstant() { return; // The contents must be changed before SetPreview is invoked. - preview_container_->ChangeWebContents(NULL); + preview_container_->SetWebContents(NULL); contents_->SetPreview(NULL, NULL); delete preview_container_; preview_container_ = NULL; @@ -1372,7 +1375,7 @@ LocationBarView* BrowserView::GetLocationBarView() const { } views::View* BrowserView::GetTabContentsContainerView() const { - return contents_container_->GetFocusView(); + return contents_container_; } ToolbarView* BrowserView::GetToolbarView() const { @@ -1390,7 +1393,7 @@ void BrowserView::TabDetachedAt(TabContentsWrapper* contents, int index) { // We need to reset the current tab contents to NULL before it gets // freed. This is because the focus manager performs some operations // on the selected TabContents when it is removed. - contents_container_->ChangeWebContents(NULL); + contents_container_->SetWebContents(NULL); infobar_container_->ChangeTabContents(NULL); UpdateDevToolsForContents(NULL); } @@ -1422,9 +1425,9 @@ void BrowserView::TabReplacedAt(TabStripModel* tab_strip_model, // If 'preview' is becoming active, swap the 'active' and 'preview' and // delete what was the active. contents_->MakePreviewContentsActiveContents(); - TabContentsContainer* old_container = contents_container_; + views::WebView* old_container = contents_container_; contents_container_ = preview_container_; - old_container->ChangeWebContents(NULL); + old_container->SetWebContents(NULL); delete old_container; preview_container_ = NULL; } @@ -1900,7 +1903,8 @@ void BrowserView::Init() { infobar_container_ = new InfoBarContainerView(this); AddChildView(infobar_container_); - contents_container_ = new TabContentsContainer; + contents_container_ = new views::WebView(browser_->profile()); + contents_container_->set_id(VIEW_ID_TAB_CONTAINER); contents_ = new ContentsContainer(contents_container_); SkColor bg_color = GetWidget()->GetThemeProvider()-> @@ -2414,7 +2418,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) { // we don't want any TabContents to be attached, so that we // avoid an unnecessary resize and re-layout of a TabContents. if (change_tab_contents) - contents_container_->ChangeWebContents(NULL); + contents_container_->SetWebContents(NULL); infobar_container_->ChangeTabContents(new_contents->infobar_tab_helper()); if (bookmark_bar_view_.get()) { bookmark_bar_view_->SetBookmarkBarState( @@ -2423,7 +2427,7 @@ void BrowserView::ProcessTabSelected(TabContentsWrapper* new_contents) { } UpdateUIForContents(new_contents); if (change_tab_contents) - contents_container_->ChangeWebContents(new_contents->web_contents()); + contents_container_->SetWebContents(new_contents->web_contents()); UpdateDevToolsForContents(new_contents); // TODO(beng): This should be called automatically by ChangeWebContents, but I diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 6d9c8fe..157c450 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -67,6 +67,7 @@ namespace views { class AccessiblePaneView; class ExternalFocusTracker; class Menu; +class WebView; } /////////////////////////////////////////////////////////////////////////////// @@ -613,13 +614,13 @@ class BrowserView : public BrowserWindow, InfoBarContainerView* infobar_container_; // The view that contains the selected TabContents. - TabContentsContainer* contents_container_; + views::WebView* contents_container_; // The view that contains devtools window for the selected TabContents. TabContentsContainer* devtools_container_; // The view that contains instant's TabContents. - TabContentsContainer* preview_container_; + views::WebView* preview_container_; // The view managing both the contents_container_ and preview_container_. ContentsContainer* contents_; diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_aura.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_aura.cc index 3fe380a..7ca4509 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_aura.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_aura.cc @@ -23,7 +23,6 @@ using content::WebContents; NativeTabContentsContainerAura::NativeTabContentsContainerAura( TabContentsContainer* container) : container_(container) { - set_id(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); } NativeTabContentsContainerAura::~NativeTabContentsContainerAura() { diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_win.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_win.cc index f962912..bb62807 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_win.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_win.cc @@ -22,7 +22,6 @@ using content::WebContents; NativeTabContentsContainerWin::NativeTabContentsContainerWin( TabContentsContainer* container) : container_(container) { - set_id(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); } NativeTabContentsContainerWin::~NativeTabContentsContainerWin() { diff --git a/content/browser/web_contents/web_contents_view_mac.mm b/content/browser/web_contents/web_contents_view_mac.mm index 7cd4a95..974a850 100644 --- a/content/browser/web_contents/web_contents_view_mac.mm +++ b/content/browser/web_contents/web_contents_view_mac.mm @@ -410,16 +410,12 @@ void WebContentsViewMac::CloseTab() { if (webContentsView_->delegate()) { [dragDest_ setDragDelegate:webContentsView_->delegate()-> GetDragDestDelegate()]; - webContentsView_->delegate()->NativeViewCreated(self); } } return self; } - (void)dealloc { - if (webContentsView_ && webContentsView_->delegate()) - webContentsView_->delegate()->NativeViewDestroyed(self); - // Cancel any deferred tab closes, just in case. [self cancelDeferredClose]; diff --git a/content/public/browser/web_contents_view_delegate.h b/content/public/browser/web_contents_view_delegate.h index 401638e..a58799f 100644 --- a/content/public/browser/web_contents_view_delegate.h +++ b/content/public/browser/web_contents_view_delegate.h @@ -79,10 +79,6 @@ class CONTENT_EXPORT WebContentsViewDelegate { virtual NSObject<RenderWidgetHostViewMacDelegate>* CreateRenderWidgetHostViewDelegate( RenderWidgetHost* render_widget_host) = 0; - - // Notifications that the native view was created/destroyed. - virtual void NativeViewCreated(NSView* view) = 0; - virtual void NativeViewDestroyed(NSView* view) = 0; #endif }; diff --git a/ui/views/controls/webview/webview.cc b/ui/views/controls/webview/webview.cc index 864ec1dd..136db8a 100644 --- a/ui/views/controls/webview/webview.cc +++ b/ui/views/controls/webview/webview.cc @@ -5,8 +5,17 @@ #include "ui/views/controls/webview/webview.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 "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/focus/focus_manager.h" namespace views { @@ -15,21 +24,45 @@ namespace views { WebView::WebView(content::BrowserContext* browser_context) : wcv_holder_(new NativeViewHost), + web_contents_(NULL), browser_context_(browser_context) { - Init(); + AddChildView(wcv_holder_); } WebView::~WebView() { } -//////////////////////////////////////////////////////////////////////////////// -// WebView, private: +content::WebContents* WebView::GetWebContents() { + if (!web_contents_) { + 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::Init() { - AddChildView(wcv_holder_); - web_contents_.reset( - content::WebContents::Create(browser_context_, NULL, MSG_ROUTING_NONE, - NULL, NULL)); +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) { + FocusManager* focus_manager = GetFocusManager(); + if (focus_manager) + focus_manager->SetFocusedView(this); } //////////////////////////////////////////////////////////////////////////////// @@ -40,8 +73,128 @@ void WebView::OnBoundsChanged(const gfx::Rect& previous_bounds) { } void WebView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - if (is_add && child == this) + if (is_add) + 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()); + + 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) && !defined(USE_AURA) + // 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 diff --git a/ui/views/controls/webview/webview.h b/ui/views/controls/webview/webview.h index c817d97..23c4748 100644 --- a/ui/views/controls/webview/webview.h +++ b/ui/views/controls/webview/webview.h @@ -7,32 +7,82 @@ #pragma once #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_delegate.h" #include "ui/views/view.h" namespace views { class NativeViewHost; -class VIEWS_EXPORT WebView : public View { +class VIEWS_EXPORT WebView : public View, + public content::NotificationObserver, + public content::WebContentsDelegate { public: explicit WebView(content::BrowserContext* browser_context); virtual ~WebView(); - content::WebContents* web_contents() { return web_contents_.get(); } + // This creates a WebContents if none is yet associated with this WebView. The + // WebView owns this implicitly created WebContents. + content::WebContents* GetWebContents(); - private: - void Init(); + // 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: // Overridden from View: virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; virtual void ViewHierarchyChanged(bool is_add, View* parent, 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_; - scoped_ptr<content::WebContents> web_contents_; + scoped_ptr<content::WebContents> wc_owner_; + content::WebContents* web_contents_; content::BrowserContext* browser_context_; + content::NotificationRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(WebView); }; |