forked from adobe/brackets-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_handler_win.cpp
More file actions
168 lines (136 loc) · 4.92 KB
/
Copy pathclient_handler_win.cpp
File metadata and controls
168 lines (136 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Copyright (c) 2011 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.
#define OS_WIN
#include "config.h"
#include "client_handler.h"
#include <string>
#include "include/cef_browser.h"
#include "include/cef_frame.h"
#include "resource.h"
#include "native_menu_model.h"
#include <ShellAPI.h>
#include "cef_popup_window.h"
#include "cef_main_window.h"
extern cef_main_window* gMainWnd;
// Additional globals
extern HACCEL hAccelTable;
void ClientHandler::OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) {
REQUIRE_UI_THREAD();
}
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) {
REQUIRE_UI_THREAD();
// Set the frame window title bar
CefWindowHandle hwnd = browser->GetHost()->GetWindowHandle();
if (m_BrowserId == browser->GetIdentifier()) {
// The frame window will be the parent of the browser window
hwnd = GetParent(hwnd);
}
SetWindowText(hwnd, std::wstring(title).c_str());
}
void ClientHandler::SendNotification(NotificationType type) {
UINT id;
switch (type) {
case NOTIFY_CONSOLE_MESSAGE:
id = ID_WARN_CONSOLEMESSAGE;
break;
case NOTIFY_DOWNLOAD_COMPLETE:
id = ID_WARN_DOWNLOADCOMPLETE;
break;
case NOTIFY_DOWNLOAD_ERROR:
id = ID_WARN_DOWNLOADERROR;
break;
default:
return;
}
PostMessage(m_MainHwnd, WM_COMMAND, id, 0);
}
void ClientHandler::SetLoading(bool isLoading) {
}
void ClientHandler::SetNavState(bool canGoBack, bool canGoForward) {
}
void ClientHandler::CloseMainWindow() {
::PostMessage(m_MainHwnd, WM_CLOSE, 0, 0);
}
void ClientHandler::PopupCreated(CefRefPtr<CefBrowser> browser)
{
HWND hWnd = browser->GetHost()->GetWindowHandle();
cef_popup_window* pw = new cef_popup_window(browser);
pw->SubclassWindow(hWnd);
}
CefRefPtr<CefBrowser> ClientHandler::GetBrowserForNativeWindow(void* window) {
CefRefPtr<CefBrowser> browser = NULL;
if (window) {
//go through all the browsers looking for a browser within this window
BrowserWindowMap::const_iterator i = browser_window_map_.find((HWND)window);
if (i != browser_window_map_.end()) {
browser = i->second;
}
}
return browser;
}
bool ClientHandler::CanCloseBrowser(CefRefPtr<CefBrowser> browser) {
// On windows, the main browser needs to be destroyed last.
// So, don't allow main browser to be closed until there's
// only 1 browser remaining in the map.
return (browser_window_map_.size() == 1) ||
(browser && browser->GetIdentifier() != m_BrowserId);
}
bool ClientHandler::OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
const CefKeyEvent& event,
CefEventHandle os_event,
bool* is_keyboard_shortcut) {
HWND frameHwnd = (HWND)getMenuParent(browser);
// Don't call ::TranslateAccelerator if we don't have a menu for the current window.
if (!GetMenu(frameHwnd)) {
return false;
}
if (os_event && ::TranslateAccelerator(frameHwnd, hAccelTable, os_event)) {
return true;
}
return false;
}
bool ClientHandler::OnKeyEvent(CefRefPtr<CefBrowser> browser,
const CefKeyEvent& event,
CefEventHandle os_event) {
return false;
}
void ClientHandler::ComputePopupPlacement(CefWindowInfo& windowInfo)
{
// both must be set to work
if (windowInfo.width == CW_USEDEFAULT ||
windowInfo.height == CW_USEDEFAULT) {
// force both vals to be CW_USEDEFAULT in this
// case because Windows doesn't correctly handle
// only one value being is supplied on input
windowInfo.width = CW_USEDEFAULT;
windowInfo.height = CW_USEDEFAULT;
return;
}
RECT rectMainWnd;
gMainWnd->GetWindowRect(&rectMainWnd);
int mW = ::RectWidth(rectMainWnd);
int mH = ::RectHeight(rectMainWnd);
int cW = windowInfo.width;
int cH = windowInfo.height;
windowInfo.x = (rectMainWnd.left + (mW /2)) - (cW / 2);
windowInfo.y = (rectMainWnd.top + (mH /2)) - (cH / 2);
// don't go offscreen
if (windowInfo.x < 0) windowInfo.x = 0;
if (windowInfo.y < 0) windowInfo.y = 0;
HMONITOR hm = ::MonitorFromWindow(gMainWnd->GetSafeWnd(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi = {0};
mi.cbSize = sizeof (mi);
GetMonitorInfo(hm, &mi);
if (windowInfo.width > ::RectWidth(mi.rcWork)) {
windowInfo.x = mi.rcWork.left;
windowInfo.width = mi.rcWork.right - windowInfo.x;
}
if (windowInfo.height > ::RectHeight(mi.rcWork)) {
windowInfo.y = mi.rcWork.top;
windowInfo.height = mi.rcWork.bottom - windowInfo.y;
}
}