diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 00:00:22 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-23 00:00:22 +0000 |
commit | 4a7e43e76fb9ff1ae2c78ed62ee802e5c855aa56 (patch) | |
tree | 1b77d018b8faba9287f830c8230ae37ba9c7d062 /ash/monitor | |
parent | 407a34a0044b8ae31051e2276ffec438d6712ace (diff) | |
download | chromium_src-4a7e43e76fb9ff1ae2c78ed62ee802e5c855aa56.zip chromium_src-4a7e43e76fb9ff1ae2c78ed62ee802e5c855aa56.tar.gz chromium_src-4a7e43e76fb9ff1ae2c78ed62ee802e5c855aa56.tar.bz2 |
Revert r128330 "* MonitorChangeObserverX11 that listen to Xrandr events and update monitor configurations."
TBR=ben@chromium.org
BUG=115510
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9839032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128346 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/monitor')
-rw-r--r-- | ash/monitor/monitor_controller.cc | 24 | ||||
-rw-r--r-- | ash/monitor/monitor_controller.h | 2 | ||||
-rw-r--r-- | ash/monitor/multi_monitor_manager.cc | 112 | ||||
-rw-r--r-- | ash/monitor/multi_monitor_manager.h | 29 | ||||
-rw-r--r-- | ash/monitor/multi_monitor_manager_unittest.cc | 178 | ||||
-rw-r--r-- | ash/monitor/secondary_monitor_view.cc | 58 |
6 files changed, 26 insertions, 377 deletions
diff --git a/ash/monitor/monitor_controller.cc b/ash/monitor/monitor_controller.cc index c09d9db..072aac5 100644 --- a/ash/monitor/monitor_controller.cc +++ b/ash/monitor/monitor_controller.cc @@ -9,9 +9,7 @@ #include "ash/shell.h" #include "ash/wm/base_layout_manager.h" #include "ash/wm/root_window_layout_manager.h" -#include "base/bind.h" #include "base/stl_util.h" -#include "base/time.h" #include "ui/aura/env.h" #include "ui/aura/monitor.h" #include "ui/aura/root_window.h" @@ -23,16 +21,14 @@ namespace internal { namespace { void SetupAsSecondaryMonitor(aura::RootWindow* root) { - root->SetFocusWhenShown(false); root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); aura::Window* container = new aura::Window(NULL); container->SetName("SecondaryMonitorContainer"); container->Init(ui::Layer::LAYER_NOT_DRAWN); root->AddChild(container); + container->Show(); container->SetLayoutManager(new internal::BaseLayoutManager(root)); CreateSecondaryMonitorWidget(container); - container->Show(); - root->layout_manager()->OnWindowResized(); root->ShowRootWindow(); } @@ -47,27 +43,14 @@ MonitorController::~MonitorController() { aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); // Remove the root first. aura::Monitor* monitor = Shell::GetRootWindow()->GetProperty(kMonitorKey); - DCHECK(monitor); root_windows_.erase(monitor); STLDeleteContainerPairSecondPointers( root_windows_.begin(), root_windows_.end()); } void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) { - root_windows_[monitor]->SetHostBounds(monitor->bounds()); -} - -void MonitorController::OnMonitorAdded(aura::Monitor* monitor) { - aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()-> - CreateRootWindowForMonitor(monitor); - root_windows_[monitor] = root; - SetupAsSecondaryMonitor(root); -} - -void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) { - aura::RootWindow* root = root_windows_[monitor]; - root_windows_.erase(monitor); - delete root; + if (aura::MonitorManager::use_fullscreen_host_window()) + root_windows_[monitor]->SetHostBounds(monitor->bounds()); } void MonitorController::Init() { @@ -79,7 +62,6 @@ void MonitorController::Init() { if (i == 0) { // Primary monitor root_windows_[key] = Shell::GetRootWindow(); - Shell::GetRootWindow()->SetHostBounds(monitor->bounds()); } else { aura::RootWindow* root = monitor_manager->CreateRootWindowForMonitor(monitor); diff --git a/ash/monitor/monitor_controller.h b/ash/monitor/monitor_controller.h index bfbd568..52df5f7 100644 --- a/ash/monitor/monitor_controller.h +++ b/ash/monitor/monitor_controller.h @@ -28,8 +28,6 @@ class MonitorController : public aura::MonitorObserver { // aura::MonitorObserver overrides: virtual void OnMonitorBoundsChanged(const aura::Monitor* monitor) OVERRIDE; - virtual void OnMonitorAdded(aura::Monitor* monitor) OVERRIDE; - virtual void OnMonitorRemoved(const aura::Monitor* monitor) OVERRIDE; private: void Init(); diff --git a/ash/monitor/multi_monitor_manager.cc b/ash/monitor/multi_monitor_manager.cc index a70c844..a6a30f9 100644 --- a/ash/monitor/multi_monitor_manager.cc +++ b/ash/monitor/multi_monitor_manager.cc @@ -22,15 +22,6 @@ DECLARE_WINDOW_PROPERTY_TYPE(aura::Monitor*); namespace ash { namespace internal { -namespace { - -aura::Monitor* Copy(aura::Monitor* m) { - aura::Monitor* monitor = new aura::Monitor; - monitor->set_bounds(m->bounds()); - return monitor; -} - -} // namespace DEFINE_WINDOW_PROPERTY_KEY(aura::Monitor*, kMonitorKey, NULL); @@ -45,57 +36,17 @@ MultiMonitorManager::MultiMonitorManager() { } MultiMonitorManager::~MultiMonitorManager() { - // All monitors must have been deleted when root windows are deleted. - DCHECK(!monitors_.size()); -} - -// static -void MultiMonitorManager::AddRemoveMonitor() { - MultiMonitorManager* manager = static_cast<MultiMonitorManager*>( - aura::Env::GetInstance()->monitor_manager()); - manager->AddRemoveMonitorImpl(); + STLDeleteContainerPointers(monitors_.begin(), monitors_.end()); } -void MultiMonitorManager::CycleMonitor() { - MultiMonitorManager* manager = static_cast<MultiMonitorManager*>( - aura::Env::GetInstance()->monitor_manager()); - manager->CycleMonitorImpl(); -} - -void MultiMonitorManager::OnNativeMonitorsChanged( - const std::vector<const aura::Monitor*>& new_monitors) { - size_t min = std::min(monitors_.size(), new_monitors.size()); - - // For m19, we only care about 1st monitor as primary, and - // don't differentiate the rest of monitors as all secondary - // monitors have the same content. - // TODO(oshima): Fix this so that we can differentiate outputs - // and keep a content on one monitor stays on the same monitor - // when a monitor is added or removed. - for (size_t i = 0; i < min; ++i) { - Monitor* current_monitor = monitors_[i]; - const Monitor* new_monitor = new_monitors[i]; - if (current_monitor->bounds() != new_monitor->bounds()) { - current_monitor->set_bounds(new_monitor->bounds()); - NotifyBoundsChanged(current_monitor); - } - } - - if (monitors_.size() < new_monitors.size()) { - // New monitors added - for (size_t i = min; i < new_monitors.size(); ++i) { - Monitor* monitor = new Monitor(); - monitor->set_bounds(new_monitors[i]->bounds()); - monitors_.push_back(monitor); - NotifyMonitorAdded(monitor); - } - } else { - // Monitors are removed. - while (monitors_.size() > new_monitors.size()) { - Monitor* monitor = monitors_.back(); - // Monitor object is deleted in OnWindowDestroying. - NotifyMonitorRemoved(monitor); - } +void MultiMonitorManager::OnNativeMonitorResized(const gfx::Size& size) { + // TODO(oshima): Update monitors using xrandr and notify observers + // Just update the primary for now. + if (use_fullscreen_host_window()) { + Monitor* monitor = + aura::Env::GetInstance()->monitor_manager()->GetMonitorAt(0); + monitor->set_size(size); + NotifyBoundsChanged(monitor); } } @@ -103,7 +54,6 @@ RootWindow* MultiMonitorManager::CreateRootWindowForMonitor( Monitor* monitor) { RootWindow* root_window = new RootWindow(monitor->bounds()); root_window->AddObserver(this); - root_window->AddRootWindowObserver(this); root_window->SetProperty(kMonitorKey, monitor); return root_window; } @@ -139,27 +89,22 @@ Monitor* MultiMonitorManager::GetMonitorNearestWindow(const Window* window) { return const_cast<Monitor*>(manager->GetMonitorNearestWindow(window)); } -void MultiMonitorManager::OnRootWindowResized(const aura::RootWindow* root, - const gfx::Size& old_size) { +void MultiMonitorManager::OnWindowBoundsChanged( + Window* window, const gfx::Rect& bounds) { if (!use_fullscreen_host_window()) { - Monitor* monitor = root->GetProperty(kMonitorKey); - monitor->set_size(root->GetHostSize()); + Monitor* monitor = window->GetProperty(kMonitorKey); + monitor->set_size(bounds.size()); NotifyBoundsChanged(monitor); } } void MultiMonitorManager::OnWindowDestroying(Window* window) { - RootWindow* root = static_cast<RootWindow*>(window); - root->RemoveObserver(this); - root->RemoveRootWindowObserver(this); - Monitor* monitor = window->GetProperty(kMonitorKey); monitors_.erase(std::find(monitors_.begin(), monitors_.end(), monitor)); delete monitor; } void MultiMonitorManager::Init() { - // TODO(oshima): Move this logic to MonitorChangeObserver. const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( switches::kAuraHostWindowSize); vector<string> parts; @@ -172,36 +117,5 @@ void MultiMonitorManager::Init() { monitors_.push_back(CreateMonitorFromSpec("" /* default */)); } -void MultiMonitorManager::AddRemoveMonitorImpl() { - std::vector<const Monitor*> new_monitors; - if (monitors_.size() > 1) { - // Remove if there is more than one monitor. - int count = monitors_.size() - 1; - for (Monitors::const_iterator iter = monitors_.begin(); count-- > 0; ++iter) - new_monitors.push_back(Copy(*iter)); - } else { - // Add if there is only one monitor. - new_monitors.push_back(Copy(monitors_[0])); - aura::Monitor* extra_monitor = new Monitor; - extra_monitor->set_bounds(gfx::Rect(100, 100, 1440, 800)); - new_monitors.push_back(extra_monitor); - } - if (new_monitors.size()) - OnNativeMonitorsChanged(new_monitors); - STLDeleteContainerPointers(new_monitors.begin(), new_monitors.end()); -} - -void MultiMonitorManager::CycleMonitorImpl() { - if (monitors_.size() > 1) { - std::vector<const Monitor*> new_monitors; - for (Monitors::const_iterator iter = monitors_.begin() + 1; - iter != monitors_.end(); ++iter) - new_monitors.push_back(Copy(*iter)); - new_monitors.push_back(Copy(monitors_.front())); - OnNativeMonitorsChanged(new_monitors); - STLDeleteContainerPointers(new_monitors.begin(), new_monitors.end()); - } -} - } // namespace internal } // namespace ash diff --git a/ash/monitor/multi_monitor_manager.h b/ash/monitor/multi_monitor_manager.h index b24c98e..609f931 100644 --- a/ash/monitor/multi_monitor_manager.h +++ b/ash/monitor/multi_monitor_manager.h @@ -6,38 +6,23 @@ #define ASH_MONITOR_MULTI_MONITOR_MANAGER_H_ #pragma once -#include "ash/ash_export.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "ui/aura/monitor_manager.h" -#include "ui/aura/root_window_observer.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" namespace ash { namespace internal { -// MultiMonitorManager maintains the current monitor 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 MultiMonitorManager : public aura::MonitorManager, - public aura::RootWindowObserver, - public aura::WindowObserver { +class MultiMonitorManager : public aura::MonitorManager, + public aura::WindowObserver { public: MultiMonitorManager(); virtual ~MultiMonitorManager(); - // Used to emulate monitor change when run in a desktop environment instead - // of on a device. - static void AddRemoveMonitor(); - static void CycleMonitor(); - // MonitorManager overrides: - virtual void OnNativeMonitorsChanged( - const std::vector<const aura::Monitor*>& monitors) OVERRIDE; + virtual void OnNativeMonitorResized(const gfx::Size& size) OVERRIDE; virtual aura::RootWindow* CreateRootWindowForMonitor( aura::Monitor* monitor) OVERRIDE; virtual const aura::Monitor* GetMonitorNearestWindow( @@ -49,19 +34,15 @@ class ASH_EXPORT MultiMonitorManager : public aura::MonitorManager, virtual aura::Monitor* GetMonitorNearestWindow( const aura::Window* window) OVERRIDE; - // RootWindowObserver overrides: - virtual void OnRootWindowResized(const aura::RootWindow* root, - const gfx::Size& new_size) OVERRIDE; - // WindowObserver overrides: + virtual void OnWindowBoundsChanged(aura::Window* window, + const gfx::Rect& bounds) OVERRIDE; virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; private: typedef std::vector<aura::Monitor*> Monitors; void Init(); - void AddRemoveMonitorImpl(); - void CycleMonitorImpl(); Monitors monitors_; diff --git a/ash/monitor/multi_monitor_manager_unittest.cc b/ash/monitor/multi_monitor_manager_unittest.cc deleted file mode 100644 index 336f91c..0000000 --- a/ash/monitor/multi_monitor_manager_unittest.cc +++ /dev/null @@ -1,178 +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/monitor/multi_monitor_manager.h" - -#include "ash/shell.h" -#include "ash/test/ash_test_base.h" -#include "base/format_macros.h" -#include "base/stl_util.h" -#include "base/string_split.h" -#include "base/stringprintf.h" -#include "ui/aura/env.h" -#include "ui/aura/monitor.h" -#include "ui/aura/root_window.h" - -namespace ash { -namespace test { - -using std::vector; -using std::string; -using aura::Monitor; - -namespace { - -vector<const aura::Monitor*> CreateMonitorsFromString( - const std::string specs) { - vector<const aura::Monitor*> monitors; - vector<string> parts; - base::SplitString(specs, ',', &parts); - for (vector<string>::const_iterator iter = parts.begin(); - iter != parts.end(); ++iter) { - monitors.push_back(aura::MonitorManager::CreateMonitorFromSpec(*iter)); - } - return monitors; -} - -} // namespace - -class MultiMonitorManagerTest : public test::AshTestBase, - public aura::MonitorObserver { - public: - MultiMonitorManagerTest() : removed_count_(0U) {} - virtual ~MultiMonitorManagerTest() {} - - virtual void SetUp() OVERRIDE { - AshTestBase::SetUp(); - monitor_manager()->AddObserver(this); - } - virtual void TearDown() OVERRIDE { - monitor_manager()->RemoveObserver(this); - AshTestBase::TearDown(); - } - - aura::MonitorManager* monitor_manager() { - return aura::Env::GetInstance()->monitor_manager(); - } - const vector<const Monitor*>& changed() const { return changed_; } - const vector<const Monitor*>& 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; - } - - // aura::MonitorObserver overrides: - virtual void OnMonitorBoundsChanged(const Monitor* monitor) OVERRIDE { - changed_.push_back(monitor); - } - virtual void OnMonitorAdded(Monitor* new_monitor) OVERRIDE { - added_.push_back(new_monitor); - } - virtual void OnMonitorRemoved(const Monitor* old_monitor) OVERRIDE { - ++removed_count_; - } - - void UpdateMonitor(const std::string str) { - vector<const aura::Monitor*> monitors = CreateMonitorsFromString(str); - monitor_manager()->OnNativeMonitorsChanged(monitors); - STLDeleteContainerPointers(monitors.begin(), monitors.end()); - } - - private: - vector<const Monitor*> changed_; - vector<const Monitor*> added_; - size_t removed_count_; - - DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest); -}; - -TEST_F(MultiMonitorManagerTest, NativeMonitorTest) { - aura::MonitorManager::set_use_fullscreen_host_window(true); - - EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); - - // Update primary and add seconary. - UpdateMonitor("0+0-500x500,0+501-400x400"); - EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); - EXPECT_EQ("1 1 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); - EXPECT_EQ("0,0 500x500", changed()[0]->bounds().ToString()); - EXPECT_EQ("0,501 400x400", added()[0]->bounds().ToString()); - reset(); - - // Delete secondary. - UpdateMonitor("0+0-500x500"); - EXPECT_EQ("0 0 1", GetCountSummary()); - reset(); - - // Change primary. - UpdateMonitor("0+0-1000x600"); - EXPECT_EQ("1 0 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ("0,0 1000x600", changed()[0]->bounds().ToString()); - reset(); - - // Add secondary. - UpdateMonitor("0+0-1000x600,1001+0-600x400"); - EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); - EXPECT_EQ("0 1 0", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(1), added()[0]); - EXPECT_EQ("1001,0 600x400", added()[0]->bounds().ToString()); - reset(); - - // Secondary removed, primary changed. - UpdateMonitor("0+0-800x300"); - EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); - EXPECT_EQ("1 0 1", GetCountSummary()); - EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]); - EXPECT_EQ("0,0 800x300", changed()[0]->bounds().ToString()); - - aura::MonitorManager::set_use_fullscreen_host_window(false); -} - -// Test in emulation mode (use_fullscreen_host_window=false) -TEST_F(MultiMonitorManagerTest, EmulatorTest) { - EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); - - internal::MultiMonitorManager::AddRemoveMonitor(); - // Update primary and add seconary. - EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); -#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::MultiMonitorManager::CycleMonitor(); - EXPECT_EQ(2U, monitor_manager()->GetNumMonitors()); - // Observer gets called twice in this mode because - // it gets notified both from |OnNativeMonitorChagned| - // and from |RootWindowObserver|, which is the consequence of - // |SetHostSize()|. - EXPECT_EQ("4 0 0", GetCountSummary()); - reset(); - - internal::MultiMonitorManager::AddRemoveMonitor(); - EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); - EXPECT_EQ("0 0 1", GetCountSummary()); - reset(); - - internal::MultiMonitorManager::CycleMonitor(); - EXPECT_EQ(1U, monitor_manager()->GetNumMonitors()); - EXPECT_EQ("0 0 0", GetCountSummary()); - reset(); -} - -} // namespace test -} // namespace ash diff --git a/ash/monitor/secondary_monitor_view.cc b/ash/monitor/secondary_monitor_view.cc index 05b4452..a570932 100644 --- a/ash/monitor/secondary_monitor_view.cc +++ b/ash/monitor/secondary_monitor_view.cc @@ -4,74 +4,26 @@ #include "ash/monitor/secondary_monitor_view.h" -#include "grit/ash_strings.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/label.h" #include "ui/views/view.h" -#include "ui/views/widget/widget.h" +#include "ui/views/background.h" #include "ui/views/widget/widget_delegate.h" +#include "ui/views/widget/widget.h" namespace ash { namespace { -// Colors for the background, the message text and the shortcut text. -const SkColor kBackgroundColor = SkColorSetRGB(0x33, 0x33, 0x33); -const SkColor kMessageColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); -const SkColor kShortcutColor = SkColorSetRGB(0x8f, 0x8f, 0x8f); +const SkColor kBackground = SkColorSetRGB(0x33, 0x33, 0x33); // A view to be displayed on secondary monitor. class SecondaryMonitorView : public views::WidgetDelegateView { public: SecondaryMonitorView() { - Init(); + set_background(views::Background::CreateSolidBackground(kBackground)); } - virtual ~SecondaryMonitorView() { + ~SecondaryMonitorView() { } - - 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::MediumFont)); - message_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); - message_->SetEnabledColor(kMessageColor); - AddChildView(message_); - - // TODO(oshima): Add image for fullscreen shortcut. - shortcut_ = new views::Label( - l10n_util::GetStringUTF16(IDS_ASH_SECONDARY_MONITOR_SHORTCUT)); - shortcut_->SetAutoColorReadabilityEnabled(false); - shortcut_->SetFont(rb.GetFont(ui::ResourceBundle::SmallFont)); - shortcut_->SetHorizontalAlignment(views::Label::ALIGN_CENTER); - shortcut_->SetEnabledColor(kShortcutColor); - AddChildView(shortcut_); - } - - virtual void Layout() { - const int kMessageMargin = 20; - const float kShortcutPositionFromBottom = 50; - gfx::Rect b = bounds(); - int bottom = bounds().height() - kShortcutPositionFromBottom; - int shortcut_height = shortcut_->GetHeightForWidth(b.width()); - shortcut_->SetBounds(0, bottom, b.width(), shortcut_height); - - int msg_height = message_->GetHeightForWidth(b.width()); - bottom -= msg_height + kMessageMargin; - message_->SetBounds(0, bottom, bounds().width(), msg_height); - } - - private: - views::Label* message_; - views::Label* shortcut_; - - DISALLOW_COPY_AND_ASSIGN(SecondaryMonitorView); }; } // namespace |