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 DisplayInfoProvider* g_display_info_provider = NULL; | |
James Cook
2014/08/20 19:57:59
nit: I presume this is leaked intentionally. If s
tmpsantos
2014/08/21 13:31:56
Done.
| |
17 | |
15 // Converts Rotation enum to integer. | 18 // Converts Rotation enum to integer. |
16 int RotationToDegrees(gfx::Display::Rotation rotation) { | 19 int RotationToDegrees(gfx::Display::Rotation rotation) { |
17 switch (rotation) { | 20 switch (rotation) { |
18 case gfx::Display::ROTATE_0: | 21 case gfx::Display::ROTATE_0: |
19 return 0; | 22 return 0; |
20 case gfx::Display::ROTATE_90: | 23 case gfx::Display::ROTATE_90: |
21 return 90; | 24 return 90; |
22 case gfx::Display::ROTATE_180: | 25 case gfx::Display::ROTATE_180: |
23 return 180; | 26 return 180; |
24 case gfx::Display::ROTATE_270: | 27 case gfx::Display::ROTATE_270: |
(...skipping 18 matching lines...) Expand all Loading... | |
43 unit->bounds.top = bounds.y(); | 46 unit->bounds.top = bounds.y(); |
44 unit->bounds.width = bounds.width(); | 47 unit->bounds.width = bounds.width(); |
45 unit->bounds.height = bounds.height(); | 48 unit->bounds.height = bounds.height(); |
46 unit->work_area.left = work_area.x(); | 49 unit->work_area.left = work_area.x(); |
47 unit->work_area.top = work_area.y(); | 50 unit->work_area.top = work_area.y(); |
48 unit->work_area.width = work_area.width(); | 51 unit->work_area.width = work_area.width(); |
49 unit->work_area.height = work_area.height(); | 52 unit->work_area.height = work_area.height(); |
50 return unit; | 53 return unit; |
51 } | 54 } |
52 | 55 |
53 DisplayInfoProvider* g_display_info_provider = NULL; | |
54 | |
55 } // namespace | 56 } // namespace |
56 | 57 |
58 DisplayInfoProvider::~DisplayInfoProvider() { | |
59 } | |
57 | 60 |
58 DisplayInfoProvider::DisplayInfoProvider() {} | 61 // static |
59 | |
60 DisplayInfoProvider::~DisplayInfoProvider() {} | |
61 | |
62 DisplayInfoProvider* DisplayInfoProvider::Get() { | 62 DisplayInfoProvider* DisplayInfoProvider::Get() { |
63 if (g_display_info_provider == NULL) | 63 if (g_display_info_provider == NULL) |
64 g_display_info_provider = new DisplayInfoProvider(); | 64 g_display_info_provider = DisplayInfoProvider::Create(); |
65 return g_display_info_provider; | 65 return g_display_info_provider; |
66 } | 66 } |
67 | 67 |
68 // static | |
68 void DisplayInfoProvider::InitializeForTesting( | 69 void DisplayInfoProvider::InitializeForTesting( |
69 DisplayInfoProvider* display_info_provider) { | 70 DisplayInfoProvider* display_info_provider) { |
70 DCHECK(display_info_provider); | 71 DCHECK(display_info_provider); |
71 g_display_info_provider = display_info_provider; | 72 g_display_info_provider = display_info_provider; |
72 } | 73 } |
73 | 74 |
74 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { | 75 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { |
75 // TODO(scottmg): Native is wrong http://crbug.com/133312 | 76 // TODO(scottmg): Native is wrong http://crbug.com/133312 |
76 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 77 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
77 int64 primary_id = screen->GetPrimaryDisplay().id(); | 78 int64 primary_id = screen->GetPrimaryDisplay().id(); |
78 std::vector<gfx::Display> displays = screen->GetAllDisplays(); | 79 std::vector<gfx::Display> displays = screen->GetAllDisplays(); |
79 DisplayInfo all_displays; | 80 DisplayInfo all_displays; |
80 for (int i = 0; i < screen->GetNumDisplays(); ++i) { | 81 for (int i = 0; i < screen->GetNumDisplays(); ++i) { |
81 linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( | 82 linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( |
82 CreateDisplayUnitInfo(displays[i], primary_id)); | 83 CreateDisplayUnitInfo(displays[i], primary_id)); |
83 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); | 84 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); |
84 all_displays.push_back(unit); | 85 all_displays.push_back(unit); |
85 } | 86 } |
86 return all_displays; | 87 return all_displays; |
87 } | 88 } |
88 | 89 |
90 DisplayInfoProvider::DisplayInfoProvider() { | |
91 } | |
92 | |
89 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |