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.
5 #include "ui/views/win/hwnd_util.h"
7 #include "ui/aura/root_window.h"
8 #include "ui/views/widget/widget.h"
12 HWND HWNDForView(const View* view) {
13 return view->GetWidget() ? HWNDForWidget(view->GetWidget()) : NULL;
16 HWND HWNDForWidget(const Widget* widget) {
17 return HWNDForNativeWindow(widget->GetNativeWindow());
20 HWND HWNDForNativeView(const gfx::NativeView view) {
21 return view && view->GetRootWindow() ?
22 view->GetDispatcher()->GetAcceleratedWidget() : NULL;
25 HWND HWNDForNativeWindow(const gfx::NativeWindow window) {
26 return window && window->GetRootWindow() ?
27 window->GetDispatcher()->GetAcceleratedWidget() : NULL;
30 gfx::Rect GetWindowBoundsForClientBounds(View* view,
31 const gfx::Rect& client_bounds) {
33 aura::WindowEventDispatcher* dispatcher =
34 view->GetWidget()->GetNativeWindow()->GetDispatcher();
36 HWND hwnd = dispatcher->GetAcceleratedWidget();
37 RECT rect = client_bounds.ToRECT();
38 DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
39 DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
40 AdjustWindowRectEx(&rect, style, FALSE, ex_style);
41 return gfx::Rect(rect);