• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
2// reserved. Use of this source code is governed by a BSD-style license that
3// can be found in the LICENSE file.
4
5#include "tests/cefclient/browser/window_test_runner_mac.h"
6
7#import <Cocoa/Cocoa.h>
8
9#include "include/wrapper/cef_helpers.h"
10#include "tests/shared/browser/main_message_loop.h"
11
12namespace client {
13namespace window_test {
14
15namespace {
16
17NSWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
18  NSView* view =
19      CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(browser->GetHost()->GetWindowHandle());
20  return [view window];
21}
22
23}  // namespace
24
25WindowTestRunnerMac::WindowTestRunnerMac() {}
26
27void WindowTestRunnerMac::SetPos(CefRefPtr<CefBrowser> browser,
28                                 int x,
29                                 int y,
30                                 int width,
31                                 int height) {
32  CEF_REQUIRE_UI_THREAD();
33  REQUIRE_MAIN_THREAD();
34
35  NSWindow* window = GetWindow(browser);
36
37  // Make sure the window isn't minimized or maximized.
38  if ([window isMiniaturized])
39    [window deminiaturize:nil];
40  else if ([window isZoomed])
41    [window performZoom:nil];
42
43  // Retrieve information for the display that contains the window.
44  NSScreen* screen = [window screen];
45  if (screen == nil)
46    screen = [NSScreen mainScreen];
47  NSRect frame = [screen frame];
48  NSRect visibleFrame = [screen visibleFrame];
49
50  // Make sure the window is inside the display.
51  CefRect display_rect(
52      visibleFrame.origin.x,
53      frame.size.height - visibleFrame.size.height - visibleFrame.origin.y,
54      visibleFrame.size.width, visibleFrame.size.height);
55  CefRect window_rect(x, y, width, height);
56  ModifyBounds(display_rect, window_rect);
57
58  NSRect newRect;
59  newRect.origin.x = window_rect.x;
60  newRect.origin.y = frame.size.height - window_rect.height - window_rect.y;
61  newRect.size.width = window_rect.width;
62  newRect.size.height = window_rect.height;
63  [window setFrame:newRect display:YES];
64}
65
66void WindowTestRunnerMac::Minimize(CefRefPtr<CefBrowser> browser) {
67  CEF_REQUIRE_UI_THREAD();
68  REQUIRE_MAIN_THREAD();
69
70  [GetWindow(browser) performMiniaturize:nil];
71}
72
73void WindowTestRunnerMac::Maximize(CefRefPtr<CefBrowser> browser) {
74  CEF_REQUIRE_UI_THREAD();
75  REQUIRE_MAIN_THREAD();
76
77  [GetWindow(browser) performZoom:nil];
78}
79
80void WindowTestRunnerMac::Restore(CefRefPtr<CefBrowser> browser) {
81  CEF_REQUIRE_UI_THREAD();
82  REQUIRE_MAIN_THREAD();
83
84  NSWindow* window = GetWindow(browser);
85  if ([window isMiniaturized])
86    [window deminiaturize:nil];
87  else if ([window isZoomed])
88    [window performZoom:nil];
89}
90
91}  // namespace window_test
92}  // namespace client
93