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 "views/widget/widget_win.h" | 5 #include "views/widget/widget_win.h" |
6 | 6 |
7 #include "app/keyboard_code_conversion_win.h" | 7 #include "app/keyboard_code_conversion_win.h" |
8 #include "app/l10n_util_win.h" | 8 #include "app/l10n_util_win.h" |
9 #include "app/system_monitor.h" | 9 #include "app/system_monitor.h" |
10 #include "app/win_util.h" | 10 #include "app/win_util.h" |
11 #include "app/win/scoped_prop.h" | 11 #include "app/win/scoped_prop.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/win_util.h" | 13 #include "base/win_util.h" |
14 #include "gfx/canvas_skia.h" | 14 #include "gfx/canvas_skia.h" |
15 #include "gfx/native_theme_win.h" | 15 #include "gfx/native_theme_win.h" |
16 #include "gfx/path.h" | 16 #include "gfx/path.h" |
17 #include "views/accessibility/view_accessibility.h" | 17 #include "views/accessibility/view_accessibility.h" |
18 #include "views/controls/native_control_win.h" | 18 #include "views/controls/native_control_win.h" |
19 #include "views/focus/focus_util_win.h" | 19 #include "views/focus/focus_util_win.h" |
20 #include "views/views_delegate.h" | 20 #include "views/views_delegate.h" |
21 #include "views/widget/aero_tooltip_manager.h" | 21 #include "views/widget/aero_tooltip_manager.h" |
| 22 #include "views/widget/child_window_message_processor.h" |
22 #include "views/widget/default_theme_provider.h" | 23 #include "views/widget/default_theme_provider.h" |
23 #include "views/widget/drop_target_win.h" | 24 #include "views/widget/drop_target_win.h" |
24 #include "views/widget/root_view.h" | 25 #include "views/widget/root_view.h" |
25 #include "views/widget/widget_delegate.h" | 26 #include "views/widget/widget_delegate.h" |
26 #include "views/window/window_win.h" | 27 #include "views/window/window_win.h" |
27 | 28 |
28 namespace views { | 29 namespace views { |
29 | 30 |
30 // Property used to link the HWND to its RootView. | 31 // Property used to link the HWND to its RootView. |
31 static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; | 32 static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__"; |
32 static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__"; | 33 static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__"; |
33 | 34 |
34 bool WidgetWin::screen_reader_active_ = false; | 35 bool WidgetWin::screen_reader_active_ = false; |
35 | 36 |
36 // A custom MSAA object id used to determine if a screen reader is actively | 37 // A custom MSAA object id used to determine if a screen reader is actively |
37 // listening for MSAA events. | 38 // listening for MSAA events. |
38 #define OBJID_CUSTOM 1 | 39 #define OBJID_CUSTOM 1 |
39 | 40 |
40 RootView* GetRootViewForHWND(HWND hwnd) { | 41 RootView* GetRootViewForHWND(HWND hwnd) { |
41 return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty)); | 42 return reinterpret_cast<RootView*>(::GetProp(hwnd, kRootViewWindowProperty)); |
42 } | 43 } |
43 | 44 |
44 NativeControlWin* GetNativeControlWinForHWND(HWND hwnd) { | |
45 return reinterpret_cast<NativeControlWin*>( | |
46 GetProp(hwnd, NativeControlWin::kNativeControlWinKey)); | |
47 } | |
48 | |
49 /////////////////////////////////////////////////////////////////////////////// | 45 /////////////////////////////////////////////////////////////////////////////// |
50 // WidgetWin, public | 46 // WidgetWin, public |
51 | 47 |
52 WidgetWin::WidgetWin() | 48 WidgetWin::WidgetWin() |
53 : close_widget_factory_(this), | 49 : close_widget_factory_(this), |
54 active_mouse_tracking_flags_(0), | 50 active_mouse_tracking_flags_(0), |
55 has_capture_(false), | 51 has_capture_(false), |
56 use_layered_buffer_(true), | 52 use_layered_buffer_(true), |
57 layered_alpha_(255), | 53 layered_alpha_(255), |
58 delete_on_destroy_(true), | 54 delete_on_destroy_(true), |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 return NULL; | 1162 return NULL; |
1167 } | 1163 } |
1168 View* focused_view = focus_manager->GetFocusedView(); | 1164 View* focused_view = focus_manager->GetFocusedView(); |
1169 if (!focused_view) | 1165 if (!focused_view) |
1170 return NULL; | 1166 return NULL; |
1171 return focused_view->GetRootView(); | 1167 return focused_view->GetRootView(); |
1172 } | 1168 } |
1173 | 1169 |
1174 // Get the source HWND of the specified message. Depending on the message, the | 1170 // Get the source HWND of the specified message. Depending on the message, the |
1175 // source HWND is encoded in either the WPARAM or the LPARAM value. | 1171 // source HWND is encoded in either the WPARAM or the LPARAM value. |
1176 HWND GetControlHWNDForMessage(UINT message, WPARAM w_param, LPARAM l_param) { | 1172 static HWND GetControlHWNDForMessage(UINT message, |
| 1173 WPARAM w_param, |
| 1174 LPARAM l_param) { |
1177 // Each of the following messages can be sent by a child HWND and must be | 1175 // Each of the following messages can be sent by a child HWND and must be |
1178 // forwarded to its associated NativeControlWin for handling. | 1176 // forwarded to its associated NativeControlWin for handling. |
1179 switch (message) { | 1177 switch (message) { |
1180 case WM_NOTIFY: | 1178 case WM_NOTIFY: |
1181 return reinterpret_cast<NMHDR*>(l_param)->hwndFrom; | 1179 return reinterpret_cast<NMHDR*>(l_param)->hwndFrom; |
1182 case WM_COMMAND: | 1180 case WM_COMMAND: |
1183 return reinterpret_cast<HWND>(l_param); | 1181 return reinterpret_cast<HWND>(l_param); |
1184 case WM_CONTEXTMENU: | 1182 case WM_CONTEXTMENU: |
1185 return reinterpret_cast<HWND>(w_param); | 1183 return reinterpret_cast<HWND>(w_param); |
1186 case WM_CTLCOLORBTN: | 1184 case WM_CTLCOLORBTN: |
1187 case WM_CTLCOLORSTATIC: | 1185 case WM_CTLCOLORSTATIC: |
1188 return reinterpret_cast<HWND>(l_param); | 1186 return reinterpret_cast<HWND>(l_param); |
1189 } | 1187 } |
1190 return NULL; | 1188 return NULL; |
1191 } | 1189 } |
1192 | 1190 |
1193 HICON WidgetWin::GetDefaultWindowIcon() const { | 1191 HICON WidgetWin::GetDefaultWindowIcon() const { |
1194 if (ViewsDelegate::views_delegate) | 1192 if (ViewsDelegate::views_delegate) |
1195 return ViewsDelegate::views_delegate->GetDefaultWindowIcon(); | 1193 return ViewsDelegate::views_delegate->GetDefaultWindowIcon(); |
1196 return NULL; | 1194 return NULL; |
1197 } | 1195 } |
1198 | 1196 |
1199 // Some messages may be sent to us by a child HWND managed by | 1197 // Some messages may be sent to us by a child HWND. If this is the case, this |
1200 // NativeControlWin. If this is the case, this function will forward those | 1198 // function will forward those messages on to the object associated with the |
1201 // messages on to the object associated with the source HWND and return true, | 1199 // source HWND and return true, in which case the window procedure must not do |
1202 // in which case the window procedure must not do any further processing of | 1200 // any further processing of the message. If there is no associated |
1203 // the message. If there is no associated NativeControlWin, the return value | 1201 // ChildWindowMessageProcessor, the return value will be false and the WndProc |
1204 // will be false and the WndProc can continue processing the message normally. | 1202 // can continue processing the message normally. |l_result| contains the result |
1205 // |l_result| contains the result of the message processing by the control and | 1203 // of the message processing by the control and must be returned by the WndProc |
1206 // must be returned by the WndProc if the return value is true. | 1204 // if the return value is true. |
1207 bool ProcessNativeControlMessage(UINT message, | 1205 static bool ProcessChildWindowMessage(UINT message, |
1208 WPARAM w_param, | 1206 WPARAM w_param, |
1209 LPARAM l_param, | 1207 LPARAM l_param, |
1210 LRESULT* l_result) { | 1208 LRESULT* l_result) { |
1211 *l_result = 0; | 1209 *l_result = 0; |
1212 | 1210 |
1213 HWND control_hwnd = GetControlHWNDForMessage(message, w_param, l_param); | 1211 HWND control_hwnd = GetControlHWNDForMessage(message, w_param, l_param); |
1214 if (IsWindow(control_hwnd)) { | 1212 if (IsWindow(control_hwnd)) { |
1215 NativeControlWin* wrapper = GetNativeControlWinForHWND(control_hwnd); | 1213 ChildWindowMessageProcessor* processor = |
1216 if (wrapper) | 1214 ChildWindowMessageProcessor::Get(control_hwnd); |
1217 return wrapper->ProcessMessage(message, w_param, l_param, l_result); | 1215 if (processor) |
| 1216 return processor->ProcessMessage(message, w_param, l_param, l_result); |
1218 } | 1217 } |
1219 | 1218 |
1220 return false; | 1219 return false; |
1221 } | 1220 } |
1222 | 1221 |
1223 LRESULT WidgetWin::OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) { | 1222 LRESULT WidgetWin::OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) { |
1224 HWND window = hwnd(); | 1223 HWND window = hwnd(); |
1225 LRESULT result = 0; | 1224 LRESULT result = 0; |
1226 | 1225 |
1227 // First allow messages sent by child controls to be processed directly by | 1226 // First allow messages sent by child controls to be processed directly by |
1228 // their associated views. If such a view is present, it will handle the | 1227 // their associated views. If such a view is present, it will handle the |
1229 // message *instead of* this WidgetWin. | 1228 // message *instead of* this WidgetWin. |
1230 if (ProcessNativeControlMessage(message, w_param, l_param, &result)) | 1229 if (ProcessChildWindowMessage(message, w_param, l_param, &result)) |
1231 return result; | 1230 return result; |
1232 | 1231 |
1233 // Otherwise we handle everything else. | 1232 // Otherwise we handle everything else. |
1234 if (!ProcessWindowMessage(window, message, w_param, l_param, result)) | 1233 if (!ProcessWindowMessage(window, message, w_param, l_param, result)) |
1235 result = DefWindowProc(window, message, w_param, l_param); | 1234 result = DefWindowProc(window, message, w_param, l_param); |
1236 if (message == WM_NCDESTROY) { | 1235 if (message == WM_NCDESTROY) { |
1237 MessageLoopForUI::current()->RemoveObserver(this); | 1236 MessageLoopForUI::current()->RemoveObserver(this); |
1238 OnFinalMessage(window); | 1237 OnFinalMessage(window); |
1239 } | 1238 } |
1240 if (message == WM_ACTIVATE) | 1239 if (message == WM_ACTIVATE) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { | 1368 Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) { |
1370 return Widget::GetWidgetFromNativeView(native_window); | 1369 return Widget::GetWidgetFromNativeView(native_window); |
1371 } | 1370 } |
1372 | 1371 |
1373 // static | 1372 // static |
1374 void Widget::NotifyLocaleChanged() { | 1373 void Widget::NotifyLocaleChanged() { |
1375 NOTIMPLEMENTED(); | 1374 NOTIMPLEMENTED(); |
1376 } | 1375 } |
1377 | 1376 |
1378 } // namespace views | 1377 } // namespace views |
OLD | NEW |