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