diff options
Diffstat (limited to 'chrome/browser')
6 files changed, 121 insertions, 98 deletions
diff --git a/chrome/browser/extensions/api/system_display/display_info_provider.cc b/chrome/browser/extensions/api/system_display/display_info_provider.cc index e01bb72..064688d 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider.cc @@ -4,8 +4,56 @@ #include "chrome/browser/extensions/api/system_display/display_info_provider.h" +#include "base/strings/string_number_conversions.h" +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" + namespace extensions { +namespace { + +// Converts Rotation enum to integer. +int RotationToDegrees(gfx::Display::Rotation rotation) { + switch (rotation) { + case gfx::Display::ROTATE_0: + return 0; + case gfx::Display::ROTATE_90: + return 90; + case gfx::Display::ROTATE_180: + return 180; + case gfx::Display::ROTATE_270: + return 270; + } + return 0; +} + +// Creates new DisplayUnitInfo struct for |display| and adds it at the end of +// |list|. +extensions::api::system_display::DisplayUnitInfo* +CreateDisplayUnitInfo(const gfx::Display& display, + int64 primary_display_id) { + extensions::api::system_display::DisplayUnitInfo* unit = + new extensions::api::system_display::DisplayUnitInfo(); + const gfx::Rect& bounds = display.bounds(); + const gfx::Rect& work_area = display.work_area(); + unit->id = base::Int64ToString(display.id()); + unit->is_primary = (display.id() == primary_display_id); + unit->is_internal = display.IsInternal(); + unit->is_enabled = true; + unit->rotation = RotationToDegrees(display.rotation()); + unit->bounds.left = bounds.x(); + unit->bounds.top = bounds.y(); + unit->bounds.width = bounds.width(); + unit->bounds.height = bounds.height(); + unit->work_area.left = work_area.x(); + unit->work_area.top = work_area.y(); + unit->work_area.width = work_area.width(); + unit->work_area.height = work_area.height(); + return unit; +} + +} // namespace + DisplayInfoProvider::DisplayInfoProvider() { } @@ -26,6 +74,32 @@ void DisplayInfoProvider::InitializeForTesting( provider_.Get() = provider; } +void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { + bool success = QueryInfo(); + + base::MessageLoopProxy::current()->PostTask( + FROM_HERE, + base::Bind(callback, success)); +} + +#if !defined(OS_WIN) +bool DisplayInfoProvider::QueryInfo() { + info_.clear(); + + // TODO(scottmg): Native is wrong http://crbug.com/133312 + gfx::Screen* screen = gfx::Screen::GetNativeScreen(); + int64 primary_id = screen->GetPrimaryDisplay().id(); + std::vector<gfx::Display> displays = screen->GetAllDisplays(); + for (int i = 0; i < screen->GetNumDisplays(); ++i) { + linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( + CreateDisplayUnitInfo(displays[i], primary_id)); + UpdateDisplayUnitInfoForPlatform(displays[i], unit.get()); + info_.push_back(unit); + } + return true; +} +#endif + // static DisplayInfoProvider* DisplayInfoProvider::Get() { if (provider_.Get().get() == NULL) diff --git a/chrome/browser/extensions/api/system_display/display_info_provider.h b/chrome/browser/extensions/api/system_display/display_info_provider.h index ac9c654..65f94eb 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider.h +++ b/chrome/browser/extensions/api/system_display/display_info_provider.h @@ -11,6 +11,10 @@ #include "chrome/browser/extensions/api/system_info/system_info_provider.h" #include "chrome/common/extensions/api/system_display.h" +namespace gfx { +class Display; +} + namespace extensions { typedef std::vector<linked_ptr< @@ -65,6 +69,12 @@ class DisplayInfoProvider : public SystemInfoProvider { // The implementation is platform specific. virtual bool QueryInfo() OVERRIDE; + // Update the content of the |unit| obtained for |display| using + // platform specific method. + void UpdateDisplayUnitInfoForPlatform( + const gfx::Display& display, + extensions::api::system_display::DisplayUnitInfo* unit); + static base::LazyInstance<scoped_refptr<DisplayInfoProvider> > provider_; DISALLOW_COPY_AND_ASSIGN(DisplayInfoProvider); diff --git a/chrome/browser/extensions/api/system_display/display_info_provider_chromeos.cc b/chrome/browser/extensions/api/system_display/display_info_provider_chromeos.cc index 712bc528..dba99e0 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider_chromeos.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider_chromeos.cc @@ -35,21 +35,6 @@ bool IsValidRotationValue(int rotation) { return rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270; } -// Converts Rotation enum to integer. -int RotationToDegrees(gfx::Display::Rotation rotation) { - switch (rotation) { - case gfx::Display::ROTATE_0: - return 0; - case gfx::Display::ROTATE_90: - return 90; - case gfx::Display::ROTATE_180: - return 180; - case gfx::Display::ROTATE_270: - return 270; - } - return 0; -} - // Converts integer integer value in degrees to Rotation enum value. gfx::Display::Rotation DegreesToRotation(int degrees) { DCHECK(IsValidRotationValue(degrees)); @@ -67,48 +52,6 @@ gfx::Display::Rotation DegreesToRotation(int degrees) { } } -// Creates new DisplayUnitInfo struct for |display| and adds it at the end of -// |list|. -void AddInfoForDisplay(const gfx::Display& display, - DisplayManager* display_manager, - int64 primary_display_id, - DisplayInfo* list) { - linked_ptr<extensions::api::system_display::DisplayUnitInfo> unit( - new extensions::api::system_display::DisplayUnitInfo()); - const gfx::Rect& bounds = display.bounds(); - const gfx::Rect& work_area = display.work_area(); - const float dpi = display.device_scale_factor() * kDpi96; - const gfx::Insets overscan_insets = - display_manager->GetOverscanInsets(display.id()); - - unit->id = base::Int64ToString(display.id()); - unit->name = display_manager->GetDisplayNameForId(display.id()); - unit->is_primary = (display.id() == primary_display_id); - unit->is_internal = display.IsInternal(); - unit->is_enabled = true; - if (display_manager->IsMirrored()) { - unit->mirroring_source_id = - base::Int64ToString(display_manager->mirrored_display().id()); - } - unit->dpi_x = dpi; - unit->dpi_y = dpi; - unit->rotation = RotationToDegrees(display.rotation()); - unit->bounds.left = bounds.x(); - unit->bounds.top = bounds.y(); - unit->bounds.width = bounds.width(); - unit->bounds.height = bounds.height(); - unit->overscan.left = overscan_insets.left(); - unit->overscan.top = overscan_insets.top(); - unit->overscan.right = overscan_insets.right(); - unit->overscan.bottom = overscan_insets.bottom(); - unit->work_area.left = work_area.x(); - unit->work_area.top = work_area.y(); - unit->work_area.width = work_area.width(); - unit->work_area.height = work_area.height(); - - list->push_back(unit); -} - // Checks if the given point is over the radius vector described by it's end // point |vector|. The point is over a vector if it's on its positive (left) // side. The method sees a point on the same line as the vector as being over @@ -359,7 +302,9 @@ bool SetInfoImpl(const std::string& display_id_str, } int64 display_id = target.id(); - const gfx::Display& primary = ash::Shell::GetScreen()->GetPrimaryDisplay(); + // TODO(scottmg): Native is wrong http://crbug.com/133312 + const gfx::Display& primary = + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(), error)) { @@ -410,14 +355,6 @@ bool SetInfoImpl(const std::string& display_id_str, } // namespace -void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { - bool success = QueryInfo(); - - base::MessageLoopProxy::current()->PostTask( - FROM_HERE, - base::Bind(callback, success)); -} - void DisplayInfoProvider::SetInfo(const std::string& display_id, const DisplayProperties& info, const SetInfoCallback& callback) { @@ -428,20 +365,28 @@ void DisplayInfoProvider::SetInfo(const std::string& display_id, base::Bind(callback, success, error)); } -bool DisplayInfoProvider::QueryInfo() { - info_.clear(); +void DisplayInfoProvider::UpdateDisplayUnitInfoForPlatform( + const gfx::Display& display, + extensions::api::system_display::DisplayUnitInfo* unit) { - DisplayManager* display_manager = - ash::Shell::GetInstance()->display_manager(); - DCHECK(display_manager); - - int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { - AddInfoForDisplay(display_manager->GetDisplayAt(i), display_manager, - primary_id, &info_); + ash::internal::DisplayManager* display_manager + = ash::Shell::GetInstance()->display_manager(); + unit->name = display_manager->GetDisplayNameForId(display.id()); + if (display_manager->IsMirrored()) { + unit->mirroring_source_id = + base::Int64ToString(display_manager->mirrored_display().id()); } - return true; + const float dpi = display.device_scale_factor() * kDpi96; + unit->dpi_x = dpi; + unit->dpi_y = dpi; + + const gfx::Insets overscan_insets = + display_manager->GetOverscanInsets(display.id()); + unit->overscan.left = overscan_insets.left(); + unit->overscan.top = overscan_insets.top(); + unit->overscan.right = overscan_insets.right(); + unit->overscan.bottom = overscan_insets.bottom(); } } // namespace extensions diff --git a/chrome/browser/extensions/api/system_display/display_info_provider_mac.cc b/chrome/browser/extensions/api/system_display/display_info_provider_mac.cc index 2b22e1e..3776bf9 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider_mac.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider_mac.cc @@ -6,11 +6,6 @@ namespace extensions { -void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { - // Redirect the request to a worker pool thread. - StartQueryInfo(callback); -} - void DisplayInfoProvider::SetInfo( const std::string& display_id, const api::system_display::DisplayProperties& info, @@ -20,9 +15,10 @@ void DisplayInfoProvider::SetInfo( base::Bind(callback, false, "Not implemented")); } -// TODO(hongbo): implement display info querying on Mac OS X. -bool DisplayInfoProvider::QueryInfo() { - return false; +void DisplayInfoProvider::UpdateDisplayUnitInfoForPlatform( + const gfx::Display& display, + extensions::api::system_display::DisplayUnitInfo* unit) { + NOTIMPLEMENTED(); } } // namespace extensions diff --git a/chrome/browser/extensions/api/system_display/display_info_provider_win.cc b/chrome/browser/extensions/api/system_display/display_info_provider_win.cc index 9d21278..846d777 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider_win.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider_win.cc @@ -67,11 +67,6 @@ BOOL CALLBACK EnumMonitorCallback(HMONITOR monitor, } // namespace -void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { - // Redirect the request to a worker pool thread. - StartQueryInfo(callback); -} - void DisplayInfoProvider::SetInfo( const std::string& display_id, const api::system_display::DisplayProperties& info, @@ -81,6 +76,7 @@ void DisplayInfoProvider::SetInfo( base::Bind(callback, false, "Not implemented")); } +// TODO(hongbo): consolidate implementation using gfx::Display/gfx::Screen. bool DisplayInfoProvider::QueryInfo() { info_.clear(); @@ -90,4 +86,10 @@ bool DisplayInfoProvider::QueryInfo() { return false; } +void DisplayInfoProvider::UpdateDisplayUnitInfoForPlatform( + const gfx::Display& display, + extensions::api::system_display::DisplayUnitInfo* unit) { + NOTIMPLEMENTED(); +} + } // namespace extensions diff --git a/chrome/browser/extensions/api/system_display/display_info_provider_x11.cc b/chrome/browser/extensions/api/system_display/display_info_provider_x11.cc index adfdb14..3776bf9 100644 --- a/chrome/browser/extensions/api/system_display/display_info_provider_x11.cc +++ b/chrome/browser/extensions/api/system_display/display_info_provider_x11.cc @@ -6,11 +6,6 @@ namespace extensions { -void DisplayInfoProvider::RequestInfo(const RequestInfoCallback& callback) { - // Redirect the request to a worker pool thread. - StartQueryInfo(callback); -} - void DisplayInfoProvider::SetInfo( const std::string& display_id, const api::system_display::DisplayProperties& info, @@ -20,9 +15,10 @@ void DisplayInfoProvider::SetInfo( base::Bind(callback, false, "Not implemented")); } -// TODO(hongbo): implement X11 display info querying. -bool DisplayInfoProvider::QueryInfo() { - return false; +void DisplayInfoProvider::UpdateDisplayUnitInfoForPlatform( + const gfx::Display& display, + extensions::api::system_display::DisplayUnitInfo* unit) { + NOTIMPLEMENTED(); } } // namespace extensions |