| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/win/window_impl.h" | 9 #include "ui/gfx/win/window_impl.h" |
| 10 | 10 |
| 11 namespace ui { | 11 namespace ui { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class TestWindow : public gfx::WindowImpl { | 15 class TestWindow : public gfx::WindowImpl { |
| 16 public: | 16 public: |
| 17 TestWindow() : saw_message(false) {} | 17 TestWindow() : saw_message(false) {} |
| 18 virtual ~TestWindow() {} | 18 virtual ~TestWindow() {} |
| 19 | 19 |
| 20 bool saw_message; | 20 bool saw_message; |
| 21 | 21 |
| 22 private: | 22 private: |
| 23 // Overridden from gfx::WindowImpl: | 23 // Overridden from gfx::WindowImpl: |
| 24 virtual BOOL ProcessWindowMessage(HWND window, | 24 virtual BOOL ProcessWindowMessage(HWND window, |
| 25 UINT message, | 25 UINT message, |
| 26 WPARAM w_param, | 26 WPARAM w_param, |
| 27 LPARAM l_param, | 27 LPARAM l_param, |
| 28 LRESULT& result, | 28 LRESULT& result, |
| 29 DWORD msg_map_id) OVERRIDE { | 29 DWORD msg_map_id) override { |
| 30 if (message == WM_NCHITTEST) | 30 if (message == WM_NCHITTEST) |
| 31 saw_message = true; | 31 saw_message = true; |
| 32 | 32 |
| 33 return FALSE; // Results in DefWindowProc(). | 33 return FALSE; // Results in DefWindowProc(). |
| 34 } | 34 } |
| 35 | 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(TestWindow); | 36 DISALLOW_COPY_AND_ASSIGN(TestWindow); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class TestMessageFilter : public HWNDMessageFilter { | 39 class TestMessageFilter : public HWNDMessageFilter { |
| 40 public: | 40 public: |
| 41 TestMessageFilter() : consume_messages(false), saw_message(false) {} | 41 TestMessageFilter() : consume_messages(false), saw_message(false) {} |
| 42 virtual ~TestMessageFilter() {} | 42 virtual ~TestMessageFilter() {} |
| 43 | 43 |
| 44 // Setting to true causes the filter subclass to stop messages from reaching | 44 // Setting to true causes the filter subclass to stop messages from reaching |
| 45 // the subclassed window procedure. | 45 // the subclassed window procedure. |
| 46 bool consume_messages; | 46 bool consume_messages; |
| 47 | 47 |
| 48 // True if the message filter saw the message. | 48 // True if the message filter saw the message. |
| 49 bool saw_message; | 49 bool saw_message; |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // Overridden from HWNDMessageFilter: | 52 // Overridden from HWNDMessageFilter: |
| 53 virtual bool FilterMessage(HWND hwnd, | 53 virtual bool FilterMessage(HWND hwnd, |
| 54 UINT message, | 54 UINT message, |
| 55 WPARAM w_param, | 55 WPARAM w_param, |
| 56 LPARAM l_param, | 56 LPARAM l_param, |
| 57 LRESULT* l_result) OVERRIDE { | 57 LRESULT* l_result) override { |
| 58 if (message == WM_NCHITTEST) { | 58 if (message == WM_NCHITTEST) { |
| 59 saw_message = true; | 59 saw_message = true; |
| 60 return consume_messages; | 60 return consume_messages; |
| 61 } | 61 } |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(TestMessageFilter); | 65 DISALLOW_COPY_AND_ASSIGN(TestMessageFilter); |
| 66 }; | 66 }; |
| 67 | 67 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // Remove a filter and try sending message again. | 153 // Remove a filter and try sending message again. |
| 154 HWNDSubclass::RemoveFilterFromAllTargets(&mf1); | 154 HWNDSubclass::RemoveFilterFromAllTargets(&mf1); |
| 155 ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0); | 155 ::SendMessage(window.hwnd(), WM_NCHITTEST, 0, 0); |
| 156 EXPECT_FALSE(mf1.saw_message); | 156 EXPECT_FALSE(mf1.saw_message); |
| 157 EXPECT_TRUE(mf2.saw_message); | 157 EXPECT_TRUE(mf2.saw_message); |
| 158 EXPECT_TRUE(window.saw_message); | 158 EXPECT_TRUE(window.saw_message); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace ui | 162 } // namespace ui |
| OLD | NEW |