Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/display/screen.h" | 5 #include "ui/display/android/screen_android.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "base/macros.h" | |
| 9 #include "ui/display/display.h" | |
| 10 #include "ui/gfx/android/device_display_info.h" | 7 #include "ui/gfx/android/device_display_info.h" |
| 11 #include "ui/gfx/geometry/size_conversions.h" | 8 #include "ui/gfx/geometry/size_conversions.h" |
| 12 | 9 |
| 13 namespace display { | 10 namespace display { |
| 14 | 11 |
| 15 class ScreenAndroid : public Screen { | 12 ScreenAndroid::ScreenAndroid() {} |
| 16 public: | 13 ScreenAndroid::~ScreenAndroid() {} |
| 17 ScreenAndroid() {} | |
| 18 | 14 |
| 19 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } | 15 gfx::Point ScreenAndroid::GetCursorScreenPoint() { return gfx::Point(); } |
| 20 | 16 |
| 21 bool IsWindowUnderCursor(gfx::NativeWindow window) override { | 17 bool ScreenAndroid::IsWindowUnderCursor(gfx::NativeWindow window) { |
| 22 NOTIMPLEMENTED(); | 18 NOTIMPLEMENTED(); |
| 23 return false; | 19 return false; |
| 20 } | |
| 21 | |
| 22 gfx::NativeWindow ScreenAndroid::GetWindowAtScreenPoint( | |
| 23 const gfx::Point& point) { | |
| 24 NOTIMPLEMENTED(); | |
| 25 return NULL; | |
| 26 } | |
| 27 | |
| 28 Display ScreenAndroid::GetPrimaryDisplay() const { | |
| 29 gfx::DeviceDisplayInfo device_info; | |
| 30 const float device_scale_factor = device_info.GetDIPScale(); | |
| 31 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | |
| 32 // decorations etc. Use it instead of GetDisplayWidth/Height() when | |
| 33 // available. | |
| 34 const gfx::Rect bounds_in_pixels = | |
| 35 gfx::Rect(device_info.GetPhysicalDisplayWidth() | |
| 36 ? device_info.GetPhysicalDisplayWidth() | |
| 37 : device_info.GetDisplayWidth(), | |
| 38 device_info.GetPhysicalDisplayHeight() | |
| 39 ? device_info.GetPhysicalDisplayHeight() | |
| 40 : device_info.GetDisplayHeight()); | |
| 41 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( | |
| 42 bounds_in_pixels.size(), 1.0f / device_scale_factor)); | |
| 43 Display display(0, bounds_in_dip); | |
| 44 if (!Display::HasForceDeviceScaleFactor()) | |
| 45 display.set_device_scale_factor(device_scale_factor); | |
| 46 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | |
| 47 display.set_color_depth(device_info.GetBitsPerPixel()); | |
| 48 display.set_depth_per_component(device_info.GetBitsPerComponent()); | |
| 49 display.set_is_monochrome(device_info.GetBitsPerComponent() == 0); | |
| 50 return display; | |
| 51 } | |
| 52 | |
| 53 void ScreenAndroid::SetDisplayForWindow(gfx::NativeView view, | |
| 54 const Display& display) { | |
| 55 base::AutoLock autolock(display_lock_); | |
| 56 display_map_[view] = display; | |
|
oshima
2016/10/24 20:01:10
nit: emplace(view, display)
| |
| 57 } | |
| 58 | |
| 59 void ScreenAndroid::ClearDisplayForWindow(gfx::NativeView view) { | |
| 60 base::AutoLock autolock(display_lock_); | |
| 61 display_map_.erase(view); | |
| 62 } | |
| 63 | |
| 64 Display ScreenAndroid::GetDisplayNearestWindow(gfx::NativeView view) const { | |
| 65 base::AutoLock autolock(display_lock_); | |
| 66 auto iter = display_map_.find(view); | |
| 67 if (iter == display_map_.end()) { | |
| 68 return GetPrimaryDisplay(); | |
| 69 } else { | |
| 70 return iter->second; | |
| 24 } | 71 } |
|
oshima
2016/10/24 20:01:10
nit:
if (cond)
return GetPrimaryDislpay();
retur
| |
| 72 } | |
| 25 | 73 |
| 26 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { | 74 Display ScreenAndroid::GetDisplayNearestPoint(const gfx::Point& point) const { |
| 27 NOTIMPLEMENTED(); | 75 return GetPrimaryDisplay(); |
| 28 return NULL; | 76 } |
| 29 } | |
| 30 | 77 |
| 31 Display GetPrimaryDisplay() const override { | 78 int ScreenAndroid::GetNumDisplays() const { return 1; } |
| 32 gfx::DeviceDisplayInfo device_info; | |
| 33 const float device_scale_factor = device_info.GetDIPScale(); | |
| 34 // Note: GetPhysicalDisplayWidth/Height() does not subtract window | |
| 35 // decorations etc. Use it instead of GetDisplayWidth/Height() when | |
| 36 // available. | |
| 37 const gfx::Rect bounds_in_pixels = | |
| 38 gfx::Rect(device_info.GetPhysicalDisplayWidth() | |
| 39 ? device_info.GetPhysicalDisplayWidth() | |
| 40 : device_info.GetDisplayWidth(), | |
| 41 device_info.GetPhysicalDisplayHeight() | |
| 42 ? device_info.GetPhysicalDisplayHeight() | |
| 43 : device_info.GetDisplayHeight()); | |
| 44 const gfx::Rect bounds_in_dip = gfx::Rect(gfx::ScaleToCeiledSize( | |
| 45 bounds_in_pixels.size(), 1.0f / device_scale_factor)); | |
| 46 Display display(0, bounds_in_dip); | |
| 47 if (!Display::HasForceDeviceScaleFactor()) | |
| 48 display.set_device_scale_factor(device_scale_factor); | |
| 49 display.SetRotationAsDegree(device_info.GetRotationDegrees()); | |
| 50 display.set_color_depth(device_info.GetBitsPerPixel()); | |
| 51 display.set_depth_per_component(device_info.GetBitsPerComponent()); | |
| 52 display.set_is_monochrome(device_info.GetBitsPerComponent() == 0); | |
| 53 return display; | |
| 54 } | |
| 55 | 79 |
| 56 Display GetDisplayNearestWindow(gfx::NativeView view) const override { | 80 std::vector<Display> ScreenAndroid::GetAllDisplays() const { |
| 57 return GetPrimaryDisplay(); | 81 return std::vector<Display>(1, GetPrimaryDisplay()); |
| 58 } | 82 } |
| 59 | 83 |
| 60 Display GetDisplayNearestPoint(const gfx::Point& point) const override { | 84 Display ScreenAndroid::GetDisplayMatching(const gfx::Rect& match_rect) const { |
| 61 return GetPrimaryDisplay(); | 85 return GetPrimaryDisplay(); |
| 62 } | 86 } |
| 63 | 87 |
| 64 int GetNumDisplays() const override { return 1; } | 88 void ScreenAndroid::AddObserver(DisplayObserver* observer) { |
| 89 // no display change on Android. | |
| 90 } | |
| 65 | 91 |
| 66 std::vector<Display> GetAllDisplays() const override { | 92 void ScreenAndroid::RemoveObserver(DisplayObserver* observer) { |
| 67 return std::vector<Display>(1, GetPrimaryDisplay()); | 93 // no display change on Android. |
| 68 } | 94 } |
| 69 | |
| 70 Display GetDisplayMatching(const gfx::Rect& match_rect) const override { | |
| 71 return GetPrimaryDisplay(); | |
| 72 } | |
| 73 | |
| 74 void AddObserver(DisplayObserver* observer) override { | |
| 75 // no display change on Android. | |
| 76 } | |
| 77 | |
| 78 void RemoveObserver(DisplayObserver* observer) override { | |
| 79 // no display change on Android. | |
| 80 } | |
| 81 | |
| 82 private: | |
| 83 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); | |
| 84 }; | |
| 85 | 95 |
| 86 Screen* CreateNativeScreen() { | 96 Screen* CreateNativeScreen() { |
| 87 return new ScreenAndroid; | 97 return new ScreenAndroid; |
| 88 } | 98 } |
| 89 | 99 |
| 90 } // namespace display | 100 } // namespace display |
| OLD | NEW |