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

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

Issue 2173033002: Make various views SetShape() methods take an unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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"
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const { 297 gfx::Rect DesktopWindowTreeHostWin::GetWorkAreaBoundsInScreen() const {
298 MONITORINFO monitor_info; 298 MONITORINFO monitor_info;
299 monitor_info.cbSize = sizeof(monitor_info); 299 monitor_info.cbSize = sizeof(monitor_info);
300 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(), 300 GetMonitorInfo(MonitorFromWindow(message_handler_->hwnd(),
301 MONITOR_DEFAULTTONEAREST), 301 MONITOR_DEFAULTTONEAREST),
302 &monitor_info); 302 &monitor_info);
303 gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork); 303 gfx::Rect pixel_bounds = gfx::Rect(monitor_info.rcWork);
304 return display::win::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds); 304 return display::win::ScreenWin::ScreenToDIPRect(GetHWND(), pixel_bounds);
305 } 305 }
306 306
307 void DesktopWindowTreeHostWin::SetShape(SkRegion* native_region) { 307 void DesktopWindowTreeHostWin::SetShape(
308 if (native_region) { 308 std::unique_ptr<SkRegion> native_region) {
309 // TODO(wez): This would be a lot simpler if we were passed an SkPath. 309 if (!native_region) {
310 // See crbug.com/410593. 310 message_handler_->SetRegion(nullptr);
311 SkRegion* shape = native_region; 311 return;
312 SkRegion device_region;
313 if (display::win::GetDPIScale() > 1.0) {
314 shape = &device_region;
315 const float& scale = display::win::GetDPIScale();
316 std::vector<SkIRect> rects;
317 for (SkRegion::Iterator it(*native_region); !it.done(); it.next()) {
318 const SkIRect& rect = it.rect();
319 SkRect scaled_rect =
320 SkRect::MakeLTRB(rect.left() * scale, rect.top() * scale,
321 rect.right() * scale, rect.bottom() * scale);
322 SkIRect rounded_scaled_rect;
323 scaled_rect.roundOut(&rounded_scaled_rect);
324 rects.push_back(rounded_scaled_rect);
325 }
326 if (!rects.empty())
327 device_region.setRects(&rects[0], rects.size());
328 }
329
330 message_handler_->SetRegion(gfx::CreateHRGNFromSkRegion(*shape));
331 } else {
332 message_handler_->SetRegion(NULL);
333 } 312 }
334 313
335 delete native_region; 314 // TODO(wez): This would be a lot simpler if we were passed an SkPath.
315 // See crbug.com/410593.
316 SkRegion* shape = native_region.get();
317 SkRegion device_region;
318 if (display::win::GetDPIScale() > 1.0) {
319 shape = &device_region;
320 const float& scale = display::win::GetDPIScale();
sadrul 2016/07/23 00:59:16 weird to use a ref here.
Lei Zhang 2016/07/25 17:57:00 Indeed. It's copy + paste... and fixed.
321 std::vector<SkIRect> rects;
322 for (SkRegion::Iterator it(*native_region); !it.done(); it.next()) {
323 const SkIRect& rect = it.rect();
324 SkRect scaled_rect =
325 SkRect::MakeLTRB(rect.left() * scale, rect.top() * scale,
326 rect.right() * scale, rect.bottom() * scale);
327 SkIRect rounded_scaled_rect;
328 scaled_rect.roundOut(&rounded_scaled_rect);
329 rects.push_back(rounded_scaled_rect);
330 }
331 if (!rects.empty())
332 device_region.setRects(&rects[0], rects.size());
333 }
334
335 message_handler_->SetRegion(gfx::CreateHRGNFromSkRegion(*shape));
336 } 336 }
337 337
338 void DesktopWindowTreeHostWin::Activate() { 338 void DesktopWindowTreeHostWin::Activate() {
339 message_handler_->Activate(); 339 message_handler_->Activate();
340 } 340 }
341 341
342 void DesktopWindowTreeHostWin::Deactivate() { 342 void DesktopWindowTreeHostWin::Deactivate() {
343 message_handler_->Deactivate(); 343 message_handler_->Deactivate();
344 } 344 }
345 345
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 997
998 // static 998 // static
999 DesktopWindowTreeHost* DesktopWindowTreeHost::Create( 999 DesktopWindowTreeHost* DesktopWindowTreeHost::Create(
1000 internal::NativeWidgetDelegate* native_widget_delegate, 1000 internal::NativeWidgetDelegate* native_widget_delegate,
1001 DesktopNativeWidgetAura* desktop_native_widget_aura) { 1001 DesktopNativeWidgetAura* desktop_native_widget_aura) {
1002 return new DesktopWindowTreeHostWin(native_widget_delegate, 1002 return new DesktopWindowTreeHostWin(native_widget_delegate,
1003 desktop_native_widget_aura); 1003 desktop_native_widget_aura);
1004 } 1004 }
1005 1005
1006 } // namespace views 1006 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698