2013-04-01 19:57:28 +02:00
|
|
|
// 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.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/window_test_runner_mac.h"
|
2013-04-01 19:57:28 +02:00
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
namespace client {
|
2013-04-01 19:57:28 +02:00
|
|
|
namespace window_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
NSWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
|
2019-04-23 19:17:56 +02:00
|
|
|
NSView* view =
|
|
|
|
CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(browser->GetHost()->GetWindowHandle());
|
2013-04-01 19:57:28 +02:00
|
|
|
return [view window];
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
WindowTestRunnerMac::WindowTestRunnerMac() {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
void WindowTestRunnerMac::SetPos(CefRefPtr<CefBrowser> browser,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2016-01-19 21:09:01 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
NSWindow* window = GetWindow(browser);
|
2013-04-01 19:57:28 +02:00
|
|
|
|
|
|
|
// Make sure the window isn't minimized or maximized.
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([window isMiniaturized]) {
|
2013-04-01 19:57:28 +02:00
|
|
|
[window deminiaturize:nil];
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if ([window isZoomed]) {
|
2013-04-01 19:57:28 +02:00
|
|
|
[window performZoom:nil];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-04-01 19:57:28 +02:00
|
|
|
|
|
|
|
// Retrieve information for the display that contains the window.
|
|
|
|
NSScreen* screen = [window screen];
|
2023-01-02 23:59:03 +01:00
|
|
|
if (screen == nil) {
|
2013-04-01 19:57:28 +02:00
|
|
|
screen = [NSScreen mainScreen];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-04-01 19:57:28 +02:00
|
|
|
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,
|
2017-05-17 11:29:28 +02:00
|
|
|
visibleFrame.size.width, visibleFrame.size.height);
|
2013-04-01 19:57:28 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void WindowTestRunnerMac::Minimize(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
[GetWindow(browser) performMiniaturize:nil];
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void WindowTestRunnerMac::Maximize(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
[GetWindow(browser) performZoom:nil];
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void WindowTestRunnerMac::Restore(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
REQUIRE_MAIN_THREAD();
|
|
|
|
|
2015-01-22 21:21:21 +01:00
|
|
|
NSWindow* window = GetWindow(browser);
|
2023-01-02 23:59:03 +01:00
|
|
|
if ([window isMiniaturized]) {
|
2013-04-01 19:57:28 +02:00
|
|
|
[window deminiaturize:nil];
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if ([window isZoomed]) {
|
2013-04-01 19:57:28 +02:00
|
|
|
[window performZoom:nil];
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2013-04-01 19:57:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace window_test
|
2015-01-22 21:21:21 +01:00
|
|
|
} // namespace client
|