Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/display/screen.h" | 5 #include "ui/display/screen.h" |
| 6 | 6 |
| 7 #include "ui/display/display.h" | 7 #include "ui/display/display.h" |
| 8 #include "ui/display/display_finder.h" | |
| 8 #include "ui/gfx/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 9 | 10 |
| 10 namespace display { | 11 namespace display { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 Screen* g_screen; | 15 Screen* g_screen; |
| 15 | 16 |
| 16 } // namespace | 17 } // namespace |
| 17 | 18 |
| 18 Screen::Screen() {} | 19 Screen::Screen() {} |
| 19 | 20 |
| 20 Screen::~Screen() {} | 21 Screen::~Screen() {} |
| 21 | 22 |
| 22 // static | 23 // static |
| 23 Screen* Screen::GetScreen() { | 24 Screen* Screen::GetScreen() { |
| 24 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
| 25 // TODO(scottmg): https://crbug.com/558054 | 26 // TODO(scottmg): https://crbug.com/558054 |
| 26 if (!g_screen) | 27 if (!g_screen) |
| 27 g_screen = CreateNativeScreen(); | 28 g_screen = CreateNativeScreen(); |
| 28 #endif | 29 #endif |
| 29 return g_screen; | 30 return g_screen; |
| 30 } | 31 } |
| 31 | 32 |
| 32 // static | 33 // static |
| 33 void Screen::SetScreenInstance(Screen* instance) { | 34 void Screen::SetScreenInstance(Screen* instance) { |
| 34 g_screen = instance; | 35 g_screen = instance; |
| 35 } | 36 } |
| 36 | 37 |
| 38 //static | |
|
msw
2016/12/12 23:04:35
nit: space after slashes
msw
2016/12/13 22:52:43
Ping
kylix_rd
2016/12/14 17:35:10
Done.
| |
| 39 gfx::Rect Screen::MoveScreenRectToNearestDisplay( | |
|
msw
2016/12/12 23:04:35
Will this be used elsewhere? Might it make sense t
kylix_rd
2016/12/13 14:17:44
I'd originally put this code in that file but this
msw
2016/12/13 22:52:43
I'm also a little surprised that I can't find a si
kylix_rd
2016/12/14 17:35:10
My point was that should this be put elsewhere, it
msw
2016/12/14 18:22:06
Finding code to reuse later isn't too hard. I sear
| |
| 40 const gfx::Rect& screen_rect) { | |
| 41 gfx::Rect display_rect = screen_rect; | |
| 42 const display::Display* display = | |
| 43 display::FindDisplayNearestPoint(GetScreen()->GetAllDisplays(), | |
| 44 display_rect.CenterPoint()); | |
|
msw
2016/12/14 18:45:11
It might make sense to use the display closest to
| |
| 45 DCHECK(display); | |
| 46 const gfx::Rect work_area = display->work_area(); | |
| 47 if (!work_area.Contains(display_rect)) { | |
|
msw
2016/12/12 23:04:35
q: do we care about making minimal changes to the
kylix_rd
2016/12/13 14:17:44
If the rect were partially visible, it would be so
msw
2016/12/13 22:52:44
Hopefully this positioning fixup is applied before
kylix_rd
2016/12/14 17:35:10
Yes, this is done prior to the dialog is initially
msw
2016/12/14 18:22:06
I'm saying that if a window were larger than the d
msw
2016/12/14 18:45:12
Perhaps the right function for this job is gfx::Re
| |
| 48 if (display_rect.x() < work_area.x()) | |
| 49 display_rect.set_x(work_area.x()); | |
| 50 if (display_rect.right() > work_area.right()) | |
|
msw
2016/12/13 22:52:44
else if? (or handle rects larger than the work are
kylix_rd
2016/12/14 17:35:10
See above comment.
| |
| 51 display_rect.set_x(work_area.right() - display_rect.width()); | |
| 52 if (display_rect.y() < work_area.y()) | |
| 53 display_rect.set_y(work_area.y()); | |
| 54 if (display_rect.bottom() > work_area.bottom()) | |
|
msw
2016/12/13 22:52:44
else if? (or handle rects larger than the work are
| |
| 55 display_rect.set_y(work_area.bottom() - display_rect.height()); | |
| 56 } | |
| 57 return display_rect; | |
| 58 } | |
| 59 | |
| 37 gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view, | 60 gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view, |
| 38 const gfx::Rect& screen_rect) const { | 61 const gfx::Rect& screen_rect) const { |
| 39 float scale = GetDisplayNearestWindow(view).device_scale_factor(); | 62 float scale = GetDisplayNearestWindow(view).device_scale_factor(); |
| 40 return ScaleToEnclosingRect(screen_rect, 1.0f / scale); | 63 return ScaleToEnclosingRect(screen_rect, 1.0f / scale); |
| 41 } | 64 } |
| 42 | 65 |
| 43 gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view, | 66 gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeView view, |
| 44 const gfx::Rect& dip_rect) const { | 67 const gfx::Rect& dip_rect) const { |
| 45 float scale = GetDisplayNearestWindow(view).device_scale_factor(); | 68 float scale = GetDisplayNearestWindow(view).device_scale_factor(); |
| 46 return ScaleToEnclosingRect(dip_rect, scale); | 69 return ScaleToEnclosingRect(dip_rect, scale); |
| 47 } | 70 } |
| 48 | 71 |
| 49 bool Screen::GetDisplayWithDisplayId(int64_t display_id, | 72 bool Screen::GetDisplayWithDisplayId(int64_t display_id, |
| 50 display::Display* display) const { | 73 display::Display* display) const { |
| 51 for (const display::Display& display_in_list : GetAllDisplays()) { | 74 for (const display::Display& display_in_list : GetAllDisplays()) { |
| 52 if (display_in_list.id() == display_id) { | 75 if (display_in_list.id() == display_id) { |
| 53 *display = display_in_list; | 76 *display = display_in_list; |
| 54 return true; | 77 return true; |
| 55 } | 78 } |
| 56 } | 79 } |
| 57 return false; | 80 return false; |
| 58 } | 81 } |
| 59 | 82 |
| 60 } // namespace display | 83 } // namespace display |
| OLD | NEW |