1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef UI_VIEWS_TEST_TEST_VIEWS_DELEGATE_H_ 6 #define UI_VIEWS_TEST_TEST_VIEWS_DELEGATE_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "build/build_config.h" 12 #include "ui/views/layout/layout_provider.h" 13 #include "ui/views/views_delegate.h" 14 15 namespace views { 16 17 class TestViewsDelegate : public ViewsDelegate { 18 public: 19 TestViewsDelegate(); 20 ~TestViewsDelegate() override; 21 22 // If set to |true|, forces widgets that do not provide a native widget to use 23 // DesktopNativeWidgetAura instead of whatever the default native widget would 24 // be. This has no effect on ChromeOS. set_use_desktop_native_widgets(bool desktop)25 void set_use_desktop_native_widgets(bool desktop) { 26 use_desktop_native_widgets_ = desktop; 27 } 28 set_use_transparent_windows(bool transparent)29 void set_use_transparent_windows(bool transparent) { 30 use_transparent_windows_ = transparent; 31 } 32 33 #if defined(OS_APPLE) 34 // Allows tests to provide a ContextFactory via the ViewsDelegate interface. set_context_factory(ui::ContextFactory * context_factory)35 void set_context_factory(ui::ContextFactory* context_factory) { 36 context_factory_ = context_factory; 37 } 38 #endif 39 40 // For convenience, we create a layout provider by default, but embedders 41 // that use their own layout provider subclasses may need to set those classes 42 // as the layout providers for their tests. set_layout_provider(std::unique_ptr<LayoutProvider> layout_provider)43 void set_layout_provider(std::unique_ptr<LayoutProvider> layout_provider) { 44 layout_provider_.swap(layout_provider); 45 } 46 47 // ViewsDelegate: 48 #if defined(OS_WIN) 49 HICON GetSmallWindowIcon() const override; 50 #endif 51 void OnBeforeWidgetInit(Widget::InitParams* params, 52 internal::NativeWidgetDelegate* delegate) override; 53 #if defined(OS_APPLE) 54 ui::ContextFactory* GetContextFactory() override; 55 #endif 56 57 private: 58 #if defined(OS_APPLE) 59 ui::ContextFactory* context_factory_ = nullptr; 60 #endif 61 bool use_desktop_native_widgets_ = false; 62 bool use_transparent_windows_ = false; 63 std::unique_ptr<LayoutProvider> layout_provider_ = 64 std::make_unique<LayoutProvider>(); 65 66 DISALLOW_COPY_AND_ASSIGN(TestViewsDelegate); 67 }; 68 69 } // namespace views 70 71 #endif // UI_VIEWS_TEST_TEST_VIEWS_DELEGATE_H_ 72