| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "gfx/window_impl.h" | 5 #include "gfx/window_impl.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/singleton.h" | 9 #include "base/singleton.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 background(NULL) {} | 35 background(NULL) {} |
| 36 | 36 |
| 37 // Compares two ClassInfos. Returns true if all members match. | 37 // Compares two ClassInfos. Returns true if all members match. |
| 38 bool Equals(const ClassInfo& other) const { | 38 bool Equals(const ClassInfo& other) const { |
| 39 return (other.style == style && other.background == background); | 39 return (other.style == style && other.background == background); |
| 40 } | 40 } |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 class ClassRegistrar { | 43 class ClassRegistrar { |
| 44 public: | 44 public: |
| 45 static ClassRegistrar* GetInstance() { |
| 46 return Singleton<ClassRegistrar>::get(); |
| 47 } |
| 48 |
| 45 ~ClassRegistrar() { | 49 ~ClassRegistrar() { |
| 46 for (RegisteredClasses::iterator i = registered_classes_.begin(); | 50 for (RegisteredClasses::iterator i = registered_classes_.begin(); |
| 47 i != registered_classes_.end(); ++i) { | 51 i != registered_classes_.end(); ++i) { |
| 48 UnregisterClass(i->name.c_str(), NULL); | 52 UnregisterClass(i->name.c_str(), NULL); |
| 49 } | 53 } |
| 50 } | 54 } |
| 51 | 55 |
| 52 // Puts the name for the class matching |class_info| in |class_name|, creating | 56 // Puts the name for the class matching |class_info| in |class_name|, creating |
| 53 // a new name if the class is not yet known. | 57 // a new name if the class is not yet known. |
| 54 // Returns true if this class was already known, false otherwise. | 58 // Returns true if this class was already known, false otherwise. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 win_util::GetWindowUserData(hwnd)); | 195 win_util::GetWindowUserData(hwnd)); |
| 192 if (!window) | 196 if (!window) |
| 193 return 0; | 197 return 0; |
| 194 | 198 |
| 195 return window->OnWndProc(message, w_param, l_param); | 199 return window->OnWndProc(message, w_param, l_param); |
| 196 } | 200 } |
| 197 | 201 |
| 198 std::wstring WindowImpl::GetWindowClassName() { | 202 std::wstring WindowImpl::GetWindowClassName() { |
| 199 ClassInfo class_info(initial_class_style()); | 203 ClassInfo class_info(initial_class_style()); |
| 200 std::wstring name; | 204 std::wstring name; |
| 201 if (Singleton<ClassRegistrar>()->RetrieveClassName(class_info, &name)) | 205 if (ClassRegistrar::GetInstance()->RetrieveClassName(class_info, &name)) |
| 202 return name; | 206 return name; |
| 203 | 207 |
| 204 // No class found, need to register one. | 208 // No class found, need to register one. |
| 205 WNDCLASSEX class_ex; | 209 WNDCLASSEX class_ex; |
| 206 class_ex.cbSize = sizeof(WNDCLASSEX); | 210 class_ex.cbSize = sizeof(WNDCLASSEX); |
| 207 class_ex.style = class_info.style; | 211 class_ex.style = class_info.style; |
| 208 class_ex.lpfnWndProc = &WindowImpl::WndProc; | 212 class_ex.lpfnWndProc = &WindowImpl::WndProc; |
| 209 class_ex.cbClsExtra = 0; | 213 class_ex.cbClsExtra = 0; |
| 210 class_ex.cbWndExtra = 0; | 214 class_ex.cbWndExtra = 0; |
| 211 class_ex.hInstance = NULL; | 215 class_ex.hInstance = NULL; |
| 212 class_ex.hIcon = GetDefaultWindowIcon(); | 216 class_ex.hIcon = GetDefaultWindowIcon(); |
| 213 class_ex.hCursor = LoadCursor(NULL, IDC_ARROW); | 217 class_ex.hCursor = LoadCursor(NULL, IDC_ARROW); |
| 214 class_ex.hbrBackground = reinterpret_cast<HBRUSH>(class_info.background + 1); | 218 class_ex.hbrBackground = reinterpret_cast<HBRUSH>(class_info.background + 1); |
| 215 class_ex.lpszMenuName = NULL; | 219 class_ex.lpszMenuName = NULL; |
| 216 class_ex.lpszClassName = name.c_str(); | 220 class_ex.lpszClassName = name.c_str(); |
| 217 class_ex.hIconSm = class_ex.hIcon; | 221 class_ex.hIconSm = class_ex.hIcon; |
| 218 ATOM atom = RegisterClassEx(&class_ex); | 222 ATOM atom = RegisterClassEx(&class_ex); |
| 219 DCHECK(atom); | 223 DCHECK(atom); |
| 220 | 224 |
| 221 Singleton<ClassRegistrar>()->RegisterClass(class_info, name, atom); | 225 Singleton<ClassRegistrar>()->RegisterClass(class_info, name, atom); |
| 222 | 226 |
| 223 return name; | 227 return name; |
| 224 } | 228 } |
| 225 | 229 |
| 226 } // namespace gfx | 230 } // namespace gfx |
| OLD | NEW |