1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/views/win/hwnd_util.h" 6 7 #include "ui/aura/root_window.h" 8 #include "ui/aura/window.h" 9 #include "ui/views/widget/widget.h" 10 11 namespace views { 12 13 HWND HWNDForView(const View* view) { 14 return view->GetWidget() ? HWNDForWidget(view->GetWidget()) : NULL; 15 } 16 17 HWND HWNDForWidget(const Widget* widget) { 18 return HWNDForNativeWindow(widget->GetNativeWindow()); 19 } 20 21 HWND HWNDForNativeView(const gfx::NativeView view) { 22 return view && view->GetRootWindow() ? 23 view->GetDispatcher()->host()->GetAcceleratedWidget() : NULL; 24 } 25 26 HWND HWNDForNativeWindow(const gfx::NativeWindow window) { 27 return window && window->GetRootWindow() ? 28 window->GetDispatcher()->host()->GetAcceleratedWidget() : NULL; 29 } 30 31 gfx::Rect GetWindowBoundsForClientBounds(View* view, 32 const gfx::Rect& client_bounds) { 33 DCHECK(view); 34 aura::WindowEventDispatcher* dispatcher = 35 view->GetWidget()->GetNativeWindow()->GetDispatcher(); 36 if (dispatcher) { 37 HWND hwnd = dispatcher->host()->GetAcceleratedWidget(); 38 RECT rect = client_bounds.ToRECT(); 39 DWORD style = ::GetWindowLong(hwnd, GWL_STYLE); 40 DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); 41 AdjustWindowRectEx(&rect, style, FALSE, ex_style); 42 return gfx::Rect(rect); 43 } 44 return client_bounds; 45 } 46 47 } // namespace views 48