cef/tests/cefclient/browser/window_test_runner_mac.mm
Jesper Papmehl-Dufay 019611c764 macOS: Add support for building clients with ARC enabled (fixes issue #2623).
Under ARC (Automatic Reference Counting), assigning to an Objective-C
pointer has different semantics than assigning to a void* pointer.
This makes it dangerous to treat the same memory address as an
Objective-C pointer in some cases and as a "regular C pointer" in
other cases.

This change removes the conditional type defines and instead uses
void* everywhere. Explicit type casting in combination with ARC
annotations makes it safe to get typed Objective-C pointers from the
void* pointers.

This change enables ARC by default in the CEF binary distribution CMake
configuration for the cefclient and cefsimple sample applications. It can be
disabled by adding `-DOPTION_USE_ARC=Off` to the CMake command line.

ARC is not supported when building Chromium due to the substantial
number of changes that would be required in the Chromium code base.
2019-04-23 17:17:56 +00:00

93 lines
2.6 KiB
Plaintext

// Copyright (c) 2013 The Chromium Embedded Framework 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 "tests/cefclient/browser/window_test_runner_mac.h"
#import <Cocoa/Cocoa.h>
#include "include/wrapper/cef_helpers.h"
#include "tests/shared/browser/main_message_loop.h"
namespace client {
namespace window_test {
namespace {
NSWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
NSView* view =
CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(browser->GetHost()->GetWindowHandle());
return [view window];
}
} // namespace
WindowTestRunnerMac::WindowTestRunnerMac() {}
void WindowTestRunnerMac::SetPos(CefRefPtr<CefBrowser> browser,
int x,
int y,
int width,
int height) {
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
NSWindow* window = GetWindow(browser);
// Make sure the window isn't minimized or maximized.
if ([window isMiniaturized])
[window deminiaturize:nil];
else if ([window isZoomed])
[window performZoom:nil];
// Retrieve information for the display that contains the window.
NSScreen* screen = [window screen];
if (screen == nil)
screen = [NSScreen mainScreen];
NSRect frame = [screen frame];
NSRect visibleFrame = [screen visibleFrame];
// Make sure the window is inside the display.
CefRect display_rect(
visibleFrame.origin.x,
frame.size.height - visibleFrame.size.height - visibleFrame.origin.y,
visibleFrame.size.width, visibleFrame.size.height);
CefRect window_rect(x, y, width, height);
ModifyBounds(display_rect, window_rect);
NSRect newRect;
newRect.origin.x = window_rect.x;
newRect.origin.y = frame.size.height - window_rect.height - window_rect.y;
newRect.size.width = window_rect.width;
newRect.size.height = window_rect.height;
[window setFrame:newRect display:YES];
}
void WindowTestRunnerMac::Minimize(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
[GetWindow(browser) performMiniaturize:nil];
}
void WindowTestRunnerMac::Maximize(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
[GetWindow(browser) performZoom:nil];
}
void WindowTestRunnerMac::Restore(CefRefPtr<CefBrowser> browser) {
CEF_REQUIRE_UI_THREAD();
REQUIRE_MAIN_THREAD();
NSWindow* window = GetWindow(browser);
if ([window isMiniaturized])
[window deminiaturize:nil];
else if ([window isZoomed])
[window performZoom:nil];
}
} // namespace window_test
} // namespace client