Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / screen_android.cc
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:
16   ScreenAndroid() {}
17
18   virtual gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
19
20   virtual gfx::NativeWindow GetWindowUnderCursor() override {
21     NOTIMPLEMENTED();
22     return NULL;
23   }
24
25   virtual gfx::NativeWindow GetWindowAtScreenPoint(const gfx::Point& point)
26       override {
27     NOTIMPLEMENTED();
28     return NULL;
29   }
30
31   virtual gfx::Display GetPrimaryDisplay() const override {
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 =
45         gfx::Rect(gfx::ToCeiledSize(gfx::ScaleSize(
46             bounds_in_pixels.size(), 1.0f / device_scale_factor)));
47     gfx::Display display(0, bounds_in_dip);
48     if (!gfx::Display::HasForceDeviceScaleFactor())
49       display.set_device_scale_factor(device_scale_factor);
50     display.SetRotationAsDegree(device_info.GetRotationDegrees());
51     return display;
52   }
53
54   virtual gfx::Display GetDisplayNearestWindow(
55       gfx::NativeView view) const override {
56     return GetPrimaryDisplay();
57   }
58
59   virtual gfx::Display GetDisplayNearestPoint(
60       const gfx::Point& point) const override {
61     return GetPrimaryDisplay();
62   }
63
64   virtual int GetNumDisplays() const override { return 1; }
65
66   virtual std::vector<gfx::Display> GetAllDisplays() const override {
67     return std::vector<gfx::Display>(1, GetPrimaryDisplay());
68   }
69
70   virtual gfx::Display GetDisplayMatching(
71       const gfx::Rect& match_rect) const override {
72     return GetPrimaryDisplay();
73   }
74
75   virtual void AddObserver(DisplayObserver* observer) override {
76     // no display change on Android.
77   }
78
79   virtual void RemoveObserver(DisplayObserver* observer) override {
80     // no display change on Android.
81   }
82
83  private:
84   DISALLOW_COPY_AND_ASSIGN(ScreenAndroid);
85 };
86
87 Screen* CreateNativeScreen() {
88   return new ScreenAndroid;
89 }
90
91 }  // namespace gfx