OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/extensions/api/system_display/display_info_provider.h" | 5 #include "chrome/browser/extensions/api/system_display/display_info_provider.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/common/extensions/api/system_display.h" |
8 #include "ui/gfx/display.h" | 9 #include "ui/gfx/display.h" |
9 #include "ui/gfx/screen.h" | 10 #include "ui/gfx/screen.h" |
10 | 11 |
11 namespace extensions { | 12 namespace extensions { |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
| 16 // Created on demand and will leak when the process exits. |
| 17 DisplayInfoProvider* g_display_info_provider = NULL; |
| 18 |
15 // Converts Rotation enum to integer. | 19 // Converts Rotation enum to integer. |
16 int RotationToDegrees(gfx::Display::Rotation rotation) { | 20 int RotationToDegrees(gfx::Display::Rotation rotation) { |
17 switch (rotation) { | 21 switch (rotation) { |
18 case gfx::Display::ROTATE_0: | 22 case gfx::Display::ROTATE_0: |
19 return 0; | 23 return 0; |
20 case gfx::Display::ROTATE_90: | 24 case gfx::Display::ROTATE_90: |
21 return 90; | 25 return 90; |
22 case gfx::Display::ROTATE_180: | 26 case gfx::Display::ROTATE_180: |
23 return 180; | 27 return 180; |
24 case gfx::Display::ROTATE_270: | 28 case gfx::Display::ROTATE_270: |
(...skipping 18 matching lines...) Expand all Loading... |
43 unit->bounds.top = bounds.y(); | 47 unit->bounds.top = bounds.y(); |
44 unit->bounds.width = bounds.width(); | 48 unit->bounds.width = bounds.width(); |
45 unit->bounds.height = bounds.height(); | 49 unit->bounds.height = bounds.height(); |
46 unit->work_area.left = work_area.x(); | 50 unit->work_area.left = work_area.x(); |
47 unit->work_area.top = work_area.y(); | 51 unit->work_area.top = work_area.y(); |
48 unit->work_area.width = work_area.width(); | 52 unit->work_area.width = work_area.width(); |
49 unit->work_area.height = work_area.height(); | 53 unit->work_area.height = work_area.height(); |
50 return unit; | 54 return unit; |
51 } | 55 } |
52 | 56 |
53 DisplayInfoProvider* g_display_info_provider = NULL; | |
54 | |
55 } // namespace | 57 } // namespace |
56 | 58 |
| 59 DisplayInfoProvider::~DisplayInfoProvider() { |
| 60 } |
57 | 61 |
58 DisplayInfoProvider::DisplayInfoProvider() {} | 62 // static |
59 | |
60 DisplayInfoProvider::~DisplayInfoProvider() {} | |
61 | |
62 DisplayInfoProvider* DisplayInfoProvider::Get() { | 63 DisplayInfoProvider* DisplayInfoProvider::Get() { |
63 if (g_display_info_provider == NULL) | 64 if (g_display_info_provider == NULL) |
64 g_display_info_provider = new DisplayInfoProvider(); | 65 g_display_info_provider = DisplayInfoProvider::Create(); |
65 return g_display_info_provider; | 66 return g_display_info_provider; |
66 } | 67 } |
67 | 68 |
| 69 // static |
68 void DisplayInfoProvider::InitializeForTesting( | 70 void DisplayInfoProvider::InitializeForTesting( |
69 DisplayInfoProvider* display_info_provider) { | 71 DisplayInfoProvider* display_info_provider) { |
70 DCHECK(display_info_provider); | 72 DCHECK(display_info_provider); |
71 g_display_info_provider = display_info_provider; | 73 g_display_info_provider = display_info_provider; |
72 } | 74 } |
73 | 75 |
74 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { | 76 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { |
75 // TODO(scottmg): Native is wrong http://crbug.com/133312 | 77 // TODO(scottmg): Native is wrong http://crbug.com/133312 |
76 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 78 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
77 int64 primary_id = screen->GetPrimaryDisplay().id(); | 79 int64 primary_id = screen->GetPrimaryDisplay().id(); |
78 std::vector<gfx::Display> displays = screen->GetAllDisplays(); | 80 std::vector<gfx::Display> displays = screen->GetAllDisplays(); |
79 DisplayInfo all_displays; | 81 DisplayInfo all_displays; |
80 for (int i = 0; i < screen->GetNumDisplays(); ++i) { | 82 for (int i = 0; i < screen->GetNumDisplays(); ++i) { |
81 linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( | 83 linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( |
82 CreateDisplayUnitInfo(displays[i], primary_id)); | 84 CreateDisplayUnitInfo(displays[i], primary_id)); |
83 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); | 85 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); |
84 all_displays.push_back(unit); | 86 all_displays.push_back(unit); |
85 } | 87 } |
86 return all_displays; | 88 return all_displays; |
87 } | 89 } |
88 | 90 |
| 91 DisplayInfoProvider::DisplayInfoProvider() { |
| 92 } |
| 93 |
89 } // namespace extensions | 94 } // namespace extensions |
OLD | NEW |