diff options
29 files changed, 423 insertions, 404 deletions
diff --git a/app/app_base.gypi b/app/app_base.gypi index f2be9f1..2581bdb 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -240,6 +240,8 @@ 'win/iat_patch_function.h', 'win/scoped_prop.cc', 'win/scoped_prop.h', + 'win/shell.cc', + 'win/shell.h', 'win/window_impl.cc', 'win/window_impl.h', 'x11_util.cc', diff --git a/app/win/hwnd_util.cc b/app/win/hwnd_util.cc index b0be404..30b7395 100644 --- a/app/win/hwnd_util.cc +++ b/app/win/hwnd_util.cc @@ -4,11 +4,49 @@ #include "app/win/hwnd_util.h" +#include <dwmapi.h> + #include "base/string_util.h" +#include "base/win/windows_version.h" +#include "gfx/rect.h" +#include "gfx/size.h" + +#pragma comment(lib, "dwmapi.lib") namespace app { namespace win { +namespace { + +// Adjust the window to fit, returning true if the window was resized or moved. +bool AdjustWindowToFit(HWND hwnd, const RECT& bounds) { + // Get the monitor. + HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); + if (!hmon) { + NOTREACHED() << "Unable to find default monitor"; + // No monitor available. + return false; + } + + MONITORINFO mi; + mi.cbSize = sizeof(mi); + GetMonitorInfo(hmon, &mi); + gfx::Rect window_rect(bounds); + gfx::Rect monitor_rect(mi.rcWork); + gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); + if (!new_window_rect.Equals(window_rect)) { + // Window doesn't fit on monitor, move and possibly resize. + SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), + new_window_rect.width(), new_window_rect.height(), + SWP_NOACTIVATE | SWP_NOZORDER); + return true; + } else { + return false; + } +} + +} // namespace + string16 GetClassName(HWND window) { // GetClassNameW will return a truncated result (properly null terminated) if // the given buffer is not large enough. So, it is not possible to determine @@ -55,5 +93,91 @@ void* GetWindowUserData(HWND hwnd) { #pragma warning(pop) +bool DoesWindowBelongToActiveWindow(HWND window) { + DCHECK(window); + HWND top_window = ::GetAncestor(window, GA_ROOT); + if (!top_window) + return false; + + HWND active_top_window = ::GetAncestor(::GetForegroundWindow(), GA_ROOT); + return (top_window == active_top_window); +} + +void CenterAndSizeWindow(HWND parent, + HWND window, + const gfx::Size& pref, + bool pref_is_client) { + DCHECK(window && pref.width() > 0 && pref.height() > 0); + + // Calculate the ideal bounds. + RECT window_bounds; + RECT center_bounds = {0}; + if (parent) { + // If there is a parent, center over the parents bounds. + ::GetWindowRect(parent, ¢er_bounds); + } else { + // No parent. Center over the monitor the window is on. + HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); + if (monitor) { + MONITORINFO mi = {0}; + mi.cbSize = sizeof(mi); + GetMonitorInfo(monitor, &mi); + center_bounds = mi.rcWork; + } else { + NOTREACHED() << "Unable to get default monitor"; + } + } + window_bounds.left = center_bounds.left + + (center_bounds.right - center_bounds.left - pref.width()) / 2; + window_bounds.right = window_bounds.left + pref.width(); + window_bounds.top = center_bounds.top + + (center_bounds.bottom - center_bounds.top - pref.height()) / 2; + window_bounds.bottom = window_bounds.top + pref.height(); + + // If we're centering a child window, we are positioning in client + // coordinates, and as such we need to offset the target rectangle by the + // position of the parent window. + if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) { + DCHECK(parent && ::GetParent(window) == parent); + POINT topleft = { window_bounds.left, window_bounds.top }; + ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1); + window_bounds.left = topleft.x; + window_bounds.top = topleft.y; + window_bounds.right = window_bounds.left + pref.width(); + window_bounds.bottom = window_bounds.top + pref.height(); + } + + // Get the WINDOWINFO for window. We need the style to calculate the size + // for the window. + WINDOWINFO win_info = {0}; + win_info.cbSize = sizeof(WINDOWINFO); + GetWindowInfo(window, &win_info); + + // Calculate the window size needed for the content size. + + if (!pref_is_client || + AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE, + win_info.dwExStyle)) { + if (!AdjustWindowToFit(window, window_bounds)) { + // The window fits, reset the bounds. + SetWindowPos(window, 0, window_bounds.left, window_bounds.top, + window_bounds.right - window_bounds.left, + window_bounds.bottom - window_bounds.top, + SWP_NOACTIVATE | SWP_NOZORDER); + } // else case, AdjustWindowToFit set the bounds for us. + } else { + NOTREACHED() << "Unable to adjust window to fit"; + } +} + +bool ShouldUseVistaFrame() { + if (base::win::GetVersion() < base::win::VERSION_VISTA) + return false; + // If composition is not enabled, we behave like on XP. + BOOL f; + DwmIsCompositionEnabled(&f); + return !!f; +} + } // namespace win } // namespace app diff --git a/app/win/hwnd_util.h b/app/win/hwnd_util.h index f8ae37e..bace47e 100644 --- a/app/win/hwnd_util.h +++ b/app/win/hwnd_util.h @@ -10,6 +10,10 @@ #include "base/string16.h" +namespace gfx { +class Size; +} + namespace app { namespace win { @@ -25,6 +29,22 @@ WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc); void* SetWindowUserData(HWND hwnd, void* user_data); void* GetWindowUserData(HWND hwnd); +// Returns true if the specified window is the current active top window or one +// of its children. +bool DoesWindowBelongToActiveWindow(HWND window); + +// Sizes the window to have a client or window size (depending on the value of +// |pref_is_client|) of pref, then centers the window over parent, ensuring the +// window fits on screen. +void CenterAndSizeWindow(HWND parent, + HWND window, + const gfx::Size& pref, + bool pref_is_client); + +// Returns true if we are on Windows Vista or greater and composition is +// enabled. +bool ShouldUseVistaFrame(); + } // namespace win } // namespace app diff --git a/app/win/shell.cc b/app/win/shell.cc new file mode 100644 index 0000000..a3c7331 --- /dev/null +++ b/app/win/shell.cc @@ -0,0 +1,112 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "app/win/shell.h" + +#include <shellapi.h> +#include <shlobj.h> + +#include "base/file_path.h" +#include "base/native_library.h" +#include "base/string_util.h" +#include "base/win/scoped_comptr.h" +#include "base/win/windows_version.h" +#include "base/win_util.h" + +namespace app { +namespace win { + +namespace { + +const wchar_t kShell32[] = L"shell32.dll"; +const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; + +// Define the type of SHGetPropertyStoreForWindow is SHGPSFW. +typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, + REFIID riid, + void** ppv); + +} // namespace + +// Open an item via a shell execute command. Error code checking and casting +// explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx +bool OpenItemViaShell(const FilePath& full_path) { + HINSTANCE h = ::ShellExecuteW( + NULL, NULL, full_path.value().c_str(), NULL, + full_path.DirName().value().c_str(), SW_SHOWNORMAL); + + LONG_PTR error = reinterpret_cast<LONG_PTR>(h); + if (error > 32) + return true; + + if ((error == SE_ERR_NOASSOC)) + return OpenItemWithExternalApp(full_path.value()); + + return false; +} + +bool OpenItemViaShellNoZoneCheck(const FilePath& full_path) { + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_NOZONECHECKS | SEE_MASK_FLAG_DDEWAIT; + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = NULL; + sei.lpFile = full_path.value().c_str(); + if (::ShellExecuteExW(&sei)) + return true; + LONG_PTR error = reinterpret_cast<LONG_PTR>(sei.hInstApp); + if ((error == SE_ERR_NOASSOC)) + return OpenItemWithExternalApp(full_path.value()); + return false; +} + +// Show the Windows "Open With" dialog box to ask the user to pick an app to +// open the file with. +bool OpenItemWithExternalApp(const string16& full_path) { + SHELLEXECUTEINFO sei = { sizeof(sei) }; + sei.fMask = SEE_MASK_FLAG_DDEWAIT; + sei.nShow = SW_SHOWNORMAL; + sei.lpVerb = L"openas"; + sei.lpFile = full_path.c_str(); + return (TRUE == ::ShellExecuteExW(&sei)); +} + +void SetAppIdForWindow(const string16& app_id, HWND hwnd) { + // This functionality is only available on Win7+. + if (base::win::GetVersion() < base::win::VERSION_WIN7) + return; + + // Load Shell32.dll into memory. + // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. + std::wstring shell32_filename(kShell32); + FilePath shell32_filepath(shell32_filename); + base::NativeLibrary shell32_library = base::LoadNativeLibrary( + shell32_filepath); + + if (!shell32_library) + return; + + // Get the function pointer for SHGetPropertyStoreForWindow. + void* function = base::GetFunctionPointerFromNativeLibrary( + shell32_library, + kSHGetPropertyStoreForWindow); + + if (!function) { + base::UnloadNativeLibrary(shell32_library); + return; + } + + // Set the application's name. + base::win::ScopedComPtr<IPropertyStore> pps; + SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); + HRESULT result = SHGetPropertyStoreForWindow( + hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); + if (S_OK == result) + win_util::SetAppIdForPropertyStore(pps, app_id.c_str()); + + // Cleanup. + base::UnloadNativeLibrary(shell32_library); +} + +} // namespace win +} // namespace app diff --git a/app/win/shell.h b/app/win/shell.h new file mode 100644 index 0000000..44ee3ba7 --- /dev/null +++ b/app/win/shell.h @@ -0,0 +1,41 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef APP_WIN_SHELL_H_ +#define APP_WIN_SHELL_H_ + +#include <windows.h> + +#include "base/string16.h" + +class FilePath; + +namespace app { +namespace win { + +// Open or run a file via the Windows shell. In the event that there is no +// default application registered for the file specified by 'full_path', +// ask the user, via the Windows "Open With" dialog. +// Returns 'true' on successful open, 'false' otherwise. +bool OpenItemViaShell(const FilePath& full_path); + +// The download manager now writes the alternate data stream with the +// zone on all downloads. This function is equivalent to OpenItemViaShell +// without showing the zone warning dialog. +bool OpenItemViaShellNoZoneCheck(const FilePath& full_path); + +// Ask the user, via the Windows "Open With" dialog, for an application to use +// to open the file specified by 'full_path'. +// Returns 'true' on successful open, 'false' otherwise. +bool OpenItemWithExternalApp(const string16& full_path); + +// Sets the application id given as the Application Model ID for the window +// specified. This method is used to insure that different web applications +// do not group together on the Win7 task bar. +void SetAppIdForWindow(const string16& app_id, HWND hwnd); + +} // namespace win +} // namespace app + +#endif // APP_WIN_SHELL_H_ diff --git a/app/win_util.cc b/app/win_util.cc index 0bbe391..31137e9 100644 --- a/app/win_util.cc +++ b/app/win_util.cc @@ -5,9 +5,7 @@ #include "app/win_util.h" #include <commdlg.h> -#include <dwmapi.h> #include <shellapi.h> -#include <shlobj.h> #include <algorithm> @@ -18,35 +16,18 @@ #include "base/file_util.h" #include "base/i18n/rtl.h" #include "base/logging.h" -#include "base/native_library.h" -#include "base/scoped_comptr_win.h" #include "base/scoped_handle.h" #include "base/scoped_handle_win.h" #include "base/string_util.h" #include "base/win_util.h" #include "base/win/scoped_gdi_object.h" -#include "base/win/windows_version.h" #include "gfx/codec/png_codec.h" #include "gfx/gdi_util.h" -// Ensure that we pick up this link library. -#pragma comment(lib, "dwmapi.lib") - namespace win_util { const int kAutoHideTaskbarThicknessPx = 2; -namespace { - -const wchar_t kShell32[] = L"shell32.dll"; -const char kSHGetPropertyStoreForWindow[] = "SHGetPropertyStoreForWindow"; - -// Define the type of SHGetPropertyStoreForWindow is SHGPSFW. -typedef DECLSPEC_IMPORT HRESULT (STDAPICALLTYPE *SHGPSFW)(HWND hwnd, - REFIID riid, - void** ppv); -} // namespace - std::wstring FormatSystemTime(const SYSTEMTIME& time, const std::wstring& format) { // If the format string is empty, just use the default format. @@ -100,155 +81,6 @@ bool IsDrag(const POINT& origin, const POINT& current) { (abs(current.y - origin.y) > (GetSystemMetrics(SM_CYDRAG) / 2)); } -bool ShouldUseVistaFrame() { - if (base::win::GetVersion() < base::win::VERSION_VISTA) - return false; - // If composition is not enabled, we behave like on XP. - BOOL f; - DwmIsCompositionEnabled(&f); - return !!f; -} - -// Open an item via a shell execute command. Error code checking and casting -// explanation: http://msdn2.microsoft.com/en-us/library/ms647732.aspx -bool OpenItemViaShell(const FilePath& full_path) { - HINSTANCE h = ::ShellExecuteW( - NULL, NULL, full_path.value().c_str(), NULL, - full_path.DirName().value().c_str(), SW_SHOWNORMAL); - - LONG_PTR error = reinterpret_cast<LONG_PTR>(h); - if (error > 32) - return true; - - if ((error == SE_ERR_NOASSOC)) - return OpenItemWithExternalApp(full_path.value()); - - return false; -} - -bool OpenItemViaShellNoZoneCheck(const FilePath& full_path) { - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_NOZONECHECKS | SEE_MASK_FLAG_DDEWAIT; - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = NULL; - sei.lpFile = full_path.value().c_str(); - if (::ShellExecuteExW(&sei)) - return true; - LONG_PTR error = reinterpret_cast<LONG_PTR>(sei.hInstApp); - if ((error == SE_ERR_NOASSOC)) - return OpenItemWithExternalApp(full_path.value()); - return false; -} - -// Show the Windows "Open With" dialog box to ask the user to pick an app to -// open the file with. -bool OpenItemWithExternalApp(const std::wstring& full_path) { - SHELLEXECUTEINFO sei = { sizeof(sei) }; - sei.fMask = SEE_MASK_FLAG_DDEWAIT; - sei.nShow = SW_SHOWNORMAL; - sei.lpVerb = L"openas"; - sei.lpFile = full_path.c_str(); - return (TRUE == ::ShellExecuteExW(&sei)); -} - -// Adjust the window to fit, returning true if the window was resized or moved. -static bool AdjustWindowToFit(HWND hwnd, const RECT& bounds) { - // Get the monitor. - HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); - if (!hmon) { - NOTREACHED() << "Unable to find default monitor"; - // No monitor available. - return false; - } - - MONITORINFO mi; - mi.cbSize = sizeof(mi); - GetMonitorInfo(hmon, &mi); - gfx::Rect window_rect(bounds); - gfx::Rect monitor_rect(mi.rcWork); - gfx::Rect new_window_rect = window_rect.AdjustToFit(monitor_rect); - if (!new_window_rect.Equals(window_rect)) { - // Window doesn't fit on monitor, move and possibly resize. - SetWindowPos(hwnd, 0, new_window_rect.x(), new_window_rect.y(), - new_window_rect.width(), new_window_rect.height(), - SWP_NOACTIVATE | SWP_NOZORDER); - return true; - } else { - return false; - } -} - -void AdjustWindowToFit(HWND hwnd) { - // Get the window bounds. - RECT r; - GetWindowRect(hwnd, &r); - AdjustWindowToFit(hwnd, r); -} - -void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref, - bool pref_is_client) { - DCHECK(window && pref.cx > 0 && pref.cy > 0); - // Calculate the ideal bounds. - RECT window_bounds; - RECT center_bounds = {0}; - if (parent) { - // If there is a parent, center over the parents bounds. - ::GetWindowRect(parent, ¢er_bounds); - } else { - // No parent. Center over the monitor the window is on. - HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - GetMonitorInfo(monitor, &mi); - center_bounds = mi.rcWork; - } else { - NOTREACHED() << "Unable to get default monitor"; - } - } - window_bounds.left = center_bounds.left + - (center_bounds.right - center_bounds.left - pref.cx) / 2; - window_bounds.right = window_bounds.left + pref.cx; - window_bounds.top = center_bounds.top + - (center_bounds.bottom - center_bounds.top - pref.cy) / 2; - window_bounds.bottom = window_bounds.top + pref.cy; - - // If we're centering a child window, we are positioning in client - // coordinates, and as such we need to offset the target rectangle by the - // position of the parent window. - if (::GetWindowLong(window, GWL_STYLE) & WS_CHILD) { - DCHECK(parent && ::GetParent(window) == parent); - POINT topleft = { window_bounds.left, window_bounds.top }; - ::MapWindowPoints(HWND_DESKTOP, parent, &topleft, 1); - window_bounds.left = topleft.x; - window_bounds.top = topleft.y; - window_bounds.right = window_bounds.left + pref.cx; - window_bounds.bottom = window_bounds.top + pref.cy; - } - - // Get the WINDOWINFO for window. We need the style to calculate the size - // for the window. - WINDOWINFO win_info = {0}; - win_info.cbSize = sizeof(WINDOWINFO); - GetWindowInfo(window, &win_info); - - // Calculate the window size needed for the content size. - - if (!pref_is_client || - AdjustWindowRectEx(&window_bounds, win_info.dwStyle, FALSE, - win_info.dwExStyle)) { - if (!AdjustWindowToFit(window, window_bounds)) { - // The window fits, reset the bounds. - SetWindowPos(window, 0, window_bounds.left, window_bounds.top, - window_bounds.right - window_bounds.left, - window_bounds.bottom - window_bounds.top, - SWP_NOACTIVATE | SWP_NOZORDER); - } // else case, AdjustWindowToFit set the bounds for us. - } else { - NOTREACHED() << "Unable to adjust window to fit"; - } -} - bool EdgeHasTopmostAutoHideTaskbar(UINT edge, HMONITOR monitor) { APPBARDATA taskbar_data = { 0 }; taskbar_data.cbSize = sizeof APPBARDATA; @@ -280,16 +112,6 @@ HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only) { return valid_section; } -bool DoesWindowBelongToActiveWindow(HWND window) { - DCHECK(window); - HWND top_window = ::GetAncestor(window, GA_ROOT); - if (!top_window) - return false; - - HWND active_top_window = ::GetAncestor(::GetForegroundWindow(), GA_ROOT); - return (top_window == active_top_window); -} - void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, gfx::Rect* child_rect, int padding) { @@ -327,48 +149,6 @@ void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, child_rect->set_x(parent_rect.right() - child_rect->width() - padding); } -void SetChildBounds(HWND child_window, HWND parent_window, - HWND insert_after_window, const gfx::Rect& bounds, - int padding, unsigned long flags) { - DCHECK(IsWindow(child_window)); - - // First figure out the bounds of the parent. - RECT parent_rect = {0}; - if (parent_window) { - GetClientRect(parent_window, &parent_rect); - } else { - // If there is no parent, we consider the bounds of the monitor the window - // is on to be the parent bounds. - - // If the child_window isn't visible yet and we've been given a valid, - // visible insert after window, use that window to locate the correct - // monitor instead. - HWND window = child_window; - if (!IsWindowVisible(window) && IsWindow(insert_after_window) && - IsWindowVisible(insert_after_window)) - window = insert_after_window; - - POINT window_point = { bounds.x(), bounds.y() }; - HMONITOR monitor = MonitorFromPoint(window_point, - MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - GetMonitorInfo(monitor, &mi); - parent_rect = mi.rcWork; - } else { - NOTREACHED() << "Unable to get default monitor"; - } - } - - gfx::Rect actual_bounds = bounds; - EnsureRectIsVisibleInRect(gfx::Rect(parent_rect), &actual_bounds, padding); - - SetWindowPos(child_window, insert_after_window, actual_bounds.x(), - actual_bounds.y(), actual_bounds.width(), - actual_bounds.height(), flags); -} - gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect) { RECT p_rect = rect.ToRECT(); HMONITOR monitor = MonitorFromRect(&p_rect, MONITOR_DEFAULTTONEAREST); @@ -495,31 +275,6 @@ bool IsReservedName(const std::wstring& filename) { return false; } -bool IsShellIntegratedExtension(const std::wstring& extension) { - std::wstring extension_lower = StringToLowerASCII(extension); - - static const wchar_t* const integrated_extensions[] = { - // See <http://msdn.microsoft.com/en-us/library/ms811694.aspx>. - L"local", - // Right-clicking on shortcuts can be magical. - L"lnk", - }; - - for (int i = 0; i < arraysize(integrated_extensions); ++i) { - if (extension_lower == integrated_extensions[i]) - return true; - } - - // See <http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html>. - // That vulnerability report is not exactly on point, but files become magical - // if their end in a CLSID. Here we block extensions that look like CLSIDs. - if (extension_lower.size() > 0 && extension_lower.at(0) == L'{' && - extension_lower.at(extension_lower.length() - 1) == L'}') - return true; - - return false; -} - // In addition to passing the RTL flags to ::MessageBox if we are running in an // RTL locale, we need to make sure that LTR strings are rendered correctly by // adding the appropriate Unicode directionality marks. @@ -553,42 +308,4 @@ gfx::Font GetWindowTitleFont() { return gfx::Font(caption_font); } -void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd) { - // This functionality is only available on Win7+. - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return; - - // Load Shell32.dll into memory. - // TODO(brg): Remove this mechanism when the Win7 SDK is available in trunk. - std::wstring shell32_filename(kShell32); - FilePath shell32_filepath(shell32_filename); - base::NativeLibrary shell32_library = base::LoadNativeLibrary( - shell32_filepath); - - if (!shell32_library) - return; - - // Get the function pointer for SHGetPropertyStoreForWindow. - void* function = base::GetFunctionPointerFromNativeLibrary( - shell32_library, - kSHGetPropertyStoreForWindow); - - if (!function) { - base::UnloadNativeLibrary(shell32_library); - return; - } - - // Set the application's name. - ScopedComPtr<IPropertyStore> pps; - SHGPSFW SHGetPropertyStoreForWindow = static_cast<SHGPSFW>(function); - HRESULT result = SHGetPropertyStoreForWindow( - hwnd, __uuidof(*pps), reinterpret_cast<void**>(pps.Receive())); - if (S_OK == result) { - SetAppIdForPropertyStore(pps, app_id.c_str()); - } - - // Cleanup. - base::UnloadNativeLibrary(shell32_library); -} - } // namespace win_util diff --git a/app/win_util.h b/app/win_util.h index ab5cbc3..4f98e63 100644 --- a/app/win_util.h +++ b/app/win_util.h @@ -111,35 +111,6 @@ bool IsDoubleClick(const POINT& origin, // would be considered a drag. bool IsDrag(const POINT& origin, const POINT& current); -// Returns true if we are on Windows Vista and composition is enabled -bool ShouldUseVistaFrame(); - -// Open or run a file via the Windows shell. In the event that there is no -// default application registered for the file specified by 'full_path', -// ask the user, via the Windows "Open With" dialog. -// Returns 'true' on successful open, 'false' otherwise. -bool OpenItemViaShell(const FilePath& full_path); - -// The download manager now writes the alternate data stream with the -// zone on all downloads. This function is equivalent to OpenItemViaShell -// without showing the zone warning dialog. -bool OpenItemViaShellNoZoneCheck(const FilePath& full_path); - -// Ask the user, via the Windows "Open With" dialog, for an application to use -// to open the file specified by 'full_path'. -// Returns 'true' on successful open, 'false' otherwise. -bool OpenItemWithExternalApp(const std::wstring& full_path); - -// If the window does not fit on the default monitor, it is moved and possibly -// resized appropriately. -void AdjustWindowToFit(HWND hwnd); - -// Sizes the window to have a client or window size (depending on the value of -// |pref_is_client|) of pref, then centers the window over parent, ensuring the -// window fits on screen. -void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref, - bool pref_is_client); - // Returns true if edge |edge| (one of ABE_LEFT, TOP, RIGHT, or BOTTOM) of // monitor |monitor| has an auto-hiding taskbar that's always-on-top. bool EdgeHasTopmostAutoHideTaskbar(UINT edge, HMONITOR monitor); @@ -152,26 +123,12 @@ HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only); // process. Returns the new valid handle or NULL on failure. HANDLE GetSectionForProcess(HANDLE section, HANDLE process, bool read_only); -// Returns true if the specified window is the current active top window or one -// of its children. -bool DoesWindowBelongToActiveWindow(HWND window); - // Adjusts the value of |child_rect| if necessary to ensure that it is // completely visible within |parent_rect|. void EnsureRectIsVisibleInRect(const gfx::Rect& parent_rect, gfx::Rect* child_rect, int padding); -// Ensures that the child window stays within the boundaries of the parent -// before setting its bounds. If |parent_window| is NULL, the bounds of the -// parent are assumed to be the bounds of the monitor that |child_window| is -// nearest to. If |child_window| isn't visible yet and |insert_after_window| -// is non-NULL and visible, the monitor |insert_after_window| is on is used -// as the parent bounds instead. -void SetChildBounds(HWND child_window, HWND parent_window, - HWND insert_after_window, const gfx::Rect& bounds, - int padding, unsigned long flags); - // Returns the bounds for the monitor that contains the largest area of // intersection with the specified rectangle. gfx::Rect GetMonitorBoundsForRect(const gfx::Rect& rect); @@ -195,10 +152,6 @@ bool IsWindowActive(HWND hwnd); // desktop.ini and thumbs.db which have special meaning to the windows shell. bool IsReservedName(const std::wstring& filename); -// Returns whether the specified extension is automatically integrated into the -// windows shell. -bool IsShellIntegratedExtension(const std::wstring& eextension); - // A wrapper around Windows' MessageBox function. Using a Chrome specific // MessageBox function allows us to control certain RTL locale flags so that // callers don't have to worry about adding these flags when running in a @@ -214,11 +167,6 @@ gfx::Font GetWindowTitleFont(); // The thickness of an auto-hide taskbar in pixels. extern const int kAutoHideTaskbarThicknessPx; -// Sets the application id given as the Application Model ID for the window -// specified. This method is used to insure that different web applications -// do not group together on the Win7 task bar. -void SetAppIdForWindow(const std::wstring& app_id, HWND hwnd); - } // namespace win_util #endif // APP_WIN_UTIL_H_ diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc index e628224..5281f8d 100644 --- a/chrome/browser/aeropeek_manager.cc +++ b/chrome/browser/aeropeek_manager.cc @@ -7,8 +7,9 @@ #include <dwmapi.h> #include <shobjidl.h> +#include "app/win/hwnd_util.h" #include "app/win/window_impl.h" -#include "app/win_util.h" +#include "app/win/shell.h" #include "base/command_line.h" #include "base/scoped_comptr_win.h" #include "base/scoped_handle_win.h" @@ -251,7 +252,7 @@ class RegisterThumbnailTask : public Task { // browser icon in the taskbar. // TODO(mattm): This should use ShellIntegration::GetChromiumAppId to work // properly with multiple profiles. - win_util::SetAppIdForWindow( + app::win::SetAppIdForWindow( BrowserDistribution::GetDistribution()->GetBrowserAppId(), window_); // Register this place-holder window to the taskbar as a child of @@ -1013,7 +1014,7 @@ bool AeroPeekManager::Enabled() { // flooding users with tab thumbnails. const CommandLine* command_line = CommandLine::ForCurrentProcess(); return base::win::GetVersion() >= base::win::VERSION_WIN7 && - win_util::ShouldUseVistaFrame() && + app::win::ShouldUseVistaFrame() && !command_line->HasSwitch(switches::kApp) && command_line->HasSwitch(switches::kEnableAeroPeekTabs); } diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 1854d11..92c24a3 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -92,6 +92,39 @@ static const int kCompleteAnimationCycles = 5; // Also used by code that cleans up said files. static const int kMaxUniqueFiles = 100; +namespace { + +#if defined(OS_WIN) +// Returns whether the specified extension is automatically integrated into the +// windows shell. +bool IsShellIntegratedExtension(const string16& extension) { + string16 extension_lower = StringToLowerASCII(extension); + + static const wchar_t* const integrated_extensions[] = { + // See <http://msdn.microsoft.com/en-us/library/ms811694.aspx>. + L"local", + // Right-clicking on shortcuts can be magical. + L"lnk", + }; + + for (int i = 0; i < arraysize(integrated_extensions); ++i) { + if (extension_lower == integrated_extensions[i]) + return true; + } + + // See <http://www.juniper.net/security/auto/vulnerabilities/vuln2612.html>. + // That vulnerability report is not exactly on point, but files become magical + // if their end in a CLSID. Here we block extensions that look like CLSIDs. + if (extension_lower.size() > 0 && extension_lower.at(0) == L'{' && + extension_lower.at(extension_lower.length() - 1) == L'}') + return true; + + return false; +} +#endif // OS_WIN + +} // namespace + // Download temporary file creation -------------------------------------------- class DefaultDownloadDirectory { @@ -157,7 +190,7 @@ void GenerateExtension(const FilePath& file_name, FILE_PATH_LITERAL("download"); // Rename shell-integrated extensions. - if (win_util::IsShellIntegratedExtension(extension)) + if (IsShellIntegratedExtension(extension)) extension.assign(default_extension); #endif diff --git a/chrome/browser/platform_util_win.cc b/chrome/browser/platform_util_win.cc index f27e936..9672d02 100644 --- a/chrome/browser/platform_util_win.cc +++ b/chrome/browser/platform_util_win.cc @@ -9,6 +9,7 @@ #include <shellapi.h> #include <shlobj.h> +#include "app/win/shell.h" #include "app/win_util.h" #include "base/file_path.h" #include "base/file_util.h" @@ -89,7 +90,7 @@ void ShowItemInFolder(const FilePath& full_path) { } void OpenItem(const FilePath& full_path) { - win_util::OpenItemViaShell(full_path); + app::win::OpenItemViaShell(full_path); } void OpenExternal(const GURL& url) { diff --git a/chrome/browser/themes/browser_theme_provider.cc b/chrome/browser/themes/browser_theme_provider.cc index 1f70532..bdd9bf1 100644 --- a/chrome/browser/themes/browser_theme_provider.cc +++ b/chrome/browser/themes/browser_theme_provider.cc @@ -20,7 +20,7 @@ #include "grit/theme_resources.h" #if defined(OS_WIN) -#include "app/win_util.h" +#include "app/win/hwnd_util.h" #endif // Strings used in alignment properties. @@ -255,7 +255,7 @@ bool BrowserThemeProvider::ShouldUseNativeFrame() const { if (HasCustomImage(IDR_THEME_FRAME)) return false; #if defined(OS_WIN) - return win_util::ShouldUseVistaFrame(); + return app::win::ShouldUseVistaFrame(); #else return false; #endif diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 52a3b96..a9a731e 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -116,7 +116,7 @@ #endif #if defined(OS_WIN) -#include "app/win_util.h" +#include "app/win/shell.h" #include "chrome/browser/autofill/autofill_ie_toolbar_import_win.h" #include "chrome/browser/browser_child_process_host.h" #include "chrome/browser/download/save_package.h" @@ -379,7 +379,7 @@ void Browser::CreateBrowserWindow() { // Set the app user model id for this application to that of the application // name. See http://crbug.com/7028. - win_util::SetAppIdForWindow( + app::win::SetAppIdForWindow( type_ & TYPE_APP ? ShellIntegration::GetAppId(UTF8ToWide(app_name_), profile_->GetPath()) : ShellIntegration::GetChromiumAppId(profile_->GetPath()), diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 199e631..28bd95e 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -42,7 +42,7 @@ #include <commctrl.h> #include <dwmapi.h> -#include "app/win_util.h" +#include "app/win/hwnd_util.h" #include "base/win/scoped_gdi_object.h" #endif @@ -1106,7 +1106,7 @@ void AutocompletePopupContentsView::MakeContentsPath( void AutocompletePopupContentsView::UpdateBlurRegion() { #if defined(OS_WIN) // We only support background blurring on Vista with Aero-Glass enabled. - if (!win_util::ShouldUseVistaFrame() || !GetWidget()) + if (!app::win::ShouldUseVistaFrame() || !GetWidget()) return; // Provide a blurred background effect within the contents region of the diff --git a/chrome/browser/ui/views/constrained_window_win.cc b/chrome/browser/ui/views/constrained_window_win.cc index b042f5b..fea24e2 100644 --- a/chrome/browser/ui/views/constrained_window_win.cc +++ b/chrome/browser/ui/views/constrained_window_win.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/constrained_window_win.h" #include "app/resource_bundle.h" +#include "app/win/hwnd_util.h" #include "app/win_util.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/prefs/pref_service.h" @@ -197,7 +198,7 @@ class ConstrainedWindowFrameView SkColor GetTitleColor() const { return (container_->owner()->profile()->IsOffTheRecord() || - !win_util::ShouldUseVistaFrame()) ? SK_ColorWHITE : SK_ColorBLACK; + !app::win::ShouldUseVistaFrame()) ? SK_ColorWHITE : SK_ColorBLACK; } // Loads the appropriate set of WindowResources for the frame view. @@ -534,7 +535,7 @@ gfx::Rect ConstrainedWindowFrameView::CalculateClientAreaBounds( } void ConstrainedWindowFrameView::InitWindowResources() { - resources_.reset(win_util::ShouldUseVistaFrame() ? + resources_.reset(app::win::ShouldUseVistaFrame() ? static_cast<views::WindowResources*>(new VistaWindowResources) : new XPWindowResources); } diff --git a/chrome/browser/ui/views/first_run_bubble.cc b/chrome/browser/ui/views/first_run_bubble.cc index b858e21..1aa3e98 100644 --- a/chrome/browser/ui/views/first_run_bubble.cc +++ b/chrome/browser/ui/views/first_run_bubble.cc @@ -7,7 +7,7 @@ #include "app/gfx/font_util.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" -#include "app/win_util.h" +#include "app/win/hwnd_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_window.h" @@ -350,7 +350,7 @@ gfx::Size FirstRunOEMBubbleView::GetPreferredSize() { // now, we force Vista to show a correctly-sized box by taking account of // the difference in font size calculation. The coefficient should not be // stored in a variable because it's a hack and should go away. - if (win_util::ShouldUseVistaFrame()) { + if (app::win::ShouldUseVistaFrame()) { size.set_width(static_cast<int>(size.width() * 0.85)); size.set_height(static_cast<int>(size.height() * 0.85)); } diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index d747f73..1fe8a6c 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -9,6 +9,7 @@ #include <set> +#include "app/win/hwnd_util.h" #include "app/win_util.h" #include "base/win_util.h" #include "chrome/browser/accessibility/browser_accessibility_state.h" @@ -108,7 +109,7 @@ bool BrowserFrameWin::AlwaysUseNativeFrame() const { // We don't theme popup or app windows, so regardless of whether or not a // theme is active for normal browser windows, we don't want to use the custom // frame for popups/apps. - if (!browser_view_->IsBrowserTypeNormal() && win_util::ShouldUseVistaFrame()) + if (!browser_view_->IsBrowserTypeNormal() && app::win::ShouldUseVistaFrame()) return true; // Otherwise, we use the native frame when we're told we should by the theme diff --git a/chrome/browser/ui/views/infobars/infobars.cc b/chrome/browser/ui/views/infobars/infobars.cc index 756ce70..0e08d7b 100644 --- a/chrome/browser/ui/views/infobars/infobars.cc +++ b/chrome/browser/ui/views/infobars/infobars.cc @@ -7,6 +7,7 @@ #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/slide_animation.h" +#include "app/win/hwnd_util.h" #include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "chrome/browser/views/event_utils.h" @@ -243,7 +244,7 @@ void InfoBar::AnimateClose() { // Do not restore focus (and active state with it) on Windows if some other // top-level window became active. if (GetWidget() && - !win_util::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { + !app::win::DoesWindowBelongToActiveWindow(GetWidget()->GetNativeView())) { restore_focus = false; } #endif // defined(OS_WIN) diff --git a/chrome/common/win_safe_util.cc b/chrome/common/win_safe_util.cc index dc5cc25..37cb0a7 100644 --- a/chrome/common/win_safe_util.cc +++ b/chrome/common/win_safe_util.cc @@ -7,7 +7,7 @@ #include "chrome/common/win_safe_util.h" -#include "app/win_util.h" +#include "app/win/shell.h" #include "base/file_path.h" #include "base/logging.h" #include "base/path_service.h" @@ -33,7 +33,7 @@ bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, NOTREACHED(); return false; } - return OpenItemViaShell(full_path); + return app::win::OpenItemViaShell(full_path); } // This GUID is associated with any 'don't ask me again' settings that the @@ -81,7 +81,7 @@ bool SaferOpenItemViaShell(HWND hwnd, const std::wstring& window_title, return false; } } - return OpenItemViaShellNoZoneCheck(full_path); + return app::win::OpenItemViaShellNoZoneCheck(full_path); } bool SetInternetZoneIdentifier(const FilePath& full_path) { diff --git a/ppapi/cpp/graphics_2d.cc b/ppapi/cpp/graphics_2d.cc index 40a6312..edd5c33 100644 --- a/ppapi/cpp/graphics_2d.cc +++ b/ppapi/cpp/graphics_2d.cc @@ -50,16 +50,11 @@ Graphics2D::~Graphics2D() { } Graphics2D& Graphics2D::operator=(const Graphics2D& other) { - Graphics2D copy(other); - swap(copy); + Resource::operator=(other); + size_ = other.size_; return *this; } -void Graphics2D::swap(Graphics2D& other) { - Resource::swap(other); - size_.swap(other.size_); -} - void Graphics2D::PaintImageData(const ImageData& image, const Point& top_left) { if (!has_interface<PPB_Graphics2D>()) diff --git a/ppapi/cpp/graphics_2d.h b/ppapi/cpp/graphics_2d.h index 8f4622f..39bcb5e 100644 --- a/ppapi/cpp/graphics_2d.h +++ b/ppapi/cpp/graphics_2d.h @@ -32,7 +32,6 @@ class Graphics2D : public Resource { virtual ~Graphics2D(); Graphics2D& operator=(const Graphics2D& other); - void swap(Graphics2D& other); const Size& size() const { return size_; } diff --git a/ppapi/cpp/image_data.cc b/ppapi/cpp/image_data.cc index 61a291d..e43263b 100644 --- a/ppapi/cpp/image_data.cc +++ b/ppapi/cpp/image_data.cc @@ -58,17 +58,12 @@ ImageData::ImageData(PP_ImageDataFormat format, } ImageData& ImageData::operator=(const ImageData& other) { - ImageData copy(other); - swap(copy); + Resource::operator=(other); + desc_ = other.desc_; + data_ = other.data_; return *this; } -void ImageData::swap(ImageData& other) { - Resource::swap(other); - std::swap(desc_, other.desc_); - std::swap(data_, other.data_); -} - const uint32_t* ImageData::GetAddr32(const Point& coord) const { // Prefer evil const casts rather than evil code duplication. return const_cast<ImageData*>(this)->GetAddr32(coord); diff --git a/ppapi/cpp/image_data.h b/ppapi/cpp/image_data.h index 388bbc0..25f9156 100644 --- a/ppapi/cpp/image_data.h +++ b/ppapi/cpp/image_data.h @@ -33,7 +33,6 @@ class ImageData : public Resource { bool init_to_zero); ImageData& operator=(const ImageData& other); - void swap(ImageData& other); // Returns the browser's preferred format for images. Using this format // guarantees no extra conversions will occur when painting. diff --git a/ppapi/cpp/rect.cc b/ppapi/cpp/rect.cc index b57be2d..ef347dc 100644 --- a/ppapi/cpp/rect.cc +++ b/ppapi/cpp/rect.cc @@ -34,13 +34,6 @@ void Rect::Offset(int32_t horizontal, int32_t vertical) { rect_.point.y += vertical; } -void Rect::swap(Rect& other) { - std::swap(rect_.point.x, other.rect_.point.x); - std::swap(rect_.point.y, other.rect_.point.y); - std::swap(rect_.size.width, other.rect_.size.width); - std::swap(rect_.size.height, other.rect_.size.height); -} - bool Rect::Contains(int32_t point_x, int32_t point_y) const { return (point_x >= x()) && (point_x < right()) && (point_y >= y()) && (point_y < bottom()); diff --git a/ppapi/cpp/rect.h b/ppapi/cpp/rect.h index 7b133d2..1b07fd1 100644 --- a/ppapi/cpp/rect.h +++ b/ppapi/cpp/rect.h @@ -147,8 +147,6 @@ class Rect { return rect_.size.width == 0 && rect_.size.height == 0; } - void swap(Rect& other); - // Returns true if the point identified by point_x and point_y falls inside // this rectangle. The point (x, y) is inside the rectangle, but the // point (x + width, y + height) is not. diff --git a/ppapi/cpp/resource.cc b/ppapi/cpp/resource.cc index e4a0d96..7daab4a 100644 --- a/ppapi/cpp/resource.cc +++ b/ppapi/cpp/resource.cc @@ -25,15 +25,14 @@ Resource::~Resource() { } Resource& Resource::operator=(const Resource& other) { - Resource copy(other); - swap(copy); + if (!is_null()) + Module::Get()->core()->ReleaseResource(pp_resource_); + pp_resource_ = other.pp_resource_; + if (!is_null()) + Module::Get()->core()->AddRefResource(pp_resource_); return *this; } -void Resource::swap(Resource& other) { - std::swap(pp_resource_, other.pp_resource_); -} - PP_Resource Resource::detach() { PP_Resource ret = pp_resource_; pp_resource_ = 0; diff --git a/ppapi/cpp/resource.h b/ppapi/cpp/resource.h index 33e9982..c59b37d 100644 --- a/ppapi/cpp/resource.h +++ b/ppapi/cpp/resource.h @@ -18,7 +18,6 @@ class Resource { virtual ~Resource(); Resource& operator=(const Resource& other); - void swap(Resource& other); // Returns true if the given resource is invalid or uninitialized. bool is_null() const { return !pp_resource_; } diff --git a/ppapi/cpp/size.h b/ppapi/cpp/size.h index adcaf78..f2f9fe1 100644 --- a/ppapi/cpp/size.h +++ b/ppapi/cpp/size.h @@ -76,15 +76,6 @@ class Size { set_height(height() + h); } - void swap(Size& other) { - int32_t w = size_.width; - int32_t h = size_.height; - size_.width = other.size_.width; - size_.height = other.size_.height; - other.size_.width = w; - other.size_.height = h; - } - bool IsEmpty() const { // Size doesn't allow negative dimensions, so testing for 0 is enough. return (width() == 0) || (height() == 0); diff --git a/views/widget/default_theme_provider.cc b/views/widget/default_theme_provider.cc index e6087e2..c9cf99c 100644 --- a/views/widget/default_theme_provider.cc +++ b/views/widget/default_theme_provider.cc @@ -7,7 +7,7 @@ #include "app/resource_bundle.h" #if defined(OS_WIN) -#include "app/win_util.h" +#include "app/win/hwnd_util.h" #endif namespace views { @@ -18,7 +18,7 @@ SkBitmap* DefaultThemeProvider::GetBitmapNamed(int id) const { bool DefaultThemeProvider::ShouldUseNativeFrame() const { #if defined(OS_WIN) - return win_util::ShouldUseVistaFrame(); + return app::win::ShouldUseVistaFrame(); #else return false; #endif diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 1f525e9..664e17f 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -47,6 +47,55 @@ bool GetMonitorAndRects(const RECT& rect, return true; } +// Ensures that the child window stays within the boundaries of the parent +// before setting its bounds. If |parent_window| is NULL, the bounds of the +// parent are assumed to be the bounds of the monitor that |child_window| is +// nearest to. If |child_window| isn't visible yet and |insert_after_window| +// is non-NULL and visible, the monitor |insert_after_window| is on is used +// as the parent bounds instead. +void SetChildBounds(HWND child_window, HWND parent_window, + HWND insert_after_window, const gfx::Rect& bounds, + int padding, unsigned long flags) { + DCHECK(IsWindow(child_window)); + + // First figure out the bounds of the parent. + RECT parent_rect = {0}; + if (parent_window) { + GetClientRect(parent_window, &parent_rect); + } else { + // If there is no parent, we consider the bounds of the monitor the window + // is on to be the parent bounds. + + // If the child_window isn't visible yet and we've been given a valid, + // visible insert after window, use that window to locate the correct + // monitor instead. + HWND window = child_window; + if (!IsWindowVisible(window) && IsWindow(insert_after_window) && + IsWindowVisible(insert_after_window)) + window = insert_after_window; + + POINT window_point = { bounds.x(), bounds.y() }; + HMONITOR monitor = MonitorFromPoint(window_point, + MONITOR_DEFAULTTONEAREST); + if (monitor) { + MONITORINFO mi = {0}; + mi.cbSize = sizeof(mi); + GetMonitorInfo(monitor, &mi); + parent_rect = mi.rcWork; + } else { + NOTREACHED() << "Unable to get default monitor"; + } + } + + gfx::Rect actual_bounds = bounds; + win_util::EnsureRectIsVisibleInRect(gfx::Rect(parent_rect), &actual_bounds, + padding); + + SetWindowPos(child_window, insert_after_window, actual_bounds.x(), + actual_bounds.y(), actual_bounds.width(), + actual_bounds.height(), flags); +} + } // namespace namespace views { @@ -133,8 +182,8 @@ gfx::Rect WindowWin::GetNormalBounds() const { void WindowWin::SetBounds(const gfx::Rect& bounds, gfx::NativeWindow other_window) { - win_util::SetChildBounds(GetNativeView(), GetParent(), other_window, bounds, - kMonitorEdgePadding, 0); + SetChildBounds(GetNativeView(), GetParent(), other_window, bounds, + kMonitorEdgePadding, 0); } void WindowWin::Show(int show_state) { @@ -491,7 +540,7 @@ gfx::NativeWindow WindowWin::GetNativeWindow() const { bool WindowWin::ShouldUseNativeFrame() const { ThemeProvider* tp = GetThemeProvider(); if (!tp) - return win_util::ShouldUseVistaFrame(); + return app::win::ShouldUseVistaFrame(); return tp->ShouldUseNativeFrame(); } @@ -565,8 +614,8 @@ void WindowWin::Init(HWND parent, const gfx::Rect& bounds) { } void WindowWin::SizeWindowToDefault() { - win_util::CenterAndSizeWindow(owning_window(), GetNativeView(), - non_client_view_->GetPreferredSize().ToSIZE(), + app::win::CenterAndSizeWindow(owning_window(), GetNativeView(), + non_client_view_->GetPreferredSize(), false); } |