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