Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc

Issue 1935883002: win: Fix black pixel artifact at right and bottom Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" 5 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "third_party/skia/include/core/SkPath.h" 8 #include "third_party/skia/include/core/SkPath.h"
9 #include "third_party/skia/include/core/SkRegion.h" 9 #include "third_party/skia/include/core/SkRegion.h"
10 #include "ui/aura/client/aura_constants.h" 10 #include "ui/aura/client/aura_constants.h"
11 #include "ui/aura/client/cursor_client.h" 11 #include "ui/aura/client/cursor_client.h"
12 #include "ui/aura/client/focus_client.h" 12 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/window_event_dispatcher.h" 13 #include "ui/aura/window_event_dispatcher.h"
14 #include "ui/aura/window_property.h" 14 #include "ui/aura/window_property.h"
15 #include "ui/base/cursor/cursor_loader_win.h" 15 #include "ui/base/cursor/cursor_loader_win.h"
16 #include "ui/base/ime/input_method.h" 16 #include "ui/base/ime/input_method.h"
17 #include "ui/base/win/shell.h" 17 #include "ui/base/win/shell.h"
18 #include "ui/compositor/compositor_constants.h" 18 #include "ui/compositor/compositor_constants.h"
19 #include "ui/compositor/paint_context.h" 19 #include "ui/compositor/paint_context.h"
20 #include "ui/display/display.h"
20 #include "ui/display/win/dpi.h" 21 #include "ui/display/win/dpi.h"
21 #include "ui/display/win/screen_win.h" 22 #include "ui/display/win/screen_win.h"
22 #include "ui/gfx/geometry/insets.h" 23 #include "ui/gfx/geometry/insets.h"
23 #include "ui/gfx/geometry/vector2d.h" 24 #include "ui/gfx/geometry/vector2d.h"
24 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
25 #include "ui/gfx/path.h" 26 #include "ui/gfx/path.h"
26 #include "ui/gfx/path_win.h" 27 #include "ui/gfx/path_win.h"
27 #include "ui/native_theme/native_theme_aura.h" 28 #include "ui/native_theme/native_theme_aura.h"
28 #include "ui/native_theme/native_theme_win.h" 29 #include "ui/native_theme/native_theme_win.h"
29 #include "ui/views/corewm/tooltip_win.h" 30 #include "ui/views/corewm/tooltip_win.h"
(...skipping 24 matching lines...) Expand all
54 // Some AMD drivers can't display windows that are less than 64x64 pixels, 55 // Some AMD drivers can't display windows that are less than 64x64 pixels,
55 // so expand them to be at least that size. http://crbug.com/286609 56 // so expand them to be at least that size. http://crbug.com/286609
56 gfx::Size expanded(std::max(size.width(), 64), std::max(size.height(), 64)); 57 gfx::Size expanded(std::max(size.width(), 64), std::max(size.height(), 64));
57 return expanded; 58 return expanded;
58 } 59 }
59 60
60 void InsetBottomRight(gfx::Rect* rect, const gfx::Vector2d& vector) { 61 void InsetBottomRight(gfx::Rect* rect, const gfx::Vector2d& vector) {
61 rect->Inset(0, 0, vector.x(), vector.y()); 62 rect->Inset(0, 0, vector.x(), vector.y());
62 } 63 }
63 64
65 // https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903.
66 bool UnadjustWindowRectEx(RECT* rect, DWORD style, BOOL menu, DWORD ex_style) {
67 RECT adjust_rect;
68 SetRectEmpty(&adjust_rect);
69 bool success = !!AdjustWindowRectEx(&adjust_rect, style, menu, ex_style);
70 if (success) {
71 rect->left -= adjust_rect.left;
72 rect->top -= adjust_rect.top;
73 rect->right -= adjust_rect.right;
74 rect->bottom -= adjust_rect.bottom;
75 }
76 return success;
77 }
78
79 double GetIntegralMultipleForDSF(double dsf) {
80 if (static_cast<int>(dsf) == dsf)
81 return dsf;
82 // Rather than calculate an integral multiple here, we only handle common
83 // DSFs; this is done so that if we somehow end up with a strange
84 // non-integral-dividing one, we don't cause the window to resize in huge
85 // chunks. This table is effectively the numerator of the DSF expressed as a
86 // reduced improper fraction.
87 static const struct { double dsf; double multiple; } kKnownFactors[] = {
88 // def GCD(a, b): return a if b == 0 else GCD(b, a % b)
89 // for i in range(125, 351, 25):
90 // if i / 100.0 == i // 100: continue
91 // gcd = GCD(i, 100)
92 // print '{ %f, %d }, ' % (i / 100.0, i / gcd)
93 { 1.250000, 5 },
94 { 1.500000, 3 },
95 { 1.750000, 7 },
96 { 2.250000, 9 },
97 { 2.500000, 5 },
98 { 2.750000, 11 },
99 { 3.250000, 13 },
100 { 3.500000, 7 },
101 };
102 for (const auto& element : kKnownFactors) {
103 if (element.dsf == dsf)
104 return element.multiple;
105 }
106 return 1.0;
107 }
108
109 void EnsureIntegralMultipleOfDeviceScaleFactor(double dsf,
110 gfx::Rect* rect,
111 UINT edge,
112 DWORD style,
113 DWORD ex_style) {
114 RECT client = rect->ToRECT();
115 if (UnadjustWindowRectEx(&client, style, false, ex_style)) {
116 // Adjust the client size so that it's an integral multiple of DSF.
117 const double multiple = GetIntegralMultipleForDSF(dsf);
118
119 const double adjusted_width =
120 floor((static_cast<double>(client.right) - client.left) / multiple) *
121 multiple;
122 if (edge == 0 || edge == WMSZ_RIGHT || edge == WMSZ_TOPRIGHT ||
123 edge == WMSZ_BOTTOMRIGHT) {
124 client.right = client.left + static_cast<int>(adjusted_width);
125 }
126 if (edge == WMSZ_LEFT || edge == WMSZ_TOPLEFT || edge == WMSZ_BOTTOMLEFT)
127 client.left = client.right - static_cast<int>(adjusted_width);
128
129 const double adjusted_height =
130 floor((static_cast<double>(client.bottom) - client.top) / multiple) *
131 multiple;
132 if (edge == 0 || edge == WMSZ_BOTTOM || edge == WMSZ_BOTTOMLEFT ||
133 edge == WMSZ_BOTTOMRIGHT) {
134 client.bottom = client.top + static_cast<int>(adjusted_height);
135 }
136 if (edge == WMSZ_TOP || edge == WMSZ_TOPLEFT || edge == WMSZ_TOPRIGHT)
137 client.top = client.bottom - static_cast<int>(adjusted_height);
138
139 // Convert client size back to window, and store into rect.
140 if (AdjustWindowRectEx(&client, style, false, ex_style))
141 *rect = gfx::Rect(client);
142 }
143 }
144
64 } // namespace 145 } // namespace
65 146
66 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL); 147 DEFINE_WINDOW_PROPERTY_KEY(aura::Window*, kContentWindowForRootWindow, NULL);
67 148
68 // Identifies the DesktopWindowTreeHostWin associated with the 149 // Identifies the DesktopWindowTreeHostWin associated with the
69 // WindowEventDispatcher. 150 // WindowEventDispatcher.
70 DEFINE_WINDOW_PROPERTY_KEY(DesktopWindowTreeHostWin*, kDesktopWindowTreeHostKey, 151 DEFINE_WINDOW_PROPERTY_KEY(DesktopWindowTreeHostWin*, kDesktopWindowTreeHostKey,
71 NULL); 152 NULL);
72 153
73 //////////////////////////////////////////////////////////////////////////////// 154 ////////////////////////////////////////////////////////////////////////////////
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 window()->SetProperty(kDesktopWindowTreeHostKey, this); 248 window()->SetProperty(kDesktopWindowTreeHostKey, this);
168 249
169 should_animate_window_close_ = 250 should_animate_window_close_ =
170 content_window_->type() != ui::wm::WINDOW_TYPE_NORMAL && 251 content_window_->type() != ui::wm::WINDOW_TYPE_NORMAL &&
171 !wm::WindowAnimationsDisabled(content_window_); 252 !wm::WindowAnimationsDisabled(content_window_);
172 253
173 // TODO this is not invoked *after* Init(), but should be ok. 254 // TODO this is not invoked *after* Init(), but should be ok.
174 SetWindowTransparency(); 255 SetWindowTransparency();
175 } 256 }
176 257
258 void DesktopWindowTreeHostWin::OnNativeWidgetInitDone() {
259 gfx::Rect pixel_bounds = message_handler_->GetWindowBoundsInScreen();
260 display::Display display =
261 display::Screen::GetScreen()->GetDisplayNearestWindow(
262 GetWidget()->GetNativeView());
263 EnsureIntegralMultipleOfDeviceScaleFactor(
264 display.device_scale_factor(), &pixel_bounds, 0,
265 message_handler_->window_style(), message_handler_->window_ex_style());
266 SetBounds(pixel_bounds);
267 }
268
177 std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostWin::CreateTooltip() { 269 std::unique_ptr<corewm::Tooltip> DesktopWindowTreeHostWin::CreateTooltip() {
178 DCHECK(!tooltip_); 270 DCHECK(!tooltip_);
179 tooltip_ = new corewm::TooltipWin(GetAcceleratedWidget()); 271 tooltip_ = new corewm::TooltipWin(GetAcceleratedWidget());
180 return base::WrapUnique(tooltip_); 272 return base::WrapUnique(tooltip_);
181 } 273 }
182 274
183 std::unique_ptr<aura::client::DragDropClient> 275 std::unique_ptr<aura::client::DragDropClient>
184 DesktopWindowTreeHostWin::CreateDragDropClient( 276 DesktopWindowTreeHostWin::CreateDragDropClient(
185 DesktopNativeCursorManager* cursor_manager) { 277 DesktopNativeCursorManager* cursor_manager) {
186 drag_drop_client_ = new DesktopDragDropClientWin(window(), GetHWND()); 278 drag_drop_client_ = new DesktopDragDropClientWin(window(), GetHWND());
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 922
831 bool DesktopWindowTreeHostWin::HandleMouseEvent(const ui::MouseEvent& event) { 923 bool DesktopWindowTreeHostWin::HandleMouseEvent(const ui::MouseEvent& event) {
832 SendEventToProcessor(const_cast<ui::MouseEvent*>(&event)); 924 SendEventToProcessor(const_cast<ui::MouseEvent*>(&event));
833 return event.handled(); 925 return event.handled();
834 } 926 }
835 927
836 void DesktopWindowTreeHostWin::HandleKeyEvent(ui::KeyEvent* event) { 928 void DesktopWindowTreeHostWin::HandleKeyEvent(ui::KeyEvent* event) {
837 GetInputMethod()->DispatchKeyEvent(event); 929 GetInputMethod()->DispatchKeyEvent(event);
838 } 930 }
839 931
932 void DesktopWindowTreeHostWin::HandleSizing(UINT edge, RECT* rect) {
933 display::Display display =
934 display::Screen::GetScreen()->GetDisplayNearestWindow(
935 GetWidget()->GetNativeView());
936 DWORD style = GetWindowLong(GetHWND(), GWL_STYLE);
937 DWORD ex_style = GetWindowLong(GetHWND(), GWL_EXSTYLE);
938 gfx::Rect gfx_rect(*rect);
939 EnsureIntegralMultipleOfDeviceScaleFactor(display.device_scale_factor(),
940 &gfx_rect, edge, style, ex_style);
941 *rect = gfx_rect.ToRECT();
942 }
943
840 void DesktopWindowTreeHostWin::HandleTouchEvent( 944 void DesktopWindowTreeHostWin::HandleTouchEvent(
841 const ui::TouchEvent& event) { 945 const ui::TouchEvent& event) {
842 // HWNDMessageHandler asynchronously processes touch events. Because of this 946 // HWNDMessageHandler asynchronously processes touch events. Because of this
843 // it's possible for the aura::WindowEventDispatcher to have been destroyed 947 // it's possible for the aura::WindowEventDispatcher to have been destroyed
844 // by the time we attempt to process them. 948 // by the time we attempt to process them.
845 if (!GetWidget()->GetNativeView()) 949 if (!GetWidget()->GetNativeView())
846 return; 950 return;
847 951
848 // Currently we assume the window that has capture gets touch events too. 952 // Currently we assume the window that has capture gets touch events too.
849 aura::WindowTreeHost* host = 953 aura::WindowTreeHost* host =
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 1088
985 // static 1089 // static
986 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( 1090 DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
987 internal::NativeWidgetDelegate* native_widget_delegate, 1091 internal::NativeWidgetDelegate* native_widget_delegate,
988 DesktopNativeWidgetAura* desktop_native_widget_aura) { 1092 DesktopNativeWidgetAura* desktop_native_widget_aura) {
989 return new DesktopWindowTreeHostWin(native_widget_delegate, 1093 return new DesktopWindowTreeHostWin(native_widget_delegate,
990 desktop_native_widget_aura); 1094 desktop_native_widget_aura);
991 } 1095 }
992 1096
993 } // namespace views 1097 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/desktop_aura/desktop_window_tree_host_win.h ('k') | ui/views/win/hwnd_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698