diff options
Diffstat (limited to 'ui/base')
24 files changed, 21 insertions, 984 deletions
diff --git a/ui/base/ime/input_method_win.cc b/ui/base/ime/input_method_win.cc index 90f87da..3982c22 100644 --- a/ui/base/ime/input_method_win.cc +++ b/ui/base/ime/input_method_win.cc @@ -10,7 +10,7 @@ #include "ui/base/events/event_utils.h" #include "ui/base/ime/text_input_client.h" #include "ui/base/keycodes/keyboard_codes.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace ui { namespace { @@ -158,7 +158,7 @@ LRESULT InputMethodWin::OnChar(HWND window_handle, // Note: Setting |handled| to FALSE for DefWindowProc triggering of the system // menu causes undesirable titlebar artifacts in the classic theme. if (message == WM_SYSCHAR && wparam == VK_SPACE) - ui::ShowSystemMenu(window_handle); + gfx::ShowSystemMenu(window_handle); return 0; } diff --git a/ui/base/l10n/l10n_util_win.cc b/ui/base/l10n/l10n_util_win.cc index c49452c..0fa34cf 100644 --- a/ui/base/l10n/l10n_util_win.cc +++ b/ui/base/l10n/l10n_util_win.cc @@ -15,7 +15,7 @@ #include "base/win/windows_version.h" #include "grit/app_locale_settings.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" namespace { diff --git a/ui/base/l10n/l10n_util_win_unittest.cc b/ui/base/l10n/l10n_util_win_unittest.cc index 3ef1100..c4ae888 100644 --- a/ui/base/l10n/l10n_util_win_unittest.cc +++ b/ui/base/l10n/l10n_util_win_unittest.cc @@ -9,7 +9,7 @@ #include "base/win/win_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" typedef PlatformTest L10nUtilWinTest; diff --git a/ui/base/layout.cc b/ui/base/layout.cc index c035ae9..40a0a9c 100644 --- a/ui/base/layout.cc +++ b/ui/base/layout.cc @@ -23,7 +23,7 @@ #if defined(OS_WIN) #include "base/win/metro.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #include <Windows.h> #endif // defined(OS_WIN) diff --git a/ui/base/resource/resource_bundle_win.cc b/ui/base/resource/resource_bundle_win.cc index ffd2cd0..0a2b185 100644 --- a/ui/base/resource/resource_bundle_win.cc +++ b/ui/base/resource/resource_bundle_win.cc @@ -10,7 +10,7 @@ #include "ui/base/layout.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_data_dll_win.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" namespace ui { diff --git a/ui/base/text/utf16_indexing.cc b/ui/base/text/utf16_indexing.cc deleted file mode 100644 index d217f5d..0000000 --- a/ui/base/text/utf16_indexing.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 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 "ui/base/text/utf16_indexing.h" - -#include "base/logging.h" -#include "base/third_party/icu/icu_utf.h" - -namespace ui { - -bool IsValidCodePointIndex(const string16& s, size_t index) { - return index == 0 || index == s.length() || - !(CBU16_IS_TRAIL(s[index]) && CBU16_IS_LEAD(s[index - 1])); -} - -ptrdiff_t UTF16IndexToOffset(const string16& s, size_t base, size_t pos) { - // The indices point between UTF-16 words (range 0 to s.length() inclusive). - // In order to consistently handle indices that point to the middle of a - // surrogate pair, we count the first word in that surrogate pair and not - // the second. The test "s[i] is not the second half of a surrogate pair" is - // "IsValidCodePointIndex(s, i)". - DCHECK_LE(base, s.length()); - DCHECK_LE(pos, s.length()); - ptrdiff_t delta = 0; - while (base < pos) - delta += IsValidCodePointIndex(s, base++) ? 1 : 0; - while (pos < base) - delta -= IsValidCodePointIndex(s, pos++) ? 1 : 0; - return delta; -} - -size_t UTF16OffsetToIndex(const string16& s, size_t base, ptrdiff_t offset) { - DCHECK_LE(base, s.length()); - // As in UTF16IndexToOffset, we count the first half of a surrogate pair, not - // the second. When stepping from pos to pos+1 we check s[pos:pos+1] == s[pos] - // (Python syntax), hence pos++. When stepping from pos to pos-1 we check - // s[pos-1], hence --pos. - size_t pos = base; - while (offset > 0 && pos < s.length()) - offset -= IsValidCodePointIndex(s, pos++) ? 1 : 0; - while (offset < 0 && pos > 0) - offset += IsValidCodePointIndex(s, --pos) ? 1 : 0; - // If offset != 0 then we ran off the edge of the string, which is a contract - // violation but is handled anyway (by clamping) in release for safety. - DCHECK_EQ(offset, 0); - // Since the second half of a surrogate pair has "length" zero, there is an - // ambiguity in the returned position. Resolve it by always returning a valid - // index. - if (!IsValidCodePointIndex(s, pos)) - ++pos; - return pos; -} - -} // namespace ui diff --git a/ui/base/text/utf16_indexing.h b/ui/base/text/utf16_indexing.h deleted file mode 100644 index a1af3d9..0000000 --- a/ui/base/text/utf16_indexing.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2012 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 UI_BASE_TEXT_UTF16_INDEXING_H_ -#define UI_BASE_TEXT_UTF16_INDEXING_H_ - -#include "base/strings/string16.h" -#include "ui/base/ui_export.h" - -namespace ui { - -// Returns false if s[index-1] is a high surrogate and s[index] is a low -// surrogate, true otherwise. -UI_EXPORT bool IsValidCodePointIndex(const string16& s, size_t index); - -// |UTF16IndexToOffset| returns the number of code points between |base| and -// |pos| in the given string. |UTF16OffsetToIndex| returns the index that is -// |offset| code points away from the given |base| index. These functions are -// named after glib's |g_utf8_pointer_to_offset| and |g_utf8_offset_to_pointer|, -// which perform the same function for UTF-8. As in glib, it is an error to -// pass an |offset| that walks off the edge of the string. -// -// These functions attempt to deal with invalid use of UTF-16 surrogates in a -// way that makes as much sense as possible: unpaired surrogates are treated as -// single characters, and if an argument index points to the middle of a valid -// surrogate pair, it is treated as though it pointed to the end of that pair. -// The index returned by |UTF16OffsetToIndex| never points to the middle of a -// surrogate pair. -// -// The following identities hold: -// If |s| contains no surrogate pairs, then -// UTF16IndexToOffset(s, base, pos) == pos - base -// UTF16OffsetToIndex(s, base, offset) == base + offset -// If |pos| does not point to the middle of a surrogate pair, then -// UTF16OffsetToIndex(s, base, UTF16IndexToOffset(s, base, pos)) == pos -// Always, -// UTF16IndexToOffset(s, base, UTF16OffsetToIndex(s, base, ofs)) == ofs -// UTF16IndexToOffset(s, i, j) == -UTF16IndexToOffset(s, j, i) -UI_EXPORT ptrdiff_t UTF16IndexToOffset(const string16& s, - size_t base, - size_t pos); -UI_EXPORT size_t UTF16OffsetToIndex(const string16& s, - size_t base, - ptrdiff_t offset); - -} // namespace ui - -#endif // UI_BASE_TEXT_UTF16_INDEXING_H_ diff --git a/ui/base/text/utf16_indexing_unittest.cc b/ui/base/text/utf16_indexing_unittest.cc deleted file mode 100644 index 1bf8c30..0000000 --- a/ui/base/text/utf16_indexing_unittest.cc +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" -#include "ui/base/text/utf16_indexing.h" - -namespace ui { - -TEST(UTF16IndexingTest, IndexOffsetConversions) { - // Valid surrogate pair surrounded by unpaired surrogates - const char16 foo[] = {0xDC00, 0xD800, 0xD800, 0xDFFF, 0xDFFF, 0xDBFF, 0}; - const string16 s(foo); - const size_t the_invalid_index = 3; - for (size_t i = 0; i <= s.length(); ++i) - EXPECT_EQ(i != the_invalid_index, IsValidCodePointIndex(s, i)); - for (size_t i = 0; i <= s.length(); ++i) { - for (size_t j = i; j <= s.length(); ++j) { - ptrdiff_t offset = static_cast<ptrdiff_t>(j - i); - if (i <= the_invalid_index && j > the_invalid_index) - --offset; - EXPECT_EQ(offset, UTF16IndexToOffset(s, i, j)); - EXPECT_EQ(-offset, UTF16IndexToOffset(s, j, i)); - size_t adjusted_j = (j == the_invalid_index) ? j + 1 : j; - EXPECT_EQ(adjusted_j, UTF16OffsetToIndex(s, i, offset)); - size_t adjusted_i = (i == the_invalid_index) ? i + 1 : i; - EXPECT_EQ(adjusted_i, UTF16OffsetToIndex(s, j, -offset)); - } - } -} - -} // namespace ui diff --git a/ui/base/ui_base_switches.cc b/ui/base/ui_base_switches.cc index 3adb215..ca4586b 100644 --- a/ui/base/ui_base_switches.cc +++ b/ui/base/ui_base_switches.cc @@ -33,9 +33,6 @@ const char kEnableTouchEditing[] = "enable-touch-editing"; // Enables the Views textfield on Windows. const char kEnableViewsTextfield[] = "enable-views-textfield"; -// Overrides the device scale factor for the browser UI and the contents. -const char kForceDeviceScaleFactor[] = "force-device-scale-factor"; - // If a resource is requested at a scale factor at which it is not available // or the resource is the incorrect size (based on the size of the 1x resource), // generates the missing resource and applies a red mask to the generated diff --git a/ui/base/ui_base_switches.h b/ui/base/ui_base_switches.h index cbe9a77..7e4c9a7 100644 --- a/ui/base/ui_base_switches.h +++ b/ui/base/ui_base_switches.h @@ -21,7 +21,6 @@ UI_EXPORT extern const char kEnableScrollPrediction[]; UI_EXPORT extern const char kEnableTouchDragDrop[]; UI_EXPORT extern const char kEnableTouchEditing[]; UI_EXPORT extern const char kEnableViewsTextfield[]; -UI_EXPORT extern const char kForceDeviceScaleFactor[]; UI_EXPORT extern const char kHighlightMissingScaledResources[]; UI_EXPORT extern const char kLang[]; UI_EXPORT extern const char kLocalePak[]; diff --git a/ui/base/win/events_win.cc b/ui/base/win/events_win.cc index 4381cb0..6cb6d81 100644 --- a/ui/base/win/events_win.cc +++ b/ui/base/win/events_win.cc @@ -11,8 +11,8 @@ #include "base/win/win_util.h" #include "ui/base/events/event_utils.h" #include "ui/base/keycodes/keyboard_code_conversion_win.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/point.h" +#include "ui/gfx/win/dpi.h" namespace ui { diff --git a/ui/base/win/foreground_helper.cc b/ui/base/win/foreground_helper.cc index 0b03582..219b26f 100644 --- a/ui/base/win/foreground_helper.cc +++ b/ui/base/win/foreground_helper.cc @@ -5,7 +5,7 @@ #include "ui/base/win/foreground_helper.h" #include "base/logging.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace ui { diff --git a/ui/base/win/foreground_helper.h b/ui/base/win/foreground_helper.h index 7fc1834..e8101a0 100644 --- a/ui/base/win/foreground_helper.h +++ b/ui/base/win/foreground_helper.h @@ -6,7 +6,7 @@ #define UI_BASE_WIN_FOREGROUND_HELPER_H_ #include "base/logging.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace ui { @@ -17,7 +17,7 @@ namespace ui { // to be capable of moving to the foreground. // // This is probably leveraging a windows bug. -class UI_EXPORT ForegroundHelper : public WindowImpl { +class UI_EXPORT ForegroundHelper : public gfx::WindowImpl { public: ForegroundHelper() : window_(NULL) { } diff --git a/ui/base/win/hidden_window.cc b/ui/base/win/hidden_window.cc index fb4f483..3b21519 100644 --- a/ui/base/win/hidden_window.cc +++ b/ui/base/win/hidden_window.cc @@ -4,7 +4,7 @@ #include "ui/base/win/hidden_window.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace ui { @@ -21,7 +21,7 @@ namespace { // window that interact poorly with us. // // See: http://crbug.com/16476 -class TempParent : public ui::WindowImpl { +class TempParent : public gfx::WindowImpl { public: static TempParent* Get() { static TempParent* g_temp_parent; diff --git a/ui/base/win/hwnd_subclass.cc b/ui/base/win/hwnd_subclass.cc index cd557fa..34e2bf4 100644 --- a/ui/base/win/hwnd_subclass.cc +++ b/ui/base/win/hwnd_subclass.cc @@ -9,8 +9,8 @@ #include "base/logging.h" #include "base/memory/scoped_vector.h" #include "base/memory/singleton.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" namespace { const char kHWNDSubclassKey[] = "__UI_BASE_WIN_HWND_SUBCLASS_PROC__"; @@ -123,7 +123,7 @@ HWNDSubclass::HWNDSubclass(HWND target) : target_(target), original_wnd_proc_(GetCurrentWndProc(target)), prop_(target, kHWNDSubclassKey, this) { - ui::SetWindowProc(target_, &WndProc); + gfx::SetWindowProc(target_, &WndProc); } HWNDSubclass::~HWNDSubclass() { diff --git a/ui/base/win/hwnd_subclass_unittest.cc b/ui/base/win/hwnd_subclass_unittest.cc index 5917ef2..520f52b 100644 --- a/ui/base/win/hwnd_subclass_unittest.cc +++ b/ui/base/win/hwnd_subclass_unittest.cc @@ -6,13 +6,13 @@ #include "base/basictypes.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace ui { namespace { -class TestWindow : public ui::WindowImpl { +class TestWindow : public gfx::WindowImpl { public: TestWindow() : saw_message(false) {} virtual ~TestWindow() {} @@ -20,7 +20,7 @@ class TestWindow : public ui::WindowImpl { bool saw_message; private: - // Overridden from ui::WindowImpl: + // Overridden from gfx::WindowImpl: virtual BOOL ProcessWindowMessage(HWND window, UINT message, WPARAM w_param, diff --git a/ui/base/win/hwnd_util.cc b/ui/base/win/hwnd_util.cc deleted file mode 100644 index 0a8dfb2..0000000 --- a/ui/base/win/hwnd_util.cc +++ /dev/null @@ -1,214 +0,0 @@ -// Copyright (c) 2012 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 "ui/base/win/hwnd_util.h" - -#include "base/i18n/rtl.h" -#include "base/strings/string_util.h" -#include "base/win/metro.h" -#include "base/win/win_util.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -namespace ui { - -namespace { - -// Adjust the window to fit. -void AdjustWindowToFit(HWND hwnd, const RECT& bounds, bool fit_to_monitor) { - if (fit_to_monitor) { - // Get the monitor. - HMONITOR hmon = MonitorFromRect(&bounds, MONITOR_DEFAULTTONEAREST); - if (hmon) { - MONITORINFO mi; - mi.cbSize = sizeof(mi); - base::win::GetMonitorInfoWrapper(hmon, &mi); - gfx::Rect window_rect(bounds); - gfx::Rect monitor_rect(mi.rcWork); - gfx::Rect new_window_rect = window_rect; - new_window_rect.AdjustToFit(monitor_rect); - if (new_window_rect != 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; - } - // Else fall through. - } else { - NOTREACHED() << "Unable to find default monitor"; - // Fall through. - } - } // Else fall through. - - // The window is not being fit to monitor, or the window fits on the monitor - // as is, or we have no monitor info; reset the bounds. - ::SetWindowPos(hwnd, 0, bounds.left, bounds.top, - bounds.right - bounds.left, bounds.bottom - bounds.top, - SWP_NOACTIVATE | SWP_NOZORDER); -} - -} // 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 - // that we got the entire class name if the result is exactly equal to the - // size of the buffer minus one. - DWORD buffer_size = MAX_PATH; - while (true) { - std::wstring output; - DWORD size_ret = - GetClassNameW(window, WriteInto(&output, buffer_size), buffer_size); - if (size_ret == 0) - break; - if (size_ret < (buffer_size - 1)) { - output.resize(size_ret); - return output; - } - buffer_size *= 2; - } - return std::wstring(); // error -} - -#pragma warning(push) -#pragma warning(disable:4312 4244) - -WNDPROC SetWindowProc(HWND hwnd, WNDPROC proc) { - // The reason we don't return the SetwindowLongPtr() value is that it returns - // the orignal window procedure and not the current one. I don't know if it is - // a bug or an intended feature. - WNDPROC oldwindow_proc = - reinterpret_cast<WNDPROC>(GetWindowLongPtr(hwnd, GWLP_WNDPROC)); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(proc)); - return oldwindow_proc; -} - -void* SetWindowUserData(HWND hwnd, void* user_data) { - return - reinterpret_cast<void*>(SetWindowLongPtr(hwnd, GWLP_USERDATA, - reinterpret_cast<LONG_PTR>(user_data))); -} - -void* GetWindowUserData(HWND hwnd) { - DWORD process_id = 0; - DWORD thread_id = GetWindowThreadProcessId(hwnd, &process_id); - // A window outside the current process needs to be ignored. - if (process_id != ::GetCurrentProcessId()) - return NULL; - return reinterpret_cast<void*>(GetWindowLongPtr(hwnd, GWLP_USERDATA)); -} - -#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) { - 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); - } - - if (::IsRectEmpty(¢er_bounds)) { - // No parent or no parent rect. Center over the monitor the window is on. - HMONITOR monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); - if (monitor) { - MONITORINFO mi = {0}; - mi.cbSize = sizeof(mi); - base::win::GetMonitorInfoWrapper(monitor, &mi); - center_bounds = mi.rcWork; - } else { - NOTREACHED() << "Unable to get default monitor"; - } - } - - window_bounds.left = center_bounds.left; - if (pref.width() < (center_bounds.right - center_bounds.left)) { - window_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; - if (pref.height() < (center_bounds.bottom - center_bounds.top)) { - window_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(); - } - - AdjustWindowToFit(window, window_bounds, !parent); -} - -void CheckWindowCreated(HWND hwnd) { - if (!hwnd) - LOG_GETLASTERROR(FATAL); -} - -void ShowSystemMenu(HWND window) { - RECT rect; - GetWindowRect(window, &rect); - gfx::Point point = gfx::Point(rect.left, rect.top); - static const int kSystemMenuOffset = 10; - point.Offset(kSystemMenuOffset, kSystemMenuOffset); - ShowSystemMenuAtPoint(window, point); -} - -void ShowSystemMenuAtPoint(HWND window, const gfx::Point& point) { - // In the Metro process, we never want to show the system menu. - if (base::win::IsMetroProcess()) - return; - UINT flags = TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD; - if (base::i18n::IsRTL()) - flags |= TPM_RIGHTALIGN; - HMENU menu = GetSystemMenu(window, FALSE); - const int command = - TrackPopupMenu(menu, flags, point.x(), point.y(), 0, window, NULL); - if (command) - SendMessage(window, WM_SYSCOMMAND, command, 0); -} - -extern "C" { - typedef HWND (*RootWindow)(); -} - -HWND GetWindowToParentTo(bool get_real_hwnd) { - HMODULE metro = base::win::GetMetroModule(); - if (!metro) - return get_real_hwnd ? ::GetDesktopWindow() : HWND_DESKTOP; - // In windows 8 metro-mode the root window is not the desktop. - RootWindow root_window = - reinterpret_cast<RootWindow>(::GetProcAddress(metro, "GetRootWindow")); - return root_window(); -} - -} // namespace ui diff --git a/ui/base/win/hwnd_util.h b/ui/base/win/hwnd_util.h deleted file mode 100644 index ece1d3c..0000000 --- a/ui/base/win/hwnd_util.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2012 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 UI_BASE_WIN_HWND_UTIL_H_ -#define UI_BASE_WIN_HWND_UTIL_H_ - -#include <windows.h> - -#include "base/strings/string16.h" -#include "ui/base/ui_export.h" - -namespace gfx { -class Point; -class Size; -} - -namespace ui { - -// A version of the GetClassNameW API that returns the class name in an -// string16. An empty result indicates a failure to get the class name. -UI_EXPORT string16 GetClassName(HWND hwnd); - -// Useful for subclassing a HWND. Returns the previous window procedure. -UI_EXPORT WNDPROC SetWindowProc(HWND hwnd, WNDPROC wndproc); - -// Pointer-friendly wrappers around Get/SetWindowLong(..., GWLP_USERDATA, ...) -// Returns the previously set value. -UI_EXPORT void* SetWindowUserData(HWND hwnd, void* user_data); -UI_EXPORT void* GetWindowUserData(HWND hwnd); - -// Returns true if the specified window is the current active top window or one -// of its children. -UI_EXPORT bool DoesWindowBelongToActiveWindow(HWND window); - -// Sizes the window to have a window size of |pref|, then centers the window -// over |parent|, ensuring the window fits on screen. -UI_EXPORT void CenterAndSizeWindow(HWND parent, - HWND window, - const gfx::Size& pref); - -// If |hwnd| is NULL logs various thing and CHECKs. Invoke right after calling -// CreateWindow. -UI_EXPORT void CheckWindowCreated(HWND hwnd); - -// Shows |window|'s system menu (at a specified |point| in screen coordinates). -UI_EXPORT void ShowSystemMenu(HWND window); -UI_EXPORT void ShowSystemMenuAtPoint(HWND window, const gfx::Point& point); - -// Returns the window you can use to parent a top level window. -// Note that in some cases we create child windows not parented to its final -// container so in those cases you should pass true in |get_real_hwnd|. -UI_EXPORT HWND GetWindowToParentTo(bool get_real_hwnd); - -} // namespace ui - -#endif // UI_BASE_WIN_HWND_UTIL_H_ diff --git a/ui/base/win/mouse_wheel_util.cc b/ui/base/win/mouse_wheel_util.cc index 941c069..223e3a8 100644 --- a/ui/base/win/mouse_wheel_util.cc +++ b/ui/base/win/mouse_wheel_util.cc @@ -8,7 +8,7 @@ #include "base/auto_reset.h" #include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace ui { @@ -31,7 +31,7 @@ static bool WindowSupportsRerouteMouseWheel(HWND window) { } static bool IsCompatibleWithMouseWheelRedirection(HWND window) { - std::wstring class_name = GetClassName(window); + std::wstring class_name = gfx::GetClassName(window); // Mousewheel redirection to comboboxes is a surprising and // undesireable user behavior. return !(class_name == L"ComboBox" || @@ -39,7 +39,7 @@ static bool IsCompatibleWithMouseWheelRedirection(HWND window) { } static bool CanRedirectMouseWheelFrom(HWND window) { - std::wstring class_name = GetClassName(window); + std::wstring class_name = gfx::GetClassName(window); // Older Thinkpad mouse wheel drivers create a window under mouse wheel // pointer. Detect if we are dealing with this window. In this case we diff --git a/ui/base/win/scoped_set_map_mode.h b/ui/base/win/scoped_set_map_mode.h deleted file mode 100644 index bf2b78d..0000000 --- a/ui/base/win/scoped_set_map_mode.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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 UI_BASE_WIN_SCOPED_SET_MAP_MODE_H_ -#define UI_BASE_WIN_SCOPED_SET_MAP_MODE_H_ - -#include <windows.h> - -#include "base/basictypes.h" -#include "base/logging.h" - -namespace ui { - -// Helper class for setting and restore the map mode on a DC. -class ScopedSetMapMode { - public: - ScopedSetMapMode(HDC hdc, int map_mode) - : hdc_(hdc), - old_map_mode_(SetMapMode(hdc, map_mode)) { - DCHECK(hdc_); - DCHECK_NE(map_mode, 0); - DCHECK_NE(old_map_mode_, 0); - } - - ~ScopedSetMapMode() { - const int mode = SetMapMode(hdc_, old_map_mode_); - DCHECK_NE(mode, 0); - } - - private: - HDC hdc_; - int old_map_mode_; - - DISALLOW_COPY_AND_ASSIGN(ScopedSetMapMode); -}; - -} // namespace ui - -#endif // UI_BASE_WIN_SCOPED_SET_MAP_MODE_H_ diff --git a/ui/base/win/singleton_hwnd.cc b/ui/base/win/singleton_hwnd.cc deleted file mode 100644 index 9d1685f..0000000 --- a/ui/base/win/singleton_hwnd.cc +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 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 "ui/base/win/singleton_hwnd.h" - -#include "base/memory/singleton.h" -#include "base/message_loop/message_loop.h" - -namespace ui { - -// static -SingletonHwnd* SingletonHwnd::GetInstance() { - return Singleton<SingletonHwnd>::get(); -} - -void SingletonHwnd::AddObserver(Observer* observer) { - if (!hwnd()) { - if (!base::MessageLoop::current() || - base::MessageLoop::current()->type() != base::MessageLoop::TYPE_UI) { - // Creating this window in (e.g.) a renderer inhibits shutdown on - // Windows. See http://crbug.com/230122 and http://crbug.com/236039. - DLOG(ERROR) << "Cannot create windows on non-UI thread!"; - return; - } - WindowImpl::Init(NULL, gfx::Rect()); - } - observer_list_.AddObserver(observer); -} - -void SingletonHwnd::RemoveObserver(Observer* observer) { - if (!hwnd()) - return; - observer_list_.RemoveObserver(observer); -} - -BOOL SingletonHwnd::ProcessWindowMessage(HWND window, - UINT message, - WPARAM wparam, - LPARAM lparam, - LRESULT& result, - DWORD msg_map_id) { - FOR_EACH_OBSERVER(Observer, - observer_list_, - OnWndProc(window, message, wparam, lparam)); - return false; -} - -SingletonHwnd::SingletonHwnd() { -} - -SingletonHwnd::~SingletonHwnd() { -} - -} // namespace ui diff --git a/ui/base/win/singleton_hwnd.h b/ui/base/win/singleton_hwnd.h deleted file mode 100644 index a84b6c0..0000000 --- a/ui/base/win/singleton_hwnd.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2012 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 UI_BASE_WIN_SINGLETON_HWND_H_ -#define UI_BASE_WIN_SINGLETON_HWND_H_ - -#include <windows.h> -#include <vector> - -#include "base/basictypes.h" -#include "base/callback_forward.h" -#include "base/observer_list.h" -#include "ui/base/win/window_impl.h" - -template<typename T> struct DefaultSingletonTraits; - -namespace ui { - -// Singleton message-only HWND that allows interested clients to receive WM_* -// notifications. -class SingletonHwnd : public WindowImpl { - public: - static SingletonHwnd* GetInstance(); - - // Observer interface for receiving Windows WM_* notifications. - class Observer { - public: - virtual void OnWndProc(HWND hwnd, - UINT message, - WPARAM wparam, - LPARAM lparam) = 0; - }; - - // Add/remove observer to receive WM_* notifications. - void AddObserver(Observer* observer); - void RemoveObserver(Observer* observer); - - // Windows callback for WM_* notifications. - virtual BOOL ProcessWindowMessage(HWND window, - UINT message, - WPARAM wparam, - LPARAM lparam, - LRESULT& result, - DWORD msg_map_id) OVERRIDE; - - private: - friend struct DefaultSingletonTraits<SingletonHwnd>; - - SingletonHwnd(); - ~SingletonHwnd(); - - // List of registered observers. - ObserverList<Observer> observer_list_; - - DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); -}; - -} // namespace ui - -#endif // UI_BASE_WIN_SINGLETON_HWND_H_ diff --git a/ui/base/win/window_impl.cc b/ui/base/win/window_impl.cc deleted file mode 100644 index 22ed535..0000000 --- a/ui/base/win/window_impl.cc +++ /dev/null @@ -1,273 +0,0 @@ -// Copyright (c) 2012 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 "ui/base/win/window_impl.h" - -#include <list> - -#include "base/debug/alias.h" -#include "base/memory/singleton.h" -#include "base/strings/string_number_conversions.h" -#include "base/synchronization/lock.h" -#include "base/win/wrapped_window_proc.h" -#include "ui/base/win/hwnd_util.h" - -namespace ui { - -static const DWORD kWindowDefaultChildStyle = - WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; -static const DWORD kWindowDefaultStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN; -static const DWORD kWindowDefaultExStyle = 0; - -/////////////////////////////////////////////////////////////////////////////// -// WindowImpl class tracking. - -// Several external scripts rely explicitly on this base class name for -// acquiring the window handle and will break if this is modified! -// static -const wchar_t* const WindowImpl::kBaseClassName = L"Chrome_WidgetWin_"; - -// WindowImpl class information used for registering unique windows. -struct ClassInfo { - UINT style; - HICON icon; - - ClassInfo(int style, HICON icon) - : style(style), - icon(icon) {} - - // Compares two ClassInfos. Returns true if all members match. - bool Equals(const ClassInfo& other) const { - return (other.style == style && other.icon == icon); - } -}; - -// WARNING: this class may be used on multiple threads. -class ClassRegistrar { - public: - ~ClassRegistrar(); - - static ClassRegistrar* GetInstance(); - - // Returns the atom identifying the class matching |class_info|, - // creating and registering a new class if the class is not yet known. - ATOM RetrieveClassAtom(const ClassInfo& class_info); - - private: - // Represents a registered window class. - struct RegisteredClass { - RegisteredClass(const ClassInfo& info, ATOM atom); - - // Info used to create the class. - ClassInfo info; - - // The atom identifying the window class. - ATOM atom; - }; - - ClassRegistrar(); - friend struct DefaultSingletonTraits<ClassRegistrar>; - - typedef std::list<RegisteredClass> RegisteredClasses; - RegisteredClasses registered_classes_; - - // Counter of how many classes have been registered so far. - int registered_count_; - - base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(ClassRegistrar); -}; - -ClassRegistrar::~ClassRegistrar() {} - -// static -ClassRegistrar* ClassRegistrar::GetInstance() { - return Singleton<ClassRegistrar, - LeakySingletonTraits<ClassRegistrar> >::get(); -} - -ATOM ClassRegistrar::RetrieveClassAtom(const ClassInfo& class_info) { - base::AutoLock auto_lock(lock_); - for (RegisteredClasses::const_iterator i = registered_classes_.begin(); - i != registered_classes_.end(); ++i) { - if (class_info.Equals(i->info)) - return i->atom; - } - - // No class found, need to register one. - string16 name = string16(WindowImpl::kBaseClassName) + - base::IntToString16(registered_count_++); - - WNDCLASSEX window_class; - base::win::InitializeWindowClass( - name.c_str(), - &base::win::WrappedWindowProc<WindowImpl::WndProc>, - class_info.style, - 0, - 0, - NULL, - NULL, - NULL, - class_info.icon, - class_info.icon, - &window_class); - HMODULE instance = window_class.hInstance; - ATOM atom = RegisterClassEx(&window_class); - CHECK(atom) << GetLastError(); - - registered_classes_.push_back(RegisteredClass(class_info, atom)); - - return atom; -} - -ClassRegistrar::RegisteredClass::RegisteredClass(const ClassInfo& info, - ATOM atom) - : info(info), - atom(atom) {} - -ClassRegistrar::ClassRegistrar() : registered_count_(0) {} - - -/////////////////////////////////////////////////////////////////////////////// -// WindowImpl, public - -WindowImpl::WindowImpl() - : window_style_(0), - window_ex_style_(kWindowDefaultExStyle), - class_style_(CS_DBLCLKS), - hwnd_(NULL), - got_create_(false), - got_valid_hwnd_(false), - destroyed_(NULL) { -} - -WindowImpl::~WindowImpl() { - if (destroyed_) - *destroyed_ = true; - ClearUserData(); -} - -void WindowImpl::Init(HWND parent, const gfx::Rect& bounds) { - if (window_style_ == 0) - window_style_ = parent ? kWindowDefaultChildStyle : kWindowDefaultStyle; - - if (parent == HWND_DESKTOP) { - // Only non-child windows can have HWND_DESKTOP (0) as their parent. - CHECK((window_style_ & WS_CHILD) == 0); - parent = GetWindowToParentTo(false); - } else if (parent == ::GetDesktopWindow()) { - // Any type of window can have the "Desktop Window" as their parent. - parent = GetWindowToParentTo(true); - } else if (parent != HWND_MESSAGE) { - CHECK(::IsWindow(parent)); - } - - int x, y, width, height; - if (bounds.IsEmpty()) { - x = y = width = height = CW_USEDEFAULT; - } else { - x = bounds.x(); - y = bounds.y(); - width = bounds.width(); - height = bounds.height(); - } - - ATOM atom = GetWindowClassAtom(); - bool destroyed = false; - destroyed_ = &destroyed; - HWND hwnd = CreateWindowEx(window_ex_style_, - reinterpret_cast<wchar_t*>(atom), NULL, - window_style_, x, y, width, height, - parent, NULL, NULL, this); - - // First nccalcszie (during CreateWindow) for captioned windows is - // deliberately ignored so force a second one here to get the right - // non-client set up. - if (hwnd && (window_style_ & WS_CAPTION)) { - SetWindowPos(hwnd, NULL, 0, 0, 0, 0, - SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | - SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); - } - - if (!hwnd_ && GetLastError() == 0) { - base::debug::Alias(&destroyed); - base::debug::Alias(&hwnd); - bool got_create = got_create_; - base::debug::Alias(&got_create); - bool got_valid_hwnd = got_valid_hwnd_; - base::debug::Alias(&got_valid_hwnd); - WNDCLASSEX class_info; - memset(&class_info, 0, sizeof(WNDCLASSEX)); - class_info.cbSize = sizeof(WNDCLASSEX); - BOOL got_class = GetClassInfoEx(GetModuleHandle(NULL), - reinterpret_cast<wchar_t*>(atom), - &class_info); - base::debug::Alias(&got_class); - bool procs_match = got_class && class_info.lpfnWndProc == - base::win::WrappedWindowProc<&WindowImpl::WndProc>; - base::debug::Alias(&procs_match); - CHECK(false); - } - if (!destroyed) - destroyed_ = NULL; - - CheckWindowCreated(hwnd_); - - // The window procedure should have set the data for us. - CHECK_EQ(this, ui::GetWindowUserData(hwnd)); -} - -HICON WindowImpl::GetDefaultWindowIcon() const { - return NULL; -} - -LRESULT WindowImpl::OnWndProc(UINT message, WPARAM w_param, LPARAM l_param) { - LRESULT result = 0; - - // Handle the message if it's in our message map; otherwise, let the system - // handle it. - if (!ProcessWindowMessage(hwnd_, message, w_param, l_param, result)) - result = DefWindowProc(hwnd_, message, w_param, l_param); - - return result; -} - -void WindowImpl::ClearUserData() { - if (::IsWindow(hwnd_)) - ui::SetWindowUserData(hwnd_, NULL); -} - -// static -LRESULT CALLBACK WindowImpl::WndProc(HWND hwnd, - UINT message, - WPARAM w_param, - LPARAM l_param) { - if (message == WM_NCCREATE) { - CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(l_param); - WindowImpl* window = reinterpret_cast<WindowImpl*>(cs->lpCreateParams); - DCHECK(window); - ui::SetWindowUserData(hwnd, window); - window->hwnd_ = hwnd; - window->got_create_ = true; - if (hwnd) - window->got_valid_hwnd_ = true; - return TRUE; - } - - WindowImpl* window = reinterpret_cast<WindowImpl*>( - ui::GetWindowUserData(hwnd)); - if (!window) - return 0; - - return window->OnWndProc(message, w_param, l_param); -} - -ATOM WindowImpl::GetWindowClassAtom() { - HICON icon = GetDefaultWindowIcon(); - ClassInfo class_info(initial_class_style(), icon); - return ClassRegistrar::GetInstance()->RetrieveClassAtom(class_info); -} - -} // namespace ui diff --git a/ui/base/win/window_impl.h b/ui/base/win/window_impl.h deleted file mode 100644 index 1f3b5d3..0000000 --- a/ui/base/win/window_impl.h +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) 2012 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 UI_BASE_WIN_WINDOW_IMPL_H_ -#define UI_BASE_WIN_WINDOW_IMPL_H_ - -#include <atlbase.h> -#include <atlapp.h> -#include <atlmisc.h> -#include <atlcrack.h> - -#include <string> - -#include "base/logging.h" -#include "ui/base/ui_export.h" -#include "ui/gfx/native_widget_types.h" -#include "ui/gfx/rect.h" - -namespace ui { - -// An interface implemented by classes that use message maps. -// ProcessWindowMessage is implemented by the BEGIN_MESSAGE_MAP_EX macro. -class MessageMapInterface { - public: - // Processes one message from the window's message queue. - virtual BOOL ProcessWindowMessage(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param, - LRESULT& result, - DWORD msg_map_id = 0) = 0; -}; - -/////////////////////////////////////////////////////////////////////////////// -// -// WindowImpl -// A convenience class that encapsulates the details of creating and -// destroying a HWND. This class also hosts the windows procedure used by all -// Windows. -// -/////////////////////////////////////////////////////////////////////////////// -class UI_EXPORT WindowImpl : public MessageMapInterface { - public: - WindowImpl(); - virtual ~WindowImpl(); - - // Initializes the Window with a parent and an initial desired size. - void Init(HWND parent, const gfx::Rect& bounds); - - // Returns the default window icon to use for windows of this type. - virtual HICON GetDefaultWindowIcon() const; - - // Returns the HWND associated with this Window. - HWND hwnd() const { return hwnd_; } - - // Sets the window styles. This is ONLY used when the window is created. - // In other words, if you invoke this after invoking Init, nothing happens. - void set_window_style(DWORD style) { window_style_ = style; } - DWORD window_style() const { return window_style_; } - - // Sets the extended window styles. See comment about |set_window_style|. - void set_window_ex_style(DWORD style) { window_ex_style_ = style; } - DWORD window_ex_style() const { return window_ex_style_; } - - // Sets the class style to use. The default is CS_DBLCLKS. - void set_initial_class_style(UINT class_style) { - // We dynamically generate the class name, so don't register it globally! - DCHECK_EQ((class_style & CS_GLOBALCLASS), 0u); - class_style_ = class_style; - } - UINT initial_class_style() const { return class_style_; } - - protected: - // Handles the WndProc callback for this object. - virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); - - // Subclasses must call this method from their destructors to ensure that - // this object is properly disassociated from the HWND during destruction, - // otherwise it's possible this object may still exist while a subclass is - // destroyed. - void ClearUserData(); - - private: - friend class ClassRegistrar; - - // The window procedure used by all Windows. - static LRESULT CALLBACK WndProc(HWND window, - UINT message, - WPARAM w_param, - LPARAM l_param); - - // Gets the window class atom to use when creating the corresponding HWND. - // If necessary, this registers the window class. - ATOM GetWindowClassAtom(); - - // All classes registered by WindowImpl start with this name. - static const wchar_t* const kBaseClassName; - - // Window Styles used when creating the window. - DWORD window_style_; - - // Window Extended Styles used when creating the window. - DWORD window_ex_style_; - - // Style of the class to use. - UINT class_style_; - - // Our hwnd. - HWND hwnd_; - - // For debugging. - // TODO(sky): nuke this when get crash data. - bool got_create_; - bool got_valid_hwnd_; - bool* destroyed_; - - DISALLOW_COPY_AND_ASSIGN(WindowImpl); -}; - -} // namespace ui - -#endif // UI_BASE_WIN_WINDOW_IMPL_H_ |