OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/shell.h" | 5 #include "content/shell/shell.h" |
6 | 6 |
7 #include <commctrl.h> | 7 #include <commctrl.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <io.h> | 9 #include <io.h> |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 void Shell::PlatformCleanUp() { | 52 void Shell::PlatformCleanUp() { |
53 // When the window is destroyed, tell the Edit field to forget about us, | 53 // When the window is destroyed, tell the Edit field to forget about us, |
54 // otherwise we will crash. | 54 // otherwise we will crash. |
55 ui::SetWindowProc(url_edit_view_, default_edit_wnd_proc_); | 55 ui::SetWindowProc(url_edit_view_, default_edit_wnd_proc_); |
56 ui::SetWindowUserData(url_edit_view_, NULL); | 56 ui::SetWindowUserData(url_edit_view_, NULL); |
57 } | 57 } |
58 | 58 |
59 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { | 59 void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { |
| 60 if (headless_) |
| 61 return; |
60 int id; | 62 int id; |
61 switch (control) { | 63 switch (control) { |
62 case BACK_BUTTON: | 64 case BACK_BUTTON: |
63 id = IDC_NAV_BACK; | 65 id = IDC_NAV_BACK; |
64 break; | 66 break; |
65 case FORWARD_BUTTON: | 67 case FORWARD_BUTTON: |
66 id = IDC_NAV_FORWARD; | 68 id = IDC_NAV_FORWARD; |
67 break; | 69 break; |
68 case STOP_BUTTON: | 70 case STOP_BUTTON: |
69 id = IDC_NAV_STOP; | 71 id = IDC_NAV_STOP; |
70 break; | 72 break; |
71 default: | 73 default: |
72 NOTREACHED() << "Unknown UI control"; | 74 NOTREACHED() << "Unknown UI control"; |
73 return; | 75 return; |
74 } | 76 } |
75 EnableWindow(GetDlgItem(window_, id), is_enabled); | 77 EnableWindow(GetDlgItem(window_, id), is_enabled); |
76 } | 78 } |
77 | 79 |
78 void Shell::PlatformSetAddressBarURL(const GURL& url) { | 80 void Shell::PlatformSetAddressBarURL(const GURL& url) { |
| 81 if (headless_) |
| 82 return; |
79 std::wstring url_string = UTF8ToWide(url.spec()); | 83 std::wstring url_string = UTF8ToWide(url.spec()); |
80 SendMessage(url_edit_view_, WM_SETTEXT, 0, | 84 SendMessage(url_edit_view_, WM_SETTEXT, 0, |
81 reinterpret_cast<LPARAM>(url_string.c_str())); | 85 reinterpret_cast<LPARAM>(url_string.c_str())); |
82 } | 86 } |
83 | 87 |
84 void Shell::PlatformSetIsLoading(bool loading) { | 88 void Shell::PlatformSetIsLoading(bool loading) { |
85 } | 89 } |
86 | 90 |
87 void Shell::PlatformCreateWindow(int width, int height) { | 91 void Shell::PlatformCreateWindow(int width, int height) { |
| 92 if (headless_) |
| 93 return; |
88 window_ = CreateWindow(kWindowClass, kWindowTitle, | 94 window_ = CreateWindow(kWindowClass, kWindowTitle, |
89 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, | 95 WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, |
90 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, | 96 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, |
91 NULL, NULL, instance_handle_, NULL); | 97 NULL, NULL, instance_handle_, NULL); |
92 ui::SetWindowUserData(window_, this); | 98 ui::SetWindowUserData(window_, this); |
93 | 99 |
94 HWND hwnd; | 100 HWND hwnd; |
95 int x = 0; | 101 int x = 0; |
96 | 102 |
97 hwnd = CreateWindow(L"BUTTON", L"Back", | 103 hwnd = CreateWindow(L"BUTTON", L"Back", |
(...skipping 29 matching lines...) Expand all Loading... |
127 default_edit_wnd_proc_ = ui::SetWindowProc(url_edit_view_, | 133 default_edit_wnd_proc_ = ui::SetWindowProc(url_edit_view_, |
128 Shell::EditWndProc); | 134 Shell::EditWndProc); |
129 ui::SetWindowUserData(url_edit_view_, this); | 135 ui::SetWindowUserData(url_edit_view_, this); |
130 | 136 |
131 ShowWindow(window_, SW_SHOW); | 137 ShowWindow(window_, SW_SHOW); |
132 | 138 |
133 SizeTo(width, height); | 139 SizeTo(width, height); |
134 } | 140 } |
135 | 141 |
136 void Shell::PlatformSetContents() { | 142 void Shell::PlatformSetContents() { |
| 143 if (headless_) |
| 144 return; |
137 SetParent(web_contents_->GetView()->GetNativeView(), window_); | 145 SetParent(web_contents_->GetView()->GetNativeView(), window_); |
138 } | 146 } |
139 | 147 |
140 void Shell::SizeTo(int width, int height) { | 148 void Shell::SizeTo(int width, int height) { |
| 149 if (headless_) |
| 150 return; |
141 RECT rc, rw; | 151 RECT rc, rw; |
142 GetClientRect(window_, &rc); | 152 GetClientRect(window_, &rc); |
143 GetWindowRect(window_, &rw); | 153 GetWindowRect(window_, &rw); |
144 | 154 |
145 int client_width = rc.right - rc.left; | 155 int client_width = rc.right - rc.left; |
146 int window_width = rw.right - rw.left; | 156 int window_width = rw.right - rw.left; |
147 window_width = (window_width - client_width) + width; | 157 window_width = (window_width - client_width) + width; |
148 | 158 |
149 int client_height = rc.bottom - rc.top; | 159 int client_height = rc.bottom - rc.top; |
150 int window_height = rw.bottom - rw.top; | 160 int window_height = rw.bottom - rw.top; |
151 window_height = (window_height - client_height) + height; | 161 window_height = (window_height - client_height) + height; |
152 | 162 |
153 // Add space for the url bar. | 163 // Add space for the url bar. |
154 window_height += kURLBarHeight; | 164 window_height += kURLBarHeight; |
155 | 165 |
156 SetWindowPos(window_, NULL, 0, 0, window_width, window_height, | 166 SetWindowPos(window_, NULL, 0, 0, window_width, window_height, |
157 SWP_NOMOVE | SWP_NOZORDER); | 167 SWP_NOMOVE | SWP_NOZORDER); |
158 } | 168 } |
159 | 169 |
160 void Shell::PlatformResizeSubViews() { | 170 void Shell::PlatformResizeSubViews() { |
| 171 if (headless_) |
| 172 return; |
161 RECT rc; | 173 RECT rc; |
162 GetClientRect(window_, &rc); | 174 GetClientRect(window_, &rc); |
163 | 175 |
164 int x = kButtonWidth * 4; | 176 int x = kButtonWidth * 4; |
165 MoveWindow(url_edit_view_, x, 0, rc.right - x, kURLBarHeight, TRUE); | 177 MoveWindow(url_edit_view_, x, 0, rc.right - x, kURLBarHeight, TRUE); |
166 | 178 |
167 MoveWindow(GetContentView(), 0, kURLBarHeight, rc.right, | 179 MoveWindow(GetContentView(), 0, kURLBarHeight, rc.right, |
168 rc.bottom - kURLBarHeight, TRUE); | 180 rc.bottom - kURLBarHeight, TRUE); |
169 } | 181 } |
170 | 182 |
171 void Shell::Close() { | 183 void Shell::Close() { |
| 184 if (headless_) { |
| 185 delete this; |
| 186 return; |
| 187 } |
172 DestroyWindow(window_); | 188 DestroyWindow(window_); |
173 } | 189 } |
174 | 190 |
175 ATOM Shell::RegisterWindowClass() { | 191 ATOM Shell::RegisterWindowClass() { |
176 WNDCLASSEX window_class; | 192 WNDCLASSEX window_class; |
177 base::win::InitializeWindowClass( | 193 base::win::InitializeWindowClass( |
178 kWindowClass, | 194 kWindowClass, |
179 &Shell::WndProc, | 195 &Shell::WndProc, |
180 CS_HREDRAW | CS_VREDRAW, | 196 CS_HREDRAW | CS_VREDRAW, |
181 0, | 197 0, |
(...skipping 10 matching lines...) Expand all Loading... |
192 | 208 |
193 LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, | 209 LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, |
194 LPARAM lParam) { | 210 LPARAM lParam) { |
195 Shell* shell = static_cast<Shell*>(ui::GetWindowUserData(hwnd)); | 211 Shell* shell = static_cast<Shell*>(ui::GetWindowUserData(hwnd)); |
196 | 212 |
197 switch (message) { | 213 switch (message) { |
198 case WM_COMMAND: { | 214 case WM_COMMAND: { |
199 int id = LOWORD(wParam); | 215 int id = LOWORD(wParam); |
200 switch (id) { | 216 switch (id) { |
201 case IDM_NEW_WINDOW: | 217 case IDM_NEW_WINDOW: |
| 218 if (shell->headless_) |
| 219 return 0; |
202 CreateNewWindow( | 220 CreateNewWindow( |
203 shell->web_contents()->GetBrowserContext(), | 221 shell->web_contents()->GetBrowserContext(), |
204 GURL(), NULL, MSG_ROUTING_NONE, gfx::Size()); | 222 GURL(), NULL, MSG_ROUTING_NONE, gfx::Size()); |
205 break; | 223 break; |
206 case IDM_CLOSE_WINDOW: | 224 case IDM_CLOSE_WINDOW: |
207 DestroyWindow(hwnd); | 225 DestroyWindow(hwnd); |
208 break; | 226 break; |
209 case IDM_EXIT: | 227 case IDM_EXIT: |
210 PlatformExit(); | 228 PlatformExit(); |
211 break; | 229 break; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 290 |
273 return 0; | 291 return 0; |
274 } | 292 } |
275 } | 293 } |
276 | 294 |
277 return CallWindowProc(shell->default_edit_wnd_proc_, hwnd, message, wParam, | 295 return CallWindowProc(shell->default_edit_wnd_proc_, hwnd, message, wParam, |
278 lParam); | 296 lParam); |
279 } | 297 } |
280 | 298 |
281 void Shell::PlatformSetTitle(const string16& text) { | 299 void Shell::PlatformSetTitle(const string16& text) { |
| 300 if (headless_) |
| 301 return; |
282 ::SetWindowText(window_, text.c_str()); | 302 ::SetWindowText(window_, text.c_str()); |
283 } | 303 } |
284 | 304 |
285 } // namespace content | 305 } // namespace content |
OLD | NEW |