| 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/hwnd_subclass.h" | 5 #include "ui/base/win/hwnd_subclass.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 namespace ui { | 51 namespace ui { |
| 52 | 52 |
| 53 // Singleton factory that creates and manages the lifetime of all | 53 // Singleton factory that creates and manages the lifetime of all |
| 54 // ui::HWNDSubclass objects. | 54 // ui::HWNDSubclass objects. |
| 55 class HWNDSubclass::HWNDSubclassFactory { | 55 class HWNDSubclass::HWNDSubclassFactory { |
| 56 public: | 56 public: |
| 57 static HWNDSubclassFactory* GetInstance() { | 57 static HWNDSubclassFactory* GetInstance() { |
| 58 return Singleton<HWNDSubclassFactory, | 58 return base::Singleton< |
| 59 LeakySingletonTraits<HWNDSubclassFactory> >::get(); | 59 HWNDSubclassFactory, |
| 60 base::LeakySingletonTraits<HWNDSubclassFactory>>::get(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Returns a non-null HWNDSubclass corresponding to the HWND |target|. Creates | 63 // Returns a non-null HWNDSubclass corresponding to the HWND |target|. Creates |
| 63 // one if none exists. Retains ownership of the returned pointer. | 64 // one if none exists. Retains ownership of the returned pointer. |
| 64 HWNDSubclass* GetHwndSubclassForTarget(HWND target) { | 65 HWNDSubclass* GetHwndSubclassForTarget(HWND target) { |
| 65 DCHECK(target); | 66 DCHECK(target); |
| 66 HWNDSubclass* subclass = reinterpret_cast<HWNDSubclass*>( | 67 HWNDSubclass* subclass = reinterpret_cast<HWNDSubclass*>( |
| 67 ui::ViewProp::GetValue(target, kHWNDSubclassKey)); | 68 ui::ViewProp::GetValue(target, kHWNDSubclassKey)); |
| 68 if (!subclass) { | 69 if (!subclass) { |
| 69 subclass = new ui::HWNDSubclass(target); | 70 subclass = new ui::HWNDSubclass(target); |
| 70 hwnd_subclasses_.push_back(subclass); | 71 hwnd_subclasses_.push_back(subclass); |
| 71 } | 72 } |
| 72 return subclass; | 73 return subclass; |
| 73 } | 74 } |
| 74 | 75 |
| 75 const ScopedVector<HWNDSubclass>& hwnd_subclasses() { | 76 const ScopedVector<HWNDSubclass>& hwnd_subclasses() { |
| 76 return hwnd_subclasses_; | 77 return hwnd_subclasses_; |
| 77 } | 78 } |
| 78 | 79 |
| 79 private: | 80 private: |
| 80 friend struct DefaultSingletonTraits<HWNDSubclassFactory>; | 81 friend struct base::DefaultSingletonTraits<HWNDSubclassFactory>; |
| 81 | 82 |
| 82 HWNDSubclassFactory() {} | 83 HWNDSubclassFactory() {} |
| 83 | 84 |
| 84 ScopedVector<HWNDSubclass> hwnd_subclasses_; | 85 ScopedVector<HWNDSubclass> hwnd_subclasses_; |
| 85 | 86 |
| 86 DISALLOW_COPY_AND_ASSIGN(HWNDSubclassFactory); | 87 DISALLOW_COPY_AND_ASSIGN(HWNDSubclassFactory); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 void HWNDSubclass::AddFilterToTarget(HWND target, HWNDMessageFilter* filter) { | 91 void HWNDSubclass::AddFilterToTarget(HWND target, HWNDMessageFilter* filter) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 // In most cases, |original_wnd_proc_| will take care of calling | 162 // In most cases, |original_wnd_proc_| will take care of calling |
| 162 // DefWindowProc. | 163 // DefWindowProc. |
| 163 return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); | 164 return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); |
| 164 } | 165 } |
| 165 | 166 |
| 166 HWNDMessageFilter::~HWNDMessageFilter() { | 167 HWNDMessageFilter::~HWNDMessageFilter() { |
| 167 HWNDSubclass::RemoveFilterFromAllTargets(this); | 168 HWNDSubclass::RemoveFilterFromAllTargets(this); |
| 168 } | 169 } |
| 169 | 170 |
| 170 } // namespace ui | 171 } // namespace ui |
| OLD | NEW |