diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-24 22:17:36 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-24 22:17:36 +0000 |
commit | c138f296d2360252812ec2051e73bc412cf11fe1 (patch) | |
tree | 7bfa104b4da5358091122c5e3052b110cf5d1858 /chrome/browser | |
parent | 284dadf39378ae2ef6b18edce0a7b4f54364f9a0 (diff) | |
download | chromium_src-c138f296d2360252812ec2051e73bc412cf11fe1.zip chromium_src-c138f296d2360252812ec2051e73bc412cf11fe1.tar.gz chromium_src-c138f296d2360252812ec2051e73bc412cf11fe1.tar.bz2 |
Fix a few issues with Chrome-in-Views-Desktop:
- adds a NativeTabContentsContainerViews, which is just a view that parents the NativeTabContentsViewViews' View.
This prevents flicker when switching tabs.
- SetPureViews is called earlier during browser_main, so that the desktop widget is created with an input method. This prevents an assert while typing in the omnibox.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7256001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90450 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
6 files changed, 183 insertions, 8 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 5c8ae10..ad100eb 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1381,6 +1381,8 @@ int BrowserMain(const MainFunctionParams& parameters) { #endif #if defined(TOOLKIT_VIEWS) + views::Widget::SetPureViews( + CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); // Launch the views desktop shell window and register it as the default parent // for all unparented views widgets. if (parsed_command_line.HasSwitch(switches::kViewsDesktop)) { @@ -1793,11 +1795,6 @@ int BrowserMain(const MainFunctionParams& parameters) { CommandLine::ForCurrentProcess()->HasSwitch(switches::kKeepMouseCursor)); #endif -#if defined(TOOLKIT_VIEWS) - views::Widget::SetPureViews( - CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePureViews)); -#endif - HandleTestParameters(parsed_command_line); RecordBreakpadStatusUMA(metrics); about_flags::RecordUMAStatistics(local_state); diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc index a25bdb1..6322cc1 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_gtk.h" #include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" #include "content/browser/renderer_host/render_widget_host_view.h" @@ -145,5 +146,7 @@ void NativeTabContentsContainerGtk::GetAccessibleState( // static NativeTabContentsContainer* NativeTabContentsContainer::CreateNativeContainer( TabContentsContainer* container) { + if (views::Widget::IsPureViews()) + return new NativeTabContentsContainerViews(container); return new NativeTabContentsContainerGtk(container); } diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.cc new file mode 100644 index 0000000..6a2bec9 --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.cc @@ -0,0 +1,133 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h" + +#include "chrome/browser/renderer_host/render_widget_host_view_views.h" +#include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" +#include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" +#include "content/browser/renderer_host/render_widget_host_view.h" +#include "content/browser/tab_contents/interstitial_page.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "ui/base/accessibility/accessible_view_state.h" +#include "views/focus/focus_manager.h" +#include "views/layout/fill_layout.h" +#include "views/widget/native_widget_views.h" + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsContainerViews, public: + +NativeTabContentsContainerViews::NativeTabContentsContainerViews( + TabContentsContainer* container) + : container_(container) { + set_id(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW); + SetLayoutManager(new views::FillLayout); +} + +NativeTabContentsContainerViews::~NativeTabContentsContainerViews() { +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsContainerViews, NativeTabContentsContainer overrides: + +void NativeTabContentsContainerViews::AttachContents(TabContents* contents) { + TabContentsViewViews* widget = + static_cast<TabContentsViewViews*>(contents->view()); + views::NativeWidgetViews* nwv = + static_cast<views::NativeWidgetViews*>(widget->native_widget()); + AddChildView(nwv->GetView()); + Layout(); +} + +void NativeTabContentsContainerViews::DetachContents(TabContents* contents) { + TabContentsViewViews* widget = + static_cast<TabContentsViewViews*>(contents->view()); + views::NativeWidgetViews* nwv = + static_cast<views::NativeWidgetViews*>(widget->native_widget()); + RemoveChildView(nwv->GetView()); +} + +void NativeTabContentsContainerViews::SetFastResize(bool fast_resize) { +} + +void NativeTabContentsContainerViews::RenderViewHostChanged( + RenderViewHost* old_host, + RenderViewHost* new_host) { + // If we are focused, we need to pass the focus to the new RenderViewHost. + if (GetFocusManager()->GetFocusedView() == this) + OnFocus(); +} + +views::View* NativeTabContentsContainerViews::GetView() { + return this; +} + +void NativeTabContentsContainerViews::TabContentsFocused( + TabContents* tab_contents) { + views::FocusManager* focus_manager = GetFocusManager(); + if (!focus_manager) { + NOTREACHED(); + return; + } + focus_manager->SetFocusedView(this); +} + +//////////////////////////////////////////////////////////////////////////////// +// NativeTabContentsContainerWin, views::View overrides: + +bool NativeTabContentsContainerViews::SkipDefaultKeyEventProcessing( + const views::KeyEvent& e) { + // 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 container_->tab_contents() && + !container_->tab_contents()->is_crashed(); +} + +bool NativeTabContentsContainerViews::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 container_->tab_contents() != NULL; +} + +void NativeTabContentsContainerViews::OnFocus() { + if (container_->tab_contents()) + container_->tab_contents()->Focus(); +} + +void NativeTabContentsContainerViews::RequestFocus() { + // This is a hack to circumvent the fact that a the OnFocus() method is not + // invoked when RequestFocus() is called on an already focused view. + // The TabContentsContainer is the view focused when the TabContents has + // focus. When switching between from one tab that has focus to another tab + // that should also have focus, RequestFocus() is invoked one the + // TabContentsContainer. In order to make sure OnFocus() is invoked we need + // to clear the focus before hands. + { + // Disable notifications. Clear focus will assign the focus to the main + // browser window. Because this change of focus was not user requested, + // don't send it to listeners. + views::AutoNativeNotificationDisabler local_notification_disabler; + GetFocusManager()->ClearFocus(); + } + View::RequestFocus(); +} + +void NativeTabContentsContainerViews::AboutToRequestFocusFromTabTraversal( + bool reverse) { + container_->tab_contents()->FocusThroughTabTraversal(reverse); +} + +void NativeTabContentsContainerViews::GetAccessibleState( + ui::AccessibleViewState* state) { + state->role = ui::AccessibilityTypes::ROLE_GROUPING; +} + +gfx::NativeViewAccessible + NativeTabContentsContainerViews::GetNativeViewAccessible() { + return View::GetNativeViewAccessible(); +} diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h new file mode 100644 index 0000000..814d1d0 --- /dev/null +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h @@ -0,0 +1,42 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_CONTAINER_VIEWS_H_ +#define CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_CONTAINER_VIEWS_H_ +#pragma once + +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_container.h" +#include "views/view.h" + +class NativeTabContentsContainerViews : public NativeTabContentsContainer, + public views::View { + public: + explicit NativeTabContentsContainerViews(TabContentsContainer* container); + virtual ~NativeTabContentsContainerViews(); + + // Overridden from NativeTabContentsContainer: + virtual void AttachContents(TabContents* contents) OVERRIDE; + virtual void DetachContents(TabContents* contents) OVERRIDE; + virtual void SetFastResize(bool fast_resize) OVERRIDE; + virtual void RenderViewHostChanged(RenderViewHost* old_host, + RenderViewHost* new_host) OVERRIDE; + virtual void TabContentsFocused(TabContents* tab_contents) OVERRIDE; + virtual views::View* GetView() OVERRIDE; + + // Overridden from views::View: + virtual bool SkipDefaultKeyEventProcessing(const views::KeyEvent& e) OVERRIDE; + virtual bool IsFocusable() const OVERRIDE; + virtual void OnFocus() OVERRIDE; + virtual void RequestFocus() OVERRIDE; + virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; + virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; + virtual gfx::NativeViewAccessible GetNativeViewAccessible(); + + private: + TabContentsContainer* container_; + + DISALLOW_COPY_AND_ASSIGN(NativeTabContentsContainerViews); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_TAB_CONTENTS_NATIVE_TAB_CONTENTS_CONTAINER_VIEWS_H_ 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 244c34e..163d59d 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 @@ -6,6 +6,7 @@ #include "chrome/browser/renderer_host/render_widget_host_view_win.h" #include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/ui/views/tab_contents/native_tab_contents_container_views.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" #include "chrome/browser/ui/views/tab_contents/tab_contents_view_views.h" #include "content/browser/renderer_host/render_widget_host_view.h" @@ -156,5 +157,7 @@ gfx::NativeViewAccessible // static NativeTabContentsContainer* NativeTabContentsContainer::CreateNativeContainer( TabContentsContainer* container) { + if (views::Widget::IsPureViews()) + return new NativeTabContentsContainerViews(container); return new NativeTabContentsContainerWin(container); } diff --git a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc index c309922..993f7d9 100644 --- a/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc +++ b/chrome/browser/ui/views/tab_contents/native_tab_contents_view_views.cc @@ -36,9 +36,6 @@ void NativeTabContentsViewViews::InitNativeTabContentsView() { } void NativeTabContentsViewViews::Unparent() { - // Note that we do not DCHECK on focus_manager_ as it may be NULL when used - // with an external tab container. - views::Widget::ReparentNativeView(GetNativeView(), NULL); } RenderWidgetHostView* NativeTabContentsViewViews::CreateRenderWidgetHostView( |