Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: ui/display/manager/display_manager_utilities.cc

Issue 2286523002: Relocate reuseable portions of ash/display/display_util.* (Closed)
Patch Set: fixed ozone build Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/display/manager/display_manager_utilities.cc
diff --git a/ash/display/display_util.cc b/ui/display/manager/display_manager_utilities.cc
similarity index 54%
copy from ash/display/display_util.cc
copy to ui/display/manager/display_manager_utilities.cc
index 2c4b167b99629f52f8e8ed589dd843d31be32b57..ce486a1e5ab42606f75496c9788b8d88237cef7e 100644
--- a/ash/display/display_util.cc
+++ b/ui/display/manager/display_manager_utilities.cc
@@ -1,64 +1,21 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "ash/display/display_util.h"
+#include "ui/display/manager/display_manager_utilities.h"
#include <algorithm>
+#include <vector>
-#include "ash/common/new_window_delegate.h"
-#include "ash/common/system/system_notifier.h"
-#include "ash/common/wm_shell.h"
-#include "ash/display/display_manager.h"
-#include "ash/host/ash_window_tree_host.h"
-#include "ash/shell.h"
-#include "base/strings/string_number_conversions.h"
-#include "grit/ash_resources.h"
-#include "ui/aura/env.h"
-#include "ui/aura/window_tree_host.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/display/display.h"
+#include "base/sys_info.h"
#include "ui/display/manager/managed_display_info.h"
-#include "ui/gfx/geometry/point.h"
-#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/message_center/message_center.h"
-#include "ui/message_center/notification.h"
-#include "ui/message_center/notification_delegate.h"
-#include "ui/message_center/notification_list.h"
-#include "ui/wm/core/coordinate_conversion.h"
+#include "ui/gfx/geometry/size_f.h"
-#if defined(OS_CHROMEOS)
-#include "base/sys_info.h"
-#endif
+namespace display {
-namespace ash {
namespace {
-const char kDisplayErrorNotificationId[] = "chrome://settings/display/error";
-
-// A notification delegate that will start the feedback app when the notication
-// is clicked.
-class DisplayErrorNotificationDelegate
- : public message_center::NotificationDelegate {
- public:
- DisplayErrorNotificationDelegate() = default;
-
- // message_center::NotificationDelegate:
- bool HasClickedListener() override { return true; }
-
- void Click() override {
- WmShell::Get()->new_window_delegate()->OpenFeedbackPage();
- }
-
- private:
- // Private destructor since NotificationDelegate is ref-counted.
- ~DisplayErrorNotificationDelegate() override = default;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate);
-};
-
// List of value UI Scale values. Scales for 2x are equivalent to 640,
// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on
// 2560 pixel width 2x density display. Please see crbug.com/233375
@@ -109,27 +66,6 @@ struct ScaleComparator {
float scale;
};
-void ConvertPointFromScreenToNative(aura::WindowTreeHost* host,
- gfx::Point* point) {
- ::wm::ConvertPointFromScreen(host->window(), point);
- host->ConvertPointToNativeScreen(point);
-}
-
-scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForUIScale(
- const display::ManagedDisplayInfo& info,
- float ui_scale) {
- const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
- info.display_modes();
- auto iter = std::find_if(
- modes.begin(), modes.end(),
- [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) {
- return mode->ui_scale() == ui_scale;
- });
- if (iter == modes.end())
- return scoped_refptr<display::ManagedDisplayMode>();
- return *iter;
-}
-
scoped_refptr<display::ManagedDisplayMode> FindNextMode(
const display::ManagedDisplayInfo::ManagedDisplayModeList& modes,
size_t index,
@@ -154,11 +90,10 @@ CreateInternalManagedDisplayModeList(
? 1.0f
: native_mode->device_scale_factor();
for (float ui_scale : GetScalesForDisplay(native_mode)) {
- scoped_refptr<display::ManagedDisplayMode> mode(
- new display::ManagedDisplayMode(
- native_mode->size(), native_mode->refresh_rate(),
- native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
- native_mode->device_scale_factor()));
+ scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode(
+ native_mode->size(), native_mode->refresh_rate(),
+ native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
+ native_mode->device_scale_factor()));
display_mode_list.push_back(mode);
}
return display_mode_list;
@@ -217,12 +152,7 @@ scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForResolution(
scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextUIScale(
const display::ManagedDisplayInfo& info,
bool up) {
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- if (!display_manager->IsActiveDisplayId(info.id()) ||
- !display::Display::IsInternalDisplayId(info.id())) {
- return scoped_refptr<display::ManagedDisplayMode>();
- }
- const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
+ const ManagedDisplayInfo::ManagedDisplayModeList& modes =
info.display_modes();
ScaleComparator comparator(info.configured_ui_scale());
auto iter = std::find_if(modes.begin(), modes.end(), comparator);
@@ -250,23 +180,7 @@ scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForNextResolution(
return FindNextMode(modes, iter - modes.begin(), up);
}
-bool SetDisplayUIScale(int64_t id, float ui_scale) {
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- if (!display_manager->IsActiveDisplayId(id) ||
- !display::Display::IsInternalDisplayId(id)) {
- return false;
- }
- const display::ManagedDisplayInfo& info = display_manager->GetDisplayInfo(id);
-
- scoped_refptr<display::ManagedDisplayMode> mode =
- GetDisplayModeForUIScale(info, ui_scale);
- if (!mode)
- return false;
- return display_manager->SetDisplayMode(id, mode);
-}
-
-bool HasDisplayModeForUIScale(const display::ManagedDisplayInfo& info,
- float ui_scale) {
+bool HasDisplayModeForUIScale(const ManagedDisplayInfo& info, float ui_scale) {
ScaleComparator comparator(ui_scale);
const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
info.display_modes();
@@ -339,83 +253,6 @@ bool ComputeBoundary(const display::Display& a_display,
return true;
}
-gfx::Rect GetNativeEdgeBounds(AshWindowTreeHost* ash_host,
- const gfx::Rect& bounds_in_screen) {
- aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
- gfx::Rect native_bounds = host->GetBounds();
- native_bounds.Inset(ash_host->GetHostInsets());
- gfx::Point start_in_native = bounds_in_screen.origin();
- gfx::Point end_in_native = bounds_in_screen.bottom_right();
-
- ConvertPointFromScreenToNative(host, &start_in_native);
- ConvertPointFromScreenToNative(host, &end_in_native);
-
- if (std::abs(start_in_native.x() - end_in_native.x()) <
- std::abs(start_in_native.y() - end_in_native.y())) {
- // vertical in native
- int x = std::abs(native_bounds.x() - start_in_native.x()) <
- std::abs(native_bounds.right() - start_in_native.x())
- ? native_bounds.x()
- : native_bounds.right() - 1;
- return gfx::Rect(x, std::min(start_in_native.y(), end_in_native.y()), 1,
- std::abs(end_in_native.y() - start_in_native.y()));
- } else {
- // horizontal in native
- int y = std::abs(native_bounds.y() - start_in_native.y()) <
- std::abs(native_bounds.bottom() - start_in_native.y())
- ? native_bounds.y()
- : native_bounds.bottom() - 1;
- return gfx::Rect(std::min(start_in_native.x(), end_in_native.x()), y,
- std::abs(end_in_native.x() - start_in_native.x()), 1);
- }
-}
-
-// Moves the cursor to the point inside the root that is closest to
-// the point_in_screen, which is outside of the root window.
-void MoveCursorTo(AshWindowTreeHost* ash_host,
- const gfx::Point& point_in_screen,
- bool update_last_location_now) {
- aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
- gfx::Point point_in_native = point_in_screen;
- ::wm::ConvertPointFromScreen(host->window(), &point_in_native);
- host->ConvertPointToNativeScreen(&point_in_native);
-
- // now fit the point inside the native bounds.
- gfx::Rect native_bounds = host->GetBounds();
- gfx::Point native_origin = native_bounds.origin();
- native_bounds.Inset(ash_host->GetHostInsets());
- // Shrink further so that the mouse doesn't warp on the
- // edge. The right/bottom needs to be shrink by 2 to subtract
- // the 1 px from width/height value.
- native_bounds.Inset(1, 1, 2, 2);
-
- // Ensure that |point_in_native| is inside the |native_bounds|.
- point_in_native.SetToMax(native_bounds.origin());
- point_in_native.SetToMin(native_bounds.bottom_right());
-
- gfx::Point point_in_host = point_in_native;
-
- point_in_host.Offset(-native_origin.x(), -native_origin.y());
- host->MoveCursorToHostLocation(point_in_host);
-
- if (update_last_location_now) {
- gfx::Point new_point_in_screen;
- if (Shell::GetInstance()->display_manager()->IsInUnifiedMode()) {
- new_point_in_screen = point_in_host;
- // First convert to the unified host.
- host->ConvertPointFromHost(&new_point_in_screen);
- // Then convert to the unified screen.
- Shell::GetPrimaryRootWindow()->GetHost()->ConvertPointFromHost(
- &new_point_in_screen);
- } else {
- new_point_in_screen = point_in_native;
- host->ConvertPointFromNativeScreen(&new_point_in_screen);
- ::wm::ConvertPointToScreen(host->window(), &new_point_in_screen);
- }
- aura::Env::GetInstance()->set_last_mouse_location(new_point_in_screen);
- }
-}
-
int FindDisplayIndexContainingPoint(
const std::vector<display::Display>& displays,
const gfx::Point& point_in_screen) {
@@ -458,39 +295,4 @@ bool CompareDisplayIds(int64_t id1, int64_t id2) {
(index_1 < index_2 && !display::Display::IsInternalDisplayId(id2));
}
-#if defined(OS_CHROMEOS)
-void ShowDisplayErrorNotification(int message_id) {
- // Always remove the notification to make sure the notification appears
- // as a popup in any situation.
- message_center::MessageCenter::Get()->RemoveNotification(
- kDisplayErrorNotificationId, false /* by_user */);
-
- ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
- std::unique_ptr<message_center::Notification> notification(
- new message_center::Notification(
- message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId,
- base::string16(), // title
- l10n_util::GetStringUTF16(message_id),
- bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
- base::string16(), // display_source
- GURL(), message_center::NotifierId(
- message_center::NotifierId::SYSTEM_COMPONENT,
- system_notifier::kNotifierDisplayError),
- message_center::RichNotificationData(),
- new DisplayErrorNotificationDelegate));
- message_center::MessageCenter::Get()->AddNotification(
- std::move(notification));
-}
-#endif
-
-base::string16 GetDisplayErrorNotificationMessageForTest() {
- message_center::NotificationList::Notifications notifications =
- message_center::MessageCenter::Get()->GetVisibleNotifications();
- for (auto* const notification : notifications) {
- if (notification->id() == kDisplayErrorNotificationId)
- return notification->message();
- }
- return base::string16();
-}
-
-} // namespace ash
+} // namespace display
« no previous file with comments | « ui/display/manager/display_manager_utilities.h ('k') | ui/display/manager/display_manager_utilities_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698