| Index: chrome/views/widget/widget_win.cc
|
| ===================================================================
|
| --- chrome/views/widget/widget_win.cc (revision 14503)
|
| +++ chrome/views/widget/widget_win.cc (working copy)
|
| @@ -42,13 +42,6 @@
|
| ::GetProp(hwnd, NativeControlWin::kNativeControlWinKey));
|
| }
|
|
|
| -// Used to locate the WidgetWin issuing the current Create. Only valid for the
|
| -// life of Create.
|
| -//
|
| -// This obviously assumes we only create WidgetWins from the same thread,
|
| -// which is currently the case.
|
| -static WidgetWin* instance_issuing_create = NULL;
|
| -
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // Window class tracking.
|
|
|
| @@ -66,37 +59,76 @@
|
| background(NULL) {}
|
|
|
| // Compares two ClassInfos. Returns true if all members match.
|
| - bool Equals(const ClassInfo& other) {
|
| + bool Equals(const ClassInfo& other) const {
|
| return (other.style == style && other.background == background);
|
| }
|
| };
|
|
|
| -// Represents a registered window class.
|
| -struct RegisteredClass {
|
| - RegisteredClass(const ClassInfo& info,
|
| - const std::wstring& name,
|
| - ATOM atom)
|
| - : info(info),
|
| - name(name),
|
| - atom(atom) {
|
| +class ClassRegistrar {
|
| + public:
|
| + ~ClassRegistrar() {
|
| + for (RegisteredClasses::iterator i = registered_classes_.begin();
|
| + i != registered_classes_.end(); ++i) {
|
| + UnregisterClass(i->name.c_str(), NULL);
|
| + }
|
| }
|
|
|
| - // Info used to create the class.
|
| - ClassInfo info;
|
| + // Puts the name for the class matching |class_info| in |class_name|, creating
|
| + // a new name if the class is not yet known.
|
| + // Returns true if this class was already known, false otherwise.
|
| + bool RetrieveClassName(const ClassInfo& class_info, std::wstring* name) {
|
| + for (RegisteredClasses::const_iterator i = registered_classes_.begin();
|
| + i != registered_classes_.end(); ++i) {
|
| + if (class_info.Equals(i->info)) {
|
| + name->assign(i->name);
|
| + return true;
|
| + }
|
| + }
|
|
|
| - // The name given to the window.
|
| - std::wstring name;
|
| + name->assign(std::wstring(WidgetWin::kBaseClassName) +
|
| + IntToWString(registered_count_++));
|
| + return false;
|
| + }
|
|
|
| - // The ATOM returned from creating the window.
|
| - ATOM atom;
|
| -};
|
| + void RegisterClass(const ClassInfo& class_info,
|
| + const std::wstring& name,
|
| + ATOM atom) {
|
| + registered_classes_.push_back(RegisteredClass(class_info, name, atom));
|
| + }
|
|
|
| -typedef std::list<RegisteredClass> RegisteredClasses;
|
| + private:
|
| + // Represents a registered window class.
|
| + struct RegisteredClass {
|
| + RegisteredClass(const ClassInfo& info,
|
| + const std::wstring& name,
|
| + ATOM atom)
|
| + : info(info),
|
| + name(name),
|
| + atom(atom) {
|
| + }
|
|
|
| -// The list of registered classes.
|
| -static RegisteredClasses* registered_classes = NULL;
|
| + // Info used to create the class.
|
| + ClassInfo info;
|
|
|
| + // The name given to the window.
|
| + std::wstring name;
|
|
|
| + // The ATOM returned from creating the window.
|
| + ATOM atom;
|
| + };
|
| +
|
| + ClassRegistrar() : registered_count_(0) { }
|
| + friend struct DefaultSingletonTraits<ClassRegistrar>;
|
| +
|
| + typedef std::list<RegisteredClass> RegisteredClasses;
|
| + RegisteredClasses registered_classes_;
|
| +
|
| + // Counter of how many classes have ben registered so far.
|
| + int registered_count_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ClassRegistrar);
|
| +};
|
| +
|
| ///////////////////////////////////////////////////////////////////////////////
|
| // WidgetWin, public
|
|
|
| @@ -855,19 +887,12 @@
|
| }
|
|
|
| std::wstring WidgetWin::GetWindowClassName() {
|
| - if (!registered_classes)
|
| - registered_classes = new RegisteredClasses();
|
| ClassInfo class_info(initial_class_style());
|
| - for (RegisteredClasses::iterator i = registered_classes->begin();
|
| - i != registered_classes->end(); ++i) {
|
| - if (class_info.Equals(i->info))
|
| - return i->name;
|
| - }
|
| + std::wstring name;
|
| + if (Singleton<ClassRegistrar>()->RetrieveClassName(class_info, &name))
|
| + return name;
|
|
|
| // No class found, need to register one.
|
| - static int registered_count = 0;
|
| - std::wstring name =
|
| - std::wstring(kBaseClassName) + IntToWString(registered_count++);
|
| WNDCLASSEX class_ex;
|
| class_ex.cbSize = sizeof(WNDCLASSEX);
|
| class_ex.style = class_info.style;
|
| @@ -884,8 +909,9 @@
|
| class_ex.hIconSm = class_ex.hIcon;
|
| ATOM atom = RegisterClassEx(&class_ex);
|
| DCHECK(atom);
|
| - RegisteredClass registered_class(class_info, name, atom);
|
| - registered_classes->push_back(registered_class);
|
| +
|
| + Singleton<ClassRegistrar>()->RegisterClass(class_info, name, atom);
|
| +
|
| return name;
|
| }
|
|
|
|
|