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; |
23 const int kBaseRotation = 90; | |
21 | 24 |
22 } // namespace | 25 } // namespace |
23 | 26 |
24 using api::system_info_display::Bounds; | 27 using api::system_info_display::Bounds; |
25 using api::system_info_display::DisplayUnitInfo; | 28 using api::system_info_display::DisplayUnitInfo; |
26 | 29 |
30 void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { | |
31 DisplayInfo requested_info; | |
32 bool success = QueryInfo(&requested_info); | |
33 | |
34 base::MessageLoopProxy::current()->PostTask( | |
35 FROM_HERE, | |
36 base::Bind(callback, requested_info, success)); | |
37 } | |
38 | |
27 bool DisplayInfoProvider::QueryInfo(DisplayInfo* info) { | 39 bool DisplayInfoProvider::QueryInfo(DisplayInfo* info) { |
40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
28 DCHECK(info); | 41 DCHECK(info); |
29 info->clear(); | 42 info->clear(); |
30 | 43 |
31 DisplayManager* display_manager = | 44 DisplayManager* display_manager = |
32 ash::Shell::GetInstance()->display_manager(); | 45 ash::Shell::GetInstance()->display_manager(); |
33 DCHECK(display_manager); | 46 DCHECK(display_manager); |
34 | 47 |
35 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 48 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
36 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 49 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
37 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); | 50 linked_ptr<DisplayUnitInfo> unit(new DisplayUnitInfo()); |
38 const gfx::Display* display = display_manager->GetDisplayAt(i); | 51 const gfx::Display* display = display_manager->GetDisplayAt(i); |
39 const gfx::Rect& bounds = display->bounds(); | 52 const gfx::Rect& bounds = display->bounds(); |
40 const gfx::Rect& work_area = display->work_area(); | 53 const gfx::Rect& work_area = display->work_area(); |
41 const float dpi = display->device_scale_factor() * kDpi96; | 54 const float dpi = display->device_scale_factor() * kDpi96; |
55 const gfx::Insets overscan_insets = | |
56 display_manager->GetOverscanInsets(display->id()); | |
57 | |
42 unit->id = base::Int64ToString(display->id()); | 58 unit->id = base::Int64ToString(display->id()); |
43 unit->name = display_manager->GetDisplayNameForId(display->id()); | 59 unit->name = display_manager->GetDisplayNameForId(display->id()); |
44 unit->is_primary = (display->id() == primary_id); | 60 unit->is_primary = (display->id() == primary_id); |
61 if (display_manager->IsMirrored() && | |
62 display_manager->mirrored_display().id() != display->id()) { | |
63 unit->mirroring_source_id = | |
64 base::Int64ToString(display_manager->mirrored_display().id()); | |
65 } | |
45 unit->is_internal = display->IsInternal(); | 66 unit->is_internal = display->IsInternal(); |
46 unit->is_enabled = true; | 67 unit->is_enabled = true; |
47 unit->dpi_x = dpi; | 68 unit->dpi_x = dpi; |
48 unit->dpi_y = dpi; | 69 unit->dpi_y = dpi; |
70 unit->rotation = static_cast<int>(display->rotation()) * kBaseRotation; | |
Greg Spencer (Chromium)
2013/06/10 19:17:42
Should this be "% 360"? Just to prevent invalid v
tbarzic
2013/06/10 19:53:51
I think it is safe to assume rotation returned fro
| |
49 unit->bounds.left = bounds.x(); | 71 unit->bounds.left = bounds.x(); |
50 unit->bounds.top = bounds.y(); | 72 unit->bounds.top = bounds.y(); |
51 unit->bounds.width = bounds.width(); | 73 unit->bounds.width = bounds.width(); |
52 unit->bounds.height = bounds.height(); | 74 unit->bounds.height = bounds.height(); |
75 unit->visible_area.left = overscan_insets.left(); | |
76 unit->visible_area.top = overscan_insets.top(); | |
77 unit->visible_area.width = bounds.width(); | |
78 unit->visible_area.height = bounds.height(); | |
53 unit->work_area.left = work_area.x(); | 79 unit->work_area.left = work_area.x(); |
54 unit->work_area.top = work_area.y(); | 80 unit->work_area.top = work_area.y(); |
55 unit->work_area.width = work_area.width(); | 81 unit->work_area.width = work_area.width(); |
56 unit->work_area.height = work_area.height(); | 82 unit->work_area.height = work_area.height(); |
57 info->push_back(unit); | 83 info->push_back(unit); |
58 } | 84 } |
59 | 85 |
60 return true; | 86 return true; |
61 } | 87 } |
62 | 88 |
63 } // namespace extensions | 89 } // namespace extensions |
OLD | NEW |