| 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/views/win/hwnd_message_handler.h" | 5 #include "ui/views/win/hwnd_message_handler.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <oleacc.h> | 8 #include <oleacc.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <tchar.h> | 10 #include <tchar.h> |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 is_first_nccalc_(true), | 326 is_first_nccalc_(true), |
| 327 menu_depth_(0), | 327 menu_depth_(0), |
| 328 id_generator_(0), | 328 id_generator_(0), |
| 329 needs_scroll_styles_(false), | 329 needs_scroll_styles_(false), |
| 330 in_size_loop_(false), | 330 in_size_loop_(false), |
| 331 touch_down_contexts_(0), | 331 touch_down_contexts_(0), |
| 332 last_mouse_hwheel_time_(0), | 332 last_mouse_hwheel_time_(0), |
| 333 dwm_transition_desired_(false), | 333 dwm_transition_desired_(false), |
| 334 sent_window_size_changing_(false), | 334 sent_window_size_changing_(false), |
| 335 left_button_down_on_caption_(false), | 335 left_button_down_on_caption_(false), |
| 336 background_fullscreen_hack_(false), |
| 336 autohide_factory_(this), | 337 autohide_factory_(this), |
| 337 weak_factory_(this) {} | 338 weak_factory_(this) {} |
| 338 | 339 |
| 339 HWNDMessageHandler::~HWNDMessageHandler() { | 340 HWNDMessageHandler::~HWNDMessageHandler() { |
| 340 delegate_ = NULL; | 341 delegate_ = NULL; |
| 341 // Prevent calls back into this class via WNDPROC now that we've been | 342 // Prevent calls back into this class via WNDPROC now that we've been |
| 342 // destroyed. | 343 // destroyed. |
| 343 ClearUserData(); | 344 ClearUserData(); |
| 344 } | 345 } |
| 345 | 346 |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 } | 838 } |
| 838 if (!app_icon.isNull()) { | 839 if (!app_icon.isNull()) { |
| 839 base::win::ScopedHICON previous_icon = app_icon_.Pass(); | 840 base::win::ScopedHICON previous_icon = app_icon_.Pass(); |
| 840 app_icon_ = IconUtil::CreateHICONFromSkBitmap(*app_icon.bitmap()).Pass(); | 841 app_icon_ = IconUtil::CreateHICONFromSkBitmap(*app_icon.bitmap()).Pass(); |
| 841 SendMessage(hwnd(), WM_SETICON, ICON_BIG, | 842 SendMessage(hwnd(), WM_SETICON, ICON_BIG, |
| 842 reinterpret_cast<LPARAM>(app_icon_.get())); | 843 reinterpret_cast<LPARAM>(app_icon_.get())); |
| 843 } | 844 } |
| 844 } | 845 } |
| 845 | 846 |
| 846 void HWNDMessageHandler::SetFullscreen(bool fullscreen) { | 847 void HWNDMessageHandler::SetFullscreen(bool fullscreen) { |
| 848 set_background_fullscreen_hack(false); |
| 847 fullscreen_handler()->SetFullscreen(fullscreen); | 849 fullscreen_handler()->SetFullscreen(fullscreen); |
| 848 // If we are out of fullscreen and there was a pending DWM transition for the | 850 // If we are out of fullscreen and there was a pending DWM transition for the |
| 849 // window, then go ahead and do it now. | 851 // window, then go ahead and do it now. |
| 850 if (!fullscreen && dwm_transition_desired_) | 852 if (!fullscreen && dwm_transition_desired_) |
| 851 PerformDwmTransition(); | 853 PerformDwmTransition(); |
| 852 } | 854 } |
| 853 | 855 |
| 854 void HWNDMessageHandler::SizeConstraintsChanged() { | 856 void HWNDMessageHandler::SizeConstraintsChanged() { |
| 855 LONG style = GetWindowLong(hwnd(), GWL_STYLE); | 857 LONG style = GetWindowLong(hwnd(), GWL_STYLE); |
| 856 // Ignore if this is not a standard window. | 858 // Ignore if this is not a standard window. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 return result; | 924 return result; |
| 923 } | 925 } |
| 924 | 926 |
| 925 if (delegate_) { | 927 if (delegate_) { |
| 926 delegate_->PostHandleMSG(message, w_param, l_param); | 928 delegate_->PostHandleMSG(message, w_param, l_param); |
| 927 if (message == WM_NCDESTROY) | 929 if (message == WM_NCDESTROY) |
| 928 delegate_->HandleDestroyed(); | 930 delegate_->HandleDestroyed(); |
| 929 } | 931 } |
| 930 | 932 |
| 931 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) | 933 if (message == WM_ACTIVATE && IsTopLevelWindow(window)) |
| 932 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param)); | 934 PostProcessActivateMessage(LOWORD(w_param), !!HIWORD(w_param), |
| 935 reinterpret_cast<HWND>(l_param)); |
| 933 return result; | 936 return result; |
| 934 } | 937 } |
| 935 | 938 |
| 936 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, | 939 LRESULT HWNDMessageHandler::HandleMouseMessage(unsigned int message, |
| 937 WPARAM w_param, | 940 WPARAM w_param, |
| 938 LPARAM l_param, | 941 LPARAM l_param, |
| 939 bool* handled) { | 942 bool* handled) { |
| 940 // Don't track forwarded mouse messages. We expect the caller to track the | 943 // Don't track forwarded mouse messages. We expect the caller to track the |
| 941 // mouse. | 944 // mouse. |
| 942 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); | 945 base::WeakPtr<HWNDMessageHandler> ref(weak_factory_.GetWeakPtr()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 } | 1023 } |
| 1021 | 1024 |
| 1022 void HWNDMessageHandler::SetInitialFocus() { | 1025 void HWNDMessageHandler::SetInitialFocus() { |
| 1023 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && | 1026 if (!(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TRANSPARENT) && |
| 1024 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { | 1027 !(GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_NOACTIVATE)) { |
| 1025 // The window does not get keyboard messages unless we focus it. | 1028 // The window does not get keyboard messages unless we focus it. |
| 1026 SetFocus(hwnd()); | 1029 SetFocus(hwnd()); |
| 1027 } | 1030 } |
| 1028 } | 1031 } |
| 1029 | 1032 |
| 1030 void HWNDMessageHandler::PostProcessActivateMessage(int activation_state, | 1033 void HWNDMessageHandler::PostProcessActivateMessage( |
| 1031 bool minimized) { | 1034 int activation_state, |
| 1035 bool minimized, |
| 1036 HWND window_gaining_or_losing_activation) { |
| 1032 DCHECK(IsTopLevelWindow(hwnd())); | 1037 DCHECK(IsTopLevelWindow(hwnd())); |
| 1033 const bool active = activation_state != WA_INACTIVE && !minimized; | 1038 const bool active = activation_state != WA_INACTIVE && !minimized; |
| 1034 if (delegate_->CanActivate()) | 1039 if (delegate_->CanActivate()) { |
| 1035 delegate_->HandleActivationChanged(active); | 1040 delegate_->HandleActivationChanged(active, |
| 1041 window_gaining_or_losing_activation); |
| 1042 } |
| 1036 } | 1043 } |
| 1037 | 1044 |
| 1038 void HWNDMessageHandler::RestoreEnabledIfNecessary() { | 1045 void HWNDMessageHandler::RestoreEnabledIfNecessary() { |
| 1039 if (delegate_->IsModal() && !restored_enabled_) { | 1046 if (delegate_->IsModal() && !restored_enabled_) { |
| 1040 restored_enabled_ = true; | 1047 restored_enabled_ = true; |
| 1041 // If we were run modally, we need to undo the disabled-ness we inflicted on | 1048 // If we were run modally, we need to undo the disabled-ness we inflicted on |
| 1042 // the owner's parent hierarchy. | 1049 // the owner's parent hierarchy. |
| 1043 HWND start = ::GetWindow(hwnd(), GW_OWNER); | 1050 HWND start = ::GetWindow(hwnd(), GW_OWNER); |
| 1044 while (start) { | 1051 while (start) { |
| 1045 ::EnableWindow(start, TRUE); | 1052 ::EnableWindow(start, TRUE); |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2160 } else if (!GetParent(hwnd())) { | 2167 } else if (!GetParent(hwnd())) { |
| 2161 RECT window_rect; | 2168 RECT window_rect; |
| 2162 HMONITOR monitor; | 2169 HMONITOR monitor; |
| 2163 gfx::Rect monitor_rect, work_area; | 2170 gfx::Rect monitor_rect, work_area; |
| 2164 if (GetWindowRect(hwnd(), &window_rect) && | 2171 if (GetWindowRect(hwnd(), &window_rect) && |
| 2165 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) { | 2172 GetMonitorAndRects(window_rect, &monitor, &monitor_rect, &work_area)) { |
| 2166 bool work_area_changed = (monitor_rect == last_monitor_rect_) && | 2173 bool work_area_changed = (monitor_rect == last_monitor_rect_) && |
| 2167 (work_area != last_work_area_); | 2174 (work_area != last_work_area_); |
| 2168 if (monitor && (monitor == last_monitor_) && | 2175 if (monitor && (monitor == last_monitor_) && |
| 2169 ((fullscreen_handler_->fullscreen() && | 2176 ((fullscreen_handler_->fullscreen() && |
| 2170 !fullscreen_handler_->metro_snap()) || | 2177 !fullscreen_handler_->metro_snap() && |
| 2178 !background_fullscreen_hack()) || |
| 2171 work_area_changed)) { | 2179 work_area_changed)) { |
| 2172 // A rect for the monitor we're on changed. Normally Windows notifies | 2180 // A rect for the monitor we're on changed. Normally Windows notifies |
| 2173 // us about this (and thus we're reaching here due to the SetWindowPos() | 2181 // us about this (and thus we're reaching here due to the SetWindowPos() |
| 2174 // call in OnSettingChange() above), but with some software (e.g. | 2182 // call in OnSettingChange() above), but with some software (e.g. |
| 2175 // nVidia's nView desktop manager) the work area can change asynchronous | 2183 // nVidia's nView desktop manager) the work area can change asynchronous |
| 2176 // to any notification, and we're just sent a SetWindowPos() call with a | 2184 // to any notification, and we're just sent a SetWindowPos() call with a |
| 2177 // new (frequently incorrect) position/size. In either case, the best | 2185 // new (frequently incorrect) position/size. In either case, the best |
| 2178 // response is to throw away the existing position/size information in | 2186 // response is to throw away the existing position/size information in |
| 2179 // |window_pos| and recalculate it based on the new work rect. | 2187 // |window_pos| and recalculate it based on the new work rect. |
| 2180 gfx::Rect new_window_rect; | 2188 gfx::Rect new_window_rect; |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2570 | 2578 |
| 2571 default: | 2579 default: |
| 2572 left_button_down_on_caption_ = false; | 2580 left_button_down_on_caption_ = false; |
| 2573 break; | 2581 break; |
| 2574 } | 2582 } |
| 2575 return handled; | 2583 return handled; |
| 2576 } | 2584 } |
| 2577 | 2585 |
| 2578 | 2586 |
| 2579 } // namespace views | 2587 } // namespace views |
| OLD | NEW |