OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_info_display/display_info_provide
r.h" | 5 #include "chrome/browser/extensions/api/system_info_display/display_info_provide
r.h" |
6 | 6 |
7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/message_loop_proxy.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "content/public/browser/browser_thread.h" |
10 #include "ui/gfx/display.h" | 12 #include "ui/gfx/display.h" |
11 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
12 | 14 |
13 using ash::internal::DisplayManager; | 15 using ash::internal::DisplayManager; |
14 | 16 |
15 namespace extensions { | 17 namespace extensions { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 // TODO(hshi): determine the DPI of the screen. | 21 // TODO(hshi): determine the DPI of the screen. |
20 const float kDpi96 = 96.0; | 22 const float kDpi96 = 96.0; |
21 | 23 |
| 24 // Converts Rotation enum to integer. |
| 25 int RotationToDegrees(gfx::Display::Rotation rotation) { |
| 26 switch (rotation) { |
| 27 case gfx::Display::ROTATE_0: |
| 28 return 0; |
| 29 case gfx::Display::ROTATE_90: |
| 30 return 90; |
| 31 case gfx::Display::ROTATE_180: |
| 32 return 180; |
| 33 case gfx::Display::ROTATE_270: |
| 34 return 270; |
| 35 } |
| 36 return 0; |
| 37 } |
| 38 |
22 } // namespace | 39 } // namespace |
23 | 40 |
24 using api::system_info_display::Bounds; | 41 using api::system_info_display::Bounds; |
25 using api::system_info_display::DisplayUnitInfo; | 42 using api::system_info_display::DisplayUnitInfo; |
26 | 43 |
| 44 void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { |
| 45 DisplayInfo requested_info; |
| 46 bool success = QueryInfo(&requested_info); |
| 47 |
| 48 base::MessageLoopProxy::current()->PostTask( |
| 49 FROM_HERE, |
| 50 base::Bind(callback, requested_info, success)); |
| 51 } |
| 52 |
27 bool DisplayInfoProvider::QueryInfo(DisplayInfo* info) { | 53 bool DisplayInfoProvider::QueryInfo(DisplayInfo* info) { |
| 54 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
28 DCHECK(info); | 55 DCHECK(info); |
29 info->clear(); | 56 info->clear(); |
30 | 57 |
31 DisplayManager* display_manager = | 58 DisplayManager* display_manager = |
32 ash::Shell::GetInstance()->display_manager(); | 59 ash::Shell::GetInstance()->display_manager(); |
33 DCHECK(display_manager); | 60 DCHECK(display_manager); |
34 | 61 |
35 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 62 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
36 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 63 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
37 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); | 64 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); |
38 const gfx::Display* display = display_manager->GetDisplayAt(i); | 65 const gfx::Display* display = display_manager->GetDisplayAt(i); |
39 const gfx::Rect& bounds = display->bounds(); | 66 const gfx::Rect& bounds = display->bounds(); |
40 const gfx::Rect& work_area = display->work_area(); | 67 const gfx::Rect& work_area = display->work_area(); |
41 const float dpi = display->device_scale_factor() * kDpi96; | 68 const float dpi = display->device_scale_factor() * kDpi96; |
| 69 const gfx::Insets overscan_insets = |
| 70 display_manager->GetOverscanInsets(display->id()); |
| 71 |
42 unit->id = base::Int64ToString(display->id()); | 72 unit->id = base::Int64ToString(display->id()); |
43 unit->name = display_manager->GetDisplayNameForId(display->id()); | 73 unit->name = display_manager->GetDisplayNameForId(display->id()); |
44 unit->is_primary = (display->id() == primary_id); | 74 unit->is_primary = (display->id() == primary_id); |
| 75 if (display_manager->IsMirrored() && |
| 76 display_manager->mirrored_display().id() != display->id()) { |
| 77 unit->mirroring_source_id = |
| 78 base::Int64ToString(display_manager->mirrored_display().id()); |
| 79 } |
45 unit->is_internal = display->IsInternal(); | 80 unit->is_internal = display->IsInternal(); |
46 unit->is_enabled = true; | 81 unit->is_enabled = true; |
47 unit->dpi_x = dpi; | 82 unit->dpi_x = dpi; |
48 unit->dpi_y = dpi; | 83 unit->dpi_y = dpi; |
| 84 unit->rotation = RotationToDegrees(display->rotation()); |
49 unit->bounds.left = bounds.x(); | 85 unit->bounds.left = bounds.x(); |
50 unit->bounds.top = bounds.y(); | 86 unit->bounds.top = bounds.y(); |
51 unit->bounds.width = bounds.width(); | 87 unit->bounds.width = bounds.width(); |
52 unit->bounds.height = bounds.height(); | 88 unit->bounds.height = bounds.height(); |
| 89 unit->overscan.left = overscan_insets.left(); |
| 90 unit->overscan.top = overscan_insets.top(); |
| 91 unit->overscan.right = overscan_insets.right(); |
| 92 unit->overscan.bottom = overscan_insets.bottom(); |
53 unit->work_area.left = work_area.x(); | 93 unit->work_area.left = work_area.x(); |
54 unit->work_area.top = work_area.y(); | 94 unit->work_area.top = work_area.y(); |
55 unit->work_area.width = work_area.width(); | 95 unit->work_area.width = work_area.width(); |
56 unit->work_area.height = work_area.height(); | 96 unit->work_area.height = work_area.height(); |
57 info->push_back(unit); | 97 info->push_back(unit); |
58 } | 98 } |
59 | 99 |
60 return true; | 100 return true; |
61 } | 101 } |
62 | 102 |
63 } // namespace extensions | 103 } // namespace extensions |
OLD | NEW |