From bde885b4e8cf11db7ba2af6c70a6580830a52e7a Mon Sep 17 00:00:00 2001 From: "ben@chromium.org" Date: Thu, 12 Sep 2013 20:55:53 +0000 Subject: Move a bunch of windows stuff from ui/base/win to ui/gfx/win R=sky@chromium.org BUG=103304 Review URL: https://codereview.chromium.org/23769011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222860 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/about_flags.cc | 4 +- chrome/browser/chrome_browser_main.cc | 2 +- .../chromeos/login/chrome_restart_request.cc | 4 +- .../system_display/display_info_provider_win.cc | 2 +- chrome/browser/hang_monitor/hung_plugin_action.cc | 4 +- chrome/browser/metrics/metrics_log.cc | 2 +- chrome/browser/process_singleton_win.cc | 2 +- chrome/browser/ui/views/app_menu_button_win.cc | 4 +- .../frame/browser_desktop_root_window_host_win.cc | 2 +- chrome/browser/ui/views/frame/browser_frame_win.cc | 2 +- .../ui/views/frame/glass_browser_frame_view.cc | 2 +- .../ui/views/frame/minimize_button_metrics_win.cc | 2 +- chrome/browser/ui/views/infobars/infobar_view.cc | 4 +- .../browser/ui/views/omnibox/omnibox_view_win.cc | 4 +- chrome/browser/ui/views/simple_message_box_win.cc | 4 +- .../ui/views/status_icons/status_tray_win.cc | 6 +- chrome/browser/ui/views/tabs/dragged_tab_view.cc | 2 +- chrome/browser/ui/views/tabs/tab_strip.cc | 4 +- content/app/content_main_runner.cc | 2 +- content/browser/plugin_service_impl.cc | 4 +- content/browser/renderer_host/backing_store_win.cc | 2 +- .../renderer_host/render_process_host_impl.cc | 1 + .../renderer_host/render_widget_host_view_base.cc | 8 +- .../render_widget_host_view_browsertest.cc | 4 +- .../renderer_host/render_widget_host_view_win.cc | 18 +- .../browser/web_contents/web_contents_view_win.h | 4 +- .../browser/zygote_host/zygote_host_impl_linux.cc | 1 + content/child/npapi/webplugin_delegate_impl_win.cc | 6 +- content/shell/app/shell_main_delegate.cc | 1 + content/shell/browser/shell_win.cc | 16 +- remoting/host/plugin/host_plugin.cc | 2 +- tools/memory_watcher/hotkey.h | 4 +- ui/aura/root_window_host_win.h | 4 +- ui/base/ime/input_method_win.cc | 4 +- ui/base/l10n/l10n_util_win.cc | 2 +- ui/base/l10n/l10n_util_win_unittest.cc | 2 +- ui/base/layout.cc | 2 +- ui/base/resource/resource_bundle_win.cc | 2 +- ui/base/text/utf16_indexing.cc | 55 ----- ui/base/text/utf16_indexing.h | 49 ---- ui/base/text/utf16_indexing_unittest.cc | 32 --- ui/base/ui_base_switches.cc | 3 - ui/base/ui_base_switches.h | 1 - ui/base/win/events_win.cc | 2 +- ui/base/win/foreground_helper.cc | 2 +- ui/base/win/foreground_helper.h | 4 +- ui/base/win/hidden_window.cc | 4 +- ui/base/win/hwnd_subclass.cc | 6 +- ui/base/win/hwnd_subclass_unittest.cc | 6 +- ui/base/win/hwnd_util.cc | 214 ---------------- ui/base/win/hwnd_util.h | 57 ----- ui/base/win/mouse_wheel_util.cc | 6 +- ui/base/win/scoped_set_map_mode.h | 40 --- ui/base/win/singleton_hwnd.cc | 55 ----- ui/base/win/singleton_hwnd.h | 61 ----- ui/base/win/window_impl.cc | 273 --------------------- ui/base/win/window_impl.h | 123 ---------- ui/compositor/test/test_compositor_host_win.cc | 4 +- ui/gfx/canvas_paint_win.h | 2 +- ui/gfx/display.cc | 2 +- ui/gfx/dpi_win.cc | 175 ------------- ui/gfx/dpi_win.h | 63 ----- ui/gfx/font_smoothing_win.cc | 6 +- ui/gfx/platform_font_win.cc | 6 +- ui/gfx/render_text.cc | 6 +- ui/gfx/render_text_linux.cc | 10 +- ui/gfx/render_text_win.cc | 12 +- ui/gfx/screen_win.cc | 2 +- ui/gfx/switches.cc | 5 +- ui/gfx/switches.h | 3 +- ui/gfx/sys_color_change_listener.cc | 8 +- ui/gfx/utf16_indexing.cc | 55 +++++ ui/gfx/utf16_indexing.h | 49 ++++ ui/gfx/utf16_indexing_unittest.cc | 32 +++ ui/gfx/win/dpi.cc | 175 +++++++++++++ ui/gfx/win/dpi.h | 63 +++++ ui/gfx/win/hwnd_util.cc | 214 ++++++++++++++++ ui/gfx/win/hwnd_util.h | 54 ++++ ui/gfx/win/scoped_set_map_mode.h | 40 +++ ui/gfx/win/singleton_hwnd.cc | 55 +++++ ui/gfx/win/singleton_hwnd.h | 61 +++++ ui/gfx/win/window_impl.cc | 272 ++++++++++++++++++++ ui/gfx/win/window_impl.h | 123 ++++++++++ ui/native_theme/native_theme_win.cc | 2 +- ui/surface/accelerated_surface_win.cc | 4 +- ui/ui.gyp | 22 +- ui/ui_unittests.gypi | 2 +- ui/views/controls/combobox/native_combobox_win.cc | 4 +- ui/views/controls/menu/menu_win.cc | 4 +- ui/views/controls/menu/native_menu_win.cc | 8 +- ui/views/controls/native/native_view_host_win.cc | 4 +- ui/views/controls/native_control.cc | 6 +- ui/views/controls/native_control_win.cc | 6 +- .../controls/textfield/native_textfield_win.cc | 4 +- .../controls/textfield/textfield_views_model.cc | 4 +- ui/views/widget/aero_tooltip_manager.cc | 4 +- .../desktop_aura/desktop_root_window_host_win.cc | 2 +- ui/views/widget/native_widget_win.cc | 4 +- ui/views/widget/native_widget_win.h | 2 +- ui/views/widget/tooltip_manager_win.cc | 8 +- ui/views/win/hwnd_message_handler.cc | 10 +- ui/views/win/hwnd_message_handler.h | 4 +- webkit/child/webthemeengine_impl_win.cc | 2 +- 103 files changed, 1368 insertions(+), 1373 deletions(-) delete mode 100644 ui/base/text/utf16_indexing.cc delete mode 100644 ui/base/text/utf16_indexing.h delete mode 100644 ui/base/text/utf16_indexing_unittest.cc delete mode 100644 ui/base/win/hwnd_util.cc delete mode 100644 ui/base/win/hwnd_util.h delete mode 100644 ui/base/win/scoped_set_map_mode.h delete mode 100644 ui/base/win/singleton_hwnd.cc delete mode 100644 ui/base/win/singleton_hwnd.h delete mode 100644 ui/base/win/window_impl.cc delete mode 100644 ui/base/win/window_impl.h delete mode 100644 ui/gfx/dpi_win.cc delete mode 100644 ui/gfx/dpi_win.h create mode 100644 ui/gfx/utf16_indexing.cc create mode 100644 ui/gfx/utf16_indexing.h create mode 100644 ui/gfx/utf16_indexing_unittest.cc create mode 100644 ui/gfx/win/dpi.cc create mode 100644 ui/gfx/win/dpi.h create mode 100644 ui/gfx/win/hwnd_util.cc create mode 100644 ui/gfx/win/hwnd_util.h create mode 100644 ui/gfx/win/scoped_set_map_mode.h create mode 100644 ui/gfx/win/singleton_hwnd.cc create mode 100644 ui/gfx/win/singleton_hwnd.h create mode 100644 ui/gfx/win/window_impl.cc create mode 100644 ui/gfx/win/window_impl.h diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index 207744e..65a2a7e 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1567,8 +1567,8 @@ const Experiment kExperiments[] = { IDS_FLAGS_HIDPI_NAME, IDS_FLAGS_HIDPI_DESCRIPTION, kOsWin, - ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(gfx::switches::kHighDPISupport, "1", - gfx::switches::kHighDPISupport, "0") + ENABLE_DISABLE_VALUE_TYPE_AND_VALUE(switches::kHighDPISupport, "1", + switches::kHighDPISupport, "0") }, #if defined(OS_CHROMEOS) { diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index fbbff83..4227996 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -175,7 +175,7 @@ #include "net/base/net_util.h" #include "printing/printed_document.h" #include "ui/base/l10n/l10n_util_win.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #endif // defined(OS_WIN) #if defined(OS_MACOSX) diff --git a/chrome/browser/chromeos/login/chrome_restart_request.cc b/chrome/browser/chromeos/login/chrome_restart_request.cc index a06f5b9..9b2edd5 100644 --- a/chrome/browser/chromeos/login/chrome_restart_request.cc +++ b/chrome/browser/chromeos/login/chrome_restart_request.cc @@ -189,8 +189,8 @@ std::string DeriveCommandLine(const GURL& start_url, chromeos::switches::kHasChromeOSKeyboard, chromeos::switches::kLoginProfile, chromeos::switches::kNaturalScrollDefault, - gfx::switches::kEnableBrowserTextSubpixelPositioning, - gfx::switches::kEnableWebkitTextSubpixelPositioning, + ::switches::kEnableBrowserTextSubpixelPositioning, + ::switches::kEnableWebkitTextSubpixelPositioning, views::corewm::switches::kNoDropShadows, views::corewm::switches::kWindowAnimationsDisabled, }; diff --git a/chrome/browser/extensions/api/system_display/display_info_provider_win.cc b/chrome/browser/extensions/api/system_display/display_info_provider_win.cc index 57a4c3a..dca172e 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider_win.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider_win.cc @@ -8,8 +8,8 @@ #include "base/strings/utf_string_conversions.h" #include "ui/gfx/display.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/size.h" +#include "ui/gfx/win/dpi.h" namespace extensions { diff --git a/chrome/browser/hang_monitor/hung_plugin_action.cc b/chrome/browser/hang_monitor/hung_plugin_action.cc index cdb9e59..bc93207 100644 --- a/chrome/browser/hang_monitor/hung_plugin_action.cc +++ b/chrome/browser/hang_monitor/hung_plugin_action.cc @@ -14,7 +14,7 @@ #include "content/public/common/webplugininfo.h" #include "grit/generated_resources.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace { @@ -186,7 +186,7 @@ bool HungPluginAction::GetPluginNameAndVersion(HWND plugin_window, // static BOOL CALLBACK HungPluginAction::DismissMessageBox(HWND window, LPARAM ignore) { - string16 class_name = ui::GetClassName(window); + string16 class_name = gfx::GetClassName(window); // #32770 is the dialog window class which is the window class of // the message box being displayed. if (class_name == L"#32770") { diff --git a/chrome/browser/metrics/metrics_log.cc b/chrome/browser/metrics/metrics_log.cc index b55fab7..38df09f 100644 --- a/chrome/browser/metrics/metrics_log.cc +++ b/chrome/browser/metrics/metrics_log.cc @@ -58,7 +58,7 @@ #if defined(OS_WIN) #include "base/win/metro.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx extern "C" IMAGE_DOS_HEADER __ImageBase; diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc index e82bf79..66a8180 100644 --- a/chrome/browser/process_singleton_win.cc +++ b/chrome/browser/process_singleton_win.cc @@ -38,7 +38,7 @@ #include "grit/generated_resources.h" #include "net/base/escape.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace { diff --git a/chrome/browser/ui/views/app_menu_button_win.cc b/chrome/browser/ui/views/app_menu_button_win.cc index 4e0a3a0..3e63d81 100644 --- a/chrome/browser/ui/views/app_menu_button_win.cc +++ b/chrome/browser/ui/views/app_menu_button_win.cc @@ -5,7 +5,7 @@ #include "chrome/browser/ui/views/app_menu_button_win.h" #include "ui/base/events/event.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/views/widget/widget.h" AppMenuButtonWin::AppMenuButtonWin(views::MenuButtonListener* listener) @@ -15,7 +15,7 @@ AppMenuButtonWin::AppMenuButtonWin(views::MenuButtonListener* listener) bool AppMenuButtonWin::OnKeyPressed(const ui::KeyEvent& event) { if (event.key_code() == ui::VKEY_SPACE) { // Explicitly show the system menu at a good location on [Alt]+[Space]. - ui::ShowSystemMenu(GetWidget()->GetNativeView()); + gfx::ShowSystemMenu(GetWidget()->GetNativeView()); return false; } return views::MenuButton::OnKeyPressed(event); diff --git a/chrome/browser/ui/views/frame/browser_desktop_root_window_host_win.cc b/chrome/browser/ui/views/frame/browser_desktop_root_window_host_win.cc index 6310a02..916fe65 100644 --- a/chrome/browser/ui/views/frame/browser_desktop_root_window_host_win.cc +++ b/chrome/browser/ui/views/frame/browser_desktop_root_window_host_win.cc @@ -17,7 +17,7 @@ #include "chrome/browser/ui/views/theme_image_mapper.h" #include "grit/theme_resources.h" #include "ui/base/theme_provider.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #include "ui/views/controls/menu/native_menu_win.h" #pragma comment(lib, "dwmapi.lib") diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 872ae88..c9d9ad8 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -36,8 +36,8 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/base/theme_provider.h" #include "ui/base/window_open_disposition.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/font.h" +#include "ui/gfx/win/dpi.h" #include "ui/views/controls/menu/native_menu_win.h" #include "ui/views/views_delegate.h" #include "ui/views/widget/native_widget_win.h" diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc index a6c83e7..bc69baa 100644 --- a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc +++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc @@ -26,9 +26,9 @@ #include "ui/base/resource/resource_bundle_win.h" #include "ui/base/theme_provider.h" #include "ui/gfx/canvas.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/icon_util.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/win/dpi.h" #include "ui/views/controls/label.h" #include "ui/views/layout/layout_constants.h" #include "ui/views/win/hwnd_util.h" diff --git a/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc b/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc index 784c483..858b7a9 100644 --- a/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc +++ b/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "base/i18n/rtl.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" namespace { diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index 0936c95..a791d1c 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -38,8 +38,8 @@ #if defined(OS_WIN) #include "base/win/win_util.h" #include "base/win/windows_version.h" -#include "ui/base/win/hwnd_util.h" #include "ui/gfx/icon_util.h" +#include "ui/gfx/win/hwnd_util.h" #endif // static @@ -340,7 +340,7 @@ void InfoBarView::PlatformSpecificHide(bool animate) { // Do not restore focus (and active state with it) if some other top-level // window became active. views::Widget* widget = GetWidget(); - if (!widget || ui::DoesWindowBelongToActiveWindow(widget->GetNativeView())) + if (!widget || gfx::DoesWindowBelongToActiveWindow(widget->GetNativeView())) FocusLastFocusedExternalView(); #endif } diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc index fde88da..651bf4c 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_win.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_win.cc @@ -62,11 +62,11 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/touch/touch_enabled.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/base/win/touch_input.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/views/button_drag_utils.h" #include "ui/views/controls/menu/menu_item_view.h" #include "ui/views/controls/menu/menu_runner.h" @@ -2037,7 +2037,7 @@ void OmniboxViewWin::OnSysChar(TCHAR ch, // something useful, so discard those. Note that [Ctrl]+[Alt]+ generates // WM_CHAR instead of WM_SYSCHAR, so it is not handled here. if (ch == VK_SPACE) { - ui::ShowSystemMenu( + gfx::ShowSystemMenu( native_view_host_->GetWidget()->GetTopLevelWidget()->GetNativeWindow()); } } diff --git a/chrome/browser/ui/views/simple_message_box_win.cc b/chrome/browser/ui/views/simple_message_box_win.cc index a0eef7d..0b31734 100644 --- a/chrome/browser/ui/views/simple_message_box_win.cc +++ b/chrome/browser/ui/views/simple_message_box_win.cc @@ -5,8 +5,8 @@ #include "chrome/browser/ui/simple_message_box.h" #include "components/startup_metric_utils/startup_metric_utils.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/message_box_win.h" +#include "ui/gfx/win/hwnd_util.h" namespace chrome { @@ -37,7 +37,7 @@ MessageBoxResult ShowMessageBox(gfx::NativeWindow parent, startup_metric_utils::SetNonBrowserUIDisplayed(); if (!parent) - parent = ui::GetWindowToParentTo(true); + parent = gfx::GetWindowToParentTo(true); return NativeShowMessageBox(parent, title, message, type); } diff --git a/chrome/browser/ui/views/status_icons/status_tray_win.cc b/chrome/browser/ui/views/status_icons/status_tray_win.cc index a1f5c66..dbc7d5a 100644 --- a/chrome/browser/ui/views/status_icons/status_tray_win.cc +++ b/chrome/browser/ui/views/status_icons/status_tray_win.cc @@ -9,8 +9,8 @@ #include "base/win/wrapped_window_proc.h" #include "chrome/browser/ui/views/status_icons/status_icon_win.h" #include "chrome/common/chrome_constants.h" -#include "ui/base/win/hwnd_util.h" #include "ui/gfx/screen.h" +#include "ui/gfx/win/hwnd_util.h" #include "win8/util/win8_util.h" static const UINT kStatusIconMessage = WM_APP + 1; @@ -50,8 +50,8 @@ StatusTrayWin::StatusTrayWin() // "TaskbarCreated". window_ = CreateWindow(MAKEINTATOM(atom_), 0, WS_POPUP, 0, 0, 0, 0, 0, 0, instance_, 0); - ui::CheckWindowCreated(window_); - ui::SetWindowUserData(window_, this); + gfx::CheckWindowCreated(window_); + gfx::SetWindowUserData(window_, this); } LRESULT CALLBACK StatusTrayWin::WndProcStatic(HWND hwnd, diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index e203fcb..bb3b8a6 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -13,7 +13,7 @@ #if defined(USE_AURA) #include "ui/views/widget/native_widget_aura.h" #elif defined(OS_WIN) -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #include "ui/views/widget/native_widget_win.h" #endif diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 321fe2c..21638bd 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -52,7 +52,7 @@ #include "ui/views/window/non_client_view.h" #if defined(OS_WIN) -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/views/widget/monitor_win.h" #include "win8/util/win8_util.h" #endif @@ -380,7 +380,7 @@ void NewTabButton::OnMouseReleased(const ui::MouseEvent& event) { views::View::ConvertPointToScreen(this, &point); bool destroyed = false; destroyed_ = &destroyed; - ui::ShowSystemMenuAtPoint(GetWidget()->GetNativeView(), point); + gfx::ShowSystemMenuAtPoint(GetWidget()->GetNativeView(), point); if (destroyed) return; diff --git a/content/app/content_main_runner.cc b/content/app/content_main_runner.cc index 7bfc37b..949514a 100644 --- a/content/app/content_main_runner.cc +++ b/content/app/content_main_runner.cc @@ -49,7 +49,7 @@ #include "sandbox/win/src/sandbox_types.h" #include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_switches.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #include "webkit/common/user_agent/user_agent.h" #if defined(USE_TCMALLOC) diff --git a/content/browser/plugin_service_impl.cc b/content/browser/plugin_service_impl.cc index 3837223..5a79f7d 100644 --- a/content/browser/plugin_service_impl.cc +++ b/content/browser/plugin_service_impl.cc @@ -33,7 +33,7 @@ #if defined(OS_WIN) #include "content/common/plugin_constants_win.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" #endif #if defined(OS_POSIX) @@ -837,7 +837,7 @@ bool PluginServiceImpl::GetPluginInfoFromWindow( } bool PluginServiceImpl::IsPluginWindow(HWND window) { - return ui::GetClassName(window) == base::string16(kNativeWindowClassName); + return gfx::GetClassName(window) == base::string16(kNativeWindowClassName); } #endif diff --git a/content/browser/renderer_host/backing_store_win.cc b/content/browser/renderer_host/backing_store_win.cc index 9992fde..8e761dd 100644 --- a/content/browser/renderer_host/backing_store_win.cc +++ b/content/browser/renderer_host/backing_store_win.cc @@ -9,10 +9,10 @@ #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/public/common/content_switches.h" #include "skia/ext/platform_canvas.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/gdi_util.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/size_conversions.h" +#include "ui/gfx/win/dpi.h" #include "ui/surface/transport_dib.h" namespace content { diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 4981d60..1c958c7 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -129,6 +129,7 @@ #include "net/url_request/url_request_context_getter.h" #include "ppapi/shared_impl/ppapi_switches.h" #include "ui/base/ui_base_switches.h" +#include "ui/gfx/switches.h" #include "ui/gl/gl_switches.h" #include "webkit/browser/fileapi/sandbox_file_system_backend.h" #include "webkit/common/resource_type.h" diff --git a/content/browser/renderer_host/render_widget_host_view_base.cc b/content/browser/renderer_host/render_widget_host_view_base.cc index 11248c3..5718103 100644 --- a/content/browser/renderer_host/render_widget_host_view_base.cc +++ b/content/browser/renderer_host/render_widget_host_view_base.cc @@ -29,9 +29,9 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_data.h" #include "content/public/common/content_switches.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/gdi_util.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" #endif #if defined(TOOLKIT_GTK) @@ -118,7 +118,7 @@ LRESULT CALLBACK PluginWrapperWindowProc(HWND window, unsigned int message, } bool IsPluginWrapperWindow(HWND window) { - return ui::GetClassNameW(window) == + return gfx::GetClassNameW(window) == string16(kWrapperNativeWindowClassName); } @@ -151,7 +151,7 @@ HWND ReparentWindow(HWND window, HWND parent) { MAKEINTATOM(atom), 0, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 0, 0, parent, 0, instance, 0); - ui::CheckWindowCreated(new_parent); + gfx::CheckWindowCreated(new_parent); ::SetParent(window, new_parent); // How many times we try to find a PluginProcessHost whose process matches // the HWND. diff --git a/content/browser/renderer_host/render_widget_host_view_browsertest.cc b/content/browser/renderer_host/render_widget_host_view_browsertest.cc index 4b7c75e..9adc504 100644 --- a/content/browser/renderer_host/render_widget_host_view_browsertest.cc +++ b/content/browser/renderer_host/render_widget_host_view_browsertest.cc @@ -37,7 +37,7 @@ #endif #if defined(OS_WIN) -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #endif namespace content { @@ -835,7 +835,7 @@ class CompositingRenderWidgetHostViewTabCaptureHighDPI cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, base::StringPrintf("%f", scale())); #if defined(OS_WIN) - cmd->AppendSwitchASCII(gfx::switches::kHighDPISupport, "1"); + cmd->AppendSwitchASCII(switches::kHighDPISupport, "1"); gfx::EnableHighDPISupport(); #endif } diff --git a/content/browser/renderer_host/render_widget_host_view_win.cc b/content/browser/renderer_host/render_widget_host_view_win.cc index c8c4dc4..a798404 100644 --- a/content/browser/renderer_host/render_widget_host_view_win.cc +++ b/content/browser/renderer_host/render_widget_host_view_win.cc @@ -67,15 +67,15 @@ #include "ui/base/touch/touch_enabled.h" #include "ui/base/ui_base_switches.h" #include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/base/win/touch_input.h" #include "ui/gfx/canvas.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/screen.h" #include "ui/gfx/text_elider.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" #include "webkit/common/cursors/webcursor.h" #include "win8/util/win8_util.h" @@ -451,7 +451,7 @@ void RenderWidgetHostViewWin::InitAsFullscreen( gfx::Rect pos = gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow( reference_host_view->GetNativeView()).bounds(); is_fullscreen_ = true; - DoPopupOrFullscreenInit(ui::GetWindowToParentTo(true), pos, 0); + DoPopupOrFullscreenInit(gfx::GetWindowToParentTo(true), pos, 0); } RenderWidgetHost* RenderWidgetHostViewWin::GetRenderWidgetHost() const { @@ -575,7 +575,7 @@ void RenderWidgetHostViewWin::CleanupCompositorWindow() { if (!compositor_host_window_) return; - ui::SetWindowUserData(compositor_host_window_, NULL); + gfx::SetWindowUserData(compositor_host_window_, NULL); // Hide the compositor and parent it to the desktop rather than destroying // it immediately. The GPU process has a grace period to stop accessing the @@ -626,7 +626,7 @@ void RenderWidgetHostViewWin::Show() { } void RenderWidgetHostViewWin::Hide() { - if (!is_fullscreen_ && GetParent() == ui::GetWindowToParentTo(true)) { + if (!is_fullscreen_ && GetParent() == gfx::GetWindowToParentTo(true)) { LOG(WARNING) << "Hide() called twice in a row: " << this << ":" << GetParent(); return; @@ -2318,7 +2318,7 @@ LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT message, ::ScreenToClient(m_hWnd, &cursor_pos); HWND child_window = ::RealChildWindowFromPoint(m_hWnd, cursor_pos); if (::IsWindow(child_window) && child_window != m_hWnd) { - if (ui::GetClassName(child_window) == kWrapperNativeWindowClassName) + if (gfx::GetClassName(child_window) == kWrapperNativeWindowClassName) child_window = ::GetWindow(child_window, GW_CHILD); ::SetFocus(child_window); @@ -2464,7 +2464,7 @@ static void PaintCompositorHostWindow(HWND hWnd) { BeginPaint(hWnd, &paint); RenderWidgetHostViewWin* win = static_cast( - ui::GetWindowUserData(hWnd)); + gfx::GetWindowUserData(hWnd)); // Trigger composite to rerender window. if (win) win->AcceleratedPaint(paint.hdc); @@ -2563,9 +2563,9 @@ gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { MAKEINTATOM(atom), 0, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DISABLED, 0, 0, width, height, m_hWnd, 0, instance, 0); - ui::CheckWindowCreated(compositor_host_window_); + gfx::CheckWindowCreated(compositor_host_window_); - ui::SetWindowUserData(compositor_host_window_, this); + gfx::SetWindowUserData(compositor_host_window_, this); gfx::GLSurfaceHandle surface_handle(compositor_host_window_, gfx::NATIVE_TRANSPORT); diff --git a/content/browser/web_contents/web_contents_view_win.h b/content/browser/web_contents/web_contents_view_win.h index 3ca6b48..adfe675 100644 --- a/content/browser/web_contents/web_contents_view_win.h +++ b/content/browser/web_contents/web_contents_view_win.h @@ -13,7 +13,7 @@ #include "content/common/drag_event_source_info.h" #include "content/port/browser/render_view_host_delegate_view.h" #include "content/port/browser/web_contents_view_port.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace ui { class HWNDMessageFilter; @@ -29,7 +29,7 @@ class WebDragDest; class CONTENT_EXPORT WebContentsViewWin : public WebContentsViewPort, public RenderViewHostDelegateView, - public ui::WindowImpl { + public gfx::WindowImpl { public: WebContentsViewWin(WebContentsImpl* web_contents, WebContentsViewDelegate* delegate); diff --git a/content/browser/zygote_host/zygote_host_impl_linux.cc b/content/browser/zygote_host/zygote_host_impl_linux.cc index 3629a84..fea43b5 100644 --- a/content/browser/zygote_host/zygote_host_impl_linux.cc +++ b/content/browser/zygote_host/zygote_host_impl_linux.cc @@ -37,6 +37,7 @@ #include "sandbox/linux/suid/client/setuid_sandbox_client.h" #include "sandbox/linux/suid/common/sandbox.h" #include "ui/base/ui_base_switches.h" +#include "ui/gfx/switches.h" #if defined(USE_TCMALLOC) #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h" diff --git a/content/child/npapi/webplugin_delegate_impl_win.cc b/content/child/npapi/webplugin_delegate_impl_win.cc index e788cb2..f6d0540 100644 --- a/content/child/npapi/webplugin_delegate_impl_win.cc +++ b/content/child/npapi/webplugin_delegate_impl_win.cc @@ -31,8 +31,8 @@ #include "content/public/common/content_constants.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/public/web/WebInputEvent.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" #include "webkit/common/cursors/webcursor.h" using WebKit::WebKeyboardEvent; @@ -1462,7 +1462,7 @@ FARPROC WINAPI WebPluginDelegateImpl::GetProcAddressPatch(HMODULE module, void WebPluginDelegateImpl::HandleCaptureForMessage(HWND window, UINT message) { - if (ui::GetClassName(window) != base::string16(kNativeWindowClassName)) + if (gfx::GetClassName(window) != base::string16(kNativeWindowClassName)) return; switch (message) { diff --git a/content/shell/app/shell_main_delegate.cc b/content/shell/app/shell_main_delegate.cc index c089007..b5fbb8ec 100644 --- a/content/shell/app/shell_main_delegate.cc +++ b/content/shell/app/shell_main_delegate.cc @@ -22,6 +22,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_switches.h" +#include "ui/gfx/switches.h" #include "ui/gl/gl_switches.h" #include "ipc/ipc_message.h" // For IPC_MESSAGE_LOG_ENABLED. diff --git a/content/shell/browser/shell_win.cc b/content/shell/browser/shell_win.cc index d1bb402..2854e5c 100644 --- a/content/shell/browser/shell_win.cc +++ b/content/shell/browser/shell_win.cc @@ -14,7 +14,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" #include "content/shell/app/resource.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace { @@ -52,8 +52,8 @@ void Shell::PlatformExit() { void Shell::PlatformCleanUp() { // When the window is destroyed, tell the Edit field to forget about us, // otherwise we will crash. - ui::SetWindowProc(url_edit_view_, default_edit_wnd_proc_); - ui::SetWindowUserData(url_edit_view_, NULL); + gfx::SetWindowProc(url_edit_view_, default_edit_wnd_proc_); + gfx::SetWindowUserData(url_edit_view_, NULL); } void Shell::PlatformEnableUIControl(UIControl control, bool is_enabled) { @@ -89,7 +89,7 @@ void Shell::PlatformCreateWindow(int width, int height) { WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, instance_handle_, NULL); - ui::SetWindowUserData(window_, this); + gfx::SetWindowUserData(window_, this); HWND hwnd; int x = 0; @@ -124,9 +124,9 @@ void Shell::PlatformCreateWindow(int width, int height) { ES_AUTOVSCROLL | ES_AUTOHSCROLL, x, 0, 0, 0, window_, 0, instance_handle_, 0); - default_edit_wnd_proc_ = ui::SetWindowProc(url_edit_view_, + default_edit_wnd_proc_ = gfx::SetWindowProc(url_edit_view_, Shell::EditWndProc); - ui::SetWindowUserData(url_edit_view_, this); + gfx::SetWindowUserData(url_edit_view_, this); ShowWindow(window_, SW_SHOW); @@ -192,7 +192,7 @@ ATOM Shell::RegisterWindowClass() { LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - Shell* shell = static_cast(ui::GetWindowUserData(hwnd)); + Shell* shell = static_cast(gfx::GetWindowUserData(hwnd)); switch (message) { case WM_COMMAND: { @@ -254,7 +254,7 @@ LRESULT CALLBACK Shell::WndProc(HWND hwnd, UINT message, WPARAM wParam, LRESULT CALLBACK Shell::EditWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - Shell* shell = static_cast(ui::GetWindowUserData(hwnd)); + Shell* shell = static_cast(gfx::GetWindowUserData(hwnd)); switch (message) { case WM_CHAR: diff --git a/remoting/host/plugin/host_plugin.cc b/remoting/host/plugin/host_plugin.cc index b8e2b13..f281bd1 100644 --- a/remoting/host/plugin/host_plugin.cc +++ b/remoting/host/plugin/host_plugin.cc @@ -21,7 +21,7 @@ #include "remoting/host/plugin/host_plugin_utils.h" #include "remoting/host/plugin/host_script_object.h" #if defined(OS_WIN) -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #endif #include "third_party/npapi/bindings/npapi.h" #include "third_party/npapi/bindings/npfunctions.h" diff --git a/tools/memory_watcher/hotkey.h b/tools/memory_watcher/hotkey.h index 0348062..3773e5d 100644 --- a/tools/memory_watcher/hotkey.h +++ b/tools/memory_watcher/hotkey.h @@ -5,12 +5,12 @@ #ifndef TOOLS_MEMORY_WATCHER_HOTKEY_H_ #define TOOLS_MEMORY_WATCHER_HOTKEY_H_ -#include "ui/base/win/window_impl.h" #include "ui/gfx/rect.h" +#include "ui/gfx/win/window_impl.h" // HotKey handler. // Programs wishing to register a hotkey can use this. -class HotKeyHandler : public ui::WindowImpl { +class HotKeyHandler : public gfx::WindowImpl { public: HotKeyHandler(UINT modifiers, UINT vk) : modifiers_(modifiers), diff --git a/ui/aura/root_window_host_win.h b/ui/aura/root_window_host_win.h index e2a60dd..42c8ada 100644 --- a/ui/aura/root_window_host_win.h +++ b/ui/aura/root_window_host_win.h @@ -8,11 +8,11 @@ #include "base/compiler_specific.h" #include "ui/aura/root_window_host.h" #include "ui/base/ui_export.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace aura { -class RootWindowHostWin : public RootWindowHost, public ui::WindowImpl { +class RootWindowHostWin : public RootWindowHost, public gfx::WindowImpl { public: RootWindowHostWin(const gfx::Rect& bounds); virtual ~RootWindowHostWin(); 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 #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(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(GetWindowLongPtr(hwnd, GWLP_WNDPROC)); - SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast(proc)); - return oldwindow_proc; -} - -void* SetWindowUserData(HWND hwnd, void* user_data) { - return - reinterpret_cast(SetWindowLongPtr(hwnd, GWLP_USERDATA, - reinterpret_cast(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(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(::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 - -#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 - -#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::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 -#include - -#include "base/basictypes.h" -#include "base/callback_forward.h" -#include "base/observer_list.h" -#include "ui/base/win/window_impl.h" - -template 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(); - - // List of registered observers. - ObserverList 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 - -#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; - - typedef std::list 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 >::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, - 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(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(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(l_param); - WindowImpl* window = reinterpret_cast(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( - 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 -#include -#include -#include - -#include - -#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_ diff --git a/ui/compositor/test/test_compositor_host_win.cc b/ui/compositor/test/test_compositor_host_win.cc index 452acee..60b7b0c 100644 --- a/ui/compositor/test/test_compositor_host_win.cc +++ b/ui/compositor/test/test_compositor_host_win.cc @@ -6,13 +6,13 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "ui/base/win/window_impl.h" #include "ui/compositor/compositor.h" +#include "ui/gfx/win/window_impl.h" namespace ui { class TestCompositorHostWin : public TestCompositorHost, - public WindowImpl, + public gfx::WindowImpl, public CompositorDelegate { public: TestCompositorHostWin(const gfx::Rect& bounds) { diff --git a/ui/gfx/canvas_paint_win.h b/ui/gfx/canvas_paint_win.h index ed31a6e..c5d3aee 100644 --- a/ui/gfx/canvas_paint_win.h +++ b/ui/gfx/canvas_paint_win.h @@ -7,8 +7,8 @@ #include "skia/ext/platform_canvas.h" #include "ui/gfx/canvas.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/size.h" +#include "ui/gfx/win/dpi.h" namespace gfx { diff --git a/ui/gfx/display.cc b/ui/gfx/display.cc index 02d97a9..d3f0745 100644 --- a/ui/gfx/display.cc +++ b/ui/gfx/display.cc @@ -8,11 +8,11 @@ #include "base/logging.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" -#include "ui/base/ui_base_switches.h" #include "ui/gfx/insets.h" #include "ui/gfx/point_conversions.h" #include "ui/gfx/point_f.h" #include "ui/gfx/size_conversions.h" +#include "ui/gfx/switches.h" namespace gfx { namespace { diff --git a/ui/gfx/dpi_win.cc b/ui/gfx/dpi_win.cc deleted file mode 100644 index 51972d2..0000000 --- a/ui/gfx/dpi_win.cc +++ /dev/null @@ -1,175 +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/gfx/dpi_win.h" - -#include -#include "base/command_line.h" -#include "base/win/scoped_hdc.h" -#include "base/win/windows_version.h" -#include "ui/base/layout.h" -#include "base/win/registry.h" -#include "ui/gfx/display.h" -#include "ui/gfx/switches.h" -#include "ui/gfx/point_conversions.h" -#include "ui/gfx/rect_conversions.h" -#include "ui/gfx/size_conversions.h" - -namespace { - -int kDefaultDPIX = 96; -int kDefaultDPIY = 96; - -// Tests to see if the command line flag "--high-dpi-support" is set. -bool IsHighDPIEnabled() { - // Default is disabled. - if (CommandLine::ForCurrentProcess()->HasSwitch( - gfx::switches::kHighDPISupport)) { - return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - gfx::switches::kHighDPISupport).compare("1") == 0; - } - return false; -} - -// Gets the device scale factor. If support is enabled, this will return the -// best available scale based on the screen's pixel density. This can be -// affected (overridden) by --force-device-scale-factor=x -float GetDeviceScaleFactorImpl() { - if (IsHighDPIEnabled()) { - float scale = gfx::Display::HasForceDeviceScaleFactor() ? - gfx::Display::GetForcedDeviceScaleFactor() : gfx::GetDPIScale(); - // Quantize to nearest supported scale factor. - scale = ui::GetScaleFactorScale(ui::GetScaleFactorFromScale(scale)); - return scale; - } - return 1.0f; -} - -BOOL IsProcessDPIAwareWrapper() { - typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID); - IsProcessDPIAwarePtr is_process_dpi_aware_func = - reinterpret_cast( - GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware")); - if (is_process_dpi_aware_func) - return is_process_dpi_aware_func(); - return FALSE; -} - -} // namespace - -namespace gfx { - -Size GetDPI() { - static int dpi_x = 0; - static int dpi_y = 0; - static bool should_initialize = true; - - if (should_initialize) { - should_initialize = false; - base::win::ScopedGetDC screen_dc(NULL); - // This value is safe to cache for the life time of the app since the - // user must logout to change the DPI setting. This value also applies - // to all screens. - dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX); - dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY); - } - return Size(dpi_x, dpi_y); -} - -float GetDPIScale() { - if (IsHighDPIEnabled()) { - return static_cast(GetDPI().width()) / - static_cast(kDefaultDPIX); - } - return 1.0; -} - -bool IsInHighDPIMode() { - return GetDPIScale() > 1.0; -} - -void EnableHighDPISupport() { - if (IsHighDPIEnabled()) { - typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); - SetProcessDPIAwarePtr set_process_dpi_aware_func = - reinterpret_cast( - GetProcAddress(GetModuleHandleA("user32.dll"), - "SetProcessDPIAware")); - if (set_process_dpi_aware_func) - set_process_dpi_aware_func(); - } -} - -namespace win { - -float GetDeviceScaleFactor() { - static const float device_scale_factor = GetDeviceScaleFactorImpl(); - return device_scale_factor; -} - -Point ScreenToDIPPoint(const Point& pixel_point) { - return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); -} - -Point DIPToScreenPoint(const Point& dip_point) { - return ToFlooredPoint(ScalePoint(dip_point, GetDeviceScaleFactor())); -} - -Rect ScreenToDIPRect(const Rect& pixel_bounds) { - // TODO(kevers): Switch to non-deprecated method for float to int conversions. - return ToFlooredRectDeprecated( - ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor())); -} - -Rect DIPToScreenRect(const Rect& dip_bounds) { - // TODO(kevers): Switch to non-deprecated method for float to int conversions. - return ToFlooredRectDeprecated( - ScaleRect(dip_bounds, GetDeviceScaleFactor())); -} - -Size ScreenToDIPSize(const Size& size_in_pixels) { - return ToFlooredSize( - ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); -} - -Size DIPToScreenSize(const Size& dip_size) { - return ToFlooredSize(ScaleSize(dip_size, GetDeviceScaleFactor())); -} - -int GetSystemMetricsInDIP(int metric) { - return static_cast(GetSystemMetrics(metric) / - GetDeviceScaleFactor() + 0.5); -} - -double GetUndocumentedDPIScale() { - // TODO(girard): Remove this code when chrome is DPIAware. - static double scale = -1.0; - if (scale == -1.0) { - scale = 1.0; - if (!IsProcessDPIAwareWrapper()) { - base::win::RegKey key(HKEY_CURRENT_USER, - L"Control Panel\\Desktop\\WindowMetrics", - KEY_QUERY_VALUE); - if (key.Valid()) { - DWORD value = 0; - if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) { - scale = static_cast(value) / kDefaultDPIX; - } - } - } - } - return scale; -} - - -double GetUndocumentedDPITouchScale() { - static double scale = - (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? - GetUndocumentedDPIScale() : 1.0; - return scale; -} - - -} // namespace win -} // namespace gfx diff --git a/ui/gfx/dpi_win.h b/ui/gfx/dpi_win.h deleted file mode 100644 index a056f53..0000000 --- a/ui/gfx/dpi_win.h +++ /dev/null @@ -1,63 +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_GFX_DPI_WIN_H_ -#define UI_GFX_DPI_WIN_H_ - -#include "ui/gfx/gfx_export.h" -#include "ui/gfx/point.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -namespace gfx { - -UI_EXPORT Size GetDPI(); - -// Gets the scale factor of the display. For example, if the display DPI is -// 96 then the scale factor is 1.0. -UI_EXPORT float GetDPIScale(); - -UI_EXPORT bool IsInHighDPIMode(); - -UI_EXPORT void EnableHighDPISupport(); - -// TODO(kevers|girard): Move above methods into win namespace. - -namespace win { - -UI_EXPORT float GetDeviceScaleFactor(); - -UI_EXPORT Point ScreenToDIPPoint(const Point& pixel_point); - -UI_EXPORT Point DIPToScreenPoint(const Point& dip_point); - -UI_EXPORT Rect ScreenToDIPRect(const Rect& pixel_bounds); - -UI_EXPORT Rect DIPToScreenRect(const Rect& dip_bounds); - -UI_EXPORT Size ScreenToDIPSize(const Size& size_in_pixels); - -UI_EXPORT Size DIPToScreenSize(const Size& dip_size); - -// Win32's GetSystemMetrics uses pixel measures. This function calls -// GetSystemMetrics for the given |metric|, then converts the result to DIP. -UI_EXPORT int GetSystemMetricsInDIP(int metric); - -// Sometimes the OS secretly scales apps that are not DPIAware. This is not -// visible through standard OS calls like GetWindowPos(), or through -// GetDPIScale(). -// Returns the scale factor of the display, where 96 DPI is 1.0. -// (Avoid this function... use GetDPIScale() instead.) -// TODO(girard): Remove this once DPIAware is enabled - http://crbug.com/149881 -UI_EXPORT double GetUndocumentedDPIScale(); - -// Win7 and Win8 send touch events scaled according to the current DPI -// scaling. Win8.1 corrects this, and sends touch events in DPI units. -// This function returns the appropriate scaling factor for touch events. -UI_EXPORT double GetUndocumentedDPITouchScale(); - -} // namespace win -} // namespace gfx - -#endif // UI_GFX_DPI_WIN_H_ diff --git a/ui/gfx/font_smoothing_win.cc b/ui/gfx/font_smoothing_win.cc index a4be729..b181fb5 100644 --- a/ui/gfx/font_smoothing_win.cc +++ b/ui/gfx/font_smoothing_win.cc @@ -5,13 +5,13 @@ #include "ui/gfx/font_smoothing_win.h" #include "base/memory/singleton.h" -#include "ui/base/win/singleton_hwnd.h" +#include "ui/gfx/win/singleton_hwnd.h" namespace { // Helper class to cache font smoothing settings and listen for notifications // to re-query them from the system. -class CachedFontSmoothingSettings : public ui::SingletonHwnd::Observer { +class CachedFontSmoothingSettings : public gfx::SingletonHwnd::Observer { public: static CachedFontSmoothingSettings* GetInstance(); @@ -66,7 +66,7 @@ void CachedFontSmoothingSettings::GetFontSmoothingSettings( need_to_query_settings_ = false; } if (!observer_added_) { - ui::SingletonHwnd::GetInstance()->AddObserver(this); + gfx::SingletonHwnd::GetInstance()->AddObserver(this); observer_added_ = true; } *smoothing_enabled = smoothing_enabled_; diff --git a/ui/gfx/platform_font_win.cc b/ui/gfx/platform_font_win.cc index 4a792f6..2d4c006 100644 --- a/ui/gfx/platform_font_win.cc +++ b/ui/gfx/platform_font_win.cc @@ -17,9 +17,9 @@ #include "base/win/scoped_hdc.h" #include "base/win/scoped_select_object.h" #include "base/win/win_util.h" -#include "ui/base/win/scoped_set_map_mode.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" +#include "ui/gfx/win/scoped_set_map_mode.h" namespace { @@ -229,7 +229,7 @@ PlatformFontWin::HFontRef* PlatformFontWin::CreateHFontRef(HFONT font) { { base::win::ScopedGetDC screen_dc(NULL); base::win::ScopedSelectObject scoped_font(screen_dc, font); - ui::ScopedSetMapMode mode(screen_dc, MM_TEXT); + gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT); GetTextMetrics(screen_dc, &font_metrics); } @@ -284,7 +284,7 @@ int PlatformFontWin::HFontRef::GetDluBaseX() { base::win::ScopedGetDC screen_dc(NULL); base::win::ScopedSelectObject font(screen_dc, hfont_); - ui::ScopedSetMapMode mode(screen_dc, MM_TEXT); + gfx::ScopedSetMapMode mode(screen_dc, MM_TEXT); // Yes, this is how Microsoft recommends calculating the dialog unit // conversions. See: http://support.microsoft.com/kb/125681 diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 06640e0..c4335b4 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -13,12 +13,12 @@ #include "third_party/icu/source/common/unicode/utf16.h" #include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkGradientShader.h" -#include "ui/base/text/utf16_indexing.h" #include "ui/gfx/canvas.h" #include "ui/gfx/insets.h" #include "ui/gfx/skia_util.h" #include "ui/gfx/text_constants.h" #include "ui/gfx/text_elider.h" +#include "ui/gfx/utf16_indexing.h" namespace gfx { @@ -952,7 +952,7 @@ void RenderText::UpdateLayoutText() { if (obscured_) { size_t obscured_text_length = - static_cast(ui::UTF16IndexToOffset(text_, 0, text_.length())); + static_cast(gfx::UTF16IndexToOffset(text_, 0, text_.length())); layout_text_.assign(obscured_text_length, kPasswordReplacementChar); if (obscured_reveal_index_ >= 0 && @@ -966,7 +966,7 @@ void RenderText::UpdateLayoutText() { // Gets the index in |layout_text_| to be replaced. const size_t cp_start = - static_cast(ui::UTF16IndexToOffset(text_, 0, start)); + static_cast(gfx::UTF16IndexToOffset(text_, 0, start)); if (layout_text_.length() > cp_start) layout_text_.replace(cp_start, 1, text_.substr(start, end - start)); } diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc index c6cf4f2..9ad2a3d 100644 --- a/ui/gfx/render_text_linux.cc +++ b/ui/gfx/render_text_linux.cc @@ -12,11 +12,11 @@ #include "base/i18n/break_iterator.h" #include "base/logging.h" #include "third_party/skia/include/core/SkTypeface.h" -#include "ui/base/text/utf16_indexing.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/font_render_params_linux.h" #include "ui/gfx/pango_util.h" +#include "ui/gfx/utf16_indexing.h" namespace gfx { @@ -252,7 +252,7 @@ std::vector RenderTextLinux::GetSubstringBounds(const gfx::Range& range) { size_t RenderTextLinux::TextIndexToLayoutIndex(size_t index) const { DCHECK(layout_); - ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, index); + ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, index); // Clamp layout indices to the length of the text actually used for layout. offset = std::min(offset, g_utf8_strlen(layout_text_, -1)); const char* layout_pointer = g_utf8_offset_to_pointer(layout_text_, offset); @@ -263,7 +263,7 @@ size_t RenderTextLinux::LayoutIndexToTextIndex(size_t index) const { DCHECK(layout_); const char* layout_pointer = layout_text_ + index; const long offset = g_utf8_pointer_to_offset(layout_text_, layout_pointer); - return ui::UTF16OffsetToIndex(text(), 0, offset); + return gfx::UTF16OffsetToIndex(text(), 0, offset); } bool RenderTextLinux::IsCursorablePosition(size_t position) { @@ -271,11 +271,11 @@ bool RenderTextLinux::IsCursorablePosition(size_t position) { return true; if (position >= text().length()) return position == text().length(); - if (!ui::IsValidCodePointIndex(text(), position)) + if (!gfx::IsValidCodePointIndex(text(), position)) return false; EnsureLayout(); - ptrdiff_t offset = ui::UTF16IndexToOffset(text(), 0, position); + ptrdiff_t offset = gfx::UTF16IndexToOffset(text(), 0, position); // Check that the index corresponds with a valid text code point, that it is // marked as a legitimate cursor position by Pango, and that it is not // truncated from layout text (its glyph is shown on screen). diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index 2415060..2eff381 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -14,11 +14,11 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" #include "third_party/icu/source/common/unicode/uchar.h" -#include "ui/base/text/utf16_indexing.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font_fallback_win.h" #include "ui/gfx/font_smoothing_win.h" #include "ui/gfx/platform_font_win.h" +#include "ui/gfx/utf16_indexing.h" namespace gfx { @@ -413,7 +413,7 @@ std::vector RenderTextWin::GetSubstringBounds(const gfx::Range& range) { size_t RenderTextWin::TextIndexToLayoutIndex(size_t index) const { DCHECK_LE(index, text().length()); - ptrdiff_t i = obscured() ? ui::UTF16IndexToOffset(text(), 0, index) : index; + ptrdiff_t i = obscured() ? gfx::UTF16IndexToOffset(text(), 0, index) : index; CHECK_GE(i, 0); // Clamp layout indices to the length of the text actually used for layout. return std::min(GetLayoutText().length(), i); @@ -424,7 +424,7 @@ size_t RenderTextWin::LayoutIndexToTextIndex(size_t index) const { return index; DCHECK_LE(index, GetLayoutText().length()); - const size_t text_index = ui::UTF16OffsetToIndex(text(), 0, index); + const size_t text_index = gfx::UTF16OffsetToIndex(text(), 0, index); DCHECK_LE(text_index, text().length()); return text_index; } @@ -439,7 +439,7 @@ bool RenderTextWin::IsCursorablePosition(size_t position) { // and that its glyph has distinct bounds (not mid-multi-character-grapheme). // An example of a multi-character-grapheme that is not a surrogate-pair is: // \x0915\x093f - (ki) - one of many Devanagari biconsonantal conjuncts. - return ui::IsValidCodePointIndex(text(), position) && + return gfx::IsValidCodePointIndex(text(), position) && position < LayoutIndexToTextIndex(GetLayoutText().length()) && GetGlyphBounds(position) != GetGlyphBounds(position - 1); } @@ -599,7 +599,7 @@ void RenderTextWin::ItemizeLogicalText() { // Clamp run lengths to avoid exceeding the maximum supported glyph count. if ((run_break - run->range.start()) > max_run_length) { run_break = run->range.start() + max_run_length; - if (!ui::IsValidCodePointIndex(layout_text, run_break)) + if (!gfx::IsValidCodePointIndex(layout_text, run_break)) --run_break; } @@ -619,7 +619,7 @@ void RenderTextWin::ItemizeLogicalText() { } } - DCHECK(ui::IsValidCodePointIndex(layout_text, run_break)); + DCHECK(gfx::IsValidCodePointIndex(layout_text, run_break)); style.UpdatePosition(LayoutIndexToTextIndex(run_break)); if (script_item_break == run_break) diff --git a/ui/gfx/screen_win.cc b/ui/gfx/screen_win.cc index 7ae5306..7903cc5 100644 --- a/ui/gfx/screen_win.cc +++ b/ui/gfx/screen_win.cc @@ -11,7 +11,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/win/win_util.h" #include "ui/gfx/display.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" namespace { diff --git a/ui/gfx/switches.cc b/ui/gfx/switches.cc index a278f46..2f2eb9a 100644 --- a/ui/gfx/switches.cc +++ b/ui/gfx/switches.cc @@ -4,7 +4,6 @@ #include "ui/gfx/switches.h" -namespace gfx { namespace switches { // Let text glyphs have X-positions that aren't snapped to the pixel grid in @@ -17,8 +16,10 @@ const char kEnableBrowserTextSubpixelPositioning[] = const char kEnableWebkitTextSubpixelPositioning[] = "enable-webkit-text-subpixel-positioning"; +// Overrides the device scale factor for the browser UI and the contents. +const char kForceDeviceScaleFactor[] = "force-device-scale-factor"; + // Enables/Disables High DPI support (windows) const char kHighDPISupport[] = "high-dpi-support"; } // namespace switches -} // namespace gfx diff --git a/ui/gfx/switches.h b/ui/gfx/switches.h index f8069d0..e3cd9e7 100644 --- a/ui/gfx/switches.h +++ b/ui/gfx/switches.h @@ -7,14 +7,13 @@ #include "ui/gfx/gfx_export.h" -namespace gfx { namespace switches { UI_EXPORT extern const char kEnableBrowserTextSubpixelPositioning[]; UI_EXPORT extern const char kEnableWebkitTextSubpixelPositioning[]; +UI_EXPORT extern const char kForceDeviceScaleFactor[]; UI_EXPORT extern const char kHighDPISupport[]; } // namespace switches -} // namespace gfx #endif // UI_GFX_SWITCHES_H_ diff --git a/ui/gfx/sys_color_change_listener.cc b/ui/gfx/sys_color_change_listener.cc index 7a9fc84..d5646b3 100644 --- a/ui/gfx/sys_color_change_listener.cc +++ b/ui/gfx/sys_color_change_listener.cc @@ -13,7 +13,7 @@ #include "base/memory/singleton.h" #include "base/observer_list.h" #if defined(OS_WIN) -#include "ui/base/win/singleton_hwnd.h" +#include "ui/gfx/win/singleton_hwnd.h" #endif namespace gfx { @@ -48,7 +48,7 @@ bool IsInvertedColorScheme() { } #if defined(OS_WIN) -class SysColorChangeObserver : public ui::SingletonHwnd::Observer { +class SysColorChangeObserver : public gfx::SingletonHwnd::Observer { public: static SysColorChangeObserver* GetInstance(); @@ -75,11 +75,11 @@ SysColorChangeObserver* SysColorChangeObserver::GetInstance() { } SysColorChangeObserver::SysColorChangeObserver() { - ui::SingletonHwnd::GetInstance()->AddObserver(this); + gfx::SingletonHwnd::GetInstance()->AddObserver(this); } SysColorChangeObserver::~SysColorChangeObserver() { - ui::SingletonHwnd::GetInstance()->RemoveObserver(this); + gfx::SingletonHwnd::GetInstance()->RemoveObserver(this); } void SysColorChangeObserver::AddListener(SysColorChangeListener* listener) { diff --git a/ui/gfx/utf16_indexing.cc b/ui/gfx/utf16_indexing.cc new file mode 100644 index 0000000..6af10c1 --- /dev/null +++ b/ui/gfx/utf16_indexing.cc @@ -0,0 +1,55 @@ +// 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/gfx/utf16_indexing.h" + +#include "base/logging.h" +#include "base/third_party/icu/icu_utf.h" + +namespace gfx { + +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 gfx diff --git a/ui/gfx/utf16_indexing.h b/ui/gfx/utf16_indexing.h new file mode 100644 index 0000000..7f56384 --- /dev/null +++ b/ui/gfx/utf16_indexing.h @@ -0,0 +1,49 @@ +// 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_GFX_UTF16_INDEXING_H_ +#define UI_GFX_UTF16_INDEXING_H_ + +#include "base/strings/string16.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { + +// 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 gfx + +#endif // UI_GFX_UTF16_INDEXING_H_ diff --git a/ui/gfx/utf16_indexing_unittest.cc b/ui/gfx/utf16_indexing_unittest.cc new file mode 100644 index 0000000..da2f8f5b --- /dev/null +++ b/ui/gfx/utf16_indexing_unittest.cc @@ -0,0 +1,32 @@ +// 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/gfx/utf16_indexing.h" + +namespace gfx { + +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(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 gfx diff --git a/ui/gfx/win/dpi.cc b/ui/gfx/win/dpi.cc new file mode 100644 index 0000000..98d23bd --- /dev/null +++ b/ui/gfx/win/dpi.cc @@ -0,0 +1,175 @@ +// 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/gfx/win/dpi.h" + +#include +#include "base/command_line.h" +#include "base/win/scoped_hdc.h" +#include "base/win/windows_version.h" +#include "ui/base/layout.h" +#include "base/win/registry.h" +#include "ui/gfx/display.h" +#include "ui/gfx/switches.h" +#include "ui/gfx/point_conversions.h" +#include "ui/gfx/rect_conversions.h" +#include "ui/gfx/size_conversions.h" + +namespace { + +int kDefaultDPIX = 96; +int kDefaultDPIY = 96; + +// Tests to see if the command line flag "--high-dpi-support" is set. +bool IsHighDPIEnabled() { + // Default is disabled. + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kHighDPISupport)) { + return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( + switches::kHighDPISupport).compare("1") == 0; + } + return false; +} + +// Gets the device scale factor. If support is enabled, this will return the +// best available scale based on the screen's pixel density. This can be +// affected (overridden) by --force-device-scale-factor=x +float GetDeviceScaleFactorImpl() { + if (IsHighDPIEnabled()) { + float scale = gfx::Display::HasForceDeviceScaleFactor() ? + gfx::Display::GetForcedDeviceScaleFactor() : gfx::GetDPIScale(); + // Quantize to nearest supported scale factor. + scale = ui::GetScaleFactorScale(ui::GetScaleFactorFromScale(scale)); + return scale; + } + return 1.0f; +} + +BOOL IsProcessDPIAwareWrapper() { + typedef BOOL(WINAPI *IsProcessDPIAwarePtr)(VOID); + IsProcessDPIAwarePtr is_process_dpi_aware_func = + reinterpret_cast( + GetProcAddress(GetModuleHandleA("user32.dll"), "IsProcessDPIAware")); + if (is_process_dpi_aware_func) + return is_process_dpi_aware_func(); + return FALSE; +} + +} // namespace + +namespace gfx { + +Size GetDPI() { + static int dpi_x = 0; + static int dpi_y = 0; + static bool should_initialize = true; + + if (should_initialize) { + should_initialize = false; + base::win::ScopedGetDC screen_dc(NULL); + // This value is safe to cache for the life time of the app since the + // user must logout to change the DPI setting. This value also applies + // to all screens. + dpi_x = GetDeviceCaps(screen_dc, LOGPIXELSX); + dpi_y = GetDeviceCaps(screen_dc, LOGPIXELSY); + } + return Size(dpi_x, dpi_y); +} + +float GetDPIScale() { + if (IsHighDPIEnabled()) { + return static_cast(GetDPI().width()) / + static_cast(kDefaultDPIX); + } + return 1.0; +} + +bool IsInHighDPIMode() { + return GetDPIScale() > 1.0; +} + +void EnableHighDPISupport() { + if (IsHighDPIEnabled()) { + typedef BOOL(WINAPI *SetProcessDPIAwarePtr)(VOID); + SetProcessDPIAwarePtr set_process_dpi_aware_func = + reinterpret_cast( + GetProcAddress(GetModuleHandleA("user32.dll"), + "SetProcessDPIAware")); + if (set_process_dpi_aware_func) + set_process_dpi_aware_func(); + } +} + +namespace win { + +float GetDeviceScaleFactor() { + static const float device_scale_factor = GetDeviceScaleFactorImpl(); + return device_scale_factor; +} + +Point ScreenToDIPPoint(const Point& pixel_point) { + return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); +} + +Point DIPToScreenPoint(const Point& dip_point) { + return ToFlooredPoint(ScalePoint(dip_point, GetDeviceScaleFactor())); +} + +Rect ScreenToDIPRect(const Rect& pixel_bounds) { + // TODO(kevers): Switch to non-deprecated method for float to int conversions. + return ToFlooredRectDeprecated( + ScaleRect(pixel_bounds, 1.0f / GetDeviceScaleFactor())); +} + +Rect DIPToScreenRect(const Rect& dip_bounds) { + // TODO(kevers): Switch to non-deprecated method for float to int conversions. + return ToFlooredRectDeprecated( + ScaleRect(dip_bounds, GetDeviceScaleFactor())); +} + +Size ScreenToDIPSize(const Size& size_in_pixels) { + return ToFlooredSize( + ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); +} + +Size DIPToScreenSize(const Size& dip_size) { + return ToFlooredSize(ScaleSize(dip_size, GetDeviceScaleFactor())); +} + +int GetSystemMetricsInDIP(int metric) { + return static_cast(GetSystemMetrics(metric) / + GetDeviceScaleFactor() + 0.5); +} + +double GetUndocumentedDPIScale() { + // TODO(girard): Remove this code when chrome is DPIAware. + static double scale = -1.0; + if (scale == -1.0) { + scale = 1.0; + if (!IsProcessDPIAwareWrapper()) { + base::win::RegKey key(HKEY_CURRENT_USER, + L"Control Panel\\Desktop\\WindowMetrics", + KEY_QUERY_VALUE); + if (key.Valid()) { + DWORD value = 0; + if (key.ReadValueDW(L"AppliedDPI", &value) == ERROR_SUCCESS) { + scale = static_cast(value) / kDefaultDPIX; + } + } + } + } + return scale; +} + + +double GetUndocumentedDPITouchScale() { + static double scale = + (base::win::GetVersion() < base::win::VERSION_WIN8_1) ? + GetUndocumentedDPIScale() : 1.0; + return scale; +} + + +} // namespace win +} // namespace gfx diff --git a/ui/gfx/win/dpi.h b/ui/gfx/win/dpi.h new file mode 100644 index 0000000..a056f53 --- /dev/null +++ b/ui/gfx/win/dpi.h @@ -0,0 +1,63 @@ +// 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_GFX_DPI_WIN_H_ +#define UI_GFX_DPI_WIN_H_ + +#include "ui/gfx/gfx_export.h" +#include "ui/gfx/point.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/size.h" + +namespace gfx { + +UI_EXPORT Size GetDPI(); + +// Gets the scale factor of the display. For example, if the display DPI is +// 96 then the scale factor is 1.0. +UI_EXPORT float GetDPIScale(); + +UI_EXPORT bool IsInHighDPIMode(); + +UI_EXPORT void EnableHighDPISupport(); + +// TODO(kevers|girard): Move above methods into win namespace. + +namespace win { + +UI_EXPORT float GetDeviceScaleFactor(); + +UI_EXPORT Point ScreenToDIPPoint(const Point& pixel_point); + +UI_EXPORT Point DIPToScreenPoint(const Point& dip_point); + +UI_EXPORT Rect ScreenToDIPRect(const Rect& pixel_bounds); + +UI_EXPORT Rect DIPToScreenRect(const Rect& dip_bounds); + +UI_EXPORT Size ScreenToDIPSize(const Size& size_in_pixels); + +UI_EXPORT Size DIPToScreenSize(const Size& dip_size); + +// Win32's GetSystemMetrics uses pixel measures. This function calls +// GetSystemMetrics for the given |metric|, then converts the result to DIP. +UI_EXPORT int GetSystemMetricsInDIP(int metric); + +// Sometimes the OS secretly scales apps that are not DPIAware. This is not +// visible through standard OS calls like GetWindowPos(), or through +// GetDPIScale(). +// Returns the scale factor of the display, where 96 DPI is 1.0. +// (Avoid this function... use GetDPIScale() instead.) +// TODO(girard): Remove this once DPIAware is enabled - http://crbug.com/149881 +UI_EXPORT double GetUndocumentedDPIScale(); + +// Win7 and Win8 send touch events scaled according to the current DPI +// scaling. Win8.1 corrects this, and sends touch events in DPI units. +// This function returns the appropriate scaling factor for touch events. +UI_EXPORT double GetUndocumentedDPITouchScale(); + +} // namespace win +} // namespace gfx + +#endif // UI_GFX_DPI_WIN_H_ diff --git a/ui/gfx/win/hwnd_util.cc b/ui/gfx/win/hwnd_util.cc new file mode 100644 index 0000000..91f0ddd --- /dev/null +++ b/ui/gfx/win/hwnd_util.cc @@ -0,0 +1,214 @@ +// 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/gfx/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 gfx { + +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); + Rect window_rect(bounds); + Rect monitor_rect(mi.rcWork); + 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(GetWindowLongPtr(hwnd, GWLP_WNDPROC)); + SetWindowLongPtr(hwnd, GWLP_WNDPROC, reinterpret_cast(proc)); + return oldwindow_proc; +} + +void* SetWindowUserData(HWND hwnd, void* user_data) { + return + reinterpret_cast(SetWindowLongPtr(hwnd, GWLP_USERDATA, + reinterpret_cast(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(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 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); + Point point = Point(rect.left, rect.top); + static const int kSystemMenuOffset = 10; + point.Offset(kSystemMenuOffset, kSystemMenuOffset); + ShowSystemMenuAtPoint(window, point); +} + +void ShowSystemMenuAtPoint(HWND window, const 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(::GetProcAddress(metro, "GetRootWindow")); + return root_window(); +} + +} // namespace gfx diff --git a/ui/gfx/win/hwnd_util.h b/ui/gfx/win/hwnd_util.h new file mode 100644 index 0000000..70e5f8f --- /dev/null +++ b/ui/gfx/win/hwnd_util.h @@ -0,0 +1,54 @@ +// 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_GFX_WIN_HWND_UTIL_H_ +#define UI_GFX_WIN_HWND_UTIL_H_ + +#include + +#include "base/strings/string16.h" +#include "ui/gfx/gfx_export.h" + +namespace gfx { +class Point; +class Size; + +// 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 gfx + +#endif // UI_GFX_WIN_HWND_UTIL_H_ diff --git a/ui/gfx/win/scoped_set_map_mode.h b/ui/gfx/win/scoped_set_map_mode.h new file mode 100644 index 0000000..910837d --- /dev/null +++ b/ui/gfx/win/scoped_set_map_mode.h @@ -0,0 +1,40 @@ +// 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_GFX_WIN_SCOPED_SET_MAP_MODE_H_ +#define UI_GFX_WIN_SCOPED_SET_MAP_MODE_H_ + +#include + +#include "base/basictypes.h" +#include "base/logging.h" + +namespace gfx { + +// 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 gfx + +#endif // UI_GFX_WIN_SCOPED_SET_MAP_MODE_H_ diff --git a/ui/gfx/win/singleton_hwnd.cc b/ui/gfx/win/singleton_hwnd.cc new file mode 100644 index 0000000..37993e8 --- /dev/null +++ b/ui/gfx/win/singleton_hwnd.cc @@ -0,0 +1,55 @@ +// 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/gfx/win/singleton_hwnd.h" + +#include "base/memory/singleton.h" +#include "base/message_loop/message_loop.h" + +namespace gfx { + +// static +SingletonHwnd* SingletonHwnd::GetInstance() { + return Singleton::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, 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 gfx diff --git a/ui/gfx/win/singleton_hwnd.h b/ui/gfx/win/singleton_hwnd.h new file mode 100644 index 0000000..96af6e7 --- /dev/null +++ b/ui/gfx/win/singleton_hwnd.h @@ -0,0 +1,61 @@ +// 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_GFX_WIN_SINGLETON_HWND_H_ +#define UI_GFX_WIN_SINGLETON_HWND_H_ + +#include +#include + +#include "base/basictypes.h" +#include "base/callback_forward.h" +#include "base/observer_list.h" +#include "ui/gfx/win/window_impl.h" + +template struct DefaultSingletonTraits; + +namespace gfx { + +// 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(); + + // List of registered observers. + ObserverList observer_list_; + + DISALLOW_COPY_AND_ASSIGN(SingletonHwnd); +}; + +} // namespace gfx + +#endif // UI_GFX_WIN_SINGLETON_HWND_H_ diff --git a/ui/gfx/win/window_impl.cc b/ui/gfx/win/window_impl.cc new file mode 100644 index 0000000..e2e6af0 --- /dev/null +++ b/ui/gfx/win/window_impl.cc @@ -0,0 +1,272 @@ +// 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/gfx/win/window_impl.h" + +#include + +#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/gfx/win/hwnd_util.h" + +namespace gfx { + +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; + + typedef std::list 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 >::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, + 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 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(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(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, 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_)) + gfx::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(l_param); + WindowImpl* window = reinterpret_cast(cs->lpCreateParams); + DCHECK(window); + gfx::SetWindowUserData(hwnd, window); + window->hwnd_ = hwnd; + window->got_create_ = true; + if (hwnd) + window->got_valid_hwnd_ = true; + return TRUE; + } + + WindowImpl* window = reinterpret_cast(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 gfx diff --git a/ui/gfx/win/window_impl.h b/ui/gfx/win/window_impl.h new file mode 100644 index 0000000..2b0018e --- /dev/null +++ b/ui/gfx/win/window_impl.h @@ -0,0 +1,123 @@ +// 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_GFX_WIN_WINDOW_IMPL_H_ +#define UI_GFX_WIN_WINDOW_IMPL_H_ + +#include +#include +#include +#include + +#include + +#include "base/logging.h" +#include "ui/gfx/gfx_export.h" +#include "ui/gfx/native_widget_types.h" +#include "ui/gfx/rect.h" + +namespace gfx { + +// 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 gfx + +#endif // UI_GFX_WIN_WINDOW_IMPL_H_ diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc index 79081b7..74b4f14 100644 --- a/ui/native_theme/native_theme_win.cc +++ b/ui/native_theme/native_theme_win.cc @@ -24,11 +24,11 @@ #include "third_party/skia/include/core/SkColorPriv.h" #include "third_party/skia/include/core/SkShader.h" #include "ui/gfx/color_utils.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/gdi_util.h" #include "ui/gfx/rect.h" #include "ui/gfx/rect_conversions.h" #include "ui/gfx/sys_color_change_listener.h" +#include "ui/gfx/win/dpi.h" #include "ui/native_theme/common_theme.h" // This was removed from Winvers.h but is still used. diff --git a/ui/surface/accelerated_surface_win.cc b/ui/surface/accelerated_surface_win.cc index 502678b..3faf01d 100644 --- a/ui/surface/accelerated_surface_win.cc +++ b/ui/surface/accelerated_surface_win.cc @@ -26,10 +26,10 @@ #include "media/base/video_util.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/latency_info.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/shell.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/rect.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/gl/gl_switches.h" #include "ui/surface/accelerated_surface_transformer_win.h" #include "ui/surface/d3d9_utils_win.h" diff --git a/ui/ui.gyp b/ui/ui.gyp index 668086e..9d14e88 100644 --- a/ui/ui.gyp +++ b/ui/ui.gyp @@ -315,8 +315,6 @@ 'base/resource/resource_handle.h', 'base/text/bytes_formatting.cc', 'base/text/bytes_formatting.h', - 'base/text/utf16_indexing.cc', - 'base/text/utf16_indexing.h', 'base/theme_provider.cc', 'base/theme_provider.h', 'base/touch/touch_device.cc', @@ -355,23 +353,16 @@ 'base/win/hidden_window.h', 'base/win/hwnd_subclass.cc', 'base/win/hwnd_subclass.h', - 'base/win/hwnd_util.cc', - 'base/win/hwnd_util.h', 'base/win/message_box_win.cc', 'base/win/message_box_win.h', 'base/win/mouse_wheel_util.cc', 'base/win/mouse_wheel_util.h', 'base/win/scoped_ole_initializer.cc', 'base/win/scoped_ole_initializer.h', - 'base/win/scoped_set_map_mode.h', 'base/win/shell.cc', 'base/win/shell.h', - 'base/win/singleton_hwnd.cc', - 'base/win/singleton_hwnd.h', 'base/win/touch_input.cc', 'base/win/touch_input.h', - 'base/win/window_impl.cc', - 'base/win/window_impl.h', 'base/window_open_disposition.cc', 'base/window_open_disposition.h', 'base/work_area_watcher_observer.h', @@ -435,8 +426,6 @@ 'gfx/display.h', 'gfx/display_observer.cc', 'gfx/display_observer.h', - 'gfx/dpi_win.cc', - 'gfx/dpi_win.h', 'gfx/favicon_size.cc', 'gfx/favicon_size.h', 'gfx/font.cc', @@ -591,6 +580,8 @@ 'gfx/transform.h', 'gfx/transform_util.cc', 'gfx/transform_util.h', + 'gfx/utf16_indexing.cc', + 'gfx/utf16_indexing.h', 'gfx/vector2d.cc', 'gfx/vector2d.h', 'gfx/vector2d_conversions.cc', @@ -599,6 +590,15 @@ 'gfx/vector2d_f.h', 'gfx/vector3d_f.cc', 'gfx/vector3d_f.h', + 'gfx/win/dpi.cc', + 'gfx/win/dpi.h', + 'gfx/win/hwnd_util.cc', + 'gfx/win/hwnd_util.h', + 'gfx/win/scoped_set_map_mode.h', + 'gfx/win/singleton_hwnd.cc', + 'gfx/win/singleton_hwnd.h', + 'gfx/win/window_impl.cc', + 'gfx/win/window_impl.h', 'webui/jstemplate_builder.cc', 'webui/jstemplate_builder.h', 'webui/web_ui_util.cc', diff --git a/ui/ui_unittests.gypi b/ui/ui_unittests.gypi index 8c9771b..28e89645 100644 --- a/ui/ui_unittests.gypi +++ b/ui/ui_unittests.gypi @@ -165,7 +165,6 @@ 'base/ozone/evdev/touch_event_converter_ozone_unittest.cc', 'base/test/data/resource.h', 'base/text/bytes_formatting_unittest.cc', - 'base/text/utf16_indexing_unittest.cc', 'base/view_prop_unittest.cc', 'gfx/blit_unittest.cc', 'gfx/break_list_unittest.cc', @@ -178,6 +177,7 @@ 'gfx/platform_font_mac_unittest.mm', 'gfx/render_text_unittest.cc', 'gfx/transform_util_unittest.cc', + 'gfx/utf16_indexing_unittest.cc', 'shell_dialogs/select_file_dialog_win_unittest.cc', 'webui/web_ui_util_unittest.cc', ], diff --git a/ui/views/controls/combobox/native_combobox_win.cc b/ui/views/controls/combobox/native_combobox_win.cc index 3093c53..a810d85 100644 --- a/ui/views/controls/combobox/native_combobox_win.cc +++ b/ui/views/controls/combobox/native_combobox_win.cc @@ -9,8 +9,8 @@ #include "ui/base/events/event.h" #include "ui/base/models/combobox_model.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/base/win/hwnd_util.h" #include "ui/gfx/font.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/native_theme/native_theme_win.h" #include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/combobox/native_combobox_views.h" @@ -188,7 +188,7 @@ void NativeComboboxWin::CreateNativeControl() { flags, 0, 0, width(), height(), GetWidget()->GetNativeView(), NULL, NULL, NULL); - ui::CheckWindowCreated(control_hwnd); + gfx::CheckWindowCreated(control_hwnd); NativeControlCreated(control_hwnd); } diff --git a/ui/views/controls/menu/menu_win.cc b/ui/views/controls/menu/menu_win.cc index 3ff01b8..d75402b 100644 --- a/ui/views/controls/menu/menu_win.cc +++ b/ui/views/controls/menu/menu_win.cc @@ -13,10 +13,10 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" -#include "ui/base/win/window_impl.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/rect.h" +#include "ui/gfx/win/window_impl.h" namespace views { @@ -62,7 +62,7 @@ static int ChromeGetMenuItemID(HMENU hMenu, int pos) { // to intercept right clicks on the HMENU and notify the delegate as well as // for drawing icons. // -class MenuHostWindow : public ui::WindowImpl { +class MenuHostWindow : public gfx::WindowImpl { public: MenuHostWindow(MenuWin* menu, HWND parent_window) : menu_(menu) { int extended_style = 0; diff --git a/ui/views/controls/menu/native_menu_win.cc b/ui/views/controls/menu/native_menu_win.cc index e357b1e..10ff3a3 100644 --- a/ui/views/controls/menu/native_menu_win.cc +++ b/ui/views/controls/menu/native_menu_win.cc @@ -17,12 +17,12 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/models/menu_model.h" -#include "ui/base/win/hwnd_util.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/rect.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/native_theme/native_theme.h" #include "ui/native_theme/native_theme_win.h" #include "ui/views/controls/menu/menu_2.h" @@ -81,8 +81,8 @@ class NativeMenuWin::MenuHostWindow { RegisterClass(); hwnd_ = CreateWindowEx(l10n_util::GetExtendedStyles(), kWindowClassName, L"", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL); - ui::CheckWindowCreated(hwnd_); - ui::SetWindowUserData(hwnd_, this); + gfx::CheckWindowCreated(hwnd_); + gfx::SetWindowUserData(hwnd_, this); } ~MenuHostWindow() { @@ -350,7 +350,7 @@ class NativeMenuWin::MenuHostWindow { WPARAM w_param, LPARAM l_param) { MenuHostWindow* host = - reinterpret_cast(ui::GetWindowUserData(window)); + reinterpret_cast(gfx::GetWindowUserData(window)); // host is null during initial construction. LRESULT l_result = 0; if (!host || !host->ProcessWindowMessage(window, message, w_param, l_param, diff --git a/ui/views/controls/native/native_view_host_win.cc b/ui/views/controls/native/native_view_host_win.cc index da71d06..e7b74c3 100644 --- a/ui/views/controls/native/native_view_host_win.cc +++ b/ui/views/controls/native/native_view_host_win.cc @@ -8,9 +8,9 @@ #include "base/logging.h" #include "ui/base/win/hidden_window.h" -#include "ui/base/win/window_impl.h" #include "ui/gfx/canvas.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/window_impl.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/focus/focus_manager.h" #include "ui/views/widget/native_widget.h" diff --git a/ui/views/controls/native_control.cc b/ui/views/controls/native_control.cc index e6219e7..e450463 100644 --- a/ui/views/controls/native_control.cc +++ b/ui/views/controls/native_control.cc @@ -17,7 +17,7 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/views/background.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/focus/focus_manager.h" @@ -88,7 +88,7 @@ class NativeControlContainer : public CWindowImplCreateNativeControl(m_hWnd); // We subclass the control hwnd so we get the WM_KEYDOWN messages. - original_handler_ = ui::SetWindowProc( + original_handler_ = gfx::SetWindowProc( control_, &NativeControl::NativeControlWndProc); prop_.reset(new ViewProp(control_, kNativeControlKey , parent_)); @@ -378,7 +378,7 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, NOTREACHED(); } } else if (message == WM_DESTROY) { - ui::SetWindowProc(window, reinterpret_cast(original_handler)); + gfx::SetWindowProc(window, reinterpret_cast(original_handler)); native_control->container_->prop_.reset(); } diff --git a/ui/views/controls/native_control_win.cc b/ui/views/controls/native_control_win.cc index 2b6c6d4..c50411d 100644 --- a/ui/views/controls/native_control_win.cc +++ b/ui/views/controls/native_control_win.cc @@ -10,7 +10,7 @@ #include "ui/base/accessibility/accessibility_types.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/views/controls/combobox/combobox.h" #include "ui/views/focus/focus_manager.h" #include "ui/views/widget/widget.h" @@ -139,7 +139,7 @@ void NativeControlWin::NativeControlCreated(HWND native_control) { props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. - original_wndproc_ = ui::SetWindowProc( + original_wndproc_ = gfx::SetWindowProc( native_control, &NativeControlWin::NativeControlWndProc); Attach(native_control); @@ -216,7 +216,7 @@ LRESULT NativeControlWin::NativeControlWndProc(HWND window, } } else if (message == WM_DESTROY) { native_control->props_.clear(); - ui::SetWindowProc(window, native_control->original_wndproc_); + gfx::SetWindowProc(window, native_control->original_wndproc_); } return CallWindowProc(native_control->original_wndproc_, window, message, diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc index c96f3cb..99cf074 100644 --- a/ui/views/controls/textfield/native_textfield_win.cc +++ b/ui/views/controls/textfield/native_textfield_win.cc @@ -22,9 +22,9 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/gfx/range/range.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/native_theme/native_theme_win.h" #include "ui/views/controls/label.h" #include "ui/views/controls/menu/menu_item_view.h" @@ -1103,7 +1103,7 @@ void NativeTextfieldWin::OnSysChar(TCHAR ch, UINT repeat_count, UINT flags) { // something useful, so discard those. Note that [Ctrl]+[Alt]+ generates // WM_CHAR instead of WM_SYSCHAR, so it is not handled here. if (ch == VK_SPACE) { - ui::ShowSystemMenu( + gfx::ShowSystemMenu( container_view_->GetWidget()->GetTopLevelWidget()->GetNativeWindow()); } } diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc index 4db0c75..dae5684 100644 --- a/ui/views/controls/textfield/textfield_views_model.cc +++ b/ui/views/controls/textfield/textfield_views_model.cc @@ -12,12 +12,12 @@ #include "base/strings/utf_string_conversions.h" #include "ui/base/clipboard/clipboard.h" #include "ui/base/clipboard/scoped_clipboard_writer.h" -#include "ui/base/text/utf16_indexing.h" #include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/range/range.h" #include "ui/gfx/render_text.h" #include "ui/gfx/text_constants.h" +#include "ui/gfx/utf16_indexing.h" #include "ui/views/controls/textfield/textfield.h" namespace views { @@ -384,7 +384,7 @@ bool TextfieldViewsModel::Backspace() { if (cursor_position > 0) { // Delete one code point, which may be two UTF-16 words. size_t previous_char = - ui::UTF16OffsetToIndex(GetText(), cursor_position, -1); + gfx::UTF16OffsetToIndex(GetText(), cursor_position, -1); ExecuteAndRecordDelete(gfx::Range(cursor_position, previous_char), true); return true; } diff --git a/ui/views/widget/aero_tooltip_manager.cc b/ui/views/widget/aero_tooltip_manager.cc index 504ae48..c54124c 100644 --- a/ui/views/widget/aero_tooltip_manager.cc +++ b/ui/views/widget/aero_tooltip_manager.cc @@ -11,9 +11,9 @@ #include "base/bind.h" #include "base/message_loop/message_loop.h" #include "ui/base/l10n/l10n_util_win.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/point.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" namespace views { diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc index b9915ba..8f6720a 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc @@ -16,10 +16,10 @@ #include "ui/base/ime/input_method.h" #include "ui/base/ime/win/tsf_bridge.h" #include "ui/base/win/shell.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/insets.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/path_win.h" +#include "ui/gfx/win/dpi.h" #include "ui/native_theme/native_theme_aura.h" #include "ui/native_theme/native_theme_win.h" #include "ui/views/corewm/compound_event_filter.h" diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index ebfa66f..87d75cf 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -24,16 +24,16 @@ #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/theme_provider.h" #include "ui/base/view_prop.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/base/win/shell.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia_paint.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/path.h" #include "ui/gfx/point_conversions.h" #include "ui/gfx/screen.h" #include "ui/gfx/size_conversions.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/native_theme/native_theme.h" #include "ui/views/controls/native_control_win.h" #include "ui/views/controls/textfield/textfield.h" diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index bc24630..cadc6fd 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -11,7 +11,7 @@ #include "base/memory/scoped_vector.h" #include "base/win/scoped_comptr.h" #include "base/win/win_util.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" #include "ui/views/widget/native_widget_private.h" #include "ui/views/win/hwnd_message_handler_delegate.h" diff --git a/ui/views/widget/tooltip_manager_win.cc b/ui/views/widget/tooltip_manager_win.cc index 4c0a241..362ff33 100644 --- a/ui/views/widget/tooltip_manager_win.cc +++ b/ui/views/widget/tooltip_manager_win.cc @@ -16,11 +16,11 @@ #include "base/win/scoped_hdc.h" #include "base/win/scoped_select_object.h" #include "ui/base/l10n/l10n_util_win.h" -#include "ui/base/win/hwnd_util.h" -#include "ui/base/win/scoped_set_map_mode.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/font_list.h" #include "ui/gfx/screen.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" +#include "ui/gfx/win/scoped_set_map_mode.h" #include "ui/views/view.h" #include "ui/views/widget/monitor_win.h" #include "ui/views/widget/widget.h" @@ -257,7 +257,7 @@ int TooltipManagerWin::CalcTooltipHeight() { if (hfont != NULL) { base::win::ScopedGetDC dc(tooltip_hwnd_); base::win::ScopedSelectObject font(dc, hfont); - ui::ScopedSetMapMode mode(dc, MM_TEXT); + gfx::ScopedSetMapMode mode(dc, MM_TEXT); TEXTMETRIC font_metrics; GetTextMetrics(dc, &font_metrics); height = font_metrics.tmHeight; diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc index d2a6804..e8823f2 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc @@ -16,18 +16,18 @@ #include "ui/base/gestures/gesture_sequence.h" #include "ui/base/keycodes/keyboard_code_conversion_win.h" #include "ui/base/touch/touch_enabled.h" -#include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" #include "ui/base/win/shell.h" #include "ui/base/win/touch_input.h" #include "ui/gfx/canvas.h" #include "ui/gfx/canvas_skia_paint.h" -#include "ui/gfx/dpi_win.h" #include "ui/gfx/icon_util.h" #include "ui/gfx/insets.h" #include "ui/gfx/path.h" #include "ui/gfx/path_win.h" #include "ui/gfx/screen.h" +#include "ui/gfx/win/dpi.h" +#include "ui/gfx/win/hwnd_util.h" #include "ui/native_theme/native_theme_win.h" #include "ui/views/views_delegate.h" #include "ui/views/widget/monitor_win.h" @@ -543,7 +543,7 @@ void HWNDMessageHandler::CenterWindow(const gfx::Size& size) { HWND parent = GetParent(hwnd()); if (!IsWindow(hwnd())) parent = ::GetWindow(hwnd(), GW_OWNER); - ui::CenterAndSizeWindow(parent, hwnd(), size); + gfx::CenterAndSizeWindow(parent, hwnd(), size); } void HWNDMessageHandler::SetRegion(HRGN region) { @@ -844,7 +844,7 @@ void HWNDMessageHandler::DispatchKeyEventPostIME(const ui::KeyEvent& key) { } //////////////////////////////////////////////////////////////////////////////// -// HWNDMessageHandler, ui::WindowImpl overrides: +// HWNDMessageHandler, gfx::WindowImpl overrides: HICON HWNDMessageHandler::GetDefaultWindowIcon() const { if (use_system_default_icon_) @@ -1526,7 +1526,7 @@ LRESULT HWNDMessageHandler::OnMouseRange(UINT message, w_param = SendMessage(hwnd(), WM_NCHITTEST, 0, MAKELPARAM(screen_point.x, screen_point.y)); if (w_param == HTCAPTION || w_param == HTSYSMENU) { - ui::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point)); + gfx::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point)); return 0; } } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) { diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h index 86b8f2e..462a937 100644 --- a/ui/views/win/hwnd_message_handler.h +++ b/ui/views/win/hwnd_message_handler.h @@ -23,8 +23,8 @@ #include "ui/base/accessibility/accessibility_types.h" #include "ui/base/events/event.h" #include "ui/base/ui_base_types.h" -#include "ui/base/win/window_impl.h" #include "ui/gfx/rect.h" +#include "ui/gfx/win/window_impl.h" #include "ui/views/ime/input_method_delegate.h" #include "ui/views/views_export.h" @@ -58,7 +58,7 @@ const int WM_NCUAHDRAWFRAME = 0xAF; // implementation. // TODO(beng): This object should eventually *become* the WindowImpl. class VIEWS_EXPORT HWNDMessageHandler : - public ui::WindowImpl, + public gfx::WindowImpl, public internal::InputMethodDelegate, public base::MessageLoopForUI::Observer { public: diff --git a/webkit/child/webthemeengine_impl_win.cc b/webkit/child/webthemeengine_impl_win.cc index 6953372..32b071e 100644 --- a/webkit/child/webthemeengine_impl_win.cc +++ b/webkit/child/webthemeengine_impl_win.cc @@ -10,7 +10,7 @@ #include "skia/ext/platform_canvas.h" #include "skia/ext/skia_utils_win.h" #include "third_party/WebKit/public/platform/WebRect.h" -#include "ui/gfx/dpi_win.h" +#include "ui/gfx/win/dpi.h" #include "ui/native_theme/native_theme.h" using WebKit::WebCanvas; -- cgit v1.1