| 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 "ui/base/win/window_impl.h" | 5 #include "ui/base/win/window_impl.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // WindowImpl class tracking. | 22 // WindowImpl class tracking. |
| 23 | 23 |
| 24 // Several external scripts rely explicitly on this base class name for | 24 // Several external scripts rely explicitly on this base class name for |
| 25 // acquiring the window handle and will break if this is modified! | 25 // acquiring the window handle and will break if this is modified! |
| 26 // static | 26 // static |
| 27 const wchar_t* const WindowImpl::kBaseClassName = L"Chrome_WidgetWin_"; | 27 const wchar_t* const WindowImpl::kBaseClassName = L"Chrome_WidgetWin_"; |
| 28 | 28 |
| 29 // WindowImpl class information used for registering unique windows. | 29 // WindowImpl class information used for registering unique windows. |
| 30 struct ClassInfo { | 30 struct ClassInfo { |
| 31 UINT style; | 31 UINT style; |
| 32 HBRUSH background; | 32 HICON icon; |
| 33 | 33 |
| 34 explicit ClassInfo(int style) | 34 ClassInfo(int style, HICON icon) |
| 35 : style(style), | 35 : style(style), |
| 36 background(NULL) {} | 36 icon(icon) {} |
| 37 | 37 |
| 38 // Compares two ClassInfos. Returns true if all members match. | 38 // Compares two ClassInfos. Returns true if all members match. |
| 39 bool Equals(const ClassInfo& other) const { | 39 bool Equals(const ClassInfo& other) const { |
| 40 return (other.style == style && other.background == background); | 40 return (other.style == style && other.icon == icon); |
| 41 } | 41 } |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 class ClassRegistrar { | 44 class ClassRegistrar { |
| 45 public: | 45 public: |
| 46 static ClassRegistrar* GetInstance() { | 46 static ClassRegistrar* GetInstance() { |
| 47 return Singleton<ClassRegistrar>::get(); | 47 return Singleton<ClassRegistrar>::get(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 ~ClassRegistrar() { | 50 ~ClassRegistrar() { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 190 |
| 191 WindowImpl* window = reinterpret_cast<WindowImpl*>( | 191 WindowImpl* window = reinterpret_cast<WindowImpl*>( |
| 192 ui::GetWindowUserData(hwnd)); | 192 ui::GetWindowUserData(hwnd)); |
| 193 if (!window) | 193 if (!window) |
| 194 return 0; | 194 return 0; |
| 195 | 195 |
| 196 return window->OnWndProc(message, w_param, l_param); | 196 return window->OnWndProc(message, w_param, l_param); |
| 197 } | 197 } |
| 198 | 198 |
| 199 std::wstring WindowImpl::GetWindowClassName() { | 199 std::wstring WindowImpl::GetWindowClassName() { |
| 200 ClassInfo class_info(initial_class_style()); | 200 HICON icon = GetDefaultWindowIcon(); |
| 201 ClassInfo class_info(initial_class_style(), icon); |
| 201 std::wstring name; | 202 std::wstring name; |
| 202 if (ClassRegistrar::GetInstance()->RetrieveClassName(class_info, &name)) | 203 if (ClassRegistrar::GetInstance()->RetrieveClassName(class_info, &name)) |
| 203 return name; | 204 return name; |
| 204 | 205 |
| 205 HICON icon = GetDefaultWindowIcon(); | |
| 206 | |
| 207 // No class found, need to register one. | 206 // No class found, need to register one. |
| 207 HBRUSH background = NULL; |
| 208 WNDCLASSEX class_ex = { | 208 WNDCLASSEX class_ex = { |
| 209 sizeof(WNDCLASSEX), | 209 sizeof(WNDCLASSEX), |
| 210 class_info.style, | 210 class_info.style, |
| 211 base::win::WrappedWindowProc<&WindowImpl::WndProc>, | 211 base::win::WrappedWindowProc<&WindowImpl::WndProc>, |
| 212 0, | 212 0, |
| 213 0, | 213 0, |
| 214 NULL, | 214 NULL, |
| 215 icon, | 215 icon, |
| 216 NULL, | 216 NULL, |
| 217 reinterpret_cast<HBRUSH>(class_info.background + 1), | 217 reinterpret_cast<HBRUSH>(background + 1), |
| 218 NULL, | 218 NULL, |
| 219 name.c_str(), | 219 name.c_str(), |
| 220 icon | 220 icon |
| 221 }; | 221 }; |
| 222 ATOM atom = RegisterClassEx(&class_ex); | 222 ATOM atom = RegisterClassEx(&class_ex); |
| 223 CHECK(atom) << GetLastError(); | 223 CHECK(atom) << GetLastError(); |
| 224 | 224 |
| 225 ClassRegistrar::GetInstance()->RegisterClass(class_info, name, atom); | 225 ClassRegistrar::GetInstance()->RegisterClass(class_info, name, atom); |
| 226 | 226 |
| 227 return name; | 227 return name; |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace ui | 230 } // namespace ui |
| OLD | NEW |