Chromium Code Reviews| 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/widget/native_widget_win.h" | 5 #include "ui/views/widget/native_widget_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 | 314 |
| 315 // Links the HWND to its NativeWidget. | 315 // Links the HWND to its NativeWidget. |
| 316 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; | 316 const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__"; |
| 317 | 317 |
| 318 // A custom MSAA object id used to determine if a screen reader is actively | 318 // A custom MSAA object id used to determine if a screen reader is actively |
| 319 // listening for MSAA events. | 319 // listening for MSAA events. |
| 320 const int kCustomObjectID = 1; | 320 const int kCustomObjectID = 1; |
| 321 | 321 |
| 322 const int kDragFrameWindowAlpha = 200; | 322 const int kDragFrameWindowAlpha = 200; |
| 323 | 323 |
| 324 struct FindOwnedWindowsData { | |
| 325 HWND window; | |
| 326 std::vector<Widget*> owned_widgets; | |
| 327 }; | |
| 328 | |
| 329 BOOL CALLBACK FindOwnedWindowsCallback(HWND hwnd, LPARAM param) { | |
| 330 FindOwnedWindowsData* data = reinterpret_cast<FindOwnedWindowsData*>(param); | |
| 331 if (GetWindow(hwnd, GW_OWNER) == data->window) { | |
| 332 Widget* widget = Widget::GetWidgetForNativeView(hwnd); | |
| 333 if (widget) | |
| 334 data->owned_widgets.push_back(widget); | |
| 335 } | |
| 336 return TRUE; | |
| 337 } | |
| 338 | |
| 324 } // namespace | 339 } // namespace |
| 325 | 340 |
| 326 // static | 341 // static |
| 327 bool NativeWidgetWin::screen_reader_active_ = false; | 342 bool NativeWidgetWin::screen_reader_active_ = false; |
| 328 | 343 |
| 329 // A scoping class that prevents a window from being able to redraw in response | 344 // A scoping class that prevents a window from being able to redraw in response |
| 330 // to invalidations that may occur within it for the lifetime of the object. | 345 // to invalidations that may occur within it for the lifetime of the object. |
| 331 // | 346 // |
| 332 // Why would we want such a thing? Well, it turns out Windows has some | 347 // Why would we want such a thing? Well, it turns out Windows has some |
| 333 // "unorthodox" behavior when it comes to painting its non-client areas. | 348 // "unorthodox" behavior when it comes to painting its non-client areas. |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 | 899 |
| 885 void NativeWidgetWin::Hide() { | 900 void NativeWidgetWin::Hide() { |
| 886 if (IsWindow()) { | 901 if (IsWindow()) { |
| 887 // NOTE: Be careful not to activate any windows here (for example, calling | 902 // NOTE: Be careful not to activate any windows here (for example, calling |
| 888 // ShowWindow(SW_HIDE) will automatically activate another window). This | 903 // ShowWindow(SW_HIDE) will automatically activate another window). This |
| 889 // code can be called while a window is being deactivated, and activating | 904 // code can be called while a window is being deactivated, and activating |
| 890 // another window will screw up the activation that is already in progress. | 905 // another window will screw up the activation that is already in progress. |
| 891 SetWindowPos(NULL, 0, 0, 0, 0, | 906 SetWindowPos(NULL, 0, 0, 0, 0, |
| 892 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | | 907 SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOMOVE | |
| 893 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); | 908 SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); |
| 909 | |
| 910 if (!GetParent()) | |
| 911 NotifyOwnedWindowsParentClosing(); | |
|
oshima
2012/04/26 03:05:27
Can a widget be closed by Windows?
sky
2012/04/26 03:54:53
Do you mean can windows close out from under us? Y
| |
| 894 } | 912 } |
| 895 } | 913 } |
| 896 | 914 |
| 897 void NativeWidgetWin::ShowMaximizedWithBounds( | 915 void NativeWidgetWin::ShowMaximizedWithBounds( |
| 898 const gfx::Rect& restored_bounds) { | 916 const gfx::Rect& restored_bounds) { |
| 899 WINDOWPLACEMENT placement = { 0 }; | 917 WINDOWPLACEMENT placement = { 0 }; |
| 900 placement.length = sizeof(WINDOWPLACEMENT); | 918 placement.length = sizeof(WINDOWPLACEMENT); |
| 901 placement.showCmd = SW_SHOWMAXIMIZED; | 919 placement.showCmd = SW_SHOWMAXIMIZED; |
| 902 placement.rcNormalPosition = restored_bounds.ToRECT(); | 920 placement.rcNormalPosition = restored_bounds.ToRECT(); |
| 903 SetWindowPlacement(hwnd(), &placement); | 921 SetWindowPlacement(hwnd(), &placement); |
| (...skipping 1575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2479 // If we were run modally, we need to undo the disabled-ness we inflicted on | 2497 // If we were run modally, we need to undo the disabled-ness we inflicted on |
| 2480 // the owner's parent hierarchy. | 2498 // the owner's parent hierarchy. |
| 2481 HWND start = ::GetWindow(GetNativeView(), GW_OWNER); | 2499 HWND start = ::GetWindow(GetNativeView(), GW_OWNER); |
| 2482 while (start) { | 2500 while (start) { |
| 2483 ::EnableWindow(start, TRUE); | 2501 ::EnableWindow(start, TRUE); |
| 2484 start = ::GetParent(start); | 2502 start = ::GetParent(start); |
| 2485 } | 2503 } |
| 2486 } | 2504 } |
| 2487 } | 2505 } |
| 2488 | 2506 |
| 2507 void NativeWidgetWin::NotifyOwnedWindowsParentClosing() { | |
| 2508 FindOwnedWindowsData data; | |
| 2509 data.window = hwnd(); | |
| 2510 EnumThreadWindows(GetCurrentThreadId(), FindOwnedWindowsCallback, | |
| 2511 reinterpret_cast<LPARAM>(&data)); | |
| 2512 for (size_t i = 0; i < data.owned_widgets.size(); ++i) | |
| 2513 data.owned_widgets[i]->OnOwnedParentClosing(); | |
| 2514 } | |
| 2515 | |
| 2489 void NativeWidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { | 2516 void NativeWidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { |
| 2490 SetMsgHandled(delegate_->OnKeyEvent(key)); | 2517 SetMsgHandled(delegate_->OnKeyEvent(key)); |
| 2491 } | 2518 } |
| 2492 | 2519 |
| 2493 //////////////////////////////////////////////////////////////////////////////// | 2520 //////////////////////////////////////////////////////////////////////////////// |
| 2494 // Widget, public: | 2521 // Widget, public: |
| 2495 | 2522 |
| 2496 // static | 2523 // static |
| 2497 void Widget::NotifyLocaleChanged() { | 2524 void Widget::NotifyLocaleChanged() { |
| 2498 NOTIMPLEMENTED(); | 2525 NOTIMPLEMENTED(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2646 return (GetKeyState(VK_LBUTTON) & 0x80) || | 2673 return (GetKeyState(VK_LBUTTON) & 0x80) || |
| 2647 (GetKeyState(VK_RBUTTON) & 0x80) || | 2674 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 2648 (GetKeyState(VK_MBUTTON) & 0x80) || | 2675 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 2649 (GetKeyState(VK_XBUTTON1) & 0x80) || | 2676 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 2650 (GetKeyState(VK_XBUTTON2) & 0x80); | 2677 (GetKeyState(VK_XBUTTON2) & 0x80); |
| 2651 } | 2678 } |
| 2652 | 2679 |
| 2653 } // namespace internal | 2680 } // namespace internal |
| 2654 | 2681 |
| 2655 } // namespace views | 2682 } // namespace views |
| OLD | NEW |