• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2015 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/browser_window_std_mac.h"
6
7#include <Cocoa/Cocoa.h>
8
9#include "include/base/cef_logging.h"
10#include "tests/cefclient/browser/client_handler_std.h"
11#include "tests/shared/browser/main_message_loop.h"
12
13namespace client {
14
15BrowserWindowStdMac::BrowserWindowStdMac(Delegate* delegate,
16                                         const std::string& startup_url)
17    : BrowserWindow(delegate) {
18  client_handler_ = new ClientHandlerStd(this, startup_url);
19}
20
21void BrowserWindowStdMac::CreateBrowser(
22    ClientWindowHandle parent_handle,
23    const CefRect& rect,
24    const CefBrowserSettings& settings,
25    CefRefPtr<CefDictionaryValue> extra_info,
26    CefRefPtr<CefRequestContext> request_context) {
27  REQUIRE_MAIN_THREAD();
28
29  CefWindowInfo window_info;
30  window_info.SetAsChild(parent_handle, rect);
31
32  CefBrowserHost::CreateBrowser(window_info, client_handler_,
33                                client_handler_->startup_url(), settings,
34                                extra_info, request_context);
35}
36
37void BrowserWindowStdMac::GetPopupConfig(CefWindowHandle temp_handle,
38                                         CefWindowInfo& windowInfo,
39                                         CefRefPtr<CefClient>& client,
40                                         CefBrowserSettings& settings) {
41  CEF_REQUIRE_UI_THREAD();
42
43  // The window will be properly sized after the browser is created.
44  windowInfo.SetAsChild(temp_handle, CefRect());
45  client = client_handler_;
46}
47
48void BrowserWindowStdMac::ShowPopup(ClientWindowHandle parent_handle,
49                                    int x,
50                                    int y,
51                                    size_t width,
52                                    size_t height) {
53  REQUIRE_MAIN_THREAD();
54
55  NSView* browser_view = CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(GetWindowHandle());
56
57  // Re-parent |browser_view| to |parent_handle|.
58  [browser_view removeFromSuperview];
59  [CAST_CEF_WINDOW_HANDLE_TO_NSVIEW(parent_handle) addSubview:browser_view];
60
61  NSSize size = NSMakeSize(static_cast<int>(width), static_cast<int>(height));
62  [browser_view setFrameSize:size];
63}
64
65void BrowserWindowStdMac::Show() {
66  REQUIRE_MAIN_THREAD();
67  // Nothing to do here. Chromium internally handles window show/hide.
68}
69
70void BrowserWindowStdMac::Hide() {
71  REQUIRE_MAIN_THREAD();
72  // Nothing to do here. Chromium internally handles window show/hide.
73}
74
75void BrowserWindowStdMac::SetBounds(int x, int y, size_t width, size_t height) {
76  REQUIRE_MAIN_THREAD();
77  // Nothing to do here. Cocoa will size the browser for us.
78}
79
80void BrowserWindowStdMac::SetFocus(bool focus) {
81  REQUIRE_MAIN_THREAD();
82  // Nothing to do here. Chromium internally handles window focus assignment.
83}
84
85ClientWindowHandle BrowserWindowStdMac::GetWindowHandle() const {
86  REQUIRE_MAIN_THREAD();
87
88  if (browser_)
89    return browser_->GetHost()->GetWindowHandle();
90  return nullptr;
91}
92
93}  // namespace client
94