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 "extensions/browser/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 "ui/gfx/display.h" | 8 #include "ui/gfx/display.h" |
9 #include "ui/gfx/screen.h" | 9 #include "ui/gfx/screen.h" |
10 | 10 |
11 namespace extensions { | 11 namespace extensions { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Converts Rotation enum to integer. | 15 // Converts Rotation enum to integer. |
16 int RotationToDegrees(gfx::Display::Rotation rotation) { | 16 int RotationToDegrees(gfx::Display::Rotation rotation) { |
17 switch (rotation) { | 17 switch (rotation) { |
18 case gfx::Display::ROTATE_0: | 18 case gfx::Display::ROTATE_0: |
19 return 0; | 19 return 0; |
20 case gfx::Display::ROTATE_90: | 20 case gfx::Display::ROTATE_90: |
21 return 90; | 21 return 90; |
22 case gfx::Display::ROTATE_180: | 22 case gfx::Display::ROTATE_180: |
23 return 180; | 23 return 180; |
24 case gfx::Display::ROTATE_270: | 24 case gfx::Display::ROTATE_270: |
25 return 270; | 25 return 270; |
26 } | 26 } |
27 return 0; | 27 return 0; |
28 } | 28 } |
29 | 29 |
30 // Creates new DisplayUnitInfo struct for |display|. | 30 // Creates new DisplayUnitInfo struct for |display|. |
31 extensions::api::system_display::DisplayUnitInfo* | 31 extensions::core_api::system_display::DisplayUnitInfo* |
32 CreateDisplayUnitInfo(const gfx::Display& display, int64 primary_display_id) { | 32 CreateDisplayUnitInfo(const gfx::Display& display, int64 primary_display_id) { |
33 extensions::api::system_display::DisplayUnitInfo* unit = | 33 extensions::core_api::system_display::DisplayUnitInfo* unit = |
34 new extensions::api::system_display::DisplayUnitInfo(); | 34 new extensions::core_api::system_display::DisplayUnitInfo(); |
35 const gfx::Rect& bounds = display.bounds(); | 35 const gfx::Rect& bounds = display.bounds(); |
36 const gfx::Rect& work_area = display.work_area(); | 36 const gfx::Rect& work_area = display.work_area(); |
37 unit->id = base::Int64ToString(display.id()); | 37 unit->id = base::Int64ToString(display.id()); |
38 unit->is_primary = (display.id() == primary_display_id); | 38 unit->is_primary = (display.id() == primary_display_id); |
39 unit->is_internal = display.IsInternal(); | 39 unit->is_internal = display.IsInternal(); |
40 unit->is_enabled = true; | 40 unit->is_enabled = true; |
41 unit->rotation = RotationToDegrees(display.rotation()); | 41 unit->rotation = RotationToDegrees(display.rotation()); |
42 unit->bounds.left = bounds.x(); | 42 unit->bounds.left = bounds.x(); |
43 unit->bounds.top = bounds.y(); | 43 unit->bounds.top = bounds.y(); |
44 unit->bounds.width = bounds.width(); | 44 unit->bounds.width = bounds.width(); |
(...skipping 26 matching lines...) Expand all Loading... |
71 g_display_info_provider = display_info_provider; | 71 g_display_info_provider = display_info_provider; |
72 } | 72 } |
73 | 73 |
74 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { | 74 DisplayInfo DisplayInfoProvider::GetAllDisplaysInfo() { |
75 // TODO(scottmg): Native is wrong http://crbug.com/133312 | 75 // TODO(scottmg): Native is wrong http://crbug.com/133312 |
76 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 76 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
77 int64 primary_id = screen->GetPrimaryDisplay().id(); | 77 int64 primary_id = screen->GetPrimaryDisplay().id(); |
78 std::vector<gfx::Display> displays = screen->GetAllDisplays(); | 78 std::vector<gfx::Display> displays = screen->GetAllDisplays(); |
79 DisplayInfo all_displays; | 79 DisplayInfo all_displays; |
80 for (int i = 0; i < screen->GetNumDisplays(); ++i) { | 80 for (int i = 0; i < screen->GetNumDisplays(); ++i) { |
81 linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( | 81 linked_ptr<extensions::core_api::system_display::DisplayUnitInfo> unit( |
82 CreateDisplayUnitInfo(displays[i], primary_id)); | 82 CreateDisplayUnitInfo(displays[i], primary_id)); |
83 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); | 83 UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); |
84 all_displays.push_back(unit); | 84 all_displays.push_back(unit); |
85 } | 85 } |
86 return all_displays; | 86 return all_displays; |
87 } | 87 } |
88 | 88 |
89 } // namespace extensions | 89 } // namespace extensions |
OLD | NEW |