diff options
author | mohsen@chromium.org <mohsen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-16 21:31:58 +0000 |
---|---|---|
committer | mohsen@chromium.org <mohsen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-16 21:31:58 +0000 |
commit | 1ac832c6e9258a68bd17c85773719225f106b3ae (patch) | |
tree | 51a45493337c4ee868b0f62911b4ac51785bc3dd /ui | |
parent | 3bdb0994b4ab7843e1c82289156761a95b4552e5 (diff) | |
download | chromium_src-1ac832c6e9258a68bd17c85773719225f106b3ae.zip chromium_src-1ac832c6e9258a68bd17c85773719225f106b3ae.tar.gz chromium_src-1ac832c6e9258a68bd17c85773719225f106b3ae.tar.bz2 |
Honor can_activate flag in ShowWindowWithState
In HWNDMessageHandler::ShowWindowWitState(), when ui::SHOW_STATE_DEFAULT
is passed as state, the window grabs activation after being shown. The
correct behavior would be to activate the widget if and only if the
can_activate flag is set. HWNDMessageHandler::Show() method already does
this since r244605.
Also, the DefaultWidgetDelegate should honor InitParams::can_activate
flag.
BUG=340736
Review URL: https://codereview.chromium.org/154783002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/controls/textfield/textfield.h | 5 | ||||
-rw-r--r-- | ui/views/test/test_views_delegate.cc | 15 | ||||
-rw-r--r-- | ui/views/test/test_views_delegate.h | 12 | ||||
-rw-r--r-- | ui/views/touchui/touch_selection_controller_impl.h | 5 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc | 2 | ||||
-rw-r--r-- | ui/views/widget/widget_interactive_uitest.cc | 78 |
6 files changed, 110 insertions, 7 deletions
diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h index 7635eca..431ceef 100644 --- a/ui/views/controls/textfield/textfield.h +++ b/ui/views/controls/textfield/textfield.h @@ -30,6 +30,10 @@ namespace views { +namespace test { +class WidgetTestInteractive; +} + class MenuRunner; class Painter; class TextfieldController; @@ -295,6 +299,7 @@ class VIEWS_EXPORT Textfield : public View, private: friend class TextfieldTest; friend class TouchSelectionControllerImplTest; + friend class test::WidgetTestInteractive; // Handles a request to change the value of this text field from software // using an accessibility API (typically automation software, screen readers diff --git a/ui/views/test/test_views_delegate.cc b/ui/views/test/test_views_delegate.cc index 81f46da..0d437ea 100644 --- a/ui/views/test/test_views_delegate.cc +++ b/ui/views/test/test_views_delegate.cc @@ -6,11 +6,16 @@ #include "ui/wm/core/wm_state.h" +#if !defined(OS_CHROMEOS) +#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" +#endif // !defined(OS_CHROMEOS) + namespace views { TestViewsDelegate::TestViewsDelegate() - : use_transparent_windows_(false) { + : use_desktop_native_widgets_(false), + use_transparent_windows_(false) { DCHECK(!ViewsDelegate::views_delegate); ViewsDelegate::views_delegate = this; #if defined(USE_AURA) @@ -23,10 +28,6 @@ TestViewsDelegate::~TestViewsDelegate() { ViewsDelegate::views_delegate = NULL; } -void TestViewsDelegate::SetUseTransparentWindows(bool transparent) { - use_transparent_windows_ = transparent; -} - void TestViewsDelegate::OnBeforeWidgetInit( Widget::InitParams* params, internal::NativeWidgetDelegate* delegate) { @@ -35,6 +36,10 @@ void TestViewsDelegate::OnBeforeWidgetInit( Widget::InitParams::TRANSLUCENT_WINDOW : Widget::InitParams::OPAQUE_WINDOW; } +#if !defined(OS_CHROMEOS) + if (!params->native_widget && use_desktop_native_widgets_) + params->native_widget = new DesktopNativeWidgetAura(delegate); +#endif // !defined(OS_CHROMEOS) } } // namespace views diff --git a/ui/views/test/test_views_delegate.h b/ui/views/test/test_views_delegate.h index 1d726f8..5d80e08 100644 --- a/ui/views/test/test_views_delegate.h +++ b/ui/views/test/test_views_delegate.h @@ -19,7 +19,16 @@ class TestViewsDelegate : public ViewsDelegate { TestViewsDelegate(); virtual ~TestViewsDelegate(); - void SetUseTransparentWindows(bool transparent); + // If set to |true|, forces widgets that do not provide a native widget to use + // DesktopNativeWidgetAura instead of whatever the default native widget would + // be. This has no effect on ChromeOS. + void set_use_desktop_native_widgets(bool desktop) { + use_desktop_native_widgets_ = desktop; + } + + void set_use_transparent_windows(bool transparent) { + use_transparent_windows_ = transparent; + } // ViewsDelegate: virtual void OnBeforeWidgetInit( @@ -27,6 +36,7 @@ class TestViewsDelegate : public ViewsDelegate { internal::NativeWidgetDelegate* delegate) OVERRIDE; private: + bool use_desktop_native_widgets_; bool use_transparent_windows_; #if defined(USE_AURA) scoped_ptr<wm::WMState> wm_state_; diff --git a/ui/views/touchui/touch_selection_controller_impl.h b/ui/views/touchui/touch_selection_controller_impl.h index 6145e97..04076af 100644 --- a/ui/views/touchui/touch_selection_controller_impl.h +++ b/ui/views/touchui/touch_selection_controller_impl.h @@ -14,6 +14,10 @@ namespace views { +namespace test { +class WidgetTestInteractive; +} + // Touch specific implementation of TouchSelectionController. Responsible for // displaying selection handles and menu elements relevant in a touch interface. class VIEWS_EXPORT TouchSelectionControllerImpl @@ -37,6 +41,7 @@ class VIEWS_EXPORT TouchSelectionControllerImpl private: friend class TouchSelectionControllerImplTest; + friend class test::WidgetTestInteractive; void SetDraggingHandle(EditingHandleView* handle); diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc index 195e5e2..82ad88a 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc @@ -605,7 +605,7 @@ bool DesktopWindowTreeHostWin::IsModal() const { } int DesktopWindowTreeHostWin::GetInitialShowState() const { - return SW_SHOWNORMAL; + return CanActivate() ? SW_SHOWNORMAL : SW_SHOWNOACTIVATE; } bool DesktopWindowTreeHostWin::WillProcessWorkAreaChange() const { diff --git a/ui/views/widget/widget_interactive_uitest.cc b/ui/views/widget/widget_interactive_uitest.cc index ae547ad..59f966b 100644 --- a/ui/views/widget/widget_interactive_uitest.cc +++ b/ui/views/widget/widget_interactive_uitest.cc @@ -4,19 +4,25 @@ #include "base/basictypes.h" #include "base/bind.h" +#include "base/command_line.h" #include "base/path_service.h" #include "base/run_loop.h" #include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" +#include "ui/aura/test/event_generator.h" #include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" +#include "ui/base/ui_base_switches.h" #include "ui/events/event_processor.h" #include "ui/gfx/native_widget_types.h" #include "ui/gl/gl_surface.h" +#include "ui/views/controls/textfield/textfield.h" #include "ui/views/test/widget_test.h" +#include "ui/views/touchui/touch_selection_controller_impl.h" #include "ui/views/widget/widget.h" #include "ui/views/window/dialog_delegate.h" #include "ui/wm/public/activation_client.h" @@ -162,6 +168,28 @@ class WidgetTestInteractive : public WidgetTest { ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file); WidgetTest::SetUp(); } + + protected: + void ShowTouchSelectionQuickMenuImmediately(Textfield* textfield) { + DCHECK(textfield); + DCHECK(textfield->touch_selection_controller_); + TouchSelectionControllerImpl* controller = + static_cast<TouchSelectionControllerImpl*>( + textfield->touch_selection_controller_.get()); + if (controller->context_menu_timer_.IsRunning()) { + controller->context_menu_timer_.Stop(); + controller->ContextMenuTimerFired(); + } + } + + bool TouchSelectionQuickMenuIsVisible(Textfield* textfield) { + DCHECK(textfield); + DCHECK(textfield->touch_selection_controller_); + TouchSelectionControllerImpl* controller = + static_cast<TouchSelectionControllerImpl*>( + textfield->touch_selection_controller_.get()); + return controller->context_menu_ && controller->context_menu_->visible(); + } }; #if defined(OS_WIN) @@ -702,6 +730,56 @@ TEST_F(WidgetTestInteractive, SystemModalWindowReleasesCapture) { #endif +TEST_F(WidgetTestInteractive, CanActivateFlagIsHonored) { + Widget widget; + Widget::InitParams init_params = + CreateParams(Widget::InitParams::TYPE_WINDOW); + init_params.bounds = gfx::Rect(0, 0, 200, 200); + init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + init_params.activatable = Widget::InitParams::ACTIVATABLE_NO; +#if !defined(OS_CHROMEOS) + init_params.native_widget = new DesktopNativeWidgetAura(&widget); +#endif // !defined(OS_CHROMEOS) + widget.Init(init_params); + + widget.Show(); + EXPECT_FALSE(widget.IsActive()); +} + +// Test that touch selection quick menu is not activated when opened. +TEST_F(WidgetTestInteractive, TouchSelectionQuickMenuIsNotActivated) { + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableTouchEditing); +#if defined(OS_WIN) + views_delegate().set_use_desktop_native_widgets(true); +#endif // !defined(OS_WIN) + + Widget widget; + Widget::InitParams init_params = + CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); + init_params.bounds = gfx::Rect(0, 0, 200, 200); + init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + widget.Init(init_params); + + Textfield* textfield = new Textfield; + textfield->SetBounds(0, 0, 200, 20); + textfield->SetText(base::ASCIIToUTF16("some text")); + widget.GetRootView()->AddChildView(textfield); + + widget.Show(); + textfield->RequestFocus(); + textfield->SelectAll(true); + + RunPendingMessages(); + + aura::test::EventGenerator generator(widget.GetNativeView()->GetRootWindow()); + generator.GestureTapAt(gfx::Point(10, 10)); + ShowTouchSelectionQuickMenuImmediately(textfield); + + EXPECT_TRUE(textfield->HasFocus()); + EXPECT_TRUE(widget.IsActive()); + EXPECT_TRUE(TouchSelectionQuickMenuIsVisible(textfield)); +} + namespace { // Used to veirfy OnMouseCaptureLost() has been invoked. |