• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "ui/gfx/screen.h"
6 
7 #include "base/logging.h"
8 #include "ui/gfx/android/device_display_info.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/size_conversions.h"
11 
12 namespace gfx {
13 
14 class ScreenAndroid : public Screen {
15  public:
ScreenAndroid()16   ScreenAndroid() {}
17 
IsDIPEnabled()18   virtual bool IsDIPEnabled() OVERRIDE { return true; }
19 
GetCursorScreenPoint()20   virtual gfx::Point GetCursorScreenPoint() OVERRIDE { return gfx::Point(); }
21 
GetWindowUnderCursor()22   virtual gfx::NativeWindow GetWindowUnderCursor() OVERRIDE {
23     NOTIMPLEMENTED();
24     return NULL;
25   }
26 
GetWindowAtScreenPoint(const gfx::Point & point)27   virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
28       OVERRIDE {
29     NOTIMPLEMENTED();
30     return NULL;
31   }
32 
GetPrimaryDisplay() const33   virtual gfx::Display GetPrimaryDisplay() const OVERRIDE {
34     gfx::DeviceDisplayInfo device_info;
35     const float device_scale_factor = device_info.GetDIPScale();
36     // Note: GetPhysicalDisplayWidth/Height() does not subtract window
37     // decorations etc. Use it instead of GetDisplayWidth/Height() when
38     // available.
39     const gfx::Rect bounds_in_pixels =
40         gfx::Rect(device_info.GetPhysicalDisplayWidth()
41                       ? device_info.GetPhysicalDisplayWidth()
42                       : device_info.GetDisplayWidth(),
43                   device_info.GetPhysicalDisplayHeight()
44                       ? device_info.GetPhysicalDisplayHeight()
45                       : device_info.GetDisplayHeight());
46     const gfx::Rect bounds_in_dip =
47         gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
48             bounds_in_pixels.size(), 1.0f / device_scale_factor)));
49     gfx::Display display(0, bounds_in_dip);
50     if (!gfx::Display::HasForceDeviceScaleFactor())
51       display.set_device_scale_factor(device_scale_factor);
52     display.SetRotationAsDegree(device_info.GetRotationDegrees());
53     return display;
54   }
55 
GetDisplayNearestWindow(gfx::NativeView view) const56   virtual gfx::Display GetDisplayNearestWindow(
57       gfx::NativeView view) const OVERRIDE {
58     return GetPrimaryDisplay();
59   }
60 
GetDisplayNearestPoint(const gfx::Point & point) const61   virtual gfx::Display GetDisplayNearestPoint(
62       const gfx::Point& point) const OVERRIDE {
63     return GetPrimaryDisplay();
64   }
65 
GetNumDisplays() const66   virtual int GetNumDisplays() const OVERRIDE { return 1; }
67 
GetAllDisplays() const68   virtual std::vector<gfx::Display> GetAllDisplays() const OVERRIDE {
69     return std::vector<gfx::Display>(1, GetPrimaryDisplay());
70   }
71 
GetDisplayMatching(const gfx::Rect & match_rect) const72   virtual gfx::Display GetDisplayMatching(
73       const gfx::Rect& match_rect) const OVERRIDE {
74     return GetPrimaryDisplay();
75   }
76 
AddObserver(DisplayObserver * observer)77   virtual void AddObserver(DisplayObserver* observer) OVERRIDE {
78     // no display change on Android.
79   }
80 
RemoveObserver(DisplayObserver * observer)81   virtual void RemoveObserver(DisplayObserver* observer) OVERRIDE {
82     // no display change on Android.
83   }
84 
85  private:
86   DISALLOW_COPY_AND_ASSIGN(ScreenAndroid);
87 };
88 
CreateNativeScreen()89 Screen* CreateNativeScreen() {
90   return new ScreenAndroid;
91 }
92 
93 }  // namespace gfx
94