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

Side by Side Diff: ui/android/screen_android.cc

Issue 1144333004: Make WebView work for external displays (over Presentations). Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr to store DeviceDisplayInfo and make DeviceDisplayInfo getters const Created 5 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/gfx/screen.h" 5 #include "ui/gfx/screen.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/android/view_android.h"
9 #include "ui/android/window_android.h"
8 #include "ui/gfx/android/device_display_info.h" 10 #include "ui/gfx/android/device_display_info.h"
9 #include "ui/gfx/display.h" 11 #include "ui/gfx/display.h"
10 #include "ui/gfx/geometry/size_conversions.h" 12 #include "ui/gfx/geometry/size_conversions.h"
11 13
12 namespace gfx { 14 namespace gfx {
13 15
16 gfx::Display DisplayFromDeviceDisplayInfo(
17 const gfx::DeviceDisplayInfo & device_info) {
18 const float device_scale_factor = device_info.GetDIPScale();
19 // Note: GetPhysicalDisplayWidth/Height() does not subtract window
20 // decorations etc. Use it instead of GetDisplayWidth/Height() when
21 // available.
22 const gfx::Rect bounds_in_pixels =
23 gfx::Rect(device_info.GetPhysicalDisplayWidth()
24 ? device_info.GetPhysicalDisplayWidth()
25 : device_info.GetDisplayWidth(),
26 device_info.GetPhysicalDisplayHeight()
27 ? device_info.GetPhysicalDisplayHeight()
28 : device_info.GetDisplayHeight());
29 const gfx::Rect bounds_in_dip =
30 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
31 bounds_in_pixels.size(), 1.0f / device_scale_factor)));
32 gfx::Display display(0, bounds_in_dip);
33 if (!gfx::Display::HasForceDeviceScaleFactor())
34 display.set_device_scale_factor(device_scale_factor);
35 display.SetRotationAsDegree(device_info.GetRotationDegrees());
36 return display;
37 }
38
14 class ScreenAndroid : public Screen { 39 class ScreenAndroid : public Screen {
15 public: 40 public:
16 ScreenAndroid() {} 41 ScreenAndroid() {}
17 42
18 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); } 43 gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
19 44
20 gfx::NativeWindow GetWindowUnderCursor() override { 45 gfx::NativeWindow GetWindowUnderCursor() override {
21 NOTIMPLEMENTED(); 46 NOTIMPLEMENTED();
22 return NULL; 47 return NULL;
23 } 48 }
24 49
25 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override { 50 gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point) override {
26 NOTIMPLEMENTED(); 51 NOTIMPLEMENTED();
27 return NULL; 52 return NULL;
28 } 53 }
29 54
30 gfx::Display GetPrimaryDisplay() const override { 55 gfx::Display GetPrimaryDisplay() const override {
31 gfx::DeviceDisplayInfo device_info; 56 gfx::DeviceDisplayInfo device_info;
32 const float device_scale_factor = device_info.GetDIPScale(); 57 return DisplayFromDeviceDisplayInfo(device_info);
33 // Note: GetPhysicalDisplayWidth/Height() does not subtract window
34 // decorations etc. Use it instead of GetDisplayWidth/Height() when
35 // available.
36 const gfx::Rect bounds_in_pixels =
37 gfx::Rect(device_info.GetPhysicalDisplayWidth()
38 ? device_info.GetPhysicalDisplayWidth()
39 : device_info.GetDisplayWidth(),
40 device_info.GetPhysicalDisplayHeight()
41 ? device_info.GetPhysicalDisplayHeight()
42 : device_info.GetDisplayHeight());
43 const gfx::Rect bounds_in_dip =
44 gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
45 bounds_in_pixels.size(), 1.0f / device_scale_factor)));
46 gfx::Display display(0, bounds_in_dip);
47 if (!gfx::Display::HasForceDeviceScaleFactor())
48 display.set_device_scale_factor(device_scale_factor);
49 display.SetRotationAsDegree(device_info.GetRotationDegrees());
50 return display;
51 } 58 }
52 59
53 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override { 60 gfx::Display GetDisplayNearestWindow(gfx::NativeView view) const override {
54 return GetPrimaryDisplay(); 61 return DisplayFromDeviceDisplayInfo(
62 view->GetWindowAndroid()->GetDeviceDisplayInfo());
55 } 63 }
56 64
57 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override { 65 gfx::Display GetDisplayNearestPoint(const gfx::Point& point) const override {
58 return GetPrimaryDisplay(); 66 return GetPrimaryDisplay();
59 } 67 }
60 68
61 int GetNumDisplays() const override { return 1; } 69 int GetNumDisplays() const override { return 1; }
62 70
63 std::vector<gfx::Display> GetAllDisplays() const override { 71 std::vector<gfx::Display> GetAllDisplays() const override {
64 return std::vector<gfx::Display>(1, GetPrimaryDisplay()); 72 return std::vector<gfx::Display>(1, GetPrimaryDisplay());
(...skipping 13 matching lines...) Expand all
78 86
79 private: 87 private:
80 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid); 88 DISALLOW_COPY_AND_ASSIGN(ScreenAndroid);
81 }; 89 };
82 90
83 Screen* CreateNativeScreen() { 91 Screen* CreateNativeScreen() {
84 return new ScreenAndroid; 92 return new ScreenAndroid;
85 } 93 }
86 94
87 } // namespace gfx 95 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698