summaryrefslogtreecommitdiffstats
path: root/ash/display
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 21:51:44 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-27 21:51:44 +0000
commite72fa4d643005f438978d8a9c21272f3acd64061 (patch)
treefabd135523ba0954c3c6b861dd21c5e165512580 /ash/display
parentf33386d952654acfad4f62029ece49f0e7ecb200 (diff)
downloadchromium_src-e72fa4d643005f438978d8a9c21272f3acd64061.zip
chromium_src-e72fa4d643005f438978d8a9c21272f3acd64061.tar.gz
chromium_src-e72fa4d643005f438978d8a9c21272f3acd64061.tar.bz2
Revert r 144499 "Rename the remaining usage of Monitor to Display"
Temporarily reverting rename change to investigate 133784 TBR=oshima@chromium.org BUG=123160 TEST=none Review URL: https://chromiumcodereview.appspot.com/10689014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display')
-rw-r--r--ash/display/display_controller.cc269
-rw-r--r--ash/display/display_controller.h109
-rw-r--r--ash/display/mouse_cursor_event_filter.cc53
-rw-r--r--ash/display/mouse_cursor_event_filter.h44
-rw-r--r--ash/display/multi_display_manager.cc247
-rw-r--r--ash/display/multi_display_manager.h84
-rw-r--r--ash/display/multi_display_manager_unittest.cc235
-rw-r--r--ash/display/secondary_display_view.cc111
-rw-r--r--ash/display/secondary_display_view.h25
9 files changed, 0 insertions, 1177 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
deleted file mode 100644
index 895532a..0000000
--- a/ash/display/display_controller.cc
+++ /dev/null
@@ -1,269 +0,0 @@
-// Copyright (c) 2012 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_controller.h"
-
-#include "ash/ash_switches.h"
-#include "ash/display/multi_display_manager.h"
-#include "ash/root_window_controller.h"
-#include "ash/shell.h"
-#include "ash/wm/window_util.h"
-#include "base/command_line.h"
-#include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/window.h"
-#include "ui/gfx/display.h"
-#include "ui/gfx/screen.h"
-
-namespace ash {
-namespace internal {
-namespace {
-// True if the extended desktop mode is enabled.
-bool extended_desktop_enabled = false;
-
-// True if the virtual screen coordinates is enabled.
-bool virtual_screen_coordinates_enabled = false;
-}
-
-DisplayController::DisplayController()
- : secondary_display_layout_(RIGHT) {
- aura::Env::GetInstance()->display_manager()->AddObserver(this);
-}
-
-DisplayController::~DisplayController() {
- aura::Env::GetInstance()->display_manager()->RemoveObserver(this);
- // Delete all root window controllers, which deletes root window
- // from the last so that the primary root window gets deleted last.
- for (std::map<int, aura::RootWindow*>::const_reverse_iterator it =
- root_windows_.rbegin(); it != root_windows_.rend(); ++it) {
- internal::RootWindowController* controller =
- wm::GetRootWindowController(it->second);
- // RootWindow may not have RootWindowController in non
- // extended desktop mode.
- if (controller)
- delete controller;
- else
- delete it->second;
- }
-}
-
-void DisplayController::InitPrimaryDisplay() {
- aura::DisplayManager* display_manager =
- aura::Env::GetInstance()->display_manager();
- const gfx::Display& display = display_manager->GetDisplayAt(0);
- DCHECK_EQ(0, display.id());
- aura::RootWindow* root = AddRootWindowForDisplay(display);
- root->SetHostBounds(display.bounds_in_pixel());
-}
-
-void DisplayController::InitSecondaryDisplays() {
- aura::DisplayManager* display_manager =
- aura::Env::GetInstance()->display_manager();
- for (size_t i = 1; i < display_manager->GetNumDisplays(); ++i) {
- const gfx::Display& display = display_manager->GetDisplayAt(i);
- aura::RootWindow* root = AddRootWindowForDisplay(display);
- Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
- }
-}
-
-aura::RootWindow* DisplayController::GetPrimaryRootWindow() {
- DCHECK(!root_windows_.empty());
- return root_windows_[0];
-}
-
-void DisplayController::CloseChildWindows() {
- for (std::map<int, aura::RootWindow*>::const_iterator it =
- root_windows_.begin(); it != root_windows_.end(); ++it) {
- aura::RootWindow* root_window = it->second;
- internal::RootWindowController* controller =
- wm::GetRootWindowController(root_window);
- if (controller) {
- controller->CloseChildWindows();
- } else {
- while (!root_window->children().empty()) {
- aura::Window* child = root_window->children()[0];
- delete child;
- }
- }
- }
-}
-
-std::vector<aura::RootWindow*> DisplayController::GetAllRootWindows() {
- std::vector<aura::RootWindow*> windows;
- for (std::map<int, aura::RootWindow*>::const_iterator it =
- root_windows_.begin(); it != root_windows_.end(); ++it) {
- DCHECK(it->second);
- if (wm::GetRootWindowController(it->second))
- windows.push_back(it->second);
- }
- return windows;
-}
-
-std::vector<internal::RootWindowController*>
-DisplayController::GetAllRootWindowControllers() {
- std::vector<internal::RootWindowController*> controllers;
- for (std::map<int, aura::RootWindow*>::const_iterator it =
- root_windows_.begin(); it != root_windows_.end(); ++it) {
- internal::RootWindowController* controller =
- wm::GetRootWindowController(it->second);
- if (controller)
- controllers.push_back(controller);
- }
- return controllers;
-}
-
-void DisplayController::SetSecondaryDisplayLayout(
- SecondaryDisplayLayout layout) {
- secondary_display_layout_ = layout;
-}
-
-bool DisplayController::WarpMouseCursorIfNecessary(
- aura::Window* current_root,
- const gfx::Point& location_in_root) {
- if (root_windows_.size() < 2)
- return false;
- // Only 1 external display is supported in extended desktop mode.
- DCHECK_EQ(2U, root_windows_.size());
-
- bool in_primary = current_root == root_windows_[0];
-
- std::map<int, aura::RootWindow*>::iterator iter = root_windows_.begin();
- aura::RootWindow* alternate_root = iter->second != current_root ?
- iter->second : (++iter)->second;
- gfx::Rect alternate_bounds = alternate_root->bounds();
- gfx::Point alternate_point;
-
- gfx::Rect display_area(
- gfx::Screen::GetDisplayNearestWindow(current_root).bounds());
-
- // TODO(oshima): This is temporary code until the virtual screen
- // coordinate is implemented.
- if (location_in_root.x() <= display_area.x()) {
- if (location_in_root.y() < alternate_bounds.height() &&
- ((in_primary && secondary_display_layout_ == LEFT) ||
- (!in_primary && secondary_display_layout_ == RIGHT))) {
- alternate_point = gfx::Point(
- alternate_bounds.right() - (location_in_root.x() - display_area.x()),
- location_in_root.y());
- } else {
- alternate_root = NULL;
- }
- } else if (location_in_root.x() >= display_area.right() - 1) {
- if (location_in_root.y() < alternate_bounds.height() &&
- ((in_primary && secondary_display_layout_ == RIGHT) ||
- (!in_primary && secondary_display_layout_ == LEFT))) {
- alternate_point = gfx::Point(location_in_root.x() - display_area.right(),
- location_in_root.y());
- } else {
- alternate_root = NULL;
- }
- } else if (location_in_root.y() < display_area.y()) {
- if (location_in_root.x() < alternate_bounds.width() &&
- ((in_primary && secondary_display_layout_ == TOP) ||
- (!in_primary && secondary_display_layout_ == BOTTOM))) {
- alternate_point = gfx::Point(
- location_in_root.x(),
- alternate_bounds.bottom() -
- (location_in_root.y() - display_area.y()));
- } else {
- alternate_root = NULL;
- }
- } else if (location_in_root.y() >= display_area.bottom() - 1) {
- if (location_in_root.x() < alternate_bounds.width() &&
- ((in_primary && secondary_display_layout_ == BOTTOM) ||
- (!in_primary && secondary_display_layout_ == TOP))) {
- alternate_point = gfx::Point(
- location_in_root.x(), location_in_root.y() - display_area.bottom());
- } else {
- alternate_root = NULL;
- }
- } else {
- alternate_root = NULL;
- }
- if (alternate_root) {
- DCHECK_NE(alternate_root, current_root);
- alternate_root->MoveCursorTo(alternate_point);
- return true;
- }
- return false;
-}
-
-void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
- root_windows_[display.id()]->SetHostBounds(display.bounds_in_pixel());
-}
-
-void DisplayController::OnDisplayAdded(const gfx::Display& display) {
- if (root_windows_.empty()) {
- DCHECK_EQ(0, display.id());
- root_windows_[display.id()] = Shell::GetPrimaryRootWindow();
- Shell::GetPrimaryRootWindow()->SetHostBounds(display.bounds_in_pixel());
- return;
- }
- aura::RootWindow* root = AddRootWindowForDisplay(display);
- Shell::GetInstance()->InitRootWindowForSecondaryDisplay(root);
-}
-
-void DisplayController::OnDisplayRemoved(const gfx::Display& display) {
- aura::RootWindow* root = root_windows_[display.id()];
- DCHECK(root);
- // Primary display should never be removed by DisplayManager.
- DCHECK(root != Shell::GetPrimaryRootWindow());
- // Display for root window will be deleted when the Primary RootWindow
- // is deleted by the Shell.
- if (root != Shell::GetPrimaryRootWindow()) {
- root_windows_.erase(display.id());
- internal::RootWindowController* controller =
- wm::GetRootWindowController(root);
- if (controller) {
- controller->MoveWindowsTo(Shell::GetPrimaryRootWindow());
- delete controller;
- } else {
- delete root;
- }
- }
-}
-
-// static
-bool DisplayController::IsExtendedDesktopEnabled(){
- return extended_desktop_enabled ||
- CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kAshExtendedDesktop);
-}
-
-// static
-void DisplayController::SetExtendedDesktopEnabled(bool enabled) {
- extended_desktop_enabled = enabled;
-}
-
-// static
-bool DisplayController::IsVirtualScreenCoordinatesEnabled() {
- return virtual_screen_coordinates_enabled ||
- CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kAshVirtualScreenCoordinates);
-}
-
-// static
-void DisplayController::SetVirtualScreenCoordinatesEnabled(bool enabled) {
- virtual_screen_coordinates_enabled = enabled;
-}
-
-aura::RootWindow* DisplayController::AddRootWindowForDisplay(
- const gfx::Display& display) {
- aura::RootWindow* root = aura::Env::GetInstance()->display_manager()->
- CreateRootWindowForDisplay(display);
- root_windows_[display.id()] = root;
- // Confine the cursor within the window if
- // 1) Extended desktop is enabled or
- // 2) the display is primary display and the host window
- // is set to be fullscreen (this is old behavior).
- if (IsExtendedDesktopEnabled() ||
- (aura::DisplayManager::use_fullscreen_host_window() &&
- display.id() == 0)) {
- root->ConfineCursorToWindow();
- }
- return root;
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h
deleted file mode 100644
index 1b66d01..0000000
--- a/ash/display/display_controller.h
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef ASH_DISPLAY_DISPLAY_CONTROLLER_H_
-#define ASH_DISPLAY_DISPLAY_CONTROLLER_H_
-#pragma once
-
-#include <map>
-#include <vector>
-
-#include "ash/ash_export.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "ui/aura/display_observer.h"
-#include "ui/aura/display_manager.h"
-
-namespace aura {
-class Display;
-class RootWindow;
-}
-
-namespace ash {
-namespace internal {
-class RootWindowController;
-
-// DisplayController owns and maintains RootWindows for each attached
-// display, keeping them in sync with display configuration changes.
-// TODO(oshima): Rename DisplayXXX to DisplayXXX.
-class ASH_EXPORT DisplayController : public aura::DisplayObserver {
- public:
- // Layout options where the secondary display should be positioned.
- enum SecondaryDisplayLayout {
- TOP,
- RIGHT,
- BOTTOM,
- LEFT
- };
-
- DisplayController();
- virtual ~DisplayController();
-
- // Initializes primary display.
- void InitPrimaryDisplay();
-
- // Initialize secondary display. This is separated because in non
- // extended desktop mode, this creates background widgets, which
- // requires other controllers.
- void InitSecondaryDisplays();
-
- // Returns the root window for primary display.
- aura::RootWindow* GetPrimaryRootWindow();
-
- // Closes all child windows in the all root windows.
- void CloseChildWindows();
-
- // Returns all root windows. In non extended desktop mode, this
- // returns the primary root window only.
- std::vector<aura::RootWindow*> GetAllRootWindows();
-
- // Returns all oot window controllers. In non extended desktop
- // mode, this return a RootWindowController for the primary root window only.
- std::vector<internal::RootWindowController*> GetAllRootWindowControllers();
-
- SecondaryDisplayLayout secondary_display_layout() const {
- return secondary_display_layout_;
- }
- void SetSecondaryDisplayLayout(SecondaryDisplayLayout layout);
-
- // Warps the mouse cursor to an alternate root window when the
- // |location_in_root|, which is the location of the mouse cursor,
- // hits or exceeds the edge of the |root_window| and the mouse cursor
- // is considered to be in an alternate display. Returns true if
- // the cursor was moved.
- bool WarpMouseCursorIfNecessary(aura::Window* root_window,
- const gfx::Point& location_in_root);
-
- // aura::DisplayObserver overrides:
- virtual void OnDisplayBoundsChanged(
- const gfx::Display& display) OVERRIDE;
- virtual void OnDisplayAdded(const gfx::Display& display) OVERRIDE;
- virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE;
-
- // Is extended desktop enabled?
- static bool IsExtendedDesktopEnabled();
- // Change the extended desktop mode. Used for testing.
- static void SetExtendedDesktopEnabled(bool enabled);
-
- // Is virtual screen coordinates enabled?
- static bool IsVirtualScreenCoordinatesEnabled();
- // Turns on/off the virtual screen coordinates.
- static void SetVirtualScreenCoordinatesEnabled(bool enabled);
-
- private:
- // Creates a root window for |display| and stores it in the |root_windows_|
- // map.
- aura::RootWindow* AddRootWindowForDisplay(const gfx::Display& display);
-
- std::map<int, aura::RootWindow*> root_windows_;
-
- SecondaryDisplayLayout secondary_display_layout_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayController);
-};
-
-} // namespace internal
-} // namespace ash
-
-#endif // ASH_DISPLAY_DISPLAY_CONTROLLER_H_
diff --git a/ash/display/mouse_cursor_event_filter.cc b/ash/display/mouse_cursor_event_filter.cc
deleted file mode 100644
index 0ab6f1c..0000000
--- a/ash/display/mouse_cursor_event_filter.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2012 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/mouse_cursor_event_filter.h"
-
-#include "ash/display/display_controller.h"
-#include "ui/aura/event.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/window.h"
-
-namespace ash {
-namespace internal {
-
-MouseCursorEventFilter::MouseCursorEventFilter(
- DisplayController* display_controller)
- : display_controller_(display_controller) {
- DCHECK(display_controller_);
-}
-
-MouseCursorEventFilter::~MouseCursorEventFilter() {
-}
-
-bool MouseCursorEventFilter::PreHandleKeyEvent(aura::Window* target,
- aura::KeyEvent* event) {
- return false;
-}
-
-bool MouseCursorEventFilter::PreHandleMouseEvent(aura::Window* target,
- aura::MouseEvent* event) {
- if (event->type() != ui::ET_MOUSE_MOVED)
- return false;
- aura::RootWindow* current_root = target->GetRootWindow();
- gfx::Point location_in_root(event->location());
- aura::Window::ConvertPointToWindow(target, current_root, &location_in_root);
- return display_controller_->WarpMouseCursorIfNecessary(
- current_root, location_in_root);
-}
-
-ui::TouchStatus MouseCursorEventFilter::PreHandleTouchEvent(
- aura::Window* target,
- aura::TouchEvent* event) {
- return ui::TOUCH_STATUS_UNKNOWN;
-}
-
-ui::GestureStatus MouseCursorEventFilter::PreHandleGestureEvent(
- aura::Window* target,
- aura::GestureEvent* event) {
- return ui::GESTURE_STATUS_UNKNOWN;
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/display/mouse_cursor_event_filter.h b/ash/display/mouse_cursor_event_filter.h
deleted file mode 100644
index a89a6b7..0000000
--- a/ash/display/mouse_cursor_event_filter.h
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
-#define ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
-#pragma once
-
-#include "ash/ash_export.h"
-#include "base/compiler_specific.h"
-#include "ui/aura/event_filter.h"
-
-namespace ash {
-namespace internal {
-class DisplayController;
-
-// An event filter that controls mouse location in extended desktop
-// environment.
-class ASH_EXPORT MouseCursorEventFilter : public aura::EventFilter {
- public:
- MouseCursorEventFilter(DisplayController* display_controller);
- virtual ~MouseCursorEventFilter();
-
- // Overridden from aura::EventFilter:
- virtual bool PreHandleKeyEvent(aura::Window* target,
- aura::KeyEvent* event) OVERRIDE;
- virtual bool PreHandleMouseEvent(aura::Window* target,
- aura::MouseEvent* event) OVERRIDE;
- virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
- aura::TouchEvent* event) OVERRIDE;
- virtual ui::GestureStatus PreHandleGestureEvent(
- aura::Window* target,
- aura::GestureEvent* event) OVERRIDE;
-
- private:
- DisplayController* display_controller_;
-
- DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilter);
-};
-
-} // namespace internal
-} // namespace ash
-
-#endif // ASH_DISPLAY_MOUSE_CURSOR_EVENT_FILTER_H
diff --git a/ash/display/multi_display_manager.cc b/ash/display/multi_display_manager.cc
deleted file mode 100644
index 54b3d74..0000000
--- a/ash/display/multi_display_manager.cc
+++ /dev/null
@@ -1,247 +0,0 @@
-// Copyright (c) 2012 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/multi_display_manager.h"
-
-#include <string>
-#include <vector>
-
-#include "base/command_line.h"
-#include "base/stl_util.h"
-#include "base/string_split.h"
-#include "ui/aura/aura_switches.h"
-#include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/root_window_host.h"
-#include "ui/aura/window_property.h"
-#include "ui/gfx/display.h"
-#include "ui/gfx/rect.h"
-
-DECLARE_WINDOW_PROPERTY_TYPE(int);
-
-namespace ash {
-namespace internal {
-namespace {
-
-gfx::Display& GetInvalidDisplay() {
- static gfx::Display* invalid_display = new gfx::Display();
- return *invalid_display;
-}
-
-} // namespace
-
-using aura::RootWindow;
-using aura::Window;
-using std::string;
-using std::vector;
-
-DEFINE_WINDOW_PROPERTY_KEY(int, kDisplayIdKey, -1);
-
-MultiDisplayManager::MultiDisplayManager() {
- Init();
-}
-
-MultiDisplayManager::~MultiDisplayManager() {
-}
-
-// static
-void MultiDisplayManager::AddRemoveDisplay() {
- MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
- aura::Env::GetInstance()->display_manager());
- manager->AddRemoveDisplayImpl();
-}
-
-void MultiDisplayManager::CycleDisplay() {
- MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
- aura::Env::GetInstance()->display_manager());
- manager->CycleDisplayImpl();
-}
-
- void MultiDisplayManager::ToggleDisplayScale() {
- MultiDisplayManager* manager = static_cast<MultiDisplayManager*>(
- aura::Env::GetInstance()->display_manager());
- manager->ScaleDisplayImpl();
-}
-
-void MultiDisplayManager::OnNativeDisplaysChanged(
- const std::vector<gfx::Display>& new_displays) {
- size_t min = std::min(displays_.size(), new_displays.size());
-
- // For m19, we only care about 1st display as primary, and
- // don't differentiate the rest of displays as all secondary
- // displays have the same content. ID for primary display stays the same
- // because we never remove it, we don't update IDs for other displays
- // , for now, because they're the same.
- // TODO(oshima): Fix this so that we can differentiate outputs
- // and keep a content on one display stays on the same display
- // when a display is added or removed.
- for (size_t i = 0; i < min; ++i) {
- gfx::Display& current_display = displays_[i];
- const gfx::Display& new_display = new_displays[i];
- if (current_display.bounds_in_pixel() != new_display.bounds_in_pixel() ||
- current_display.device_scale_factor() !=
- new_display.device_scale_factor()) {
- current_display.SetScaleAndBounds(new_display.device_scale_factor(),
- new_display.bounds_in_pixel());
- NotifyBoundsChanged(current_display);
- }
- }
-
- if (displays_.size() < new_displays.size()) {
- // New displays added
- for (size_t i = min; i < new_displays.size(); ++i) {
- const gfx::Display& new_display = new_displays[i];
- displays_.push_back(gfx::Display(new_display.id()));
- gfx::Display& display = displays_.back();
- // Force the primary display's ID to be 0.
- if (i == 0)
- display.set_id(0);
- display.SetScaleAndBounds(new_display.device_scale_factor(),
- new_display.bounds_in_pixel());
- NotifyDisplayAdded(display);
- }
- } else {
- // Displays are removed. We keep the display for the primary
- // display (at index 0) because it needs the display information
- // even if it doesn't exit.
- while (displays_.size() > new_displays.size() && displays_.size() > 1) {
- Displays::reverse_iterator iter = displays_.rbegin();
- NotifyDisplayRemoved(*iter);
- displays_.erase(iter.base() - 1);
- }
- }
-}
-
-RootWindow* MultiDisplayManager::CreateRootWindowForDisplay(
- const gfx::Display& display) {
- RootWindow* root_window = new RootWindow(display.bounds_in_pixel());
- // No need to remove RootWindowObserver because
- // the DisplayManager object outlives RootWindow objects.
- root_window->AddRootWindowObserver(this);
- root_window->SetProperty(kDisplayIdKey, display.id());
- root_window->Init();
- return root_window;
-}
-
-const gfx::Display& MultiDisplayManager::GetDisplayAt(size_t index) {
- return index < displays_.size() ? displays_[index] : GetInvalidDisplay();
-}
-
-size_t MultiDisplayManager::GetNumDisplays() const {
- return displays_.size();
-}
-
-const gfx::Display& MultiDisplayManager::GetDisplayNearestWindow(
- const Window* window) const {
- if (!window) {
- MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this);
- return manager->GetDisplayAt(0);
- }
- const RootWindow* root = window->GetRootWindow();
- MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this);
- return root ? manager->FindDisplayForRootWindow(root) : GetInvalidDisplay();
-}
-
-const gfx::Display& MultiDisplayManager::GetDisplayNearestPoint(
- const gfx::Point& point) const {
- // TODO(oshima): For m19, mouse is constrained within
- // the primary window.
- MultiDisplayManager* manager = const_cast<MultiDisplayManager*>(this);
- return manager->GetDisplayAt(0);
-}
-
-void MultiDisplayManager::OnRootWindowResized(const aura::RootWindow* root,
- const gfx::Size& old_size) {
- if (!use_fullscreen_host_window()) {
- gfx::Display& display = FindDisplayForRootWindow(root);
- display.SetSize(root->GetHostSize());
- NotifyBoundsChanged(display);
- }
-}
-
-bool MultiDisplayManager::UpdateWorkAreaOfDisplayNearestWindow(
- const aura::Window* window,
- const gfx::Insets& insets) {
- const RootWindow* root = window->GetRootWindow();
- gfx::Display& display = FindDisplayForRootWindow(root);
- gfx::Rect old_work_area = display.work_area();
- display.UpdateWorkAreaFromInsets(insets);
- return old_work_area != display.work_area();
-}
-
-void MultiDisplayManager::Init() {
- // TODO(oshima): Move this logic to DisplayChangeObserver.
- const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kAuraHostWindowSize);
- vector<string> parts;
- base::SplitString(size_str, ',', &parts);
- for (vector<string>::const_iterator iter = parts.begin();
- iter != parts.end(); ++iter) {
- displays_.push_back(CreateDisplayFromSpec(*iter));
- }
- if (displays_.empty())
- displays_.push_back(CreateDisplayFromSpec("" /* default */));
- // Force the 1st display to be the primary display (id == 0).
- displays_[0].set_id(0);
-}
-
-void MultiDisplayManager::AddRemoveDisplayImpl() {
- std::vector<gfx::Display> new_displays;
- if (displays_.size() > 1) {
- // Remove if there is more than one display.
- int count = displays_.size() - 1;
- for (Displays::const_iterator iter = displays_.begin(); count-- > 0; ++iter)
- new_displays.push_back(*iter);
- } else {
- // Add if there is only one display.
- new_displays.push_back(displays_[0]);
- new_displays.push_back(CreateDisplayFromSpec("50+50-1280x768"));
- }
- if (new_displays.size())
- OnNativeDisplaysChanged(new_displays);
-}
-
-void MultiDisplayManager::CycleDisplayImpl() {
- if (displays_.size() > 1) {
- std::vector<gfx::Display> new_displays;
- for (Displays::const_iterator iter = displays_.begin() + 1;
- iter != displays_.end(); ++iter) {
- gfx::Display display = *iter;
- new_displays.push_back(display);
- }
- new_displays.push_back(displays_.front());
- OnNativeDisplaysChanged(new_displays);
- }
-}
-
-void MultiDisplayManager::ScaleDisplayImpl() {
- if (displays_.size() > 0) {
- std::vector<gfx::Display> new_displays;
- for (Displays::const_iterator iter = displays_.begin();
- iter != displays_.end(); ++iter) {
- gfx::Display display = *iter;
- float factor = display.device_scale_factor() == 1.0f ? 2.0f : 1.0f;
- display.SetScaleAndBounds(
- factor, gfx::Rect(display.bounds_in_pixel().origin(),
- display.size().Scale(factor)));
- new_displays.push_back(display);
- }
- OnNativeDisplaysChanged(new_displays);
- }
-}
-
-gfx::Display& MultiDisplayManager::FindDisplayForRootWindow(
- const aura::RootWindow* root_window) {
- int id = root_window->GetProperty(kDisplayIdKey);
- for (Displays::iterator iter = displays_.begin();
- iter != displays_.end(); ++iter) {
- if ((*iter).id() == id)
- return *iter;
- }
- DLOG(FATAL) << "Could not find display by id:" << id;
- return GetInvalidDisplay();
-}
-
-} // namespace internal
-} // namespace ash
diff --git a/ash/display/multi_display_manager.h b/ash/display/multi_display_manager.h
deleted file mode 100644
index 3aae410..0000000
--- a/ash/display/multi_display_manager.h
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_
-#define ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_
-#pragma once
-
-#include <vector>
-
-#include "ash/ash_export.h"
-#include "base/compiler_specific.h"
-#include "base/gtest_prod_util.h"
-#include "ui/aura/display_manager.h"
-#include "ui/aura/root_window_observer.h"
-#include "ui/aura/window.h"
-
-namespace gfx {
-class Insets;
-class Display;
-}
-
-namespace ash {
-namespace internal {
-
-// MultiDisplayManager maintains the current display configurations,
-// and notifies observers when configuration changes.
-// This is exported for unittest.
-//
-// TODO(oshima): gfx::Screen needs to return translated coordinates
-// if the root window is translated. crbug.com/119268.
-class ASH_EXPORT MultiDisplayManager : public aura::DisplayManager,
- public aura::RootWindowObserver {
- public:
- MultiDisplayManager();
- virtual ~MultiDisplayManager();
-
- // Used to emulate display change when run in a desktop environment instead
- // of on a device.
- static void AddRemoveDisplay();
- static void CycleDisplay();
- static void ToggleDisplayScale();
-
- bool UpdateWorkAreaOfDisplayNearestWindow(const aura::Window* window,
- const gfx::Insets& insets);
-
- // DisplayManager overrides:
- virtual void OnNativeDisplaysChanged(
- const std::vector<gfx::Display>& displays) OVERRIDE;
- virtual aura::RootWindow* CreateRootWindowForDisplay(
- const gfx::Display& display) OVERRIDE;
- virtual const gfx::Display& GetDisplayAt(size_t index) OVERRIDE;
-
- virtual size_t GetNumDisplays() const OVERRIDE;
- virtual const gfx::Display& GetDisplayNearestPoint(
- const gfx::Point& point) const OVERRIDE;
- virtual const gfx::Display& GetDisplayNearestWindow(
- const aura::Window* window) const OVERRIDE;
-
- // RootWindowObserver overrides:
- virtual void OnRootWindowResized(const aura::RootWindow* root,
- const gfx::Size& new_size) OVERRIDE;
-
- private:
- FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, ConvertPoint);
- typedef std::vector<gfx::Display> Displays;
-
- void Init();
- void AddRemoveDisplayImpl();
- void CycleDisplayImpl();
- void ScaleDisplayImpl();
- gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root);
-
- Displays displays_;
-
- DISALLOW_COPY_AND_ASSIGN(MultiDisplayManager);
-};
-
-extern const aura::WindowProperty<int>* const kDisplayIdKey;
-
-} // namespace internal
-} // namespace ash
-
-#endif // ASH_DISPLAY_MULTI_DISPLAY_MANAGER_H_
diff --git a/ash/display/multi_display_manager_unittest.cc b/ash/display/multi_display_manager_unittest.cc
deleted file mode 100644
index b1adc53..0000000
--- a/ash/display/multi_display_manager_unittest.cc
+++ /dev/null
@@ -1,235 +0,0 @@
-// Copyright (c) 2012 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/multi_display_manager.h"
-
-#include "ash/shell.h"
-#include "ash/test/ash_test_base.h"
-#include "base/format_macros.h"
-#include "base/stringprintf.h"
-#include "ui/aura/display_observer.h"
-#include "ui/aura/env.h"
-#include "ui/aura/root_window.h"
-#include "ui/aura/window_observer.h"
-#include "ui/gfx/display.h"
-
-namespace ash {
-namespace test {
-
-using std::vector;
-using std::string;
-
-class MultiDisplayManagerTest : public test::AshTestBase,
- public aura::DisplayObserver,
- public aura::WindowObserver {
- public:
- MultiDisplayManagerTest()
- : removed_count_(0U),
- root_window_destroyed_(false) {
- }
- virtual ~MultiDisplayManagerTest() {}
-
- virtual void SetUp() OVERRIDE {
- AshTestBase::SetUp();
- display_manager()->AddObserver(this);
- Shell::GetPrimaryRootWindow()->AddObserver(this);
- }
- virtual void TearDown() OVERRIDE {
- Shell::GetPrimaryRootWindow()->RemoveObserver(this);
- display_manager()->RemoveObserver(this);
- AshTestBase::TearDown();
- }
-
- aura::DisplayManager* display_manager() {
- return aura::Env::GetInstance()->display_manager();
- }
- const vector<gfx::Display>& changed() const { return changed_; }
- const vector<gfx::Display>& added() const { return added_; }
-
- string GetCountSummary() const {
- return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS,
- changed_.size(), added_.size(), removed_count_);
- }
-
- void reset() {
- changed_.clear();
- added_.clear();
- removed_count_ = 0U;
- root_window_destroyed_ = false;
- }
-
- bool root_window_destroyed() const {
- return root_window_destroyed_;
- }
-
- // aura::DisplayObserver overrides:
- virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE {
- changed_.push_back(display);
- }
- virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE {
- added_.push_back(new_display);
- }
- virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE {
- ++removed_count_;
- }
-
- // aura::WindowObserver overrides:
- virtual void OnWindowDestroying(aura::Window* window) {
- ASSERT_EQ(Shell::GetPrimaryRootWindow(), window);
- root_window_destroyed_ = true;
- }
-
- private:
- vector<gfx::Display> changed_;
- vector<gfx::Display> added_;
- size_t removed_count_;
- bool root_window_destroyed_;
-
- DISALLOW_COPY_AND_ASSIGN(MultiDisplayManagerTest);
-};
-
-TEST_F(MultiDisplayManagerTest, NativeDisplayTest) {
- aura::DisplayManager::set_use_fullscreen_host_window(true);
-
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
-
- // Update primary and add seconary.
- UpdateDisplay("0+0-500x500,0+501-400x400");
- EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- EXPECT_EQ("1 1 0", GetCountSummary());
- EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
- EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
- EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString());
- EXPECT_EQ("0,0 400x400", added()[0].bounds().ToString());
- EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString());
- reset();
-
- // Delete secondary.
- UpdateDisplay("0+0-500x500");
- EXPECT_EQ("0 0 1", GetCountSummary());
- reset();
-
- // Change primary.
- UpdateDisplay("0+0-1000x600");
- EXPECT_EQ("1 0 0", GetCountSummary());
- EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
- EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString());
- reset();
-
- // Add secondary.
- UpdateDisplay("0+0-1000x600,1001+0-600x400");
- EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- EXPECT_EQ("0 1 0", GetCountSummary());
- EXPECT_EQ(display_manager()->GetDisplayAt(1).id(), added()[0].id());
- EXPECT_EQ("0,0 600x400", added()[0].bounds().ToString());
- EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString());
- reset();
-
- // Secondary removed, primary changed.
- UpdateDisplay("0+0-800x300");
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_EQ("1 0 1", GetCountSummary());
- EXPECT_EQ(display_manager()->GetDisplayAt(0).id(), changed()[0].id());
- EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString());
- reset();
-
- // # of display can go to zero when screen is off.
- const vector<gfx::Display> empty;
- display_manager()->OnNativeDisplaysChanged(empty);
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_EQ("0 0 0", GetCountSummary());
- EXPECT_FALSE(root_window_destroyed());
- // Display configuration stays the same
- EXPECT_EQ("0,0 800x300",
- display_manager()->GetDisplayAt(0).bounds().ToString());
- reset();
-
- // Connect to display again
- UpdateDisplay("100+100-500x400");
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_EQ("1 0 0", GetCountSummary());
- EXPECT_FALSE(root_window_destroyed());
- EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString());
- EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString());
- reset();
-
- // Go back to zero and wake up with multiple displays.
- display_manager()->OnNativeDisplaysChanged(empty);
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_FALSE(root_window_destroyed());
- reset();
-
- // Add secondary.
- UpdateDisplay("0+0-1000x600,1000+0-600x400");
- EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- EXPECT_EQ("0,0 1000x600",
- display_manager()->GetDisplayAt(0).bounds().ToString());
- EXPECT_EQ("0,0 600x400",
- display_manager()->GetDisplayAt(1).bounds().ToString());
- EXPECT_EQ("1000,0 600x400",
- display_manager()->GetDisplayAt(1).bounds_in_pixel().ToString());
- reset();
-
- aura::DisplayManager::set_use_fullscreen_host_window(false);
-}
-
-// Test in emulation mode (use_fullscreen_host_window=false)
-TEST_F(MultiDisplayManagerTest, EmulatorTest) {
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
-
- internal::MultiDisplayManager::AddRemoveDisplay();
- // Update primary and add seconary.
- EXPECT_EQ(2U, display_manager()->GetNumDisplays());
-#if defined(OS_WIN)
- // TODO(oshima): Windows receives resize event for some reason.
- EXPECT_EQ("1 1 0", GetCountSummary());
-#else
- EXPECT_EQ("0 1 0", GetCountSummary());
-#endif
- reset();
-
- internal::MultiDisplayManager::CycleDisplay();
- EXPECT_EQ(2U, display_manager()->GetNumDisplays());
- // Observer gets called twice in this mode because
- // it gets notified both from |OnNativeDisplayChagned|
- // and from |RootWindowObserver|, which is the consequence of
- // |SetHostSize()|.
- EXPECT_EQ("4 0 0", GetCountSummary());
- reset();
-
- internal::MultiDisplayManager::AddRemoveDisplay();
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_EQ("0 0 1", GetCountSummary());
- reset();
-
- internal::MultiDisplayManager::CycleDisplay();
- EXPECT_EQ(1U, display_manager()->GetNumDisplays());
- EXPECT_EQ("0 0 0", GetCountSummary());
- reset();
-}
-
-// TODO(oshima): Device scale factor is supported on chromeos only for now.
-#if defined(OS_CHROMEOS)
-#define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange
-#else
-#define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange
-#endif
-
-TEST_F(MultiDisplayManagerTest, MAYBE_TestDeviceScaleOnlyChange) {
- aura::DisplayManager::set_use_fullscreen_host_window(true);
- UpdateDisplay("0+0-1000x600");
- EXPECT_EQ(1,
- Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor());
- EXPECT_EQ("1000x600",
- Shell::GetPrimaryRootWindow()->bounds().size().ToString());
- UpdateDisplay("0+0-1000x600*2");
- EXPECT_EQ(2,
- Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor());
- EXPECT_EQ("500x300",
- Shell::GetPrimaryRootWindow()->bounds().size().ToString());
- aura::DisplayManager::set_use_fullscreen_host_window(false);
-}
-
-} // namespace test
-} // namespace ash
diff --git a/ash/display/secondary_display_view.cc b/ash/display/secondary_display_view.cc
deleted file mode 100644
index ea8963e..0000000
--- a/ash/display/secondary_display_view.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright (c) 2012 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/secondary_display_view.h"
-
-#include "grit/ash_strings.h"
-#include "grit/ui_resources.h"
-#include "third_party/skia/include/core/SkColor.h"
-#include "ui/aura/window.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/resource/resource_bundle.h"
-#include "ui/views/background.h"
-#include "ui/views/controls/image_view.h"
-#include "ui/views/controls/label.h"
-#include "ui/views/view.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_delegate.h"
-
-namespace ash {
-namespace {
-
-// Colors for the background, the message text and the shortcut text.
-const SkColor kBackgroundColor = SkColorSetRGB(0x33, 0x33, 0x33);
-const SkColor kTextColor = SkColorSetRGB(127, 127, 127);
-
-// A view to be displayed on secondary display.
-class SecondaryDisplayView : public views::WidgetDelegateView {
- public:
- SecondaryDisplayView() {
- Init();
- }
- virtual ~SecondaryDisplayView() {
- }
-
- void Init() {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
-
- set_background(views::Background::CreateSolidBackground(kBackgroundColor));
- message_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_ASH_SECONDARY_MONITOR));
- message_->SetAutoColorReadabilityEnabled(false);
- message_->SetFont(rb.GetFont(ui::ResourceBundle::LargeFont));
- message_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
- message_->SetEnabledColor(kTextColor);
- AddChildView(message_);
-
- shortcut_text_ = new views::Label(
- l10n_util::GetStringUTF16(IDS_ASH_SECONDARY_MONITOR_SHORTCUT));
- shortcut_text_->SetAutoColorReadabilityEnabled(false);
- shortcut_text_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
- shortcut_text_->SetHorizontalAlignment(views::Label::ALIGN_CENTER);
- shortcut_text_->SetEnabledColor(kTextColor);
- AddChildView(shortcut_text_);
-
- shortcut_image_ = new views::ImageView();
- shortcut_image_->SetImage(rb.GetImageSkiaNamed(IDR_AURA_SWITCH_MONITOR));
- AddChildView(shortcut_image_);
- }
-
- virtual void Layout() {
- const int kMessagePositionTopMargin = 40;
- const int kShortcutPositionBottomMargin = 40;
- const int kShortcutMargin = 4; // margin between text and image.
- gfx::Rect b = bounds();
-
- int msg_height = message_->GetHeightForWidth(b.width());
- message_->SetBounds(
- 0, kMessagePositionTopMargin, bounds().width(), msg_height);
-
- // TODO(oshima): Figure out what to do for RTL.
- // Align the shortcut text & image to the center.
- gfx::Size text_size = shortcut_text_->GetPreferredSize();
- gfx::Size image_size = shortcut_image_->GetPreferredSize();
- int height = std::max(text_size.height(), image_size.height());
- int y = b.height() - kShortcutPositionBottomMargin - height;
- int x = (b.width() -
- (text_size.width() + kShortcutMargin + image_size.width())) / 2;
- shortcut_text_->SetBounds(x, y + (height - text_size.height()) / 2,
- text_size.width(), text_size.height());
- shortcut_image_->SetBounds(
- x + text_size.width() + kShortcutMargin,
- y + (height - image_size.height()) / 2,
- image_size.width(), image_size.height());
- }
-
- private:
- views::Label* message_;
- views::Label* shortcut_text_;
- views::ImageView* shortcut_image_;
-
- DISALLOW_COPY_AND_ASSIGN(SecondaryDisplayView);
-};
-
-} // namespace
-
-views::Widget* CreateSecondaryDisplayWidget(aura::Window* parent) {
- views::Widget* desktop_widget = new views::Widget;
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- SecondaryDisplayView* view = new SecondaryDisplayView();
- params.delegate = view;
- params.parent = parent;
- desktop_widget->Init(params);
- desktop_widget->SetContentsView(view);
- desktop_widget->Show();
- desktop_widget->GetNativeView()->SetName("SecondaryDisplay");
- return desktop_widget;
-}
-
-} // namespace ash
diff --git a/ash/display/secondary_display_view.h b/ash/display/secondary_display_view.h
deleted file mode 100644
index 60db1e0..0000000
--- a/ash/display/secondary_display_view.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef ASH_DISPLAY_SECONDARY_DISPLAY_VIEW_H_
-#define ASH_DISPLAY_SECONDARY_DISPLAY_VIEW_H_
-#pragma once
-
-namespace aura {
-class Window;
-}
-
-namespace views {
-class Widget;
-}
-
-namespace ash {
-
-// Creates the widget that hosts the static message displayed on the
-// secondary display.
-views::Widget* CreateSecondaryDisplayWidget(aura::Window* parent);
-
-} // namespace ash
-
-#endif // ASH_DISPLAY_SECONDARY_DISPLAY_VIEW_H_