Commit 23f920b2 authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Use std::make_unique in ui/views/

Bug: chromium:996915
Change-Id: Idd0a9b3c8d01af0c53d0fc52576a64025e655542
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1769027
Commit-Queue: Robert Liao <robliao@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690005}
parent 0d6f90e3
...@@ -54,7 +54,7 @@ class BridgedNativeWidgetUITest : public WidgetTest { ...@@ -54,7 +54,7 @@ class BridgedNativeWidgetUITest : public WidgetTest {
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.bounds = gfx::Rect(100, 100, 300, 200); init_params.bounds = gfx::Rect(100, 100, 300, 200);
init_params.delegate = new ResizableDelegateView; init_params.delegate = new ResizableDelegateView;
widget_.reset(new Widget); widget_ = std::make_unique<Widget>();
widget_->Init(std::move(init_params)); widget_->Init(std::move(init_params));
} }
......
...@@ -632,7 +632,7 @@ void BridgedNativeWidgetTest::SetHandleKeyEventCallback( ...@@ -632,7 +632,7 @@ void BridgedNativeWidgetTest::SetHandleKeyEventCallback(
void BridgedNativeWidgetTest::SetUp() { void BridgedNativeWidgetTest::SetUp() {
BridgedNativeWidgetTestBase::SetUp(); BridgedNativeWidgetTestBase::SetUp();
view_.reset(new views::internal::RootView(widget_.get())); view_ = std::make_unique<views::internal::RootView>(widget_.get());
base::scoped_nsobject<NSWindow> window([bridge_window() retain]); base::scoped_nsobject<NSWindow> window([bridge_window() retain]);
// The delegate should exist before setting the root view. // The delegate should exist before setting the root view.
...@@ -865,7 +865,7 @@ class BridgedNativeWidgetInitTest : public BridgedNativeWidgetTestBase { ...@@ -865,7 +865,7 @@ class BridgedNativeWidgetInitTest : public BridgedNativeWidgetTestBase {
// Prepares a new |window_| and |widget_| for a call to PerformInit(). // Prepares a new |window_| and |widget_| for a call to PerformInit().
void CreateNewWidgetToInit() { void CreateNewWidgetToInit() {
widget_.reset(new Widget); widget_ = std::make_unique<Widget>();
native_widget_mac_ = new MockNativeWidgetMac(widget_.get()); native_widget_mac_ = new MockNativeWidgetMac(widget_.get());
} }
......
...@@ -39,7 +39,7 @@ class TestCaptureDelegate : public CocoaMouseCaptureDelegate { ...@@ -39,7 +39,7 @@ class TestCaptureDelegate : public CocoaMouseCaptureDelegate {
explicit TestCaptureDelegate(NSWindow* window) explicit TestCaptureDelegate(NSWindow* window)
: event_count_(0), capture_lost_count_(0), window_(window) {} : event_count_(0), capture_lost_count_(0), window_(window) {}
void Acquire() { mouse_capture_.reset(new CocoaMouseCapture(this)); } void Acquire() { mouse_capture_ = std::make_unique<CocoaMouseCapture>(this); }
bool IsActive() { return mouse_capture_ && mouse_capture_->IsActive(); } bool IsActive() { return mouse_capture_ && mouse_capture_->IsActive(); }
void SimulateDestroy() { mouse_capture_.reset(); } void SimulateDestroy() { mouse_capture_.reset(); }
......
...@@ -426,7 +426,7 @@ void NativeWidgetMacNSWindowHost::InitWindow(const Widget::InitParams& params) { ...@@ -426,7 +426,7 @@ void NativeWidgetMacNSWindowHost::InitWindow(const Widget::InitParams& params) {
// native on Mac, so nothing should ever want one in Widget form. // native on Mac, so nothing should ever want one in Widget form.
DCHECK_NE(params.type, Widget::InitParams::TYPE_TOOLTIP); DCHECK_NE(params.type, Widget::InitParams::TYPE_TOOLTIP);
widget_type_ = params.type; widget_type_ = params.type;
tooltip_manager_.reset(new TooltipManagerMac(GetNSWindowMojo())); tooltip_manager_ = std::make_unique<TooltipManagerMac>(GetNSWindowMojo());
// Initialize the window. // Initialize the window.
{ {
...@@ -530,8 +530,8 @@ void NativeWidgetMacNSWindowHost::SetRootView(views::View* root_view) { ...@@ -530,8 +530,8 @@ void NativeWidgetMacNSWindowHost::SetRootView(views::View* root_view) {
if (root_view_) { if (root_view_) {
// TODO(ccameron): Drag-drop functionality does not yet run over mojo. // TODO(ccameron): Drag-drop functionality does not yet run over mojo.
if (in_process_ns_window_bridge_) { if (in_process_ns_window_bridge_) {
drag_drop_client_.reset(new DragDropClientMac( drag_drop_client_ = std::make_unique<DragDropClientMac>(
in_process_ns_window_bridge_.get(), root_view_)); in_process_ns_window_bridge_.get(), root_view_);
} }
} else { } else {
drag_drop_client_.reset(); drag_drop_client_.reset();
......
...@@ -98,7 +98,7 @@ class MenuRunnerCocoaTest : public ViewsTestBase, ...@@ -98,7 +98,7 @@ class MenuRunnerCocoaTest : public ViewsTestBase,
const int kWindowWidth = 300; const int kWindowWidth = 300;
ViewsTestBase::SetUp(); ViewsTestBase::SetUp();
menu_.reset(new TestModel()); menu_ = std::make_unique<TestModel>();
menu_->AddCheckItem(kTestCommandId, base::ASCIIToUTF16("Menu Item")); menu_->AddCheckItem(kTestCommandId, base::ASCIIToUTF16("Menu Item"));
parent_ = new views::Widget(); parent_ = new views::Widget();
......
...@@ -25,8 +25,8 @@ constexpr uint32_t kTransparentMask = 0xffffffff; ...@@ -25,8 +25,8 @@ constexpr uint32_t kTransparentMask = 0xffffffff;
constexpr int kDefaultHeight = 20; constexpr int kDefaultHeight = 20;
// Masks are monochromatic. // Masks are monochromatic.
constexpr size_t kNumberOfColors = 2; constexpr size_t kNumberOfColors = 2;
const size_t KHeaderAndPalette = const size_t kHeaderAndPalette =
sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD); sizeof(BITMAPINFOHEADER) + kNumberOfColors * sizeof(RGBQUAD);
HeightStorage* cached_heights = nullptr; HeightStorage* cached_heights = nullptr;
...@@ -40,10 +40,11 @@ PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) { ...@@ -40,10 +40,11 @@ PixelData GetBitmapData(HBITMAP handle, const BITMAPINFO& info, HDC hdc) {
// When getting pixel data palette is appended to memory pointed by // When getting pixel data palette is appended to memory pointed by
// BITMAPINFO passed so allocate additional memory to store additional data. // BITMAPINFO passed so allocate additional memory to store additional data.
std::unique_ptr<char[]> header(new char[KHeaderAndPalette]); auto header = std::make_unique<char[]>(kHeaderAndPalette);
memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader)); memcpy(header.get(), &(info.bmiHeader), sizeof(info.bmiHeader));
data.reset(new uint32_t[info.bmiHeader.biSizeImage / sizeof(uint32_t)]); data = std::make_unique<uint32_t[]>(info.bmiHeader.biSizeImage /
sizeof(uint32_t));
int result = GetDIBits(hdc, int result = GetDIBits(hdc,
handle, handle,
......
...@@ -95,8 +95,8 @@ class TooltipControllerTest : public ViewsTestBase { ...@@ -95,8 +95,8 @@ class TooltipControllerTest : public ViewsTestBase {
#if defined(OS_CHROMEOS) || defined(OS_WIN) #if defined(OS_CHROMEOS) || defined(OS_WIN)
if (root_window) { if (root_window) {
tooltip_aura_ = new views::corewm::TooltipAura(); tooltip_aura_ = new views::corewm::TooltipAura();
controller_.reset(new TooltipController( controller_ = std::make_unique<TooltipController>(
std::unique_ptr<views::corewm::Tooltip>(tooltip_aura_))); std::unique_ptr<views::corewm::Tooltip>(tooltip_aura_));
root_window->AddPreTargetHandler(controller_.get()); root_window->AddPreTargetHandler(controller_.get());
SetTooltipClient(root_window, controller_.get()); SetTooltipClient(root_window, controller_.get());
} }
......
...@@ -397,13 +397,14 @@ EventGeneratorDelegateMac::EventGeneratorDelegateMac( ...@@ -397,13 +397,14 @@ EventGeneratorDelegateMac::EventGeneratorDelegateMac(
withObject:[window.GetNativeNSWindow() firstResponder]]; withObject:[window.GetNativeNSWindow() firstResponder]];
if (owner_) { if (owner_) {
swizzle_pressed_.reset(new base::mac::ScopedObjCClassSwizzler( swizzle_pressed_ = std::make_unique<base::mac::ScopedObjCClassSwizzler>(
[NSEvent class], [NSEventDonor class], @selector(pressedMouseButtons))); [NSEvent class], [NSEventDonor class], @selector(pressedMouseButtons));
swizzle_location_.reset(new base::mac::ScopedObjCClassSwizzler( swizzle_location_ = std::make_unique<base::mac::ScopedObjCClassSwizzler>(
[NSEvent class], [NSEventDonor class], @selector(mouseLocation))); [NSEvent class], [NSEventDonor class], @selector(mouseLocation));
swizzle_current_event_.reset(new base::mac::ScopedObjCClassSwizzler( swizzle_current_event_ =
[NSApplication class], [NSApplicationDonor class], std::make_unique<base::mac::ScopedObjCClassSwizzler>(
@selector(currentEvent))); [NSApplication class], [NSApplicationDonor class],
@selector(currentEvent));
} }
} }
......
...@@ -48,10 +48,12 @@ void ViewsTestHelperMac::SetUp() { ...@@ -48,10 +48,12 @@ void ViewsTestHelperMac::SetUp() {
// activations and fullscreen mode. This allows interactive_ui_tests to test // activations and fullscreen mode. This allows interactive_ui_tests to test
// the actual OS window activation and fullscreen codepaths. // the actual OS window activation and fullscreen codepaths.
if (!ui_controls::IsUIControlsEnabled()) { if (!ui_controls::IsUIControlsEnabled()) {
faked_focus_.reset(new ui::test::ScopedFakeNSWindowFocus); faked_focus_ = std::make_unique<ui::test::ScopedFakeNSWindowFocus>();
faked_fullscreen_.reset(new ui::test::ScopedFakeNSWindowFullscreen); faked_fullscreen_ =
std::make_unique<ui::test::ScopedFakeNSWindowFullscreen>();
} }
faked_full_keyboard_access_.reset(new ui::test::ScopedFakeFullKeyboardAccess); faked_full_keyboard_access_ =
std::make_unique<ui::test::ScopedFakeFullKeyboardAccess>();
} }
void ViewsTestHelperMac::TearDown() { void ViewsTestHelperMac::TearDown() {
......
...@@ -72,7 +72,7 @@ class DesktopScreenX11Test : public views::ViewsTestBase, ...@@ -72,7 +72,7 @@ class DesktopScreenX11Test : public views::ViewsTestBase,
// Initialize the world to the single monitor case. // Initialize the world to the single monitor case.
std::vector<display::Display> displays; std::vector<display::Display> displays;
displays.emplace_back(kFirstDisplay, gfx::Rect(0, 0, 640, 480)); displays.emplace_back(kFirstDisplay, gfx::Rect(0, 0, 640, 480));
screen_.reset(new DesktopScreenX11); screen_ = std::make_unique<DesktopScreenX11>();
UpdateDisplayListForTest(displays); UpdateDisplayListForTest(displays);
screen_->AddObserver(this); screen_->AddObserver(this);
} }
......
...@@ -71,7 +71,7 @@ class NativeWidgetMacInteractiveUITest::Observer : public TestWidgetObserver { ...@@ -71,7 +71,7 @@ class NativeWidgetMacInteractiveUITest::Observer : public TestWidgetObserver {
// Test that showing a window causes it to attain global keyWindow status. // Test that showing a window causes it to attain global keyWindow status.
TEST_P(NativeWidgetMacInteractiveUITest, ShowAttainsKeyStatus) { TEST_P(NativeWidgetMacInteractiveUITest, ShowAttainsKeyStatus) {
Widget* widget = MakeWidget(); Widget* widget = MakeWidget();
observer_.reset(new Observer(this, widget)); observer_ = std::make_unique<Observer>(this, widget);
EXPECT_FALSE(widget->IsActive()); EXPECT_FALSE(widget->IsActive());
EXPECT_EQ(0, activation_count_); EXPECT_EQ(0, activation_count_);
......
...@@ -33,7 +33,7 @@ void ViewsContentClientMainParts::PreCreateMainMessageLoop() {} ...@@ -33,7 +33,7 @@ void ViewsContentClientMainParts::PreCreateMainMessageLoop() {}
void ViewsContentClientMainParts::PreMainMessageLoopRun() { void ViewsContentClientMainParts::PreMainMessageLoopRun() {
ui::MaterialDesignController::Initialize(); ui::MaterialDesignController::Initialize();
ui::InitializeInputMethodForTesting(); ui::InitializeInputMethodForTesting();
browser_context_.reset(new content::ShellBrowserContext(false)); browser_context_ = std::make_unique<content::ShellBrowserContext>(false);
std::unique_ptr<views::TestViewsDelegate> test_views_delegate( std::unique_ptr<views::TestViewsDelegate> test_views_delegate(
new views::DesktopTestViewsDelegate); new views::DesktopTestViewsDelegate);
......
...@@ -20,7 +20,7 @@ ViewsContentClientMainPartsAura::~ViewsContentClientMainPartsAura() { ...@@ -20,7 +20,7 @@ ViewsContentClientMainPartsAura::~ViewsContentClientMainPartsAura() {
void ViewsContentClientMainPartsAura::ToolkitInitialized() { void ViewsContentClientMainPartsAura::ToolkitInitialized() {
ViewsContentClientMainParts::ToolkitInitialized(); ViewsContentClientMainParts::ToolkitInitialized();
wm_state_.reset(new ::wm::WMState); wm_state_ = std::make_unique<::wm::WMState>();
} }
void ViewsContentClientMainPartsAura::PostMainMessageLoopRun() { void ViewsContentClientMainPartsAura::PostMainMessageLoopRun() {
......
...@@ -88,7 +88,8 @@ void ViewsContentMainDelegate::PreCreateMainMessageLoop() { ...@@ -88,7 +88,8 @@ void ViewsContentMainDelegate::PreCreateMainMessageLoop() {
content::ContentBrowserClient* content::ContentBrowserClient*
ViewsContentMainDelegate::CreateContentBrowserClient() { ViewsContentMainDelegate::CreateContentBrowserClient() {
browser_client_.reset(new ViewsContentBrowserClient(views_content_client_)); browser_client_ =
std::make_unique<ViewsContentBrowserClient>(views_content_client_);
return browser_client_.get(); return browser_client_.get();
} }
......
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